Open Babel  3.0
ring.h
Go to the documentation of this file.
1 /**********************************************************************
2 ring.h - Deal with rings, find smallest set of smallest rings (SSSR).
3 
4 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5 Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
6 
7 This file is part of the Open Babel project.
8 For more information, see <http://openbabel.org/>
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation version 2 of the License.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 ***********************************************************************/
19 
20 #ifndef OB_RING_H
21 #define OB_RING_H
22 
23 #include <deque>
24 #include <algorithm>
25 
26 // TODO: Make this work as a free-standing header
27 // Currently only used in ring.cpp which imports mol.h beforehand
28 #include <openbabel/bitvec.h>
29 #include <openbabel/typer.h>
30 
31 namespace OpenBabel
32 {
33 
34  class OBMol;
35  class OBAtom;
36  class OBBond;
37  class vector3;
38 
39  // class introduction in ring.cpp
40  class OBAPI OBRing
41  {
42  OBMol *_parent;
43  public:
44  //public data members
45  int ring_id;
46  std::vector<int> _path;
48 
50 
51  OBRing() {}
53  OBRing(std::vector<int>& path, int size);
54  OBRing(std::vector<int>& path, OBBitVec set) : _path(path), _pathset(set) {}
55  OBRing(const OBRing &src);
56  OBRing& operator=(const OBRing &src);
58 
59  //member functions
60 
62  size_t Size() const { return(_path.size()); }
65  size_t PathSize() const { return(_path.size()); }
66 
70  bool IsAromatic();
71 
73  void SetType(char *type);
75  void SetType(std::string &type);
77  char *GetType();
81  unsigned int GetRootAtom();
82 
84  bool IsMember(OBAtom *a);
87  bool IsMember(OBBond *b);
89  bool IsInRing(int i)
90  {
91  return(_pathset.BitIsSet(i));
92  }
93 
95  void SetParent(OBMol *m) { _parent = m; }
97  OBMol *GetParent() { return(_parent);}
98 
105  bool findCenterAndNormal(vector3 & center, vector3 &norm1, vector3 &norm2);
106  private:
107  char _type[30];
108  };
109 
112  OBAPI bool CompareRingSize(const OBRing *,const OBRing *);
113 
114 
118  class OBAPI OBRingSearch
119  {
120  std::vector<OBBond*> _bonds;
121  std::vector<OBRing*> _rlist;
122  public:
124  ~OBRingSearch();
125 
127  void SortRings()
128  {
129  std::vector<OBRing*>::iterator j;
130  int ring_id; // for each ring, assign a unique id to ensure a stable sort
131 
132  for (j = _rlist.begin(), ring_id = 0; j != _rlist.end(); ++j, ++ring_id)
133  (*j)->ring_id = ring_id;
134  std::sort(_rlist.begin(),_rlist.end(),CompareRingSize);
135  }
137  void RemoveRedundant(int);
139  void AddRingFromClosure(OBMol &,OBBond *);
140 
141  bool SaveUniqueRing(std::deque<int>&,std::deque<int>&);
142 
144  void WriteRings();
145 
147 
148  std::vector<OBRing*>::iterator BeginRings()
150  {
151  return(_rlist.begin());
152  }
154  std::vector<OBRing*>::iterator EndRings()
155  {
156  return(_rlist.end());
157  }
159  };
160 
165  class OBAPI OBRTree
166  {
167  OBAtom *_atom;
168  OBRTree *_prv;
169  public:
172  ~OBRTree() {}
173 
175  int GetAtomIdx();
177  void PathToRoot(std::vector<OBAtom*>&);
178  };
179 
180 } // end namespace OpenBabel
181 
182 #endif // OB_RING_H
183 
Stores information on rings in a molecule from SSSR perception.
Definition: ring.h:40
bool BitIsSet(unsigned bit_offset) const
Asks if the bit_offset &#39;th bit is set.
Definition: bitvec.h:150
Internal class to facilitate OBMol::FindSSSR()
Definition: ring.h:118
Bond class.
Definition: bond.h:58
Molecule Class.
Definition: mol.h:118
bool CompareRingSize(const OBRing *, const OBRing *)
Definition: ring.cpp:486
OBRing(std::vector< int > &path, OBBitVec set)
Definition: ring.h:54
OBRing()
Definition: ring.h:51
Internal class for OBRing search algorithms to create a search tree of OBAtom objects.
Definition: ring.h:165
void SortRings()
Sort ring sizes from smallest to largest.
Definition: ring.h:127
bool IsInRing(int i)
Definition: ring.h:89
std::vector< OBRing * >::iterator EndRings()
Definition: ring.h:154
A speed-optimized vector of bits.
Definition: bitvec.h:57
int ring_id
a unique id to ensure a stable sort in SSSR determination
Definition: ring.h:45
size_t PathSize() const
Definition: ring.h:65
std::vector< int > _path
the path of this ring (i.e., the atom indexes)
Definition: ring.h:46
Represents a vector in 3-dimensional real space.
Definition: vector3.h:44
OBBitVec _pathset
the path of this ring as a redundant bit vector
Definition: ring.h:47
~OBRTree()
Definition: ring.h:172
OBMol * GetParent()
Definition: ring.h:97
Open Babel atom and aromaticity typer.
size_t Size() const
Definition: ring.h:62
OBRingSearch()
Definition: ring.h:123
Fast and efficient bitstring class.
void SetParent(OBMol *m)
Set the parent of this ring to m.
Definition: ring.h:95
Global namespace for all Open Babel code.
Definition: alias.h:22
Atom class.
Definition: atom.h:71