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 
79 
84 
88  EXHAUSTIVE
89  };
90 
94  typedef std::shared_ptr<TautomerGenerator> SharedPointer;
95 
99  typedef std::function<bool(MolecularGraph&)> CallbackFunction;
100 
104  typedef std::function<void(MolecularGraph&)> CustomSetupFunction;
105 
110 
116 
120  virtual ~TautomerGenerator() {}
121 
128 
134 
142 
148  void removeTautomerizationRule(std::size_t idx);
149 
154  std::size_t getNumTautomerizationRules() const;
155 
165 
171 
176  void setMode(Mode mode);
177 
182  Mode getMode() const;
183 
188  void regardStereochemistry(bool regard);
189 
195 
200  void regardIsotopes(bool regard);
201 
206  bool isotopesRegarded() const;
207 
213  void clearCoordinates2D(bool clear);
214 
220  bool coordinates2DCleared() const;
221 
227  void clearCoordinates3D(bool clear);
228 
234  bool coordinates3DCleared() const;
235 
241  void removeResonanceDuplicates(bool remove);
242 
249 
255 
260  void generate(const MolecularGraph& molgraph);
261 
262  private:
264  typedef MoleculeCache::SharedObjectPointer MoleculePtr;
265 
266  bool init(const MolecularGraph& molgraph);
267  void initHashCalculator();
268 
269  MoleculePtr copyInputMolGraph(const MolecularGraph& molgraph);
270 
271  void extractStereoCenters(const MolecularGraph& molgraph);
272  void extractAtomStereoCenters(const MolecularGraph& molgraph);
273  void extractBondStereoCenters(const MolecularGraph& molgraph);
274 
275  bool addNewTautomer(const MoleculePtr& mol_ptr);
276  bool outputTautomer(const MoleculePtr& mol_ptr);
277 
278  std::uint64_t calcConTabHashCode(const MolecularGraph& molgraph, bool arom_bonds);
279 
280  void generateSSSR(MolecularGraph& molgraph);
281  void setAromaticityFlags(MolecularGraph& molgraph);
282  void calcCIPConfigurations(MolecularGraph& molgraph);
283 
284  typedef std::array<std::size_t, 3> BondDescriptor;
285  typedef std::vector<MoleculePtr> MoleculeList;
286  typedef std::vector<TautomerizationRule::SharedPointer> TautRuleList;
287  typedef std::vector<BondDescriptor> BondDescrArray;
288  typedef std::vector<std::size_t> SizeTArray;
289  typedef std::unordered_set<std::uint64_t> HashCodeSet;
290  typedef std::array<std::size_t, 6> StereoCenter;
291  typedef std::vector<StereoCenter> StereoCenterList;
292 
293  MoleculeCache molCache;
294  CallbackFunction callbackFunc;
295  Mode mode;
296  bool regStereo;
297  bool regIsotopes;
298  bool remResDuplicates;
299  bool clear2DCoords;
300  bool clear3DCoords;
301  CustomSetupFunction customSetupFunc;
302  TautRuleList tautRules;
303  MoleculeList currGeneration;
304  MoleculeList nextGeneration;
305  StereoCenterList atomStereoCenters;
306  StereoCenterList bondStereoCenters;
307  HashCodeSet intermTautHashCodes;
308  HashCodeSet outputTautHashCodes;
309  HashCodeCalculator hashCalculator;
310  AromaticSubstructure aromSubstruct;
311  CIPConfigurationLabeler cipLabeler;
312  BondDescrArray tautomerBonds;
313  SizeTArray shaInput;
314  const MolecularGraph* molGraph;
315  };
316  } // namespace Chem
317 } // namespace CDPL
318 
319 #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:94
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:120
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:99
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:78
@ GEOMETRICALLY_UNIQUE
Report a generated tautomer only if its ordinary H-deplete molecular graph connection table is differ...
Definition: TautomerGenerator.hpp:83
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:104
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:56
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 the molecular graph m...
The namespace of the Chemical Data Processing Library.