RDKit
Open-source cheminformatics and machine learning.
RingInfo.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2019 Greg Landrum and Rational Discovery LLC
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/shared_ptr.hpp>
19 #ifdef RDK_USE_URF
20 #include <RingDecomposerLib.h>
21 #endif
22 
23 namespace RDKit {
24 //! A class to store information about a molecule's rings
25 /*!
26 
27  */
29  friend class MolPickler;
30 
31  public:
32  typedef std::vector<int> MemberType;
33  typedef std::vector<MemberType> DataType;
34  typedef std::vector<int> INT_VECT;
35  typedef std::vector<INT_VECT> VECT_INT_VECT;
36 
37  RingInfo() : df_init(false){};
38  RingInfo(const RingInfo &other)
39  : df_init(other.df_init),
40  d_atomMembers(other.d_atomMembers),
41  d_bondMembers(other.d_bondMembers),
42  d_atomRings(other.d_atomRings),
43  d_bondRings(other.d_bondRings),
44  d_atomRingFamilies(other.d_atomRingFamilies),
45  d_bondRingFamilies(other.d_bondRingFamilies)
46 #ifdef RDK_USE_URF
47  ,dp_urfData(other.dp_urfData)
48 #endif
49  {};
50 
51  //! checks to see if we've been properly initialized
52  bool isInitialized() const { return df_init; };
53  //! does initialization
54  void initialize();
55 
56  //! blows out all current data and de-initializes
57  void reset();
58 
59  //! adds a ring to our data
60  /*!
61  \param atomIndices the integer indices of the atoms involved in the ring
62  \param bondIndices the integer indices of the bonds involved in the ring,
63  this must be the same size as \c atomIndices.
64 
65  \return the number of rings
66 
67  <b>Notes:</b>
68  - the object must be initialized before calling this
69 
70  */
71  unsigned int addRing(const INT_VECT &atomIndices,
72  const INT_VECT &bondIndices);
73 
74  //! \name Atom information
75  //@{
76 
77  //! returns whether or not the atom with index \c idx is in a \c size - ring.
78  /*!
79  <b>Notes:</b>
80  - the object must be initialized before calling this
81  */
82  bool isAtomInRingOfSize(unsigned int idx, unsigned int size) const;
83  //! returns the number of rings atom \c idx is involved in
84  /*!
85  <b>Notes:</b>
86  - the object must be initialized before calling this
87  */
88  unsigned int numAtomRings(unsigned int idx) const;
89  //! returns the size of the smallest ring atom \c idx is involved in
90  /*!
91  <b>Notes:</b>
92  - the object must be initialized before calling this
93  */
94  unsigned int minAtomRingSize(unsigned int idx) const;
95 
96  //! returns our \c atom-rings vectors
97  /*!
98  <b>Notes:</b>
99  - the object must be initialized before calling this
100  */
101  const VECT_INT_VECT &atomRings() const { return d_atomRings; };
102 
103  //@}
104 
105  //! \name Bond information
106  //@{
107 
108  //! returns whether or not the bond with index \c idx is in a \c size - ring.
109  /*!
110  <b>Notes:</b>
111  - the object must be initialized before calling this
112  */
113  bool isBondInRingOfSize(unsigned int idx, unsigned int size) const;
114  //! returns the number of rings bond \c idx is involved in
115  /*!
116  <b>Notes:</b>
117  - the object must be initialized before calling this
118  */
119  unsigned int numBondRings(unsigned int idx) const;
120  //! returns the size of the smallest ring bond \c idx is involved in
121  /*!
122  <b>Notes:</b>
123  - the object must be initialized before calling this
124  */
125  unsigned int minBondRingSize(unsigned int idx) const;
126 
127  //! returns the total number of rings
128  /*!
129  <b>Notes:</b>
130  - the object must be initialized before calling this
131  - if the RDKit has been built with URF support, this returns the number
132  of ring families.
133  */
134  unsigned int numRings() const;
135 
136  //! returns our \c bond-rings vectors
137  /*!
138  <b>Notes:</b>
139  - the object must be initialized before calling this
140  */
141  const VECT_INT_VECT &bondRings() const { return d_bondRings; };
142 
143 #ifdef RDK_USE_URF
144  //! adds a ring family to our data
145  /*!
146  \param atomIndices the integer indices of the atoms involved in the
147  ring family
148  \param bondIndices the integer indices of the bonds involved in the
149  ring family,
150  this must be the same size as \c atomIndices.
151 
152  \return the number of ring families
153 
154  <b>Notes:</b>
155  - the object must be initialized before calling this
156 
157  */
158  unsigned int addRingFamily(const INT_VECT &atomIndices,
159  const INT_VECT &bondIndices);
160  //! returns the total number of ring families
161  /*!
162  <b>Notes:</b>
163  - the object must be initialized before calling this
164  */
165  unsigned int numRingFamilies() const;
166 
167  //! returns the total number of relevant cycles
168  /*!
169  <b>Notes:</b>
170  - the object must be initialized before calling this
171  */
172  unsigned int numRelevantCycles() const;
173 
174  //! returns our atom ring family vectors
175  /*!
176  <b>Notes:</b>
177  - the object must be initialized before calling this
178  */
179  const VECT_INT_VECT &atomRingFamilies() const { return d_atomRingFamilies; };
180 
181  //! returns our bond ring family vectors
182  /*!
183  <b>Notes:</b>
184  - the object must be initialized before calling this
185  */
186  const VECT_INT_VECT &bondRingFamilies() const { return d_bondRingFamilies; };
187 
188  //! check if the ring families have been initialized
189  bool areRingFamiliesInitialized() const { return dp_urfData != NULL; }
190 #endif
191 
192  //@}
193 
194  private:
195  //! pre-allocates some memory to save time later
196  void preallocate(unsigned int numAtoms, unsigned int numBonds);
197 
198  bool df_init;
199  DataType d_atomMembers, d_bondMembers;
200  VECT_INT_VECT d_atomRings, d_bondRings;
201  VECT_INT_VECT d_atomRingFamilies, d_bondRingFamilies;
202 
203 #ifdef RDK_USE_URF
204  public:
205  boost::shared_ptr<RDL_data> dp_urfData;
206 #endif
207 };
208 } // namespace RDKit
209 
210 #endif
RDKit::VECT_INT_VECT
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:268
RDKit::INT_VECT
std::vector< int > INT_VECT
Definition: types.h:254
BoostStartInclude.h
RDKit::RingInfo::DataType
std::vector< MemberType > DataType
Definition: RingInfo.h:33
BoostEndInclude.h
RDKit::RingInfo::bondRings
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
Definition: RingInfo.h:141
RDKit::RingInfo
A class to store information about a molecule's rings.
Definition: RingInfo.h:28
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::RingInfo::MemberType
std::vector< int > MemberType
Definition: RingInfo.h:32
RDKit::RingInfo::atomRings
const VECT_INT_VECT & atomRings() const
returns our atom-rings vectors
Definition: RingInfo.h:101
RDKit::RingInfo::RingInfo
RingInfo(const RingInfo &other)
Definition: RingInfo.h:38
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::MolPickler
handles pickling (serializing) molecules
Definition: MolPickler.h:63
RDKit::RingInfo::isInitialized
bool isInitialized() const
checks to see if we've been properly initialized
Definition: RingInfo.h:52
RDKit::RingInfo::VECT_INT_VECT
std::vector< INT_VECT > VECT_INT_VECT
Definition: RingInfo.h:35
RDKit::RingInfo::RingInfo
RingInfo()
Definition: RingInfo.h:37
RDKit::RingInfo::INT_VECT
std::vector< int > INT_VECT
Definition: RingInfo.h:34
export.h