From bd89422654f2af297ccce699297393ff92e96a4a Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Wed, 3 Jul 2024 10:02:45 +0200
Subject: [PATCH] bugfix: avoid setting n_ter/c_ter generic properties in
 TopologyCreator

This may cause trouble for downstream applications when called on the same
entity several times. The result may be a generic property that marks a
terminal residue which is not terminal anymore because the entity has been
updated. This leads to a crash in the parameterization stage.
---
 modules/mol/mm/src/topology_creator.cc | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/modules/mol/mm/src/topology_creator.cc b/modules/mol/mm/src/topology_creator.cc
index 00ba0738d..9f0222b9c 100644
--- a/modules/mol/mm/src/topology_creator.cc
+++ b/modules/mol/mm/src/topology_creator.cc
@@ -88,7 +88,8 @@ TopologyPtr TopologyCreator::Create(ost::mol::EntityHandle& ent,
   //this should be enough for most needs
 
   ost::mol::ResidueHandle next,prev;
-  bool n_ter,c_ter; 
+  bool n_ter, c_ter;
+  std::set<unsigned long> n_ter_residues, c_ter_residues;
   ost::mol::AtomHandle peptide_n,peptide_c,nucleotide_p,nucleotide_o; 
 
   for(ost::mol::ResidueHandleList::iterator i = res_list.begin(); 
@@ -133,8 +134,8 @@ TopologyPtr TopologyCreator::Create(ost::mol::EntityHandle& ent,
       }
     }
 
-    if(n_ter) i->SetBoolProp("n_ter",true);
-    if(c_ter) i->SetBoolProp("c_ter",true);
+    if(n_ter) n_ter_residues.insert(i->GetHashCode());
+    if(c_ter) c_ter_residues.insert(i->GetHashCode());
   }
 
 
@@ -181,7 +182,7 @@ TopologyPtr TopologyCreator::Create(ost::mol::EntityHandle& ent,
       }
     }
     //check for n terminus
-    if(i->HasProp("n_ter")){
+    if(n_ter_residues.find(i->GetHashCode()) != n_ter_residues.end()){
       String exception_name = "";
       if(settings->termini_exceptions->HasException(*i)){
         exception_name = settings->termini_exceptions->GetException(*i);
@@ -193,7 +194,7 @@ TopologyPtr TopologyCreator::Create(ost::mol::EntityHandle& ent,
         block->RemoveInteractionsToPrev();
       }
     }
-    if(i->HasProp("c_ter")){
+    if(c_ter_residues.find(i->GetHashCode()) != c_ter_residues.end()){
       String exception_name = "";
       if(settings->termini_exceptions->HasException(*i)){
         exception_name = settings->termini_exceptions->GetException(*i);
-- 
GitLab