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