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
16#include <Geometry/point.h>
17#include "Grid3D.h"
18
19namespace RDGeom {
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 }
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.
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.
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.
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.
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
192 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
194 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
196 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
198 const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2);
199} // namespace RDGeom
200
201#endif
Virtual base class for a grid object.
Definition Grid3D.h:39
UniformRealValueGrid3D(const std::string &pkl)
construct from a string pickle
UniformRealValueGrid3D & operator=(const UniformRealValueGrid3D &other)
bool compareParams(const UniformRealValueGrid3D &other) const
returns true if the grid other has parameters compatible with ours.
UniformRealValueGrid3D & operator-=(const UniformRealValueGrid3D &other)
calculates the difference between the data on this grid and that on other. This grid is modified....
void setVal(const RDGeom::Point3D &point, double val) override
Set the value at the grid point closest to the specified point.
int getGridPointIndex(const RDGeom::Point3D &point) const override
Get the index of the grid point closest to point.
double getSpacing() const
get the grid's spacing
UniformRealValueGrid3D & operator|=(const UniformRealValueGrid3D &other)
calculates the union between the data on this grid and that on other. This grid is modified....
std::string toString() const
create and return a pickle
UniformRealValueGrid3D & operator&=(const UniformRealValueGrid3D &other)
calculates the intersection between the data on this grid and that on other. This grid is modified....
double getVal(unsigned int pointId) const override
Get the value at a specified grid point.
bool compareGrids(const UniformRealValueGrid3D &other) const
returns true if the grid other has the same parameters and values as ours.
UniformRealValueGrid3D(const UniformRealValueGrid3D &other)
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
unsigned int getSize() const override
get the size of the grid (number of grid points)
void setVal(unsigned int pointId, double val) override
Set the value at the specified grid point.
const RDGeom::Point3D & getOffset() const
get the grid's offset
const RDKit::RealValueVect * getOccupancyVect() const override
return a const pointer to our occupancy vector
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::Point3D getGridPointLoc(unsigned int pointId) const override
get the location of the specified grid point
unsigned int getNumZ() const
get the number of grid points along z-axis
UniformRealValueGrid3D(const char *pkl, unsigned int)
construct from a text pickle
double getVal(const RDGeom::Point3D &point) const override
Get the value at the grid point closest to the specified point.
unsigned int getNumY() const
get the number of grid points along y-axis
const std::vector< double > & getData() const
brief returns raw vector
UniformRealValueGrid3D & operator+=(const UniformRealValueGrid3D &other)
calculates the sum of the data on this grid and that on other. This grid is modified....
unsigned int getNumX() const
get the number of grid points along x-axis
bool compareVectors(const UniformRealValueGrid3D &other) const
returns true if the grid other has the same values as ours.
UniformRealValueGrid3D(double dimX, double dimY, double dimZ, double spacing=0.5, const RDGeom::Point3D *offset=nullptr, const RDKit::RealValueVect *data=nullptr)
ctor
#define RDKIT_RDGEOMETRYLIB_EXPORT
Definition export.h:417
RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator&(const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2)
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator-(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)
RDKIT_RDGEOMETRYLIB_EXPORT UniformRealValueGrid3D operator|(const UniformRealValueGrid3D &grd1, const UniformRealValueGrid3D &grd2)
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator+(const RDGeom::Point3D &p1, const RDGeom::Point3D &p2)