| 1 |
#include <iostream> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
extern "C" { |
| 6 |
#include "apbscfg.h" |
| 7 |
#include "apbs.h" |
| 8 |
#include "routines.h" |
| 9 |
#include "apbs_driver.h" |
| 10 |
} |
| 11 |
using namespace std; |
| 12 |
|
| 13 |
|
| 14 |
bool apbs(); |
| 15 |
// ========================================================================= |
| 16 |
int main(int argc,char **argv) |
| 17 |
{ |
| 18 |
/** |
| 19 |
|
| 20 |
C++ version of wrapper.f; a simple program to use iAPBS API. |
| 21 |
This is a working but bare minimum example how to interact with iAPBS. |
| 22 |
|
| 23 |
Contributed by E. Prabhu Raman ([email protected]) |
| 24 |
|
| 25 |
How to compile: |
| 26 |
APBS_LIB=${APBS_HOME}/lib |
| 27 |
APBS_INCL=${APBS_HOME}/include |
| 28 |
g++ -g wrapper.cpp -I${APBS_INCL} -I${APBS_INCL}/apbs -I${APBS_INCL}/iapbs -I${APBS_INCL}/maloc -L${APBS_LIB} -liapbs -lapbs_routines -lapbs_mg -lapbs_generic -lapbs_pmgc -lm -lmaloc -o wrapper.o |
| 29 |
|
| 30 |
|
| 31 |
*/ |
| 32 |
|
| 33 |
cout<<"Hello World"<<endl; |
| 34 |
cout<<"Testing iAPBS-APBS"<<endl; |
| 35 |
cout<<"Test Molecule: Methanol (hardcoded geomtery and params)"<<endl; |
| 36 |
|
| 37 |
apbs(); |
| 38 |
|
| 39 |
return(0); |
| 40 |
} |
| 41 |
// ========================================================================= |
| 42 |
bool apbs(){ |
| 43 |
int rc, natom, i, j, loop; |
| 44 |
|
| 45 |
double r_param[9]; |
| 46 |
int i_param[25]; |
| 47 |
int ispara; |
| 48 |
int dime[3], pdime[3]; |
| 49 |
double grid[3], glen[3], center[3], cglen[3], fglen[3]; |
| 50 |
double ccenter[3], fcenter[3]; |
| 51 |
double ofrac; |
| 52 |
|
| 53 |
double ionq[MAXION], ionc[MAXION], ionrr[MAXION]; |
| 54 |
|
| 55 |
double esenergy[1],npenergy[1]; |
| 56 |
double *x = new double[NATOMS]; |
| 57 |
double *y = new double[NATOMS]; |
| 58 |
double *z = new double[NATOMS]; |
| 59 |
double *radius = new double[NATOMS]; |
| 60 |
double *charge = new double[NATOMS]; |
| 61 |
double *apbsdx = new double[NATOMS]; |
| 62 |
double *apbsdy = new double[NATOMS]; |
| 63 |
double *apbsdz = new double[NATOMS]; |
| 64 |
double *apbsqfx = new double[NATOMS]; |
| 65 |
double *apbsqfy = new double[NATOMS]; |
| 66 |
double *apbsqfz = new double[NATOMS]; |
| 67 |
double *apbsdbx = new double[NATOMS]; |
| 68 |
double *apbsdby = new double[NATOMS]; |
| 69 |
double *apbsdbz = new double[NATOMS]; |
| 70 |
double *apbsnpx = new double[NATOMS]; |
| 71 |
double *apbsnpy = new double[NATOMS]; |
| 72 |
double *apbsnpz = new double[NATOMS]; |
| 73 |
double *apbsibx = new double[NATOMS]; |
| 74 |
double *apbsiby = new double[NATOMS]; |
| 75 |
double *apbsibz = new double[NATOMS]; |
| 76 |
|
| 77 |
double apbsnp[3]; |
| 78 |
double apbsgrid_meta[13] ; |
| 79 |
|
| 80 |
double *apbsgrid = new double[3*NATOMS]; |
| 81 |
|
| 82 |
int apbs_debug; |
| 83 |
|
| 84 |
double pdie, sdie, srad, swin, temp, gamma, sdens; |
| 85 |
double smvolume, smsize; |
| 86 |
int nonlin, bcfl, nion, srfm, calcenergy, calcforce; |
| 87 |
int calc_type, nlev, cmeth, ccmeth, fcmeth, chgm; |
| 88 |
int wpot, wchg, wsmol, wkappa, wdiel, rchg, rkappa; |
| 89 |
int watompot, rpot, rdiel; |
| 90 |
int calcnpenergy, calcnpforce; |
| 91 |
|
| 92 |
int dummyi; |
| 93 |
char dummyc; |
| 94 |
double dummyr, maxx, minx, maxy, miny, maxz, minz; |
| 95 |
|
| 96 |
//initialization of input data |
| 97 |
for(int i=0;i<3;i++){ |
| 98 |
grid[i] = 0.0; |
| 99 |
dime[i] = 0; |
| 100 |
glen[i] = 0.0; |
| 101 |
center[i] = 0.0; |
| 102 |
pdime[i] = 0; |
| 103 |
cglen[i] = 0.0; |
| 104 |
fglen[i] = 0.0; |
| 105 |
ccenter[i] = 0.0; |
| 106 |
fcenter[i] = 0.0; |
| 107 |
} |
| 108 |
for(int i=0;i<13;i++){ |
| 109 |
apbsgrid_meta[i] = 0.0; |
| 110 |
} |
| 111 |
for(int i=0;i<3*NATOMS;i++){ |
| 112 |
apbsgrid[i] = 0.0; |
| 113 |
} |
| 114 |
|
| 115 |
//defaults |
| 116 |
for(int i=0;i<3;i++) |
| 117 |
grid[i] = 0.25; |
| 118 |
|
| 119 |
pdie = 2.0; |
| 120 |
sdie = 78.0; |
| 121 |
srad = 0.0 ; //1.4 radius of the solvent molecules |
| 122 |
swin = 0.3; //size of the support (i.e., the rate of change) for spline-based |
| 123 |
//surface definitions (see srfm spl2). The value is usually set to 0.3 Å |
| 124 |
temp = 298.0; |
| 125 |
sdens = 10.0; //10.0 the number of quadrature points per Å2 to use in surface terms |
| 126 |
// (e.g., molecular surface, solvent accessible surface) for apolar |
| 127 |
|
| 128 |
|
| 129 |
gamma = 0.0085; //0.105 surface tension coefficient for apolar solvation models |
| 130 |
smvolume = 10.0; // controls the lattice size (in A^3) used in the SMPBE formalism. |
| 131 |
smsize = 1000.0; // controls the relative size of the ions (in Angstroms) such that |
| 132 |
// !each lattice site can contain a single ion of volume radius^3 |
| 133 |
// !or size ions of volume radius^3/size. |
| 134 |
|
| 135 |
calc_type = 0; |
| 136 |
nlev = 4; |
| 137 |
cmeth = 1; |
| 138 |
ccmeth = 1 ; |
| 139 |
fcmeth = 1 ; |
| 140 |
chgm = 0 ; // !1! the method by which the biomolecular point charges (i.e., |
| 141 |
// ! Dirac delta functions) are mapped to the grid for a multigrid PB |
| 142 |
|
| 143 |
nonlin = 0; //!non-linear PB |
| 144 |
bcfl = 2; // !1 !Specifies the type of boundary conditions used to solve PB |
| 145 |
srfm = 1; // ! 2 !the model used to construct the solvent-related surface and volume |
| 146 |
calcenergy = 1; |
| 147 |
calcforce = 0; |
| 148 |
calcnpenergy = 1; |
| 149 |
calcnpforce = 0; |
| 150 |
|
| 151 |
//Read/Write only |
| 152 |
wpot = 0 ; //Writes electrostatic potential data to iapbs-pot.dx in DX format |
| 153 |
wchg = 0 ; // Writes charge data to iapbs-charge.dx in DX format |
| 154 |
wsmol = 0 ; //!Writes molecular surface data to iapbs-smol.dx in DX format |
| 155 |
wkappa = 0 ; |
| 156 |
wdiel= 0 ; |
| 157 |
watompot = 0 ; |
| 158 |
rchg = 0 ; //!Reads charge data from iapbs-charge.dx in DX format |
| 159 |
rkappa = 0 ; //!Reads the ion-accessibility kappa map from iapbs-kappa.dx in DX format |
| 160 |
rdiel = 0 ; //!Reads dielectric maps from iapbs-diel[x,y,z].dx in DX format |
| 161 |
rpot = 0 ; |
| 162 |
|
| 163 |
nion = 0; |
| 164 |
for(int i=0;i<MAXION;i++){ |
| 165 |
ionq[i] = 0.0; |
| 166 |
ionc[i] = 0.0; |
| 167 |
ionrr[i] = 0.0; |
| 168 |
} |
| 169 |
|
| 170 |
ofrac = 0.3; |
| 171 |
|
| 172 |
apbs_debug = 3; |
| 173 |
loop = 1; |
| 174 |
|
| 175 |
cout<<"Hardcoded PQR Data ..."<<endl; |
| 176 |
x[0]=0.0190; y[0]=0.0000; z[0]=0.6556; charge[0]=0.2700; radius[0]=1.8875; |
| 177 |
x[1]=-0.1197; y[1]=0.0000; z[1]=-0.7372; charge[1]=-0.7000; radius[1]=1.5350; |
| 178 |
x[2]=0.7370; y[2]=0.0000; z[2]=-1.1390; charge[2]=0.4300; radius[2]=0.2000; |
| 179 |
natom=3; |
| 180 |
|
| 181 |
maxx = x[0]; |
| 182 |
minx = x[0]; |
| 183 |
maxy = y[0]; |
| 184 |
miny = y[0]; |
| 185 |
maxz = z[0]; |
| 186 |
minz = z[0]; |
| 187 |
for(int i=0;i<natom;i++){ |
| 188 |
if(maxx < x[i]+radius[i]) |
| 189 |
maxx = x[i]+radius[i]; |
| 190 |
if(minx > x[i]-radius[i]) |
| 191 |
minx = x[i]-radius[i]; |
| 192 |
if(maxy < y[i]+radius[i]) |
| 193 |
maxy = y[i]+radius[i]; |
| 194 |
if(miny > y[i]-radius[i]) |
| 195 |
miny = y[i]-radius[i]; |
| 196 |
if(maxz < z[i]+radius[i]) |
| 197 |
maxz = z[i]+radius[i]; |
| 198 |
if(minz > z[i]-radius[i]) |
| 199 |
minz = z[i]-radius[i]; |
| 200 |
} |
| 201 |
|
| 202 |
cout<<"Mol. dimensions: "<<maxx-minx<<" "<<maxy-miny<<" "<<maxz-minz<<endl; |
| 203 |
|
| 204 |
//if we are doing mg-auto calculate recommended grid values |
| 205 |
//including dime, if not specified |
| 206 |
|
| 207 |
if(((calc_type == 0) || (calc_type == 1)) && dime[0] == 0){ |
| 208 |
cglen[0] = 1.7 * (maxx-minx); |
| 209 |
cglen[1] = 1.7 * (maxy-miny); |
| 210 |
cglen[2] = 1.7 * (maxz-minz); |
| 211 |
fglen[0] = 20.0 + (maxx-minx); |
| 212 |
fglen[1] = 20.0 + (maxy-miny); |
| 213 |
fglen[2] = 20.0 + (maxz-minz); |
| 214 |
|
| 215 |
for(int i=0;i<3;i++){ |
| 216 |
if(fglen[i] > cglen[i]) |
| 217 |
cglen[i] = fglen[i]; |
| 218 |
} |
| 219 |
|
| 220 |
if (dime[0] == 0 ){ |
| 221 |
cout<<"Grid dime not specified, calculating ..."<<endl; |
| 222 |
for(int i=0;i<3;i++){ |
| 223 |
dime[i] = 32*(int((int(fglen[i]/grid[i]+0.5)-1)/32 + 0.5))+ 1; |
| 224 |
if (dime[i] < 33) |
| 225 |
dime[i] = 33; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
cout<<"Grid values: "<<endl; |
| 230 |
cout<<"fglen: "<<" "<<fglen[0]<<" "<<fglen[1]<<" "<<fglen[2]<<endl; |
| 231 |
cout<<"cglen: "<<" "<<cglen[0]<<" "<<cglen[1]<<" "<<cglen[2]<<endl; |
| 232 |
cout<<"dime: "<<" "<<dime[0]<<" "<<dime[1]<<" "<<dime[2]<<endl; |
| 233 |
cout<<"grid: "<<grid[0]<<" "<<grid[1]<<" "<<grid[2]<<endl; |
| 234 |
cout<<"Required memory (in MB): "<<dime[0]*dime[1]*dime[2]*200.0/1024.0/1024.0<<endl; |
| 235 |
} |
| 236 |
|
| 237 |
i_param[0] = calc_type; |
| 238 |
i_param[1] = nlev ; |
| 239 |
i_param[2] = cmeth; |
| 240 |
i_param[3] = ccmeth; |
| 241 |
i_param[4] = fcmeth; |
| 242 |
i_param[5] = chgm; |
| 243 |
i_param[6] = nonlin; |
| 244 |
i_param[7] = bcfl; |
| 245 |
i_param[8] = srfm; |
| 246 |
i_param[9] = calcenergy; |
| 247 |
i_param[10] = calcforce; |
| 248 |
i_param[11] = wpot; |
| 249 |
i_param[12] = wchg; |
| 250 |
i_param[13] = wsmol; |
| 251 |
i_param[14] = wkappa; |
| 252 |
i_param[15] = wdiel; |
| 253 |
i_param[16] = watompot; |
| 254 |
i_param[17] = rpot; |
| 255 |
i_param[18] = 0; |
| 256 |
i_param[19] = calcnpforce; |
| 257 |
i_param[20] = calcnpenergy; |
| 258 |
i_param[21] = nion; |
| 259 |
i_param[22] = rchg; |
| 260 |
i_param[23] = rkappa; |
| 261 |
i_param[24] = rdiel; |
| 262 |
|
| 263 |
r_param[0] = pdie; |
| 264 |
r_param[1] = sdie; |
| 265 |
r_param[2] = srad; |
| 266 |
r_param[3] = swin; |
| 267 |
r_param[4] = temp; |
| 268 |
r_param[5] = sdens; |
| 269 |
r_param[6] = gamma; |
| 270 |
r_param[7] = smvolume; |
| 271 |
r_param[8] = smsize; |
| 272 |
|
| 273 |
//more intialization |
| 274 |
for(int i=0;i<natom;i++){ |
| 275 |
apbsdx[i] = 0.0; |
| 276 |
apbsdy[i] = 0.0; |
| 277 |
apbsdz[i] = 0.0; |
| 278 |
apbsqfx[i] = 0.0; |
| 279 |
apbsqfy[i] = 0.0; |
| 280 |
apbsqfz[i] = 0.0; |
| 281 |
apbsibx[i] = 0.0; |
| 282 |
apbsiby[i] = 0.0; |
| 283 |
apbsibz[i] = 0.0; |
| 284 |
apbsdbx[i] = 0.0; |
| 285 |
apbsdby[i] = 0.0; |
| 286 |
apbsdbz[i] = 0.0; |
| 287 |
apbsnpx[i] = 0.0; |
| 288 |
apbsnpy[i] = 0.0; |
| 289 |
apbsnpz[i] = 0.0; |
| 290 |
} |
| 291 |
|
| 292 |
esenergy[0] = 0.0; //WATCH OUT FOR THIS |
| 293 |
npenergy[0] = 0.0; |
| 294 |
|
| 295 |
//OK, now we are ready to call the apbs_driver and start the show |
| 296 |
for(int j=0;j<loop;j++){ |
| 297 |
rc = apbsdrv_(&natom,x,y,z,radius,charge,r_param,i_param,grid,dime, |
| 298 |
pdime, glen, center, cglen, fglen, |
| 299 |
ccenter, fcenter, &ofrac, &apbs_debug, |
| 300 |
ionq, ionc, ionrr, |
| 301 |
esenergy,npenergy, |
| 302 |
apbsdx, apbsdy, apbsdz, |
| 303 |
apbsqfx, apbsqfy, apbsqfz, |
| 304 |
apbsibx, apbsiby, apbsibz, |
| 305 |
apbsnpx, apbsnpy, apbsnpz, |
| 306 |
apbsdbx, apbsdby, apbsdbz, |
| 307 |
apbsgrid_meta, &apbsgrid); |
| 308 |
} |
| 309 |
|
| 310 |
cout<<"ElecEnergy :"<<esenergy[0]<<endl; |
| 311 |
cout<<"NP Energy :"<<npenergy[0]<<endl; |
| 312 |
return true; |
| 313 |
} |
| 314 |
// ========================================================================= |