00001 // 00002 // Copyright (C) 2003-2009 Greg Landrum and Rational Discovery LLC 00003 // 00004 // @@ All Rights Reserved @@ 00005 // This file is part of the RDKit. 00006 // The contents are covered by the terms of the BSD license 00007 // which is included in the file license.txt, found at the root 00008 // of the RDKit source tree. 00009 // 00010 /*! \file RWMol.h 00011 00012 \brief Defines the editable molecule class \c RWMol 00013 00014 */ 00015 00016 #ifndef __RD_RWMOL_H__ 00017 #define __RD_RWMOL_H__ 00018 00019 // our stuff 00020 #include "ROMol.h" 00021 00022 namespace RDKit{ 00023 00024 //! RWMol is a molecule class that is intended to be edited 00025 /*! 00026 See documentation for ROMol for general remarks 00027 00028 */ 00029 class RWMol : public ROMol { 00030 public: 00031 00032 RWMol() { d_partialBonds.clear(); } 00033 00034 //! copy constructor with a twist 00035 /*! 00036 \param other the molecule to be copied 00037 \param quickCopy (optional) if this is true, the resulting ROMol will not 00038 copy any of the properties or bookmarks and conformers from \c other. This can 00039 make the copy substantially faster (thus the name). 00040 */ 00041 RWMol(const ROMol &other,bool quickCopy=false) {d_partialBonds.clear(); initFromOther(other,quickCopy);}; 00042 00043 00044 //! insert the atoms and bonds from \c other into this molecule 00045 void insertMol( const ROMol &other); 00046 00047 00048 //! \name Atoms 00049 //@{ 00050 00051 //! adds an empty Atom to our collection 00052 /*! 00053 \param updateLabel (optional) if this is true, the new Atom will be 00054 our \c activeAtom 00055 00056 \return the new number of atoms 00057 00058 */ 00059 unsigned int addAtom(bool updateLabel=true); 00060 00061 //! adds an Atom to our collection 00062 /*! 00063 \param atom pointer to the Atom to add 00064 \param updateLabel (optional) if this is true, the new Atom will be 00065 our \c activeAtom 00066 \param takeOwnership (optional) if this is true, we take ownership of \c atom 00067 instead of copying it. 00068 00069 \return the new number of atoms 00070 */ 00071 unsigned int addAtom(Atom *atom,bool updateLabel=true,bool takeOwnership=false){ 00072 return ROMol::addAtom(atom,updateLabel,takeOwnership); 00073 }; 00074 00075 //! adds an Atom to our collection 00076 /*! 00077 \param atom pointer to the Atom to add 00078 \param updateLabel (optional) if this is true, the new Atom will be 00079 our \c activeAtom 00080 00081 00082 \return the new number of atoms 00083 00084 <b>Note:</b> since this is using a smart pointer, we don't need to worry about 00085 issues of ownership. 00086 00087 */ 00088 unsigned int addAtom(ATOM_SPTR atom,bool updateLabel=true){ 00089 return ROMol::addAtom(atom,updateLabel); 00090 }; 00091 00092 //! replaces a particular Atom 00093 /*! 00094 \param idx the index of the Atom to replace 00095 \param atom the new atom, which will be copied. 00096 \param updateLabel (optional) if this is true, the new Atom will be 00097 our \c activeAtom 00098 00099 */ 00100 void replaceAtom(unsigned int idx,Atom *atom,bool updateLabel=false); 00101 //! returns a pointer to the highest-numbered Atom 00102 Atom *getLastAtom() { return getAtomWithIdx(getNumAtoms()-1); }; 00103 //! returns a pointer to the "active" Atom 00104 /*! 00105 If we have an \c activeAtom, it will be returned, 00106 otherwise the results of getLastAtom() will be returned. 00107 */ 00108 Atom *getActiveAtom(); 00109 //! sets our \c activeAtom 00110 void setActiveAtom(Atom *atom); 00111 //! \overload 00112 void setActiveAtom(unsigned int idx); 00113 //! removes an Atom from the molecule 00114 void removeAtom(unsigned int idx); 00115 //! \overload 00116 void removeAtom(Atom *atom); 00117 00118 //@} 00119 00120 00121 //! \name Bonds 00122 //@{ 00123 00124 //! adds a Bond between the indicated Atoms 00125 /*! 00126 \return the number of Bonds 00127 */ 00128 unsigned int addBond(unsigned int beginAtomIdx,unsigned int endAtomIdx, 00129 Bond::BondType order=Bond::UNSPECIFIED); 00130 //! \overload 00131 unsigned int addBond(ATOM_SPTR beginAtom,ATOM_SPTR endAtom, 00132 Bond::BondType order=Bond::UNSPECIFIED); 00133 //! \overload 00134 unsigned int addBond(Atom *beginAtom, Atom *endAtom, 00135 Bond::BondType order=Bond::UNSPECIFIED); 00136 00137 00138 //! adds a Bond to our collection 00139 /*! 00140 \param bond pointer to the Bond to add 00141 \param takeOwnership (optional) if this is true, we take ownership of \c bond 00142 instead of copying it. 00143 00144 \return the new number of bonds 00145 */ 00146 unsigned int addBond(Bond *bond,bool takeOwnership=false){ 00147 return ROMol::addBond(bond,takeOwnership); 00148 }; 00149 //! adds a Bond to our collection 00150 /*! 00151 \param bsp smart pointer to the Bond to add 00152 00153 \return the new number of bonds 00154 00155 <b>Note:</b> since this is using a smart pointer, we don't need to worry about 00156 issues of ownership. 00157 */ 00158 unsigned int addBond(BOND_SPTR bsp){ 00159 return ROMol::addBond(bsp); 00160 }; 00161 00162 00163 //! starts a Bond and sets its beginAtomIdx 00164 /*! 00165 \return a pointer to the new bond 00166 00167 The caller should set a bookmark to the returned Bond in order 00168 to be able to later complete it: 00169 00170 \verbatim 00171 Bond *pBond = mol->createPartialBond(1); 00172 mol->setBondBookmark(pBond,666); 00173 ... do some other stuff ... 00174 mol->finishPartialBond(2,666,Bond::SINGLE); 00175 mol->clearBondBookmark(666,pBond); 00176 \endverbatim 00177 00178 or, if we want to set the \c BondType initially: 00179 \verbatim 00180 Bond *pBond = mol->createPartialBond(1,Bond::DOUBLE); 00181 mol->setBondBookmark(pBond,666); 00182 ... do some other stuff ... 00183 mol->finishPartialBond(2,666); 00184 mol->clearBondBookmark(666,pBond); 00185 \endverbatim 00186 00187 the call to finishPartialBond() will take priority if you set the 00188 \c BondType in both calls. 00189 00190 */ 00191 Bond *createPartialBond(unsigned int beginAtomIdx, 00192 Bond::BondType order=Bond::UNSPECIFIED); 00193 //! finishes a partially constructed bond 00194 /*! 00195 \return the final number of Bonds 00196 00197 See the documentation for createPartialBond() for more details 00198 */ 00199 unsigned int finishPartialBond(unsigned int endAtomIdx,int bondBookmark, 00200 Bond::BondType order=Bond::UNSPECIFIED); 00201 00202 //! removes a bond from the molecule 00203 void removeBond(unsigned int beginAtomIdx, unsigned int endAtomIdx); 00204 //@} 00205 00206 private: 00207 std::vector<BOND_SPTR> d_partialBonds; 00208 void destroy(); 00209 ROMol &operator=(const ROMol &); // disable assignment 00210 00211 }; 00212 00213 typedef boost::shared_ptr<RWMol> RWMOL_SPTR; 00214 typedef std::vector< RWMOL_SPTR > RWMOL_SPTR_VECT; 00215 00216 }; // end of RDKit namespace 00217 00218 #endif
1.7.1