Chemical Data Processing Library C++ API - Version 1.4.0
PatternBasedTautomerizationRule.hpp
Go to the documentation of this file.
1 /*
2  * PatternBasedTautomerizationRule.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_PATTERNBASEDTAUTOMERIZATIONRULE_HPP
30 #define CDPL_CHEM_PATTERNBASEDTAUTOMERIZATIONRULE_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <algorithm>
35 #include <iterator>
36 #include <memory>
37 #include <functional>
38 
39 #include "CDPL/Chem/APIPrefix.hpp"
43 #include "CDPL/Util/BitSet.hpp"
45 
46 
47 namespace CDPL
48 {
49 
50  namespace Chem
51  {
52 
63  {
64 
65  public:
69  typedef std::shared_ptr<PatternBasedTautomerizationRule> SharedPointer;
70 
76  {
77 
81  std::size_t atom1ID;
82 
86  std::size_t atom2ID;
87 
92  };
93 
98  PatternBasedTautomerizationRule(unsigned int rule_id);
99 
105 
112 
125  template <typename Iter>
126  void addTransformationPattern(const MolecularGraph::SharedPointer& molgraph, Iter bond_chgs_beg, Iter bond_chgs_end)
127  {
128  structPatterns.push_back(molgraph);
129  patternSubSearchList.push_back(SubstructureSearch::SharedPointer(new SubstructureSearch(*molgraph)));
130  patternBondChangeLists.resize(patternBondChangeLists.size() + 1);
131 
132  std::copy(bond_chgs_beg, bond_chgs_end, std::back_inserter(patternBondChangeLists.back()));
133  }
134 
144 
150 
155 
156  bool setup(MolecularGraph& parent_molgraph);
157 
158  unsigned int getID() const;
159 
160  bool generate(Molecule& tautomer);
161 
163 
164  private:
165  bool applyTransformation(Molecule& tautomer);
166 
167  Atom* getTautomerAtom(Molecule& tautomer, std::size_t ptn_atom_id, const AtomMapping& mapping) const;
168 
169  void freeBitSet(Util::BitSet* bset);
170 
171  void createMatchedBondMask(const BondMapping& mapping, Util::BitSet& bond_mask) const;
172 
173  typedef std::vector<BondOrderChange> BondOrderChangeList;
174  typedef std::vector<BondOrderChangeList> BondOrderChangeListArray;
175  typedef std::vector<MolecularGraph::SharedPointer> StructPatternList;
176  typedef std::vector<SubstructureSearch::SharedPointer> SubstructureSearchList;
177  typedef std::vector<Util::BitSet*> BitSetList;
179 
180  unsigned int ruleID;
181  StructPatternList structPatterns;
182  StructPatternList excludePatterns;
183  BondOrderChangeListArray patternBondChangeLists;
184  SubstructureSearchList patternSubSearchList;
185  SubstructureSearchList excludeSubSearchList;
186  const MolecularGraph* parentMolGraph;
187  std::size_t currPatternIdx;
188  std::size_t currMappingIdx;
189  Util::BitSet bondMask;
190  BitSetList excludeMatches;
191  BitSetCache bitSetCache;
192  };
193  } // namespace Chem
194 } // namespace CDPL
195 
196 #endif // CDPL_CHEM_PATTERNBASEDTAUTOMERIZATIONRULE_HPP
Declaration of 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 class CDPL::Chem::MolecularGraph.
Definition of class CDPL::Util::ObjectStack.
Definition of class CDPL::Chem::SubstructureSearch.
Definition of class CDPL::Chem::TautomerizationRule.
Data type for the storage and lookup of arbitrary atom to atom mappings.
Definition: AtomMapping.hpp:54
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:58
Data type for the storage and lookup of arbitrary bond to bond mappings.
Definition: BondMapping.hpp:54
Abstract base class for data structures that represent chemical structures as molecular graphs.
Definition: MolecularGraph.hpp:60
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:66
Abstract base class representing a mutable molecular graph that owns and manages its atoms and bonds.
Definition: Molecule.hpp:53
Substructure search pattern-based implementation of the Chem::TautomerizationRule interface.
Definition: PatternBasedTautomerizationRule.hpp:63
PatternBasedTautomerizationRule(unsigned int rule_id)
Constructs the PatternBasedTautomerizationRule instance with the given rule identifier.
void addExcludePattern(const MolecularGraph::SharedPointer &molgraph)
Registers a rule exclude pattern.
void addExcludePatterns(const PatternBasedTautomerizationRule &rule)
Appends all registered search patterns of rule to the exclude pattern list of this rule.
PatternBasedTautomerizationRule(const PatternBasedTautomerizationRule &rule)
Constructs a PatternBasedTautomerizationRule instance that is copy of rule.
void addTransformationPattern(const MolecularGraph::SharedPointer &molgraph, Iter bond_chgs_beg, Iter bond_chgs_end)
Registers a new transformation pattern.
Definition: PatternBasedTautomerizationRule.hpp:126
void clearExcludePatterns()
Removes all registered exclude patterns.
unsigned int getID() const
Returns the rule identifier.
bool setup(MolecularGraph &parent_molgraph)
Performs rule-specific setup work for the given molecular graph that shall be tautomerized.
std::shared_ptr< PatternBasedTautomerizationRule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated PatternBasedTautomerizationRule i...
Definition: PatternBasedTautomerizationRule.hpp:69
TautomerizationRule::SharedPointer clone() const
Returns a deep copy of this rule instance.
PatternBasedTautomerizationRule & operator=(const PatternBasedTautomerizationRule &rule)
Replaces the state of this rule by a copy of the state of rule.
bool generate(Molecule &tautomer)
Generates the next tautomer of the parent molecular graph and stores it in molecule.
Searches for substructures of a target molecular graph that match the topology of a given query molec...
Definition: SubstructureSearch.hpp:78
std::shared_ptr< SubstructureSearch > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureSearch instances.
Definition: SubstructureSearch.hpp:90
Abstract base class for tautomerization rule implementations employed by the Chem::TautomerGenerator ...
Definition: TautomerizationRule.hpp:50
std::shared_ptr< TautomerizationRule > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated TautomerizationRule instances.
Definition: TautomerizationRule.hpp:56
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.
Encodes a single bond order change between two pattern atoms applied when the parent transformation p...
Definition: PatternBasedTautomerizationRule.hpp:76
std::size_t atom1ID
Pattern atom mapping ID of the first atom of the bond whose order changes.
Definition: PatternBasedTautomerizationRule.hpp:81
std::size_t atom2ID
Pattern atom mapping ID of the second atom of the bond whose order changes.
Definition: PatternBasedTautomerizationRule.hpp:86
long orderChange
Signed bond order delta applied to the matched bond (positive = increase, negative = decrease).
Definition: PatternBasedTautomerizationRule.hpp:91