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