From 548fe6d92e90b105fad3a8f3b24b9ff47c395241 Mon Sep 17 00:00:00 2001
From: B13nch3n <stefan.bienert@me.com>
Date: Thu, 16 Jul 2020 15:08:39 +0200
Subject: [PATCH] Removed the need for an Editor from connecting branched
 entities out of mmCIFInfo

---
 modules/io/src/mol/mmcif_info.cc    | 15 +++++++++------
 modules/io/src/mol/mmcif_info.hh    |  2 +-
 modules/io/tests/test_io_mmcif.py   |  2 +-
 modules/io/tests/test_mmcif_info.cc |  2 +-
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/modules/io/src/mol/mmcif_info.cc b/modules/io/src/mol/mmcif_info.cc
index af1e72588..c797a14f8 100644
--- a/modules/io/src/mol/mmcif_info.cc
+++ b/modules/io/src/mol/mmcif_info.cc
@@ -225,16 +225,19 @@ const std::vector<MMCifInfoEntityBranch> MMCifInfo::GetEntityBranchLinks() const
   return all_links;
 }
 
-void MMCifInfo::ConnectBranchLinks(mol::XCSEditor editor)
+void MMCifInfo::ConnectBranchLinks()
 {
   MMCifInfoEntityBranchMap::iterator blm_it;
   for (blm_it = entity_branches_.begin();
        blm_it != entity_branches_.end(); ++blm_it) {
-    for (std::vector<MMCifInfoEntityBranch>::iterator blv_it =
-           blm_it->second.begin();
-         blv_it != blm_it->second.end();
-         ++blv_it) {
-      blv_it->ConnectBranchLink(editor);
+    // We assume that one chain only comes from one entity, so we go with one
+    // editor per chain
+    std::vector<MMCifInfoEntityBranch>::iterator blv_it = blm_it->second.begin();
+    if (blv_it != blm_it->second.end()) {
+      mol::XCSEditor editor = blv_it->GetAtom1().GetEntity().EditXCS();
+      for (; blv_it != blm_it->second.end(); ++blv_it) {
+        blv_it->ConnectBranchLink(editor);
+      }
     }
   }
 }
diff --git a/modules/io/src/mol/mmcif_info.hh b/modules/io/src/mol/mmcif_info.hh
index 5dfffb201..4e5e62a9d 100644
--- a/modules/io/src/mol/mmcif_info.hh
+++ b/modules/io/src/mol/mmcif_info.hh
@@ -1179,7 +1179,7 @@ public:
 
   /// \brief Connect all atoms listed as links for branched entities.
   ///
-  void ConnectBranchLinks(mol::XCSEditor editor);
+  void ConnectBranchLinks();
 
 //protected:
 
diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py
index 72d84658d..8f850f55e 100644
--- a/modules/io/tests/test_io_mmcif.py
+++ b/modules/io/tests/test_io_mmcif.py
@@ -294,7 +294,7 @@ class TestMMCifInfo(unittest.TestCase):
     self.assertEqual(blinks[1].atom1.qualified_name, "B.NAG2.C1")
     self.assertEqual(blinks[1].GetAtom2().qualified_name, "B.NAG1.O4")
 
-    info.ConnectBranchLinks(editor)
+    info.ConnectBranchLinks()
     self.assertEqual(atom4.GetBondPartners()[0].qualified_name, "B.NAG2.C1")
 
 if __name__== '__main__':
diff --git a/modules/io/tests/test_mmcif_info.cc b/modules/io/tests/test_mmcif_info.cc
index 25fccecea..6265eba1d 100644
--- a/modules/io/tests/test_mmcif_info.cc
+++ b/modules/io/tests/test_mmcif_info.cc
@@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(mmcif_info)
   BOOST_CHECK(blinks[1].GetAtom2().GetQualifiedName() == "B.BMA1.O3");
 
   // check that branch links get bonds
-  info.ConnectBranchLinks(editor);
+  info.ConnectBranchLinks();
 
   BOOST_CHECK(atom11.GetBondPartners()[0] == atom12);
   BOOST_CHECK(atom22.GetBondPartners()[0] == atom21);
-- 
GitLab