Chemical Data Processing Library C++ API - Version 1.4.0
TautomerGenerator.hpp
Go to the documentation of this file.
1 /*
2  * TautomerGenerator.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_TAUTOMERGENERATOR_HPP
30 #define CDPL_CHEM_TAUTOMERGENERATOR_HPP
31 
32 #include <vector>
33 #include <cstddef>
34 #include <cstdint>
35 #include <unordered_set>
36 #include <array>
37 #include <memory>
38 #include <functional>
39 
40 #include "CDPL/Chem/APIPrefix.hpp"
46 #include "CDPL/Util/ObjectPool.hpp"
47 
48 
49 namespace CDPL
50 {
51 
52  namespace Chem
53  {
54 
66  {
67 
68  public:
72  enum Mode
73  {
74 
80  EXHAUSTIVE
81  };
82 
84  typedef std::shared_ptr<TautomerGenerator> SharedPointer;
85 
87  typedef std::function<bool(MolecularGraph&)> CallbackFunction;
89  typedef std::function<void(MolecularGraph&)> CustomSetupFunction;
90 
95 
101 
105  virtual ~TautomerGenerator() {}
106 
113 
119 
127 
133  void removeTautomerizationRule(std::size_t idx);
134 
139  std::size_t getNumTautomerizationRules() const;
140 
150 
156 
161  void setMode(Mode mode);
162 
167  Mode getMode() const;
168 
173  void regardStereochemistry(bool regard);
174 
180 
185  void regardIsotopes(bool regard);
186 
191  bool isotopesRegarded() const;
192 
198  void clearCoordinates2D(bool clear);
199 
205  bool coordinates2DCleared() const;
206 
212  void clearCoordinates3D(bool clear);
213 
219  bool coordinates3DCleared() const;
220 
226  void removeResonanceDuplicates(bool remove);
227 
234 
240 
245  void generate(const MolecularGraph& molgraph);
246 
247  private:
249  typedef MoleculeCache::SharedObjectPointer MoleculePtr;
250 
251  bool init(const MolecularGraph& molgraph);
252  void initHashCalculator();
253 
254  MoleculePtr copyInputMolGraph(const MolecularGraph& molgraph);
255 
256  void extractStereoCenters(const MolecularGraph& molgraph);
257  void extractAtomStereoCenters(const MolecularGraph& molgraph);
258  void extractBondStereoCenters(const MolecularGraph& molgraph);
259 
260  bool addNewTautomer(const MoleculePtr& mol_ptr);
261  bool outputTautomer(const MoleculePtr& mol_ptr);
262 
263  std::uint64_t calcConTabHashCode(const MolecularGraph& molgraph, bool arom_bonds);
264 
265  void generateSSSR(MolecularGraph& molgraph);
266  void setAromaticityFlags(MolecularGraph& molgraph);
267  void calcCIPConfigurations(MolecularGraph& molgraph);
268 
269  typedef std::array<std::size_t, 3> BondDescriptor;
270  typedef std::vector<MoleculePtr> MoleculeList;
271  typedef std::vector<TautomerizationRule::SharedPointer> TautRuleList;
272  typedef std::vector<BondDescriptor> BondDescrArray;
273  typedef std::vector<std::size_t> SizeTArray;
274  typedef std::unordered_set<std::uint64_t> HashCodeSet;
275  typedef std::array<std::size_t, 6> StereoCenter;
276  typedef std::vector<StereoCenter> StereoCenterList;
277 
278  MoleculeCache molCache;
279  CallbackFunction callbackFunc;
280  Mode mode;
281  bool regStereo;
282  bool regIsotopes;
283  bool remResDuplicates;
284  bool clear2DCoords;
285  bool clear3DCoords;
286  CustomSetupFunction customSetupFunc;
287  TautRuleList tautRules;
288  MoleculeList currGeneration;
289  MoleculeList nextGeneration;
290  StereoCenterList atomStereoCenters;
291  StereoCenterList bondStereoCenters;
292  HashCodeSet intermTautHashCodes;
293  HashCodeSet outputTautHashCodes;
294  HashCodeCalculator hashCalculator;
295  AromaticSubstructure aromSubstruct;
296  CIPConfigurationLabeler cipLabeler;
297  BondDescrArray tautomerBonds;
298  SizeTArray shaInput;
299  const MolecularGraph* molGraph;
300  };
301  } // namespace Chem
302 } // namespace CDPL
303 
304 #endif // CDPL_CHEM_TAUTOMERGENERATOR_HPP
Definition of class CDPL::Chem::AromaticSubstructure.
Definition of class CDPL::Chem::BasicMolecule.
Definition of class CDPL::Chem::CIPConfigurationLabeler.
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::Chem::HashCodeCalculator.
Definition of class CDPL::Util::ObjectPool.
Definition of class CDPL::Chem::TautomerizationRule.
Implements the perception of aromatic atoms and bonds in a molecular graph.
Definition: AromaticSubstructure.hpp:52
Assigns Cahn-Ingold-Prelog (CIP) configuration labels to stereogenic atoms and bonds of a molecular g...
Definition: CIPConfigurationLabeler.hpp:60
Computes a 64-bit hash code that identifies a molecular graph up to a configurable set of atom and bo...
Definition: HashCodeCalculator.hpp:67
Abstract base class for representations of a chemical structure as a graph of bonded atoms.
Definition: MolecularGraph.hpp:57
Enumerates the tautomers of a molecular graph by iteratively applying a configurable set of Chem::Tau...
Definition: TautomerGenerator.hpp:66
std::shared_ptr< TautomerGenerator > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated TautomerGenerator instances.
Definition: TautomerGenerator.hpp:84
bool coordinates3DCleared() const
Tells whether 3D atom coordinates are cleared from the generated tautomers.
bool resonanceDuplicatesRemoved() const
Tells whether resonance-only duplicates are filtered out.
void setCallbackFunction(const CallbackFunction &func)
Sets the callback invoked for every accepted output tautomer.
TautomerGenerator()
Constructs the TautomerGenerator instance.
bool isotopesRegarded() const
Tells whether atom isotope information is regarded by the tautomer duplicate detection algorithm.
std::size_t getNumTautomerizationRules() const
Returns the number of registered tautomerization rules.
virtual ~TautomerGenerator()
Virtual destructor.
Definition: TautomerGenerator.hpp:105
bool stereochemistryRegarded() const
Tells whether atom/bond stereochemistry is regarded by the tautomer duplicate detection algorithm.
void clearCoordinates3D(bool clear)
Specifies whether 3D atom coordinates shall be cleared from the generated tautomers.
void regardStereochemistry(bool regard)
Specifies whether atom/bond stereochemistry shall be regarded by the tautomer duplicate detection alg...
TautomerGenerator(const TautomerGenerator &gen)
Constructs a copy of the TautomerGenerator instance gen.
std::function< bool(MolecularGraph &)> CallbackFunction
Type of the callback invoked for every generated tautomer (returning false aborts the enumeration).
Definition: TautomerGenerator.hpp:87
const TautomerizationRule::SharedPointer & getTautomerizationRule(std::size_t idx) const
Returns the registered tautomerization rule at index idx.
void generate(const MolecularGraph &molgraph)
Enumerates the tautomers of molgraph and reports each accepted one to the registered callback.
void removeResonanceDuplicates(bool remove)
Specifies whether tautomers that differ only by resonance (no atom-connectivity change) shall be filt...
void removeTautomerizationRule(std::size_t idx)
Removes the registered tautomerization rule at index idx.
Mode
Constants specifying the output tautomer filtering strategy.
Definition: TautomerGenerator.hpp:73
@ TOPOLOGICALLY_UNIQUE
Report a generated tautomer only if its molecular graph is not topologically equivalent to an already...
Definition: TautomerGenerator.hpp:76
@ GEOMETRICALLY_UNIQUE
Report a generated tautomer only if its ordinary H-deplete molecular graph connection table is differ...
Definition: TautomerGenerator.hpp:78
bool coordinates2DCleared() const
Tells whether 2D atom coordinates are cleared from the generated tautomers.
void setMode(Mode mode)
Sets the tautomer duplicate filtering mode.
Mode getMode() const
Returns the currently configured tautomer duplicate filtering mode.
void addTautomerizationRule(const TautomerizationRule::SharedPointer &rule)
Registers a new tautomerization rule.
void clearCoordinates2D(bool clear)
Specifies whether 2D atom coordinates shall be cleared from the generated tautomers.
void setCustomSetupFunction(const CustomSetupFunction &func)
Sets the optional setup function invoked on the generated tautomers.
void regardIsotopes(bool regard)
Specifies whether atom isotope information shall be regarded by the tautomer duplicate detection algo...
const CallbackFunction & getCallbackFunction() const
Returns the currently configured callback.
std::function< void(MolecularGraph &)> CustomSetupFunction
Type of the optional setup function invoked on the input molecular graph before enumeration starts.
Definition: TautomerGenerator.hpp:89
TautomerGenerator & operator=(const TautomerGenerator &gen)
Replaces the state of this generator by a copy of the state of gen.
std::shared_ptr< TautomerizationRule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated TautomerizationRule instances.
Definition: TautomerizationRule.hpp:54
std::shared_ptr< ObjectType > SharedObjectPointer
A smart pointer to a borrowed object that returns the object to the pool on destruction.
Definition: ObjectPool.hpp:71
CDPL_CHEM_API void setAromaticityFlags(MolecularGraph &molgraph, bool overwrite)
Perceives aromaticity and sets the corresponding atom/bond aromaticity flags on molgraph.
The namespace of the Chemical Data Processing Library.