Chemical Data Processing Library C++ API - Version 1.2.0
CompleteRingSet.hpp
Go to the documentation of this file.
1 /*
2  * CompleteRingSet.hpp
3  *
4  * Hanser algorithm for exhaustive ring perception in a molecular graph
5  * (Th. Hanser, Ph. Jauffret, G. Kaufmann, J. Chem. Inf. Comput. Sci. 1996, 36, 1146-1152)
6  *
7  * This file is part of the Chemical Data Processing Toolkit
8  *
9  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this library; see the file COPYING. If not, write to
23  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  */
26 
32 #ifndef CDPL_CHEM_COMPLETERINGSET_HPP
33 #define CDPL_CHEM_COMPLETERINGSET_HPP
34 
35 #include <queue>
36 #include <vector>
37 #include <list>
38 #include <cstddef>
39 #include <memory>
40 
41 #include "CDPL/Chem/APIPrefix.hpp"
43 #include "CDPL/Util/BitSet.hpp"
44 #include "CDPL/Util/ObjectPool.hpp"
45 
46 
47 namespace CDPL
48 {
49 
50  namespace Chem
51  {
52 
58  {
59 
60  public:
64  typedef std::shared_ptr<CompleteRingSet> SharedPointer;
65 
70 
75  CompleteRingSet(const MolecularGraph& molgraph);
76 
77  CompleteRingSet(const CompleteRingSet&) = delete;
78 
83 
85 
90  void perceive(const MolecularGraph& molgraph);
91 
92  private:
93  class Edge;
94  class Node;
95 
97  typedef EdgeCache::SharedObjectPointer EdgePtr;
98 
99  void init(const MolecularGraph&);
100  void reduce();
101 
102  EdgePtr allocEdge(const EdgePtr&, const EdgePtr&, Node*, Node*, bool);
103  EdgePtr allocEdge(const Bond&, Node*, Node*);
104 
105  const char* getClassName() const
106  {
107  return "CompleteRingSet";
108  }
109 
110  class Node
111  {
112 
113  typedef std::list<EdgePtr> EdgeList;
114 
115  public:
116  typedef EdgeList::iterator EdgeIterator;
117 
119  {
120 
121  bool operator()(const Node*, const Node*) const;
122  };
123 
124  Node(std::size_t idx):
125  index(idx) {}
126 
127  EdgeIterator addEdge(const EdgePtr&);
128  void removeEdge(const EdgeIterator&);
129 
130  EdgeIterator getEdgesBegin();
131  EdgeIterator getEdgesEnd();
132 
133  std::size_t getIndex() const;
134 
135  private:
136  std::size_t index;
137  EdgeList edges;
138  };
139 
140  class Edge
141  {
142 
143  public:
144  void init(const EdgePtr& this_edge, const MolecularGraph*, const Bond&, Node*, Node*);
145  void init(const EdgePtr& this_edge, const EdgePtr&, const EdgePtr&, Node*, Node*, bool);
146 
147  bool intersects(const EdgePtr&) const;
148 
149  Fragment::SharedPointer createRing(const MolecularGraph*) const;
150 
151  Node* getNeighbor(const Node*) const;
152  const Node::EdgeIterator& getEdgeListIterator(const Node*) const;
153 
154  private:
155  Node* nodes[2];
156  Node::EdgeIterator edgeListIters[2];
157  Util::BitSet bondPath;
158  Util::BitSet nodePath;
159  mutable Util::BitSet tmpBitMask;
160  };
161 
162  typedef std::vector<Node> NodeArray;
163  typedef std::priority_queue<Node*, std::vector<Node*>, Node::GreaterCmpFunc> NodeQueue;
164 
165  EdgeCache edgeCache;
166  const MolecularGraph* molGraph;
167  NodeArray nodes;
168  NodeQueue nodeQueue;
169  };
170  } // namespace Chem
171 } // namespace CDPL
172 
173 #endif // CDPL_CHEM_COMPLETERINGSET_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.
Bond.
Definition: Bond.hpp:50
Implements the exhaustive perception of rings in a molecular graph.
Definition: CompleteRingSet.hpp:58
CompleteRingSet & operator=(const CompleteRingSet &)=delete
std::shared_ptr< CompleteRingSet > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated CompleteRingSet instances.
Definition: CompleteRingSet.hpp:64
CompleteRingSet(const CompleteRingSet &)=delete
void perceive(const MolecularGraph &molgraph)
Replaces the current set of rings by the rings in the molecular graph molgraph.
CompleteRingSet()
Constructs an empty CompleteRingSet instance.
CompleteRingSet(const MolecularGraph &molgraph)
Constructs a CompleteRingSet instance that contains the rings in the molecular graph molgraph.
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
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.
Definition: CompleteRingSet.hpp:119
bool operator()(const Node *, const Node *) const