From 896a60cc827d038983e85fa02764b4fe01bd0774 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavalias-github@xavier.robin.name>
Date: Tue, 24 Jan 2023 17:29:05 +0100
Subject: [PATCH] fix: SCHWED-5783 add bonds to copied ligand

---
 modules/mol/alg/pymod/ligand_scoring.py      | 5 +++++
 modules/mol/alg/tests/test_ligand_scoring.py | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/modules/mol/alg/pymod/ligand_scoring.py b/modules/mol/alg/pymod/ligand_scoring.py
index 2149af916..d52fbc60c 100644
--- a/modules/mol/alg/pymod/ligand_scoring.py
+++ b/modules/mol/alg/pymod/ligand_scoring.py
@@ -258,6 +258,11 @@ class LigandScorer:
                 new_chain = new_editor.InsertChain(handle.chain.name)
             # Add the residue with its original residue number
             new_res = new_editor.AppendResidue(new_chain, handle, deep=True)
+            for old_atom in handle.atoms:
+                for old_bond in old_atom.bonds:
+                    new_first = new_res.FindAtom(old_bond.first.name)
+                    new_second = new_res.FindAtom(old_bond.second.name)
+                    new_editor.Connect(new_first, new_second)
             return new_res
 
         def _process_ligand_residue(res):
diff --git a/modules/mol/alg/tests/test_ligand_scoring.py b/modules/mol/alg/tests/test_ligand_scoring.py
index 78f4b1275..4bff9e812 100644
--- a/modules/mol/alg/tests/test_ligand_scoring.py
+++ b/modules/mol/alg/tests/test_ligand_scoring.py
@@ -232,7 +232,8 @@ class TestLigandScoring(unittest.TestCase):
         """
         trg, trg_seqres = io.LoadMMCIF(os.path.join('testfiles', "1r8q.cif.gz"), seqres=True)
         mdl, mdl_seqres = io.LoadMMCIF(os.path.join('testfiles', "P84080_model_02.cif.gz"), seqres=True)
-        sc = LigandScorer(mdl, trg, None, None)
+        mdl_lig = io.LoadEntity(os.path.join('testfiles', "P84080_model_02_ligand_0.sdf"))
+        sc = LigandScorer(mdl, trg, [mdl_lig], None)
 
         # Note: expect warning about Binding site of H.ZN1 not mapped to the model
         sc._compute_scores()
@@ -246,7 +247,7 @@ class TestLigandScoring(unittest.TestCase):
             [np.inf],
             [np.inf],
             [0.29399303],
-            [np.inf]]))
+            [np.inf]]), decimal=5)
 
         # Check lDDT-PLI
         self.assertEqual(sc.lddt_pli_matrix.shape, (7, 1))
-- 
GitLab