RDKit: RingInfo.h Source File

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