Chemical Data Processing Library C++ API - Version 1.2.0
ConnectedSubstructureSet.hpp
Go to the documentation of this file.
1 /*
2  * ConnectedSubstructureSet.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_CONNECTEDSUBSTRUCTURESET_HPP
30 #define CDPL_CHEM_CONNECTEDSUBSTRUCTURESET_HPP
31 
32 #include <cstddef>
33 #include <vector>
34 #include <memory>
35 
36 #include "CDPL/Chem/APIPrefix.hpp"
38 #include "CDPL/Util/BitSet.hpp"
39 #include "CDPL/Util/ObjectPool.hpp"
40 
41 
42 namespace CDPL
43 {
44 
45  namespace Chem
46  {
47 
52  {
53 
54  public:
58  typedef std::shared_ptr<ConnectedSubstructureSet> SharedPointer;
59 
64 
70 
72 
74 
82  void reset(const MolecularGraph& molgraph);
83 
94  void findSubstructures(std::size_t size);
95 
104  std::size_t getSubstructureSize() const;
105 
106  private:
107  class SubstructDescriptor;
108 
110  typedef SubstructDescriptorCache::SharedObjectPointer SubstructDescriptorPtr;
111 
112  void reset();
113 
114  void growSubstructDescriptors(std::size_t);
115  void createSubstructFragments();
116 
117  SubstructDescriptorPtr allocSubstructDescriptor(const Bond&);
118 
119  const char* getClassName() const
120  {
121  return "ConnectedSubstructureSet";
122  }
123 
124  class SubstructDescriptor
125  {
126 
127  public:
128  void init(const MolecularGraph*, const Bond&);
129 
130  bool grow(const Util::BitSet&);
131  void ungrow();
132 
133  Fragment::SharedPointer createFragment() const;
134 
135  void copy(const SubstructDescriptor&);
136 
137  bool operator<(const SubstructDescriptor&) const;
138 
139  private:
140  typedef std::vector<const Atom*> AtomList;
141  typedef std::vector<std::size_t> BondCountList;
142 
143  const MolecularGraph* molGraph;
144  Util::BitSet bondMask;
145  AtomList unsatAtoms;
146  BondCountList atomBondCounts;
147  std::size_t unsatAListIdx;
148  std::size_t nbrBListIdx;
149  std::size_t lastBondIdx;
150  bool addedAtom;
151  const Atom* startAtom;
152  };
153 
154  struct SubstructDescriptorLessCmpFunc
155  {
156 
157  bool operator()(const SubstructDescriptorPtr&, const SubstructDescriptorPtr&) const;
158  };
159 
160  typedef std::vector<SubstructDescriptorPtr> SubstructDescriptorList;
161 
162  SubstructDescriptorCache substructDescrCache;
163  SubstructDescriptorList foundSubstructDescriptors;
164  Util::BitSet bondMask;
165  std::size_t currSubstructSize;
166  const MolecularGraph* molGraph;
167  };
168  } // namespace Chem
169 } // namespace CDPL
170 
171 #endif // CDPL_CHEM_CONNECTEDSUBSTRUCTURESET_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::Util::ObjectPool.
Atom.
Definition: Atom.hpp:52
Bond.
Definition: Bond.hpp:50
ConnectedSubstructureSet.
Definition: ConnectedSubstructureSet.hpp:52
ConnectedSubstructureSet()
Constructs an empty ConnectedSubstructureSet instance.
ConnectedSubstructureSet & operator=(const ConnectedSubstructureSet &)=delete
ConnectedSubstructureSet(const MolecularGraph &molgraph)
Constructs and initialzes a ConnectedSubstructureSet instance for the molecular graph molgraph.
void reset(const MolecularGraph &molgraph)
Specifies the molecular graph that is searched for connected substructures.
void findSubstructures(std::size_t size)
Searches the specified molecular graph for connected substructures of the given size.
std::size_t getSubstructureSize() const
Returns the current substructure size in terms of number of bonds.
std::shared_ptr< ConnectedSubstructureSet > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated ConnectedSubstructureSet instance...
Definition: ConnectedSubstructureSet.hpp:58
ConnectedSubstructureSet(const ConnectedSubstructureSet &)=delete
A data type for the storage of Chem::Fragment objects.
Definition: FragmentList.hpp:49
std::shared_ptr< Fragment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Fragment instances.
Definition: Fragment.hpp:61
MolecularGraph.
Definition: MolecularGraph.hpp:52
std::shared_ptr< ObjectType > SharedObjectPointer
Definition: ObjectPool.hpp:65
bool operator<(const Array< ValueType > &array1, const Array< ValueType > &array2)
Less than comparison operator.
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.