use of ffx.potential.nonbonded.GeneralizedKirkwood in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method updateCustomGBForce.
/**
* Updates the custom GB force for change in Use flags.
*
* @param atoms Array of all Atoms in the system
*/
private void updateCustomGBForce(Atom[] atoms) {
GeneralizedKirkwood gk = super.getGK();
double[] baseRadii = gk.getBaseRadii();
double[] overlapScale = gk.getOverlapScale();
PointerByReference doubleArray = OpenMM_DoubleArray_create(0);
int nAtoms = atoms.length;
for (int i = 0; i < nAtoms; i++) {
Atom atom = atoms[i];
double useFactor = 1.0;
if (!atoms[i].getUse() || !atoms[i].getElectrostatics()) {
// if (!atoms[i].getUse()) {
useFactor = 0.0;
}
double lambdaScale = lambda;
if (!atom.applyLambda()) {
lambdaScale = 1.0;
}
useFactor *= lambdaScale;
MultipoleType multipoleType = atom.getMultipoleType();
double charge = multipoleType.charge * useFactor;
double oScale = overlapScale[i] * useFactor;
OpenMM_DoubleArray_append(doubleArray, charge);
OpenMM_DoubleArray_append(doubleArray, OpenMM_NmPerAngstrom * baseRadii[i]);
OpenMM_DoubleArray_append(doubleArray, oScale);
OpenMM_CustomGBForce_setParticleParameters(customGBForce, i, doubleArray);
OpenMM_DoubleArray_resize(doubleArray, 0);
}
OpenMM_DoubleArray_destroy(doubleArray);
OpenMM_CustomGBForce_updateParametersInContext(customGBForce, context);
}
use of ffx.potential.nonbonded.GeneralizedKirkwood in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method addFixedChargeNonBondedForce.
/**
* Uses arithmetic mean to define sigma and geometric mean for epsilon.
*/
private void addFixedChargeNonBondedForce() {
VanDerWaals vdW = super.getVdwNode();
if (vdW == null) {
return;
}
/**
* Only 6-12 LJ with arithmetic mean to define sigma and geometric mean
* for epsilon is supported.
*/
VanDerWaalsForm vdwForm = vdW.getVDWForm();
if (vdwForm.vdwType != LENNARD_JONES || vdwForm.radiusRule != ARITHMETIC || vdwForm.epsilonRule != GEOMETRIC) {
logger.info(format(" VDW Type: %s", vdwForm.vdwType));
logger.info(format(" VDW Radius Rule: %s", vdwForm.radiusRule));
logger.info(format(" VDW Epsilon Rule: %s", vdwForm.epsilonRule));
logger.log(Level.SEVERE, String.format(" Unsuppporterd van der Waals functional form."));
return;
}
fixedChargeNonBondedForce = OpenMM_NonbondedForce_create();
/**
* OpenMM vdW force requires a diameter (i.e. not radius).
*/
double radScale = 1.0;
if (vdwForm.radiusSize == RADIUS) {
radScale = 2.0;
}
/**
* OpenMM vdw force requires atomic sigma values (i.e. not r-min).
*/
if (vdwForm.radiusType == R_MIN) {
radScale /= 1.122462048309372981;
}
/**
* Add particles.
*/
Atom[] atoms = molecularAssembly.getAtomArray();
int nAtoms = atoms.length;
for (int i = 0; i < nAtoms; i++) {
Atom atom = atoms[i];
VDWType vdwType = atom.getVDWType();
double sigma = OpenMM_NmPerAngstrom * vdwType.radius * radScale;
double eps = OpenMM_KJPerKcal * vdwType.wellDepth;
double charge = 0.0;
MultipoleType multipoleType = atom.getMultipoleType();
if (multipoleType != null && atoms[i].getElectrostatics()) {
charge = multipoleType.charge;
}
OpenMM_NonbondedForce_addParticle(fixedChargeNonBondedForce, charge, sigma, eps);
}
/**
* Define 1-4 scale factors.
*/
double lj14Scale = vdwForm.getScale14();
double coulomb14Scale = 1.0 / 1.2;
ParticleMeshEwald pme = super.getPmeNode();
Bond[] bonds = super.getBonds();
if (bonds != null && bonds.length > 0) {
int nBonds = bonds.length;
PointerByReference bondArray;
bondArray = OpenMM_BondArray_create(0);
for (int i = 0; i < nBonds; i++) {
Bond bond = bonds[i];
int i1 = bond.getAtom(0).getXyzIndex() - 1;
int i2 = bond.getAtom(1).getXyzIndex() - 1;
OpenMM_BondArray_append(bondArray, i1, i2);
}
if (pme != null) {
coulomb14Scale = pme.getScale14();
}
OpenMM_NonbondedForce_createExceptionsFromBonds(fixedChargeNonBondedForce, bondArray, coulomb14Scale, lj14Scale);
OpenMM_BondArray_destroy(bondArray);
int num = OpenMM_NonbondedForce_getNumExceptions(fixedChargeNonBondedForce);
chargeExclusion = new boolean[num];
vdWExclusion = new boolean[num];
exceptionChargeProd = new double[num];
exceptionEps = new double[num];
IntByReference particle1 = new IntByReference();
IntByReference particle2 = new IntByReference();
DoubleByReference chargeProd = new DoubleByReference();
DoubleByReference sigma = new DoubleByReference();
DoubleByReference eps = new DoubleByReference();
for (int i = 0; i < num; i++) {
OpenMM_NonbondedForce_getExceptionParameters(fixedChargeNonBondedForce, i, particle1, particle2, chargeProd, sigma, eps);
if (abs(chargeProd.getValue()) > 0.0) {
chargeExclusion[i] = false;
exceptionChargeProd[i] = chargeProd.getValue();
} else {
exceptionChargeProd[i] = 0.0;
chargeExclusion[i] = true;
}
if (abs(eps.getValue()) > 0.0) {
vdWExclusion[i] = false;
exceptionEps[i] = eps.getValue();
} else {
vdWExclusion[i] = true;
exceptionEps[i] = 0.0;
}
}
}
Crystal crystal = super.getCrystal();
if (crystal.aperiodic()) {
OpenMM_NonbondedForce_setNonbondedMethod(fixedChargeNonBondedForce, OpenMM_NonbondedForce_NonbondedMethod.OpenMM_NonbondedForce_NoCutoff);
} else {
OpenMM_NonbondedForce_setNonbondedMethod(fixedChargeNonBondedForce, OpenMM_NonbondedForce_NonbondedMethod.OpenMM_NonbondedForce_PME);
if (pme != null) {
// Units of the Ewald coefficient are A^-1; Multiply by AngstromsPerNM to convert to (Nm^-1).
double aEwald = OpenMM_AngstromsPerNm * pme.getEwaldCoefficient();
int nx = pme.getReciprocalSpace().getXDim();
int ny = pme.getReciprocalSpace().getYDim();
int nz = pme.getReciprocalSpace().getZDim();
OpenMM_NonbondedForce_setPMEParameters(fixedChargeNonBondedForce, aEwald, nx, ny, nz);
}
NonbondedCutoff nonbondedCutoff = vdW.getNonbondedCutoff();
double off = nonbondedCutoff.off;
double cut = nonbondedCutoff.cut;
OpenMM_NonbondedForce_setCutoffDistance(fixedChargeNonBondedForce, OpenMM_NmPerAngstrom * off);
OpenMM_NonbondedForce_setUseSwitchingFunction(fixedChargeNonBondedForce, OpenMM_True);
if (cut == off) {
logger.warning(" OpenMM does not properly handle cutoffs where cut == off!");
if (cut == Double.MAX_VALUE || cut == Double.POSITIVE_INFINITY) {
logger.info(" Detected infinite or max-value cutoff; setting cut to 1E+40 for OpenMM.");
cut = 1E40;
} else {
logger.info(String.format(" Detected cut %8.4g == off %8.4g; scaling cut to 0.99 of off for OpenMM.", cut, off));
cut *= 0.99;
}
}
OpenMM_NonbondedForce_setSwitchingDistance(fixedChargeNonBondedForce, OpenMM_NmPerAngstrom * cut);
}
OpenMM_NonbondedForce_setUseDispersionCorrection(fixedChargeNonBondedForce, OpenMM_False);
// OpenMM_Force_setForceGroup(fixedChargeNonBondedForce, 1);
OpenMM_System_addForce(system, fixedChargeNonBondedForce);
logger.log(Level.INFO, String.format(" Added fixed charge non-bonded force."));
GeneralizedKirkwood gk = super.getGK();
if (gk != null) {
addCustomGBForce();
}
}
Aggregations