Conformer.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2001-2008 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 #ifndef _RD_CONFORMER_H
00011 #define _RD_CONFORMER_H
00012 
00013 #include <Geometry/point.h>
00014 #include <RDGeneral/types.h>
00015 #include <boost/smart_ptr.hpp>
00016 
00017 namespace RDKit {
00018   class ROMol;
00019   
00020   //! used to indicate errors from incorrect confomer access
00021   class ConformerException : public std::exception {
00022   public:
00023     //! construct with an error message
00024     ConformerException(const char *msg) : _msg(msg) {};
00025     //! construct with an error message
00026     ConformerException(const std::string msg) : _msg(msg) {};
00027     //! get the error message
00028     const char *message () const { return _msg.c_str(); };
00029     ~ConformerException () throw () {};
00030   private:
00031     std::string _msg;
00032   };
00033 
00034 
00035   //! The class for representing 2D or 3D conformation of a molecule
00036   /*!
00037     This class contains
00038     - a pointer to the owing molecule
00039     - a vector of 3D points (positions of atoms)
00040   */
00041   class Conformer {
00042   public:
00043 
00044     friend class ROMol;
00045 
00046     //! Constructor
00047     Conformer() : df_is3D(true), d_id(0), dp_mol(NULL) {
00048       d_positions.clear();
00049     };
00050 
00051     //! Constructor with number of atoms specified ID specification
00052     Conformer(unsigned int numAtoms) : df_is3D(true), d_id(0), dp_mol(NULL) {
00053       if(numAtoms){
00054         d_positions.resize(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0));
00055       } else {
00056         d_positions.resize(0);
00057         d_positions.clear();
00058       }
00059     };
00060 
00061     //! Copy COnstructor: initialize from a second conformation.
00062     Conformer(const Conformer &other);
00063 
00064     //! Destructor
00065     ~Conformer() {};
00066 
00067     //! Resize the conformer so that more atoms location can be added.
00068     //! Useful, for e.g., when adding hydrogens 
00069     void resize(unsigned int size) {
00070       d_positions.resize(size);
00071     }
00072 
00073     //! Reserve more space for atom position 
00074     void reserve(unsigned int size) {
00075       d_positions.reserve(size);
00076     }
00077 
00078     //! Get the molecule that oqns this conformation
00079     ROMol &getOwningMol() const {return *dp_mol;}
00080 
00081     //! Get a const reference to the vector of atom positions
00082     const RDGeom::POINT3D_VECT &getPositions() const;
00083       
00084     //! Get a reference to the atom positions
00085     RDGeom::POINT3D_VECT &getPositions(); 
00086 
00087     //! Get the position of the specified atom
00088     const RDGeom::Point3D &getAtomPos(unsigned int atomId) const; 
00089 
00090     //! Get the position of the specified atom
00091     RDGeom::Point3D &getAtomPos(unsigned int atomId); 
00092 
00093     //! Set the position of the specified atom
00094     inline void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position) {
00095       //RANGE_CHECK(0,atomId,d_positions.size()-1);
00096       if (atomId >= d_positions.size()) {
00097         d_positions.resize(atomId+1, RDGeom::Point3D(0.0, 0.0, 0.0));
00098       }
00099       d_positions[atomId] = position;
00100     }
00101 
00102     //! get the ID of this conformer
00103     inline unsigned int getId() const {return d_id;}
00104     
00105     //! set the ID of this conformer
00106     inline void setId(unsigned int id) {
00107       d_id = id;
00108     }
00109 
00110     //! Get the number of atoms
00111     inline unsigned int getNumAtoms() const {
00112       return d_positions.size();
00113     }
00114 
00115     inline bool is3D() const {
00116       return df_is3D;
00117     }
00118     inline void set3D(bool v) {
00119       df_is3D=v;
00120     }
00121   protected:
00122     //! Set owning moelcule
00123     void setOwningMol(ROMol *mol);
00124 
00125     //! Set owning moelcule
00126     void setOwningMol(ROMol &mol);
00127 
00128   private:
00129     bool df_is3D; // is this a 3D conformation?
00130     unsigned int d_id; // id is the conformation
00131     ROMol *dp_mol; // owning molecule
00132     RDGeom::POINT3D_VECT d_positions; // positions of the atoms
00133   };
00134 
00135   typedef boost::shared_ptr<Conformer>    CONFORMER_SPTR;
00136 }
00137 
00138 #endif