RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
BaseGrid.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// Interface to all grid classes. Provides conversion methods between different
14// addressing methods: (iXYZ),(iX,iY,iZ), and (x,y,z) coords. Underlying data
15// values are managed by subclasses.
16
17#ifndef _RBTBASEGRID_H_
18#define _RBTBASEGRID_H_
19
20#include "rxdock/Config.h"
21#include "rxdock/Coord.h"
22
23#include <set>
24
25namespace rxdock {
26
27class BaseGrid {
28public:
29 // Class type string
30 static const std::string _CT;
31
33 // Constructors/destructors
34 // Construct a NXxNYxNZ grid running from gridMin at gridStep resolution
35 BaseGrid(const Coord &gridMin, const Vector &gridStep, unsigned int NX,
36 unsigned int NY, unsigned int NZ, unsigned int NPad = 0);
37 // Constructor reading all params from binary stream
38 BaseGrid(json j);
39 BaseGrid(const BaseGrid &); // Copy constructor
40 BaseGrid &operator=(const BaseGrid &); // Copy assignment
41 virtual ~BaseGrid(); // Default destructor
42
43 // Friend functions
44 // Insertion operator (primarily for debugging)
45 friend std::ostream &operator<<(std::ostream &s, const BaseGrid &grid);
46 friend void to_json(json &j, const BaseGrid &grid);
47 friend void from_json(const json &j, BaseGrid &grid);
48
50 // Virtual functions for reading/writing grid data to streams in
51 // text and binary format
52 // Subclasses should provide their own private OwnPrint
53 // method to handle subclass data members, and override the public
54 // Print method
55 virtual void Print(std::ostream &ostr) const; // Text output
56
58 // Public methods
60
62 // Get attribute functions
64
65 unsigned int GetNX() const { return m_NX; }
66 unsigned int GetNY() const { return m_NY; }
67 unsigned int GetNZ() const { return m_NZ; }
68 unsigned int GetN() const { return m_N; }
69 unsigned int GetStrideX() const { return m_SX; }
70 unsigned int GetStrideY() const { return m_SY; }
71 unsigned int GetStrideZ() const { return m_SZ; }
72 int GetnXMin() const { return m_nXMin; }
73 int GetnYMin() const { return m_nYMin; }
74 int GetnZMin() const { return m_nZMin; }
75 int GetnXMax() const { return m_nXMax; }
76 int GetnYMax() const { return m_nYMax; }
77 int GetnZMax() const { return m_nZMax; }
78
79 const Coord &GetGridMin() const { return m_min; }
80 const Coord &GetGridMax() const { return m_max; }
81 const Vector &GetGridStep() const { return m_step; }
82 Coord GetGridCenter() const { return (GetGridMax() + GetGridMin()) / 2.0; }
83 Coord GetGridSize() const { return GetGridMax() - GetGridMin(); }
84 unsigned int GetPad() const { return m_NPad; }
85 const Coord &GetPadMin() const { return m_padMin; }
86 const Coord &GetPadMax() const { return m_padMax; }
87
89 // Set attribute functions
91
92 // Set grid min without changing the grid step
93 void SetGridMin(const Coord &gridMin);
94 // Translate the grid by the given vector
95 void TranslateGrid(const Vector &vec) { SetGridMin(GetGridMin() + vec); }
96 // Set the center of the grid to the given coord
97 void SetGridCenter(const Coord &gridCenter) {
98 TranslateGrid(gridCenter - GetGridCenter());
99 }
100 // Set grid step
101 void SetGridStep(const Vector &gridStep);
102 // Set a pad region (cuboid inside the grid which defines the valid coords)
103 void SetPad(unsigned int NPad = 0);
104
106 // Bounds checking and index conversion routines
108
109 // When checking coords, take account of pad region
110 bool isValid(const Coord &c) const {
111 return (c >= m_padMin) && (c < m_padMax);
112 }
113 // When checking 3-D indices, take account of pad region
114 bool isValid(unsigned int iX, unsigned int iY, unsigned int iZ) const {
115 return (iX >= m_NPad) && (iX < m_NX - m_NPad) && (iY >= m_NPad) &&
116 (iY < m_NY - m_NPad) && (iZ >= m_NPad) && (iZ < m_NZ - m_NPad);
117 }
118 // When checking 1-D index, don't take account of pad region
119 bool isValid(unsigned int iXYZ) const { return (iXYZ < m_N); }
120
121 // Return iX,iY,iZ indices for given coord
122 unsigned int GetIX(const Coord &c) const {
123 return static_cast<unsigned int>((c.xyz(0) - m_min.xyz(0)) / m_step.xyz(0));
124 }
125 unsigned int GetIY(const Coord &c) const {
126 return static_cast<unsigned int>((c.xyz(1) - m_min.xyz(1)) / m_step.xyz(1));
127 }
128 unsigned int GetIZ(const Coord &c) const {
129 return static_cast<unsigned int>((c.xyz(2) - m_min.xyz(2)) / m_step.xyz(2));
130 }
131
132 // Return iX,iY,iZ indices for given coord
133 unsigned int GetIX(double x) const {
134 return static_cast<unsigned int>((x - m_min.xyz(0)) / m_step.xyz(0));
135 }
136 unsigned int GetIY(double y) const {
137 return static_cast<unsigned int>((y - m_min.xyz(1)) / m_step.xyz(1));
138 }
139 unsigned int GetIZ(double z) const {
140 return static_cast<unsigned int>((z - m_min.xyz(2)) / m_step.xyz(2));
141 }
142
143 // Return iX,iY,iZ indices for given iXYZ index
144 unsigned int GetIX(unsigned int iXYZ) const { return iXYZ / m_SX; }
145 unsigned int GetIY(unsigned int iXYZ) const { return (iXYZ % m_SX) / m_SY; }
146 unsigned int GetIZ(unsigned int iXYZ) const { return (iXYZ % m_SY) / m_SZ; }
147
148 // Return iXYZ index for given iX,iY,iZ indices
149 unsigned int GetIXYZ(unsigned int iX, unsigned int iY,
150 unsigned int iZ) const {
151 return iX * m_SX + iY * m_SY + iZ * m_SZ;
152 }
153 // Return iXYZ index for given coord
154 unsigned int GetIXYZ(const Coord &c) const {
155 return GetIXYZ(GetIX(c), GetIY(c), GetIZ(c));
156 }
157
158 // Returns real-world coordinate for given iX,iY,iZ indices
159 Coord GetCoord(unsigned int iX, unsigned int iY, unsigned int iZ) const {
160 return (Coord(m_nXMin, m_nYMin, m_nZMin) + Coord(iX, iY, iZ)) * m_step;
161 }
162 // Returns real-world X coordinate for given iX index
163 double GetXCoord(unsigned int iX) const {
164 return (m_nXMin + static_cast<int>(iX)) * m_step.xyz(0);
165 }
166 // Returns real-world Y coordinate for given iY index
167 double GetYCoord(unsigned int iY) const {
168 return (m_nYMin + static_cast<int>(iY)) * m_step.xyz(1);
169 }
170 // Returns real-world Z coordinate for given iZ index
171 double GetZCoord(unsigned int iZ) const {
172 return (m_nZMin + static_cast<int>(iZ)) * m_step.xyz(2);
173 }
174
175 // Returns real-world coordinate for given iXYZ index
176 Coord GetCoord(unsigned int iXYZ) const {
177 return GetCoord(GetIX(iXYZ), GetIY(iXYZ), GetIZ(iXYZ));
178 }
179 // Returns list of real-world coordinates for given set of iXYZ indices
180 CoordList GetCoordList(const std::set<unsigned int> &iXYZSet) const;
181
182 // DM 17 May 1999 - returns the set of valid grid points within a sphere of a
183 // given center and radius DM 17 Jul 2000 - use std::vector<UInt> and
184 // return by reference, for performance boost
185 void GetSphereIndices(const Coord &c, double radius,
186 std::vector<unsigned int> &sIndices) const;
187
188protected:
190 // Protected methods
192
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 BaseGrid(); // Disable default constructor
201
202 // Helper function called by copy constructor and assignment operator
203 void CopyGrid(const BaseGrid &);
204
205protected:
207 // Protected data
209
210private:
212 // Private data
214 unsigned int
215 m_NX; // Number of grid points in X direction (fixed in constructor)
216 unsigned int
217 m_NY; // Number of grid points in Y direction (fixed in constructor)
218 unsigned int
219 m_NZ; // Number of grid points in Z direction (fixed in constructor)
220 unsigned int m_N; // Total number of grid points (fixed in constructor)
221 unsigned int m_SX; // Stride of X
222 unsigned int m_SY; // Stride of Y
223 unsigned int m_SZ; // Stride of Z
224 Coord m_min; // Minimum grid coords (real-world units)
225 Coord m_max; // Maximum grid coords (real-world units)
226 Vector m_step; // Grid step in X,Y,Z (real-world units)
227 unsigned int m_NPad; // Defines a zero-padded border around the grid
228 Coord m_padMin; // Minimum pad coords (used to define an active region of
229 // the grid)
230 Coord m_padMax; // Maximum pad coords (used to define an active region of
231 // the grid)
232 int m_nXMin; // Minimum X grid point (in units of grid step)
233 int m_nXMax; // Maximum X grid point (in units of grid step)
234 int m_nYMin; // Minimum Y grid point (in units of grid step)
235 int m_nYMax; // Maximum Y grid point (in units of grid step)
236 int m_nZMin; // Minimum Z grid point (in units of grid step)
237 int m_nZMax; // Maximum Z grid point (in units of grid step)
238};
239
240// Useful typedefs
241typedef SmartPtr<BaseGrid> BaseGridPtr; // Smart pointer
242
243void to_json(json &j, const BaseGrid &grid);
244void from_json(const json &j, BaseGrid &grid);
245
246} // namespace rxdock
247
248#endif //_RBTBASEGRID_H_
Definition BaseGrid.h:27
Definition Coord.h:45
Definition SmartPointer.h:48