VPUBLIC int Vgreen_coulomb_direct(Vgreen *thee, int npos, double *x, double *y, double *z, double *val) { Vatom *atom; double *apos, charge, dist, dx, dy, dz, scale; double *q, qtemp, fx, fy, fz; int iatom, ipos; if (thee == VNULL) { Vnm_print(2, "Vgreen_coulomb: Got NULL thee!\n"); return 0; } for (ipos=0; ipos<npos; ipos++) val[ipos] = 0.0; for (iatom=0; iatom<Valist_getNumberAtoms(thee->alist); iatom++) { atom = Valist_getAtom(thee->alist, iatom); apos = Vatom_getPosition(atom); charge = Vatom_getCharge(atom); for (ipos=0; ipos<npos; ipos++) { dx = apos[0] - x[ipos]; dy = apos[1] - y[ipos]; dz = apos[2] - z[ipos]; dist = VSQRT(VSQR(dx) + VSQR(dy) + VSQR(dz)); if (dist > VSMALL) val[ipos] += (charge/dist); } } scale = Vunit_ec/(4*Vunit_pi*Vunit_eps0*1.0e-10); for (ipos=0; ipos<npos; ipos++) val[ipos] = val[ipos]*scale; return 1; }
VPUBLIC int Vgreen_coulombD_direct(Vgreen *thee, int npos, double *x, double *y, double *z, double *pot, double *gradx, double *grady, double *gradz) { Vatom *atom; double *apos, charge, dist, dist2, idist3, dy, dz, dx, scale; double *q, qtemp; int iatom, ipos; if (thee == VNULL) { Vnm_print(2, "Vgreen_coulombD: Got VNULL thee!\n"); return 0; } for (ipos=0; ipos<npos; ipos++) { pot[ipos] = 0.0; gradx[ipos] = 0.0; grady[ipos] = 0.0; gradz[ipos] = 0.0; } for (iatom=0; iatom<Valist_getNumberAtoms(thee->alist); iatom++) { atom = Valist_getAtom(thee->alist, iatom); apos = Vatom_getPosition(atom); charge = Vatom_getCharge(atom); for (ipos=0; ipos<npos; ipos++) { dx = apos[0] - x[ipos]; dy = apos[1] - y[ipos]; dz = apos[2] - z[ipos]; dist2 = VSQR(dx) + VSQR(dy) + VSQR(dz); dist = VSQRT(dist2); if (dist > VSMALL) { idist3 = 1.0/(dist*dist2); gradx[ipos] -= (charge*dx*idist3); grady[ipos] -= (charge*dy*idist3); gradz[ipos] -= (charge*dz*idist3); pot[ipos] += (charge/dist); } } } scale = Vunit_ec/(4*VPI*Vunit_eps0*(1.0e-10)); for (ipos=0; ipos<npos; ipos++) { gradx[ipos] = gradx[ipos]*scale; grady[ipos] = grady[ipos]*scale; gradz[ipos] = gradz[ipos]*scale; pot[ipos] = pot[ipos]*scale; } return 1; }
/* /////////////////////////////////////////////////////////////////////////// // Routine: Vopot_gradient // // Authors: Nathan Baker /////////////////////////////////////////////////////////////////////////// */ VPUBLIC int Vopot_gradient(Vopot *thee, double pt[3], double grad[3]) { Vatom *atom; int iatom; double T, charge, eps_w, xkappa, size, val, *position; double dx, dy, dz, dist; Valist *alist; VASSERT(thee != VNULL); eps_w = Vpbe_getSolventDiel(thee->pbe); xkappa = (1.0e10)*Vpbe_getXkappa(thee->pbe); T = Vpbe_getTemperature(thee->pbe); alist = Vpbe_getValist(thee->pbe); if (!Vmgrid_gradient(thee->mgrid, pt, grad)) { switch (thee->bcfl) { case BCFL_ZERO: grad[0] = 0.0; grad[1] = 0.0; grad[2] = 0.0; break; case BCFL_SDH: grad[0] = 0.0; grad[1] = 0.0; grad[2] = 0.0; size = (1.0e-10)*Vpbe_getSoluteRadius(thee->pbe); position = Vpbe_getSoluteCenter(thee->pbe); charge = Vunit_ec*Vpbe_getSoluteCharge(thee->pbe); dx = position[0] - pt[0]; dy = position[1] - pt[1]; dz = position[2] - pt[2]; dist = VSQR(dx) + VSQR(dy) + VSQR(dz); dist = (1.0e-10)*VSQRT(dist); val = (charge)/(4*VPI*Vunit_eps0*eps_w); if (xkappa != 0.0) val = val*(exp(-xkappa*(dist-size))/(1+xkappa*size)); val = val*Vunit_ec/(Vunit_kb*T); grad[0] = val*dx/dist*(-1.0/dist/dist + xkappa/dist); grad[1] = val*dy/dist*(-1.0/dist/dist + xkappa/dist); grad[2] = val*dz/dist*(-1.0/dist/dist + xkappa/dist); break; case BCFL_MDH: grad[0] = 0.0; grad[1] = 0.0; grad[2] = 0.0; for (iatom=0; iatom<Valist_getNumberAtoms(alist); iatom++) { atom = Valist_getAtom(alist, iatom); position = Vatom_getPosition(atom); charge = Vunit_ec*Vatom_getCharge(atom); size = (1e-10)*Vatom_getRadius(atom); dx = position[0] - pt[0]; dy = position[1] - pt[1]; dz = position[2] - pt[2]; dist = VSQR(dx) + VSQR(dy) + VSQR(dz); dist = (1.0e-10)*VSQRT(dist); val = (charge)/(4*VPI*Vunit_eps0*eps_w); if (xkappa != 0.0) val = val*(exp(-xkappa*(dist-size))/(1+xkappa*size)); val = val*Vunit_ec/(Vunit_kb*T); grad[0] += (val*dx/dist*(-1.0/dist/dist + xkappa/dist)); grad[1] += (val*dy/dist*(-1.0/dist/dist + xkappa/dist)); grad[2] += (val*dz/dist*(-1.0/dist/dist + xkappa/dist)); } break; case BCFL_UNUSED: Vnm_print(2, "Vopot: Invalid bcfl (%d)!\n", thee->bcfl); return 0; case BCFL_FOCUS: Vnm_print(2, "Vopot: Invalid bcfl (%d)!\n", thee->bcfl); return 0; default: Vnm_print(2, "Vopot_pot: Bogus thee->bcfl flag (%d)!\n", thee->bcfl); return 0; break; } return 1; } return 1; }
/* /////////////////////////////////////////////////////////////////////////// // Routine: Vopot_curvature // // Notes: cflag=0 ==> Reduced Maximal Curvature // cflag=1 ==> Mean Curvature (Laplace) // cflag=2 ==> Gauss Curvature // cflag=3 ==> True Maximal Curvature // If we are off the grid, we can still evaluate the Laplacian; assuming, we // are away from the molecular surface, it is simply equal to the DH factor. // // Authors: Nathan Baker /////////////////////////////////////////////////////////////////////////// */ VPUBLIC int Vopot_curvature(Vopot *thee, double pt[3], int cflag, double *value) { Vatom *atom; int i, iatom; double u, T, charge, eps_w, xkappa, dist, size, val, *position, zkappa2; Valist *alist; VASSERT(thee != VNULL); eps_w = Vpbe_getSolventDiel(thee->pbe); xkappa = (1.0e10)*Vpbe_getXkappa(thee->pbe); zkappa2 = Vpbe_getZkappa2(thee->pbe); T = Vpbe_getTemperature(thee->pbe); alist = Vpbe_getValist(thee->pbe); u = 0; if (Vmgrid_curvature(thee->mgrid, pt, cflag, value)) return 1; else if (cflag != 1) { Vnm_print(2, "Vopot_curvature: Off mesh!\n"); return 1; } else { switch (thee->bcfl) { case BCFL_ZERO: u = 0; break; case BCFL_SDH: size = (1.0e-10)*Vpbe_getSoluteRadius(thee->pbe); position = Vpbe_getSoluteCenter(thee->pbe); charge = Vunit_ec*Vpbe_getSoluteCharge(thee->pbe); dist = 0; for (i=0; i<3; i++) dist += VSQR(position[i] - pt[i]); dist = (1.0e-10)*VSQRT(dist); if (xkappa != 0.0) u = zkappa2*(exp(-xkappa*(dist-size))/(1+xkappa*size)); break; case BCFL_MDH: u = 0; for (iatom=0; iatom<Valist_getNumberAtoms(alist); iatom++) { atom = Valist_getAtom(alist, iatom); position = Vatom_getPosition(atom); charge = Vunit_ec*Vatom_getCharge(atom); size = (1e-10)*Vatom_getRadius(atom); dist = 0; for (i=0; i<3; i++) dist += VSQR(position[i] - pt[i]); dist = (1.0e-10)*VSQRT(dist); if (xkappa != 0.0) val = zkappa2*(exp(-xkappa*(dist-size))/(1+xkappa*size)); u = u + val; } break; case BCFL_UNUSED: Vnm_print(2, "Vopot_pot: Invlid bcfl (%d)!\n", thee->bcfl); return 0; case BCFL_FOCUS: Vnm_print(2, "Vopot_pot: Invlid bcfl (%d)!\n", thee->bcfl); return 0; default: Vnm_print(2, "Vopot_pot: Bogus thee->bcfl flag (%d)!\n", thee->bcfl); return 0; break; } *value = u; } return 1; }
VPUBLIC int Vopot_pot(Vopot *thee, double pt[3], double *value) { Vatom *atom; int i, iatom; double u, T, charge, eps_w, xkappa, dist, size, val, *position; Valist *alist; VASSERT(thee != VNULL); eps_w = Vpbe_getSolventDiel(thee->pbe); xkappa = (1.0e10)*Vpbe_getXkappa(thee->pbe); T = Vpbe_getTemperature(thee->pbe); alist = Vpbe_getValist(thee->pbe); u = 0; /* See if we're on the mesh */ if (Vmgrid_value(thee->mgrid, pt, &u)) { *value = u; } else { switch (thee->bcfl) { case BCFL_ZERO: u = 0; break; case BCFL_SDH: size = (1.0e-10)*Vpbe_getSoluteRadius(thee->pbe); position = Vpbe_getSoluteCenter(thee->pbe); charge = Vunit_ec*Vpbe_getSoluteCharge(thee->pbe); dist = 0; for (i=0; i<3; i++) dist += VSQR(position[i] - pt[i]); dist = (1.0e-10)*VSQRT(dist); val = (charge)/(4*VPI*Vunit_eps0*eps_w*dist); if (xkappa != 0.0) val = val*(exp(-xkappa*(dist-size))/(1+xkappa*size)); val = val*Vunit_ec/(Vunit_kb*T); u = val; break; case BCFL_MDH: u = 0; for (iatom=0; iatom<Valist_getNumberAtoms(alist); iatom++) { atom = Valist_getAtom(alist, iatom); position = Vatom_getPosition(atom); charge = Vunit_ec*Vatom_getCharge(atom); size = (1e-10)*Vatom_getRadius(atom); dist = 0; for (i=0; i<3; i++) dist += VSQR(position[i] - pt[i]); dist = (1.0e-10)*VSQRT(dist); val = (charge)/(4*VPI*Vunit_eps0*eps_w*dist); if (xkappa != 0.0) val = val*(exp(-xkappa*(dist-size))/(1+xkappa*size)); val = val*Vunit_ec/(Vunit_kb*T); u = u + val; } break; case BCFL_UNUSED: Vnm_print(2, "Vopot_pot: Invalid bcfl flag (%d)!\n", thee->bcfl); return 0; case BCFL_FOCUS: Vnm_print(2, "Vopot_pot: Invalid bcfl flag (%d)!\n", thee->bcfl); return 0; default: Vnm_print(2, "Vopot_pot: Bogus thee->bcfl flag (%d)!\n", thee->bcfl); return 0; break; } *value = u; } return 1; }
VPRIVATE int treesetup(Vgreen *thee) { #ifdef HAVE_TREE double dist_tol = FMM_DIST_TOL; int iflag = FMM_IFLAG; double order = FMM_ORDER; int theta = FMM_THETA; int shrink = FMM_SHRINK; int maxparnode = FMM_MAXPARNODE; int minlevel = FMM_MINLEVEL; int maxlevel = FMM_MAXLEVEL; int level = 0; int one = 1; Vatom *atom; double xyzminmax[6], *pos; int i; /* Set up particle arrays with atomic coordinates and charges */ Vnm_print(0, "treesetup: Initializing FMM particle arrays...\n"); thee->np = Valist_getNumberAtoms(thee->alist); thee->xp = VNULL; thee->xp = (double *)Vmem_malloc(thee->vmem, thee->np, sizeof(double)); if (thee->xp == VNULL) { Vnm_print(2, "Vgreen_ctor2: Failed to allocate %d*sizeof(double)!\n", thee->np); return 0; } thee->yp = VNULL; thee->yp = (double *)Vmem_malloc(thee->vmem, thee->np, sizeof(double)); if (thee->yp == VNULL) { Vnm_print(2, "Vgreen_ctor2: Failed to allocate %d*sizeof(double)!\n", thee->np); return 0; } thee->zp = VNULL; thee->zp = (double *)Vmem_malloc(thee->vmem, thee->np, sizeof(double)); if (thee->zp == VNULL) { Vnm_print(2, "Vgreen_ctor2: Failed to allocate %d*sizeof(double)!\n", thee->np); return 0; } thee->qp = VNULL; thee->qp = (double *)Vmem_malloc(thee->vmem, thee->np, sizeof(double)); if (thee->qp == VNULL) { Vnm_print(2, "Vgreen_ctor2: Failed to allocate %d*sizeof(double)!\n", thee->np); return 0; } for (i=0; i<thee->np; i++) { atom = Valist_getAtom(thee->alist, i); pos = Vatom_getPosition(atom); thee->xp[i] = pos[0]; thee->yp[i] = pos[1]; thee->zp[i] = pos[2]; thee->qp[i] = Vatom_getCharge(atom); } Vnm_print(0, "treesetup: Setting things up...\n"); F77SETUP(thee->xp, thee->yp, thee->zp, &(thee->np), &order, &theta, &iflag, &dist_tol, xyzminmax, &(thee->np)); Vnm_print(0, "treesetup: Initializing levels...\n"); F77INITLEVELS(&minlevel, &maxlevel); Vnm_print(0, "treesetup: Creating tree...\n"); F77CREATE_TREE(&one, &(thee->np), thee->xp, thee->yp, thee->zp, thee->qp, &shrink, &maxparnode, xyzminmax, &level, &(thee->np)); return 1; #else /* ifdef HAVE_TREE */ Vnm_print(2, "treesetup: Error! APBS not linked with treecode!\n"); return 0; #endif /* ifdef HAVE_TREE */ }