Search in sources :

Example 1 with RestraintBond

use of ffx.potential.bonded.RestraintBond in project ffx by mjschnie.

the class ForceFieldEnergy method setRestraintBond.

/**
 * <p>
 * setRestraintBond</p>
 *
 * @param a1 a {@link ffx.potential.bonded.Atom} object.
 * @param a2 a {@link ffx.potential.bonded.Atom} object.
 * @param distance a double.
 * @param forceConstant the force constant in kcal/mole.
 * @param flatBottom Radius of a flat-bottom potential in Angstroms.
 */
public void setRestraintBond(Atom a1, Atom a2, double distance, double forceConstant, double flatBottom) {
    restraintBondTerm = true;
    RestraintBond rb = new RestraintBond(a1, a2, crystal);
    int[] classes = { a1.getAtomType().atomClass, a2.getAtomType().atomClass };
    if (flatBottom != 0) {
        rb.setBondType(new BondType(classes, forceConstant, distance, BondType.BondFunction.FLAT_BOTTOM_HARMONIC, flatBottom));
    } else {
        rb.setBondType((new BondType(classes, forceConstant, distance, BondType.BondFunction.HARMONIC)));
    }
    // As long as we continue to add elements one-at-a-time to an array, this code will continue to be ugly.
    RestraintBond[] newRbs = new RestraintBond[++nRestraintBonds];
    if (restraintBonds != null && restraintBonds.length != 0) {
        System.arraycopy(restraintBonds, 0, newRbs, 0, (nRestraintBonds - 1));
    }
    newRbs[nRestraintBonds - 1] = rb;
    restraintBonds = newRbs;
    rb.energy(false);
    rb.log();
}
Also used : BondType(ffx.potential.parameters.BondType) RestraintBond(ffx.potential.bonded.RestraintBond)

Example 2 with RestraintBond

use of ffx.potential.bonded.RestraintBond in project ffx by mjschnie.

the class ForceFieldEnergyOpenMM method addRestraintBonds.

/**
 * Adds restraint bonds, if any.
 */
private void addRestraintBonds() {
    List<RestraintBond> restraintBonds = super.getRestraintBonds();
    if (restraintBonds != null && !restraintBonds.isEmpty()) {
        // OpenMM's HarmonicBondForce class uses k, not 1/2*k as does FFX.
        double kParameterConversion = BondType.units * 2.0 * OpenMM_KJPerKcal / (OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom);
        for (RestraintBond rbond : super.getRestraintBonds()) {
            // Is not a valid substitute for a targeting computer.
            PointerByReference theForce;
            BondType bType = rbond.bondType;
            BondType.BondFunction funct = bType.bondFunction;
            if (restraintForces.containsKey(funct)) {
                theForce = restraintForces.get(funct);
            } else {
                theForce = OpenMM_CustomBondForce_create(funct.toMathematicalForm());
                OpenMM_CustomBondForce_addPerBondParameter(theForce, "k");
                OpenMM_CustomBondForce_addPerBondParameter(theForce, "r0");
                if (funct.hasFlatBottom()) {
                    OpenMM_CustomBondForce_addPerBondParameter(theForce, "fb");
                }
                // Wholly untested code.
                switch(funct) {
                    case QUARTIC:
                    case FLAT_BOTTOM_QUARTIC:
                        OpenMM_CustomBondForce_addGlobalParameter(theForce, "cubic", BondType.cubic / OpenMM_NmPerAngstrom);
                        OpenMM_CustomBondForce_addGlobalParameter(theForce, "quartic", BondType.quartic / (OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom));
                        break;
                    default:
                        break;
                }
                OpenMM_System_addForce(system, theForce);
            }
            double forceConst = bType.forceConstant * kParameterConversion;
            double equilDist = bType.distance * OpenMM_NmPerAngstrom;
            Atom[] ats = rbond.getAtomArray();
            int at1 = ats[0].getXyzIndex() - 1;
            int at2 = ats[1].getXyzIndex() - 1;
            PointerByReference bondParams = OpenMM_DoubleArray_create(0);
            OpenMM_DoubleArray_append(bondParams, forceConst);
            OpenMM_DoubleArray_append(bondParams, equilDist);
            if (funct.hasFlatBottom()) {
                OpenMM_DoubleArray_append(bondParams, bType.flatBottomRadius * OpenMM_NmPerAngstrom);
            }
            OpenMM_CustomBondForce_addBond(theForce, at1, at2, bondParams);
            OpenMM_DoubleArray_destroy(bondParams);
        }
    }
}
Also used : BondType(ffx.potential.parameters.BondType) PointerByReference(com.sun.jna.ptr.PointerByReference) RestraintBond(ffx.potential.bonded.RestraintBond) BondFunction(ffx.potential.parameters.BondType.BondFunction) Atom(ffx.potential.bonded.Atom) OpenMM_System_addConstraint(simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint) CoordRestraint(ffx.potential.nonbonded.CoordRestraint)

Aggregations

RestraintBond (ffx.potential.bonded.RestraintBond)2 BondType (ffx.potential.parameters.BondType)2 PointerByReference (com.sun.jna.ptr.PointerByReference)1 Atom (ffx.potential.bonded.Atom)1 CoordRestraint (ffx.potential.nonbonded.CoordRestraint)1 BondFunction (ffx.potential.parameters.BondType.BondFunction)1 OpenMM_System_addConstraint (simtk.openmm.OpenMMLibrary.OpenMM_System_addConstraint)1