RDKit
Open-source cheminformatics and machine learning.
Conformer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2008 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 #ifndef _RD_CONFORMER_H
11 #define _RD_CONFORMER_H
12 
13 #include <Geometry/point.h>
14 #include <RDGeneral/types.h>
15 #include <boost/smart_ptr.hpp>
16 
17 namespace RDKit {
18 class ROMol;
19 
20 //! used to indicate errors from incorrect confomer access
21 class ConformerException : public std::exception {
22  public:
23  //! construct with an error message
24  ConformerException(const char *msg) : _msg(msg){};
25  //! construct with an error message
26  ConformerException(const std::string &msg) : _msg(msg){};
27  //! get the error message
28  const char *message() const { return _msg.c_str(); };
29  ~ConformerException() throw(){};
30 
31  private:
32  std::string _msg;
33 };
34 
35 //! The class for representing 2D or 3D conformation of a molecule
36 /*!
37  This class contains
38  - a pointer to the owing molecule
39  - a vector of 3D points (positions of atoms)
40 */
41 class Conformer {
42  public:
43  friend class ROMol;
44 
45  //! Constructor
46  Conformer() : df_is3D(true), d_id(0), dp_mol(NULL) { d_positions.clear(); };
47 
48  //! Constructor with number of atoms specified ID specification
49  Conformer(unsigned int numAtoms) : df_is3D(true), d_id(0), dp_mol(NULL) {
50  if (numAtoms) {
51  d_positions.resize(numAtoms, RDGeom::Point3D(0.0, 0.0, 0.0));
52  } else {
53  d_positions.resize(0);
54  d_positions.clear();
55  }
56  };
57 
58  //! Copy Constructor: initialize from a second conformation.
59  Conformer(const Conformer &other);
60 
61  //! Destructor
63 
64  //! Resize the conformer so that more atoms location can be added.
65  //! Useful, for e.g., when adding hydrogens
66  void resize(unsigned int size) { d_positions.resize(size); }
67 
68  //! Reserve more space for atom position
69  void reserve(unsigned int size) { d_positions.reserve(size); }
70 
71  //! Get the molecule that oqns this conformation
72  ROMol &getOwningMol() const { return *dp_mol; }
73 
74  //! Get a const reference to the vector of atom positions
75  const RDGeom::POINT3D_VECT &getPositions() const;
76 
77  //! Get a reference to the atom positions
78  RDGeom::POINT3D_VECT &getPositions();
79 
80  //! Get the position of the specified atom
81  const RDGeom::Point3D &getAtomPos(unsigned int atomId) const;
82  //! overload
83  template<class U>
84  const RDGeom::Point3D &getAtomPos(U atomId) const {
85  return getAtomPos(rdcast<unsigned int>(atomId));
86  }
87 
88  //! Get the position of the specified atom
89  RDGeom::Point3D &getAtomPos(unsigned int atomId);
90  //! overload
91  template<class U>
93  return getAtomPos(rdcast<unsigned int>(atomId));
94  }
95 
96  //! Set the position of the specified atom
97  inline void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position) {
98  // RANGE_CHECK(0,atomId,d_positions.size()-1);
99  if (atomId >= d_positions.size()) {
100  d_positions.resize(atomId + 1, RDGeom::Point3D(0.0, 0.0, 0.0));
101  }
102  d_positions[atomId] = position;
103  }
104  //! overload
105  template<class U>
106  void setAtomPos(U atomId, const RDGeom::Point3D &position) {
107  return setAtomPos(rdcast<unsigned int>(atomId), position);
108  }
109  //! get the ID of this conformer
110  inline unsigned int getId() const { return d_id; }
111 
112  //! set the ID of this conformer
113  inline void setId(unsigned int id) { d_id = id; }
114 
115  //! Get the number of atoms
116  inline unsigned int getNumAtoms() const { return rdcast<unsigned int>(d_positions.size()); }
117 
118  inline bool is3D() const { return df_is3D; }
119  inline void set3D(bool v) { df_is3D = v; }
120 
121  protected:
122  //! Set owning moelcule
123  void setOwningMol(ROMol *mol);
124 
125  //! Set owning moelcule
126  void setOwningMol(ROMol &mol);
127 
128  private:
129  bool df_is3D; // is this a 3D conformation?
130  unsigned int d_id; // id is the conformation
131  ROMol *dp_mol; // owning molecule
132  RDGeom::POINT3D_VECT d_positions; // positions of the atoms
133 };
134 
135 typedef boost::shared_ptr<Conformer> CONFORMER_SPTR;
136 }
137 
138 #endif
used to indicate errors from incorrect confomer access
Definition: Conformer.h:21
void setId(unsigned int id)
set the ID of this conformer
Definition: Conformer.h:113
const char * message() const
get the error message
Definition: Conformer.h:28
ConformerException(const char *msg)
construct with an error message
Definition: Conformer.h:24
bool is3D() const
Definition: Conformer.h:118
ROMol & getOwningMol() const
Get the molecule that oqns this conformation.
Definition: Conformer.h:72
ConformerException(const std::string &msg)
construct with an error message
Definition: Conformer.h:26
void setAtomPos(unsigned int atomId, const RDGeom::Point3D &position)
Set the position of the specified atom.
Definition: Conformer.h:97
std::vector< Point3D > POINT3D_VECT
Definition: point.h:507
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:103
void reserve(unsigned int size)
Reserve more space for atom position.
Definition: Conformer.h:69
Conformer()
Constructor.
Definition: Conformer.h:46
~Conformer()
Destructor.
Definition: Conformer.h:62
RDGeom::Point3D & getAtomPos(U atomId)
overload
Definition: Conformer.h:92
const RDGeom::Point3D & getAtomPos(U atomId) const
overload
Definition: Conformer.h:84
Std stuff.
Definition: Atom.h:29
void setAtomPos(U atomId, const RDGeom::Point3D &position)
overload
Definition: Conformer.h:106
unsigned int getId() const
get the ID of this conformer
Definition: Conformer.h:110
boost::shared_ptr< Conformer > CONFORMER_SPTR
Definition: Conformer.h:135
unsigned int getNumAtoms() const
Get the number of atoms.
Definition: Conformer.h:116
The class for representing 2D or 3D conformation of a molecule.
Definition: Conformer.h:41
void set3D(bool v)
Definition: Conformer.h:119
Conformer(unsigned int numAtoms)
Constructor with number of atoms specified ID specification.
Definition: Conformer.h:49
void resize(unsigned int size)
Definition: Conformer.h:66