From 54decf4b6c0098a71978f6b6364c2456767c4326 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Fri, 13 Jan 2012 17:17:18 -0500
Subject: [PATCH] Corrected the function to set the residue number of a residue
 in the editor to check for breaking of the in_sequence property. Added an
 SetInSequence() function to the ChainHandle to check and update the
 in_sequence property

---
 CMakeLists.txt                          |  2 +-
 modules/io/pymod/wrap_io.cc             |  1 -
 modules/mol/base/src/chain_handle.cc    |  6 ++++++
 modules/mol/base/src/chain_handle.hh    |  4 +++-
 modules/mol/base/src/editor_base.cc     |  2 ++
 modules/mol/base/src/impl/chain_impl.cc | 15 +++++++++++++++
 modules/mol/base/src/impl/chain_impl.hh |  5 ++++-
 7 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 306445073..e438e4cb4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -242,4 +242,4 @@ message(STATUS
         "   Compound Lib                   (-DCOMPOUND_LIB) : ${_COMP_LIB}\n"
         "   TMAlign and TMScore         (-DCOMPILE_TMTOOLS) : ${_TM_TOOLS}\n"
         "   Static Libraries              (-DENABLE_STATIC) : ${ENABLE_STATIC}\n"
-        "   Debian-style 'libexec' (-DDEBIAN_STYLE_LIBEXEC) : ${_DEBIAN_STYLE_LIBEXEC}")
\ No newline at end of file
+        "   Debian-style 'libexec' (-DDEBIAN_STYLE_LIBEXEC) : ${_DEBIAN_STYLE_LIBEXEC}")
diff --git a/modules/io/pymod/wrap_io.cc b/modules/io/pymod/wrap_io.cc
index 53ba11f7c..bc10f6f6a 100644
--- a/modules/io/pymod/wrap_io.cc
+++ b/modules/io/pymod/wrap_io.cc
@@ -113,7 +113,6 @@ BOOST_PYTHON_MODULE(_ost_io)
   def("LoadCRD", &LoadCRD);
   def("LoadCHARMMTraj_", &LoadCHARMMTraj, (arg("ent"), arg("trj_filename"), 
       arg("stride")=1, arg("lazy_load")=false));
-
   def("LoadMAE", &LoadMAE);
 
   export_pdb_io();
diff --git a/modules/mol/base/src/chain_handle.cc b/modules/mol/base/src/chain_handle.cc
index 9ff209e35..c1e745f2c 100644
--- a/modules/mol/base/src/chain_handle.cc
+++ b/modules/mol/base/src/chain_handle.cc
@@ -251,5 +251,11 @@ EntityView ChainHandle::Select(const String& q, QueryFlags flags) const {
   else return this->GetEntity().Select(Query("cname='"+Impl()->GetName()+"'"), flags);
 }
 
+void ChainHandle::SetInSequence(const int index)
+{
+  this->CheckValidity();    
+  Impl()->SetInSequence(index);
+}
+
 }}
 
diff --git a/modules/mol/base/src/chain_handle.hh b/modules/mol/base/src/chain_handle.hh
index 576c4b671..8f88c6e37 100644
--- a/modules/mol/base/src/chain_handle.hh
+++ b/modules/mol/base/src/chain_handle.hh
@@ -193,7 +193,9 @@ public:
   bool operator==(const ChainHandle& ref) const;
   bool operator!=(const ChainHandle& ref) const;
 
-
+  /// \brief checks whether res breaks the in sequence property
+  ///        and updates it accordingly
+  void SetInSequence(const int index);
 };
 
 }} // ns
diff --git a/modules/mol/base/src/editor_base.cc b/modules/mol/base/src/editor_base.cc
index 6757c2af6..e9fed6874 100644
--- a/modules/mol/base/src/editor_base.cc
+++ b/modules/mol/base/src/editor_base.cc
@@ -79,7 +79,9 @@ void EditorBase::RenameResidue(ResidueHandle res, const String& new_name)
 void EditorBase::SetResidueNumber(ResidueHandle res, const ResNum& new_num)
 {
   CheckHandleValidity(res);
+  int index=res.GetIndex();
   res.Impl()->SetNumber(new_num);
+  res.GetChain().SetInSequence(index);
 }
   
 void EditorBase::RenameChain(ChainHandle chain, const String& new_name)
diff --git a/modules/mol/base/src/impl/chain_impl.cc b/modules/mol/base/src/impl/chain_impl.cc
index 460269020..5ac2b91ab 100644
--- a/modules/mol/base/src/impl/chain_impl.cc
+++ b/modules/mol/base/src/impl/chain_impl.cc
@@ -484,4 +484,19 @@ void ChainImpl::ReorderResidues()
   UpdateShifts();
 }
 
+void ChainImpl::SetInSequence(const int index)
+{
+  ResNum num=residue_list_[index]->GetNumber();
+  //Check if rp is in sequence
+  if (in_sequence_) {
+    if (index>0 && residue_list_[index-1]->GetNumber()>=num)
+      in_sequence_=false;
+    if (index<static_cast<int>(residue_list_.size())-1 && residue_list_[index+1]->GetNumber()<=num)
+      in_sequence_=false;
+  }
+  if (in_sequence_) {
+    this->UpdateShifts();
+  }
+}
+  
 }}} // ns
diff --git a/modules/mol/base/src/impl/chain_impl.hh b/modules/mol/base/src/impl/chain_impl.hh
index 1f871d504..8e99792dd 100644
--- a/modules/mol/base/src/impl/chain_impl.hh
+++ b/modules/mol/base/src/impl/chain_impl.hh
@@ -175,7 +175,10 @@ public:
                                 const ResNum& start,
                                 const ResNum& end); 
   int GetIndexForResNum(const ResNum& number) const;
-  
+  ///\brief checks if the residue with that index breaks the in_sequence
+  ///       property and updates it accordingly      
+  void SetInSequence(int index);
+
 private:
   int GetIndexForResNumInSequence(const ResNum& number) const;
   void UpdateShifts();
-- 
GitLab