RDKit
Open-source cheminformatics and machine learning.
RingInfo.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2019 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #include <RDGeneral/export.h>
11 #ifndef _RD_RINGINFO_H
12 #define _RD_RINGINFO_H
13 
14 #include <map>
15 #include <vector>
17 #include <boost/shared_ptr.hpp>
19 #ifdef RDK_USE_URF
20 #include <RingDecomposerLib.h>
21 #endif
22 
23 namespace RDKit {
24 //! A class to store information about a molecule's rings
25 /*!
26 
27  */
29  friend class MolPickler;
30 
31  public:
32  typedef std::vector<int> MemberType;
33  typedef std::vector<MemberType> DataType;
34  typedef std::vector<int> INT_VECT;
35  typedef std::vector<INT_VECT> VECT_INT_VECT;
36 
37  RingInfo() : df_init(false){};
38  RingInfo(const RingInfo &other)
39  : df_init(other.df_init),
40  d_atomMembers(other.d_atomMembers),
41  d_bondMembers(other.d_bondMembers),
42  d_atomRings(other.d_atomRings),
43  d_bondRings(other.d_bondRings),
44  d_atomRingFamilies(other.d_atomRingFamilies),
45  d_bondRingFamilies(other.d_bondRingFamilies)
46 #ifdef RDK_USE_URF
47  ,dp_urfData(other.dp_urfData)
48 #endif
49  {};
50 
51  //! checks to see if we've been properly initialized
52  bool isInitialized() const { return df_init; };
53  //! does initialization
54  void initialize();
55 
56  //! blows out all current data and de-initializes
57  void reset();
58 
59  //! adds a ring to our data
60  /*!
61  \param atomIndices the integer indices of the atoms involved in the ring
62  \param bondIndices the integer indices of the bonds involved in the ring,
63  this must be the same size as \c atomIndices.
64 
65  \return the number of rings
66 
67  <b>Notes:</b>
68  - the object must be initialized before calling this
69 
70  */
71  unsigned int addRing(const INT_VECT &atomIndices,
72  const INT_VECT &bondIndices);
73 
74  //! \name Atom information
75  //@{
76 
77  //! returns a vector with sizes of the rings that atom with index \c idx is in.
78  /*!
79  <b>Notes:</b>
80  - the object must be initialized before calling this
81  */
82  INT_VECT atomRingSizes(unsigned int idx) const;
83  //! returns whether or not the atom with index \c idx is in a \c size - ring.
84  /*!
85  <b>Notes:</b>
86  - the object must be initialized before calling this
87  */
88  bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const;
89  //! returns the number of rings atom \c idx is involved in
90  /*!
91  <b>Notes:</b>
92  - the object must be initialized before calling this
93  */
94  unsigned int numAtomRings(unsigned int idx) const;
95  //! returns the size of the smallest ring atom \c idx is involved in
96  /*!
97  <b>Notes:</b>
98  - the object must be initialized before calling this
99  */
100  unsigned int minAtomRingSize(unsigned int idx) const;
101 
102  //! returns our \c atom-rings vectors
103  /*!
104  <b>Notes:</b>
105  - the object must be initialized before calling this
106  */
107  const VECT_INT_VECT &atomRings() const { return d_atomRings; };
108 
109  //@}
110 
111  //! \name Bond information
112  //@{
113 
114  //! returns a vector with sizes of the rings that bond with index \c idx is in.
115  /*!
116  <b>Notes:</b>
117  - the object must be initialized before calling this
118  */
119  INT_VECT bondRingSizes(unsigned int idx) const;
120  //! returns whether or not the bond with index \c idx is in a \c size - ring.
121  /*!
122  <b>Notes:</b>
123  - the object must be initialized before calling this
124  */
125  bool isBondInRingOfSize(unsigned int idx, unsigned int size) const;
126  //! returns the number of rings bond \c idx is involved in
127  /*!
128  <b>Notes:</b>
129  - the object must be initialized before calling this
130  */
131  unsigned int numBondRings(unsigned int idx) const;
132  //! returns the size of the smallest ring bond \c idx is involved in
133  /*!
134  <b>Notes:</b>
135  - the object must be initialized before calling this
136  */
137  unsigned int minBondRingSize(unsigned int idx) const;
138 
139  //! returns the total number of rings
140  /*!
141  <b>Notes:</b>
142  - the object must be initialized before calling this
143  - if the RDKit has been built with URF support, this returns the number
144  of ring families.
145  */
146  unsigned int numRings() const;
147 
148  //! returns our \c bond-rings vectors
149  /*!
150  <b>Notes:</b>
151  - the object must be initialized before calling this
152  */
153  const VECT_INT_VECT &bondRings() const { return d_bondRings; };
154 
155 #ifdef RDK_USE_URF
156  //! adds a ring family to our data
157  /*!
158  \param atomIndices the integer indices of the atoms involved in the
159  ring family
160  \param bondIndices the integer indices of the bonds involved in the
161  ring family,
162  this must be the same size as \c atomIndices.
163 
164  \return the number of ring families
165 
166  <b>Notes:</b>
167  - the object must be initialized before calling this
168 
169  */
170  unsigned int addRingFamily(const INT_VECT &atomIndices,
171  const INT_VECT &bondIndices);
172  //! returns the total number of ring families
173  /*!
174  <b>Notes:</b>
175  - the object must be initialized before calling this
176  */
177  unsigned int numRingFamilies() const;
178 
179  //! returns the total number of relevant cycles
180  /*!
181  <b>Notes:</b>
182  - the object must be initialized before calling this
183  */
184  unsigned int numRelevantCycles() const;
185 
186  //! returns our atom ring family vectors
187  /*!
188  <b>Notes:</b>
189  - the object must be initialized before calling this
190  */
191  const VECT_INT_VECT &atomRingFamilies() const { return d_atomRingFamilies; };
192 
193  //! returns our bond ring family vectors
194  /*!
195  <b>Notes:</b>
196  - the object must be initialized before calling this
197  */
198  const VECT_INT_VECT &bondRingFamilies() const { return d_bondRingFamilies; };
199 
200  //! check if the ring families have been initialized
201  bool areRingFamiliesInitialized() const { return dp_urfData != NULL; }
202 #endif
203 
204  //@}
205 
206  private:
207  //! pre-allocates some memory to save time later
208  void preallocate(unsigned int numAtoms, unsigned int numBonds);
209 
210  bool df_init;
211  DataType d_atomMembers, d_bondMembers;
212  VECT_INT_VECT d_atomRings, d_bondRings;
213  VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
214 
215 #ifdef RDK_USE_URF
216  public:
217  boost::shared_ptr<RDL_data> dp_urfData;
218 #endif
219 };
220 } // namespace RDKit
221 
222 #endif
RDKit::RingInfo::initialize
void initialize()
does initialization
RDKit::RingInfo::addRing
unsigned int addRing(const INT_VECT &atomIndices, const INT_VECT &bondIndices)
adds a ring to our data
RDKit::RingInfo::numAtomRings
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
RDKit::VECT_INT_VECT
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:280
RDKit::INT_VECT
std::vector< int > INT_VECT
Definition: types.h:266
BoostStartInclude.h
RDKit::RingInfo::numBondRings
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
RDKit::RingInfo::minBondRingSize
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
RDKit::RingInfo::bondRingSizes
INT_VECT bondRingSizes(unsigned int idx) const
returns a vector with sizes of the rings that bond with index idx is in.
RDKit::RingInfo::reset
void reset()
blows out all current data and de-initializes
RDKit::RingInfo::DataType
std::vector< MemberType > DataType
Definition: RingInfo.h:33
BoostEndInclude.h
RDKit::RingInfo::bondRings
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
Definition: RingInfo.h:153
RDKit::RingInfo::numRings
unsigned int numRings() const
returns the total number of rings
RDKit::RingInfo
A class to store information about a molecule's rings.
Definition: RingInfo.h:28
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::RingInfo::MemberType
std::vector< int > MemberType
Definition: RingInfo.h:32
RDKit::RingInfo::atomRings
const VECT_INT_VECT & atomRings() const
returns our atom-rings vectors
Definition: RingInfo.h:107
RDKit::RingInfo::RingInfo
RingInfo(const RingInfo &other)
Definition: RingInfo.h:38
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::RingInfo::isBondInRingOfSize
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
RDKit::RingInfo::isAtomInRingOfSize
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
RDKit::MolPickler
handles pickling (serializing) molecules
Definition: MolPickler.h:65
RDKit::RingInfo::isInitialized
bool isInitialized() const
checks to see if we've been properly initialized
Definition: RingInfo.h:52
RDKit::RingInfo::VECT_INT_VECT
std::vector< INT_VECT > VECT_INT_VECT
Definition: RingInfo.h:35
RDKit::RingInfo::atomRingSizes
INT_VECT atomRingSizes(unsigned int idx) const
returns a vector with sizes of the rings that atom with index idx is in.
RDKit::RingInfo::minAtomRingSize
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
RDKit::RingInfo::RingInfo
RingInfo()
Definition: RingInfo.h:37
RDKit::RingInfo::INT_VECT
std::vector< int > INT_VECT
Definition: RingInfo.h:34
export.h