Chemical Data Processing Library C++ API - Version 1.1.1
BondOrderCalculator.hpp
Go to the documentation of this file.
1 /*
2  * BondOrderCalculator.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_CHEM_BONDORDERCALCULATOR_HPP
30 #define CDPL_CHEM_BONDORDERCALCULATOR_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <utility>
35 #include <memory>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
38 #include "CDPL/Math/Vector.hpp"
39 #include "CDPL/Util/Array.hpp"
40 #include "CDPL/Util/BitSet.hpp"
41 
42 
43 namespace CDPL
44 {
45 
46  namespace Chem
47  {
48 
49  class SubstructureSearch;
50  class Fragment;
51  class MolecularGraph;
52  class Atom;
53  class Bond;
54  class AtomBondMapping;
55 
60  {
61 
62  public:
67 
77  BondOrderCalculator(const MolecularGraph& molgraph, Util::STArray& orders, bool undef_only = true);
78 
84  void undefinedOnly(bool undef_only);
85 
90  bool undefinedOnly() const;
91 
100  void calculate(const MolecularGraph& molgraph, Util::STArray& orders);
101 
102  private:
103  enum Geometry
104  {
105 
106  UNDEF,
107  TERMINAL,
108  LINEAR,
109  TRIG_PLANAR,
111  };
112 
113  typedef std::shared_ptr<MolecularGraph> MolecularGraphPtr;
114  typedef std::shared_ptr<SubstructureSearch> SubstructureSearchPtr;
115  typedef std::vector<const Bond*> BondList;
116  typedef std::vector<const Atom*> AtomList;
117  typedef std::vector<std::size_t> UIntTable;
118  typedef std::vector<Geometry> GeometryTable;
119  typedef std::vector<MolecularGraphPtr> MolecularGraphPtrList;
120  typedef std::vector<std::pair<double, const AtomBondMapping*> > ABMappingList;
121 
122  class AtomMatchExpression;
123  class BondMatchExpression;
124 
125  friend class BondMatchExpression;
126 
127  void init(const MolecularGraph& molgraph, Util::STArray& orders);
128 
129  void calcFreeAtomValences(Util::STArray& orders);
130  void perceiveAtomGeometries(Util::STArray& orders);
131  void assignBondOrders(Util::STArray& orders);
132 
133  void assignTetrahedralAtomBondOrders(Util::STArray& orders);
134  void assignFunctionalGroupBondOrders(Util::STArray& orders);
135  void assignConjPiSystemBondOrders(Util::STArray& orders);
136  void assignRemainingBondOrders(Util::STArray& orders);
137  void fixNitroGroups(Util::STArray& orders);
138 
139  void assignFragBondOrders(std::size_t depth, Util::STArray& orders);
140 
141  double calcHybridizationMatchScore();
142  double calcMappingScore(const AtomBondMapping& mapping) const;
143 
144  void markPlanarPiBonds(Util::STArray& orders);
145 
146  Geometry perceiveInitialGeometry(const Atom& atom);
147  void fixRingAtomGeometries(const Fragment& ring);
148  void postprocessGeometry(const Atom& atom, Util::STArray& orders);
149 
150  void assignNbrBondOrders(const Atom& atom, Util::STArray& orders);
151 
152  void getNeighborAtoms(const Atom& atom, AtomList& atom_list, const Atom* exclude_atom) const;
153  std::size_t countBondsWithOrder(const Atom& atom, std::size_t order, const UIntTable& order_table) const;
154 
155  template <typename Pred>
156  void getUndefBondFragment(const Atom& atom, bool add_atoms, const Pred& bond_pred);
157 
158  double calcAvgBondAngle(const Atom& atom, const AtomList& nbr_atoms) const;
159  double calcDihedralAngle(const Atom& atom1, const Atom& atom2, const Atom& atom3, const Atom& atom4) const;
160  double calcDihedralAngle(const Math::Vector3D& atom1_pos, const Math::Vector3D& atom2_pos,
161  const Math::Vector3D& atom3_pos, const Math::Vector3D& atom4_pos) const;
162  double calcAvgTorsionAngle(const Fragment& ring) const;
163 
164  bool isPlanarPiBond(const Bond& bond) const;
165 
166  const MolecularGraph* molGraph;
167  bool undefOnly;
168  Util::BitSet defOrderMask;
169  Util::BitSet multibondAtomMask;
170  UIntTable freeAtomValences;
171  GeometryTable atomGeometries;
172  BondList undefBonds;
173  BondList fragBondList;
174  AtomList fragAtomList;
175  AtomList nbrAtomList1;
176  AtomList nbrAtomList2;
177  UIntTable fragBondOrders;
178  UIntTable workingBondOrders;
179  double currOrderAssmentScore;
180  double bestOrderAssmentScore;
181  SubstructureSearchPtr substructSearch;
182  MolecularGraphPtrList funcGroupPatterns;
183  ABMappingList funcGroupMappings;
184  Util::BitSet procMappingMask;
185  Util::BitSet bondMappingMask1;
186  Util::BitSet bondMappingMask2;
187  Util::BitSet planarPiBondMask;
188  };
189  } // namespace Chem
190 } // namespace CDPL
191 
192 #endif // CDPL_CHEM_BONDORDERCALCULATOR_HPP
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::BondOrderCalculator::calculate
void calculate(const MolecularGraph &molgraph, Util::STArray &orders)
Perceives the order of the bonds in the molecular graph molgraph from its 3D structure and atom conne...
CDPL::Math::Vector3D
CVector< double, 3 > Vector3D
A bounded 3 element vector holding floating point values of type double.
Definition: Vector.hpp:1637
CDPL::Chem::BondOrderCalculator::BondOrderCalculator
BondOrderCalculator()
Constructs the BondOrderCalculator instance.
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::Fragment
Fragment.
Definition: Fragment.hpp:52
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
Array.hpp
Definition of the class CDPL::Util::Array.
CDPL::Biomol::PDBFormatVersion::UNDEF
const unsigned int UNDEF
Specifies that the data format version is undefined.
Definition: PDBFormatVersion.hpp:49
CDPL::Chem::BondOrderCalculator
BondOrderCalculator.
Definition: BondOrderCalculator.hpp:60
CDPL::Chem::BondOrderCalculator::undefinedOnly
bool undefinedOnly() const
Tells whether or not only undefined bond orders have to be perceived.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Util::STArray
Array< std::size_t > STArray
An array of unsigned integers of type std::size_t.
Definition: Array.hpp:567
CDPL::MolProp::CoordinationGeometry::LINEAR
const unsigned int LINEAR
Specifies linear geometry.
Definition: CoordinationGeometry.hpp:58
CDPL::Chem::AtomBondMapping
A data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
CDPL::Chem::BondOrderCalculator::undefinedOnly
void undefinedOnly(bool undef_only)
Allows to specify whether already defined bond orders should be left unchanged.
CDPL::MolProp::CoordinationGeometry::TETRAHEDRAL
const unsigned int TETRAHEDRAL
Specifies tetrahedral geometry.
Definition: CoordinationGeometry.hpp:68
Vector.hpp
Definition of vector data types.
CDPL::Chem::BondOrderCalculator::BondOrderCalculator
BondOrderCalculator(const MolecularGraph &molgraph, Util::STArray &orders, bool undef_only=true)
Constructs the BondOrderCalculator instance and perceives the order of the bonds in the molecular gra...