Chemical Data Processing Library C++ API - Version 1.4.0
BondStereoFlagCalculator.hpp
Go to the documentation of this file.
1 /*
2  * BondStereoFlagCalculator.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_BONDSTEREOFLAGCALCULATOR_HPP
30 #define CDPL_CHEM_BONDSTEREOFLAGCALCULATOR_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <utility>
35 #include <memory>
36 #include <functional>
37 
38 #include "CDPL/Chem/APIPrefix.hpp"
39 #include "CDPL/Util/BitSet.hpp"
40 #include "CDPL/Util/Array.hpp"
42 
43 
44 namespace CDPL
45 {
46 
47  namespace Chem
48  {
49 
50  class MolecularGraph;
51  class Atom;
52  class Bond;
53 
63  {
64 
65  public:
69  typedef std::function<const Math::Vector2D&(const Atom&)> Atom2DCoordinatesFunction;
70 
75 
87 
89 
91 
97 
103 
113  void calculate(const MolecularGraph& molgraph, Util::UIArray& flags);
114 
115  private:
116  class StereoAtomInfo;
117 
118  void init(const MolecularGraph&, Util::UIArray&);
119 
120  void assignStereoFlags(Util::UIArray&);
121 
122  void assignFlagsForEitherDoubleBonds(Util::UIArray&);
123  void assignFlagsForIsolatedCenter(const StereoAtomInfo*, Util::UIArray&);
124  bool assignFlagsForNonIsolatedCenters(std::size_t, std::size_t, Util::UIArray&);
125 
126  void switchStereoFlag(std::size_t);
127 
128  class StereoAtomInfo
129  {
130 
131  public:
132  typedef std::shared_ptr<StereoAtomInfo> SharedPointer;
133 
134  StereoAtomInfo(const MolecularGraph*, const Atom2DCoordinatesFunction& coords_func,
135  const Atom*, unsigned int, std::size_t, const Atom**, const Bond**);
136 
137  unsigned int getConfiguration() const;
138 
139  void findBestBondOrder(const Util::BitSet&, const Util::BitSet&);
140 
141  bool hasStereoAtomNbrs() const;
142 
143  bool configMatches(const Util::UIArray&) const;
144 
145  std::size_t getNumBonds() const;
146 
147  std::size_t getBondIndex(std::size_t) const;
148  std::size_t getNbrAtomIndex(std::size_t) const;
149 
150  std::size_t getAtomIndex() const;
151 
152  private:
153  typedef std::pair<const Atom*, std::size_t> Ligand;
154 
155  const MolecularGraph* molGraph;
156  const Atom* atom;
157  unsigned int configuration;
158  std::size_t numBonds;
159  bool hasStereoNbrs;
160  double configCalcTerms[4];
161  bool bondEndFlags[4];
162  Ligand ligands[4];
163  Ligand orderedLigands[4];
164  };
165 
166  typedef std::vector<StereoAtomInfo*> StereoAtomInfoList;
167  typedef std::vector<StereoAtomInfo::SharedPointer> StereoAtomInfoPtrTable;
168  typedef std::vector<const Bond*> BondList;
169 
170  const MolecularGraph* molGraph;
171  Atom2DCoordinatesFunction coordsFunc;
172  Util::UIArray currentStereoFlags;
173  StereoAtomInfoPtrTable stereoAtomTable;
174  StereoAtomInfoList stereoAtomList;
175  BondList eitherBondList;
176  Util::BitSet stereoAtomMask;
177  Util::BitSet configMatchMask;
178  Util::BitSet stereoDBAtomMask;
179  Util::BitSet ringBondMask;
180  Util::BitSet singleBondMask;
181  std::size_t numMismatchingCtrs;
182  std::size_t minNumMismatchingCtrs;
183  };
184  } // namespace Chem
185 } // namespace CDPL
186 
187 #endif // CDPL_CHEM_BONDSTEREOFLAGCALCULATOR_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 class CDPL::Math::VectorArray.
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:57
Calculator that derives 2D wedge/hash bond stereo flags from atom 2D coordinates and stereochemical d...
Definition: BondStereoFlagCalculator.hpp:63
BondStereoFlagCalculator(const MolecularGraph &molgraph, Util::UIArray &flags)
Constructs the BondStereoFlagCalculator instance and calculates the 2D stereo flags of the bonds in t...
BondStereoFlagCalculator(const BondStereoFlagCalculator &)=delete
const Atom2DCoordinatesFunction & getAtom2DCoordinatesFunction() const
Returns the function that was registered for the retrieval of atom 2D-coordinates.
BondStereoFlagCalculator & operator=(const BondStereoFlagCalculator &)=delete
BondStereoFlagCalculator()
Constructs the BondStereoFlagCalculator instance.
std::function< const Math::Vector2D &(const Atom &)> Atom2DCoordinatesFunction
Type of the generic functor class used to store a user-defined atom 2D-coordinates function.
Definition: BondStereoFlagCalculator.hpp:69
void setAtom2DCoordinatesFunction(const Atom2DCoordinatesFunction &func)
Specifies a function for the retrieval of atom 2D-coordinates.
void calculate(const MolecularGraph &molgraph, Util::UIArray &flags)
Calculates the 2D stereo flags of the bonds in the molecular graph molgraph.
Abstract base class representing a chemical bond between two Chem::Atom instances.
Definition: Bond.hpp:54
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
CVector< double, 2 > Vector2D
Bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:2932
Array< unsigned int > UIArray
Array storing unsigned integers of type unsigned int.
Definition: Array.hpp:570
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.