Open Babel  3.0
grid.h
Go to the documentation of this file.
1 /**********************************************************************
2 grid.h - Handle grids of values.
3 
4 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
5 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
6 Some Portions Copyright (C) 2008 by Marcus D. Hanwell
7 
8 This file is part of the Open Babel project.
9 For more information, see <http://openbabel.org/>
10 
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation version 2 of the License.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 ***********************************************************************/
20 
21 #ifndef OB_GRID_H
22 #define OB_GRID_H
23 
24 #include <openbabel/babelconfig.h>
25 #include <openbabel/math/vector3.h>
26 #include <openbabel/base.h>
27 
28 // Necessary evil for 2.x series -- should use OBMol* below
29 #include <openbabel/mol.h>
30 
31 #include <iosfwd>
32 #include <algorithm>
33 #include <vector>
34 #include <string>
35 
36 namespace OpenBabel
37 {
38 
39  // Forward declaration
40  class OBMol;
41 
44  class OBAPI OBGrid: public OBBase
45  {
46  protected:
47  double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax;
48 
49  public:
50  OBGrid() {}
51 
55  virtual void Init(OBMol &box);
56 
58  double GetXmin() const { return(_xmin); }
60  double GetYmin() const { return(_ymin); }
62  double GetZmin() const { return(_zmin); }
64  double GetXmax() const { return(_xmax); }
66  double GetYmax() const { return(_ymax); }
68  double GetZmax() const { return(_zmax); }
69 
71  bool PointIsInBox(double x,double y,double z)
72  {
73  return (x>=_xmin) && (x<=_xmax) &&
74  (y>=_ymin) && (y<=_ymax) &&
75  (z>=_zmin) && (z<=_zmax);
76  }
78  bool PointIsInBox(double *c)
79  {
80  return (c[0]>=_xmin) && (c[0]<=_xmax) &&
81  (c[1]>=_ymin) && (c[1]<=_ymax) &&
82  (c[2]>=_zmin) && (c[2]<=_zmax);
83  }
84 
87  {
88  return (v.x() >= _xmin) && (v.x() <=_xmax) &&
89  (v.y()>=_ymin) && (v.y()<=_ymax) &&
90  (v.z()>=_zmin) && (v.z()<=_zmax);
91  }
92  };
93 
101  class OBAPI OBFloatGrid: public OBGrid
102  {
103  protected:
104  std::vector<double> _values;
105  int *_ival;
106  double _midz,_midx,_midy;
107  int _ydim,_xdim,_zdim;
108  double _spacing,_inv_spa;
109  double _halfSpace;
110  vector3 _xAxis, _yAxis, _zAxis;
112 
113  public:
114 
115  OBFloatGrid() : _ival(NULL), _halfSpace(0.0) {}
117  {
118  if (_ival) delete [] _ival;
119  }
120 
123  void Init(OBMol &box,double spacing, double pad=0.0);
124 
126  vector3 GetMin() { return vector3(_xmin, _ymin, _zmin); }
127 
131  void GetMin(double *a)
132  {
133  a[0]=_xmin;
134  a[1]=_ymin;
135  a[2]=_zmin;
136  }
137 
139  vector3 GetMax() { return vector3(_xmax, _ymax, _zmax); }
140 
144  void GetMax(double *a)
145  {
146  a[0]=_xmax;
147  a[1]=_ymax;
148  a[2]=_zmax;
149  }
150 
152  double GetSpacing() const { return(_spacing); }
156  void GetSpacing(double &s)
157  {
158  s=_spacing;
159  }
161  double GetScale() const { return(_inv_spa); }
163  double GetHalfSpace() const {return(_halfSpace);}
165  int GetXdim() const { return(_xdim); }
167  int GetYdim() const { return(_ydim); }
169  int GetZdim() const { return(_zdim); }
173  void GetDim(int *a)
174  {
175  a[0]=_xdim;
176  a[1]=_ydim;
177  a[2]=_zdim;
178  }
179 
182  {
183  vector3 v;
184  v.Set(_midx,_midy,_midz);
185  return(v);
186  }
187 
190  {
191  return _xAxis;
192  }
193 
196  {
197  return _yAxis;
198  }
199 
202  {
203  return _zAxis;
204  }
205 
207  void SetNumberOfPoints(int nx, int ny, int nz);
208 
210  void SetXAxis(vector3);
212  void SetYAxis(vector3);
214  void SetZAxis(vector3);
215 
220  void SetLimits(const vector3& origin, const vector3& x, const vector3& y,
221  const vector3& z);
224  void SetLimits(const double origin[3], const double x[3], const double y[3],
225  const double z[3]);
226 
228  std::vector<double> GetDataVector();
232  void SetVals(const std::vector<double> & vals);
233 
238  double *GetVals() { return(&_values[0]); }
239 
241  double GetValue(int i, int j, int k)
242  {
243  if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
244  return 0.0;
245  else
246  return _values[i*_ydim*_zdim + j*_zdim + k];
247  }
248 
251  void SetVals(double *ptr)
252  {
253  for (int i = 0; i < _xdim*_ydim*_zdim; ++i)
254  _values[i] = ptr[i];
255  }
256 
258  bool SetValue(int i, int j, int k, double val)
259  {
260  if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
261  return false;
262 
263  _values[i*_ydim*_zdim + j*_zdim + k] = val;
264  return true;
265  }
266 
269  {
270  return vector3(_midx,_midy,_midz);
271  }
272 
273  friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ;
274  friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ;
275 
277  double Inject(double x,double y,double z);
278  void IndexToCoords(int idx, double &x, double &y, double &z);
279  void CoordsToIndex(int*,double*);
280  int CoordsToIndex(double x, double y, double z);
282  double Interpolate(double,double,double);
284  double InterpolateDerivatives(double,double,double,double *derivatives);
285  };
286 
287 #ifndef OBPolarGrid
288 #define OBPolarGrid 0x01 /* polar interactions? */
289 #endif //OBPolarGrid
290 
291 #ifndef OBLipoGrid
292 #define OBLipoGrid 0x02 /* lipophilicity? */
293 #endif //OBLipoGrid
294 
298  class OBAPI OBProxGrid: public OBGrid
299  {
300  protected:
302  int _nxinc,_nyinc,_nzinc,_maxinc;
303  double _inc;
304  std::vector<std::vector<int> > cell;
305 
306  public:
307 
308  OBProxGrid(int gridtype=0)
309  {
310  _gridtype=gridtype;
311  }
313  {}
314  void Setup(OBMol &mol,OBMol &box, double cutoff,double resolution = 0.5);
315  void Setup(OBMol &mol,OBMol &box, double cutoff,
316  std::vector<bool> &use,double resolution = 0.5);
317  std::vector<int> *GetProxVector(double,double,double);
318  std::vector<int> *GetProxVector(double*);
319 
320  bool LipoGrid()
321  {
322  return((_gridtype&OBLipoGrid) ? true : false);
323  }
324  bool PolarGrid()
325  {
326  return(_gridtype&OBPolarGrid);
327  }
328  void SetGridType(int gridtype)
329  {
330  _gridtype = gridtype;
331  }
332  };
333 
334  // scoring function used: PLP = Piecewise Linear Potential or ChemScore algorithm
335  typedef enum { Undefined = -1, PLP, ChemScore } score_t;
336 
340  class OBAPI OBScoreGrid
341  {
342  protected:
343  score_t gridtype;
344  bool verbose;
345 
346  public:
347 
348  double score;
349 
350  OBScoreGrid(void) { verbose = false; }
351  virtual ~OBScoreGrid(void) {}
352 
353  void SetVerbose(bool v) { verbose = v; }
354  void SetType(score_t type) { gridtype = type; }
355  score_t GetType(void) { return gridtype; }
356 
357  virtual void Clear(void) { }
358  virtual double Eval(double *) { return -1; }
359  virtual double Eval(OBMol &mol){return Eval(mol.GetCoordinates());}
360  virtual void Init(OBMol &, OBMol &, std::string &, double){}
361  virtual void Setup(OBMol &) {}
362  virtual void Setup(OBMol &, std::vector<int> &){}
363  virtual void Setup(std::vector<int> &) {}
364  virtual void Config(std::string) {}
365  virtual bool Read(std::string) { return false; }
366  virtual bool Write(std::string) { return false; }
367  virtual vector3 Center() { return VZero; }
368  virtual vector3 CenterMol(OBMol &) { return VZero; }
369  };
370 
371 } // end namespace OpenBabel
372 
373 #endif // OB_GRID_H
374 
const vector3 VZero
The zero vector: <0.0, 0.0, 0.0>
double _halfSpace
Definition: grid.h:109
double score
Definition: grid.h:348
double GetHalfSpace() const
Definition: grid.h:163
double GetYmax() const
Definition: grid.h:66
virtual void Setup(OBMol &, std::vector< int > &)
Definition: grid.h:362
std::vector< std::vector< int > > cell
Definition: grid.h:304
Handle 3D coordinates.
double GetXmin() const
Definition: grid.h:58
double GetSpacing() const
Definition: grid.h:152
void GetMax(double *a)
Definition: grid.h:144
OBScoreGrid(void)
Definition: grid.h:350
A base grid class.
Definition: grid.h:44
~OBFloatGrid()
Definition: grid.h:116
vector3 GetMax()
Definition: grid.h:139
~OBProxGrid()
Definition: grid.h:312
Base classes to build a graph.
void Set(const double inX, const double inY, const double inZ)
Set x,y and z-component of a vector.
Definition: vector3.h:87
int GetYdim() const
Definition: grid.h:167
score_t gridtype
Definition: grid.h:343
virtual void Setup(OBMol &)
Definition: grid.h:361
double _midz
Definition: grid.h:106
int GetXdim() const
Definition: grid.h:165
vector3 GetXAxis() const
Definition: grid.h:189
virtual void Setup(std::vector< int > &)
Definition: grid.h:363
void GetSpacing(double &s)
Definition: grid.h:156
virtual void Config(std::string)
Definition: grid.h:364
double GetValue(int i, int j, int k)
Definition: grid.h:241
std::vector< double > _values
floating point values
Definition: grid.h:104
const double & x() const
Access function to get the x-coordinate of the vector.
Definition: vector3.h:237
Handle double precision floating point 3D grids (e.g., charge density around an OBMol) ...
Definition: grid.h:101
Molecule Class.
Definition: mol.h:118
virtual void Init(OBMol &, OBMol &, std::string &, double)
Definition: grid.h:360
void GetDim(int *a)
Definition: grid.h:173
int _gridtype
Definition: grid.h:301
int _zdim
grid dimensions
Definition: grid.h:107
score_t GetType(void)
Definition: grid.h:355
double _spacing
Definition: grid.h:108
Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel) ...
bool SetValue(int i, int j, int k, double val)
Set the value at the grid point specified by i, j and k to val.
Definition: grid.h:258
virtual void Clear(void)
Definition: grid.h:357
void SetVals(double *ptr)
Definition: grid.h:251
int _nzinc
Definition: grid.h:302
virtual double Eval(double *)
Definition: grid.h:358
double * GetVals()
Definition: grid.h:238
virtual vector3 Center()
Definition: grid.h:367
bool LipoGrid()
Definition: grid.h:320
vector3 Center()
Definition: grid.h:268
int * _ival
for integer values (deprecated)
Definition: grid.h:105
vector3 GetYAxis() const
Definition: grid.h:195
bool PolarGrid()
Definition: grid.h:324
virtual bool Read(std::string)
Definition: grid.h:365
Definition: grid.h:335
vector3 GetMidpointVector()
Definition: grid.h:181
const double & y() const
Access function to get the y-coordinate of the vector.
Definition: vector3.h:242
double GetScale() const
Definition: grid.h:161
virtual double Eval(OBMol &mol)
Definition: grid.h:359
void SetVerbose(bool v)
Definition: grid.h:353
Represents a vector in 3-dimensional real space.
Definition: vector3.h:44
virtual bool Write(std::string)
Definition: grid.h:366
vector3 GetZAxis() const
Definition: grid.h:201
bool PointIsInBox(double x, double y, double z)
Definition: grid.h:71
Definition: grid.h:335
bool PointIsInBox(double *c)
Definition: grid.h:78
double _inc
Definition: grid.h:303
double GetXmax() const
Definition: grid.h:64
bool PointIsInBox(vector3 v)
Definition: grid.h:86
std::ostream & operator<<(std::ostream &, const vector3 &)
Prints a representation of the vector as a row vector of the form "<0.1,1,2>".
Definition: vector3.cpp:109
std::istream & operator>>(std::istream &is, OBBitVec &bv)
Definition: bitvec.cpp:592
void SetGridType(int gridtype)
Definition: grid.h:328
void GetMin(double *a)
Definition: grid.h:131
Definition: grid.h:335
virtual vector3 CenterMol(OBMol &)
Definition: grid.h:368
double * GetCoordinates()
Definition: mol.h:325
virtual ~OBScoreGrid(void)
Definition: grid.h:351
void SetType(score_t type)
Definition: grid.h:354
score_t
Definition: grid.h:335
bool verbose
Definition: grid.h:344
double GetYmin() const
Definition: grid.h:60
A base class for scoring docking interactions between multiple molecules.
Definition: grid.h:340
const double & z() const
Access function to get the z-coordinate of the vector.
Definition: vector3.h:247
#define OBPolarGrid
Definition: grid.h:288
double GetZmax() const
Definition: grid.h:68
OBFloatGrid()
Definition: grid.h:115
double GetZmin() const
Definition: grid.h:62
#define OBLipoGrid
Definition: grid.h:292
Base Class.
Definition: base.h:239
double _zmin
Definition: grid.h:47
A grid for determining the proximity of a given point to atoms in an OBMol.
Definition: grid.h:298
OBGrid()
Definition: grid.h:50
vector3 GetMin()
Definition: grid.h:126
OBProxGrid(int gridtype=0)
Definition: grid.h:308
int GetZdim() const
Definition: grid.h:169
Global namespace for all Open Babel code.
Definition: alias.h:22