Chemical Data Processing Library C++ API - Version 1.3.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 
60  {
61 
62  struct Pattern;
63 
64  typedef std::vector<Pattern> PatternList;
65  typedef const MolecularGraph::SharedPointer& (*GetMolGraphFunc)(const Pattern&);
66 
67  public:
68  typedef std::shared_ptr<SubstructureEditor> SharedPointer;
69 
70  typedef boost::transform_iterator<GetMolGraphFunc, PatternList::const_iterator> ConstPatternIterator;
71  typedef boost::transform_iterator<GetMolGraphFunc, PatternList::iterator> PatternIterator;
72 
77 
83 
88 
94 
95  std::size_t getNumSearchPatterns() const;
96 
97  const MolecularGraph::SharedPointer& getSearchPattern(std::size_t idx) const;
98 
99  void removeSearchPattern(std::size_t idx);
100 
102 
107 
109 
111 
113 
115 
121 
122  std::size_t getNumExcludePatterns() const;
123 
124  const MolecularGraph::SharedPointer& getExcludePattern(std::size_t idx) const;
125 
126  void removeExcludePattern(std::size_t idx);
127 
129 
134 
136 
138 
140 
142 
144 
146 
150  void clear();
151 
152  std::size_t edit(Molecule& mol);
153 
154  std::size_t edit(const MolecularGraph& molgraph, Molecule& res_mol);
155 
162 
163  private:
164  struct Pattern
165  {
166 
167  Pattern(const MolecularGraph::SharedPointer& molgraph):
168  molGraph(molgraph), subSearch(new Chem::SubstructureSearch(*molgraph))
169  {}
170 
173  };
174 
175  bool edit(Molecule& mol, const AtomMapping& mapping);
176 
177  bool editAtomStereoDescriptors(Molecule& mol) const;
178  bool editBondStereoDescriptors(Molecule& mol) const;
179 
180  void getExcludeMatches(const MolecularGraph& molgraph);
181 
182  bool createMatchedAtomAndBondMask(const MolecularGraph& molgraph, const AtomBondMapping& mapping,
183  Util::BitSet& mask, bool lbld_only, bool init) const;
184 
185  Chem::Atom* getMappedAtomForID(const AtomMapping& mapping, std::size_t id) const;
186  const Chem::Atom* getNeighbor(const Atom* ctr_atom, const Atom* excl_nbr) const;
187 
188  template <typename T>
189  void copyProperty(const T& src_cntnr, T& tgt_cntnr, const Base::LookupKey& key) const;
190 
191  template <typename VT, typename T>
192  bool copyPropertyWithChangeCheck(const T& src_cntnr, T& tgt_cntnr, const Base::LookupKey& key) const;
193 
194  bool setStereoDescriptorWithChangeCheck(Atom& atom, const StereoDescriptor& descr) const;
195  bool setStereoDescriptorWithChangeCheck(Bond& bond, const StereoDescriptor& descr) const;
196 
197  static const MolecularGraph::SharedPointer& getMolGraph(const Pattern& ptn);
198 
199  typedef Util::ObjectStack<Util::BitSet> BitSetCache;
200  typedef std::vector<Util::BitSet*> BitSetList;
201  typedef std::vector<Atom*> AtomArray;
202  typedef std::unordered_set<Atom*> AtomSet;
203  typedef std::unordered_set<Bond*> BondSet;
204 
205  const MolecularGraph* molGraph;
206  PatternList searchPatterns;
207  PatternList excludePatterns;
208  MolecularGraph::SharedPointer resultPattern;
209  BitSetList excludeMatches;
210  AtomArray resPtnAtomMapping;
211  AtomSet hybStateUpdateAtoms;
212  AtomSet configUpdateAtoms;
213  BondSet configUpdateBonds;
214  BitSetCache bitSetCache;
215  };
216  } // namespace Chem
217 } // namespace CDPL
218 
219 #endif // CDPL_CHEM_SUBSTRUCTUREEDITOR_HPP
Definition of the 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 the class CDPL::Chem::MolecularGraph.
Definition of the class CDPL::Util::ObjectStack.
Definition of the class CDPL::Chem::SubstructureSearch.
An unique lookup key for control-parameter and property values.
Definition: LookupKey.hpp:54
Atom.
Definition: Atom.hpp:52
MolecularGraph.
Definition: MolecularGraph.hpp:52
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:58
Molecule.
Definition: Molecule.hpp:49
SubstructureEditor.
Definition: SubstructureEditor.hpp:60
PatternIterator getExcludePatternsEnd()
ConstPatternIterator getExcludePatternsBegin() const
ConstPatternIterator getExcludePatternsEnd() const
const MolecularGraph::SharedPointer & getSearchPattern(std::size_t idx) const
const MolecularGraph::SharedPointer & getResultPattern() const
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
Definition: SubstructureEditor.hpp:71
void removeExcludePattern(const PatternIterator &it)
std::size_t edit(const MolecularGraph &molgraph, Molecule &res_mol)
void removeSearchPattern(std::size_t idx)
void setResultPattern(const MolecularGraph::SharedPointer &pattern)
PatternIterator getSearchPatternsBegin()
PatternIterator getSearchPatternsEnd()
PatternIterator getExcludePatternsBegin()
SubstructureEditor()
Constructs the SubstructureEditor instance.
SubstructureEditor(const SubstructureEditor &editor)
Constructs a copy of the SubstructureEditor instance editor.
ConstPatternIterator getSearchPatternsEnd() const
void clear()
Clears the current editing result pattern and the sets of substructure search and exclude patterns.
std::shared_ptr< SubstructureEditor > SharedPointer
Definition: SubstructureEditor.hpp:68
ConstPatternIterator getSearchPatternsBegin() const
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
Definition: SubstructureEditor.hpp:70
SubstructureEditor & operator=(const SubstructureEditor &gen)
Copies the state of the SubstructureEditor instance gen.
std::size_t getNumSearchPatterns() const
const MolecularGraph::SharedPointer & getExcludePattern(std::size_t idx) const
void clearSearchPatterns()
Clears the current set of substructuresearch patterns.
void clearExcludePatterns()
Clears the current set of substructure exclude patterns.
std::size_t getNumExcludePatterns() const
void removeExcludePattern(std::size_t idx)
void removeSearchPattern(const PatternIterator &it)
std::size_t edit(Molecule &mol)
SubstructureSearch.
Definition: SubstructureSearch.hpp:64
std::shared_ptr< SubstructureSearch > SharedPointer
Definition: SubstructureSearch.hpp:73
constexpr unsigned int T
Specifies Hydrogen (Tritium).
Definition: AtomType.hpp:67
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.