RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
RealGrid.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Manages an array of floats representing a 3-D lattice of grid points
14
15#ifndef _RBTREALGRID_H_
16#define _RBTREALGRID_H_
17
18#ifdef __PGI
19#define EIGEN_DONT_VECTORIZE
20#endif
21#ifdef _WIN32
22#define NOMINMAX
23#endif
24#include <unsupported/Eigen/CXX11/Tensor>
25
26#include "rxdock/BaseGrid.h"
27
28namespace rxdock {
29
30class RealGrid : public BaseGrid {
31public:
32 // Class type string
33 static const std::string _CT;
34
36 // Constructors/destructors
37 // Construct a NXxNYxNZ grid running from gridMin at gridStep resolution
38 RBTDLL_EXPORT RealGrid(const Coord &gridMin, const Coord &gridStep,
39 unsigned int NX, unsigned int NY, unsigned int NZ,
40 unsigned int NPad = 0);
41
42 // Constructor reading all params from binary stream
43 RBTDLL_EXPORT RealGrid(json j);
44
45 ~RealGrid(); // Default destructor
46
47 // Copy constructor
48 RealGrid(const RealGrid &);
49 // Copy constructor taking a base class argument
50 // Sets up the grid dimensions, then creates an empty data array
51 RealGrid(const BaseGrid &);
52 // Copy assignment
53 RealGrid &operator=(const RealGrid &);
54 // Copy assignment taking a base class argument
55 // Sets up the grid dimensions, then creates an empty data array
56 RealGrid &operator=(const BaseGrid &);
57
59 // Virtual functions for reading/writing grid data to streams in
60 // text and binary format
61 // Subclasses should provide their own private OwnPrint
62 // method to handle subclass data members, and override the public
63 // Print method
64 virtual void Print(std::ostream &ostr) const; // Text output
65
67 // Public methods
69
71 // Get attribute functions
73 float *GetGridData() {
74 float *data = m_grid.data();
75 return data;
76 }
77
79 // Get/Set value functions
81
82 // Get/Set tolerance used for assessing value equality
83 double GetTolerance() const { return m_tol; }
84 void SetTolerance(double tol) { m_tol = tol; }
85
86 // Get/Set single grid point value with bounds checking
87 double GetValue(const Coord &c) const {
88 return isValid(c) ? m_grid(GetIX(c), GetIY(c), GetIZ(c)) : 0.0;
89 }
90
91 double GetValue(unsigned int iX, unsigned int iY, unsigned int iZ) const {
92 return isValid(iX, iY, iZ) ? m_grid(iX, iY, iZ) : 0.0;
93 }
94
95 double GetValue(unsigned int iXYZ) const {
96 const float *data = m_grid.data();
97 return isValid(iXYZ) ? data[iXYZ] : 0.0;
98 }
99
100 // DM 20 Jul 2000 - get values smoothed by trilinear interpolation
101 // D. Oberlin and H.A. Scheraga, J. Comp. Chem. (1998) 19, 71.
102 RBTDLL_EXPORT double GetSmoothedValue(const Coord &c) const;
103
104 void SetValue(const Coord &c, double val) {
105 if (isValid(c))
106 m_grid(GetIX(c), GetIY(c), GetIZ(c)) = val;
107 }
108
109 void SetValue(unsigned int iX, unsigned int iY, unsigned int iZ, double val) {
110 if (isValid(iX, iY, iZ))
111 m_grid(iX, iY, iZ) = val;
112 }
113
114 void SetValue(unsigned int iXYZ, double val) {
115 float *data = m_grid.data();
116 if (isValid(iXYZ))
117 data[iXYZ] = val;
118 }
119
120 // Set all grid points to the given value
121 RBTDLL_EXPORT void SetAllValues(double val);
122 // Replaces all grid points with a given value (+/- tolerance) with newVal
123 void ReplaceValue(double oldVal, double newVal) {
124 ReplaceValueRange(oldVal - m_tol, oldVal + m_tol, newVal);
125 }
126 // Replaces all grid points between oldValMin and oldValMax with newVal
127 void ReplaceValueRange(double oldValMin, double oldValMax, double newVal);
128
129 // Set all grid points within radius of coord to the given value
130 // If bOverwrite is false, does not replace non-zero values
131 // If bOverwrite is true, all grid points are set the new value
132 void SetSphere(const Coord &c, double radius, double val,
133 bool bOverwrite = true);
134
135 // Set all grid points with radii between rad1 and rad2 from coord to the
136 // given value If bOverwrite is false, does not replace non-zero values If
137 // bOverwrite is true, all grid points are set the new value
138 void SetSurface(const Coord &c, double innerRad, double outerRad, double val,
139 bool bOverwrite = true);
140
141 // Sets all grid points with value=oldValue, which are adjacent to those with
142 // value=adjacentValue, to value=newValue
143 //+/- tolerance is applied to oldValue and adjacentValue
144 void CreateSurface(double oldVal, double adjVal, double newVal);
145
146 // DM 16 Apr 1999 - helper function for determining solvent accessible regions
147 // Returns true if any of the grid points within a sphere around the central
148 // coord have the specified value
149 bool isValueWithinSphere(const Coord &c, double radius, double val);
150 // Sets all grid points with value=oldValue, which have no grid points with
151 // value=adjacentValue within a sphere of given radius, to value=newValue
152 //+/- tolerance is applied to oldValue and adjacentValue
153 // If bCenterOnly is true, just the center of the sphere is set the newValue
154 // If bCenterOnly is false, all grid points in the sphere are set to the
155 // newValue
156 void SetAccessible(double radius, double oldVal, double adjVal, double newVal,
157 bool bCenterOnly = true);
158
160 // Statistical functions
162
163 // Returns number of occurrences of a given value (+/- tolerance)
164 unsigned int Count(double val) const {
165 return CountRange(val - m_tol, val + m_tol);
166 }
167 // Returns number of occurrences of a given value range
168 unsigned int CountRange(double valMin, double valMax) const;
169
170 // Min/max values
171 double MinValue() const;
172 double MaxValue() const;
173
174 unsigned int
175 FindMinValue() const; // iXYZ index of grid point with minimum value
176 unsigned int
177 FindMaxValue() const; // iXYZ index of grid point with maximum value
178
180 // I/O functions
182
183 // Dump grid in a format readable by Insight
184 RBTDLL_EXPORT void PrintInsightGrid(std::ostream &s) const;
185
186 RBTDLL_EXPORT friend void to_json(json &j, const RealGrid &grid);
187 friend void from_json(const json &j, RealGrid &grid);
188
189protected:
191 // Protected methods
193 // Protected method for writing data members for this class to text stream
194 void OwnPrint(std::ostream &ostr) const;
195
196private:
198 // Private methods
200 RealGrid(); // Disable default constructor
201
202 // DM 17 Jul 2000 - analogous to isValueWithinSphere but iterates over
203 // arbitrary set of IXYZ indices. Private method as there is no error checking
204 // on iXYZ values out of bounds
205 bool isValueWithinList(const std::vector<unsigned int> &iXYZList, double val);
206 // Analogous to SetSphere but iterates over arbitrary set
207 // of IXYZ indices. Private method as there is no error checking on iXYZ
208 // values out of bounds If bOverwrite is false, does not replace non-zero
209 // values If bOverwrite is true, all grid points are set the new value
210 void SetValues(const std::vector<unsigned int> &iXYZList, double val,
211 bool bOverwrite = true);
212
213 void CreateArrays();
214
215 // Helper function called by copy constructor and assignment operator
216 void CopyGrid(const RealGrid &);
217
218protected:
220 // Protected data
222
223private:
225 // Private data
227 Eigen::Tensor<float, 3, Eigen::RowMajor>
228 m_grid; // 3-D array, accessed as m_grid(i, j, k), indicies from 0
229 double m_tol; // Tolerance for comparing grid values;
230};
231
232// Useful typedefs
233typedef SmartPtr<RealGrid> RealGridPtr; // Smart pointer
234typedef std::vector<RealGridPtr> RealGridList;
235typedef RealGridList::iterator RealGridListIter;
236typedef RealGridList::const_iterator RealGridListConstIter;
237
238RBTDLL_EXPORT void to_json(json &j, const RealGrid &grid);
239void from_json(const json &j, RealGrid &grid);
240
241} // namespace rxdock
242
243#endif //_RBTREALGRID_H_
Definition BaseGrid.h:27
Definition Coord.h:45
Definition RealGrid.h:30
Definition SmartPointer.h:48