NanoShaper
0.3.1
NanoShaper is a tool able to triangulate and inspect an arbitray triangulated surface or several types of molecular surfaces such as the Gaussian, Skin and the SES
|
00001 00002 //--------------------------------------------------------- 00003 /* @file tools.h 00004 * @brief tools.h Includes some common tools 00005 * */ 00006 //--------------------------------------------------------- 00007 00008 #ifndef tools_h 00009 #define tools_h 00010 00011 #include "jama_eig.h" 00012 #include "globals.h" 00013 #include "./sturm/solve.h" 00014 #include <string> 00015 00016 using namespace TNT; 00017 using namespace JAMA; 00018 // Miscellanous utility functions and lightweighted classes 00019 #define MAX_POLY_DEGREE 10 // max polynomial degree supported by the bgp projection routine (6 is needed for skin, 4 by Connolly) 00020 00022 class Point 00023 { 00024 public: 00025 double pos[3]; 00026 Point() 00027 { 00028 pos[0]=0; 00029 pos[1]=0; 00030 pos[2]=0; 00031 } 00032 Point(double x,double y,double z) 00033 { 00034 pos[0] = x; 00035 pos[1] = y; 00036 pos[2] = z; 00037 } 00038 Point(Point& p) 00039 { 00040 pos[0]= p.pos[0]; 00041 pos[1]= p.pos[1]; 00042 pos[2]= p.pos[2]; 00043 } 00044 00045 double squaredDist(Point* x) 00046 { 00047 double acc =0; 00048 for (int i=0;i<3;i++) 00049 { 00050 double t = x->pos[i]-pos[i]; 00051 acc += t*t; 00052 } 00053 return acc; 00054 } 00055 00056 double dot(Point* x) 00057 { 00058 double acc =0; 00059 for (int i=0;i<3;i++) 00060 acc += x->pos[i]*pos[i]; 00061 return acc; 00062 } 00063 00064 00065 double norm(Point* x) 00066 { 00067 double acc =0; 00068 for (int i=0;i<3;i++) 00069 acc += (pos[i])*(pos[i]); 00070 return sqrt(acc); 00071 } 00072 00073 double dist(Point* x) 00074 { 00075 double acc = 0; 00076 for (int i=0;i<3;i++) 00077 { 00078 double t = x->pos[i]-pos[i]; 00079 acc += t*t; 00080 } 00081 return sqrt(acc); 00082 } 00083 00084 void sumInPlace(Point* x) 00085 { 00086 for (int i=0;i<3;i++) 00087 { 00088 pos[0]+=x->pos[0]; 00089 pos[1]+=x->pos[1]; 00090 pos[2]+=x->pos[2]; 00091 } 00092 } 00093 00094 Point* sum(Point* x) 00095 { 00096 Point* p = new Point(); 00097 for (int i=0;i<3;i++) 00098 { 00099 p->pos[0]=pos[0]+x->pos[0]; 00100 p->pos[1]=pos[1]+x->pos[1]; 00101 p->pos[2]=pos[2]+x->pos[2]; 00102 } 00103 return p; 00104 } 00105 }; 00106 00108 class Atom: public Point 00109 { 00110 public: 00111 double radius; 00112 double charge; 00113 int dielectric; 00114 00115 Atom():Point() 00116 { 00117 radius=0; 00118 charge=0; 00119 dielectric=0; 00120 } 00121 00122 Atom(double x,double y,double z,double r,double c,int d):Point(x,y,z) 00123 { 00124 radius = r; 00125 charge = c; 00126 dielectric = d; 00127 } 00128 00129 // copy constructor 00130 Atom(Atom& p):Point(p) 00131 { 00132 radius = p.radius; 00133 charge = p.charge; 00134 dielectric = p.dielectric; 00135 } 00136 00137 }; 00138 00139 00141 00142 template<class T> T* allocateVector(int n) 00143 { 00144 T* t = (T*)malloc(sizeof(T)*n); 00145 if (t==NULL) 00146 { 00147 cout << endl << ERR << "Not enough memory to allocate vector "; 00148 return NULL; 00149 } 00150 return t; 00151 } 00152 00153 template<class T> T** allocateMatrix2D(int nrows,int ncol) 00154 { 00155 T** t = (T**)malloc(sizeof(T*)*nrows); 00156 if (t==NULL) 00157 { 00158 cout << endl << ERR << "Not enough memory to allocate 2D matrix "; 00159 return NULL; 00160 } 00161 for (int i=0;i<nrows;i++) 00162 { 00163 t[i] = (T*)malloc(sizeof(T)*ncol); 00164 00165 if (t[i]==NULL) 00166 { 00167 cout << endl << ERR << "Not enough memory to allocate 2D matrix "; 00168 return NULL; 00169 } 00170 } 00171 return t; 00172 } 00173 00174 template<class T> T*** allocateMatrix3D(int nx,int ny,int nz) 00175 { 00176 T*** t = (T***)malloc(sizeof(T**)*nx); 00177 if (t==NULL) 00178 { 00179 cout << endl << ERR << "Not enough memory to allocate 3D matrix "; 00180 return NULL; 00181 } 00182 for (int i=0;i<nx;i++) 00183 { 00184 t[i] = (T**)malloc(sizeof(T*)*ny); 00185 if (t[i]==NULL) 00186 { 00187 cout << endl << ERR << "Not enough memory to allocate 3D matrix "; 00188 return NULL; 00189 } 00190 00191 for (int j=0;j<ny;j++) 00192 { 00193 t[i][j] = (T*)malloc(sizeof(T)*nz); 00194 if (t[i][j]==NULL) 00195 { 00196 cout << endl << ERR << "Not enough memory to allocate 3D matrix "; 00197 return NULL; 00198 } 00199 } 00200 } 00201 return t; 00202 } 00203 00204 template<class T> void deleteVector(T* t) 00205 { 00206 free(t); 00207 } 00208 00209 template<class T> void deleteMatrix2D(int nrows,T** t) 00210 { 00211 for (int i=0;i<nrows;i++) 00212 free(t[i]); 00213 free(t); 00214 } 00215 00216 template<class T> void deleteMatrix3D(int nx,int ny,T*** t) 00217 { 00218 for (int i=0;i<nx;i++) 00219 { 00220 for (int j=0;j<ny;j++) 00221 free(t[i][j]); 00222 free(t[i]); 00223 } 00224 free(t); 00225 } 00227 00228 00230 00231 bool compKeepIndex(pair<double,double*> a, pair<double,double*> b); 00233 00234 typedef std::pair<double,int> indexed_double; 00235 bool index_double_comparator( const indexed_double& l, const indexed_double& r); 00237 00241 bool testInCube(double proj0,double proj1,double proj2,double point0,double point1, double point2,double side,double toll=0); 00242 double rintp(double x); 00243 string toLowerCase(string str); 00244 void cleanLine(); 00245 00246 static long int SEED=1234; 00247 // randnumber between 0 and 1 00248 double randnum(); 00249 00253 void getRealRootsCompanion(double* poly,int degree,double* roots,int& numroots); 00255 void getRealRootsSturm(double* poly,int degree,double* roots,int& numroots); 00256 void plane3points(double p1[3],double p2[3],double p3[3],double w[4],bool normalize=true); 00257 void point2plane(double p[3], double w[4],double* dist, double proj[3]); 00258 void inplace_invert4x4(double M[4][4]); 00259 void Matrix4x4MultiplyBy4x4 (double src1[4][4], double src2[4][4], double dest[4][4]); 00260 00261 static int shift_map[27][3]= { {0,0,0}, 00262 {0,0,-1}, 00263 {0,0,+1}, 00264 {0,+1,0}, 00265 {0,+1,-1}, 00266 {0,+1,+1}, 00267 {0,-1,0}, 00268 {0,-1,-1}, 00269 {0,-1,+1}, 00270 00271 {+1,0,0}, 00272 {+1,0,-1}, 00273 {+1,0,+1}, 00274 {+1,+1,0}, 00275 {+1,+1,-1}, 00276 {+1,+1,+1}, 00277 {+1,-1,0}, 00278 {+1,-1,-1}, 00279 {+1,-1,+1}, 00280 00281 {-1,0,0}, 00282 {-1,0,-1}, 00283 {-1,0,+1}, 00284 {-1,+1,0}, 00285 {-1,+1,-1}, 00286 {-1,+1,+1}, 00287 {-1,-1,0}, 00288 {-1,-1,-1}, 00289 {-1,-1,+1} }; 00290 #endif