Search in sources :

Example 6 with VanDerWaalsForm

use of ffx.potential.nonbonded.VanDerWaalsForm in project ffx by mjschnie.

the class ForceFieldEnergyOpenMM method addWCAForce.

private void addWCAForce() {
    double epso = 0.1100;
    double epsh = 0.0135;
    double rmino = 1.7025;
    double rminh = 1.3275;
    double awater = 0.033428;
    double slevy = 1.0;
    double dispoff = 0.26;
    double shctd = 0.81;
    VanDerWaals vdW = super.getVdwNode();
    VanDerWaalsForm vdwForm = vdW.getVDWForm();
    double radScale = 1.0;
    if (vdwForm.radiusSize == VanDerWaalsForm.RADIUS_SIZE.DIAMETER) {
        radScale = 0.5;
    }
    amoebaWcaDispersionForce = OpenMM_AmoebaWcaDispersionForce_create();
    Atom[] atoms = molecularAssembly.getAtomArray();
    int nAtoms = atoms.length;
    for (int i = 0; i < nAtoms; i++) {
        // cdispTotal += nonpol__.cdisp[ii];
        Atom atom = atoms[i];
        VDWType vdwType = atom.getVDWType();
        double radius = vdwType.radius;
        double eps = vdwType.wellDepth;
        OpenMM_AmoebaWcaDispersionForce_addParticle(amoebaWcaDispersionForce, OpenMM_NmPerAngstrom * radius * radScale, OpenMM_KJPerKcal * eps);
    }
    OpenMM_AmoebaWcaDispersionForce_setEpso(amoebaWcaDispersionForce, epso * OpenMM_KJPerKcal);
    OpenMM_AmoebaWcaDispersionForce_setEpsh(amoebaWcaDispersionForce, epsh * OpenMM_KJPerKcal);
    OpenMM_AmoebaWcaDispersionForce_setRmino(amoebaWcaDispersionForce, rmino * OpenMM_NmPerAngstrom);
    OpenMM_AmoebaWcaDispersionForce_setRminh(amoebaWcaDispersionForce, rminh * OpenMM_NmPerAngstrom);
    OpenMM_AmoebaWcaDispersionForce_setDispoff(amoebaWcaDispersionForce, dispoff * OpenMM_NmPerAngstrom);
    OpenMM_AmoebaWcaDispersionForce_setAwater(amoebaWcaDispersionForce, awater / (OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom));
    OpenMM_AmoebaWcaDispersionForce_setSlevy(amoebaWcaDispersionForce, slevy);
    OpenMM_AmoebaWcaDispersionForce_setShctd(amoebaWcaDispersionForce, shctd);
    OpenMM_System_addForce(system, amoebaWcaDispersionForce);
    logger.log(Level.INFO, " Added WCA dispersion force.");
}
Also used : VDWType(ffx.potential.parameters.VDWType) VanDerWaals(ffx.potential.nonbonded.VanDerWaals) VanDerWaalsForm(ffx.potential.nonbonded.VanDerWaalsForm) Atom(ffx.potential.bonded.Atom) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint)

Example 7 with VanDerWaalsForm

use of ffx.potential.nonbonded.VanDerWaalsForm in project ffx by mjschnie.

the class ForceFieldEnergyOpenMM method updateWCAForce.

/**
 * Updates the WCA force for change in Use flags.
 *
 * @param atoms Array of all Atoms in the system
 */
private void updateWCAForce(Atom[] atoms) {
    VanDerWaals vdW = super.getVdwNode();
    VanDerWaalsForm vdwForm = vdW.getVDWForm();
    double radScale = 1.0;
    if (vdwForm.radiusSize == VanDerWaalsForm.RADIUS_SIZE.DIAMETER) {
        radScale = 0.5;
    }
    int nAtoms = atoms.length;
    for (int i = 0; i < nAtoms; i++) {
        double useFactor = 1.0;
        if (!atoms[i].getUse()) {
            useFactor = 0.0;
        }
        double lambdaScale = lambda;
        if (!atoms[i].applyLambda()) {
            lambdaScale = 1.0;
        }
        useFactor *= lambdaScale;
        Atom atom = atoms[i];
        VDWType vdwType = atom.getVDWType();
        double radius = vdwType.radius;
        double eps = vdwType.wellDepth;
        OpenMM_AmoebaWcaDispersionForce_setParticleParameters(amoebaWcaDispersionForce, i, OpenMM_NmPerAngstrom * radius * radScale, OpenMM_KJPerKcal * eps * useFactor);
    }
    OpenMM_AmoebaWcaDispersionForce_updateParametersInContext(amoebaWcaDispersionForce, context);
}
Also used : VDWType(ffx.potential.parameters.VDWType) VanDerWaals(ffx.potential.nonbonded.VanDerWaals) VanDerWaalsForm(ffx.potential.nonbonded.VanDerWaalsForm) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint) Atom(ffx.potential.bonded.Atom)

Example 8 with VanDerWaalsForm

use of ffx.potential.nonbonded.VanDerWaalsForm 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();
    }
}
Also used : DoubleByReference(com.sun.jna.ptr.DoubleByReference) IntByReference(com.sun.jna.ptr.IntByReference) VanDerWaals(ffx.potential.nonbonded.VanDerWaals) GeneralizedKirkwood(ffx.potential.nonbonded.GeneralizedKirkwood) VanDerWaalsForm(ffx.potential.nonbonded.VanDerWaalsForm) MultipoleType(ffx.potential.parameters.MultipoleType) Atom(ffx.potential.bonded.Atom) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint) VDWType(ffx.potential.parameters.VDWType) NonbondedCutoff(ffx.potential.nonbonded.NonbondedCutoff) PointerByReference(com.sun.jna.ptr.PointerByReference) Bond(ffx.potential.bonded.Bond) OpenMM_AmoebaBondForce_addBond(simtk.openmm.AmoebaOpenMMLibrary.OpenMM_AmoebaBondForce_addBond) RestraintBond(ffx.potential.bonded.RestraintBond) OpenMM_CustomBondForce_addBond(simtk.openmm.OpenMMLibrary.OpenMM_CustomBondForce_addBond) OpenMM_HarmonicBondForce_addBond(simtk.openmm.OpenMMLibrary.OpenMM_HarmonicBondForce_addBond) ParticleMeshEwald(ffx.potential.nonbonded.ParticleMeshEwald) Crystal(ffx.crystal.Crystal)

Aggregations

VanDerWaals (ffx.potential.nonbonded.VanDerWaals)8 VanDerWaalsForm (ffx.potential.nonbonded.VanDerWaalsForm)8 Atom (ffx.potential.bonded.Atom)7 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)7 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)7 VDWType (ffx.potential.parameters.VDWType)6 DoubleByReference (com.sun.jna.ptr.DoubleByReference)3 IntByReference (com.sun.jna.ptr.IntByReference)3 PointerByReference (com.sun.jna.ptr.PointerByReference)3 Crystal (ffx.crystal.Crystal)3 NonbondedCutoff (ffx.potential.nonbonded.NonbondedCutoff)3 GeneralizedKirkwood (ffx.potential.nonbonded.GeneralizedKirkwood)2 MultipoleType (ffx.potential.parameters.MultipoleType)2 Bond (ffx.potential.bonded.Bond)1 RestraintBond (ffx.potential.bonded.RestraintBond)1 ParticleMeshEwald (ffx.potential.nonbonded.ParticleMeshEwald)1 OpenMM_AmoebaBondForce_addBond (simtk.openmm.AmoebaOpenMMLibrary.OpenMM_AmoebaBondForce_addBond)1 OpenMM_CustomBondForce_addBond (simtk.openmm.OpenMMLibrary.OpenMM_CustomBondForce_addBond)1 OpenMM_HarmonicBondForce_addBond (simtk.openmm.OpenMMLibrary.OpenMM_HarmonicBondForce_addBond)1