From 887f8fdae8769c4252782b49f7e4ac9df0885bd1 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavier.robin@unibas.ch>
Date: Wed, 14 Feb 2024 13:41:05 +0100
Subject: [PATCH] test: fix check_resname test

This test was relying on a "bad" alignment between two essentially
unrelated chains. This is no longer happening after the replacement of
GlobalAlign by SemiGlobal in commit ddfa2ab5, and the chains no longer
align meaningfully. As a result no residue names were mismatching, as
the representation of the binding site in the model no longer existed.

We removed this assumption and only replace a single residue in the
entity. This avoids depending on an alignment in this test.
---
 modules/mol/alg/tests/test_ligand_scoring.py | 22 +++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/modules/mol/alg/tests/test_ligand_scoring.py b/modules/mol/alg/tests/test_ligand_scoring.py
index 84abfb48c..df2cd5287 100644
--- a/modules/mol/alg/tests/test_ligand_scoring.py
+++ b/modules/mol/alg/tests/test_ligand_scoring.py
@@ -313,20 +313,28 @@ class TestLigandScoring(unittest.TestCase):
         self.assertTrue(np.isnan(sc.lddt_pli_matrix[6, 0]))
 
     def test_check_resnames(self):
-        """Test check_resname argument works
+        """Test that the check_resname argument works.
+
+        When set to True, it should raise an error if any residue in the
+        representation of the binding site in the model has a different
+        name than in the reference. Here we manually modify a residue
+        name to achieve that effect.
         """
-        # 4C0A has mismatching sequence and fails with check_resnames=True
-        mdl_1r8q = _LoadMMCIF("1r8q.cif.gz")
         trg_4c0a = _LoadMMCIF("4c0a.cif.gz")
-
-        mdl = mdl_1r8q.Select("cname=D or cname=F")
         trg = trg_4c0a.Select("cname=C or cname=I")
 
+        # Here we modify the name of a residue in 4C0A (THR => TPO in C.15)
+        # This residue is in the binding site and should trigger the error
+        mdl = ost.mol.CreateEntityFromView(trg, include_exlusive_atoms=False)
+        ed = mdl.EditICS()
+        ed.RenameResidue(mdl.FindResidue("C", 15), "TPO")
+        ed.UpdateXCS()
+
         with self.assertRaises(RuntimeError):
-            sc = LigandScorer(mdl, trg, [mdl.FindResidue("F", 1)], [trg.FindResidue("I", 1)], check_resnames=True)
+            sc = LigandScorer(mdl, trg, [mdl.FindResidue("I", 1)], [trg.FindResidue("I", 1)], check_resnames=True)
             sc._compute_scores()
 
-        sc = LigandScorer(mdl, trg, [mdl.FindResidue("F", 1)], [trg.FindResidue("I", 1)], check_resnames=False)
+        sc = LigandScorer(mdl, trg, [mdl.FindResidue("I", 1)], [trg.FindResidue("I", 1)], check_resnames=False)
         sc._compute_scores()
 
     def test__scores(self):
-- 
GitLab