RDKit: UniformRealValueGrid3D.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
UniformRealValueGrid3D.h
Go to the documentation of this file.
1//
2// Copyright (c) 2014-2024, Novartis Institutes for BioMedical Research and
3// other RDKit contributors
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11#include <RDGeneral/export.h>
12#ifndef UNIFORMREALVALUEGRID3D_H_20140403
13#define UNIFORMREALVALUEGRID3D_H_20140403
14
15#include <DataStructs/RealValueVect.h>
16#include <Geometry/point.h>
17#include "Grid3D.h"
18
19namespace RDGeom {
20 class RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D
21 : public Grid3D<RDKit::RealValueVect, double, double> {
22 public:
23 UniformRealValueGrid3D() { initGrid(1.0, 1.0, 1.0, 1.0, RDGeom::Point3D()); };
24 //! \brief ctor
25 /*
26 \param dimX: the x dimension of the grid, in Angstroms
27 \param dimY: the y dimension of the grid, in Angstroms
28 \param dimZ: the z dimension of the grid, in Angstroms
29 \param spacing: the grid spacing, in Angstroms
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 UniformRealValueGrid3D(double dimX, double dimY, double dimZ,
39 double spacing = 0.5,
40 const RDGeom::Point3D *offset = nullptr,
41 const RDKit::RealValueVect *data = nullptr) {
42 if (offset == nullptr) {
43 initGrid(dimX, dimY, dimZ, spacing,
44 RDGeom::Point3D(-0.5 * dimX, -0.5 * dimY, -0.5 * dimZ), data);
45 } else {
46 initGrid(dimX, dimY, dimZ, spacing, *offset, data);
47 }
48 }
49 UniformRealValueGrid3D(const UniformRealValueGrid3D &other);
50 UniformRealValueGrid3D &operator=(const UniformRealValueGrid3D &other);
51
52 //! construct from a string pickle
53 UniformRealValueGrid3D(const std::string &pkl);
54 //! construct from a text pickle
55 UniformRealValueGrid3D(const char *pkl, unsigned int);
56
57 //! \brief Get the index of the grid point closest to point
58 //!
59 //! \return the integer index, -1 if the specified point is outside the grid
60 int getGridPointIndex(const RDGeom::Point3D &point) const override;
61
62 //! \brief Get the value at the grid point closest to the specified point
63 //!
64 //! \return the double value, -1 if the specified index is outside the grid
65 double getVal(const RDGeom::Point3D &point) const override;
66
67 //! \brief Get the value at a specified grid point
68 //!
69 //! \return the double value
70 double getVal(unsigned int pointId) const override;
71
72 //! \brief Set the value at the grid point closest to the specified point
73 //!
74 //! doesn't do anything if the point is outside the grid
75 void setVal(const RDGeom::Point3D &point, double val) override;
76
77 //! \brief get the location of the specified grid point
78 RDGeom::Point3D getGridPointLoc(unsigned int pointId) const override;
79
80 //! \brief Set the value at the specified grid point
81 void setVal(unsigned int pointId, double val) override;
82
83 //! \brief get the size of the grid (number of grid points)
84 unsigned int getSize() const override { return d_numX * d_numY * d_numZ; };
85
86 //! \brief get the index of the grid point given the x, y, z indices
87 //!
88 //! \return the integer value, -1 if the indices are outside the grid
89 int getGridIndex(unsigned int xi, unsigned int yi, unsigned int zi) const;
90
91 //! \brief get the x, y, and z indices of a grid-point index
92 //!
93 void getGridIndices(unsigned int idx, unsigned int &xi, unsigned int &yi,
94 unsigned int &zi) const;
95
96 //! \brief get the number of grid points along x-axis
97 unsigned int getNumX() const { return d_numX; };
98
99 //! \brief get the number of grid points along y-axis
100 unsigned int getNumY() const { return d_numY; };
101
102 //! \brief get the number of grid points along z-axis
103 unsigned int getNumZ() const { return d_numZ; };
104
105 //! \brief get the grid's offset
106 const RDGeom::Point3D &getOffset() const { return d_offSet; };
107
108 //! \brief get the grid's spacing
109 double getSpacing() const { return d_spacing; };
110
111 //! \brief return a \b const pointer to our occupancy vector
112 const RDKit::RealValueVect *getOccupancyVect() const override {
113 return &d_storage;
114 };
115
116 //! brief returns raw vector
117 const std::vector<double> &getData() const { return d_storage.getData(); }
118 std::vector<double> &getData() { return d_storage.getData(); }
119
120 //! \brief returns true if the grid \c other has parameters
121 //! compatible with ours.
122 bool compareParams(const UniformRealValueGrid3D &other) const;
123
124 //! \brief returns true if the grid \c other has the same values
125 //! as ours.
126 bool compareVectors(const UniformRealValueGrid3D &other) const;
127
128 //! \brief returns true if the grid \c other has the same parameters and
129 //! values as ours.
130 bool compareGrids(const UniformRealValueGrid3D &other) const;
131
132 //! \brief calculates the union between the data on this grid and
133 //! that on \c other.
134 //! This grid is modified.
135 //! NOTE that the grids must have the same parameters.
136 UniformRealValueGrid3D &operator|=(const UniformRealValueGrid3D &other);
137 //! \brief calculates the intersection between the data on this grid and
138 //! that on \c other.
139 //! This grid is modified.
140 //! NOTE that the grids must have the same parameters.
141 UniformRealValueGrid3D &operator&=(const UniformRealValueGrid3D &other);
142 //! \brief calculates the sum of the data on this grid and
143 //! that on \c other.
144 //! This grid is modified.
145 //! NOTE that the grids must have the same parameters.
146 UniformRealValueGrid3D &operator+=(const UniformRealValueGrid3D &other);
147 //! \brief calculates the difference between the data on this grid and
148 //! that on \c other.
149 //! This grid is modified.
150 //! NOTE that the grids must have the same parameters.
151 UniformRealValueGrid3D &operator-=(const UniformRealValueGrid3D &other);
152
153 //! \brief create and return a pickle
154 std::string toString() const;
155
156 /*
157 UniformRealValueGrid3D operator& (const UniformRealValueGrid3D &other) const{
158 PRECONDITION(dp_storage,"bad storage");
159 PRECONDITION(compareParams(other),"mismatched params");
160 UniformRealValueGrid3D
161 res(d_numX*d_spacing,d_numY*d_spacing,d_numZ*d_spacing, d_spacing,&d_offSet);
162 return res;
163 };*/
164
165 private:
166 //! \brief internal initialization code
167 /*
168 \param dimX: the x dimension of the grid, in Angstroms
169 \param dimY: the y dimension of the grid, in Angstroms
170 \param dimZ: the z dimension of the grid, in Angstroms
171 \param spacing: the grid spacing, in Angstroms
172 \param offset: the offset of the grid from (0,0,0), in Angstroms.
173 \param data: (optional) a pointer to a DoubleVector to use, we take
174 ownership of the pointer.
175 */
176 void initGrid(double dimX, double dimY, double dimZ, double spacing,
177 const RDGeom::Point3D &offSet,
178 const RDKit::RealValueVect *data = nullptr);
179
180 unsigned int d_numX, d_numY,
181 d_numZ; //! number of grid points along x, y, z axes
182 double d_spacing; //! grid spacing
183
184 RDGeom::Point3D d_offSet; //! the grid offset (from the origin)
185 RDKit::RealValueVect d_storage; //! storage for values at each grid point
186
187 //! \brief construct from a pickle
188 void initFromText(const char *pkl, const unsigned int length);
189};
190
191 RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator|(
192 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
193 RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator&(
194 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
195 RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator+(
196 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
197 RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator-(
198 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
199} // namespace RDGeom
200
201#endif
Grid3D.h
RealValueVect.h
RDGeom::Grid3D
Virtual base class for a grid object.
Definition Grid3D.h:39
RDGeom::Point3D
Definition point.h:53
RDGeom::UniformRealValueGrid3D
Definition UniformRealValueGrid3D.h:21
RDGeom::UniformRealValueGrid3D::UniformRealValueGrid3D
UniformRealValueGrid3D(const std::string &pkl)
construct from a string pickle
RDGeom::UniformRealValueGrid3D::operator=
UniformRealValueGrid3D & operator=(const UniformRealValueGrid3D &other)
RDGeom::UniformRealValueGrid3D::compareParams
bool compareParams(const UniformRealValueGrid3D &other) const
returns true if the grid other has parameters compatible with ours.
RDGeom::UniformRealValueGrid3D::operator-=
UniformRealValueGrid3D & operator-=(const UniformRealValueGrid3D &other)
calculates the difference between the data on this grid and that on other. This grid is modified....
RDGeom::UniformRealValueGrid3D::setVal
void setVal(const RDGeom::Point3D &point, double val) override
Set the value at the grid point closest to the specified point.
RDGeom::UniformRealValueGrid3D::getGridPointIndex
int getGridPointIndex(const RDGeom::Point3D &point) const override
Get the index of the grid point closest to point.
RDGeom::UniformRealValueGrid3D::getSpacing
double getSpacing() const
get the grid's spacing
Definition UniformRealValueGrid3D.h:109
RDGeom::UniformRealValueGrid3D::operator|=
UniformRealValueGrid3D & operator|=(const UniformRealValueGrid3D &other)
calculates the union between the data on this grid and that on other. This grid is modified....
RDGeom::UniformRealValueGrid3D::toString
std::string toString() const
create and return a pickle
RDGeom::UniformRealValueGrid3D::operator&=
UniformRealValueGrid3D & operator&=(const UniformRealValueGrid3D &other)
calculates the intersection between the data on this grid and that on other. This grid is modified....
RDGeom::UniformRealValueGrid3D::getVal
double getVal(unsigned int pointId) const override
Get the value at a specified grid point.
RDGeom::UniformRealValueGrid3D::compareGrids
bool compareGrids(const UniformRealValueGrid3D &other) const
returns true if the grid other has the same parameters and values as ours.
RDGeom::UniformRealValueGrid3D::UniformRealValueGrid3D
UniformRealValueGrid3D(const UniformRealValueGrid3D &other)
RDGeom::UniformRealValueGrid3D::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::UniformRealValueGrid3D::getSize
unsigned int getSize() const override
get the size of the grid (number of grid points)
Definition UniformRealValueGrid3D.h:84
RDGeom::UniformRealValueGrid3D::setVal
void setVal(unsigned int pointId, double val) override
Set the value at the specified grid point.
RDGeom::UniformRealValueGrid3D::UniformRealValueGrid3D
UniformRealValueGrid3D()
Definition UniformRealValueGrid3D.h:23
RDGeom::UniformRealValueGrid3D::getOffset
const RDGeom::Point3D & getOffset() const
get the grid's offset
Definition UniformRealValueGrid3D.h:106
RDGeom::UniformRealValueGrid3D::getOccupancyVect
const RDKit::RealValueVect * getOccupancyVect() const override
return a const pointer to our occupancy vector
Definition UniformRealValueGrid3D.h:112
RDGeom::UniformRealValueGrid3D::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::UniformRealValueGrid3D::getGridPointLoc
RDGeom::Point3D getGridPointLoc(unsigned int pointId) const override
get the location of the specified grid point
RDGeom::UniformRealValueGrid3D::getNumZ
unsigned int getNumZ() const
get the number of grid points along z-axis
Definition UniformRealValueGrid3D.h:103
RDGeom::UniformRealValueGrid3D::UniformRealValueGrid3D
UniformRealValueGrid3D(const char *pkl, unsigned int)
construct from a text pickle
RDGeom::UniformRealValueGrid3D::getVal
double getVal(const RDGeom::Point3D &point) const override
Get the value at the grid point closest to the specified point.
RDGeom::UniformRealValueGrid3D::getNumY
unsigned int getNumY() const
get the number of grid points along y-axis
Definition UniformRealValueGrid3D.h:100
RDGeom::UniformRealValueGrid3D::getData
const std::vector< double > & getData() const
brief returns raw vector
Definition UniformRealValueGrid3D.h:117
RDGeom::UniformRealValueGrid3D::operator+=
UniformRealValueGrid3D & operator+=(const UniformRealValueGrid3D &other)
calculates the sum of the data on this grid and that on other. This grid is modified....
RDGeom::UniformRealValueGrid3D::getNumX
unsigned int getNumX() const
get the number of grid points along x-axis
Definition UniformRealValueGrid3D.h:97
RDGeom::UniformRealValueGrid3D::compareVectors
bool compareVectors(const UniformRealValueGrid3D &other) const
returns true if the grid other has the same values as ours.
RDGeom::UniformRealValueGrid3D::UniformRealValueGrid3D
UniformRealValueGrid3D(double dimX, double dimY, double dimZ, double spacing=0.5, const RDGeom::Point3D *offset=nullptr, const RDKit::RealValueVect *data=nullptr)
ctor
Definition UniformRealValueGrid3D.h:38
RDGeom::UniformRealValueGrid3D::getData
std::vector< double > & getData()
Definition UniformRealValueGrid3D.h:118
RDKit::RealValueVect
Definition RealValueVect.h:27
export.h
RDKIT_RDGEOMETRYLIB_EXPORT
#define RDKIT_RDGEOMETRYLIB_EXPORT
Definition export.h:449
RDGeom
Definition TorsionAngleContribs.h:17
RDGeom::operator&
RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator&(const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2)
RDGeom::operator-
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator-(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)
RDGeom::operator|
RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator|(const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2)
RDGeom::operator+
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator+(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)
point.h