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