RDKit
Open-source cheminformatics and machine learning.
RWMol.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2009 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 /*! \file RWMol.h
11 
12  \brief Defines the editable molecule class \c RWMol
13 
14 */
15 
16 #ifndef __RD_RWMOL_H__
17 #define __RD_RWMOL_H__
18 
19 // our stuff
20 #include "ROMol.h"
21 #include "RingInfo.h"
22 
23 namespace RDKit {
24 
25 //! RWMol is a molecule class that is intended to be edited
26 /*!
27  See documentation for ROMol for general remarks
28 
29  */
30 class RWMol : public ROMol {
31  public:
32  RWMol() : ROMol() { d_partialBonds.clear(); }
33 
34  //! copy constructor with a twist
35  /*!
36  \param other the molecule to be copied
37  \param quickCopy (optional) if this is true, the resulting ROMol will not
38  copy any of the properties or bookmarks and conformers from \c other.
39  This can
40  make the copy substantially faster (thus the name).
41  \param confId if this is >=0, the resulting ROMol will contain only
42  the specified conformer from \c other.
43  */
44  RWMol(const ROMol &other, bool quickCopy = false, int confId = -1)
45  : ROMol(other, quickCopy, confId) {
46  d_partialBonds.clear();
47  };
48  RWMol &operator=(const RWMol &);
49 
50  //! insert the atoms and bonds from \c other into this molecule
51  void insertMol(const ROMol &other);
52 
53  //! \name Atoms
54  //@{
55 
56  //! adds an empty Atom to our collection
57  /*!
58  \param updateLabel (optional) if this is true, the new Atom will be
59  our \c activeAtom
60 
61  \return the index of the added atom
62 
63  */
64  unsigned int addAtom(bool updateLabel = true);
65 
66  //! adds an Atom to our collection
67  /*!
68  \param atom pointer to the Atom to add
69  \param updateLabel (optional) if this is true, the new Atom will be
70  our \c activeAtom
71  \param takeOwnership (optional) if this is true, we take ownership of \c
72  atom
73  instead of copying it.
74 
75  \return the index of the added atom
76  */
77  unsigned int addAtom(Atom *atom, bool updateLabel = true,
78  bool takeOwnership = false) {
79  return ROMol::addAtom(atom, updateLabel, takeOwnership);
80  };
81 
82  //! adds an Atom to our collection
83  /*!
84  \param atom pointer to the Atom to add
85  \param updateLabel (optional) if this is true, the new Atom will be
86  our \c activeAtom
87 
88 
89  \return the new number of atoms
90 
91  <b>Note:</b> since this is using a smart pointer, we don't need to worry
92  about
93  issues of ownership.
94 
95  */
96  unsigned int addAtom(ATOM_SPTR atom, bool updateLabel = true) {
97  return ROMol::addAtom(atom, updateLabel);
98  };
99 
100  //! replaces a particular Atom
101  /*!
102  \param idx the index of the Atom to replace
103  \param atom the new atom, which will be copied.
104  \param updateLabel (optional) if this is true, the new Atom will be
105  our \c activeAtom
106  \param preserveProps if true preserve the original atom property data
107 
108  */
109  void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel = false,
110  bool preserveProps = false);
111  //! returns a pointer to the highest-numbered Atom
113  //! returns a pointer to the "active" Atom
114  /*!
115  If we have an \c activeAtom, it will be returned,
116  otherwise the results of getLastAtom() will be returned.
117  */
118  Atom *getActiveAtom();
119  //! sets our \c activeAtom
120  void setActiveAtom(Atom *atom);
121  //! \overload
122  void setActiveAtom(unsigned int idx);
123  //! removes an Atom from the molecule
124  void removeAtom(unsigned int idx);
125  //! \overload
126  void removeAtom(Atom *atom);
127 
128  //@}
129 
130  //! \name Bonds
131  //@{
132 
133  //! adds a Bond between the indicated Atoms
134  /*!
135  \return the number of Bonds
136  */
137  unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx,
139  //! \overload
140  unsigned int addBond(ATOM_SPTR beginAtom, ATOM_SPTR endAtom,
142  //! \overload
143  unsigned int addBond(Atom *beginAtom, Atom *endAtom,
145 
146  //! adds a Bond to our collection
147  /*!
148  \param bond pointer to the Bond to add
149  \param takeOwnership (optional) if this is true, we take ownership of \c
150  bond
151  instead of copying it.
152 
153  \return the new number of bonds
154  */
155  unsigned int addBond(Bond *bond, bool takeOwnership = false) {
156  return ROMol::addBond(bond, takeOwnership);
157  };
158  //! adds a Bond to our collection
159  /*!
160  \param bsp smart pointer to the Bond to add
161 
162  \return the new number of bonds
163 
164  <b>Note:</b> since this is using a smart pointer, we don't need to worry
165  about
166  issues of ownership.
167  */
168  unsigned int addBond(BOND_SPTR bsp) { return ROMol::addBond(bsp); };
169 
170  //! starts a Bond and sets its beginAtomIdx
171  /*!
172  \return a pointer to the new bond
173 
174  The caller should set a bookmark to the returned Bond in order
175  to be able to later complete it:
176 
177  \verbatim
178  Bond *pBond = mol->createPartialBond(1);
179  mol->setBondBookmark(pBond,666);
180  ... do some other stuff ...
181  mol->finishPartialBond(2,666,Bond::SINGLE);
182  mol->clearBondBookmark(666,pBond);
183  \endverbatim
184 
185  or, if we want to set the \c BondType initially:
186  \verbatim
187  Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
188  mol->setBondBookmark(pBond,666);
189  ... do some other stuff ...
190  mol->finishPartialBond(2,666);
191  mol->clearBondBookmark(666,pBond);
192  \endverbatim
193 
194  the call to finishPartialBond() will take priority if you set the
195  \c BondType in both calls.
196 
197  */
198  Bond *createPartialBond(unsigned int beginAtomIdx,
200  //! finishes a partially constructed bond
201  /*!
202  \return the final number of Bonds
203 
204  See the documentation for createPartialBond() for more details
205  */
206  unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark,
208 
209  //! removes a bond from the molecule
210  void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
211 
212  //! replaces a particular Bond
213  /*!
214  \param idx the index of the Bond to replace
215  \param bond the new bond, which will be copied.
216  \param preserveProps if true preserve the original bond property data
217 
218  */
219  void replaceBond(unsigned int idx, Bond *bond, bool preserveProps=false);
220 
221  //@}
222 
223  //! removes all atoms, bonds, properties, bookmarks, etc.
224  void clear() {
225  d_atomBookmarks.clear();
226  d_bondBookmarks.clear();
227  d_graph.clear();
228  d_confs.clear();
229  dp_props.reset();
230  STR_VECT computed;
232  numBonds = 0;
233  if (dp_ringInfo) dp_ringInfo->reset();
234  };
235 
236  private:
237  std::vector<BOND_SPTR> d_partialBonds;
238  void destroy();
239 };
240 
241 typedef boost::shared_ptr<RWMol> RWMOL_SPTR;
242 typedef std::vector<RWMOL_SPTR> RWMOL_SPTR_VECT;
243 
244 }; // end of RDKit namespace
245 
246 #endif
boost::shared_ptr< Bond > BOND_SPTR
Definition: ROMol.h:42
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:224
std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT
Definition: FileParsers.h:30
Dict dp_props
Definition: RDProps.h:11
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
Definition: Dict.h:212
void insertMol(const ROMol &other)
insert the atoms and bonds from other into this molecule
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
unsigned int addAtom(bool updateLabel=true)
adds an empty Atom to our collection
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
unsigned int addBond(BOND_SPTR bsp)
adds a Bond to our collection
Definition: RWMol.h:168
Defines the primary molecule class ROMol as well as associated typedefs.
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Bond.h:27
void replaceBond(unsigned int idx, Bond *bond, bool preserveProps=false)
replaces a particular Bond
BondType
the type of Bond
Definition: Bond.h:57
void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel=false, bool preserveProps=false)
replaces a particular Atom
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
unsigned int numBonds
Definition: ROMol.h:598
RWMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: RWMol.h:44
unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark, Bond::BondType order=Bond::UNSPECIFIED)
finishes a partially constructed bond
Bond * createPartialBond(unsigned int beginAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
starts a Bond and sets its beginAtomIdx
Std stuff.
Definition: Atom.h:29
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:241
unsigned int addAtom(ATOM_SPTR atom, bool updateLabel=true)
adds an Atom to our collection
Definition: RWMol.h:96
void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx)
removes a bond from the molecule
class for representing a bond
Definition: Bond.h:47
unsigned int addBond(Bond *bond, bool takeOwnership=false)
adds a Bond to our collection
Definition: RWMol.h:155
void removeAtom(unsigned int idx)
removes an Atom from the molecule
void setActiveAtom(Atom *atom)
sets our activeAtom
RWMol & operator=(const RWMol &)
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
Atom * getActiveAtom()
returns a pointer to the "active" Atom
void reset()
Clears all keys (and values) from the dictionary.
Definition: Dict.h:282
const std::string computedPropName
unsigned int addAtom(Atom *atom, bool updateLabel=true, bool takeOwnership=false)
adds an Atom to our collection
Definition: RWMol.h:77
The class for representing atoms.
Definition: Atom.h:68
Atom * getLastAtom()
returns a pointer to the highest-numbered Atom
Definition: RWMol.h:112
std::vector< std::string > STR_VECT
Definition: Dict.h:28
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms