RDKit: RWMol.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
112 Atom *getLastAtom() { return getAtomWithIdx(getNumAtoms() - 1); };
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,
138 Bond::BondType order = Bond::UNSPECIFIED);
139 //! \overload
140 unsigned int addBond(ATOM_SPTR beginAtom, ATOM_SPTR endAtom,
141 Bond::BondType order = Bond::UNSPECIFIED);
142 //! \overload
143 unsigned int addBond(Atom *beginAtom, Atom *endAtom,
144 Bond::BondType order = Bond::UNSPECIFIED);
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,
199 Bond::BondType order = Bond::UNSPECIFIED);
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,
207 Bond::BondType order = Bond::UNSPECIFIED);
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;
231 dp_props.setVal(RDKit::detail::computedPropName, 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
RDKit::BOND_SPTR
boost::shared_ptr< Bond > BOND_SPTR
Definition: ROMol.h:42
RDKit::RWMol::clear
void clear()
removes all atoms, bonds, properties, bookmarks, etc.
Definition: RWMol.h:224
RDKit::RWMOL_SPTR_VECT
std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT
Definition: FileParsers.h:30
RDKit::RDProps::dp_props
Dict dp_props
Definition: RDProps.h:11
RDKit::Dict::setVal
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
Definition: Dict.h:212
RDKit::RWMol::insertMol
void insertMol(const ROMol &other)
insert the atoms and bonds from other into this molecule
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:30
RDKit::RWMol::addAtom
unsigned int addAtom(bool updateLabel=true)
adds an empty Atom to our collection
RDKit::RWMol::addBond
unsigned int addBond(BOND_SPTR bsp)
adds a Bond to our collection
Definition: RWMol.h:168
ROMol.h
Defines the primary molecule class ROMol as well as associated typedefs.
RDKit::ATOM_SPTR
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Bond.h:27
RDKit::ROMol::getNumAtoms
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
RDKit::RWMol::replaceBond
void replaceBond(unsigned int idx, Bond *bond, bool preserveProps=false)
replaces a particular Bond
RDKit::Bond::BondType
BondType
the type of Bond
Definition: Bond.h:57
RDKit::RWMol::replaceAtom
void replaceAtom(unsigned int idx, Atom *atom, bool updateLabel=false, bool preserveProps=false)
replaces a particular Atom
RDKit::ROMol
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
RingInfo.h
RDKit::ROMol::numBonds
unsigned int numBonds
Definition: ROMol.h:598
RDKit::RWMol::RWMol
RWMol(const ROMol &other, bool quickCopy=false, int confId=-1)
copy constructor with a twist
Definition: RWMol.h:44
RDKit::RWMol::finishPartialBond
unsigned int finishPartialBond(unsigned int endAtomIdx, int bondBookmark, Bond::BondType order=Bond::UNSPECIFIED)
finishes a partially constructed bond
RDKit::RWMol::createPartialBond
Bond * createPartialBond(unsigned int beginAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
starts a Bond and sets its beginAtomIdx
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::RWMOL_SPTR
boost::shared_ptr< RWMol > RWMOL_SPTR
Definition: RWMol.h:241
RDKit::RWMol::addAtom
unsigned int addAtom(ATOM_SPTR atom, bool updateLabel=true)
adds an Atom to our collection
Definition: RWMol.h:96
RDKit::RWMol::removeBond
void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx)
removes a bond from the molecule
RDKit::Bond
class for representing a bond
Definition: Bond.h:47
RDKit::RWMol::addBond
unsigned int addBond(Bond *bond, bool takeOwnership=false)
adds a Bond to our collection
Definition: RWMol.h:155
RDKit::RWMol::removeAtom
void removeAtom(unsigned int idx)
removes an Atom from the molecule
RDKit::RWMol::setActiveAtom
void setActiveAtom(Atom *atom)
sets our activeAtom
RDKit::Bond::UNSPECIFIED
Definition: Bond.h:58
RDKit::RWMol::RWMol
RWMol()
Definition: RWMol.h:32
RDKit::RWMol::operator=
RWMol & operator=(const RWMol &)
RDKit::ROMol::getAtomWithIdx
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
RDKit::RWMol::getActiveAtom
Atom * getActiveAtom()
returns a pointer to the "active" Atom
RDKit::Dict::reset
void reset()
Clears all keys (and values) from the dictionary.
Definition: Dict.h:282
RDKit::detail::computedPropName
const std::string computedPropName
RDKit::RWMol::addAtom
unsigned int addAtom(Atom *atom, bool updateLabel=true, bool takeOwnership=false)
adds an Atom to our collection
Definition: RWMol.h:77
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:68
RDKit::RWMol::getLastAtom
Atom * getLastAtom()
returns a pointer to the highest-numbered Atom
Definition: RWMol.h:112
RDKit::STR_VECT
std::vector< std::string > STR_VECT
Definition: Dict.h:28
RDKit::RWMol::addBond
unsigned int addBond(unsigned int beginAtomIdx, unsigned int endAtomIdx, Bond::BondType order=Bond::UNSPECIFIED)
adds a Bond between the indicated Atoms