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() {}
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  ,
48  dp_urfData(other.dp_urfData)
49 #endif
50  {
51  }
52 
53  //! checks to see if we've been properly initialized
54  bool isInitialized() const { return df_init; }
55  //! does initialization
56  void initialize();
57 
58  //! blows out all current data and de-initializes
59  void reset();
60 
61  //! adds a ring to our data
62  /*!
63  \param atomIndices the integer indices of the atoms involved in the ring
64  \param bondIndices the integer indices of the bonds involved in the ring,
65  this must be the same size as \c atomIndices.
66 
67  \return the number of rings
68 
69  <b>Notes:</b>
70  - the object must be initialized before calling this
71 
72  */
73  unsigned int addRing(const INT_VECT &atomIndices,
74  const INT_VECT &bondIndices);
75 
76  //! \name Atom information
77  //@{
78 
79  //! returns a vector with sizes of the rings that atom with index \c idx is
80  //! in.
81  /*!
82  <b>Notes:</b>
83  - the object must be initialized before calling this
84  */
85  INT_VECT atomRingSizes(unsigned int idx) const;
86  //! returns whether or not the atom with index \c idx is in a \c size - ring.
87  /*!
88  <b>Notes:</b>
89  - the object must be initialized before calling this
90  */
91  bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const;
92  //! returns the number of rings atom \c idx is involved in
93  /*!
94  <b>Notes:</b>
95  - the object must be initialized before calling this
96  */
97  unsigned int numAtomRings(unsigned int idx) const;
98  //! returns the size of the smallest ring atom \c idx is involved in
99  /*!
100  <b>Notes:</b>
101  - the object must be initialized before calling this
102  */
103  unsigned int minAtomRingSize(unsigned int idx) const;
104 
105  //! returns our \c atom-rings vectors
106  /*!
107  <b>Notes:</b>
108  - the object must be initialized before calling this
109  */
110  const VECT_INT_VECT &atomRings() const { return d_atomRings; }
111 
112  //@}
113 
114  //! \name Bond information
115  //@{
116 
117  //! returns a vector with sizes of the rings that bond with index \c idx is
118  //! in.
119  /*!
120  <b>Notes:</b>
121  - the object must be initialized before calling this
122  */
123  INT_VECT bondRingSizes(unsigned int idx) const;
124  //! returns whether or not the bond with index \c idx is in a \c size - ring.
125  /*!
126  <b>Notes:</b>
127  - the object must be initialized before calling this
128  */
129  bool isBondInRingOfSize(unsigned int idx, unsigned int size) const;
130  //! returns the number of rings bond \c idx is involved in
131  /*!
132  <b>Notes:</b>
133  - the object must be initialized before calling this
134  */
135  unsigned int numBondRings(unsigned int idx) const;
136  //! returns the size of the smallest ring bond \c idx is involved in
137  /*!
138  <b>Notes:</b>
139  - the object must be initialized before calling this
140  */
141  unsigned int minBondRingSize(unsigned int idx) const;
142 
143  //! returns the total number of rings
144  /*!
145  <b>Notes:</b>
146  - the object must be initialized before calling this
147  - if the RDKit has been built with URF support, this returns the number
148  of ring families.
149  */
150  unsigned int numRings() const;
151 
152  //! returns our \c bond-rings vectors
153  /*!
154  <b>Notes:</b>
155  - the object must be initialized before calling this
156  */
157  const VECT_INT_VECT &bondRings() const { return d_bondRings; }
158 
159 #ifdef RDK_USE_URF
160  //! adds a ring family to our data
161  /*!
162  \param atomIndices the integer indices of the atoms involved in the
163  ring family
164  \param bondIndices the integer indices of the bonds involved in the
165  ring family,
166  this must be the same size as \c atomIndices.
167 
168  \return the number of ring families
169 
170  <b>Notes:</b>
171  - the object must be initialized before calling this
172 
173  */
174  unsigned int addRingFamily(const INT_VECT &atomIndices,
175  const INT_VECT &bondIndices);
176  //! returns the total number of ring families
177  /*!
178  <b>Notes:</b>
179  - the object must be initialized before calling this
180  */
181  unsigned int numRingFamilies() const;
182 
183  //! returns the total number of relevant cycles
184  /*!
185  <b>Notes:</b>
186  - the object must be initialized before calling this
187  */
188  unsigned int numRelevantCycles() const;
189 
190  //! returns our atom ring family vectors
191  /*!
192  <b>Notes:</b>
193  - the object must be initialized before calling this
194  */
195  const VECT_INT_VECT &atomRingFamilies() const { return d_atomRingFamilies; }
196 
197  //! returns our bond ring family vectors
198  /*!
199  <b>Notes:</b>
200  - the object must be initialized before calling this
201  */
202  const VECT_INT_VECT &bondRingFamilies() const { return d_bondRingFamilies; }
203 
204  //! check if the ring families have been initialized
205  bool areRingFamiliesInitialized() const { return dp_urfData != nullptr; }
206 #endif
207 
208  //@}
209 
210  private:
211  //! pre-allocates some memory to save time later
212  void preallocate(unsigned int numAtoms, unsigned int numBonds);
213 
214  bool df_init{false};
215  DataType d_atomMembers, d_bondMembers;
216  VECT_INT_VECT d_atomRings, d_bondRings;
217  VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
218 
219 #ifdef RDK_USE_URF
220  public:
221  boost::shared_ptr<RDL_data> dp_urfData;
222 #endif
223 };
224 } // namespace RDKit
225 
226 #endif
handles pickling (serializing) molecules
Definition: MolPickler.h:68
A class to store information about a molecule's rings.
Definition: RingInfo.h:28
void reset()
blows out all current data and de-initializes
unsigned int numRings() const
returns the total number of rings
std::vector< MemberType > DataType
Definition: RingInfo.h:33
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
INT_VECT atomRingSizes(unsigned int idx) const
std::vector< int > INT_VECT
Definition: RingInfo.h:34
const VECT_INT_VECT & atomRings() const
returns our atom-rings vectors
Definition: RingInfo.h:110
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
RingInfo(const RingInfo &other)
Definition: RingInfo.h:38
INT_VECT bondRingSizes(unsigned int idx) const
unsigned int addRing(const INT_VECT &atomIndices, const INT_VECT &bondIndices)
adds a ring to our data
void initialize()
does initialization
unsigned int numAtomRings(unsigned int idx) const
returns the number of rings atom idx is involved in
bool isBondInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the bond with index idx is in a size - ring.
bool isInitialized() const
checks to see if we've been properly initialized
Definition: RingInfo.h:54
std::vector< int > MemberType
Definition: RingInfo.h:32
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
Definition: RingInfo.h:157
unsigned int minAtomRingSize(unsigned int idx) const
returns the size of the smallest ring atom idx is involved in
std::vector< INT_VECT > VECT_INT_VECT
Definition: RingInfo.h:35
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:209
Std stuff.
Definition: Abbreviations.h:18
std::vector< int > INT_VECT
Definition: types.h:274
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:288