From b288d57d7844ddb00dbe49f76f82b71411a5ace5 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Wed, 27 Nov 2019 09:37:54 +0100
Subject: [PATCH] Implement setters for QSscorer properties

Requirement of Python 3 to fulfill our promise of being able to set
various things. This also removes an ugly hack of setting a variable
intended to be private in the unit test.
---
 modules/mol/alg/pymod/qsscoring.py      | 28 +++++++++++++++++++++++++
 modules/mol/alg/tests/test_qsscoring.py |  3 +--
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/modules/mol/alg/pymod/qsscoring.py b/modules/mol/alg/pymod/qsscoring.py
index ba9c2af9d..8f9286b49 100644
--- a/modules/mol/alg/pymod/qsscoring.py
+++ b/modules/mol/alg/pymod/qsscoring.py
@@ -228,6 +228,10 @@ class QSscorer:
       self._chem_mapping = _GetChemGroupsMapping(self.qs_ent_1, self.qs_ent_2)
     return self._chem_mapping
 
+  @chem_mapping.setter
+  def chem_mapping(self, chem_mapping):
+    self._chem_mapping = chem_mapping
+
   @property
   def ent_to_cm_1(self):
     """Subset of :attr:`qs_ent_1` used to compute chain mapping and symmetries.
@@ -255,6 +259,10 @@ class QSscorer:
       self._ComputeAlignedEntities()
     return self._ent_to_cm_1
 
+  @ent_to_cm_1.setter
+  def ent_to_cm_1(self, ent_to_cm_1):
+    self._ent_to_cm_1 = ent_to_cm_1
+
   @property
   def ent_to_cm_2(self):
     """Subset of :attr:`qs_ent_1` used to compute chain mapping and symmetries
@@ -264,6 +272,10 @@ class QSscorer:
       self._ComputeAlignedEntities()
     return self._ent_to_cm_2
 
+  @ent_to_cm_2.setter
+  def ent_to_cm_2(self, ent_to_cm_2):
+    self._ent_to_cm_2 = ent_to_cm_2
+
   @property
   def symm_1(self):
     """Symmetry groups for :attr:`qs_ent_1` used to speed up chain mapping.
@@ -384,6 +396,10 @@ class QSscorer:
       LogInfo('Mapping found: %s' % str(self._chain_mapping))
     return self._chain_mapping
 
+  @chain_mapping.setter
+  def chain_mapping(self, chain_mapping):
+    self._chain_mapping = chain_mapping
+
   @property
   def chain_mapping_scheme(self):
     """Mapping scheme used to get :attr:`chain_mapping`.
@@ -440,6 +456,10 @@ class QSscorer:
                                               self.res_num_alignment)
     return self._alignments
 
+  @alignments.setter
+  def alignments(self, alignments):
+    self._alignments = alignments
+
   @property
   def mapped_residues(self):
     """Mapping of shared residues in :attr:`alignments`.
@@ -454,6 +474,10 @@ class QSscorer:
       self._mapped_residues = _GetMappedResidues(self.alignments)
     return self._mapped_residues
 
+  @mapped_residues.setter
+  def mapped_residues(self, mapped_residues):
+    self._mapped_residues = mapped_residues
+
   @property
   def global_score(self):
     """QS-score with penalties.
@@ -522,6 +546,10 @@ class QSscorer:
       self._clustalw_bin = settings.Locate(('clustalw', 'clustalw2'))
     return self._clustalw_bin
 
+  @clustalw_bin.setter
+  def clustalw_bin(self, clustalw_bin):
+    self._clustalw_bin = clustalw_bin
+
   def GetOligoLDDTScorer(self, settings, penalize_extra_chains=True):
     """
     :return: :class:`OligoLDDTScorer` object, setup for this QS scoring problem.
diff --git a/modules/mol/alg/tests/test_qsscoring.py b/modules/mol/alg/tests/test_qsscoring.py
index 29aaa6210..0e57f2a3e 100644
--- a/modules/mol/alg/tests/test_qsscoring.py
+++ b/modules/mol/alg/tests/test_qsscoring.py
@@ -167,8 +167,7 @@ class TestQSscore(unittest.TestCase):
     # enforce different chain mapping
     enforced_cm = {'C': 'C', 'E': 'A', 'D': 'D', 'F': 'B'}
     qs_scorer_2 = QSscorer(qs_scorer.qs_ent_1, qs_scorer.qs_ent_2)
-    # directly overwrite variable intended to be private. Have mercy with me.
-    qs_scorer_2._chain_mapping = enforced_cm
+    qs_scorer_2.chain_mapping = enforced_cm
     self.assertAlmostEqual(qs_scorer_2.global_score, 0.356, 2)
     self.assertAlmostEqual(qs_scorer_2.best_score, 0.419, 2)
     self.assertEqual(qs_scorer_2.chain_mapping, enforced_cm)
-- 
GitLab