Chemical Data Processing Library C++ API - Version 1.2.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 
59  {
60 
61  public:
62  enum Mode
63  {
64 
67  EXHAUSTIVE
68  };
69 
70  typedef std::shared_ptr<TautomerGenerator> SharedPointer;
71 
72  typedef std::function<bool(MolecularGraph&)> CallbackFunction;
73  typedef std::function<void(MolecularGraph&)> CustomSetupFunction;
74 
79 
81 
82  virtual ~TautomerGenerator() {}
83 
85 
87 
89 
90  void removeTautomerizationRule(std::size_t idx);
91 
92  std::size_t getNumTautomerizationRules() const;
93 
95 
97 
98  void setMode(Mode mode);
99 
100  Mode getMode() const;
101 
102  void regardStereochemistry(bool regard);
103 
105 
106  void regardIsotopes(bool regard);
107 
108  bool isotopesRegarded() const;
109 
113  void removeResonanceDuplicates(bool remove);
114 
119 
121 
126  void generate(const MolecularGraph& molgraph);
127 
128  private:
130  typedef MoleculeCache::SharedObjectPointer MoleculePtr;
131 
132  bool init(const MolecularGraph& molgraph);
133  void initHashCalculator();
134 
135  MoleculePtr copyInputMolGraph(const MolecularGraph& molgraph);
136 
137  void extractStereoCenters(const MolecularGraph& molgraph);
138  void extractAtomStereoCenters(const MolecularGraph& molgraph);
139  void extractBondStereoCenters(const MolecularGraph& molgraph);
140 
141  bool addNewTautomer(const MoleculePtr& mol_ptr);
142  bool outputTautomer(const MoleculePtr& mol_ptr);
143 
144  std::uint64_t calcConTabHashCode(const MolecularGraph& molgraph, bool arom_bonds);
145 
146  void generateSSSR(MolecularGraph& molgraph);
147  void setAromaticityFlags(MolecularGraph& molgraph);
148  void calcCIPConfigurations(MolecularGraph& molgraph);
149 
150  typedef std::array<std::size_t, 3> BondDescriptor;
151  typedef std::vector<MoleculePtr> MoleculeList;
152  typedef std::vector<TautomerizationRule::SharedPointer> TautRuleList;
153  typedef std::vector<BondDescriptor> BondDescrArray;
154  typedef std::vector<std::size_t> SizeTArray;
155  typedef std::unordered_set<std::uint64_t> HashCodeSet;
156  typedef std::array<std::size_t, 6> StereoCenter;
157  typedef std::vector<StereoCenter> StereoCenterList;
158 
159  MoleculeCache molCache;
160  CallbackFunction callbackFunc;
161  Mode mode;
162  bool regStereo;
163  bool regIsotopes;
164  bool remResDuplicates;
165  CustomSetupFunction customSetupFunc;
166  TautRuleList tautRules;
167  MoleculeList currGeneration;
168  MoleculeList nextGeneration;
169  StereoCenterList atomStereoCenters;
170  StereoCenterList bondStereoCenters;
171  HashCodeSet intermTautHashCodes;
172  HashCodeSet outputTautHashCodes;
173  HashCodeCalculator hashCalculator;
174  AromaticSubstructure aromSubstruct;
175  CIPConfigurationLabeler cipLabeler;
176  BondDescrArray tautomerBonds;
177  SizeTArray shaInput;
178  const MolecularGraph* molGraph;
179  };
180  } // namespace Chem
181 } // namespace CDPL
182 
183 #endif // CDPL_CHEM_TAUTOMERGENERATOR_HPP
Definition of the class CDPL::Chem::AromaticSubstructure.
Definition of the class CDPL::Chem::BasicMolecule.
Definition of the 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 the class CDPL::Chem::HashCodeCalculator.
Definition of the class CDPL::Util::ObjectPool.
Definition of the class CDPL::Chem::TautomerizationRule.
Implements the perception of aromatic atoms and bonds in a molecular graph.
Definition: AromaticSubstructure.hpp:52
CIPConfigurationLabeler.
Definition: CIPConfigurationLabeler.hpp:55
HashCodeCalculator.
Definition: HashCodeCalculator.hpp:57
MolecularGraph.
Definition: MolecularGraph.hpp:52
TautomerGenerator.
Definition: TautomerGenerator.hpp:59
std::shared_ptr< TautomerGenerator > SharedPointer
Definition: TautomerGenerator.hpp:70
bool resonanceDuplicatesRemoved() const
void setCallbackFunction(const CallbackFunction &func)
TautomerGenerator()
Constructs the TautomerGenerator instance.
std::size_t getNumTautomerizationRules() const
virtual ~TautomerGenerator()
Definition: TautomerGenerator.hpp:82
bool stereochemistryRegarded() const
void regardStereochemistry(bool regard)
TautomerGenerator(const TautomerGenerator &gen)
std::function< bool(MolecularGraph &)> CallbackFunction
Definition: TautomerGenerator.hpp:72
const TautomerizationRule::SharedPointer & getTautomerizationRule(std::size_t idx) const
void generate(const MolecularGraph &molgraph)
Generates all unique tautomers of the molecular graph molgraph.
void removeResonanceDuplicates(bool remove)
void removeTautomerizationRule(std::size_t idx)
Mode
Definition: TautomerGenerator.hpp:63
@ TOPOLOGICALLY_UNIQUE
Definition: TautomerGenerator.hpp:65
@ GEOMETRICALLY_UNIQUE
Definition: TautomerGenerator.hpp:66
void addTautomerizationRule(const TautomerizationRule::SharedPointer &rule)
void setCustomSetupFunction(const CustomSetupFunction &func)
void regardIsotopes(bool regard)
const CallbackFunction & getCallbackFunction() const
std::function< void(MolecularGraph &)> CustomSetupFunction
Definition: TautomerGenerator.hpp:73
TautomerGenerator & operator=(const TautomerGenerator &gen)
std::shared_ptr< TautomerizationRule > SharedPointer
Definition: TautomerizationRule.hpp:53
std::shared_ptr< ObjectType > SharedObjectPointer
Definition: ObjectPool.hpp:65
CDPL_CHEM_API void setAromaticityFlags(MolecularGraph &molgraph, bool overwrite)
The namespace of the Chemical Data Processing Library.