Loading...
Searching...
No Matches
grid.h
Go to the documentation of this file.
/**********************************************************************
grid.h - Handle grids of values.
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison
Some Portions Copyright (C) 2008 by Marcus D. Hanwell
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#ifndef OB_GRID_H
#define OB_GRID_H
#include <openbabel/babelconfig.h>
#include <openbabel/math/vector3.h>
#include <openbabel/base.h>
// Necessary evil for 2.x series -- should use OBMol* below
#include <openbabel/mol.h>
#include <iosfwd>
#include <algorithm>
#include <vector>
#include <string>
namespace OpenBabel
{
// Forward declaration
class OBMol;
class OBAPI OBGrid: public OBBase
{
protected:
double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax;
public:
OBGrid() {}
virtual void Init(OBMol &box);
double GetXmin() const { return(_xmin); }
double GetYmin() const { return(_ymin); }
double GetZmin() const { return(_zmin); }
double GetXmax() const { return(_xmax); }
double GetYmax() const { return(_ymax); }
double GetZmax() const { return(_zmax); }
bool PointIsInBox(double x,double y,double z)
{
return (x>=_xmin) && (x<=_xmax) &&
(y>=_ymin) && (y<=_ymax) &&
(z>=_zmin) && (z<=_zmax);
}
bool PointIsInBox(double *c)
{
return (c[0]>=_xmin) && (c[0]<=_xmax) &&
(c[1]>=_ymin) && (c[1]<=_ymax) &&
(c[2]>=_zmin) && (c[2]<=_zmax);
}
bool PointIsInBox(vector3 v)
{
return (v.x() >= _xmin) && (v.x() <=_xmax) &&
(v.y()>=_ymin) && (v.y()<=_ymax) &&
(v.z()>=_zmin) && (v.z()<=_zmax);
}
};
class OBAPI OBFloatGrid: public OBGrid
{
protected:
std::vector<double> _values;
int *_ival;
double _midz,_midx,_midy;
int _ydim,_xdim,_zdim;
double _spacing,_inv_spa;
double _halfSpace;
vector3 _xAxis, _yAxis, _zAxis;
public:
OBFloatGrid() : _ival(nullptr), _halfSpace(0.0) {}
~OBFloatGrid()
{
if (_ival) delete [] _ival;
}
void Init(OBMol &box,double spacing, double pad=0.0);
vector3 GetMin() { return vector3(_xmin, _ymin, _zmin); }
void GetMin(double *a)
{
a[0]=_xmin;
a[1]=_ymin;
a[2]=_zmin;
}
vector3 GetMax() { return vector3(_xmax, _ymax, _zmax); }
void GetMax(double *a)
{
a[0]=_xmax;
a[1]=_ymax;
a[2]=_zmax;
}
double GetSpacing() const { return(_spacing); }
void GetSpacing(double &s)
{
s=_spacing;
}
double GetScale() const { return(_inv_spa); }
double GetHalfSpace() const {return(_halfSpace);}
int GetXdim() const { return(_xdim); }
int GetYdim() const { return(_ydim); }
int GetZdim() const { return(_zdim); }
void GetDim(int *a)
{
a[0]=_xdim;
a[1]=_ydim;
a[2]=_zdim;
}
vector3 GetMidpointVector()
{
vector3 v;
v.Set(_midx,_midy,_midz);
return(v);
}
vector3 GetXAxis() const
{
return _xAxis;
}
vector3 GetYAxis() const
{
return _yAxis;
}
vector3 GetZAxis() const
{
return _zAxis;
}
void SetNumberOfPoints(int nx, int ny, int nz);
void SetXAxis(vector3);
void SetYAxis(vector3);
void SetZAxis(vector3);
void SetLimits(const vector3& origin, const vector3& x, const vector3& y,
const vector3& z);
void SetLimits(const double origin[3], const double x[3], const double y[3],
const double z[3]);
std::vector<double> GetDataVector();
void SetVals(const std::vector<double> & vals);
double *GetVals() { return(&_values[0]); }
double GetValue(int i, int j, int k)
{
if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
return 0.0;
else
return _values[i*_ydim*_zdim + j*_zdim + k];
}
void SetVals(double *ptr)
{
for (int i = 0; i < _xdim*_ydim*_zdim; ++i)
_values[i] = ptr[i];
}
bool SetValue(int i, int j, int k, double val)
{
if (i*_ydim*_zdim + j*_zdim + k > _xdim*_ydim*_zdim)
return false;
_values[i*_ydim*_zdim + j*_zdim + k] = val;
return true;
}
vector3 Center()
{
return vector3(_midx,_midy,_midz);
}
friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ;
friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ;
double Inject(double x,double y,double z);
void IndexToCoords(int idx, double &x, double &y, double &z);
void CoordsToIndex(int*,double*);
int CoordsToIndex(double x, double y, double z);
double Interpolate(double,double,double);
double InterpolateDerivatives(double,double,double,double *derivatives);
};
#ifndef OBPolarGrid
#define OBPolarGrid 0x01 /* polar interactions? */
#endif //OBPolarGrid
#ifndef OBLipoGrid
#define OBLipoGrid 0x02 /* lipophilicity? */
#endif //OBLipoGrid
class OBAPI OBProxGrid: public OBGrid
{
protected:
int _gridtype;
int _nxinc,_nyinc,_nzinc,_maxinc;
double _inc;
std::vector<std::vector<int> > cell;
public:
OBProxGrid(int gridtype=0)
{
_gridtype=gridtype;
}
~OBProxGrid()
{}
void Setup(OBMol &mol,OBMol &box, double cutoff,double resolution = 0.5);
void Setup(OBMol &mol,OBMol &box, double cutoff,
std::vector<bool> &use,double resolution = 0.5);
std::vector<int> *GetProxVector(double,double,double);
std::vector<int> *GetProxVector(double*);
bool LipoGrid()
{
return((_gridtype&OBLipoGrid) ? true : false);
}
bool PolarGrid()
{
return(_gridtype&OBPolarGrid);
}
void SetGridType(int gridtype)
{
_gridtype = gridtype;
}
};
// scoring function used: PLP = Piecewise Linear Potential or ChemScore algorithm
typedef enum { Undefined = -1, PLP, ChemScore } score_t;
class OBAPI OBScoreGrid
{
protected:
score_t gridtype;
bool verbose;
public:
double score;
OBScoreGrid(void) { verbose = false; }
virtual ~OBScoreGrid(void) {}
void SetVerbose(bool v) { verbose = v; }
void SetType(score_t type) { gridtype = type; }
score_t GetType(void) { return gridtype; }
virtual void Clear(void) { }
virtual double Eval(double *) { return -1; }
virtual double Eval(OBMol &mol){return Eval(mol.GetCoordinates());}
virtual void Init(OBMol &, OBMol &, std::string &, double){}
virtual void Setup(OBMol &) {}
virtual void Setup(OBMol &, std::vector<int> &){}
virtual void Setup(std::vector<int> &) {}
virtual void Config(std::string) {}
virtual bool Read(std::string) { return false; }
virtual bool Write(std::string) { return false; }
virtual vector3 Center() { return VZero; }
virtual vector3 CenterMol(OBMol &) { return VZero; }
};
} // end namespace OpenBabel
#endif // OB_GRID_H
base.h
Base classes to build a graph.
OpenBabel::OBBase
Base Class.
Definition base.h:240
OpenBabel::OBFloatGrid
Handle double precision floating point 3D grids (e.g., charge density around an OBMol).
Definition grid.h:102
OpenBabel::OBFloatGrid::GetScale
double GetScale() const
Definition grid.h:161
OpenBabel::OBFloatGrid::_zAxis
vector3 _zAxis
Definition grid.h:111
OpenBabel::OBFloatGrid::GetMax
void GetMax(double *a)
Definition grid.h:144
OpenBabel::OBFloatGrid::GetSpacing
double GetSpacing() const
Definition grid.h:152
OpenBabel::OBFloatGrid::Center
vector3 Center()
Definition grid.h:268
OpenBabel::OBFloatGrid::GetZdim
int GetZdim() const
Definition grid.h:169
OpenBabel::OBFloatGrid::_halfSpace
double _halfSpace
Definition grid.h:109
OpenBabel::OBFloatGrid::_spacing
double _spacing
Definition grid.h:108
OpenBabel::OBFloatGrid::GetVals
double * GetVals()
Definition grid.h:238
OpenBabel::OBFloatGrid::_yAxis
vector3 _yAxis
Definition grid.h:111
OpenBabel::OBFloatGrid::_midz
double _midz
Definition grid.h:106
OpenBabel::OBFloatGrid::GetDim
void GetDim(int *a)
Definition grid.h:173
OpenBabel::OBFloatGrid::SetVals
void SetVals(double *ptr)
Definition grid.h:251
OpenBabel::OBFloatGrid::GetXdim
int GetXdim() const
Definition grid.h:165
OpenBabel::OBFloatGrid::_xAxis
vector3 _xAxis
Three axes (i.e., translation vectors like a unit cell).
Definition grid.h:111
OpenBabel::OBFloatGrid::GetSpacing
void GetSpacing(double &s)
Definition grid.h:156
OpenBabel::OBFloatGrid::_ydim
int _ydim
Definition grid.h:107
OpenBabel::OBFloatGrid::_values
std::vector< double > _values
floating point values
Definition grid.h:104
OpenBabel::OBFloatGrid::OBFloatGrid
OBFloatGrid()
Definition grid.h:115
OpenBabel::OBFloatGrid::GetMin
vector3 GetMin()
Definition grid.h:126
OpenBabel::OBFloatGrid::_inv_spa
double _inv_spa
spacing between grid points and its inverse
Definition grid.h:108
OpenBabel::OBFloatGrid::_ival
int * _ival
for integer values (deprecated)
Definition grid.h:105
OpenBabel::OBFloatGrid::SetValue
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
OpenBabel::OBFloatGrid::GetZAxis
vector3 GetZAxis() const
Definition grid.h:201
OpenBabel::OBFloatGrid::GetHalfSpace
double GetHalfSpace() const
Definition grid.h:163
OpenBabel::OBFloatGrid::_zdim
int _zdim
grid dimensions
Definition grid.h:107
OpenBabel::OBFloatGrid::GetYAxis
vector3 GetYAxis() const
Definition grid.h:195
OpenBabel::OBFloatGrid::_xdim
int _xdim
Definition grid.h:107
OpenBabel::OBFloatGrid::GetMin
void GetMin(double *a)
Definition grid.h:131
OpenBabel::OBFloatGrid::GetValue
double GetValue(int i, int j, int k)
Definition grid.h:241
OpenBabel::OBFloatGrid::GetYdim
int GetYdim() const
Definition grid.h:167
OpenBabel::OBFloatGrid::GetMidpointVector
vector3 GetMidpointVector()
Definition grid.h:181
OpenBabel::OBFloatGrid::~OBFloatGrid
~OBFloatGrid()
Definition grid.h:116
OpenBabel::OBFloatGrid::GetMax
vector3 GetMax()
Definition grid.h:139
OpenBabel::OBFloatGrid::_midy
double _midy
center of grid in world coordinates
Definition grid.h:106
OpenBabel::OBFloatGrid::_midx
double _midx
Definition grid.h:106
OpenBabel::OBFloatGrid::GetXAxis
vector3 GetXAxis() const
Definition grid.h:189
OpenBabel::OBGrid::PointIsInBox
bool PointIsInBox(double x, double y, double z)
Definition grid.h:71
OpenBabel::OBGrid::GetYmin
double GetYmin() const
Definition grid.h:60
OpenBabel::OBGrid::PointIsInBox
bool PointIsInBox(vector3 v)
Definition grid.h:86
OpenBabel::OBGrid::GetZmin
double GetZmin() const
Definition grid.h:62
OpenBabel::OBGrid::_ymin
double _ymin
Definition grid.h:47
OpenBabel::OBGrid::GetXmin
double GetXmin() const
Definition grid.h:58
OpenBabel::OBGrid::_xmin
double _xmin
Definition grid.h:47
OpenBabel::OBGrid::_ymax
double _ymax
Definition grid.h:47
OpenBabel::OBGrid::OBGrid
OBGrid()
Definition grid.h:50
OpenBabel::OBGrid::GetXmax
double GetXmax() const
Definition grid.h:64
OpenBabel::OBGrid::GetYmax
double GetYmax() const
Definition grid.h:66
OpenBabel::OBGrid::_xmax
double _xmax
Definition grid.h:47
OpenBabel::OBGrid::_zmax
double _zmax
the min/max axes in XYZ axes (i.e., the box)
Definition grid.h:47
OpenBabel::OBGrid::GetZmax
double GetZmax() const
Definition grid.h:68
OpenBabel::OBGrid::_zmin
double _zmin
Definition grid.h:47
OpenBabel::OBGrid::PointIsInBox
bool PointIsInBox(double *c)
Definition grid.h:78
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
OpenBabel::OBMol::GetCoordinates
double * GetCoordinates()
Definition mol.h:327
OpenBabel::OBProxGrid::SetGridType
void SetGridType(int gridtype)
Definition grid.h:328
OpenBabel::OBProxGrid::_maxinc
int _maxinc
Definition grid.h:302
OpenBabel::OBProxGrid::cell
std::vector< std::vector< int > > cell
Definition grid.h:304
OpenBabel::OBProxGrid::~OBProxGrid
~OBProxGrid()
Definition grid.h:312
OpenBabel::OBProxGrid::OBProxGrid
OBProxGrid(int gridtype=0)
Definition grid.h:308
OpenBabel::OBProxGrid::PolarGrid
bool PolarGrid()
Definition grid.h:324
OpenBabel::OBProxGrid::_nzinc
int _nzinc
Definition grid.h:302
OpenBabel::OBProxGrid::_gridtype
int _gridtype
Definition grid.h:301
OpenBabel::OBProxGrid::_nyinc
int _nyinc
Definition grid.h:302
OpenBabel::OBProxGrid::_inc
double _inc
Definition grid.h:303
OpenBabel::OBProxGrid::LipoGrid
bool LipoGrid()
Definition grid.h:320
OpenBabel::OBProxGrid::_nxinc
int _nxinc
Definition grid.h:302
OpenBabel::OBScoreGrid::gridtype
score_t gridtype
Definition grid.h:343
OpenBabel::OBScoreGrid::Clear
virtual void Clear(void)
Definition grid.h:357
OpenBabel::OBScoreGrid::~OBScoreGrid
virtual ~OBScoreGrid(void)
Definition grid.h:351
OpenBabel::OBScoreGrid::Center
virtual vector3 Center()
Definition grid.h:367
OpenBabel::OBScoreGrid::Eval
virtual double Eval(OBMol &mol)
Definition grid.h:359
OpenBabel::OBScoreGrid::Setup
virtual void Setup(std::vector< int > &)
Definition grid.h:363
OpenBabel::OBScoreGrid::Eval
virtual double Eval(double *)
Definition grid.h:358
OpenBabel::OBScoreGrid::SetVerbose
void SetVerbose(bool v)
Definition grid.h:353
OpenBabel::OBScoreGrid::score
double score
Definition grid.h:348
OpenBabel::OBScoreGrid::Config
virtual void Config(std::string)
Definition grid.h:364
OpenBabel::OBScoreGrid::SetType
void SetType(score_t type)
Definition grid.h:354
OpenBabel::OBScoreGrid::Write
virtual bool Write(std::string)
Definition grid.h:366
OpenBabel::OBScoreGrid::verbose
bool verbose
Definition grid.h:344
OpenBabel::OBScoreGrid::Init
virtual void Init(OBMol &, OBMol &, std::string &, double)
Definition grid.h:360
OpenBabel::OBScoreGrid::Read
virtual bool Read(std::string)
Definition grid.h:365
OpenBabel::OBScoreGrid::Setup
virtual void Setup(OBMol &, std::vector< int > &)
Definition grid.h:362
OpenBabel::OBScoreGrid::Setup
virtual void Setup(OBMol &)
Definition grid.h:361
OpenBabel::OBScoreGrid::GetType
score_t GetType(void)
Definition grid.h:355
OpenBabel::OBScoreGrid::OBScoreGrid
OBScoreGrid(void)
Definition grid.h:350
OpenBabel::OBScoreGrid::CenterMol
virtual vector3 CenterMol(OBMol &)
Definition grid.h:368
OpenBabel::vector3
Represents a vector in 3-dimensional real space.
Definition vector3.h:45
OpenBabel::vector3::x
const double & x() const
Access function to get the x-coordinate of the vector.
Definition vector3.h:237
OpenBabel::vector3::Set
void Set(const double inX, const double inY, const double inZ)
Set x,y and z-component of a vector.
Definition vector3.h:87
OpenBabel::vector3::z
const double & z() const
Access function to get the z-coordinate of the vector.
Definition vector3.h:247
OpenBabel::vector3::y
const double & y() const
Access function to get the y-coordinate of the vector.
Definition vector3.h:242
OBPolarGrid
#define OBPolarGrid
Definition grid.h:288
OBLipoGrid
#define OBLipoGrid
Definition grid.h:292
mol.h
Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel).
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::VZero
const vector3 VZero
The zero vector: <0.0, 0.0, 0.0>.
OpenBabel::score_t
score_t
Definition grid.h:335
OpenBabel::Undefined
@ Undefined
Definition grid.h:335
OpenBabel::PLP
@ PLP
Definition grid.h:335
OpenBabel::ChemScore
@ ChemScore
Definition grid.h:335
vector3.h
Handle 3D coordinates.