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 new number of atoms
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 new number of atoms
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 
107  */
108  void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel = false);
109  //! returns a pointer to the highest-numbered Atom
111  //! returns a pointer to the "active" Atom
112  /*!
113  If we have an \c activeAtom, it will be returned,
114  otherwise the results of getLastAtom() will be returned.
115  */
116  Atom *getActiveAtom();
117  //! sets our \c activeAtom
118  void setActiveAtom(Atom *atom);
119  //! \overload
120  void setActiveAtom(unsigned int idx);
121  //! removes an Atom from the molecule
122  void removeAtom(unsigned int idx);
123  //! \overload
124  void removeAtom(Atom *atom);
125 
126  //@}
127 
128  //! \name Bonds
129  //@{
130 
131  //! adds a Bond between the indicated Atoms
132  /*!
133  \return the number of Bonds
134  */
135  unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx,
137  //! \overload
138  unsigned int addBond(ATOM_SPTR beginAtom, ATOM_SPTR endAtom,
140  //! \overload
141  unsigned int addBond(Atom *beginAtom, Atom *endAtom,
143 
144  //! adds a Bond to our collection
145  /*!
146  \param bond pointer to the Bond to add
147  \param takeOwnership (optional) if this is true, we take ownership of \c
148  bond
149  instead of copying it.
150 
151  \return the new number of bonds
152  */
153  unsigned int addBond(Bond *bond, bool takeOwnership = false) {
154  return ROMol::addBond(bond, takeOwnership);
155  };
156  //! adds a Bond to our collection
157  /*!
158  \param bsp smart pointer to the Bond to add
159 
160  \return the new number of bonds
161 
162  <b>Note:</b> since this is using a smart pointer, we don't need to worry
163  about
164  issues of ownership.
165  */
166  unsigned int addBond(BOND_SPTR bsp) { return ROMol::addBond(bsp); };
167 
168  //! starts a Bond and sets its beginAtomIdx
169  /*!
170  \return a pointer to the new bond
171 
172  The caller should set a bookmark to the returned Bond in order
173  to be able to later complete it:
174 
175  \verbatim
176  Bond *pBond = mol->createPartialBond(1);
177  mol->setBondBookmark(pBond,666);
178  ... do some other stuff ...
179  mol->finishPartialBond(2,666,Bond::SINGLE);
180  mol->clearBondBookmark(666,pBond);
181  \endverbatim
182 
183  or, if we want to set the \c BondType initially:
184  \verbatim
185  Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
186  mol->setBondBookmark(pBond,666);
187  ... do some other stuff ...
188  mol->finishPartialBond(2,666);
189  mol->clearBondBookmark(666,pBond);
190  \endverbatim
191 
192  the call to finishPartialBond() will take priority if you set the
193  \c BondType in both calls.
194 
195  */
196  Bond *createPartialBond(unsigned int beginAtomIdx,
198  //! finishes a partially constructed bond
199  /*!
200  \return the final number of Bonds
201 
202  See the documentation for createPartialBond() for more details
203  */
204  unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark,
206 
207  //! removes a bond from the molecule
208  void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
209 
210  //! replaces a particular Bond
211  /*!
212  \param idx the index of the Bond to replace
213  \param bond the new bond, which will be copied.
214 
215  */
216  void replaceBond(unsigned int idx, Bond *bond);
217 
218  //@}
219 
220  //! removes all atoms, bonds, properties, bookmarks, etc.
221  void clear() {
222  d_atomBookmarks.clear();
223  d_bondBookmarks.clear();
224  d_graph.clear();
225  d_confs.clear();
226  dp_props.reset();
227  STR_VECT computed;
229 
230  if (dp_ringInfo) dp_ringInfo->reset();
231  };
232 
233  private:
234  std::vector<BOND_SPTR> d_partialBonds;
235  void destroy();
236 };
237 
238 typedef boost::shared_ptr<RWMol> RWMOL_SPTR;
239 typedef std::vector<RWMOL_SPTR> RWMOL_SPTR_VECT;
240 
241 }; // end of RDKit namespace
242 
243 #endif
boost::shared_ptr< Bond > BOND_SPTR
Definition: ROMol.h:42
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:221
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:177
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 addBond(BOND_SPTR bsp)
adds a Bond to our collection
Definition: RWMol.h:166
Defines the primary molecule class ROMol as well as associated typedefs.
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Bond.h:27
void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel=false)
replaces a particular Atom
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
BondType
the type of Bond
Definition: Bond.h:57
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
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
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:238
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:153
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:255
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:110
std::vector< std::string > STR_VECT
Definition: Dict.h:26
void replaceBond(unsigned int idx, Bond *bond)
replaces a particular Bond
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms