Chemical Data Processing Library C++ API - Version 1.1.1
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
CDPL::Chem::MolecularGraph::SharedPointer
std::shared_ptr< MolecularGraph > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated MolecularGraph instances.
Definition: MolecularGraph.hpp:58
CDPL::Chem::FragmentGenerator::getNumFragmentationRules
std::size_t getNumFragmentationRules() const
CDPL::Chem::FragmentGenerator::removeFragmentationRule
void removeFragmentationRule(std::size_t idx)
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL::Chem::FragmentGenerator::ExcludePattern::setMatchPattern
void setMatchPattern(const MolecularGraph::SharedPointer &ptn)
CDPL::Chem::FragmentGenerator::addFragmentationRule
void addFragmentationRule(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
CDPL::Chem::FragmentGenerator::addExcludePattern
void addExcludePattern(const ExcludePattern &excl_ptn)
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::FragmentGenerator::FragmentationRule
Definition: FragmentGenerator.hpp:62
CDPL::Chem::FragmentGenerator::getFragmentationRulesEnd
ConstFragmentationRuleIterator getFragmentationRulesEnd() const
CDPL::Chem::FragmentGenerator::getFragmentationRulesBegin
ConstFragmentationRuleIterator getFragmentationRulesBegin() const
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::FragmentGenerator::ConstFragmentationRuleIterator
FragmentationRuleList::const_iterator ConstFragmentationRuleIterator
Definition: FragmentGenerator.hpp:140
CDPL::Chem::FragmentGenerator::getNumFragmentLinks
std::size_t getNumFragmentLinks() const
CDPL::Chem::FragmentGenerator::clearFragmentationRules
void clearFragmentationRules()
CDPL::Chem::FragmentGenerator::addExcludePattern
void addExcludePattern(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
CDPL::Chem::FragmentGenerator::ExcludePattern::setGeneric
void setGeneric(bool generic)
CDPL::Chem::FragmentGenerator::FragmentationRule::getMatchPattern
const MolecularGraph::SharedPointer & getMatchPattern() const
CDPL::Chem::SubstructureSearch
SubstructureSearch.
Definition: SubstructureSearch.hpp:64
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
CDPL::Chem::FragmentGenerator::removeExcludePattern
void removeExcludePattern(std::size_t idx)
CDPL::Chem::Atom
Atom.
Definition: Atom.hpp:52
CDPL::Chem::Fragment
Fragment.
Definition: Fragment.hpp:52
CDPL::Chem::FragmentGenerator::ExcludePattern::isGeneric
bool isGeneric() const
CDPL::Chem::FragmentGenerator::getExcludePattern
const ExcludePattern & getExcludePattern(std::size_t idx) const
CDPL::Chem::FragmentGenerator::getNumExcludePatterns
std::size_t getNumExcludePatterns() const
CDPL::Chem::FragmentGenerator::FragmentGenerator
FragmentGenerator(const FragmentGenerator &gen)
CDPL::Chem::FragmentGenerator::operator=
FragmentGenerator & operator=(const FragmentGenerator &gen)
bool
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
CDPL::Chem::FragmentGenerator::ExcludePattern
Definition: FragmentGenerator.hpp:81
CDPL::Chem::FragmentGenerator::ExcludePattern::ExcludePattern
ExcludePattern(const MolecularGraph::SharedPointer &match_ptn, unsigned int rule_id)
CDPL::Chem::FragmentGenerator::FragmentationRule::setMatchPattern
void setMatchPattern(const MolecularGraph::SharedPointer &ptn)
CDPL::Chem::FragmentGenerator::SharedPointer
std::shared_ptr< FragmentGenerator > SharedPointer
Definition: FragmentGenerator.hpp:57
CDPL::Chem::FragmentGenerator::addExcludePattern
void addExcludePattern(const MolecularGraph::SharedPointer &match_ptn)
CDPL::Chem::FragmentGenerator::getFragmentLinksEnd
ConstFragmentLinkIterator getFragmentLinksEnd() const
CDPL::Chem::FragmentGenerator::getFragmentationRulesBegin
FragmentationRuleIterator getFragmentationRulesBegin()
CDPL::Chem::FragmentGenerator::getExcludePatternsBegin
ConstExcludePatternIterator getExcludePatternsBegin() const
MolecularGraph.hpp
Definition of the class CDPL::Chem::MolecularGraph.
CDPL::Chem::FragmentGenerator::FragmentGenerator
FragmentGenerator()
Constructs the FragmentGenerator instance.
CDPL::Chem::FragmentGenerator::splitBondsIncluded
bool splitBondsIncluded() const
CDPL::Chem::FragmentGenerator::setFragmentFilterFunction
void setFragmentFilterFunction(const FragmentFilterFunction &func)
CDPL::Chem::FragmentGenerator
FragmentGenerator.
Definition: FragmentGenerator.hpp:54
CDPL::Chem::FragmentGenerator::getFragmentLink
const FragmentLink & getFragmentLink(std::size_t idx) const
CDPL::Chem::FragmentGenerator::ExcludePattern::getRuleID
unsigned int getRuleID() const
CDPL::Chem::FragmentList
A data type for the storage of Chem::Fragment objects.
Definition: FragmentList.hpp:49
CDPL::Chem::FragmentGenerator::getFragmentLinksBegin
ConstFragmentLinkIterator getFragmentLinksBegin() const
CDPL::Chem::FragmentGenerator::includeSplitBonds
void includeSplitBonds(bool include)
CDPL::Chem::splitIntoFragments
CDPL_CHEM_API void splitIntoFragments(const MolecularGraph &molgraph, FragmentList &frag_list, const Util::BitSet &split_bond_mask, bool append=false)
CDPL::Chem::FragmentGenerator::ConstExcludePatternIterator
ExcludePatternList::const_iterator ConstExcludePatternIterator
Definition: FragmentGenerator.hpp:143
CDPL::Chem::FragmentGenerator::getFragmentationRulesEnd
FragmentationRuleIterator getFragmentationRulesEnd()
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::FragmentGenerator::getExcludePatternsEnd
ExcludePatternIterator getExcludePatternsEnd()
CDPL::Chem::FragmentGenerator::ExcludePattern::getMatchPattern
const MolecularGraph::SharedPointer & getMatchPattern() const
CDPL::Chem::FragmentGenerator::ExcludePattern::ExcludePattern
ExcludePattern(const MolecularGraph::SharedPointer &match_ptn)
CDPL::Chem::FragmentGenerator::FragmentFilterFunction
std::function< bool(const MolecularGraph &)> FragmentFilterFunction
Definition: FragmentGenerator.hpp:59
CDPL::Chem::FragmentGenerator::ExcludePattern::setRuleID
void setRuleID(unsigned int id)
CDPL::Chem::FragmentGenerator::getExcludePattern
ExcludePattern & getExcludePattern(std::size_t idx)
CDPL::Chem::FragmentGenerator::getFragmentationRule
FragmentationRule & getFragmentationRule(std::size_t idx)
CDPL::Chem::FragmentGenerator::addFragmentationRule
void addFragmentationRule(const FragmentationRule &rule)
CDPL::Chem::FragmentGenerator::getExcludePatternsEnd
ConstExcludePatternIterator getExcludePatternsEnd() const
CDPL::Chem::FragmentGenerator::getFragmentFilterFunction
const FragmentFilterFunction & getFragmentFilterFunction() const
CDPL::Chem::FragmentGenerator::FragmentationRule::getID
unsigned int getID() const
SubstructureSearch.hpp
Definition of the class CDPL::Chem::SubstructureSearch.
CDPL::Chem::FragmentGenerator::FragmentationRuleIterator
FragmentationRuleList::iterator FragmentationRuleIterator
Definition: FragmentGenerator.hpp:141
CDPL::Chem::FragmentGenerator::~FragmentGenerator
virtual ~FragmentGenerator()
Definition: FragmentGenerator.hpp:155
CDPL::Chem::FragmentGenerator::getExcludePatternsBegin
ExcludePatternIterator getExcludePatternsBegin()
CDPL::Chem::FragmentGenerator::ConstFragmentLinkIterator
FragmentLinkList::const_iterator ConstFragmentLinkIterator
Definition: FragmentGenerator.hpp:146
FragmentList.hpp
Definition of the class CDPL::Chem::FragmentList.
CDPL::Chem::FragmentGenerator::clearExcludePatterns
void clearExcludePatterns()
CDPL::Chem::FragmentGenerator::FragmentationRule::FragmentationRule
FragmentationRule(const MolecularGraph::SharedPointer &match_ptn, unsigned int id)
CDPL::Chem::FragmentGenerator::FragmentationRule::setID
void setID(unsigned int id)
CDPL::Chem::FragmentGenerator::generate
void generate(const MolecularGraph &molgraph, FragmentList &frag_list, bool append=false)
CDPL::Chem::FragmentGenerator::getFragmentationRule
const FragmentationRule & getFragmentationRule(std::size_t idx) const
CDPL::Chem::FragmentGenerator::ExcludePatternIterator
ExcludePatternList::iterator ExcludePatternIterator
Definition: FragmentGenerator.hpp:144