Chemical Data Processing Library C++ API - Version 1.4.0
SubstructureEditor.hpp
Go to the documentation of this file.
1 /*
2  * SubstructureEditor.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_SUBSTRUCTUREEDITOR_HPP
30 #define CDPL_CHEM_SUBSTRUCTUREEDITOR_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <memory>
35 #include <unordered_set>
36 
37 #include <boost/iterator/transform_iterator.hpp>
38 
39 #include "CDPL/Chem/APIPrefix.hpp"
42 #include "CDPL/Util/BitSet.hpp"
44 
45 
46 namespace CDPL
47 {
48 
49  namespace Chem
50  {
51 
52  class Molecule;
53  class StereoDescriptor;
54 
66  {
67 
68  struct Pattern;
69 
70  typedef std::vector<Pattern> PatternList;
71  typedef const MolecularGraph::SharedPointer& (*GetMolGraphFunc)(const Pattern&);
72 
73  public:
77  typedef std::shared_ptr<SubstructureEditor> SharedPointer;
78 
82  typedef boost::transform_iterator<GetMolGraphFunc, PatternList::const_iterator> ConstPatternIterator;
83 
87  typedef boost::transform_iterator<GetMolGraphFunc, PatternList::iterator> PatternIterator;
88 
93 
99 
106 
112 
117  std::size_t getNumSearchPatterns() const;
118 
125  const MolecularGraph::SharedPointer& getSearchPattern(std::size_t idx) const;
126 
132  void removeSearchPattern(std::size_t idx);
133 
140 
145 
151 
157 
163 
169 
175 
180  std::size_t getNumExcludePatterns() const;
181 
188  const MolecularGraph::SharedPointer& getExcludePattern(std::size_t idx) const;
189 
195  void removeExcludePattern(std::size_t idx);
196 
203 
208 
214 
220 
226 
232 
238 
244 
248  void clear();
249 
256  std::size_t edit(Molecule& mol);
257 
264  std::size_t edit(const MolecularGraph& molgraph, Molecule& res_mol);
265 
272 
273  private:
274  struct Pattern
275  {
276 
277  Pattern(const MolecularGraph::SharedPointer& molgraph):
278  molGraph(molgraph), subSearch(new Chem::SubstructureSearch(*molgraph))
279  {}
280 
283  };
284 
285  bool edit(Molecule& mol, const AtomMapping& mapping);
286 
287  bool editAtomStereoDescriptors(Molecule& mol) const;
288  bool editBondStereoDescriptors(Molecule& mol) const;
289 
290  void getExcludeMatches(const MolecularGraph& molgraph);
291 
292  bool createMatchedAtomAndBondMask(const MolecularGraph& molgraph, const AtomBondMapping& mapping,
293  Util::BitSet& mask, bool lbld_only, bool init) const;
294 
295  Chem::Atom* getMappedAtomForID(const AtomMapping& mapping, std::size_t id) const;
296  const Chem::Atom* getNeighbor(const Atom* ctr_atom, const Atom* excl_nbr) const;
297 
298  template <typename T>
299  void copyProperty(const T& src_cntnr, T& tgt_cntnr, const Base::LookupKey& key) const;
300 
301  template <typename VT, typename T>
302  bool copyPropertyWithChangeCheck(const T& src_cntnr, T& tgt_cntnr, const Base::LookupKey& key) const;
303 
304  bool setStereoDescriptorWithChangeCheck(Atom& atom, const StereoDescriptor& descr) const;
305  bool setStereoDescriptorWithChangeCheck(Bond& bond, const StereoDescriptor& descr) const;
306 
307  static const MolecularGraph::SharedPointer& getMolGraph(const Pattern& ptn);
308 
309  typedef Util::ObjectStack<Util::BitSet> BitSetCache;
310  typedef std::vector<Util::BitSet*> BitSetList;
311  typedef std::vector<Atom*> AtomArray;
312  typedef std::unordered_set<Atom*> AtomSet;
313  typedef std::unordered_set<Bond*> BondSet;
314 
315  PatternList searchPatterns;
316  PatternList excludePatterns;
317  MolecularGraph::SharedPointer resultPattern;
318  BitSetList excludeMatches;
319  AtomArray resPtnAtomMapping;
320  AtomSet hybStateUpdateAtoms;
321  AtomSet configUpdateAtoms;
322  BondSet configUpdateBonds;
323  BitSetCache bitSetCache;
324  };
325  } // namespace Chem
326 } // namespace CDPL
327 
328 #endif // CDPL_CHEM_SUBSTRUCTUREEDITOR_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.
Unique lookup key for control-parameter and property values.
Definition: LookupKey.hpp:54
Abstract base class representing a chemical atom and its bonded neighborhood.
Definition: Atom.hpp:58
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
Pattern-driven editor that rewrites matched substructures of a molecule according to a given editing ...
Definition: SubstructureEditor.hpp:66
PatternIterator getExcludePatternsEnd()
Returns a mutable iterator pointing to the end of the stored exclude pattern Chem::MolecularGraph obj...
ConstPatternIterator getExcludePatternsBegin() const
Returns a constant iterator pointing to the beginning of the stored exclude pattern const Chem::Molec...
ConstPatternIterator getExcludePatternsEnd() const
Returns a constant iterator pointing to the end of the stored exclude pattern const Chem::MolecularGr...
const MolecularGraph::SharedPointer & getSearchPattern(std::size_t idx) const
Returns the molecular graph of the substructure search pattern at index idx.
const MolecularGraph::SharedPointer & getResultPattern() const
Returns the currently set result pattern.
void addExcludePattern(const MolecularGraph::SharedPointer &molgraph)
Appends a new substructure exclude pattern to the current set of patterns.
boost::transform_iterator< GetMolGraphFunc, PatternList::iterator > PatternIterator
A mutable iterator used to iterate over the stored search/exclude pattern Chem::MolecularGraph object...
Definition: SubstructureEditor.hpp:87
void removeExcludePattern(const PatternIterator &it)
Removes the substructure exclude pattern pointed to by it.
std::size_t edit(const MolecularGraph &molgraph, Molecule &res_mol)
Copies the molecular graph molgraph into the molecule res_mol and then edits it by calling edit(Molec...
void removeSearchPattern(std::size_t idx)
Removes the substructure search pattern at index idx.
void setResultPattern(const MolecularGraph::SharedPointer &pattern)
Sets the result pattern that defines how each matched search pattern instance will be rewritten.
PatternIterator getSearchPatternsBegin()
Returns a mutable iterator pointing to the beginning of the stored search pattern Chem::MolecularGrap...
PatternIterator getSearchPatternsEnd()
Returns a mutable iterator pointing to the end of the stored search pattern Chem::MolecularGraph obje...
PatternIterator getExcludePatternsBegin()
Returns a mutable iterator pointing to the beginning of the stored exclude pattern Chem::MolecularGra...
SubstructureEditor()
Constructs the SubstructureEditor instance.
SubstructureEditor(const SubstructureEditor &editor)
Constructs a copy of the SubstructureEditor instance editor.
ConstPatternIterator getSearchPatternsEnd() const
Returns a constant iterator pointing to the end of the stored search pattern const Chem::MolecularGra...
void clear()
Clears the current editing result pattern and the sets of substructure search and exclude patterns.
std::shared_ptr< SubstructureEditor > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated SubstructureEditor instances.
Definition: SubstructureEditor.hpp:77
ConstPatternIterator getSearchPatternsBegin() const
Returns a constant iterator pointing to the beginning of the stored search pattern const Chem::Molecu...
void addSearchPattern(const MolecularGraph::SharedPointer &molgraph)
Appends a new substructure search pattern to the current set of patterns.
boost::transform_iterator< GetMolGraphFunc, PatternList::const_iterator > ConstPatternIterator
A constant iterator used to iterate over the stored search/exclude pattern Chem::MolecularGraph objec...
Definition: SubstructureEditor.hpp:82
SubstructureEditor & operator=(const SubstructureEditor &gen)
Copies the state of the SubstructureEditor instance gen.
std::size_t getNumSearchPatterns() const
Returns the number of stored substructure search patterns.
const MolecularGraph::SharedPointer & getExcludePattern(std::size_t idx) const
Returns the molecular graph of the substructure exclude pattern at index idx.
void clearSearchPatterns()
Clears the current set of substructure search patterns.
void clearExcludePatterns()
Clears the current set of substructure exclude patterns.
std::size_t getNumExcludePatterns() const
Returns the number of stored substructure exclude patterns.
void removeExcludePattern(std::size_t idx)
Removes the substructure exclude pattern at index idx.
void removeSearchPattern(const PatternIterator &it)
Removes the substructure search pattern pointed to by it.
std::size_t edit(Molecule &mol)
Edits the molecule mol in place by applying the result pattern at every search pattern match that is ...
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
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
boost::dynamic_bitset BitSet
Dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.