00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OB_GRID_H
00021 #define OB_GRID_H
00022
00023 #include "babelconfig.h"
00024
00025 #if HAVE_IOSTREAM
00026 #include <iostream>
00027 #elif HAVE_IOSTREAM_H
00028 #include <iostream.h>
00029 #endif
00030
00031 #include <algorithm>
00032 #include <vector>
00033 #include <string>
00034
00035 #ifndef OBPolarGrid
00036 #define OBPolarGrid 0x01
00037 #endif //OBPolarGrid
00038
00039 #ifndef OBLipoGrid
00040 #define OBLipoGrid 0x02
00041 #endif //OBLipoGrid
00042
00043 namespace OpenBabel
00044 {
00045
00047 class OBAPI OBProxGrid
00048 {
00049 int _gridtype;
00050 int _nxinc,_nyinc,_nzinc,_maxinc;
00051 double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax,_inc;
00052 std::vector<std::vector<int> > cell;
00053
00054 public:
00055
00056 OBProxGrid(int gridtype=0)
00057 {
00058 _gridtype=gridtype;
00059 }
00060 ~OBProxGrid()
00061 {}
00062 void Setup(OBMol &mol,OBMol &box, double cutoff,double resolution = 0.5);
00063 void Setup(OBMol &mol,OBMol &box, double cutoff,
00064 std::vector<bool> &use,double resolution = 0.5);
00065 std::vector<int> *GetProxVector(double,double,double);
00066 std::vector<int> *GetProxVector(double*);
00067
00068 bool LipoGrid()
00069 {
00070 return((_gridtype&OBLipoGrid) ? true : false);
00071 }
00072 bool PolarGrid()
00073 {
00074 return(_gridtype&OBPolarGrid);
00075 }
00076 void SetGridType(int gridtype)
00077 {
00078 _gridtype = gridtype;
00079 }
00080 bool PointIsInBox(double x,double y,double z)
00081 {
00082 return (x>=_xmin) && (x<=_xmax) &&
00083 (y>=_ymin) && (y<=_ymax) &&
00084 (z>=_zmin) && (z<=_zmax);
00085 }
00086 };
00087
00089 class OBAPI OBFloatGrid
00090 {
00091 protected:
00092 double *_val;
00093 int *_ival;
00094 double _midz,_midx,_midy;
00095 int _ydim,_xdim,_zdim;
00096 double _spacing,_inv_spa;
00097 double _xmin,_xmax,_ymin,_ymax,_zmin,_zmax;
00098 double _halfSpace;
00099
00100 public:
00101
00102 OBFloatGrid() : _halfSpace(0.0)
00103 {
00104 _val=NULL;
00105 _ival=NULL;
00106 }
00107 ~OBFloatGrid()
00108 {
00109 if (_ival)
00110 {
00111 delete [] _ival;
00112 _ival = NULL;
00113 }
00114 if (_val)
00115 {
00116 delete [] _val;
00117 _val = NULL;
00118 }
00119 }
00122 void Init(OBMol &box,double spacing, double pad= 0.0);
00124 bool PointIsInBox(double x,double y,double z)
00125 {
00126 return (x>=_xmin) && (x<=_xmax) &&
00127 (y>=_ymin) && (y<=_ymax) &&
00128 (z>=_zmin) && (z<=_zmax);
00129 }
00131 bool PointIsInBox(double *c)
00132 {
00133 return (c[0]>=_xmin) && (c[0]<=_xmax) &&
00134 (c[1]>=_ymin) && (c[1]<=_ymax) &&
00135 (c[2]>=_zmin) && (c[2]<=_zmax);
00136 }
00137 double GetXmin() const { return(_xmin); }
00138 double GetYmin() const { return(_ymin); }
00139 double GetZmin() const { return(_zmin); }
00140 double GetXmax() const { return(_xmax); }
00141 double GetYmax() const { return(_ymax); }
00142 double GetZmax() const { return(_zmax); }
00143 void GetMin(double *a)
00144 {
00145 a[0]=_xmin;
00146 a[1]=_ymin;
00147 a[2]=_zmin;
00148 }
00149 void GetMax(double *a)
00150 {
00151 a[0]=_xmax;
00152 a[1]=_ymax;
00153 a[2]=_zmax;
00154 }
00155
00156 double GetSpacing() const { return(_spacing); }
00157 void GetSpacing(double &s)
00158 {
00159 s=_spacing;
00160 }
00161 double GetScale() const { return(_inv_spa); }
00162 double GetHalfSpace() const {return(_halfSpace);}
00163 int GetXdim() const { return(_xdim); }
00164 int GetYdim() const { return(_ydim); }
00165 int GetZdim() const { return(_zdim); }
00166 void GetDim(int *a)
00167 {
00168 a[0]=_xdim;
00169 a[1]=_ydim;
00170 a[2]=_zdim;
00171 }
00172 vector3 GetMidpointVector()
00173 {
00174 vector3 v;
00175 v.Set(_midx,_midy,_midz);
00176 return(v);
00177 }
00178 double *GetVals() { return(_val); }
00179 void SetVals(double *ptr) { _val = ptr; }
00180 vector3 Center()
00181 {
00182 return vector3(_midx,_midy,_midz);
00183 }
00184
00185 friend std::ostream& operator<< ( std::ostream&, const OBFloatGrid& ) ;
00186 friend std::istream& operator>> ( std::istream&,OBFloatGrid& ) ;
00187
00189 double Inject(double x,double y,double z);
00190
00191 void IndexToCoords(int idx, double &x, double &y, double &z);
00192 void CoordsToIndex(int*,double*);
00193 int CoordsToIndex(double &x, double &y, double &z);
00195 double Interpolate(double,double,double);
00197 double InterpolateDerivatives(double,double,double,double *derivatives);
00198 };
00199
00200
00201 typedef enum { Undefined = -1, PLP, ChemScore } score_t;
00202
00204 class OBAPI OBScoreGrid
00205 {
00206 protected:
00207
00208 score_t gridtype;
00209 bool verbose;
00210
00211 public:
00212
00213 double score;
00214
00215 OBScoreGrid(void)
00216 {
00217 verbose = false;
00218 }
00219 virtual ~OBScoreGrid(void)
00220 {}
00221
00222 void SetVerbose(bool v)
00223 {
00224 verbose = v;
00225 }
00226 void SetType(score_t type)
00227 {
00228 gridtype = type;
00229 }
00230 score_t GetType(void)
00231 {
00232 return gridtype;
00233 }
00234
00235 virtual void Clear(void)
00236 { }
00237 virtual double Eval(double *)
00238 {
00239 return -1;
00240 }
00241 virtual double Eval(OBMol &mol)
00242 {
00243 return Eval(mol.GetCoordinates());
00244 }
00245 virtual void Init(OBMol &, OBMol &, std::string &, double)
00246 {}
00247 virtual void Setup(OBMol &)
00248 {}
00249 virtual void Setup(OBMol &, std::vector<int> &)
00250 {}
00251 virtual void Setup(std::vector<int> &)
00252 {}
00253 virtual void Config(std::string)
00254 {}
00255 virtual bool Read(std::string)
00256 {
00257 return false;
00258 }
00259 virtual bool Write(std::string)
00260 {
00261 return false;
00262 }
00263 virtual vector3 Center()
00264 {
00265 return VZero;
00266 }
00267 virtual vector3 CenterMol(OBMol &)
00268 {
00269 return VZero;
00270 }
00271 };
00272
00273 }
00274
00275 #endif // OB_GRID_H
00276