diff --git a/modules/conop/pymod/export_builder.cc b/modules/conop/pymod/export_builder.cc deleted file mode 100644 index 1897983f90b7c4065316633db738732c0ba4b93f..0000000000000000000000000000000000000000 --- a/modules/conop/pymod/export_builder.cc +++ /dev/null @@ -1,65 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#include <boost/python.hpp> -using namespace boost::python; -#include <ost/conop/builder.hh> -#include <ost/conop/heuristic_builder.hh> -#include <ost/conop/rule_based_builder.hh> - -using namespace ost::conop; - -void export_Builder() { - - enum_<Dialect>("Dialect") - .value("PDB_DIALECT", PDB_DIALECT) - .value("CHARMM_DIALECT", CHARMM_DIALECT) - .export_values() - ; - //TODO Export virtual calls as Default* (see export_visitor.cc) - class_<Builder>("Builder", no_init) - .add_property("dialect", &Builder::GetDialect, &Builder::SetDialect) - .add_property("strict_hydrogens", &Builder::GetStrictHydrogenMode, - &Builder::SetStrictHydrogenMode) - .add_property("bond_feasibility_check", &Builder::GetBondFeasibilityCheck, - &Builder::SetBondFeasibilityCheck) - .def("GetDialect", &Builder::GetDialect) - .def("SetDialect", &Builder::SetDialect) - .def("CompleteAtoms", &Builder::CompleteAtoms) - .def("CheckResidueCompleteness", &Builder::CheckResidueCompleteness) - .def("IdentifyResidue", &Builder::IdentifyResidue) - .def("ConnectAtomsOfResidue", &Builder::ConnectAtomsOfResidue) - .def("ConnectResidueToNext", &Builder::ConnectResidueToNext) - .def("ConnectResidueToPrev", &Builder::ConnectResidueToPrev) - .def("AssignTorsions", &Builder::AssignTorsions) - .def("AssignTorsionsToResidue", &Builder::AssignTorsionsToResidue) - .def("FillAtomProps", &Builder::FillAtomProps) - .def("IsResidueComplete", &Builder::IsResidueComplete) - .def("SetBondFeasibilityFlag", &Builder::SetBondFeasibilityCheck) - .def("GetBondFeasibilityFlag", &Builder::GetBondFeasibilityCheck) - ; - - class_<HeuristicBuilder, bases<Builder> >("HeuristicBuilder", init<>()) - ; - class_<RuleBasedBuilder, bases<Builder> >("RuleBasedBuilder", - init<const CompoundLibPtr&>()) - .add_property("compound_lib", &RuleBasedBuilder::GetCompoundLib) - .def("GetUnknownAtoms", &RuleBasedBuilder::GetUnknownAtoms) - - ; -} diff --git a/modules/conop/src/builder.cc b/modules/conop/src/builder.cc deleted file mode 100644 index 0a24cf56fa398f19fb61e6a37d181e2fbd5ebb95..0000000000000000000000000000000000000000 --- a/modules/conop/src/builder.cc +++ /dev/null @@ -1,246 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#include "builder.hh" - -/* - Author: Marco Biasini - */ - -namespace ost { namespace conop { - -Builder::~Builder() {} - -void Builder::CompleteAtoms(mol::ResidueHandle rh) {} - -void Builder::CheckResidueCompleteness(const mol::ResidueHandle& rh) {} - -mol::ResidueKey Builder::IdentifyResidue(const mol::ResidueHandle& rh) { - return mol::ResidueKey(); -} -void Builder::FillResidueProps(mol::ResidueHandle residue){}; -void Builder::ConnectAtomsOfResidue(mol::ResidueHandle rh) {} - -void Builder::ConnectResidueToPrev(mol::ResidueHandle rh, - mol::ResidueHandle p) { - this->ConnectResidueToNext(p, rh); -} - -bool Builder::IsResidueComplete(const mol::ResidueHandle& rh) -{ - return true; -} - -void Builder::ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle n) {} - -void Builder::AssignTorsions(mol::ChainHandle ch) {} -void Builder::AssignTorsionsToResidue(mol::ResidueHandle rh) {} - -void Builder::FillAtomProps(mol::AtomHandle atom) {} - -bool Builder::DoesPeptideBondExist(const mol::AtomHandle& n, - const mol::AtomHandle& c) -{ - return this->IsBondFeasible(n, c); -} - -bool Builder::IsBondFeasible(const mol::AtomHandle& atom_a, - const mol::AtomHandle& atom_b) -{ - Real radii=0.0; - if (atom_a.GetRadius()>0.0) { - radii=atom_a.GetRadius(); - } else { - return false; - } - if (atom_b.GetRadius()>0.0) { - radii+=atom_b.GetRadius(); - } else { - return false; - } - Real len=geom::Length2(atom_a.GetPos()-atom_b.GetPos()); - Real lower_bound=radii*radii*0.0625; - Real upper_bound=lower_bound*6.0; - return (len<=upper_bound && len>=lower_bound); -} - -String Builder::GuessAtomElement(const String& aname, bool hetatm) -{ - static String l1[] = { - "H","C","N","O","P","S","K" - }; - static int l1c=7; - static String l2[] = { - "NA","MG","AL","SI","CL", - "CA","CR","MN","FE","CO","NI","CU","ZN","AS","SE","BR","MO" - }; - static int l2c=17; - static String l3[] = { - "B","F","V" - }; - static int l3c=3; - static String l4[] = { - "HE","LI","BE","AR","SC","TI","GA","GE","KR" - }; - static int l4c=9; - - String ele=aname.substr(0,2); - // hydrogen hack - if(ele[0]=='H') { - return "H"; - } - if (hetatm==false) { - if (ele=="CA" || ele=="CB") { - return "C"; - } - } - - // two characters - if(aname.size()==2) { - for(int i=0;i<l2c;i++) { - if(ele==l2[i]) return ele; - } - // check second character for match - for(int i=0;i<l1c;i++) { - if(ele[1]==l1[i][0]) { - return l1[i]; - } - } - // still no match, repeat with less likely tables - for(int i=0;i<l4c;i++) { - if(ele==l4[i]) return ele; - } - // check second character for match - for(int i=0;i<l3c;i++) { - if(ele[1]==l3[i][0]) { - return l3[i]; - } - } - // check second character for match - for(int i=0;i<l1c;i++) { - if(ele[0]==l1[i][0]) { - return l1[i]; - } - } - } else { - for(int i=0;i<l1c;i++) { - if(ele==l1[i]) return ele; - } - for(int i=0;i<l3c;i++) { - if(ele==l3[i]) return ele; - } - } - size_t i=0; - while (i<aname.size() && isdigit(aname[i])) { - ++i; - } - return i<aname.size() ? String(1, aname[i]) : ""; -} - -bool Builder::AreResiduesConsecutive(const mol::ResidueHandle& r1, - const mol::ResidueHandle& r2) -{ - if (!r1 || !r2) return false; // protect against invalid handles - if(r1.GetChain() != r2.GetChain()) return false; - return r2.GetNumber().GetNum()==r1.GetNumber().GetNum()+1 || - r2.GetNumber().GetInsCode()==r1.GetNumber().NextInsertionCode().GetInsCode(); -} - -void Builder::GuessChemClass(mol::ResidueHandle res) -{ - // try peptide - res.SetChemClass(mol::ChemClass()); - mol::AtomHandle ca=res.FindAtom("CA"); - if (!ca.IsValid() || ca.GetElement()!="C") return; - mol::AtomHandle n=res.FindAtom("N"); - if (!n.IsValid() || n.GetElement()!="N") return; - mol::AtomHandle c=res.FindAtom("C"); - if (!c.IsValid() || c.GetElement()!="C") return; - mol::AtomHandle o=res.FindAtom("O"); - if (!o.IsValid() || o.GetElement()!="O") return; - if (this->IsBondFeasible(n, ca) && this->IsBondFeasible(ca, c) && - this->IsBondFeasible(c, o)) { - res.SetChemClass(mol::ChemClass(mol::ChemClass::PEPTIDE_LINKING)); - } -} - - -void Builder::AssignBackBoneTorsionsToResidue(mol::ResidueHandle res) -{ - - mol::ResidueHandle prev=res.GetPrev(); - mol::ResidueHandle next=res.GetNext(); - mol::XCSEditor e=res.GetEntity().EditXCS(mol::BUFFERED_EDIT); - //psi - if (next.IsValid() && next.IsPeptideLinking()){ - mol::AtomHandle ca_this=res.FindAtom("CA"); - mol::AtomHandle n_this=res.FindAtom("N"); - mol::AtomHandle c_this=res.FindAtom("C"); - mol::AtomHandle n_next=next.FindAtom("N"); - if ((ca_this && n_this && c_this && n_next && BondExists(c_this, n_next)) - && !res.GetPsiTorsion()) { - e.AddTorsion("PSI", n_this, ca_this, c_this, n_next); - } - }; - //phi - if (prev.IsValid() && prev.IsPeptideLinking()) { - mol::AtomHandle c_prev=prev.FindAtom("C"); - mol::AtomHandle n_this=res.FindAtom("N"); - mol::AtomHandle ca_this=res.FindAtom("CA"); - mol::AtomHandle c_this=res.FindAtom("C"); - if ((c_prev && n_this && ca_this && c_this && BondExists(c_prev, n_this)) - && !res.GetPhiTorsion()) { - e.AddTorsion("PHI", c_prev, n_this, ca_this, c_this); - } - } - //omega - if (prev.IsValid() && prev.IsPeptideLinking()) { - mol::AtomHandle ca_prev=prev.FindAtom("CA"); - mol::AtomHandle c_prev=prev.FindAtom("C"); - mol::AtomHandle n=res.FindAtom("N"); - mol::AtomHandle ca=res.FindAtom("CA"); - if ((ca_prev && c_prev && n && ca && BondExists(c_prev, n)) - && !res.GetOmegaTorsion()) { - e.AddTorsion("OMEGA",ca_prev , c_prev, n, ca); - } - } -} - - - -void Builder::DistanceBasedConnect(mol::AtomHandle atom) -{ - mol::EntityHandle ent=atom.GetEntity(); - mol::XCSEditor editor=ent.EditXCS(mol::BUFFERED_EDIT); - mol::AtomHandleList alist = ent.FindWithin(atom.GetPos(),4.0); - mol::ResidueHandle res_a=atom.GetResidue(); - for (mol::AtomHandleList::const_iterator it=alist.begin(), - e=alist.end();it!=e;++it) { - if (*it!=atom) { - if (this->IsBondFeasible(atom, *it)) { - if (Builder::AreResiduesConsecutive(res_a, it->GetResidue()) || - it->GetResidue()==res_a) { - editor.Connect(*it, atom); - } - } - } - } -} - -}} // ns diff --git a/modules/conop/src/builder.hh b/modules/conop/src/builder.hh deleted file mode 100644 index 4b915681a51d2d47c6d36fe449424f5b189de772..0000000000000000000000000000000000000000 --- a/modules/conop/src/builder.hh +++ /dev/null @@ -1,162 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_CONOP_BUILDER_HH -#define OST_CONOP_BUILDER_HH - -/* - Author: Marco Biasini - */ -#include <ost/mol/mol.hh> - -#include <ost/conop/module_config.hh> -#include <ost/conop/builder_fw.hh> - -namespace ost { namespace conop { - -typedef enum { - PDB_DIALECT, - CHARMM_DIALECT -} Dialect; -/// \brief abstract builder interface -/// -/// A builder serves several purposes: \li knows how to connect atoms of -/// residues based on their name \li is able to identify as residue based on -/// its name \li knows whether a residue has all required atoms \li assigns -/// named torsions to residues \li knows when to connect two consecutive -/// residues. -/// -/// The exact behaviour for a builder is implementation-specific. While some -/// builders implement sophisticated checks to identity residues, other builders -/// may only perform a name lookup. For two specific implementations of -/// builders, HeuristicBuilder and RuleBasedBuilder. -/// -/// Custom builders can be registered with Conopology::RegisterBuilder(). The -/// default builder is set with Conopology::SetDefaultBuilder(). Since all -/// entity loaders make use of the default builder to infer connectivity of the -/// atoms, changing the default builder can largely affect the loading -/// behaviour. -class DLLEXPORT_OST_CONOP Builder { -public: - - Builder(): dialect_(PDB_DIALECT), strict_(false), bond_feasibility_check_(true) { } - virtual ~Builder(); - - /// \brief add any missing atoms to the residue based on its key, - /// with coordinates set to zero - virtual void CompleteAtoms(mol::ResidueHandle rh); - - virtual void SetDialect(Dialect dialect) { dialect_=dialect; } - - virtual void SetStrictHydrogenMode(bool strict) { strict_=strict; } - bool GetStrictHydrogenMode() const { return strict_; } - - Dialect GetDialect() const { return dialect_; } - /// \brief verify that the given residue has all atoms it - /// is supposed to have based on its key - virtual void CheckResidueCompleteness(const mol::ResidueHandle& rh); - - /// \brief Check whether the residue has all atoms it is supposed to have - /// \todo Add hydrogen flag - virtual bool IsResidueComplete(const mol::ResidueHandle& rh); - - /// \brief attempt to identify the residue based on its atoms, and return a - /// suggestion for the proper residue key - virtual mol::ResidueKey IdentifyResidue(const mol::ResidueHandle& rh); - - /// \brief Assign (correct) residue properties - /// - /// Assign chemical class of the residue and one letter code. - virtual void FillResidueProps(mol::ResidueHandle residue); - - virtual void FillAtomProps(mol::AtomHandle atom); - /// \brief connect atoms of one residue - /// - /// Connects atoms of residue based on residue and atom name. This method does - /// not establish inter-residue bonds. To connect atoms that belong to - /// different residues, use ConnectResidueToPrev(), or ConnectResidueToNext(). - virtual void ConnectAtomsOfResidue(mol::ResidueHandle rh); - /// \brief connect atoms of residue to previous - /// - /// The order of the parameters is important. In case of a polypeptide chain, - /// the residues are thought to be ordered from N- to C- terminus. - /// - /// \sa ConnectResidueToNext - virtual void ConnectResidueToPrev(mol::ResidueHandle rh, - mol::ResidueHandle prev); - /// \sa ConnectResidueToPrev - virtual void ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle next); - - /// \brief assign named torsions to a complete chain - virtual void AssignTorsions(mol::ChainHandle ch); - - /// \brief assign named torsions to single residue - virtual void AssignTorsionsToResidue(mol::ResidueHandle residue); - - /// \brief assign Backbone torsions to single residue - void AssignBackBoneTorsionsToResidue(mol::ResidueHandle res); - - /// \brief Check if peptide bond is formed between the two atoms. - /// - /// This method is called by ConnectResidueWithNext() after making sure that - /// both residues participating in the peptide bond are peptide linking - /// components. - /// - /// By default, IsBondFeasible() is used to check whether the two atoms form - /// a peptide bond. - virtual bool DoesPeptideBondExist(const mol::AtomHandle& n, - const mol::AtomHandle& c); - - /// \brief Overloadable hook to check if bond between to atoms is feasible - /// - /// The default implementation uses a distance-based check to check if the - /// two atoms should be connected. The atoms are connected if they are in - /// the range of 0.8 to 1.2 times their van-der-WAALS radius. - virtual bool IsBondFeasible(const mol::AtomHandle& atom_a, - const mol::AtomHandle& atom_b); - - /// \brief guess element of atom based on name and hetatm flag - static String GuessAtomElement(const String& atom_name, bool hetatm); - - /// \brief whether the r1 and r2 have consecutive residue numbers - static bool AreResiduesConsecutive(const mol::ResidueHandle& r1, - const mol::ResidueHandle& r2); - /// \brief guess and assign chemical class of residue based on atoms and - /// connectivity - void GuessChemClass(mol::ResidueHandle res); - /// |brief Connect \p atom with all atoms for whith IsBondFeasible() and - /// AreResiduesConsecutive() returns true - void DistanceBasedConnect(mol::AtomHandle atom); - - /// \brief Set bond feasibility check flag - void SetBondFeasibilityCheck(bool b_feas_flag) { bond_feasibility_check_ = b_feas_flag; } - - /// \brief Get bond feasibility check flag - bool GetBondFeasibilityCheck() const { return bond_feasibility_check_; } - -private: - Dialect dialect_; - bool strict_; - bool bond_feasibility_check_; -}; - - -}} // ns - -#endif diff --git a/modules/conop/src/builder_fw.hh b/modules/conop/src/builder_fw.hh deleted file mode 100644 index c61de7becda4a9e3476a620a71da563d0c4c2f5c..0000000000000000000000000000000000000000 --- a/modules/conop/src/builder_fw.hh +++ /dev/null @@ -1,31 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_CONOP_BUILDER_FW_HH -#define OST_CONOP_BUILDER_FW_HH - -#include <boost/shared_ptr.hpp> - -namespace ost { namespace conop { - -class Builder; -typedef boost::shared_ptr<Builder> BuilderP; - -}} - -#endif diff --git a/modules/conop/src/heuristic_builder.cc b/modules/conop/src/heuristic_builder.cc deleted file mode 100644 index 07922d6a2dab0aa5fd162323749ebb4c9a4efaaa..0000000000000000000000000000000000000000 --- a/modules/conop/src/heuristic_builder.cc +++ /dev/null @@ -1,531 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#include <boost/algorithm/string/trim.hpp> - -#include <ost/log.hh> -#include <ost/geom/geom.hh> -#include "conop.hh" -#include "heuristic_builder.hh" -#include "heuristic_connect_table.hh" -#include <ost/mol/residue_handle.hh> - - -namespace ost { namespace conop { - -namespace detail { - -// internal helper class -ConnResEntry::ConnResEntry(const String& rname, char single, - const mol::ChemClass& chem_class): - rkey_(rname), - abbrev_(single), - chem_class_(chem_class), - pset_(), - prev_(""), - next_(""), - torsion_entry_list_() -{} - -int ConnResEntry::Check(const String& name1, const String& name2) const -{ - NamePair np1(name1,name2); - NamePair np2(name2,name1); - // does this pair exist? - if(pset_.find(np1)!=pset_.end()) { - return 1; - } else if(pset_.find(np2)!=pset_.end()) { - return 2; - } - - return 0; -} - -bool ConnResEntry::HasAtom(const String& name) -{ - for(PairSet::const_iterator it=pset_.begin();it!=pset_.end();++it) { - if(it->first==name || it->second==name) return true; - } - return false; -} - -// add a connection entry -void ConnResEntry::AddConn(const String& n1, const String& n2) -{ - pset_.insert(std::make_pair(n1,n2)); -} - -void ConnResEntry::AddTors(const String& a1, const String& a2, const String& a3, - const String& a4, const String& name) -{ - TorsionEntry te={{a1,a2,a3,a4},name}; - torsion_entry_list_.push_back(te); -} - -// atom that connects to previous residue in chain -void ConnResEntry::SetPrev(const String& n) -{ - prev_=n; -} - -const String& ConnResEntry::GetPrev() const -{ - return prev_; -} - -// atom that connects to next residue in chain -void ConnResEntry::SetNext(const String& n) -{ - next_=n; -} - -const String& ConnResEntry::GetNext() const -{ - return next_; -} - -ConnResEntry::TorsionEntryList ConnResEntry::GetTorsionList() const -{ - return torsion_entry_list_; -} - -} // ns - -// actual builder - -HeuristicBuilder::HeuristicBuilder(): - emap_(), - default_peptide_() -{ - int def_entry_count = sizeof(heuristic_connect::def_entry_table)/sizeof(heuristic_connect::CONN_DEF_ENTRY); - - LOG_DEBUG("importing internal connectivity tables"); - for(int ec=0;ec<def_entry_count;++ec) { - heuristic_connect::CONN_DEF_ENTRY& def_entry = heuristic_connect::def_entry_table[ec]; - detail::ConnResEntry entry(def_entry.abbrev, def_entry.single, - def_entry.chem_class); - LOG_TRACE("creating table entry for " << def_entry.abbrev); - LOG_TRACE("working on bond entries"); - for (int xx=0;xx<def_entry.name_count;++xx) { - String name=def_entry.name_list[xx]; - if (name!="OXT") - entry.AddAtom(name); - } - // first the connectivity entries - for(int cc=0;cc<def_entry.conn_count;++cc) { - int conn_id[] = {def_entry.conn_list[cc][0],def_entry.conn_list[cc][1]}; - String conn_nam[] = {"",""}; - bool special=false; - for(int cid=0;cid<2;++cid) { - if(conn_id[cid]>0) { - conn_nam[cid]=def_entry.name_list[conn_id[cid]-1]; - } else if (conn_id[cid]==-2) { - // PREV key - conn_nam[cid]="-"; - special=true; - } else if (conn_id[cid]==-3) { - // NEXT key - conn_nam[cid]="+"; - special=true; - } else { - // ignore - continue; - } - } - if(special) { - if(conn_nam[0]==String("-")) { entry.SetPrev(conn_nam[1]);} - else if(conn_nam[1]==String("-")) { entry.SetPrev(conn_nam[0]);} - else if(conn_nam[0]==String("+")) { entry.SetNext(conn_nam[1]);} - else if(conn_nam[1]==String("+")) { entry.SetNext(conn_nam[0]);} - LOG_TRACE(" " << conn_nam[0] << " " << conn_nam[1]); - } else { - LOG_TRACE(" " << conn_nam[0] << " " << conn_nam[1]); - entry.AddConn(conn_nam[0],conn_nam[1]); - } - } - // then the torsion entries - LOG_DEBUG("working on torsion entries"); - for(int cc=0;cc<def_entry.tor_count;++cc) { - int tor_id[] = {def_entry.tor_list[cc].n1, - def_entry.tor_list[cc].n2, - def_entry.tor_list[cc].n3, - def_entry.tor_list[cc].n4}; - String tor_nam[] = {"","","",""}; - String tor_nam2(def_entry.tor_list[cc].name); - for(int cid=0;cid<4;++cid) { - if(tor_id[cid]>0) { - tor_nam[cid]=def_entry.name_list[tor_id[cid]-1]; - } else if (tor_id[cid]==-2) { - tor_nam[cid]="-"; - } else if (tor_id[cid]==-3) { - tor_nam[cid]="+"; - } else if (tor_id[cid]==-4) { - tor_nam[cid]=":"; - } - } - - entry.AddTors(tor_nam[0],tor_nam[1],tor_nam[2],tor_nam[3],tor_nam2); - } - if(ec==0) { - default_peptide_=entry; - } else { - emap_[def_entry.abbrev]=entry; - } - } - default_nucleotide_=LookupResEntry("G").first; - LOG_DEBUG("done importing internal tables"); -} - -HeuristicBuilder::~HeuristicBuilder() -{} - - -void HeuristicBuilder::ConnectivityFromAtomNames(const mol::ResidueHandle& res, - detail::ConnResEntry& centry, - mol::AtomHandleList& unknown_atoms) { - unknown_atoms.clear(); - mol::AtomHandleList atomlist=res.GetAtomList(); - mol::XCSEditor editor=res.GetEntity().EditXCS(mol::BUFFERED_EDIT); - for (mol::AtomHandleList::iterator it1=atomlist.begin();it1!=atomlist.end();++it1) { - if (centry.HasAtom(it1->GetName())) { - mol::AtomHandleList::iterator it2=it1; - ++it2; - for (;it2!=atomlist.end();++it2) { - LOG_TRACE("checking for atom pair (" << it1->GetName() << "," - << it2->GetName() << ") in connectivity table of " - << res.GetKey() << "... "); - int conn=centry.Check(it1->GetName(),it2->GetName()); - if (conn==1) { - if (this->GetBondFeasibilityCheck()==false) { - LOG_TRACE( "found"); - editor.Connect(*it1,*it2); - } else { - if (this->IsBondFeasible(*it1, *it2)) { - LOG_TRACE( "found"); - editor.Connect(*it1,*it2); - } else { - LOG_TRACE( "not found"); - } - } - } else if (conn==2) { - if (this->GetBondFeasibilityCheck()==false) { - LOG_TRACE( "found (reversed)"); - editor.Connect(*it2,*it1); - } else { - if(this->IsBondFeasible(*it2, *it1)) { - LOG_TRACE( "found (reversed)"); - editor.Connect(*it2,*it1); - } - } - } else { - LOG_TRACE( "not found"); - } - } - } else { - unknown_atoms.push_back(*it1); - LOG_TRACE( "atom not found, pushing it to unknown atoms"); - } - } -} - -void HeuristicBuilder::ConnectAtomsOfResidue(mol::ResidueHandle res) -{ - LOG_TRACE("HeuristicBuilder: ConnectAtomsOfResidue on " << res.GetKey() << " " << res.GetNumber()); - - mol::AtomHandleList atomlist = res.GetAtomList(); - mol::AtomHandleList unk_atomlist; -#if !defined(NDEBUG) - std::stringstream ss; - ss << "using atom list:"; - for(mol::AtomHandleList::iterator it=atomlist.begin();it!=atomlist.end();++it) { - ss << " " << it->GetName() << " @" << it->GetPos(); - } - LOG_TRACE(ss.str()); -#endif - std::pair<detail::ConnResEntry,bool> ret = LookupResEntry(res.GetKey()); - - if(ret.second) { - // residue entry found - this->ConnectivityFromAtomNames(res, ret.first, unk_atomlist); - // only run the distance based connectivity after the rest is done - for(mol::AtomHandleList::iterator it1=unk_atomlist.begin(); - it1!=unk_atomlist.end(); - ++it1) { - LOG_TRACE( "atom " << it1->GetName() << " not found, using distance based connect"); - Builder::DistanceBasedConnect(*it1); - } - } else { - LOG_TRACE("no residue entry found, using distance based connect"); - for(mol::AtomHandleList::iterator it1=atomlist.begin(); - it1!=atomlist.end(); - ++it1) { - Builder::DistanceBasedConnect(*it1); - } - } -} - -namespace { - -template<bool flag> // false:=prev, true:=next -void ConnectPrevNext(HeuristicBuilder* builder,mol::ResidueHandle res0, - mol::ResidueHandle res1) -{ - static String fname=flag ? "HeuristicBuilder: ConnectNextXCS" : "HeuristicBuilder: ConnectPrevXCS"; - if(!res0) return; // return if invalid - mol::XCSEditor editor=res0.GetEntity().EditXCS(mol::BUFFERED_EDIT); - LOG_TRACE(fname << " on " << res0.GetKey() << " " << res0.GetNumber()); - - if(!res1) { - // auto-detect prev or next residue in chain - // and perform sequence check - if(flag) { - LOG_TRACE(fname << " autodecting next residue"); - res1 = res0.GetChain().GetNext(res0); - } else { - LOG_TRACE(fname << " autodecting next residue"); - res1 = res0.GetChain().GetPrev(res0); - } - } else { - if(res0.GetEntity() != res1.GetEntity()) return; // different entity handles - } - if (flag) { - if(!Builder::AreResiduesConsecutive(res0,res1)) return; - } else { - if(!Builder::AreResiduesConsecutive(res1, res0)) return; - } - - if(!res1) return; // ignore if prev/next residue is invalid - LOG_TRACE(fname << " found second residue " << res1.GetKey() - << " " << res1.GetNumber()); - - std::pair<detail::ConnResEntry,bool> res0_ret = builder->LookupResEntry(res0.GetKey()); - std::pair<detail::ConnResEntry,bool> res1_ret = builder->LookupResEntry(res1.GetKey()); - - if(!res0_ret.second) { - if(res0.FindAtom("N") && res0.FindAtom("CA") && res0.FindAtom("C")) { - LOG_TRACE("using default peptide for " << res0.GetKey()); - res0_ret.first=builder->DefaultPeptide(); - res0_ret.second=true; - } - if (res0.FindAtom("C3'") && res0.FindAtom("P")) { - res0_ret.first=builder->DefaultNucleotide(); - res0_ret.second=true; - } - } - - if(!res1_ret.second) { - if(res1.FindAtom("N") && res1.FindAtom("CA") && res1.FindAtom("C")) { - LOG_TRACE("using default peptide for " << res1.GetKey()); - res1_ret.first=builder->DefaultPeptide(); - res1_ret.second=true; - } - if (res1.FindAtom("C3'") && res1.FindAtom("P")) { - res1_ret.first=builder->DefaultNucleotide(); - res1_ret.second=true; - } - } - - if(res0_ret.second && res1_ret.second) { - detail::ConnResEntry& res0_centry=res0_ret.first; - detail::ConnResEntry& res1_centry=res1_ret.first; - String res0_atom_name = res0_centry.GetPrev(); - String res1_atom_name = res1_centry.GetNext(); - - if(res0_atom_name.empty() || res1_atom_name.empty()) return; - LOG_TRACE(fname << ": looking up atom names " << res0_atom_name << " " << res1_atom_name); - - // lookup both atoms in their respective residues - mol::AtomHandle res0_atom = res0.FindAtom(res0_atom_name); - mol::AtomHandle res1_atom = res1.FindAtom(res1_atom_name); - if(res0_atom && res1_atom) { - LOG_TRACE(fname << ": found atoms, connecting"); - if(flag) { - if (builder->DoesPeptideBondExist(res0_atom, res1_atom)) { - editor.Connect(res0_atom,res1_atom); - if (res0_ret.first.GetChemClass().IsPeptideLinking()) { - res0.SetIsProtein(true); - res1.SetIsProtein(true); - } - } - } else { - if (builder->DoesPeptideBondExist(res1_atom, res0_atom)) { - editor.Connect(res1_atom, res0_atom); - if (res0_ret.first.GetChemClass().IsPeptideLinking()) { - res0.SetIsProtein(true); - res1.SetIsProtein(true); - } - } - } - } - } else { - // could implement some sort of distance based heuristics here - } -} - -} - -void HeuristicBuilder::AssignTorsionsToResidue(mol::ResidueHandle res) -{ - - mol::XCSEditor editor=res.GetEntity().EditXCS(mol::BUFFERED_EDIT); - mol::ChainHandle chain=res.GetChain(); - std::pair<detail::ConnResEntry,bool> centry2 = LookupResEntry(res.GetKey()); - if (centry2.second) { - // residue entry found - detail::ConnResEntry& centry=centry2.first; - - detail::ConnResEntry::TorsionEntryList tel=centry.GetTorsionList(); - // for each entry in torsion list - for (unsigned int ti=0;ti<tel.size();++ti) { - // assign the four atom handles - mol::AtomHandle ah[4]; - for (unsigned int ahi=0;ahi<4;++ahi) { - mol::ResidueHandle search_in=res; - String cur_name=tel[ti].a[ahi]; - bool flag=false; - if (cur_name=="+") { - mol::ResidueHandle next=res.GetNext(); - // NEXT - if (Builder::AreResiduesConsecutive(res, next)) { - centry2=LookupResEntry(next.GetKey()); - if (centry2.second) { - cur_name=centry2.first.GetPrev(); - search_in=next; - flag=true; - } - } - } else if (cur_name=="-") { - mol::ResidueHandle prev=res.GetPrev(); - if (Builder::AreResiduesConsecutive(prev, res)) { - centry2=LookupResEntry(prev.GetKey()); - if (centry2.second) { - cur_name=centry2.first.GetNext(); - search_in=prev; - flag=true; - } - } - } else { - flag=true; - } - if (flag) { - // lookup atom based on cur_residue and cur_name - mol::AtomHandle a=search_in.FindAtom(cur_name); - if (!a.IsValid()) - continue; - ah[ahi]=a; - } - } // ahi - if (ah[0] && ah[1] && ah[2] && ah[3]) { - mol::TorsionHandle th = editor.AddTorsion(tel[ti].name, ah[0], ah[1], - ah[2], ah[3]); - if(th) { - LOG_TRACE("added torsion entry for " << tel[ti].a[0] << " " - << tel[ti].a[1] << " " << tel[ti].a[2] << " " - << tel[ti].a[3]); - } else { - LOG_TRACE("no torsion entry for " << tel[ti].a[0] << " " - << tel[ti].a[1] << " " << tel[ti].a[2] - << " " << tel[ti].a[3]); - } - } - } - } -} - -void HeuristicBuilder::AssignTorsions(mol::ChainHandle chain) -{ - if (chain.GetResidueCount()==0) - return; - std::vector<mol::ResidueHandle> rlist = chain.GetResidueList(); - for(unsigned int ri=0;ri<rlist.size();++ri) { - mol::ResidueHandle res=rlist[ri]; - this->AssignTorsionsToResidue(res); - if (!res.IsPeptideLinking()) { - return; - } - Builder::AssignBackBoneTorsionsToResidue(res); - } -} - -void HeuristicBuilder::ConnectResidueToPrev(mol::ResidueHandle rh, - mol::ResidueHandle prev) { - ConnectPrevNext<false>(this, rh, prev); -} - -void HeuristicBuilder::ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle next) { - ConnectPrevNext<true>(this, rh, next); -} - -void HeuristicBuilder::FillResidueProps(mol::ResidueHandle residue) { - std::pair<detail::ConnResEntry,bool> ret = LookupResEntry(residue.GetKey()); - if (ret.second) { - residue.SetChemClass(mol::ChemClass(ret.first.GetChemClass())); - residue.SetOneLetterCode(ret.first.GetOneLetterCode()); - } else { - if (residue.FindAtom("N") && residue.FindAtom("CA") && - residue.FindAtom("C") && residue.FindAtom("O")) { - residue.SetChemClass(mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING)); - } else { - residue.SetChemClass(mol::ChemClass(mol::ChemClass::UNKNOWN)); - } - - residue.SetOneLetterCode('?'); - } - -} - -std::pair<detail::ConnResEntry,bool> HeuristicBuilder::LookupResEntry(const mol::ResidueKey& key) -{ - static detail::ConnResEntry dummy; - - - - detail::ConnResEntryMap::iterator pos = emap_.find(key); - if(pos!=emap_.end()) { - LOG_TRACE("reskey '" << key << "' found in connectivity map"); - return std::make_pair(pos->second,true); - } - LOG_TRACE("reskey '" << key << "' not found connectivity map"); - return std::make_pair(dummy,false); -} - -bool HeuristicBuilder::IsResidueComplete(const mol::ResidueHandle& rh) -{ - std::pair<detail::ConnResEntry,bool> ret=LookupResEntry(rh.GetKey()); - if (!ret.second) { - // if the residue is unknown we return false... - return false; - } - for (std::vector<String>::const_iterator i=ret.first.GetReqAtoms().begin(), - e=ret.first.GetReqAtoms().end(); i!=e; ++i) { - if (!rh.FindAtom(*i)) { - return false; - } - } - return true; -} - -void HeuristicBuilder::FillAtomProps(mol::AtomHandle atom) -{ - if (atom.GetElement()=="") { - atom.SetElement(Builder::GuessAtomElement(atom.GetName(), atom.IsHetAtom())); - } -} - -}} // ns diff --git a/modules/conop/src/heuristic_builder.hh b/modules/conop/src/heuristic_builder.hh deleted file mode 100644 index 09a991345264b6031265c9bf2505a874f730daac..0000000000000000000000000000000000000000 --- a/modules/conop/src/heuristic_builder.hh +++ /dev/null @@ -1,127 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_CONOP_HEURISTIC_BUILDER_HH -#define OST_CONOP_HEURISTIC_BUILDER_HH - -#include <set> -#include <map> - -#include <ost/mol/chem_class.hh> - -#include "builder.hh" - -namespace ost { namespace conop { - -namespace detail { - -// internally used class -class DLLEXPORT_OST_CONOP ConnResEntry { -public: - typedef std::pair<String,String> NamePair; - typedef std::multiset<NamePair> PairSet; - struct TorsionEntry { - String a[4]; - String name; - }; - typedef std::vector<TorsionEntry> TorsionEntryList; - -public: - ConnResEntry(const String& rname="", char single='\0', - const mol::ChemClass& chem_class=mol::ChemClass(mol::ChemClass::UNKNOWN)); - int Check(const String& name1, const String& name2) const; - bool HasAtom(const String& name); - void AddAtom(const String& atom) { required_atoms_.push_back(atom); } - void AddConn(const String& n1, const String& n2); - void AddTors(const String& a1, const String& a2, - const String& a3, const String& a4, const String& name); - void SetPrev(const String& n); - const String& GetPrev() const; - void SetNext(const String& n); - const String& GetNext() const; - TorsionEntryList GetTorsionList() const; - char GetOneLetterCode() const {return abbrev_;} - mol::ChemClass GetChemClass() const { return chem_class_; } - - std::vector<String> GetReqAtoms() const { return required_atoms_;} -private: - mol::ResidueKey rkey_; - char abbrev_; - mol::ChemClass chem_class_; - PairSet pset_; - String prev_; - String next_; - std::vector<String> required_atoms_; - TorsionEntryList torsion_entry_list_; -}; - -typedef std::map<mol::ResidueKey,ConnResEntry> ConnResEntryMap; - -} // ns - -class DLLEXPORT_OST_CONOP HeuristicBuilder: public Builder { -public: - HeuristicBuilder(); - virtual ~HeuristicBuilder(); - - virtual void AssignTorsions(mol::ChainHandle ch); - - //! \brief connect by using information in the heuristic connectivity table. - // - // This does not make any assumption on the correctness of internal or external - // coordinates. Only the atom names and residue need to be known. - virtual void ConnectAtomsOfResidue(mol::ResidueHandle rh); - - virtual bool IsResidueComplete(const mol::ResidueHandle& rh); -// virtual char GetOneLetterCode(const mol::ResidueKey& residue) const; - - //!\brief connect to previous residue in chain. - virtual void ConnectResidueToPrev(mol::ResidueHandle rh, - mol::ResidueHandle prev); - //! - virtual void AssignTorsionsToResidue(mol::ResidueHandle residue); - - virtual void FillResidueProps(mol::ResidueHandle residue); - - //!\brief connect to next residue in chain. - virtual void ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle next); - - //!\brief get connectivity table for residues - // Retrieve connectiviy information based on residue key. The returned - // \c pair->second is true, if an entry has been found and and false otherwise. - std::pair<detail::ConnResEntry,bool> LookupResEntry(const mol::ResidueKey& key); - - virtual void FillAtomProps(mol::AtomHandle atom); - - const detail::ConnResEntry& DefaultPeptide() const {return default_peptide_;} - const detail::ConnResEntry& DefaultNucleotide() const {return default_nucleotide_;} -protected: - void ConnectivityFromAtomNames(const mol::ResidueHandle& res, - detail::ConnResEntry& centry, - mol::AtomHandleList& unknown_atoms); -private: - detail::ConnResEntryMap emap_; - detail::ConnResEntry default_peptide_; - detail::ConnResEntry default_nucleotide_; -}; - - -}} // ns - -#endif diff --git a/modules/conop/src/heuristic_connect_table.hh b/modules/conop/src/heuristic_connect_table.hh deleted file mode 100644 index 15e0f1a25eeada4159f10cc60140eeaa4bea55fc..0000000000000000000000000000000000000000 --- a/modules/conop/src/heuristic_connect_table.hh +++ /dev/null @@ -1,304 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_HEURISTIC_CONNECT_TABLE_HH -#define OST_HEURISTIC_CONNECT_TABLE_HH - -#include <string> - -namespace ost { namespace conop { namespace heuristic_connect { - -struct CONN_DEF_ENTRY { - char name[256]; - char abbrev[16],single; - mol::ChemClass chem_class; - char name_list[48][8]; - int name_count; - int conn_list[48][2]; - int conn_count; - struct CONN_TORSION_TMP { - int n1,n2,n3,n4; - String name; - }tor_list[8]; - int tor_count; - int flag_list[128]; - int flag_count; -}; - -CONN_DEF_ENTRY def_entry_table[]={ - // the first entry must be this generic one - {"Generic","___",'_', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C"},3, - {{-2,1}, {1,2}, {2,3}, {3,-3}},4, - { - },0, - {0, 0, 0, 0, 0, 0},6 - }, - {"Alanine","ALA",'A', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","OXT"},6, - {{-2,1}, {1,2}, {2,3}, {3,4}, {2,5}, {3,-3}, {6, 3}},7, - { - },0, - {0, 0, 0, 0, 0, 0},6 - }, - {"Cystein","CYS",'C', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","SG","OXT"},7, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{3,-3},{8, 3}},8, - {{1,2,5,6,"CHI1"} - },1, - {0, 0, 0, 0, 0, 0, 0},7 - }, - {"Aspartate","ASP",'D', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","OD1","OD2","OXT"},9, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{3,-3},{9, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0, 0, 0, 0, 0, 0, 0, 0, 0},9 - }, - {"Glutamate","GLU",'E', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD","OE1","OE2","OXT"},10, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{7,8},{7,9},{3,-3},{10, 3}},11, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"},{5,6,7,8,"CHI3"} - },3, - {0},1 - }, - {"Phenylalanine","PHE",'F', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD1","CD2","CE1","CE2","CZ","OXT"},12, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{7,9},{8,10},{9,11},{10,11},{3,-3},{12, 3}},14, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Glycin","GLY",'G', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","OXT"},5, - {{-2,1},{1,2},{2,3},{3,4},{3,-3},{5, 3}},6, - { - },0, - {0},1 - }, - {"Histidine","HIS",'H', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","ND1","CD2","CE1","NE2","OXT"},11, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{7,9},{8,10},{9,10},{3,-3},{11, 3}},13, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Isoleucine","ILE",'I', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG1","CG2","CD1","OXT"},9, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{5,7},{6,8},{3,-3},{9, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,8,"CHI2"} - },2, - {0},1 - }, - {"Lysin","LYS",'K', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD","CE","NZ","OXT"},10, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{7,8},{8,9},{3,-3},{10, 3}},11, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"},{5,6,7,8,"CHI3"},{6,7,8,9,"CHI4"} - },4, - {0},1 - }, - {"Leucin","LEU",'L', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD1","CD2","OXT"},9, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{3,-3},{9, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Methionine","MET",'M', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","SD","CE","OXT"},9, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{7,8},{3,-3},{10, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"},{5,6,7,8,"CHI3"} - },3, - {0},1 - }, - {"Asparagine","ASN",'N', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","OD1","ND2","OXT"},9, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{3,-3},{9, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Proline","PRO",'P', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD","OXT"},8, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{3,-3},{1,7},{8, 3}},10, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Glutamine","GLN",'Q', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD","OE1","NE2","OXT"},10, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{7,8},{7,9},{3,-3},{10, 3}},11, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"},{5,6,7,8,"CHI3"} - },3, - {0},1 - }, - {"Arginine","ARG",'R', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD","NE","CZ","NH1","NH2","OXT"},12, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{7,8},{8,9},{9,10},{9,11},{3,-3},{12, 3}},13, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"},{5,6,7,8,"CHI3"},{6,7,8,9,"CHI4"},{7,8,9,10,"CHI5"} - },5, - {0},1 - }, - {"Serine","SER",'S', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","OG","OXT"},7, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{3,-3},{7, 3}},8, - { - {1,2,5,6,"CHI1"} - },1, - {0},1 - }, - {"Threonine","THR",'T', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","OG1","CG2","OXT"},8, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{5,7},{3,-3},{8, 3}},9, - { - {1,2,5,6,"CHI1"} - },1, - {0},1 - }, - {"Valine","VAL",'V', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG1","CG2","OXT"},8, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{5,7},{3,-3},{8, 3}},9, - { - {1,2,5,6,"CHI1"} - },1, - {0},1 - }, - {"Tryptophan","TRP",'W', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD1","CD2","NE1","CE2","CE3","CZ2","CZ3","CH2","OXT"},15, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{7,9},{8,10},{9,10},{8,11},{10,12},{11,13},{12,14},{13,14},{3,-3},{15, 3}},18, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - {"Tyrosin","TYR",'Y', mol::ChemClass(mol::ChemClass::L_PEPTIDE_LINKING), - {"N","CA","C","O","CB","CG","CD1","CD2","CE1","CE2","CZ","OH","OXT"},13, - {{-2,1},{1,2},{2,3},{3,4},{2,5},{5,6},{6,7},{6,8},{7,9},{8,10},{9,11},{10,11},{11,12},{3,-3},{13, 3}},15, - { - {1,2,5,6,"CHI1"},{2,5,6,7,"CHI2"} - },2, - {0},1 - }, - /* NUCLEIC ACIDS */ - {"Adenosin","A",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","N9","C8","N7","C5","C6","N6","N1","C2","N3","C4","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,22},{7,-3}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Cytosin","C",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,12},{7,-3}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Guanidin","G",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Thymidin","T",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{8,12},{1,11}},15, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Uracil","U",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Adenosin","ADE",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","N9","C8","N7","C5","C6","N6","N1","C2","N3","C4","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,22},{9,12},{7,-3}},15, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Cytosin","CYT",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,12},{7,-3}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Guanidin","GUA",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Thymidin","THY",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{8,12},{1,11}},15, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Uracil","URI",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Adenosin","DA",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","N9","C8","N7","C5","C6","N6","N1","C2","N3","C4","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,22},{9,12},{7,-3}},15, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Cytosin","DC",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{1,10},{1,11},{8,12},{7,-3}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Guanidin","DG",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Thymidin","DT",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{8,12},{1,11}},15, - {{0,0,0,0,""}},1, - {0},1 - }, - {"Uracil","DU",'?', mol::ChemClass(mol::ChemClass::DNA_LINKING), - {"P","O5'","C5'","C4'","O4'","C3'","O3'","C2'","C1'","O1P","O2P","O2'"},12, - {{-2,1},{1,2},{2,3},{3,4},{4,5},{4,6},{6,7},{6,8},{8,9},{5,9},{7,-3},{1,10},{1,11},{8,12}},14, - {{0,0,0,0,""}},1, - {0},1 - } -}; - -}}} // ns - -#endif diff --git a/modules/conop/src/rule_based_builder.cc b/modules/conop/src/rule_based_builder.cc deleted file mode 100644 index 53410e52d4ffbb9c8395892ad98cdd2a38f04a8d..0000000000000000000000000000000000000000 --- a/modules/conop/src/rule_based_builder.cc +++ /dev/null @@ -1,380 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -/* - Author: Marco Biasini - */ -#include <ost/log.hh> -#include <ost/geom/geom.hh> -#include <ost/mol/impl/atom_impl.hh> -#include <ost/mol/impl/residue_impl.hh> -#include <ost/conop/conop.hh> -#include <limits> -#include "rule_based_builder.hh" - - -namespace ost { namespace conop { - - -void RuleBasedBuilder::CompleteAtoms(mol::ResidueHandle rh) {} - -void RuleBasedBuilder::CheckResidueCompleteness(const mol::ResidueHandle& rh) -{ - this->LookupCompound(rh); - if (!last_compound_) { - mol::AtomHandleList atoms=rh.GetAtomList(); - for (mol::AtomHandleList::const_iterator i=atoms.begin(), - e=atoms.end(); i!=e; ++i) { - this->OnUnknownAtom(*i); - } - return; - } - this->ReorderAtoms(rh , last_compound_); - AtomSpecList::const_iterator j=last_compound_->GetAtomSpecs().begin(); - mol::AtomHandleList atoms=rh.GetAtomList(); - mol::AtomHandleList::iterator i=atoms.begin(); - for (; j!=last_compound_->GetAtomSpecs().end() && i!=atoms.end(); ++j) { - if ((*j).is_leaving || (*j).element=="H" || (*j).element=="D") - continue; - if ((*j).ordinal!=static_cast<int>((*i).Impl()->GetState())) { - this->OnMissingAtom(rh, (*j).name); - } else { - ++i; - } - } -} - -bool RuleBasedBuilder::HasUnknownAtoms(mol::ResidueHandle res) -{ - this->LookupCompound(res); - if (!last_compound_) { - return true; - } - this->ReorderAtoms(res, last_compound_); - AtomSpecList::const_iterator j=last_compound_->GetAtomSpecs().begin(); - mol::AtomHandleList atoms=res.GetAtomList(); - mol::AtomHandleList::iterator i=atoms.begin(); - for (mol::AtomHandleList::iterator - i=atoms.begin(), e=atoms.end(); i!=e; ++i) { - if ((*i).Impl()->GetState()==std::numeric_limits<unsigned int>::max()) { - if (((*i).GetElement()=="H" || (*i).GetElement()=="D") && - this->GetStrictHydrogenMode()==false) { - continue; - } - return true; - } - } - return false; -} - -mol::AtomHandleList RuleBasedBuilder::GetUnknownAtoms(mol::ResidueHandle res) -{ - mol::AtomHandleList unknown; - this->LookupCompound(res); - if (!last_compound_) { - return unknown; - } - mol::AtomHandleList atoms=res.GetAtomList(); - last_residue_=mol::ResidueHandle(); - this->ReorderAtoms(res, last_compound_); - AtomSpecList::const_iterator j=last_compound_->GetAtomSpecs().begin(); - mol::AtomHandleList::iterator i=atoms.begin(); - for (mol::AtomHandleList::iterator - i=atoms.begin(), e=atoms.end(); i!=e; ++i) { - if ((*i).Impl()->GetState()==std::numeric_limits<unsigned int>::max()) { - if (((*i).GetElement()=="H" || (*i).GetElement()=="D") && - this->GetStrictHydrogenMode()==false) { - continue; - } - unknown.push_back(*i); - } - } - return unknown; -} - -void RuleBasedBuilder::FillAtomProps(mol::AtomHandle atom, const AtomSpec& spec) -{ - Conopology& conop_inst=Conopology::Instance(); - if (!conop_inst.IsValidElement(atom.GetElement())) { - atom.SetElement(spec.element); - } -} - -void RuleBasedBuilder::FillResidueProps(mol::ResidueHandle residue) -{ - this->LookupCompound(residue); - if (!last_compound_) - return; - residue.SetChemClass(last_compound_->GetChemClass()); - residue.SetChemType(last_compound_->GetChemType()); - residue.SetOneLetterCode(last_compound_->GetOneLetterCode()); -}; - -struct OrdinalComp { - bool operator()(const mol::impl::AtomImplPtr& a, - const mol::impl::AtomImplPtr& b) const { - return a->GetState()<b->GetState(); - } -}; - - -void RuleBasedBuilder::LookupCompound(const mol::ResidueHandle& rh) -{ - Compound::Dialect dialect=this->GetDialect()==PDB_DIALECT ? Compound::PDB : Compound::CHARMM; - if ((last_compound_) && (rh.GetName()==last_compound_->GetID())) { - return; - } - last_compound_=compound_lib_->FindCompound(rh.GetName(), dialect); - if (!last_compound_ && this->GetDialect()!=PDB_DIALECT) { - last_compound_=compound_lib_->FindCompound(rh.GetName(), Compound::PDB); - } -} - -void RuleBasedBuilder::ReorderAtoms(mol::ResidueHandle residue, - CompoundPtr compound) -{ - if (last_residue_==residue) { - return; - } - mol::impl::ResidueImplPtr impl=residue.Impl(); - mol::impl::AtomImplList::iterator i=impl->GetAtomList().begin(); - for (; i!=impl->GetAtomList().end(); ++i) { - mol::impl::AtomImplPtr atom=*i; - atom->SetState(std::numeric_limits<unsigned int>::max()); - int index=compound->GetAtomSpecIndex(atom->GetName()); - if (index==-1) { - if (!this->OnUnknownAtom(mol::AtomHandle(atom))) { - atom->SetState(std::numeric_limits<unsigned int>::max()); - } - continue; - } - atom->SetState((compound->GetAtomSpecs())[index].ordinal); - } - std::sort(impl->GetAtomList().begin(), impl->GetAtomList().end(), - OrdinalComp()); - last_residue_=residue; - unknown_atoms_=this->HasUnknownAtoms(residue); - if (unknown_atoms_) { - LOG_WARNING("residue " << residue << " doesn't look like a standard " - << residue.GetKey() << " (" << compound->GetFormula() << ")"); - residue.SetChemClass(mol::ChemClass(mol::ChemClass::UNKNOWN)); - residue.SetChemType(mol::ChemType(mol::ChemType::UNKNOWN)); - residue.SetOneLetterCode('?'); - } -} - - - -mol::ResidueKey RuleBasedBuilder::IdentifyResidue(const mol::ResidueHandle& rh) -{ - LookupCompound(rh); - if (last_compound_) { - return last_compound_->GetID(); - } else { - return "UNK"; - } -} - -mol::AtomHandle RuleBasedBuilder::LocateAtom(const mol::AtomHandleList& ahl, - int ordinal) -{ - if (ahl.empty()) - return mol::AtomHandle(); - const mol::AtomHandle* r_it=&ahl.back(); - if (static_cast<int>(ahl.size())>ordinal) { - r_it=&ahl.front()+ordinal; - } - while ((r_it>=&ahl.front()) && - (static_cast<int>(r_it->Impl()->GetState())>ordinal)) { - --r_it; - } - bool not_found=(r_it<&ahl.front() || - static_cast<int>(r_it->Impl()->GetState())!=ordinal); - return not_found ? mol::AtomHandle() : *r_it; -} - - -inline void dist_connect(RuleBasedBuilder* b, mol::AtomHandleList atoms) -{ - for (mol::AtomHandleList::const_iterator i=atoms.begin(), - e=atoms.end(); i!=e; ++i) { - b->DistanceBasedConnect(*i); - } -} - -void RuleBasedBuilder::ConnectAtomsOfResidue(mol::ResidueHandle rh) -{ - - LookupCompound(rh); - - if (!last_compound_) { - dist_connect(this, rh.GetAtomList()); - return; - } - this->ReorderAtoms(rh, last_compound_); - if (unknown_atoms_) { - dist_connect(this, rh.GetAtomList()); - return; - } - mol::XCSEditor e=rh.GetEntity().EditXCS(mol::BUFFERED_EDIT); - BondSpecList::const_iterator j=last_compound_->GetBondSpecs().begin(); - mol::AtomHandleList atoms=rh.GetAtomList(); - for(; j!=last_compound_->GetBondSpecs().end(); ++j) { - const BondSpec& bond=*j; - mol::AtomHandle a1=this->LocateAtom(atoms, bond.atom_one); - mol::AtomHandle a2=this->LocateAtom(atoms, bond.atom_two); - if (a1.IsValid() && a2.IsValid()) { - if (this->GetBondFeasibilityCheck()==false) { - if (this->GetStrictHydrogenMode() && (a1.GetElement()=="H" || - a2.GetElement()=="D")) { - continue; - } - e.Connect(a1, a2, bond.order); - } else { - if (IsBondFeasible(a1, a2)) { - if (this->GetStrictHydrogenMode() && (a1.GetElement()=="H" || - a2.GetElement()=="D")) { - continue; - } - e.Connect(a1, a2, bond.order); - } - } - } - } - for (mol::AtomHandleList::iterator i=atoms.begin(), e=atoms.end(); i!=e; ++i) { - if (((*i).GetElement()=="H" || (*i).GetElement()=="D") && - (*i).GetBondCount()==0) { - this->DistanceBasedConnect(*i); - } - } -} - -void RuleBasedBuilder::ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle next) -{ - if (!next.IsValid()) { - return; - } - - Compound::Dialect dialect=this->GetDialect()==PDB_DIALECT ? Compound::PDB : Compound::CHARMM; - - mol::XCSEditor e=rh.GetEntity().EditXCS(mol::BUFFERED_EDIT); - CompoundPtr mc=compound_lib_->FindCompound(rh.GetName(), dialect); - CompoundPtr nc=compound_lib_->FindCompound(next.GetName(), dialect); - if (!(mc && nc)) - return; - - // check if both of the residues are able to form a peptide bond. - if (mc->IsPeptideLinking() && nc->IsPeptideLinking()) { - // If we have an OXT then there is no peptide bond connecting the two - // residues. - if (rh.FindAtom("OXT")) - return; - mol::AtomHandle c=rh.FindAtom("C"); - mol::AtomHandle n=next.FindAtom("N"); - // Give subclasses a chance to give us their opinions on the feasibility of - // the peptide bond. - if (c.IsValid() && n.IsValid() && this->DoesPeptideBondExist(c, n)) { - e.Connect(c, n, 1); - rh.SetIsProtein(true); - next.SetIsProtein(true); - } - } else if (mc->IsNucleotideLinking() && nc->IsNucleotideLinking()) { - mol::AtomHandle c=rh.FindAtom("O3'"); - mol::AtomHandle n=next.FindAtom("P"); - if (c.IsValid() && n.IsValid() && this->IsBondFeasible(c, n)) { - e.Connect(c, n, 1); - } - } -} - - -void RuleBasedBuilder::AssignTorsions(mol::ChainHandle chain) -{ - if (chain.GetResidueCount()==0) - return; - std::vector<mol::ResidueHandle> rlist = chain.GetResidueList(); - mol::AtomHandleList atom_list = rlist[0].GetAtomList(); - for(unsigned int ri=0;ri<rlist.size();++ri) { - mol::ResidueHandle res=rlist[ri]; - this->AssignTorsionsToResidue(res); - } -} - -void RuleBasedBuilder::AssignTorsionsToResidue(mol::ResidueHandle residue) -{ - /// The only components having named torsions are the standard set of amino - /// acids, plus some of compounds derived from them such as selenium - /// methionine. Things are simplified a lot by only storing the torsions - /// of the side chains in the database. PHI, PSI and OMEGA torsions are - /// checked without a lookup in the database. - LookupCompound(residue); - if (!last_compound_) - return; - if (!last_compound_->IsPeptideLinking()) { - return; - } - Builder::AssignBackBoneTorsionsToResidue(residue); -} - -bool RuleBasedBuilder::IsResidueComplete(const mol::ResidueHandle& residue) -{ - LookupCompound(residue); - if (!last_compound_) - return false; - mol::AtomHandleList atoms=residue.GetAtomList(); - mol::AtomHandleList::iterator i=atoms.begin(); - for (AtomSpecList::const_iterator j=last_compound_->GetAtomSpecs().begin(), - e=last_compound_->GetAtomSpecs().end(); j!=e; ++j) { - if ((*j).is_leaving || (*j).element=="H" || (*j).element=="D") { - continue; - } - if (!(residue.FindAtom(j->name) || residue.FindAtom(j->alt_name))) { - return false; - } - } - return true; -} - - -void RuleBasedBuilder::FillAtomProps(mol::AtomHandle atom) -{ - LookupCompound(atom.GetResidue()); - if (!last_compound_) { - this->OnUnknownAtom(atom); - return; - } - int index=last_compound_->GetAtomSpecIndex(atom.GetName()); - if (index==-1) { - this->OnUnknownAtom(atom); - return; - } - const AtomSpec& atom_spec=last_compound_->GetAtomSpecs()[index]; - this->FillAtomProps(atom, atom_spec); -} - -bool RuleBasedBuilder::OnUnknownAtom(mol::AtomHandle atom) -{ - Conopology& conop_inst=Conopology::Instance(); - if (!conop_inst.IsValidElement(atom.GetElement())) { - atom.SetElement(Builder::GuessAtomElement(atom.GetName(), atom.IsHetAtom())); - } - return false; -} - -}} diff --git a/modules/conop/src/rule_based_builder.hh b/modules/conop/src/rule_based_builder.hh deleted file mode 100644 index 71a6fd03453ba9c418a6e39d8c0e011161f13be6..0000000000000000000000000000000000000000 --- a/modules/conop/src/rule_based_builder.hh +++ /dev/null @@ -1,150 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#ifndef OST_CONOP_RULE_BASED_BUILDER_HH -#define OST_CONOP_RULE_BASED_BUILDER_HH - -/* - Author: Marco Biasini - */ -#include <set> -#include <map> - -#include "builder.hh" -#include "compound_lib.hh" - -namespace ost { namespace conop { - -/// \brief Use library of chemical compounds to derive bonds and clean-up -/// structural problems -/// -/// \todo Sorting of the residues directly uses impl layer of the base module. -/// Would be much nicer if the order could be assigned in the public -/// interface and then tell the residues to sort the atoms in ascending -/// order. -class DLLEXPORT_OST_CONOP RuleBasedBuilder: public Builder { -public: - RuleBasedBuilder(const CompoundLibPtr& compound_lib) - : compound_lib_(compound_lib), last_compound_() { - } - - virtual void SetDialect(Dialect dialect) { - if (this->GetDialect()!=dialect) { - Builder::SetDialect(dialect); - last_compound_=CompoundPtr(); - compound_lib_->ClearCache(); - } - } - - /// \brief fill atom properties such as element and radius - virtual void FillAtomProps(mol::AtomHandle atom); - - virtual void CompleteAtoms(mol::ResidueHandle rh); - - /// \brief Check residue completeness - /// - /// By using the description of the chemical compound, the completeness of - /// the residue is verified. The method distinguishes between required atoms - /// and atoms that are optional, like OXT that is only present, if not peptide - /// bond is formed. Whenever an unknown atom is encountered, OnUnknownAtom() - /// is invoked. Subclasses of the RuleBasedBuilder may implement some - /// additional logic to deal with unknown atom. Likewise, whenever a required - /// atom is missing, OnMissingAtom() is invoked. Hydrogen atoms are not - /// considered as required by default - virtual void CheckResidueCompleteness(const mol::ResidueHandle& rh); - - /// \brief Identify residue by name - /// - /// Looks-up the residue in the database of chemical compounds and returns the - /// name of the residue or "UNK" if the residue has not been found in the - /// library. - virtual mol::ResidueKey IdentifyResidue(const mol::ResidueHandle& rh); - - - virtual void ConnectAtomsOfResidue(mol::ResidueHandle rh); - - /// \brief Connects the two residues together. - /// - /// Connections are established if both of the residues are peptide-linking - /// components and when PeptideBondExists() returns true. - /// \param rh - /// is the N-terminal partner donating the C and O for the peptide - /// bond. - /// \param next - /// is the C-terminal partner, donating the nitrogen to the bond. - virtual void ConnectResidueToNext(mol::ResidueHandle rh, - mol::ResidueHandle next); - /// \brief requires chemical types - virtual void AssignTorsions(mol::ChainHandle ch); - virtual void AssignTorsionsToResidue(mol::ResidueHandle residue); - /// \brief Invoked whenever an unkknown atom has been encountered during a - /// residue completeness check. - /// - /// The default implementation guesses the atom properties based on the name - /// and returns false, meaning that it should be treated as an unknown atom. - /// - /// Custom implementations of this method may delete the atom, or modify it. - /// \todo what should be done when the atom name is changed? it would be - /// neccessary to rerun CheckResidueCompleteness(). - virtual bool OnUnknownAtom(mol::AtomHandle atom); - - /// \brief Invoked whenever an atom is missing - /// - /// It is up to the overloaded method to deal with the missing atom, either - /// by ignoring it or by inserting a dummy atom. - virtual void OnMissingAtom(const mol::ResidueHandle& residue, - const String& atom_name) { } - - /// \brief Fill in missing information based on atom name. - virtual void FillAtomProps(mol::AtomHandle atom, const AtomSpec& spec); - - /// \brief Set residue properties such as chemical class - virtual void FillResidueProps(mol::ResidueHandle residue); - - mol::AtomHandleList GetUnknownAtoms(mol::ResidueHandle res); - - /// \brief Check whether the residue has all required atoms. This does not - /// include hydrogens and leaving atoms such as the terminal OXT. - virtual bool IsResidueComplete(const mol::ResidueHandle& residue); - - CompoundLibPtr GetCompoundLib() const { return compound_lib_; } - -private: - CompoundLibPtr compound_lib_; - CompoundPtr last_compound_; - mol::ResidueHandle last_residue_; - bool unknown_atoms_; - /// \brief whether the residue has unknown atoms - bool HasUnknownAtoms(mol::ResidueHandle res); - - void LookupCompound(const mol::ResidueHandle& rh); - /// Change internal order of atoms in residue to the order given by compound - void ReorderAtoms(mol::ResidueHandle residue, CompoundPtr compound); - - mol::AtomHandle LocateAtom(const mol::AtomHandleList& ahl, int ordinal); - - void AssignBackBoneTorsionsToResidue(mol::ResidueHandle residue); - -}; - -typedef boost::shared_ptr<RuleBasedBuilder> RuleBasedBuilderPtr; - -}} - -#endif - diff --git a/modules/conop/tests/test_builder.cc b/modules/conop/tests/test_builder.cc deleted file mode 100644 index 0d5d6537145ea27dc63cbe2960afe7f9e6b293a2..0000000000000000000000000000000000000000 --- a/modules/conop/tests/test_builder.cc +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> -// -// Copyright (C) 2008-2011 by the OpenStructure authors -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -//------------------------------------------------------------------------------ -#include <ost/mol/mol.hh> -#include <ost/conop/builder.hh> -#include <ost/conop/heuristic_builder.hh> -#define BOOST_TEST_DYN_LINK -#include <boost/test/unit_test.hpp> -#include <boost/test/auto_unit_test.hpp> - - -// using boost::unit_test_framework::test_suite; -using namespace ost; -using namespace ost::conop; -using namespace ost::mol; - -BOOST_AUTO_TEST_SUITE( conop ); - -BOOST_AUTO_TEST_CASE(test_guess_chem_class) -{ - HeuristicBuilder h; - EntityHandle ent=mol::CreateEntity(); - XCSEditor edi=ent.EditXCS(); - ChainHandle chain=edi.InsertChain("A"); - ResidueHandle res=edi.AppendResidue(chain, "DUMMY"); - AtomHandle n=edi.InsertAtom(res, "N", geom::Vec3(1, 0, 0), "N"); - AtomHandle ca=edi.InsertAtom(res, "CA", geom::Vec3(2, 0, 0), "C"); - AtomHandle c=edi.InsertAtom(res, "C", geom::Vec3(3, 0, 0), "C"); - AtomHandle o=edi.InsertAtom(res, "O", geom::Vec3(4, 0, 0), "O"); - h.GuessChemClass(res); - BOOST_CHECK(res.IsPeptideLinking()); - res.SetChemClass(ChemClass()); - edi.SetAtomPos(n, geom::Vec3(-1,0,0)); - h.GuessChemClass(res); - BOOST_CHECK(!res.IsPeptideLinking()); -} - -BOOST_AUTO_TEST_CASE( test_builder ) -{ - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("CA", false), "C"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("CB", false), "C"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("N", false), "N"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("O", false), "O"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("CG1", false), "C"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("CG2", false), "C"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("OG1", false), "O"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("SG", false), "S"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1HA", false), "H"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1HB", false), "H"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1DA", false), "D"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1DB", false), "D"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1HA", true), "H"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1HB", true), "H"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1DA", true), "D"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("1DB", true), "D"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("CA", true), "CA"); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("11", true), ""); - BOOST_CHECK_EQUAL(Builder::GuessAtomElement("11", false), ""); -} - -BOOST_AUTO_TEST_SUITE_END(); diff --git a/modules/conop/tests/test_heuristic_builder.cc b/modules/conop/tests/test_heuristic_builder.cc deleted file mode 100644 index bca1b67ee9e4e5ed9b9a9784031ba6fd57918370..0000000000000000000000000000000000000000 --- a/modules/conop/tests/test_heuristic_builder.cc +++ /dev/null @@ -1,222 +0,0 @@ -// ------------------------------------------------------------------------------ -// This file is part of the OpenStructure project <www.openstructure.org> - -// Copyright (C) 2008-2011 by the OpenStructure authors - -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. - -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// ------------------------------------------------------------------------------ - -#include <ost/mol/mol.hh> -#include <ost/conop/heuristic_builder.hh> - -#define BOOST_TEST_DYN_LINK -#include <boost/test/unit_test.hpp> -#include <boost/test/auto_unit_test.hpp> - -#include <ost/log.hh> -using boost::unit_test_framework::test_suite; -using namespace ost; -using namespace ost::conop; -using namespace ost::mol; -namespace { -} // anon ns - -ResidueHandle make_arg(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res = e.AppendResidue(chain, "ARG"); - e.InsertAtom(res, "N",geom::Vec3(20.202,33.112,58.011)); - e.InsertAtom(res, "CA",geom::Vec3(19.396,31.903,58.033)); - e.InsertAtom(res, "C",geom::Vec3(18.608,31.739,59.328)); - e.InsertAtom(res, "O",geom::Vec3(17.651,30.965,59.381)); - e.InsertAtom(res, "CB",geom::Vec3(20.284,30.681,57.801)); - e.InsertAtom(res, "CG",geom::Vec3(20.665,30.488,56.342)); - e.InsertAtom(res, "CD",geom::Vec3(21.557,29.281,56.154)); - e.InsertAtom(res, "NE",geom::Vec3(22.931,29.557,56.551)); - e.InsertAtom(res, "CZ",geom::Vec3(23.901,28.653,56.528)); - e.InsertAtom(res, "NH1",geom::Vec3(23.640,27.417,56.130)); - e.InsertAtom(res, "NH2",geom::Vec3(25.132,28.980,56.893)); - return res; -} - -ResidueHandle make_leu(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res=e.AppendResidue(chain, "LEU"); - - e.InsertAtom(res, "N", geom::Vec3(19.003,32.473,60.366)); - e.InsertAtom(res, "CA", geom::Vec3(18.330,32.402,61.664)); - e.InsertAtom(res, "C", geom::Vec3(17.884,33.787,62.117)); - e.InsertAtom(res, "O", geom::Vec3(17.853,34.091,63.308)); - e.InsertAtom(res, "CB", geom::Vec3(19.269,31.793,62.710)); - e.InsertAtom(res, "CG", geom::Vec3(19.695,30.340,62.501)); - e.InsertAtom(res, "CD1", geom::Vec3(20.585,29.897,63.648)); - e.InsertAtom(res, "CD2", geom::Vec3(18.461,29.459,62.420)); - return res; -} - -ResidueHandle make_defective_leu(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res=e.AppendResidue(chain, "LEU"); - - e.InsertAtom(res, "N", geom::Vec3(19.003,32.473,60.366)); - e.InsertAtom(res, "CA", geom::Vec3(18.330,32.402,61.664)); - e.InsertAtom(res, "C", geom::Vec3(17.884,33.787,62.117)); - e.InsertAtom(res, "O", geom::Vec3(17.853,34.091,63.308)); - e.InsertAtom(res, "CB", geom::Vec3(19.269,31.793,102.710)); - e.InsertAtom(res, "CG", geom::Vec3(19.695,30.340,62.501)); - e.InsertAtom(res, "CD1", geom::Vec3(20.585,29.897,63.648)); - e.InsertAtom(res, "CD2", geom::Vec3(18.461,29.459,62.420)); - return res; -} - -void verify_connectivity_x(const ResidueHandle& res) -{ - BOOST_CHECK(BondExists(res.FindAtom("XN"), - res.FindAtom("XCA"))); - BOOST_CHECK(BondExists(res.FindAtom("XCA"), - res.FindAtom("XC"))); - BOOST_CHECK(BondExists(res.FindAtom("XC"), - res.FindAtom("XO"))); - BOOST_CHECK(BondExists(res.FindAtom("XCA"), - res.FindAtom("XCB"))); - BOOST_CHECK(BondExists(res.FindAtom("XCB"), - res.FindAtom("XCG"))); - if (res.GetKey()=="ARG") { - - BOOST_CHECK(BondExists(res.FindAtom("XCB"), - res.FindAtom("XCG"))); - BOOST_CHECK(BondExists(res.FindAtom("XCG"), - res.FindAtom("XCD"))); - BOOST_CHECK(BondExists(res.FindAtom("XCD"), - res.FindAtom("XNE"))); - BOOST_CHECK(BondExists(res.FindAtom("XNE"), - res.FindAtom("XCZ"))); - BOOST_CHECK(BondExists(res.FindAtom("XCZ"), - res.FindAtom("XNH1"))); - BOOST_CHECK(BondExists(res.FindAtom("XCZ"), - res.FindAtom("XNH2"))); - // TODO: Check that no other atoms are connected! - } - if (res.GetKey()=="ILE") { - BOOST_CHECK(BondExists(res.FindAtom("XCG"), - res.FindAtom("XCD1"))); - BOOST_CHECK(BondExists(res.FindAtom("XCG"), - res.FindAtom("XCD2"))); - // TODO: Check that no other atoms are connected! - } -} - -void verify_connectivity(const ResidueHandle& res) -{ - BOOST_CHECK(BondExists(res.FindAtom("N"), - res.FindAtom("CA"))); - BOOST_CHECK(BondExists(res.FindAtom("CA"), - res.FindAtom("C"))); - BOOST_CHECK(BondExists(res.FindAtom("C"), - res.FindAtom("O"))); - BOOST_CHECK(BondExists(res.FindAtom("CA"), - res.FindAtom("CB"))); - BOOST_CHECK(BondExists(res.FindAtom("CB"), - res.FindAtom("CG"))); - if (res.GetKey()=="ARG") { - - BOOST_CHECK(BondExists(res.FindAtom("CB"), - res.FindAtom("CG"))); - BOOST_CHECK(BondExists(res.FindAtom("CG"), - res.FindAtom("CD"))); - BOOST_CHECK(BondExists(res.FindAtom("CD"), - res.FindAtom("NE"))); - BOOST_CHECK(BondExists(res.FindAtom("NE"), - res.FindAtom("CZ"))); - BOOST_CHECK(BondExists(res.FindAtom("CZ"), - res.FindAtom("NH1"))); - BOOST_CHECK(BondExists(res.FindAtom("CZ"), - res.FindAtom("NH2"))); - // TODO: Check that no other atoms are connected! - } - if (res.GetKey()=="ILE") { - BOOST_CHECK(BondExists(res.FindAtom("CG"), - res.FindAtom("CD1"))); - BOOST_CHECK(BondExists(res.FindAtom("CG"), - res.FindAtom("CD2"))); - // TODO: Check that no other atoms are connected! - } -} - -BOOST_AUTO_TEST_SUITE( conop ); - - -BOOST_AUTO_TEST_CASE(name_based_connect) -{ - EntityHandle e=CreateEntity(); - ChainHandle c=e.EditXCS().InsertChain("A"); - ResidueHandle ile=make_leu(c); - ResidueHandle arg=make_arg(c); - HeuristicBuilder heuristic_builder; - for (AtomHandleIter i=e.AtomsBegin(),x=e.AtomsEnd(); i!=x; ++i) { - heuristic_builder.FillAtomProps(*i); - } - - EntityHandle de=CreateEntity(); - ChainHandle dc=de.EditXCS().InsertChain("A"); - ResidueHandle dile=make_defective_leu(dc); - HeuristicBuilder dheuristic_builder; - dheuristic_builder.SetBondFeasibilityCheck(false); - for (AtomHandleIter i=de.AtomsBegin(),x=de.AtomsEnd(); i!=x; ++i) { - dheuristic_builder.FillAtomProps(*i); - } - - BOOST_MESSAGE("running distance based checks on arginine"); - heuristic_builder.ConnectAtomsOfResidue(arg); - verify_connectivity(arg); - BOOST_MESSAGE("running distance based checks on leu"); - heuristic_builder.ConnectAtomsOfResidue(ile); - verify_connectivity(ile); - - BOOST_MESSAGE("running distance based checks on defective leu"); - dheuristic_builder.ConnectAtomsOfResidue(dile); - verify_connectivity(dile); -} - -BOOST_AUTO_TEST_CASE(test_assign_torsions){ - EntityHandle e=CreateEntity(); - ChainHandle c=e.EditXCS().InsertChain("A"); - ResidueHandle l1=make_leu(c); - ResidueHandle a2=make_arg(c); - ResidueHandle l3=make_leu(c); - l1.SetChemClass(ChemClass(ChemClass::L_PEPTIDE_LINKING)); - a2.SetChemClass(ChemClass(ChemClass::L_PEPTIDE_LINKING)); - l3.SetChemClass(ChemClass(ChemClass::L_PEPTIDE_LINKING)); - HeuristicBuilder heuristic_builder; - for (AtomHandleIter i=e.AtomsBegin(),x=e.AtomsEnd(); i!=x; ++i) { - heuristic_builder.FillAtomProps(*i); - } - heuristic_builder.ConnectAtomsOfResidue(l1); - heuristic_builder.ConnectAtomsOfResidue(a2); - heuristic_builder.ConnectAtomsOfResidue(l3); - XCSEditor edi=e.EditXCS(); - edi.Connect(l1.FindAtom("C"), a2.FindAtom("N")); - edi.Connect(a2.FindAtom("C"), l3.FindAtom("N")); - heuristic_builder.AssignTorsions(c); - - BOOST_CHECK(a2.GetPhiTorsion().IsValid()); - BOOST_CHECK(l3.GetPhiTorsion().IsValid()); - - BOOST_CHECK(l1.GetPsiTorsion().IsValid()); - BOOST_CHECK(a2.GetPsiTorsion().IsValid()); -} - -BOOST_AUTO_TEST_SUITE_END( ); diff --git a/modules/conop/tests/test_rule_based_builder.cc b/modules/conop/tests/test_rule_based_builder.cc deleted file mode 100644 index bc89d94a5a297f1e3c690d8ddcc05a0a643e5dda..0000000000000000000000000000000000000000 --- a/modules/conop/tests/test_rule_based_builder.cc +++ /dev/null @@ -1,456 +0,0 @@ -// ----------------------------------------------------------------------------- -// This file is part of the OpenStructure project <www.openstructure.org> - -// Copyright (C) 2008-2011 by the OpenStructure authors - -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation; either version 3.0 of the License, or (at your option) -// any later version. -// This library is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more -// details. - -// You should have received a copy of the GNU Lesser General Public License -// along with this library; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- - -#include <ost/mol/mol.hh> -#include <ost/platform.hh> -#include <ost/conop/rule_based_builder.hh> -#include <ost/conop/conop.hh> -#define BOOST_TEST_DYN_LINK -#include <boost/test/unit_test.hpp> -#include <boost/test/auto_unit_test.hpp> - -#include <ost/log.hh> -using boost::unit_test_framework::test_suite; -using namespace ost; -using namespace ost::conop; -//using namespace ost::io; -using namespace ost::mol; -namespace { -} // anon ns - -ResidueHandle make_cytosine(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res=e.AppendResidue(chain, "DC"); - - e.InsertAtom(res, "P", geom::Vec3(21.412, 34.391, 37.142)); - e.InsertAtom(res, "OP1", geom::Vec3(22.938, 34.599, 36.988)); - e.InsertAtom(res, "OP2", geom::Vec3(20.690, 35.640, 37.689)); - e.InsertAtom(res, "O5'", geom::Vec3(21.215, 33.299, 38.339)); - e.InsertAtom(res, "C5'", geom::Vec3(20.524, 33.660, 39.548)); - e.InsertAtom(res, "C4'", geom::Vec3(19.064, 33.285, 39.452)); - e.InsertAtom(res, "O4'", geom::Vec3(18.246, 34.411, 39.034)); - e.InsertAtom(res, "C3'", geom::Vec3(18.778, 32.150, 38.469)); - e.InsertAtom(res, "O3'", geom::Vec3(17.930, 31.199, 39.081)); - e.InsertAtom(res, "C2'", geom::Vec3(18.046, 32.827, 37.330)); - e.InsertAtom(res, "C1'", geom::Vec3(17.326, 33.955, 38.048)); - e.InsertAtom(res, "N1", geom::Vec3(16.891, 35.100, 37.196)); - e.InsertAtom(res, "C2", geom::Vec3(15.709, 35.782, 37.543)); - e.InsertAtom(res, "O2", geom::Vec3(15.137, 35.489, 38.610)); - e.InsertAtom(res, "N3", geom::Vec3(15.226, 36.742, 36.710)); - e.InsertAtom(res, "C4", geom::Vec3(15.878, 37.041, 35.582)); - e.InsertAtom(res, "N4", geom::Vec3(15.324, 37.943, 34.762)); - e.InsertAtom(res, "C5", geom::Vec3(17.116, 36.415, 35.238)); - e.InsertAtom(res, "C6", geom::Vec3(17.584, 35.464, 36.067)); - - return res; -} - -ResidueHandle make_uracil1(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res = e.AppendResidue(chain, "U"); - - e.InsertAtom(res, "P", geom::Vec3(18.533, 30.238, 40.226)); - e.InsertAtom(res, "OP1", geom::Vec3(20.012, 30.098, 40.003)); - e.InsertAtom(res, "OP2", geom::Vec3(17.680, 29.017, 40.258)); - e.InsertAtom(res, "O5'", geom::Vec3(18.237, 31.056, 41.570)); - e.InsertAtom(res, "C5'", geom::Vec3(17.104, 31.923, 41.642)); - e.InsertAtom(res, "C4'", geom::Vec3(16.332, 31.729, 42.937)); - e.InsertAtom(res, "O4'", geom::Vec3(15.180, 32.616, 42.841)); - e.InsertAtom(res, "C3'", geom::Vec3(15.785, 30.319, 43.194)); - e.InsertAtom(res, "O3'", geom::Vec3(15.960, 29.834, 44.527)); - e.InsertAtom(res, "C2'", geom::Vec3(14.311, 30.371, 42.766)); - e.InsertAtom(res, "O2'", geom::Vec3(13.442, 29.708, 43.677)); - e.InsertAtom(res, "C1'", geom::Vec3(13.972, 31.863, 42.765)); - e.InsertAtom(res, "N1", geom::Vec3(13.282, 32.212, 41.499)); - e.InsertAtom(res, "C2", geom::Vec3(12.072, 32.896, 41.568)); - e.InsertAtom(res, "O2", geom::Vec3(11.510, 33.142, 42.626)); - e.InsertAtom(res, "N3", geom::Vec3(11.535, 33.257, 40.349)); - e.InsertAtom(res, "C4", geom::Vec3(12.048, 32.976, 39.096)); - e.InsertAtom(res, "O4", geom::Vec3(11.490, 33.447, 38.087)); - e.InsertAtom(res, "C5", geom::Vec3(13.268, 32.207, 39.106)); - e.InsertAtom(res, "C6", geom::Vec3(13.831, 31.872, 40.261)); - - return res; -} - -ResidueHandle make_uracil2(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res = e.AppendResidue(chain, "U"); - - e.InsertAtom(res, "P", geom::Vec3(16.249, 28.254, 44.759)); - e.InsertAtom(res, "OP1", geom::Vec3(16.654, 28.055, 46.181)); - e.InsertAtom(res, "OP2", geom::Vec3(17.115, 27.731, 43.656)); - e.InsertAtom(res, "O5'", geom::Vec3(14.826, 27.572, 44.574)); - e.InsertAtom(res, "C5'", geom::Vec3(14.711, 26.206, 44.216)); - e.InsertAtom(res, "C4'", geom::Vec3(13.279, 25.889, 43.887)); - e.InsertAtom(res, "O4'", geom::Vec3(12.832, 26.793, 42.838)); - e.InsertAtom(res, "C3'", geom::Vec3(13.155, 24.434, 43.329)); - e.InsertAtom(res, "O3'", geom::Vec3(12.269, 23.625, 44.098)); - e.InsertAtom(res, "C2'", geom::Vec3(12.871, 24.595, 41.875)); - e.InsertAtom(res, "O2'", geom::Vec3(11.811, 23.752, 41.462)); - e.InsertAtom(res, "C1'", geom::Vec3(12.424, 26.056, 41.694)); - e.InsertAtom(res, "N1", geom::Vec3(13.030, 26.692, 40.497)); - e.InsertAtom(res, "C2", geom::Vec3(12.517, 26.365, 39.228)); - e.InsertAtom(res, "O2", geom::Vec3(11.579, 25.594, 39.068)); - e.InsertAtom(res, "N3", geom::Vec3(13.141, 26.987, 38.161)); - e.InsertAtom(res, "C4", geom::Vec3(14.197, 27.888, 38.210)); - e.InsertAtom(res, "O4", geom::Vec3(14.627, 28.368, 37.156)); - e.InsertAtom(res, "C5", geom::Vec3(14.671, 28.189, 39.542)); - e.InsertAtom(res, "C6", geom::Vec3(14.087, 27.597, 40.612)); - - return res; -} - -ResidueHandle make_defective_uracil2(ChainHandle chain) -{ - XCSEditor e=chain.GetEntity().EditXCS(); - ResidueHandle res = e.AppendResidue(chain, "U"); - - e.InsertAtom(res, "P", geom::Vec3(16.249, 28.254, 44.759)); - e.InsertAtom(res, "OP1", geom::Vec3(16.654, 28.055, 46.181)); - e.InsertAtom(res, "OP2", geom::Vec3(17.115, 27.731, 43.656)); - e.InsertAtom(res, "O5'", geom::Vec3(14.826, 27.572, 44.574)); - e.InsertAtom(res, "C5'", geom::Vec3(14.711, 26.206, 44.216)); - e.InsertAtom(res, "C4'", geom::Vec3(13.279, 25.889, 43.887)); - e.InsertAtom(res, "O4'", geom::Vec3(12.832, 26.793, 42.838)); - e.InsertAtom(res, "C3'", geom::Vec3(13.155, 24.434, 43.329)); - e.InsertAtom(res, "O3'", geom::Vec3(12.269, 23.625, 44.098)); - e.InsertAtom(res, "C2'", geom::Vec3(12.871, 24.595, 41.875)); - e.InsertAtom(res, "O2'", geom::Vec3(11.811, 23.752, 41.462)); - e.InsertAtom(res, "C1'", geom::Vec3(12.424, 26.056, 41.694)); - e.InsertAtom(res, "N1", geom::Vec3(13.030, 26.692, 40.497)); - e.InsertAtom(res, "C2", geom::Vec3(12.517, 26.365, 39.228)); - e.InsertAtom(res, "O2", geom::Vec3(11.579, 25.594, 39.068)); - e.InsertAtom(res, "N3", geom::Vec3(13.141, 26.987, 38.161)); - e.InsertAtom(res, "C4", geom::Vec3(14.197, 27.888, 38.210)); - e.InsertAtom(res, "O4", geom::Vec3(14.627, 28.368, 37.156)); - e.InsertAtom(res, "C5", geom::Vec3(14.671, 28.189, 39.542)); - e.InsertAtom(res, "C6", geom::Vec3(14.087, 27.597, 80.612)); - - return res; -} - -ResidueHandle make_1zk(ChainHandle chain) -{ - XCSEditor edi=chain.GetEntity().EditXCS(); - ResidueHandle r=edi.AppendResidue(chain, "1ZK"); - edi.InsertAtom(r, "C", geom::Vec3(3.946, 3.520, 10.861),"C"); - edi.InsertAtom(r, "C1", geom::Vec3(6.308, 3.824, 8.036),"C"); - edi.InsertAtom(r, "CA", geom::Vec3(4.856, 4.282, 9.931),"C"); - edi.InsertAtom(r, "C2", geom::Vec3(6.770, 5.099, 8.019),"C"); - edi.InsertAtom(r, "C3", geom::Vec3(7.805, 5.484, 7.142),"C"); - edi.InsertAtom(r, "C4", geom::Vec3(8.363, 4.590, 6.284),"C"); - edi.InsertAtom(r, "C5", geom::Vec3(8.469, 2.345, 5.318),"C"); - edi.InsertAtom(r, "C6", geom::Vec3(7.986, 1.072, 5.322),"C"); - edi.InsertAtom(r, "C4A", geom::Vec3(7.885, 3.277, 6.208),"C"); - edi.InsertAtom(r, "C7", geom::Vec3(6.949, 0.682, 6.190),"C"); - edi.InsertAtom(r, "C8", geom::Vec3(6.398, 1.548, 7.074),"C"); - edi.InsertAtom(r, "C9", geom::Vec3(4.018, 0.269, 12.183),"C"); - edi.InsertAtom(r, "C1A", geom::Vec3(6.824, 2.882, 7.117),"C"); - edi.InsertAtom(r, "O", geom::Vec3(3.224, 4.213, 11.565),"O"); - edi.InsertAtom(r, "O1", geom::Vec3(5.331, 3.476, 8.904),"O"); - edi.InsertAtom(r, "O3", geom::Vec3(5.748, -4.044, 14.612),"O"); - edi.InsertAtom(r, "N", geom::Vec3(3.855, 2.201, 10.790),"N"); - edi.InsertAtom(r, "N1", geom::Vec3(4.814, 0.719, 13.173),"N"); - edi.InsertAtom(r, "CA1", geom::Vec3(3.077, 1.346, 11.644),"C"); - edi.InsertAtom(r, "O2", geom::Vec3(4.203, -0.810, 11.651),"O"); - edi.InsertAtom(r, "O4", geom::Vec3(7.311, -5.667, 18.880),"O"); - edi.InsertAtom(r, "CB", geom::Vec3(1.856, 0.712, 11.049),"C"); - edi.InsertAtom(r, "CG", geom::Vec3(1.015, 1.845, 10.511),"C"); - edi.InsertAtom(r, "ND1", geom::Vec3(1.467, 2.439, 9.321),"N"); - edi.InsertAtom(r, "N2", geom::Vec3(6.478, -3.958, 16.751),"N"); - edi.InsertAtom(r, "CD2", geom::Vec3(-0.105, 2.479, 10.887),"C"); - edi.InsertAtom(r, "CE1", geom::Vec3(0.638, 3.428, 9.002),"C"); - edi.InsertAtom(r, "NE2", geom::Vec3(-0.372, 3.461, 9.881),"N"); - edi.InsertAtom(r, "N3", geom::Vec3(6.871, -7.136, 17.332),"N"); - edi.InsertAtom(r, "CA2", geom::Vec3(5.881, -0.001, 13.808),"C"); - edi.InsertAtom(r, "CB1", geom::Vec3(7.140, 0.860, 13.743),"C"); - edi.InsertAtom(r, "CG1", geom::Vec3(7.503, 1.324, 12.299),"C"); - edi.InsertAtom(r, "C21", geom::Vec3(5.126, -8.557, 18.179),"C"); - edi.InsertAtom(r, "CD1", geom::Vec3(8.185, 0.142, 11.507),"C"); - edi.InsertAtom(r, "CD21", geom::Vec3(8.420, 2.537, 12.325),"C"); - edi.InsertAtom(r, "CE11", geom::Vec3(8.381, 0.689, 10.066),"C"); - edi.InsertAtom(r, "CE2", geom::Vec3(8.907, 2.979, 10.922),"C"); - edi.InsertAtom(r, "CZ", geom::Vec3(9.409, 1.807, 10.075),"C"); - edi.InsertAtom(r, "CH", geom::Vec3(5.592, -0.511, 15.204),"C"); - edi.InsertAtom(r, "OH", geom::Vec3(5.225, 0.377, 16.238),"O"); - edi.InsertAtom(r, "CB11", geom::Vec3(4.426, -1.543, 15.170),"C"); - edi.InsertAtom(r, "CA'", geom::Vec3(4.451, -2.730, 16.152),"C"); - edi.InsertAtom(r, "CB'", geom::Vec3(3.124, -3.441, 16.281),"C"); - edi.InsertAtom(r, "CG11", geom::Vec3(2.553, -3.986, 14.933),"C"); - edi.InsertAtom(r, "C31", geom::Vec3(4.413, -7.811, 19.117),"C"); - edi.InsertAtom(r, "CG2", geom::Vec3(3.204, -4.586, 17.345),"C"); - edi.InsertAtom(r, "OB1", geom::Vec3(3.249, -0.875, 15.134),"O"); - edi.InsertAtom(r, "CC", geom::Vec3(5.603, -3.655, 15.782),"C"); - edi.InsertAtom(r, "CA3", geom::Vec3(7.592, -4.867, 16.603),"C"); - edi.InsertAtom(r, "CD", geom::Vec3(7.274, -5.947, 17.691),"C"); - edi.InsertAtom(r, "CB2", geom::Vec3(8.986, -4.351, 16.803),"C"); - edi.InsertAtom(r, "CG12", geom::Vec3(9.488, -3.108, 16.016),"C"); - edi.InsertAtom(r, "CG21", geom::Vec3(10.000, -5.461, 16.472),"C"); - edi.InsertAtom(r, "CD11", geom::Vec3(9.099, -3.257, 14.571),"C"); - edi.InsertAtom(r, "CM", geom::Vec3(6.587, -8.286, 18.106),"C"); - edi.InsertAtom(r, "C41", geom::Vec3(3.045, -7.980, 19.287),"C"); - edi.InsertAtom(r, "C51", geom::Vec3(2.423, -8.911, 18.456),"C"); - edi.InsertAtom(r, "C61", geom::Vec3(3.164, -9.631, 17.518),"C"); - edi.InsertAtom(r, "N11", geom::Vec3(4.497, -9.459, 17.386),"N"); - return r; -} - -void verify_1zk_connectivity(const ResidueHandle& r1) -{ - BOOST_CHECK(BondExists(r1.FindAtom("C"), r1.FindAtom("CA"))); - BOOST_CHECK(BondExists(r1.FindAtom("C"), r1.FindAtom("O"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA"), r1.FindAtom("O1"))); - BOOST_CHECK(BondExists(r1.FindAtom("C1"), r1.FindAtom("C2"))); - BOOST_CHECK(BondExists(r1.FindAtom("C1"), r1.FindAtom("C1A"))); - BOOST_CHECK(BondExists(r1.FindAtom("C1"), r1.FindAtom("O1"))); - BOOST_CHECK(BondExists(r1.FindAtom("C2"), r1.FindAtom("C3"))); - BOOST_CHECK(BondExists(r1.FindAtom("C3"), r1.FindAtom("C4"))); - BOOST_CHECK(BondExists(r1.FindAtom("C4"), r1.FindAtom("C4A"))); - BOOST_CHECK(BondExists(r1.FindAtom("C4A"), r1.FindAtom("C5"))); - BOOST_CHECK(BondExists(r1.FindAtom("C4A"), r1.FindAtom("C1A"))); - BOOST_CHECK(BondExists(r1.FindAtom("C5"), r1.FindAtom("C6"))); - BOOST_CHECK(BondExists(r1.FindAtom("C6"), r1.FindAtom("C7"))); - BOOST_CHECK(BondExists(r1.FindAtom("C7"), r1.FindAtom("C8"))); - BOOST_CHECK(BondExists(r1.FindAtom("C8"), r1.FindAtom("C1A"))); - BOOST_CHECK(BondExists(r1.FindAtom("N"), r1.FindAtom("CA1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA1"), r1.FindAtom("C9"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA1"), r1.FindAtom("CB"))); - BOOST_CHECK(BondExists(r1.FindAtom("C9"), r1.FindAtom("O2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB"), r1.FindAtom("CG"))); - BOOST_CHECK(BondExists(r1.FindAtom("CG"), r1.FindAtom("ND1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CG"), r1.FindAtom("CD2"))); - BOOST_CHECK(BondExists(r1.FindAtom("ND1"), r1.FindAtom("CE1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CD2"), r1.FindAtom("NE2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CE1"), r1.FindAtom("NE2"))); - BOOST_CHECK(BondExists(r1.FindAtom("N1"), r1.FindAtom("CA2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA2"), r1.FindAtom("CB1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA2"), r1.FindAtom("CH"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB1"), r1.FindAtom("CG1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CG1"), r1.FindAtom("CD1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CG1"), r1.FindAtom("CD21"))); - BOOST_CHECK(BondExists(r1.FindAtom("CD1"), r1.FindAtom("CE11"))); - BOOST_CHECK(BondExists(r1.FindAtom("CD21"), r1.FindAtom("CE2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CE11"), r1.FindAtom("CZ"))); - BOOST_CHECK(BondExists(r1.FindAtom("CE2"), r1.FindAtom("CZ"))); - BOOST_CHECK(BondExists(r1.FindAtom("CH"), r1.FindAtom("OH"))); - BOOST_CHECK(BondExists(r1.FindAtom("CH"), r1.FindAtom("CB11"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB11"), r1.FindAtom("CA'"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB11"), r1.FindAtom("OB1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA'"), r1.FindAtom("CB'"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA'"), r1.FindAtom("CC"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB'"), r1.FindAtom("CG11"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB'"), r1.FindAtom("CG2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CC"), r1.FindAtom("O3"))); - BOOST_CHECK(BondExists(r1.FindAtom("N2"), r1.FindAtom("CA3"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA3"), r1.FindAtom("CD"))); - BOOST_CHECK(BondExists(r1.FindAtom("CA3"), r1.FindAtom("CB2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CD"), r1.FindAtom("O4"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB2"), r1.FindAtom("CG12"))); - BOOST_CHECK(BondExists(r1.FindAtom("CB2"), r1.FindAtom("CG21"))); - BOOST_CHECK(BondExists(r1.FindAtom("CG12"), r1.FindAtom("CD11"))); - BOOST_CHECK(BondExists(r1.FindAtom("N3"), r1.FindAtom("CM"))); - BOOST_CHECK(BondExists(r1.FindAtom("CM"), r1.FindAtom("C21"))); - BOOST_CHECK(BondExists(r1.FindAtom("C21"), r1.FindAtom("C31"))); - BOOST_CHECK(BondExists(r1.FindAtom("C21"), r1.FindAtom("N11"))); - BOOST_CHECK(BondExists(r1.FindAtom("C31"), r1.FindAtom("C41"))); - BOOST_CHECK(BondExists(r1.FindAtom("C41"), r1.FindAtom("C51"))); - BOOST_CHECK(BondExists(r1.FindAtom("C51"), r1.FindAtom("C61"))); - BOOST_CHECK(BondExists(r1.FindAtom("C61"), r1.FindAtom("N11"))); - BOOST_CHECK(BondExists(r1.FindAtom("C"), r1.FindAtom("N"))); - BOOST_CHECK(BondExists(r1.FindAtom("C9"), r1.FindAtom("N1"))); - BOOST_CHECK(BondExists(r1.FindAtom("CC"), r1.FindAtom("N2"))); - BOOST_CHECK(BondExists(r1.FindAtom("CD"), r1.FindAtom("N3"))); -} - -void verify_nucleotide_connectivity(const ResidueHandle& res) -{ - BOOST_CHECK(BondExists(res.FindAtom("P"), - res.FindAtom("OP1"))); - BOOST_CHECK(BondExists(res.FindAtom("P"), - res.FindAtom("OP2"))); - BOOST_CHECK(BondExists(res.FindAtom("P"), - res.FindAtom("O5'"))); - BOOST_CHECK(BondExists(res.FindAtom("O5'"), - res.FindAtom("C5'"))); - BOOST_CHECK(BondExists(res.FindAtom("C5'"), - res.FindAtom("C4'"))); - BOOST_CHECK(BondExists(res.FindAtom("C4'"), - res.FindAtom("O4'"))); - BOOST_CHECK(BondExists(res.FindAtom("C4'"), - res.FindAtom("C3'"))); - BOOST_CHECK(BondExists(res.FindAtom("C3'"), - res.FindAtom("O3'"))); - BOOST_CHECK(BondExists(res.FindAtom("C3'"), - res.FindAtom("C2'"))); - BOOST_CHECK(BondExists(res.FindAtom("C2'"), - res.FindAtom("C1'"))); - BOOST_CHECK(BondExists(res.FindAtom("C1'"), - res.FindAtom("O4'"))); - - if (res.GetKey()=="DC") { - BOOST_CHECK(BondExists(res.FindAtom("C1'"), - res.FindAtom("N1"))); - BOOST_CHECK(BondExists(res.FindAtom("N1"), - res.FindAtom("C2"))); - BOOST_CHECK(BondExists(res.FindAtom("C2"), - res.FindAtom("O2"))); - BOOST_CHECK(BondExists(res.FindAtom("C2"), - res.FindAtom("N3"))); - BOOST_CHECK(BondExists(res.FindAtom("N3"), - res.FindAtom("C4"))); - BOOST_CHECK(BondExists(res.FindAtom("C4"), - res.FindAtom("N4"))); - BOOST_CHECK(BondExists(res.FindAtom("C4"), - res.FindAtom("C5"))); - BOOST_CHECK(BondExists(res.FindAtom("C5"), - res.FindAtom("C6"))); - BOOST_CHECK(BondExists(res.FindAtom("C6"), - res.FindAtom("N1"))); - // TODO: Check that no other atoms are connected! - } - - if (res.GetKey()=="U") { - BOOST_CHECK(BondExists(res.FindAtom("O2'"), - res.FindAtom("C2'"))); - BOOST_CHECK(BondExists(res.FindAtom("C1'"), - res.FindAtom("N1"))); - BOOST_CHECK(BondExists(res.FindAtom("N1"), - res.FindAtom("C2"))); - BOOST_CHECK(BondExists(res.FindAtom("C2"), - res.FindAtom("O2"))); - BOOST_CHECK(BondExists(res.FindAtom("C2"), - res.FindAtom("N3"))); - BOOST_CHECK(BondExists(res.FindAtom("N3"), - res.FindAtom("C4"))); - BOOST_CHECK(BondExists(res.FindAtom("C4"), - res.FindAtom("O4"))); - BOOST_CHECK(BondExists(res.FindAtom("C4"), - res.FindAtom("C5"))); - BOOST_CHECK(BondExists(res.FindAtom("C5"), - res.FindAtom("C6"))); - BOOST_CHECK(BondExists(res.FindAtom("C6"), - res.FindAtom("N1"))); - // TODO: Check that no other atoms are connected! - } -} -void verify_nucleotide_link(const ResidueHandle& p3, const ResidueHandle& p5) -{ - BOOST_CHECK(BondExists(p3.FindAtom("O3'"), - p5.FindAtom("P"))); -} - -void verify_nucleotide_nolink(const ResidueHandle& p3, const ResidueHandle& p5) -{ - BOOST_CHECK(!BondExists(p3.FindAtom("O3'"), - p5.FindAtom("P"))); -} - -BOOST_AUTO_TEST_SUITE( conop ); - - -BOOST_AUTO_TEST_CASE(nucleotide_based_connect) -{ - SetPrefixPath(getenv("OST_ROOT")); - String lib_path=GetSharedDataPath()+"/compounds.chemlib"; - CompoundLibPtr compound_lib=CompoundLib::Load(lib_path); - if (!compound_lib) { - std::cout << "WARNING: skipping NUCLEOTIDE_BASED connect unit test. " - << "Rule-based builder is required" << std::endl; - return; - } - RuleBasedBuilder rb_builder = RuleBasedBuilder(compound_lib); - - RuleBasedBuilder drb_builder = RuleBasedBuilder(compound_lib); - drb_builder.SetBondFeasibilityCheck(false); - - EntityHandle e=CreateEntity(); - ChainHandle c=e.EditXCS().InsertChain("A"); - ResidueHandle c0=make_cytosine(c); - ResidueHandle u1=make_uracil1(c); - ResidueHandle u2=make_uracil2(c); - - EntityHandle de=CreateEntity(); - ChainHandle dc=de.EditXCS().InsertChain("A"); - ResidueHandle du2=make_defective_uracil2(dc); - - - for (AtomHandleIter i=e.AtomsBegin(),x=e.AtomsEnd(); i!=x; ++i) { - rb_builder.FillAtomProps(*i); - } - - for (AtomHandleIter i=de.AtomsBegin(),x=de.AtomsEnd(); i!=x; ++i) { - drb_builder.FillAtomProps(*i); - } - - // running positive test - BOOST_MESSAGE("running distance based checks on cytosine"); - rb_builder.ConnectAtomsOfResidue(c0); - verify_nucleotide_connectivity(c0); - BOOST_MESSAGE("running distance based checks on first uracil"); - rb_builder.ConnectAtomsOfResidue(u1); - verify_nucleotide_connectivity(u1); - BOOST_MESSAGE("running distance based checks on second uracil"); - rb_builder.ConnectAtomsOfResidue(u2); - verify_nucleotide_connectivity(u2); - BOOST_MESSAGE("connecting cytosine to first uracil"); - rb_builder.ConnectResidueToNext(c0, u1); - verify_nucleotide_link(c0, u1); - BOOST_MESSAGE("connecting first uracil to second uracil"); - rb_builder.ConnectResidueToNext(u1, u2); - verify_nucleotide_link(u1, u2); - // one negative test - BOOST_MESSAGE("connecting cytosine to second uracil"); - rb_builder.ConnectResidueToNext(c0, u2); - verify_nucleotide_nolink(c0, u2); - - // running positive test - BOOST_MESSAGE("running distance based checks on defective uracil"); - drb_builder.ConnectAtomsOfResidue(du2); - verify_nucleotide_connectivity(du2); - -} - -BOOST_AUTO_TEST_CASE(rule_based_connect_1zk) -{ - SetPrefixPath(getenv("OST_ROOT")); - String lib_path=GetSharedDataPath()+"/compounds.chemlib"; - CompoundLibPtr compound_lib=CompoundLib::Load(lib_path); - if (!compound_lib) { - std::cout << "WARNING: skipping NUCLEOTIDE_BASED connect unit test. " - << "Rule-based builder is required" << std::endl; - return; - } - - boost::shared_ptr<RuleBasedBuilder> drb_builder(new RuleBasedBuilder(compound_lib)); - Conopology::Instance().RegisterBuilder(drb_builder, "RBB"); - Conopology::Instance().SetDefaultBuilder("RBB"); - drb_builder->SetBondFeasibilityCheck(false); - EntityHandle e=CreateEntity(); - ChainHandle c=e.EditXCS().InsertChain("A"); - ResidueHandle r1=make_1zk(c); - Conopology::Instance().ConnectAll(drb_builder, e); - Conopology::Instance().SetDefaultBuilder("HEURISTIC"); - verify_1zk_connectivity(r1); -} - -BOOST_AUTO_TEST_SUITE_END( );