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 #include <RDGeneral/export.h>
17 #ifndef __RD_RWMOL_H__
18 #define __RD_RWMOL_H__
19 
20 // our stuff
21 #include "ROMol.h"
22 #include "RingInfo.h"
23 
24 namespace RDKit {
25 
26 //! RWMol is a molecule class that is intended to be edited
27 /*!
28  See documentation for ROMol for general remarks
29 
30  */
32  public:
33  RWMol() : ROMol() { d_partialBonds.clear(); }
34 
35  //! copy constructor with a twist
36  /*!
37  \param other the molecule to be copied
38  \param quickCopy (optional) if this is true, the resulting ROMol will not
39  copy any of the properties or bookmarks and conformers from \c other.
40  This can
41  make the copy substantially faster (thus the name).
42  \param confId if this is >=0, the resulting ROMol will contain only
43  the specified conformer from \c other.
44  */
45  RWMol(const ROMol &other, bool quickCopy = false, int confId = -1)
46  : ROMol(other, quickCopy, confId) {
47  d_partialBonds.clear();
48  };
49  RWMol &operator=(const RWMol &);
50 
51  //! insert the atoms and bonds from \c other into this molecule
52  void insertMol(const ROMol &other);
53 
54  //! \name Atoms
55  //@{
56 
57  //! adds an empty Atom to our collection
58  /*!
59  \param updateLabel (optional) if this is true, the new Atom will be
60  our \c activeAtom
61 
62  \return the index of the added atom
63 
64  */
65  unsigned int addAtom(bool updateLabel = true);
66 
67  //! adds an Atom to our collection
68  /*!
69  \param atom pointer to the Atom to add
70  \param updateLabel (optional) if this is true, the new Atom will be
71  our \c activeAtom
72  \param takeOwnership (optional) if this is true, we take ownership of \c
73  atom
74  instead of copying it.
75 
76  \return the index of the added atom
77  */
78  unsigned int addAtom(Atom *atom, bool updateLabel = true,
79  bool takeOwnership = false) {
80  return ROMol::addAtom(atom, updateLabel, takeOwnership);
81  };
82 
83  //! adds an Atom to our collection
84 
85  //! replaces a particular Atom
86  /*!
87  \param idx the index of the Atom to replace
88  \param atom the new atom, which will be copied.
89  \param updateLabel (optional) if this is true, the new Atom will be
90  our \c activeAtom
91  \param preserveProps if true preserve the original atom property data
92 
93  */
94  void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel = false,
95  bool preserveProps = false);
96  //! returns a pointer to the highest-numbered Atom
97  Atom *getLastAtom() { return getAtomWithIdx(getNumAtoms() - 1); };
98  //! returns a pointer to the "active" Atom
99  /*!
100  If we have an \c activeAtom, it will be returned,
101  otherwise the results of getLastAtom() will be returned.
102  */
103  Atom *getActiveAtom();
104  //! sets our \c activeAtom
105  void setActiveAtom(Atom *atom);
106  //! \overload
107  void setActiveAtom(unsigned int idx);
108  //! removes an Atom from the molecule
109  void removeAtom(unsigned int idx);
110  //! \overload
111  void removeAtom(Atom *atom);
112 
113  //@}
114 
115  //! \name Bonds
116  //@{
117 
118  //! adds a Bond between the indicated Atoms
119  /*!
120  \return the number of Bonds
121  */
122  unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx,
124  //! \overload
125  unsigned int addBond(Atom *beginAtom, Atom *endAtom,
127 
128  //! adds a Bond to our collection
129  /*!
130  \param bond pointer to the Bond to add
131  \param takeOwnership (optional) if this is true, we take ownership of \c
132  bond
133  instead of copying it.
134 
135  \return the new number of bonds
136  */
137  unsigned int addBond(Bond *bond, bool takeOwnership = false) {
138  return ROMol::addBond(bond, takeOwnership);
139  };
140 
141  //! starts a Bond and sets its beginAtomIdx
142  /*!
143  \return a pointer to the new bond
144 
145  The caller should set a bookmark to the returned Bond in order
146  to be able to later complete it:
147 
148  \verbatim
149  Bond *pBond = mol->createPartialBond(1);
150  mol->setBondBookmark(pBond,666);
151  ... do some other stuff ...
152  mol->finishPartialBond(2,666,Bond::SINGLE);
153  mol->clearBondBookmark(666,pBond);
154  \endverbatim
155 
156  or, if we want to set the \c BondType initially:
157  \verbatim
158  Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE);
159  mol->setBondBookmark(pBond,666);
160  ... do some other stuff ...
161  mol->finishPartialBond(2,666);
162  mol->clearBondBookmark(666,pBond);
163  \endverbatim
164 
165  the call to finishPartialBond() will take priority if you set the
166  \c BondType in both calls.
167 
168  */
169  Bond *createPartialBond(unsigned int beginAtomIdx,
171  //! finishes a partially constructed bond
172  /*!
173  \return the final number of Bonds
174 
175  See the documentation for createPartialBond() for more details
176  */
177  unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark,
179 
180  //! removes a bond from the molecule
181  void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx);
182 
183  //! replaces a particular Bond
184  /*!
185  \param idx the index of the Bond to replace
186  \param bond the new bond, which will be copied.
187  \param preserveProps if true preserve the original bond property data
188 
189  */
190  void replaceBond(unsigned int idx, Bond *bond, bool preserveProps = false);
191 
192  //@}
193 
194  //! Sets groups of atoms with relative stereochemistry
195  /*!
196  \param stereo_groups the new set of stereo groups. All will be replaced.
197 
198  Stereo groups are also called enhanced stereochemistry in the SDF/Mol3000
199  file format. stereo_groups should be std::move()ed into this function.
200  */
201  void setStereoGroups(std::vector<StereoGroup> &&stereo_groups) {
202  return ROMol::setStereoGroups(std::move(stereo_groups));
203  };
204 
205  //! removes all atoms, bonds, properties, bookmarks, etc.
206  void clear() {
207  destroy();
208  d_confs.clear();
209  ROMol::initMol(); // make sure we have a "fresh" ready to go copy
210  numBonds = 0;
211  };
212 
213  private:
214  std::vector<Bond *> d_partialBonds;
215  void destroy();
216 };
217 
218 typedef boost::shared_ptr<RWMol> RWMOL_SPTR;
219 typedef std::vector<RWMOL_SPTR> RWMOL_SPTR_VECT;
220 
221 }; // namespace RDKit
222 
223 #endif
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:206
std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT
Definition: FileParsers.h:31
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
Defines the primary molecule class ROMol as well as associated typedefs.
BondType
the type of Bond
Definition: Bond.h:56
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:294
RWMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: RWMol.h:45
Std stuff.
Definition: Atom.h:30
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:218
void setStereoGroups(std::vector< StereoGroup > &&stereo_groups)
Sets groups of atoms with relative stereochemistry.
Definition: RWMol.h:201
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:137
void clear()
Definition: RDProps.h:24
unsigned int addAtom(Atom *atom, bool updateLabel=true, bool takeOwnership=false)
adds an Atom to our collection
Definition: RWMol.h:78
The class for representing atoms.
Definition: Atom.h:69
Atom * getLastAtom()
returns a pointer to the highest-numbered Atom
Definition: RWMol.h:97