RDKit: UniformGrid3D.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
UniformGrid3D.h
Go to the documentation of this file.
1//
2// Copyright (C) 2005-2013 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 UNIFORMGRID3D_H_20050124_1703
12#define UNIFORMGRID3D_H_20050124_1703
13
14#include "point.h"
15#include <DataStructs/DiscreteValueVect.h>
16#include "Grid3D.h"
17
18namespace RDGeom {
19 class RDKIT_RDGEOMETRYLIB_EXPORT UniformGrid3D
20 : public Grid3D<RDKit::DiscreteValueVect, int, unsigned int> {
21 public:
22 //! \brief ctor
23 /*
24 \param dimX: the x dimension of the grid, in Angstroms
25 \param dimY: the y dimension of the grid, in Angstroms
26 \param dimZ: the z dimension of the grid, in Angstroms
27 \param spacing: the grid spacing, in Angstroms
28 \param valType: the data type of the grid (determines the number of bits
29 per point)
30 \param offset: OPTIONAL: the offset of the grid from (0,0,0), in
31 Angstroms.
32
33 \b Note: the values of arguments such as \c dimX and \c spacing
34 don't actually need to be in Angstroms, but they should be internally
35 consistent.
36
37*/
38 UniformGrid3D(double dimX, double dimY, double dimZ, double spacing = 0.5,
39 RDKit::DiscreteValueVect::DiscreteValueType valType =
40 RDKit::DiscreteValueVect::TWOBITVALUE,
41 const RDGeom::Point3D *offset = nullptr) {
42 if (offset == nullptr) {
43 initGrid(dimX, dimY, dimZ, spacing, valType,
44 Point3D(-0.5 * dimX, -0.5 * dimY, -0.5 * dimZ));
45 } else {
46 initGrid(dimX, dimY, dimZ, spacing, valType, *offset);
47 }
48 }
49 //! copy ctor
50 UniformGrid3D(const UniformGrid3D &other);
51 //! construct from a string pickle
52 UniformGrid3D(const std::string &pkl);
53 //! construct from a text pickle
54 UniformGrid3D(const char *pkl, unsigned int);
55 UniformGrid3D &operator=(const UniformGrid3D &other);
56
57 ~UniformGrid3D() override;
58
59 //! \brief Get the index of the grid point closest to point
60 //!
61 //! \return the integer index, -1 if the specified point is outside the grid
62 int getGridPointIndex(const Point3D &point) const override;
63
64 //! \brief Get the value at the grid point closest to the specified point
65 //!
66 //! \return the integer value, -1 if the specified index is outside the grid
67 int getVal(const Point3D &point) const override;
68
69 //! \brief Get the value at a specified grid point
70 //!
71 //! \return the unsigned integer value
72 unsigned int getVal(unsigned int pointId) const override;
73
74 //! \brief Set the value at the grid point closest to the specified point
75 //!
76 //! doesn't do anything if the point is outside the grid
77 void setVal(const Point3D &point, unsigned int val) override;
78
79 //! \brief get the location of the specified grid point
80 Point3D getGridPointLoc(unsigned int pointId) const override;
81
82 //! \brief Set the value at the specified grid point
83 void setVal(unsigned int pointId, unsigned int val) override;
84
85 //! \brief get the size of the grid (number of grid points)
86 unsigned int getSize() const override { return d_numX * d_numY * d_numZ; }
87
88 //! \brief set the occupancy for a multi-layered sphere
89 /*!
90 This function encodes the occupancy for a sphere and multiple layers around
91 it
92 \param center location of the sphere center
93 \param radius Radius of the base sphere
94 \param stepSize thickness of each layer on top of the base sphere
95 \param maxNumLayers maximum number of layers, if -1 this is
96 determined by
97 the number of bits used per grid points in the
98 storage
99 \param ignoreOutOfBound if true, ignore if center is outside the grid,
100 otherwise throw
101 an exception
102
103 */
104 void setSphereOccupancy(const Point3D &center, double radius, double stepSize,
105 int maxNumLayers = -1, bool ignoreOutOfBound = true);
106
107 //! \brief get the index of the grid point given the x, y, z indices
108 //!
109 //! \return the integer value, -1 if the indices are outside the grid
110 int getGridIndex(unsigned int xi, unsigned int yi, unsigned int zi) const;
111
112 //! \brief get the x, y, and z indices of a grid-point index
113 //!
114 void getGridIndices(unsigned int idx, unsigned int &xi, unsigned int &yi,
115 unsigned int &zi) const;
116
117 //! \brief get the number of grid points along x-axis
118 unsigned int getNumX() const { return d_numX; }
119
120 //! \brief get the number of grid points along y-axis
121 unsigned int getNumY() const { return d_numY; }
122
123 //! \brief get the number of grid points along z-axis
124 unsigned int getNumZ() const { return d_numZ; }
125
126 //! \brief get the grid's offset
127 const Point3D &getOffset() const { return d_offSet; }
128
129 //! \brief get the grid's spacing
130 double getSpacing() const { return d_spacing; }
131
132 //! \brief return a \b const pointer to our occupancy vector
133 const RDKit::DiscreteValueVect *getOccupancyVect() const override {
134 return dp_storage;
135 }
136
137 //! \brief returns true if the grid \c other has parameters
138 //! compatible with ours.
139 virtual bool compareParams(const UniformGrid3D &other) const;
140 //! \brief calculates the union between the data on this grid and
141 //! that on \c other.
142 //! This grid is modified.
143 //! NOTE that the grids must have the same parameters.
144 UniformGrid3D &operator|=(const UniformGrid3D &other);
145 //! \brief calculates the intersection between the data on this grid and
146 //! that on \c other.
147 //! This grid is modified.
148 //! NOTE that the grids must have the same parameters.
149 UniformGrid3D &operator&=(const UniformGrid3D &other);
150 //! \brief calculates the sum of the data on this grid and
151 //! that on \c other.
152 //! This grid is modified.
153 //! NOTE that the grids must have the same parameters.
154 UniformGrid3D &operator+=(const UniformGrid3D &other);
155 //! \brief calculates the difference between the data on this grid and
156 //! that on \c other.
157 //! This grid is modified.
158 //! NOTE that the grids must have the same parameters.
159 UniformGrid3D &operator-=(const UniformGrid3D &other);
160
161 //! \brief create and return a pickle
162 std::string toString() const;
163
164 UniformGrid3D operator&(const UniformGrid3D &other) const {
165 PRECONDITION(dp_storage, "bad storage");
166 PRECONDITION(compareParams(other), "mismatched params");
167 UniformGrid3D res(d_numX * d_spacing, d_numY * d_spacing,
168 d_numZ * d_spacing, d_spacing, dp_storage->getValueType(),
169 &d_offSet);
170 return res;
171 }
172
173 private:
174 //! \brief internal initialization code
175 /*
176 \param dimX: the x dimension of the grid, in Angstroms
177 \param dimY: the y dimension of the grid, in Angstroms
178 \param dimZ: the z dimension of the grid, in Angstroms
179 \param spacing: the grid spacing, in Angstroms
180 \param valType: the data type of the grid (determines the number of bits
181 per point)
182 \param offset: the offset of the grid from (0,0,0), in Angstroms.
183 \param data: (optional) a pointer to a DiscreteValueVect to use, we
184 take
185 ownership of the pointer.
186 */
187 void initGrid(double dimX, double dimY, double dimZ, double spacing,
188 RDKit::DiscreteValueVect::DiscreteValueType valType,
189 const RDGeom::Point3D &offSet,
190 RDKit::DiscreteValueVect *data = nullptr);
191 unsigned int d_numX; //!< number of grid points along x axis
192 unsigned int d_numY; //!< number of grid points along y axis
193 unsigned int d_numZ; //!< number of grid points along z axis
194 double d_spacing; //!< grid spacing
195 Point3D d_offSet; //!< the grid offset (from the origin)
196 RDKit::DiscreteValueVect
197 *dp_storage; //!< storage for values at each grid point
198
199 //! \brief construct from a pickle
200 void initFromText(const char *pkl, const unsigned int length);
201};
202
203//! \brief writes the contents of the grid to a stream
204/*
205 The grid is written in GRD format
206*/
207 RDKIT_RDGEOMETRYLIB_EXPORT void writeGridToStream(const UniformGrid3D &grid,
208 std::ostream &outStrm);
209
210//! \brief writes the contents of the grid to a named file
211/*
212 The grid is written in GRD format
213*/
214 RDKIT_RDGEOMETRYLIB_EXPORT void writeGridToFile(const UniformGrid3D &grid,
215 const std::string &filename);
216} // namespace RDGeom
217
218#endif
DiscreteValueVect.h
Grid3D.h
PRECONDITION
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
RDGeom::Grid3D
Virtual base class for a grid object.
Definition Grid3D.h:39
RDGeom::Point3D
Definition point.h:53
RDGeom::UniformGrid3D
Definition UniformGrid3D.h:20
RDGeom::UniformGrid3D::getNumY
unsigned int getNumY() const
get the number of grid points along y-axis
Definition UniformGrid3D.h:121
RDGeom::UniformGrid3D::operator&
UniformGrid3D operator&(const UniformGrid3D &other) const
Definition UniformGrid3D.h:164
RDGeom::UniformGrid3D::operator-=
UniformGrid3D & operator-=(const UniformGrid3D &other)
calculates the difference between the data on this grid and that on other. This grid is modified....
RDGeom::UniformGrid3D::getVal
int getVal(const Point3D &point) const override
Get the value at the grid point closest to the specified point.
RDGeom::UniformGrid3D::setSphereOccupancy
void setSphereOccupancy(const Point3D &center, double radius, double stepSize, int maxNumLayers=-1, bool ignoreOutOfBound=true)
set the occupancy for a multi-layered sphere
RDGeom::UniformGrid3D::UniformGrid3D
UniformGrid3D(const char *pkl, unsigned int)
construct from a text pickle
RDGeom::UniformGrid3D::UniformGrid3D
UniformGrid3D(const std::string &pkl)
construct from a string pickle
RDGeom::UniformGrid3D::getGridPointIndex
int getGridPointIndex(const Point3D &point) const override
Get the index of the grid point closest to point.
RDGeom::UniformGrid3D::getGridPointLoc
Point3D getGridPointLoc(unsigned int pointId) const override
get the location of the specified grid point
RDGeom::UniformGrid3D::setVal
void setVal(const Point3D &point, unsigned int val) override
Set the value at the grid point closest to the specified point.
RDGeom::UniformGrid3D::UniformGrid3D
UniformGrid3D(double dimX, double dimY, double dimZ, double spacing=0.5, RDKit::DiscreteValueVect::DiscreteValueType valType=RDKit::DiscreteValueVect::TWOBITVALUE, const RDGeom::Point3D *offset=nullptr)
ctor
Definition UniformGrid3D.h:38
RDGeom::UniformGrid3D::getOffset
const Point3D & getOffset() const
get the grid's offset
Definition UniformGrid3D.h:127
RDGeom::UniformGrid3D::getOccupancyVect
const RDKit::DiscreteValueVect * getOccupancyVect() const override
return a const pointer to our occupancy vector
Definition UniformGrid3D.h:133
RDGeom::UniformGrid3D::getSize
unsigned int getSize() const override
get the size of the grid (number of grid points)
Definition UniformGrid3D.h:86
RDGeom::UniformGrid3D::getSpacing
double getSpacing() const
get the grid's spacing
Definition UniformGrid3D.h:130
RDGeom::UniformGrid3D::~UniformGrid3D
~UniformGrid3D() override
RDGeom::UniformGrid3D::operator+=
UniformGrid3D & operator+=(const UniformGrid3D &other)
calculates the sum of the data on this grid and that on other. This grid is modified....
RDGeom::UniformGrid3D::operator&=
UniformGrid3D & operator&=(const UniformGrid3D &other)
calculates the intersection between the data on this grid and that on other. This grid is modified....
RDGeom::UniformGrid3D::operator=
UniformGrid3D & operator=(const UniformGrid3D &other)
RDGeom::UniformGrid3D::getGridIndex
int getGridIndex(unsigned int xi, unsigned int yi, unsigned int zi) const
get the index of the grid point given the x, y, z indices
RDGeom::UniformGrid3D::getNumX
unsigned int getNumX() const
get the number of grid points along x-axis
Definition UniformGrid3D.h:118
RDGeom::UniformGrid3D::getGridIndices
void getGridIndices(unsigned int idx, unsigned int &xi, unsigned int &yi, unsigned int &zi) const
get the x, y, and z indices of a grid-point index
RDGeom::UniformGrid3D::operator|=
UniformGrid3D & operator|=(const UniformGrid3D &other)
calculates the union between the data on this grid and that on other. This grid is modified....
RDGeom::UniformGrid3D::getNumZ
unsigned int getNumZ() const
get the number of grid points along z-axis
Definition UniformGrid3D.h:124
RDGeom::UniformGrid3D::getVal
unsigned int getVal(unsigned int pointId) const override
Get the value at a specified grid point.
RDGeom::UniformGrid3D::compareParams
virtual bool compareParams(const UniformGrid3D &other) const
returns true if the grid other has parameters compatible with ours.
RDGeom::UniformGrid3D::UniformGrid3D
UniformGrid3D(const UniformGrid3D &other)
copy ctor
RDGeom::UniformGrid3D::setVal
void setVal(unsigned int pointId, unsigned int val) override
Set the value at the specified grid point.
RDGeom::UniformGrid3D::toString
std::string toString() const
create and return a pickle
RDKit::DiscreteValueVect
a class for efficiently storing vectors of discrete values
Definition DiscreteValueVect.h:24
RDKit::DiscreteValueVect::DiscreteValueType
DiscreteValueType
used to define the possible range of the values
Definition DiscreteValueVect.h:29
RDKit::DiscreteValueVect::TWOBITVALUE
@ TWOBITVALUE
Definition DiscreteValueVect.h:31
export.h
RDKIT_RDGEOMETRYLIB_EXPORT
#define RDKIT_RDGEOMETRYLIB_EXPORT
Definition export.h:449
RDGeom
Definition TorsionAngleContribs.h:17
RDGeom::writeGridToFile
RDKIT_RDGEOMETRYLIB_EXPORT void writeGridToFile(const UniformGrid3D &grid, const std::string &filename)
writes the contents of the grid to a named file
RDGeom::writeGridToStream
RDKIT_RDGEOMETRYLIB_EXPORT void writeGridToStream(const UniformGrid3D &grid, std::ostream &outStrm)
writes the contents of the grid to a stream
point.h