Chemical Data Processing Library C++ API - Version 1.0.0
BondDirectionCalculator.hpp
Go to the documentation of this file.
1 /*
2  * BondDirectionGenerator.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_BONDDIRECTIONCALCULATOR_HPP
30 #define CDPL_CHEM_BONDDIRECTIONCALCULATOR_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 
35 #include "CDPL/Chem/APIPrefix.hpp"
36 #include "CDPL/Util/Array.hpp"
37 #include "CDPL/Util/BitSet.hpp"
38 
39 
40 namespace CDPL
41 {
42 
43  namespace Chem
44  {
45 
46  class MolecularGraph;
47  class Atom;
48  class Bond;
49 
55  {
56 
57  public:
62 
74 
82  void includeRingBonds(bool include);
83 
90  bool ringBondsIncluded() const;
91 
99  void setRingSizeLimit(std::size_t min_size);
100 
106  std::size_t getRingSizeLimit() const;
107 
118  void calculate(const MolecularGraph& molgraph, Util::UIArray& dirs);
119 
120  private:
121  class StereoBond;
122 
123  class StereoBondOrderingFunction
124  {
125 
126  public:
127  StereoBondOrderingFunction(const BondDirectionCalculator& gen):
128  calculator(gen) {}
129 
130  bool operator()(const StereoBond*, const StereoBond*) const;
131 
132  private:
133  const BondDirectionCalculator& calculator;
134  };
135 
136  BondDirectionCalculator(const BondDirectionCalculator&);
137 
138  BondDirectionCalculator& operator=(const BondDirectionCalculator&);
139 
140  void init(const MolecularGraph&, Util::UIArray&);
141 
142  bool assignDirections(std::size_t, Util::UIArray&);
143 
144  void switchDirection(unsigned int&);
145 
146  class StereoBond
147  {
148 
149  public:
150  StereoBond(const Bond&);
151 
152  const Bond& getBond() const;
153 
154  unsigned int getConfiguration() const;
155  void setConfiguration(unsigned int);
156 
157  void setConfigRefBondIndex(std::size_t, std::size_t);
158 
159  std::size_t getNumNeighbors(std::size_t) const;
160 
161  std::size_t getNeighborBondIndex(std::size_t, std::size_t) const;
162  std::size_t getNeighborAtomIndex(std::size_t, std::size_t) const;
163 
164  void addNeighborIndices(std::size_t, std::size_t, std::size_t);
165 
166  bool hasDirBonds(const Util::UIArray&, std::size_t) const;
167 
168  bool configMatches(const Util::UIArray&) const;
169 
170  private:
171  const Bond* bond;
172  std::size_t nbrBondCounts[2];
173  std::size_t nbrAtomIndices[2][2];
174  std::size_t nbrBondIndices[2][2];
175  unsigned int configuration;
176  };
177 
178  typedef std::vector<StereoBond> StereoBondArray;
179  typedef std::vector<StereoBond*> StereoBondPtrArray;
180 
181  const MolecularGraph* molGraph;
182  bool incRingBonds;
183  std::size_t minRingSize;
184  StereoBondArray stereoBonds;
185  StereoBondPtrArray orderedStereoBonds;
186  StereoBondPtrArray atomStereoBondTable;
187  Util::UIArray workingDirs;
188  Util::BitSet configMatchMask;
189  std::size_t numMismatches;
190  std::size_t minNumMismatches;
191  std::size_t numDirBonds;
192  std::size_t minNumDirBonds;
193  };
194  } // namespace Chem
195 } // namespace CDPL
196 
197 #endif // CDPL_CHEM_BONDDIRECTIONCALCULATOR_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::BondDirectionCalculator::setRingSizeLimit
void setRingSizeLimit(std::size_t min_size)
Sets the minimum ring size that is required for ring double bonds to be considered in the performed b...
CDPL::Chem::BondDirectionCalculator::calculate
void calculate(const MolecularGraph &molgraph, Util::UIArray &dirs)
Calculates direction flags for a minimum set of directional bonds that unambiguously define the confi...
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
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::Chem::BondDirectionCalculator::BondDirectionCalculator
BondDirectionCalculator()
Construcst the BondDirectionCalculator instance.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::BondDirectionCalculator::includeRingBonds
void includeRingBonds(bool include)
Allows to specify whether or not the configuration of ring double bonds shall also be regarded in the...
CDPL::Chem::BondDirectionCalculator
BondDirectionCalculator.
Definition: BondDirectionCalculator.hpp:55
CDPL::Chem::BondDirectionCalculator::getRingSizeLimit
std::size_t getRingSizeLimit() const
Returns the minimum ring size that is required for ring double bonds to be considered in the performe...
CDPL::Chem::BondDirectionCalculator::ringBondsIncluded
bool ringBondsIncluded() const
Tells whether the configuration of ring double bonds is also regarded in the performed bond direction...
CDPL::Util::UIArray
Array< unsigned int > UIArray
An array of unsigned integers.
Definition: Array.hpp:562
CDPL::Chem::BondDirectionCalculator::BondDirectionCalculator
BondDirectionCalculator(const MolecularGraph &molgraph, Util::UIArray &dirs)
Constructs the BondDirectionCalculator instance and calculates direction flags for a minimum set of d...