Chemical Data Processing Library C++ API - Version 1.0.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 
81 
86  void perceive(const MolecularGraph& molgraph);
87 
88  private:
89  class Edge;
90  class Node;
91 
93  typedef EdgeCache::SharedObjectPointer EdgePtr;
94 
96 
97  CompleteRingSet& operator=(const CompleteRingSet&);
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  class Node
106  {
107 
108  typedef std::list<EdgePtr> EdgeList;
109 
110  public:
111  typedef EdgeList::iterator EdgeIterator;
112 
114  {
115 
116  bool operator()(const Node*, const Node*) const;
117  };
118 
119  Node(std::size_t idx):
120  index(idx) {}
121 
122  EdgeIterator addEdge(const EdgePtr&);
123  void removeEdge(const EdgeIterator&);
124 
125  EdgeIterator getEdgesBegin();
126  EdgeIterator getEdgesEnd();
127 
128  std::size_t getIndex() const;
129 
130  private:
131  std::size_t index;
132  EdgeList edges;
133  };
134 
135  class Edge
136  {
137 
138  public:
139  void init(const EdgePtr& this_edge, const MolecularGraph*, const Bond&, Node*, Node*);
140  void init(const EdgePtr& this_edge, const EdgePtr&, const EdgePtr&, Node*, Node*, bool);
141 
142  bool intersects(const EdgePtr&) const;
143 
144  Fragment::SharedPointer createRing(const MolecularGraph*) const;
145 
146  Node* getNeighbor(const Node*) const;
147  const Node::EdgeIterator& getEdgeListIterator(const Node*) const;
148 
149  private:
150  Node* nodes[2];
151  Node::EdgeIterator edgeListIters[2];
152  Util::BitSet bondPath;
153  Util::BitSet nodePath;
154  mutable Util::BitSet tmpBitMask;
155  };
156 
157  typedef std::vector<Node> NodeArray;
158  typedef std::priority_queue<Node*, std::vector<Node*>, Node::GreaterCmpFunc> NodeQueue;
159 
160  EdgeCache edgeCache;
161  const MolecularGraph* molGraph;
162  NodeArray nodes;
163  NodeQueue nodeQueue;
164  };
165  } // namespace Chem
166 } // namespace CDPL
167 
168 #endif // CDPL_CHEM_COMPLETERINGSET_HPP
CDPL::Chem::CompleteRingSet::perceive
void perceive(const MolecularGraph &molgraph)
Replaces the current set of rings by the rings in the molecular graph molgraph.
ObjectPool.hpp
Definition of the class CDPL::Util::ObjectPool.
CDPL::Chem::CompleteRingSet::SharedPointer
std::shared_ptr< CompleteRingSet > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated CompleteRingSet instances.
Definition: CompleteRingSet.hpp:64
APIPrefix.hpp
Definition of the preprocessor macro CDPL_CHEM_API.
CDPL_CHEM_API
#define CDPL_CHEM_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
CDPL::Chem::Bond
Bond.
Definition: Bond.hpp:50
CDPL::Chem::CompleteRingSet
Implements the exhaustive perception of rings in a molecular graph.
Definition: CompleteRingSet.hpp:58
CDPL::Chem::CompleteRingSet::CompleteRingSet
CompleteRingSet(const MolecularGraph &molgraph)
Constructs a CompleteRingSet instance that contains the rings in the molecular graph molgraph.
CDPL::Util::BitSet
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
CDPL::Chem::MolecularGraph
MolecularGraph.
Definition: MolecularGraph.hpp:52
BitSet.hpp
Definition of the type CDPL::Util::BitSet.
CDPL::Util::ObjectPool< Edge >::SharedObjectPointer
std::shared_ptr< ObjectType > SharedObjectPointer
Definition: ObjectPool.hpp:64
CDPL::Util::ObjectPool< Edge >
CDPL::Chem::Fragment::SharedPointer
std::shared_ptr< Fragment > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Fragment instances.
Definition: Fragment.hpp:61
CDPL::Chem::FragmentList
A data type for the storage of Chem::Fragment objects.
Definition: FragmentList.hpp:49
CDPL::Chem::CompleteRingSet::Node::GreaterCmpFunc
Definition: CompleteRingSet.hpp:114
CDPL::Chem::CompleteRingSet::CompleteRingSet
CompleteRingSet()
Constructs an empty CompleteRingSet instance.
CDPL
The namespace of the Chemical Data Processing Library.
CDPL::Chem::CompleteRingSet::Node::GreaterCmpFunc::operator()
bool operator()(const Node *, const Node *) const
CDPL::Chem::CompleteRingSet::~CompleteRingSet
~CompleteRingSet()
Destructor.
FragmentList.hpp
Definition of the class CDPL::Chem::FragmentList.