Loading...
Searching...
No Matches
RingInfo.h
Go to the documentation of this file.
//
// 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>
#include <RDGeneral/BoostStartInclude.h>
#include <boost/dynamic_bitset.hpp>
#ifdef RDK_USE_URF
#include <boost/shared_ptr.hpp>
#endif
#include <RDGeneral/BoostEndInclude.h>
#ifdef RDK_USE_URF
#include <RingDecomposerLib.h>
#endif
namespace RDKit {
//! A class to store information about a molecule's rings
/*!
*/
typedef enum {
FIND_RING_TYPE_FAST,
FIND_RING_TYPE_SSSR,
FIND_RING_TYPE_SYMM_SSSR,
FIND_RING_TYPE_OTHER_OR_UNKNOWN
} FIND_RING_TYPE;
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(
RDKit::FIND_RING_TYPE ringType = FIND_RING_TYPE_OTHER_OR_UNKNOWN);
RDKit::FIND_RING_TYPE getRingType() const { return df_find_type_type; };
//! blows out all current data and de-initializes
void reset();
bool isFindFastOrBetter() const {
return df_init && (df_find_type_type == FIND_RING_TYPE_FAST ||
df_find_type_type == FIND_RING_TYPE_SSSR ||
df_find_type_type == FIND_RING_TYPE_SYMM_SSSR);
}
bool isSssrOrBetter() const {
return df_init && (df_find_type_type == FIND_RING_TYPE_SSSR ||
df_find_type_type == FIND_RING_TYPE_SYMM_SSSR);
}
bool isSymmSssr() const {
return df_init && df_find_type_type == FIND_RING_TYPE_SYMM_SSSR;
}
//! 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
*/
const 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
*/
const 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;
//! returns whether ring with index \c ringIdx is fused with other rings.
/*!
<b>Notes:</b>
- the object must be initialized before calling this
*/
bool isRingFused(unsigned int ringIdx);
//! returns whether rings with indices \c ring1Idx and \c ring2Idx have
//! at least one bond in common.
/*!
<b>Notes:</b>
- the object must be initialized before calling this
*/
bool areRingsFused(unsigned int ring1Idx, unsigned int ring2Idx);
//! returns the number of bonds shared with other rings in ring with index
//! \c ringIdx.
/*!
<b>Notes:</b>
- the object must be initialized before calling this
*/
unsigned int numFusedBonds(unsigned int ringIdx);
//! returns the number of rings which have at least one bond
//! in common with ring with index \c ringIdx.
/*!
<b>Notes:</b>
- the object must be initialized before calling this
*/
unsigned int numFusedRingNeighbors(unsigned int ringIdx);
//! returns the indices of rings which have at least one bond
//! in common with ring with index \c ringIdx.
/*!
<b>Notes:</b>
- the object must be initialized before calling this
*/
std::vector<unsigned int> fusedRingNeighbors(unsigned int ringIdx);
#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);
void initFusedRings();
bool df_init{false};
FIND_RING_TYPE df_find_type_type{FIND_RING_TYPE_OTHER_OR_UNKNOWN};
DataType d_atomMembers, d_bondMembers;
VECT_INT_VECT d_atomRings, d_bondRings;
VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
std::vector<boost::dynamic_bitset<>> d_fusedRings;
std::vector<unsigned int> d_numFusedBonds;
#ifdef RDK_USE_URF
public:
boost::shared_ptr<RDL_data> dp_urfData;
#endif
};
} // namespace RDKit
#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:257
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::VECT_INT_VECT
std::vector< INT_VECT > VECT_INT_VECT
Definition types.h:240
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