From 9f0fc39fa963609d070535bf5887d5a86d2731f6 Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Tue, 21 Sep 2010 12:34:42 +0000
Subject: [PATCH] introduce protein/water property at the residue level

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2713 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/conop/src/chemdict_tool.cc        | 16 +++++++++++-----
 modules/conop/src/heuristic_builder.cc    | 11 +++++++++--
 modules/conop/src/rule_based_builder.cc   |  2 ++
 modules/mol/base/src/chem_class.hh        |  3 +++
 modules/mol/base/src/impl/residue_impl.hh |  7 ++++++-
 modules/mol/base/src/property_id.cc       |  8 +++++++-
 modules/mol/base/src/property_id.hh       |  3 ++-
 modules/mol/base/src/query_state.cc       | 10 +++++++++-
 modules/mol/base/src/residue_base.cc      | 12 ++++++++++++
 modules/mol/base/src/residue_base.hh      |  6 +++++-
 modules/mol/base/src/residue_handle.hh    |  2 +-
 11 files changed, 67 insertions(+), 13 deletions(-)

diff --git a/modules/conop/src/chemdict_tool.cc b/modules/conop/src/chemdict_tool.cc
index 156b7f2d1..8671b4fa4 100644
--- a/modules/conop/src/chemdict_tool.cc
+++ b/modules/conop/src/chemdict_tool.cc
@@ -122,13 +122,19 @@ public:
         for (String::iterator i=type.begin(), e=type.end(); i!=e; ++i) {
           *i=toupper(*i);
         }
-        std::map<String, mol::ChemClass>::iterator i=tm_.find(type);
-        if (i!=tm_.end()) {
-          compound_->SetChemClass(i->second);          
+        // The type of water is set to "?". let's change it to water...
+        if (compound_->GetID()=="HOH") {
+          compound_->SetChemClass(mol::ChemClass(mol::ChemClass::Water));
         } else {
-          std::cout << "unknown type '" << type << "' for compound " 
-                    << compound_->GetID() << std::endl;
+          std::map<String, mol::ChemClass>::iterator i=tm_.find(type);
+          if (i!=tm_.end()) {
+            compound_->SetChemClass(i->second);          
+          } else {
+            std::cout << "unknown type '" << type << "' for compound " 
+                      << compound_->GetID() << std::endl;
+          }        
         }
+
       } else if (item.GetName()==StringRef("formula", 7)) {
         compound_->SetFormula(item.GetValue().str());
       } else if (item.GetName()==StringRef("one_letter_code", 15)) {
diff --git a/modules/conop/src/heuristic_builder.cc b/modules/conop/src/heuristic_builder.cc
index 5429a5697..bb4a63a22 100644
--- a/modules/conop/src/heuristic_builder.cc
+++ b/modules/conop/src/heuristic_builder.cc
@@ -309,11 +309,18 @@ void ConnectPrevNext(HeuristicBuilder* builder,mol::ResidueHandle res0,
     if(res0_atom && res1_atom) {
       LOG_DEBUG(fname << ": found atoms, connecting");
       if(flag) {
-        if (builder->DoesPeptideBondExist(res0_atom, res1_atom))
+        if (builder->DoesPeptideBondExist(res0_atom, res1_atom)) {
           editor.Connect(res0_atom,res1_atom);
+          res0.SetIsProtein(true);
+          res1.SetIsProtein(true);
+        }
       } else {
-        if (builder->DoesPeptideBondExist(res1_atom, res0_atom))
+        if (builder->DoesPeptideBondExist(res1_atom, res0_atom)) {
           editor.Connect(res1_atom, res0_atom);
+          res0.SetIsProtein(true);
+          res1.SetIsProtein(true);
+        }
+
       }
     }
   } else {
diff --git a/modules/conop/src/rule_based_builder.cc b/modules/conop/src/rule_based_builder.cc
index 755d03dd5..3353dfb46 100644
--- a/modules/conop/src/rule_based_builder.cc
+++ b/modules/conop/src/rule_based_builder.cc
@@ -202,6 +202,8 @@ void RuleBasedBuilder::ConnectResidueToNext(mol::ResidueHandle rh,
   // the peptide bond.
   if (c.IsValid() && n.IsValid() && this->DoesPeptideBondExist(c, n)) {
     e.Connect(c, n, 1);
+    rh.SetIsProtein(true);
+    next.SetIsProtein(true);
   }
 }
 
diff --git a/modules/mol/base/src/chem_class.hh b/modules/mol/base/src/chem_class.hh
index b7740a942..f9c0f8279 100644
--- a/modules/mol/base/src/chem_class.hh
+++ b/modules/mol/base/src/chem_class.hh
@@ -37,6 +37,7 @@ struct ChemClass {
   const static char LSaccharide     ='X';
   const static char DSaccharide     ='Y';    
   const static char Saccharide      ='Z';
+  const static char Water           ='W';
   const static char Unknown         ='U';
   explicit ChemClass(char chem_class)
     : chem_class_(chem_class) {
@@ -62,6 +63,8 @@ struct ChemClass {
     return (chem_class_==ChemClass::DNALinking || 
             chem_class_==ChemClass::RNALinking);
   }
+  
+  bool IsWater() const { return chem_class_==ChemClass::Water; }
   operator char() const {
     return chem_class_;
   }
diff --git a/modules/mol/base/src/impl/residue_impl.hh b/modules/mol/base/src/impl/residue_impl.hh
index 0e0393767..183a9ccef 100644
--- a/modules/mol/base/src/impl/residue_impl.hh
+++ b/modules/mol/base/src/impl/residue_impl.hh
@@ -199,6 +199,9 @@ public:
   
   int GetIntProperty(Prop::ID prop_id) const;
   
+  void SetProtein(bool protein) { protein_=protein; }
+  
+  bool IsProtein() const { return protein_; }
 private:
   void AddAltAtom(const String& group, const AtomImplPtr& atom,
                   const geom::Vec3& position);
@@ -207,13 +210,15 @@ private:
   AtomEntryGroups            alt_groups_;
   EntityImplW                ent_;
   ChainImplW                 chain_;
-  ResNum              num_;
+  ResNum                     num_;
   ResidueKey                 key_;
   AtomImplList               atom_list_;
   TorsionImplList            torsion_list_;
   SecStructure               sec_structure_;
   ChemClass                  chem_class_;
   char                       olc_;
+  // whether the residue is part of the protein.
+  bool                       protein_;
 };
 
 }}} // ns
diff --git a/modules/mol/base/src/property_id.cc b/modules/mol/base/src/property_id.cc
index ed19a4f3e..a6408b83e 100644
--- a/modules/mol/base/src/property_id.cc
+++ b/modules/mol/base/src/property_id.cc
@@ -49,7 +49,9 @@ struct Properties : public boost::spirit::symbols<Prop> {
       ("abfac", Prop(Prop::ABFAC, Prop::FLOAT, Prop::ATOM))
       ("rbfac", Prop(Prop::RBFAC, Prop::FLOAT, Prop::RESIDUE))
       ("peptide", Prop(Prop::PEPTIDE, Prop::INT, Prop::RESIDUE))
-      ("rindex", Prop(Prop::RINDEX, Prop::INT, Prop::RESIDUE))      
+      ("rindex", Prop(Prop::RINDEX, Prop::INT, Prop::RESIDUE))
+      ("protein", Prop(Prop::PROTEIN, Prop::INT, Prop::RESIDUE))
+      ("water", Prop(Prop::WATER, Prop::INT, Prop::RESIDUE))
       ("acharge", Prop(Prop::ACHARGE, Prop::FLOAT, Prop::ATOM));
   }
 } properties;
@@ -112,6 +114,10 @@ String Prop::GetName() const
       return "acharge";
     case RINDEX:
       return "rindex";
+    case PROTEIN:
+      return "protein";
+    case WATER:
+      return "water";
     default:
       return "";
   }
diff --git a/modules/mol/base/src/property_id.hh b/modules/mol/base/src/property_id.hh
index dfc984bc2..4ea4be13f 100644
--- a/modules/mol/base/src/property_id.hh
+++ b/modules/mol/base/src/property_id.hh
@@ -40,7 +40,8 @@ public:
   /// respectively.
   typedef enum {
     RNAME, ANAME, CNAME, ELE, RNUM, ANUM, AX, AY, AZ, OCC, RTYPE, ISHETATM,
-    RBFAC, ABFAC, PEPTIDE, ACHARGE, RINDEX, WITHIN, UNDEF, CUSTOM
+    RBFAC, ABFAC, PEPTIDE, ACHARGE, RINDEX, PROTEIN, WATER, WITHIN, 
+    UNDEF, CUSTOM
   } ID;
   
   typedef enum {
diff --git a/modules/mol/base/src/query_state.cc b/modules/mol/base/src/query_state.cc
index c84670d78..95dc07e16 100644
--- a/modules/mol/base/src/query_state.cc
+++ b/modules/mol/base/src/query_state.cc
@@ -198,7 +198,7 @@ boost::logic::tribool QueryState::EvalResidue(const impl::ResidueImplPtr& r) {
         s_[*i]=cmp_num<int>(ss.comp_op,int_value,boost::get<int>(ss.param));        
         break;
       case Prop::PEPTIDE:
-        int_value=r->GetChemClass().IsPeptideLinking() ? 1 : 0;
+        int_value=r->GetChemClass().IsPeptideLinking();
         s_[*i] = cmp_num<int>(ss.comp_op,int_value,boost::get<int>(ss.param));        
         break;        
       case Prop::RBFAC:
@@ -209,6 +209,14 @@ boost::logic::tribool QueryState::EvalResidue(const impl::ResidueImplPtr& r) {
         s_[*i] = cmp_num<Real>(ss.comp_op, float_value,
                                  boost::get<float>(ss.param));        
         break;
+      case Prop::PROTEIN:
+        int_value=r->IsProtein();
+        s_[*i]=cmp_num<int>(ss.comp_op,int_value,boost::get<int>(ss.param));
+        break;
+      case Prop::WATER:
+        int_value=r->GetChemClass().IsWater();
+        s_[*i]=cmp_num<int>(ss.comp_op,int_value,boost::get<int>(ss.param));
+        break;
       case Prop::RTYPE:
         p=boost::get<String>(ss.param);
         if (p.length()>1) {
diff --git a/modules/mol/base/src/residue_base.cc b/modules/mol/base/src/residue_base.cc
index f4ce54ee5..9ae05d783 100644
--- a/modules/mol/base/src/residue_base.cc
+++ b/modules/mol/base/src/residue_base.cc
@@ -181,5 +181,17 @@ int ResidueBase::GetIntProperty(Prop::ID prop_id) const
   return Impl()->GetIntProperty(prop_id);
 }
 
+bool ResidueBase::IsProtein() const
+{
+  this->CheckValidity();
+  return Impl()->IsProtein();
+}
+
+void ResidueBase::SetIsProtein(bool protein)
+{
+  this->CheckValidity();
+  Impl()->SetProtein(protein);
+}
+
 }}
 
diff --git a/modules/mol/base/src/residue_base.hh b/modules/mol/base/src/residue_base.hh
index 69749ed49..1ad743879 100644
--- a/modules/mol/base/src/residue_base.hh
+++ b/modules/mol/base/src/residue_base.hh
@@ -139,7 +139,11 @@ public:
   
   /// \brief Get int property by id
   int GetIntProperty(Prop::ID prop_id) const;
-    
+  
+  /// \brief whether the residue is part of the protein.
+  bool IsProtein() const;
+  
+  void SetIsProtein(bool protein);
 public:
   impl::ResidueImplPtr& Impl();
 
diff --git a/modules/mol/base/src/residue_handle.hh b/modules/mol/base/src/residue_handle.hh
index 57b7c5619..f1eb07850 100644
--- a/modules/mol/base/src/residue_handle.hh
+++ b/modules/mol/base/src/residue_handle.hh
@@ -197,7 +197,7 @@ public:
   /// \brief return view based on query String.
   /// \sa Query
   EntityView Select(const String& query_string, QueryFlags flags=0) const;
-
+    
   bool operator==(const ResidueHandle& ref) const;
   bool operator!=(const ResidueHandle& ref) const;
   
-- 
GitLab