RDKit
Open-source cheminformatics and machine learning.
RingInfo.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2022 Greg Landrum and other RDKit contributors
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>
16 #ifdef RDK_USE_URF
18 #include <boost/shared_ptr.hpp>
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) = default;
39  RingInfo &operator=(const RingInfo &other) = default;
40  RingInfo(RingInfo &&other) noexcept = default;
41  RingInfo &operator=(RingInfo &&other) noexcept = default;
42  //! checks to see if we've been properly initialized
43  bool isInitialized() const { return df_init; }
44  //! does initialization
45  void initialize();
46 
47  //! blows out all current data and de-initializes
48  void reset();
49 
50  //! adds a ring to our data
51  /*!
52  \param atomIndices the integer indices of the atoms involved in the ring
53  \param bondIndices the integer indices of the bonds involved in the ring,
54  this must be the same size as \c atomIndices.
55 
56  \return the number of rings
57 
58  <b>Notes:</b>
59  - the object must be initialized before calling this
60 
61  */
62  unsigned int addRing(const INT_VECT &atomIndices,
63  const INT_VECT &bondIndices);
64 
65  //! \name Atom information
66  //! @{
67 
68  //! returns a vector with sizes of the rings that atom with index \c idx is
69  //! in.
70  /*!
71  <b>Notes:</b>
72  - the object must be initialized before calling this
73  */
74  INT_VECT atomRingSizes(unsigned int idx) const;
75  //! returns whether or not the atom with index \c idx is in a \c size - ring.
76  /*!
77  <b>Notes:</b>
78  - the object must be initialized before calling this
79  */
80  bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const;
81  //! returns the number of rings atom \c idx is involved in
82  /*!
83  <b>Notes:</b>
84  - the object must be initialized before calling this
85  */
86  unsigned int numAtomRings(unsigned int idx) const;
87  //! returns the size of the smallest ring atom \c idx is involved in
88  /*!
89  <b>Notes:</b>
90  - the object must be initialized before calling this
91  */
92  unsigned int minAtomRingSize(unsigned int idx) const;
93 
94  //! returns our \c atom-rings vectors, i.e. a vector of int vectors
95  //! reporting the atom indices which are part of each ring
96  /*!
97  <b>Notes:</b>
98  - the object must be initialized before calling this
99  */
100  const VECT_INT_VECT &atomRings() const { return d_atomRings; }
101 
102  //! returns our \c atom-members vector for atom idx (i.e.,
103  //! a vector of ints reporting the ring indices that
104  //! atom idx is member of), or an empty vector if the atom is
105  //! not in any ring.
106  /*!
107  <b>Notes:</b>
108  - the object must be initialized before calling this
109  */
110  INT_VECT atomMembers(unsigned int idx) const;
111 
112  //! returns whether or not atoms with indices \c idx1 and \c idx2 belong to
113  //! the same ring.
114  /*!
115  <b>Notes:</b>
116  - the object must be initialized before calling this
117  */
118  bool areAtomsInSameRing(unsigned int idx1, unsigned int idx2) const {
119  return areAtomsInSameRingOfSize(idx1, idx2, 0);
120  }
121 
122  //! returns whether or not atoms with indices \c idx1 and \c idx2 belong to
123  //! the same ring of size \c size.
124  /*!
125  <b>Notes:</b>
126  - the object must be initialized before calling this
127  */
128  bool areAtomsInSameRingOfSize(unsigned int idx1, unsigned int idx2,
129  unsigned int size) const;
130 
131  //! @}
132 
133  //! \name Bond information
134  //! @{
135 
136  //! returns a vector with sizes of the rings that bond with index \c idx is
137  //! in.
138  /*!
139  <b>Notes:</b>
140  - the object must be initialized before calling this
141  */
142  INT_VECT bondRingSizes(unsigned int idx) const;
143  //! returns whether or not the bond with index \c idx is in a \c size - ring.
144  /*!
145  <b>Notes:</b>
146  - the object must be initialized before calling this
147  */
148  bool isBondInRingOfSize(unsigned int idx, unsigned int size) const;
149  //! returns the number of rings bond \c idx is involved in
150  /*!
151  <b>Notes:</b>
152  - the object must be initialized before calling this
153  */
154  unsigned int numBondRings(unsigned int idx) const;
155  //! returns the size of the smallest ring bond \c idx is involved in
156  /*!
157  <b>Notes:</b>
158  - the object must be initialized before calling this
159  */
160  unsigned int minBondRingSize(unsigned int idx) const;
161 
162  //! returns the total number of rings
163  /*!
164  <b>Notes:</b>
165  - the object must be initialized before calling this
166  - if the RDKit has been built with URF support, this returns the number
167  of ring families.
168  */
169  unsigned int numRings() const;
170 
171  //! returns our \c bond-rings vectors, i.e. a vector of int vectors
172  //! reporting the bond indices which are part of each ring
173  /*!
174  <b>Notes:</b>
175  - the object must be initialized before calling this
176  */
177  const VECT_INT_VECT &bondRings() const { return d_bondRings; }
178 
179  //! returns our \c bond-members vector for bond idx (i.e.,
180  //! a vector of ints reporting the ring indices that
181  //! bond idx is member of), or an empty vector if the bond is
182  //! not in any ring.
183  /*!
184  <b>Notes:</b>
185  - the object must be initialized before calling this
186  */
187  INT_VECT bondMembers(unsigned int idx) const;
188 
189  //! returns whether or not bonds with indices \c idx1 and \c idx2 belong to
190  //! the same ring.
191  /*!
192  <b>Notes:</b>
193  - the object must be initialized before calling this
194  */
195  bool areBondsInSameRing(unsigned int idx1, unsigned int idx2) const {
196  return areBondsInSameRingOfSize(idx1, idx2, 0);
197  }
198 
199  //! returns whether or not bonds with indices \c idx1 and \c idx2 belong to
200  //! the same ring of size \c size.
201  /*!
202  <b>Notes:</b>
203  - the object must be initialized before calling this
204  */
205  bool areBondsInSameRingOfSize(unsigned int idx1, unsigned int idx2,
206  unsigned int size) const;
207 
208 #ifdef RDK_USE_URF
209  //! adds a ring family to our data
210  /*!
211  \param atomIndices the integer indices of the atoms involved in the
212  ring family
213  \param bondIndices the integer indices of the bonds involved in the
214  ring family,
215  this must be the same size as \c atomIndices.
216 
217  \return the number of ring families
218 
219  <b>Notes:</b>
220  - the object must be initialized before calling this
221 
222  */
223  unsigned int addRingFamily(const INT_VECT &atomIndices,
224  const INT_VECT &bondIndices);
225  //! returns the total number of ring families
226  /*!
227  <b>Notes:</b>
228  - the object must be initialized before calling this
229  */
230  unsigned int numRingFamilies() const;
231 
232  //! returns the total number of relevant cycles
233  /*!
234  <b>Notes:</b>
235  - the object must be initialized before calling this
236  */
237  unsigned int numRelevantCycles() const;
238 
239  //! returns our atom ring family vectors
240  /*!
241  <b>Notes:</b>
242  - the object must be initialized before calling this
243  */
244  const VECT_INT_VECT &atomRingFamilies() const { return d_atomRingFamilies; }
245 
246  //! returns our bond ring family vectors
247  /*!
248  <b>Notes:</b>
249  - the object must be initialized before calling this
250  */
251  const VECT_INT_VECT &bondRingFamilies() const { return d_bondRingFamilies; }
252 
253  //! check if the ring families have been initialized
254  bool areRingFamiliesInitialized() const { return dp_urfData != nullptr; }
255 #endif
256 
257  //! @}
258 
259  private:
260  //! pre-allocates some memory to save time later
261  void preallocate(unsigned int numAtoms, unsigned int numBonds);
262  bool df_init{false};
263  DataType d_atomMembers, d_bondMembers;
264  VECT_INT_VECT d_atomRings, d_bondRings;
265  VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
266 
267 #ifdef RDK_USE_URF
268  public:
269  boost::shared_ptr<RDL_data> dp_urfData;
270 #endif
271 };
272 } // namespace RDKit
273 
274 #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
RingInfo(RingInfo &&other) noexcept=default
RingInfo & operator=(RingInfo &&other) noexcept=default
bool areBondsInSameRing(unsigned int idx1, unsigned int idx2) const
Definition: RingInfo.h:195
INT_VECT atomMembers(unsigned int idx) const
bool areAtomsInSameRing(unsigned int idx1, unsigned int idx2) const
Definition: RingInfo.h:118
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
bool areAtomsInSameRingOfSize(unsigned int idx1, unsigned int idx2, unsigned int size) const
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
RingInfo(const RingInfo &other)=default
INT_VECT atomRingSizes(unsigned int idx) const
std::vector< int > INT_VECT
Definition: RingInfo.h:34
const VECT_INT_VECT & atomRings() const
Definition: RingInfo.h:100
RingInfo & operator=(const RingInfo &other)=default
INT_VECT bondMembers(unsigned int idx) const
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
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
bool areBondsInSameRingOfSize(unsigned int idx1, unsigned int idx2, unsigned int size) const
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:43
std::vector< int > MemberType
Definition: RingInfo.h:32
const VECT_INT_VECT & bondRings() const
Definition: RingInfo.h:177
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:225
RDKIT_FORCEFIELDHELPERS_EXPORT bool areAtomsInSameRingOfSize(const ROMol &mol, const unsigned int ringSize, const unsigned int numAtoms,...)
Std stuff.
Definition: Abbreviations.h:19
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:292