Chemical Data Processing Library C++ API - Version 1.2.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 
58  {
59 
60  public:
61  typedef std::function<const Math::Vector2D&(const Atom&)> Atom2DCoordinatesFunction;
62 
67 
79 
81 
83 
89 
95 
105  void calculate(const MolecularGraph& molgraph, Util::UIArray& flags);
106 
107  private:
108  class StereoAtomInfo;
109 
110  void init(const MolecularGraph&, Util::UIArray&);
111 
112  void assignStereoFlags(Util::UIArray&);
113 
114  void assignFlagsForEitherDoubleBonds(Util::UIArray&);
115  void assignFlagsForIsolatedCenter(const StereoAtomInfo*, Util::UIArray&);
116  bool assignFlagsForNonIsolatedCenters(std::size_t, std::size_t, Util::UIArray&);
117 
118  void switchStereoFlag(std::size_t);
119 
120  class StereoAtomInfo
121  {
122 
123  public:
124  typedef std::shared_ptr<StereoAtomInfo> SharedPointer;
125 
126  StereoAtomInfo(const MolecularGraph*, const Atom2DCoordinatesFunction& coords_func,
127  const Atom*, unsigned int, std::size_t, const Atom**, const Bond**);
128 
129  unsigned int getConfiguration() const;
130 
131  void findBestBondOrder(const Util::BitSet&, const Util::BitSet&);
132 
133  bool hasStereoAtomNbrs() const;
134 
135  bool configMatches(const Util::UIArray&) const;
136 
137  std::size_t getNumBonds() const;
138 
139  std::size_t getBondIndex(std::size_t) const;
140  std::size_t getNbrAtomIndex(std::size_t) const;
141 
142  std::size_t getAtomIndex() const;
143 
144  private:
145  typedef std::pair<const Atom*, std::size_t> Ligand;
146 
147  const MolecularGraph* molGraph;
148  const Atom* atom;
149  unsigned int configuration;
150  std::size_t numBonds;
151  bool hasStereoNbrs;
152  double configCalcTerms[4];
153  bool bondEndFlags[4];
154  Ligand ligands[4];
155  Ligand orderedLigands[4];
156  };
157 
158  typedef std::vector<StereoAtomInfo*> StereoAtomInfoList;
159  typedef std::vector<StereoAtomInfo::SharedPointer> StereoAtomInfoPtrTable;
160  typedef std::vector<const Bond*> BondList;
161 
162  const MolecularGraph* molGraph;
163  Atom2DCoordinatesFunction coordsFunc;
164  Util::UIArray currentStereoFlags;
165  StereoAtomInfoPtrTable stereoAtomTable;
166  StereoAtomInfoList stereoAtomList;
167  BondList eitherBondList;
168  Util::BitSet stereoAtomMask;
169  Util::BitSet configMatchMask;
170  Util::BitSet stereoDBAtomMask;
171  Util::BitSet ringBondMask;
172  Util::BitSet singleBondMask;
173  std::size_t numMismatchingCtrs;
174  std::size_t minNumMismatchingCtrs;
175  };
176  } // namespace Chem
177 } // namespace CDPL
178 
179 #endif // CDPL_CHEM_BONDSTEREOFLAGCALCULATOR_HPP
Definition of the class CDPL::Util::Array.
Definition of the 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 the class CDPL::Math::VectorArray.
Atom.
Definition: Atom.hpp:52
BondStereoFlagCalculator.
Definition: BondStereoFlagCalculator.hpp:58
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
Definition: BondStereoFlagCalculator.hpp:61
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.
Bond.
Definition: Bond.hpp:50
MolecularGraph.
Definition: MolecularGraph.hpp:52
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
Array< unsigned int > UIArray
An array of unsigned integers.
Definition: Array.hpp:562
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.