Chemical Data Processing Library C++ API - Version 1.4.0
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 
64  {
65 
66  public:
71 
83  BondOrderCalculator(const MolecularGraph& molgraph, Util::STArray& orders, bool undef_only = true);
84 
90  void undefinedOnly(bool undef_only);
91 
96  bool undefinedOnly() const;
97 
108  void calculate(const MolecularGraph& molgraph, Util::STArray& orders);
109 
110  private:
111  enum Geometry
112  {
113 
114  UNDEF,
115  TERMINAL,
116  LINEAR,
117  TRIG_PLANAR,
119  };
120 
121  typedef std::shared_ptr<MolecularGraph> MolecularGraphPtr;
122  typedef std::shared_ptr<SubstructureSearch> SubstructureSearchPtr;
123  typedef std::vector<const Bond*> BondList;
124  typedef std::vector<const Atom*> AtomList;
125  typedef std::vector<std::size_t> UIntTable;
126  typedef std::vector<Geometry> GeometryTable;
127  typedef std::vector<MolecularGraphPtr> MolecularGraphPtrList;
128  typedef std::vector<std::pair<double, const AtomBondMapping*> > ABMappingList;
129 
130  class AtomMatchExpression;
131  class BondMatchExpression;
132 
133  friend class BondMatchExpression;
134 
135  void init(const MolecularGraph& molgraph, Util::STArray& orders);
136 
137  void calcFreeAtomValences(Util::STArray& orders);
138  void perceiveAtomGeometries(Util::STArray& orders);
139  void assignBondOrders(Util::STArray& orders);
140 
141  void assignTetrahedralAtomBondOrders(Util::STArray& orders);
142  void assignFunctionalGroupBondOrders(Util::STArray& orders);
143  void assignConjPiSystemBondOrders(Util::STArray& orders);
144  void assignRemainingBondOrders(Util::STArray& orders);
145  void fixNitroGroups(Util::STArray& orders);
146 
147  void assignFragBondOrders(std::size_t depth, Util::STArray& orders);
148 
149  double calcHybridizationMatchScore();
150  double calcMappingScore(const AtomBondMapping& mapping) const;
151 
152  void markPlanarPiBonds(Util::STArray& orders);
153 
154  Geometry perceiveInitialGeometry(const Atom& atom);
155  void fixRingAtomGeometries(const Fragment& ring);
156  void postprocessGeometry(const Atom& atom, Util::STArray& orders);
157 
158  void assignNbrBondOrders(const Atom& atom, Util::STArray& orders);
159 
160  void getNeighborAtoms(const Atom& atom, AtomList& atom_list, const Atom* exclude_atom) const;
161  std::size_t countBondsWithOrder(const Atom& atom, std::size_t order, const UIntTable& order_table) const;
162 
163  template <typename Pred>
164  void getUndefBondFragment(const Atom& atom, bool add_atoms, const Pred& bond_pred);
165 
166  double calcAvgBondAngle(const Atom& atom, const AtomList& nbr_atoms) const;
167  double calcDihedralAngle(const Atom& atom1, const Atom& atom2, const Atom& atom3, const Atom& atom4) const;
168  double calcDihedralAngle(const Math::Vector3D& atom1_pos, const Math::Vector3D& atom2_pos,
169  const Math::Vector3D& atom3_pos, const Math::Vector3D& atom4_pos) const;
170  double calcAvgTorsionAngle(const Fragment& ring) const;
171 
172  bool isPlanarPiBond(const Bond& bond) const;
173 
174  const MolecularGraph* molGraph;
175  bool undefOnly;
176  Util::BitSet defOrderMask;
177  Util::BitSet multibondAtomMask;
178  UIntTable freeAtomValences;
179  GeometryTable atomGeometries;
180  BondList undefBonds;
181  BondList fragBondList;
182  AtomList fragAtomList;
183  AtomList nbrAtomList1;
184  AtomList nbrAtomList2;
185  UIntTable fragBondOrders;
186  UIntTable workingBondOrders;
187  double currOrderAssmentScore;
188  double bestOrderAssmentScore;
189  SubstructureSearchPtr substructSearch;
190  MolecularGraphPtrList funcGroupPatterns;
191  ABMappingList funcGroupMappings;
192  Util::BitSet procMappingMask;
193  Util::BitSet bondMappingMask1;
194  Util::BitSet bondMappingMask2;
195  Util::BitSet planarPiBondMask;
196  };
197  } // namespace Chem
198 } // namespace CDPL
199 
200 #endif // CDPL_CHEM_BONDORDERCALCULATOR_HPP
Definition of class CDPL::Util::Array.
Declaration of type CDPL::Util::BitSet.
Definition of the preprocessor macro CDPL_CHEM_API.
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
Definition of vector data types.
Data structure for the common storage of related atom to atom and bond to bond mappings.
Definition: AtomBondMapping.hpp:55
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:58
Perceives bond orders of a molecular graph from its 3D structure and atom connectivity.
Definition: BondOrderCalculator.hpp:64
bool undefinedOnly() const
Tells whether or not only undefined bond orders have to be perceived.
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...
void undefinedOnly(bool undef_only)
Allows to specify whether already defined bond orders should be left unchanged.
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...
BondOrderCalculator()
Constructs the BondOrderCalculator instance.
Abstract base class representing a chemical bond between two atoms (represented by Chem::Atom instanc...
Definition: Bond.hpp:54
Concrete implementation of the Chem::MolecularGraph interface that stores references to selectable Ch...
Definition: Fragment.hpp:60
Abstract base class for data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
constexpr unsigned int UNDEF
Specifies that the data format version is undefined.
Definition: PDBFormatVersion.hpp:49
CVector< double, 3 > Vector3D
Bounded 3 element vector holding floating-point values of type double.
Definition: Vector.hpp:3218
constexpr unsigned int LINEAR
Specifies linear geometry.
Definition: CoordinationGeometry.hpp:58
constexpr unsigned int TETRAHEDRAL
Specifies tetrahedral geometry.
Definition: CoordinationGeometry.hpp:68
Array< std::size_t > STArray
Array storing unsigned integers of type std::size_t.
Definition: Array.hpp:578
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.