Chemical Data Processing Library C++ API - Version 1.2.0
FragmentGenerator.hpp
Go to the documentation of this file.
1 /*
2  * FragmentGenerator.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_FRAGMENTGENERATOR_HPP
30 #define CDPL_CHEM_FRAGMENTGENERATOR_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <memory>
35 #include <functional>
36 
37 #include "CDPL/Chem/APIPrefix.hpp"
41 #include "CDPL/Util/BitSet.hpp"
42 
43 
44 namespace CDPL
45 {
46 
47  namespace Chem
48  {
49 
54  {
55 
56  public:
57  typedef std::shared_ptr<FragmentGenerator> SharedPointer;
58 
59  typedef std::function<bool(const MolecularGraph&)> FragmentFilterFunction;
60 
62  {
63 
64  public:
65  FragmentationRule(const MolecularGraph::SharedPointer& match_ptn, unsigned int id);
66 
68 
70 
71  unsigned int getID() const;
72 
73  void setID(unsigned int id);
74 
75  private:
77  unsigned int id;
78  };
79 
81  {
82 
83  public:
84  ExcludePattern(const MolecularGraph::SharedPointer& match_ptn, unsigned int rule_id);
85 
87 
89 
91 
92  unsigned int getRuleID() const;
93 
94  void setRuleID(unsigned int id);
95 
96  bool isGeneric() const;
97 
98  void setGeneric(bool generic);
99 
100  private:
102  unsigned int ruleID;
103  bool generic;
104  };
105 
107  {
108 
109  public:
110  FragmentLink(std::size_t frag1_idx, std::size_t frag2_idx, const Bond& bond,
111  unsigned int rule_id, unsigned int atom1_label, unsigned int atom2_label);
112 
113  std::size_t getFragment1Index() const;
114 
115  std::size_t getFragment2Index() const;
116 
117  const Bond& getBond() const;
118 
119  unsigned int getRuleID() const;
120 
121  unsigned int getAtom1Label() const;
122 
123  unsigned int getAtom2Label() const;
124 
125  private:
126  std::size_t frag1Idx;
127  std::size_t frag2Idx;
128  const Bond* bond;
129  unsigned int ruleID;
130  unsigned int atom1Label;
131  unsigned int atom2Label;
132  };
133 
134  private:
135  typedef std::vector<FragmentationRule> FragmentationRuleList;
136  typedef std::vector<ExcludePattern> ExcludePatternList;
137  typedef std::vector<FragmentLink> FragmentLinkList;
138 
139  public:
140  typedef FragmentationRuleList::const_iterator ConstFragmentationRuleIterator;
141  typedef FragmentationRuleList::iterator FragmentationRuleIterator;
142 
143  typedef ExcludePatternList::const_iterator ConstExcludePatternIterator;
144  typedef ExcludePatternList::iterator ExcludePatternIterator;
145 
146  typedef FragmentLinkList::const_iterator ConstFragmentLinkIterator;
147 
152 
154 
155  virtual ~FragmentGenerator() {}
156 
158 
159  void addFragmentationRule(const MolecularGraph::SharedPointer& match_ptn, unsigned int rule_id);
160 
162 
163  const FragmentationRule& getFragmentationRule(std::size_t idx) const;
164 
166 
168 
170 
172 
174 
175  void removeFragmentationRule(std::size_t idx);
176 
177  std::size_t getNumFragmentationRules() const;
178 
180 
181  void addExcludePattern(const MolecularGraph::SharedPointer& match_ptn, unsigned int rule_id);
182 
184 
185  void addExcludePattern(const ExcludePattern& excl_ptn);
186 
187  const ExcludePattern& getExcludePattern(std::size_t idx) const;
188 
190 
192 
194 
196 
198 
199  void removeExcludePattern(std::size_t idx);
200 
201  std::size_t getNumExcludePatterns() const;
202 
204 
205  bool splitBondsIncluded() const;
206 
207  void includeSplitBonds(bool include);
208 
210 
212 
213  void generate(const MolecularGraph& molgraph, FragmentList& frag_list, bool append = false);
214 
215  std::size_t getNumFragmentLinks() const;
216 
217  const FragmentLink& getFragmentLink(std::size_t idx) const;
218 
220 
222 
223  private:
224  void init(const MolecularGraph& molgraph);
225 
226  void processFragRuleMatches(const MolecularGraph& molgraph, const FragmentationRule& rule);
227  void processExcludePatternMatches(const MolecularGraph& molgraph, const ExcludePattern& ptn);
228  void splitIntoFragments(const MolecularGraph& molgraph, FragmentList& frag_list, bool append);
229  void growFragment(const Chem::Atom& atom, const Chem::MolecularGraph& molgraph, Chem::Fragment& frag);
230 
231  std::size_t findContainingFragment(const Chem::Atom& atom, const FragmentList& frag_list,
232  std::size_t start_idx) const;
233 
234  struct SplitBondData
235  {
236 
237  const Bond* bond;
238  unsigned int ruleID;
239  unsigned int atom1Label;
240  unsigned int atom2Label;
241  };
242 
243  typedef std::vector<SplitBondData> SplitBondDataArray;
244 
245  FragmentationRuleList fragRules;
246  ExcludePatternList exclPatterns;
247  FragmentLinkList fragLinks;
248  bool incSplitBonds;
249  FragmentFilterFunction fragFilterFunc;
250  SubstructureSearch subSearch;
251  Util::BitSet splitBondMask;
252  Util::BitSet visAtomMask;
253  SplitBondDataArray splitBondData;
254  };
255  } // namespace Chem
256 } // namespace CDPL
257 
258 #endif // CDPL_CHEM_FRAGMENTGENERATOR_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::FragmentList.
Definition of the class CDPL::Chem::MolecularGraph.
Definition of the class CDPL::Chem::SubstructureSearch.
Atom.
Definition: Atom.hpp:52
Bond.
Definition: Bond.hpp:50
Definition: FragmentGenerator.hpp:81
ExcludePattern(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
void setMatchPattern(const MolecularGraph::SharedPointer &ptn)
ExcludePattern(const MolecularGraph::SharedPointer &match_ptn)
const MolecularGraph::SharedPointer & getMatchPattern() const
Definition: FragmentGenerator.hpp:62
void setMatchPattern(const MolecularGraph::SharedPointer &ptn)
const MolecularGraph::SharedPointer & getMatchPattern() const
FragmentationRule(const MolecularGraph::SharedPointer &match_ptn, unsigned int id)
FragmentGenerator.
Definition: FragmentGenerator.hpp:54
void removeFragmentationRule(std::size_t idx)
void addExcludePattern(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
FragmentLinkList::const_iterator ConstFragmentLinkIterator
Definition: FragmentGenerator.hpp:146
ConstFragmentLinkIterator getFragmentLinksBegin() const
ExcludePatternList::iterator ExcludePatternIterator
Definition: FragmentGenerator.hpp:144
FragmentationRule & getFragmentationRule(std::size_t idx)
FragmentationRuleIterator getFragmentationRulesBegin()
ConstFragmentationRuleIterator getFragmentationRulesBegin() const
FragmentationRuleIterator getFragmentationRulesEnd()
std::shared_ptr< FragmentGenerator > SharedPointer
Definition: FragmentGenerator.hpp:57
const FragmentLink & getFragmentLink(std::size_t idx) const
ConstFragmentationRuleIterator getFragmentationRulesEnd() const
const ExcludePattern & getExcludePattern(std::size_t idx) const
ConstExcludePatternIterator getExcludePatternsEnd() const
virtual ~FragmentGenerator()
Definition: FragmentGenerator.hpp:155
ConstFragmentLinkIterator getFragmentLinksEnd() const
std::size_t getNumFragmentLinks() const
FragmentationRuleList::const_iterator ConstFragmentationRuleIterator
Definition: FragmentGenerator.hpp:140
const FragmentFilterFunction & getFragmentFilterFunction() const
void setFragmentFilterFunction(const FragmentFilterFunction &func)
const FragmentationRule & getFragmentationRule(std::size_t idx) const
std::size_t getNumExcludePatterns() const
std::size_t getNumFragmentationRules() const
FragmentGenerator(const FragmentGenerator &gen)
FragmentGenerator & operator=(const FragmentGenerator &gen)
ExcludePatternIterator getExcludePatternsBegin()
void addFragmentationRule(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
ConstExcludePatternIterator getExcludePatternsBegin() const
FragmentGenerator()
Constructs the FragmentGenerator instance.
void addExcludePattern(const ExcludePattern &excl_ptn)
ExcludePattern & getExcludePattern(std::size_t idx)
std::function< bool(const MolecularGraph &)> FragmentFilterFunction
Definition: FragmentGenerator.hpp:59
void addExcludePattern(const MolecularGraph::SharedPointer &match_ptn)
void includeSplitBonds(bool include)
FragmentationRuleList::iterator FragmentationRuleIterator
Definition: FragmentGenerator.hpp:141
void addFragmentationRule(const FragmentationRule &rule)
void generate(const MolecularGraph &molgraph, FragmentList &frag_list, bool append=false)
ExcludePatternIterator getExcludePatternsEnd()
void removeExcludePattern(std::size_t idx)
ExcludePatternList::const_iterator ConstExcludePatternIterator
Definition: FragmentGenerator.hpp:143
A data type for the storage of Chem::Fragment objects.
Definition: FragmentList.hpp:49
Fragment.
Definition: Fragment.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
SubstructureSearch.
Definition: SubstructureSearch.hpp:64
CDPL_CHEM_API void splitIntoFragments(const MolecularGraph &molgraph, FragmentList &frag_list, const Util::BitSet &split_bond_mask, bool append=false)
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.