RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
RingInfo.h
Go to the documentation of this file.
1//
2// Copyright (C) 2004-2026 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>
17#include <boost/dynamic_bitset.hpp>
18#include <boost/shared_ptr.hpp>
20#include <RingDecomposerLib.h>
21
22namespace RDKit {
23//! A class to store information about a molecule's rings
24/*!
25
26 */
33
35 friend class MolPickler;
36
37 public:
38 typedef std::vector<int> MemberType;
39 typedef std::vector<MemberType> DataType;
40 typedef std::vector<int> INT_VECT;
41 typedef std::vector<INT_VECT> VECT_INT_VECT;
42
44 RingInfo(const RingInfo &other) = default;
45 RingInfo &operator=(const RingInfo &other) = default;
46 RingInfo(RingInfo &&other) noexcept = default;
47 RingInfo &operator=(RingInfo &&other) noexcept = default;
48 //! checks to see if we've been properly initialized
49 bool isInitialized() const { return df_init; }
50 //! does initialization
53 RDKit::FIND_RING_TYPE getRingType() const { return df_find_type_type; };
54 //! blows out all current data and de-initializes
55 void reset(bool resetRingFamilies = true);
56
57 bool isFindFastOrBetter() const {
58 return df_init && (df_find_type_type == FIND_RING_TYPE_FAST ||
59 df_find_type_type == FIND_RING_TYPE_SSSR ||
60 df_find_type_type == FIND_RING_TYPE_SYMM_SSSR);
61 }
62
63 bool isSssrOrBetter() const {
64 return df_init && (df_find_type_type == FIND_RING_TYPE_SSSR ||
65 df_find_type_type == FIND_RING_TYPE_SYMM_SSSR);
66 }
67
68 bool isSymmSssr() const {
69 return df_init && df_find_type_type == FIND_RING_TYPE_SYMM_SSSR;
70 }
71
72 //! adds a ring to our data
73 /*!
74 \param atomIndices the integer indices of the atoms involved in the ring
75 \param bondIndices the integer indices of the bonds involved in the ring,
76 this must be the same size as \c atomIndices.
77
78 \return the number of rings
79
80 <b>Notes:</b>
81 - the object must be initialized before calling this
82
83 */
84 unsigned int addRing(const INT_VECT &atomIndices,
85 const INT_VECT &bondIndices);
86
87 //! \name Atom information
88 //! @{
89
90 //! returns a vector with sizes of the rings that atom with index \c idx is
91 //! in.
92 /*!
93 <b>Notes:</b>
94 - the object must be initialized before calling this
95 */
96 INT_VECT atomRingSizes(unsigned int idx) const;
97 //! returns whether or not the atom with index \c idx is in a \c size - ring.
98 /*!
99 <b>Notes:</b>
100 - the object must be initialized before calling this
101 */
102 bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const;
103 //! returns the number of rings atom \c idx is involved in
104 /*!
105 <b>Notes:</b>
106 - the object must be initialized before calling this
107 */
108 unsigned int numAtomRings(unsigned int idx) const;
109 //! returns the size of the smallest ring atom \c idx is involved in
110 /*!
111 <b>Notes:</b>
112 - the object must be initialized before calling this
113 */
114 unsigned int minAtomRingSize(unsigned int idx) const;
115
116 //! returns our \c atom-rings vectors, i.e. a vector of int vectors
117 //! reporting the atom indices which are part of each ring
118 /*!
119 <b>Notes:</b>
120 - the object must be initialized before calling this
121 */
122 const VECT_INT_VECT &atomRings() const { return d_atomRings; }
123
124 //! returns our \c atom-members vector for atom idx (i.e.,
125 //! a vector of ints reporting the ring indices that
126 //! atom idx is member of), or an empty vector if the atom is
127 //! not in any ring.
128 /*!
129 <b>Notes:</b>
130 - the object must be initialized before calling this
131 */
132 const INT_VECT &atomMembers(unsigned int idx) const;
133
134 //! returns whether or not atoms with indices \c idx1 and \c idx2 belong to
135 //! the same ring.
136 /*!
137 <b>Notes:</b>
138 - the object must be initialized before calling this
139 */
140 bool areAtomsInSameRing(unsigned int idx1, unsigned int idx2) const {
141 return areAtomsInSameRingOfSize(idx1, idx2, 0);
142 }
143
144 //! returns whether or not atoms with indices \c idx1 and \c idx2 belong to
145 //! the same ring of size \c size.
146 /*!
147 <b>Notes:</b>
148 - the object must be initialized before calling this
149 */
150 bool areAtomsInSameRingOfSize(unsigned int idx1, unsigned int idx2,
151 unsigned int size) const;
152
153 //! @}
154
155 //! \name Bond information
156 //! @{
157
158 //! returns a vector with sizes of the rings that bond with index \c idx is
159 //! in.
160 /*!
161 <b>Notes:</b>
162 - the object must be initialized before calling this
163 */
164 INT_VECT bondRingSizes(unsigned int idx) const;
165 //! returns whether or not the bond with index \c idx is in a \c size - ring.
166 /*!
167 <b>Notes:</b>
168 - the object must be initialized before calling this
169 */
170 bool isBondInRingOfSize(unsigned int idx, unsigned int size) const;
171 //! returns the number of rings bond \c idx is involved in
172 /*!
173 <b>Notes:</b>
174 - the object must be initialized before calling this
175 */
176 unsigned int numBondRings(unsigned int idx) const;
177 //! returns the size of the smallest ring bond \c idx is involved in
178 /*!
179 <b>Notes:</b>
180 - the object must be initialized before calling this
181 */
182 unsigned int minBondRingSize(unsigned int idx) const;
183
184 //! returns the total number of rings
185 /*!
186 <b>Notes:</b>
187 - the object must be initialized before calling this
188 - if the RDKit has been built with URF support, this returns the number
189 of ring families.
190 */
191 unsigned int numRings() const;
192
193 //! returns our \c bond-rings vectors, i.e. a vector of int vectors
194 //! reporting the bond indices which are part of each ring
195 /*!
196 <b>Notes:</b>
197 - the object must be initialized before calling this
198 */
199 const VECT_INT_VECT &bondRings() const { return d_bondRings; }
200
201 //! returns our \c bond-members vector for bond idx (i.e.,
202 //! a vector of ints reporting the ring indices that
203 //! bond idx is member of), or an empty vector if the bond is
204 //! not in any ring.
205 /*!
206 <b>Notes:</b>
207 - the object must be initialized before calling this
208 */
209 const INT_VECT &bondMembers(unsigned int idx) const;
210
211 //! returns whether or not bonds with indices \c idx1 and \c idx2 belong to
212 //! the same ring.
213 /*!
214 <b>Notes:</b>
215 - the object must be initialized before calling this
216 */
217 bool areBondsInSameRing(unsigned int idx1, unsigned int idx2) const {
218 return areBondsInSameRingOfSize(idx1, idx2, 0);
219 }
220
221 //! returns whether or not bonds with indices \c idx1 and \c idx2 belong to
222 //! the same ring of size \c size.
223 /*!
224 <b>Notes:</b>
225 - the object must be initialized before calling this
226 */
227 bool areBondsInSameRingOfSize(unsigned int idx1, unsigned int idx2,
228 unsigned int size) const;
229
230 //! returns whether ring with index \c ringIdx is fused with other rings.
231 /*!
232 <b>Notes:</b>
233 - the object must be initialized before calling this
234 */
235 bool isRingFused(unsigned int ringIdx);
236
237 //! returns whether rings with indices \c ring1Idx and \c ring2Idx have
238 //! at least one bond in common.
239 /*!
240 <b>Notes:</b>
241 - the object must be initialized before calling this
242 */
243 bool areRingsFused(unsigned int ring1Idx, unsigned int ring2Idx);
244
245 //! returns the number of bonds shared with other rings in ring with index
246 //! \c ringIdx.
247 /*!
248 <b>Notes:</b>
249 - the object must be initialized before calling this
250 */
251 unsigned int numFusedBonds(unsigned int ringIdx);
252
253 //! returns the number of rings which have at least one bond
254 //! in common with ring with index \c ringIdx.
255 /*!
256 <b>Notes:</b>
257 - the object must be initialized before calling this
258 */
259 unsigned int numFusedRingNeighbors(unsigned int ringIdx);
260
261 //! returns the indices of rings which have at least one bond
262 //! in common with ring with index \c ringIdx.
263 /*!
264 <b>Notes:</b>
265 - the object must be initialized before calling this
266 */
267 std::vector<unsigned int> fusedRingNeighbors(unsigned int ringIdx);
268
269 //! adds a ring family to our data
270 /*!
271 \param atomIndices the integer indices of the atoms involved in the
272 ring family
273 \param bondIndices the integer indices of the bonds involved in the
274 ring family,
275 this must be the same size as \c atomIndices.
276
277 \return the number of ring families
278
279 <b>Notes:</b>
280 - the object must be initialized before calling this
281
282 */
283 unsigned int addRingFamily(const INT_VECT &atomIndices,
284 const INT_VECT &bondIndices);
285 //! returns the total number of ring families
286 /*!
287 <b>Notes:</b>
288 - the object must be initialized before calling this
289 */
290 unsigned int numRingFamilies() const;
291
292 //! returns the total number of relevant cycles
293 /*!
294 <b>Notes:</b>
295 - the object must be initialized before calling this
296 */
297 unsigned int numRelevantCycles() const;
298
299 //! returns our atom ring family vectors
300 /*!
301 <b>Notes:</b>
302 - the object must be initialized before calling this
303 */
304 const VECT_INT_VECT &atomRingFamilies() const { return d_atomRingFamilies; }
306
307 //! returns our bond ring family vectors
308 /*!
309 <b>Notes:</b>
310 - the object must be initialized before calling this
311 */
312 const VECT_INT_VECT &bondRingFamilies() const { return d_bondRingFamilies; }
313
314 //! check if the ring families have been initialized
315 bool areRingFamiliesInitialized() const { return dp_urfData != nullptr; }
316
317 //! reset ring family information
319
320 //! @}
321
322 //! pre-allocates some memory to save time later
323 void preallocate(unsigned int numAtoms, unsigned int numBonds);
324
325 private:
326 void initFusedRings();
327 bool df_init{false};
329 DataType d_atomMembers, d_bondMembers;
330 VECT_INT_VECT d_atomRings, d_bondRings;
331 VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
332 std::vector<boost::dynamic_bitset<>> d_fusedRings;
333 std::vector<unsigned int> d_numFusedBonds;
334
335 public:
336 boost::shared_ptr<RDL_data> dp_urfData;
337};
338
339} // namespace RDKit
340
341#endif
bool isSymmSssr() const
Definition RingInfo.h:68
RingInfo(RingInfo &&other) noexcept=default
const VECT_INT_VECT & atomRings() const
Definition RingInfo.h:122
bool areBondsInSameRing(unsigned int idx1, unsigned int idx2) const
Definition RingInfo.h:217
unsigned int numRingFamilies() const
returns the total number of ring families
bool areRingsFused(unsigned int ring1Idx, unsigned int ring2Idx)
RingInfo & operator=(RingInfo &&other) noexcept=default
unsigned int addRingFamily(const INT_VECT &atomIndices, const INT_VECT &bondIndices)
adds a ring family to our data
bool areAtomsInSameRing(unsigned int idx1, unsigned int idx2) const
Definition RingInfo.h:140
boost::shared_ptr< RDL_data > dp_urfData
Definition RingInfo.h:336
bool isRingFused(unsigned int ringIdx)
returns whether ring with index ringIdx is fused with other rings.
const VECT_INT_VECT & bondRingFamilies() const
returns our bond ring family vectors
Definition RingInfo.h:312
unsigned int numRings() const
returns the total number of rings
RingInfo & operator=(const RingInfo &other)=default
std::vector< MemberType > DataType
Definition RingInfo.h:39
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
VECT_INT_VECT atomRelevantCycles() const
bool areAtomsInSameRingOfSize(unsigned int idx1, unsigned int idx2, unsigned int size) const
friend class MolPickler
Definition RingInfo.h:35
unsigned int minBondRingSize(unsigned int idx) const
returns the size of the smallest ring bond idx is involved in
const VECT_INT_VECT & atomRingFamilies() const
returns our atom ring family vectors
Definition RingInfo.h:304
RingInfo(const RingInfo &other)=default
const INT_VECT & atomMembers(unsigned int idx) const
unsigned int numFusedBonds(unsigned int ringIdx)
INT_VECT atomRingSizes(unsigned int idx) const
const VECT_INT_VECT & bondRings() const
Definition RingInfo.h:199
const INT_VECT & bondMembers(unsigned int idx) const
std::vector< int > INT_VECT
Definition RingInfo.h:40
RDKit::FIND_RING_TYPE getRingType() const
Definition RingInfo.h:53
void initialize(RDKit::FIND_RING_TYPE ringType=FIND_RING_TYPE_OTHER_OR_UNKNOWN)
does initialization
bool isSssrOrBetter() const
Definition RingInfo.h:63
std::vector< unsigned int > fusedRingNeighbors(unsigned int ringIdx)
bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const
returns whether or not the atom with index idx is in a size - ring.
void reset(bool resetRingFamilies=true)
blows out all current data and de-initializes
unsigned int numRelevantCycles() const
returns the total number of relevant cycles
unsigned int numFusedRingNeighbors(unsigned int ringIdx)
void preallocate(unsigned int numAtoms, unsigned int numBonds)
pre-allocates some memory to save time later
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 resetRingFamilies()
reset ring family information
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:49
std::vector< int > MemberType
Definition RingInfo.h:38
bool isFindFastOrBetter() const
Definition RingInfo.h:57
bool areRingFamiliesInitialized() const
check if the ring families have been initialized
Definition RingInfo.h:315
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:41
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:321
Std stuff.
FIND_RING_TYPE
A class to store information about a molecule's rings.
Definition RingInfo.h:27
@ FIND_RING_TYPE_FAST
Definition RingInfo.h:28
@ FIND_RING_TYPE_OTHER_OR_UNKNOWN
Definition RingInfo.h:31
@ FIND_RING_TYPE_SSSR
Definition RingInfo.h:29
@ FIND_RING_TYPE_SYMM_SSSR
Definition RingInfo.h:30