use of ffx.potential.parameters.BondType in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method setUpHydrogenConstraints.
public void setUpHydrogenConstraints(PointerByReference system) {
int i;
int iAtom1;
int iAtom2;
// Atom[] atoms = molecularAssembly.getAtomArray();
Bond[] bonds = super.getBonds();
logger.info(String.format(" Setting up Hydrogen constraints"));
if (bonds == null || bonds.length < 1) {
return;
}
int nBonds = bonds.length;
Atom atom1;
Atom atom2;
Atom parentAtom;
Bond bondForBondLength;
BondType bondType;
for (i = 0; i < nBonds; i++) {
Bond bond = bonds[i];
atom1 = bond.getAtom(0);
atom2 = bond.getAtom(1);
if (atom1.isHydrogen()) {
parentAtom = atom1.getBonds().get(0).get1_2(atom1);
bondForBondLength = atom1.getBonds().get(0);
bondType = bondForBondLength.bondType;
iAtom1 = atom1.getXyzIndex() - 1;
iAtom2 = parentAtom.getXyzIndex() - 1;
OpenMM_System_addConstraint(system, iAtom1, iAtom2, bondForBondLength.bondType.distance * OpenMM_NmPerAngstrom);
} else if (atom2.isHydrogen()) {
parentAtom = atom2.getBonds().get(0).get1_2(atom2);
bondForBondLength = atom2.getBonds().get(0);
bondType = bondForBondLength.bondType;
iAtom1 = atom2.getXyzIndex() - 1;
iAtom2 = parentAtom.getXyzIndex() - 1;
OpenMM_System_addConstraint(system, iAtom1, iAtom2, bondForBondLength.bondType.distance * OpenMM_NmPerAngstrom);
}
}
}
use of ffx.potential.parameters.BondType in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method addBondForce.
private void addBondForce() {
Bond[] bonds = super.getBonds();
if (bonds == null || bonds.length < 1) {
return;
}
int nBonds = bonds.length;
amoebaBondForce = OpenMM_AmoebaBondForce_create();
double kParameterConversion = OpenMM_KJPerKcal / (OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom);
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;
BondType bondType = bond.bondType;
OpenMM_AmoebaBondForce_addBond(amoebaBondForce, i1, i2, bond.bondType.distance * OpenMM_NmPerAngstrom, kParameterConversion * bondType.forceConstant * BondType.units);
}
if (bonds[0].bondType.bondFunction == BondFunction.QUARTIC) {
OpenMM_AmoebaBondForce_setAmoebaGlobalBondCubic(amoebaBondForce, BondType.cubic / OpenMM_NmPerAngstrom);
OpenMM_AmoebaBondForce_setAmoebaGlobalBondQuartic(amoebaBondForce, BondType.quartic / (OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom));
}
OpenMM_System_addForce(system, amoebaBondForce);
logger.log(Level.INFO, " Added bonds ({0})", nBonds);
}
use of ffx.potential.parameters.BondType in project ffx by mjschnie.
the class BondedUtils method buildBond.
public static Bond buildBond(Atom a1, Atom a2, ForceField forceField, ArrayList<Bond> bondList) {
Bond bond = new Bond(a1, a2);
int[] c = new int[2];
c[0] = a1.getAtomType().atomClass;
c[1] = a2.getAtomType().atomClass;
String key = BondType.sortKey(c);
BondType bondType = forceField.getBondType(key);
if (bondType == null) {
logger.severe(format("No BondType for key: %s\n %s\n %s\n %s\n %s", key, a1.toString(), a1.getAtomType().toString(), a2.toString(), a2.getAtomType().toString()));
} else {
bond.setBondType(bondType);
}
if (bondList != null) {
bondList.add(bond);
}
return bond;
}
use of ffx.potential.parameters.BondType in project ffx by mjschnie.
the class MultiTerminus method updateBondedTerms.
private void updateBondedTerms() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("Updating bonded terms: \n"));
List<ROLS> bonds = getBondList();
for (int i = 0; i < bonds.size(); i++) {
Bond bond = (Bond) bonds.get(i);
BondType oldType = bond.bondType;
int[] c = new int[2];
c[0] = bond.atoms[0].getAtomType().atomClass;
c[1] = bond.atoms[1].getAtomType().atomClass;
String key = BondType.sortKey(c);
BondType newType = forceField.getBondType(key);
if (oldType != newType) {
sb.append(String.format(" Bond: %s --> %s \n", bond.bondType, newType));
bond.setBondType(newType);
if (newType.distance < 0.9 * oldType.distance || newType.distance > 1.1 * oldType.distance) {
logger.info(String.format(" Large bond distance change: %s %s, %.2f --> %.2f ", bond.atoms[0].describe(Atom.Descriptions.XyzIndex_Name), bond.atoms[1].describe(Atom.Descriptions.XyzIndex_Name), oldType.distance, newType.distance));
}
}
}
List<ROLS> angles = getAngleList();
for (int i = 0; i < angles.size(); i++) {
Angle angle = (Angle) angles.get(i);
AngleType oldType = angle.angleType;
if (DEBUG) {
logger.info(String.format(" %d ( %s %s %s ) ( %d %d %d )", i, angle.atoms[0].describe(Atom.Descriptions.XyzIndex_Name), angle.atoms[1].describe(Atom.Descriptions.XyzIndex_Name), angle.atoms[2].describe(Atom.Descriptions.XyzIndex_Name), angle.atoms[0].getAtomType().atomClass, angle.atoms[1].getAtomType().atomClass, angle.atoms[2].getAtomType().atomClass));
}
Angle dummy = Angle.angleFactory(angle.bonds[0], angle.bonds[1], forceField);
AngleType newType = dummy.angleType;
if (oldType != newType) {
sb.append(String.format(" Angle: %s --> %s \n", angle.angleType, dummy.angleType));
angle.setAngleType(dummy.angleType);
if (newType.angle[0] < 0.9 * oldType.angle[0] || newType.angle[0] > 1.1 * oldType.angle[0]) {
logger.info(String.format(" Large angle change: %s %s %s, %.2f --> %.2f ", angle.atoms[0].describe(Atom.Descriptions.XyzIndex_Name), angle.atoms[1].describe(Atom.Descriptions.XyzIndex_Name), angle.atoms[2].describe(Atom.Descriptions.XyzIndex_Name), oldType.angle[0], newType.angle[0]));
}
}
}
List<ROLS> torsions = getTorsionList();
for (int i = 0; i < torsions.size(); i++) {
Torsion tors = (Torsion) torsions.get(i);
TorsionType oldType = tors.torsionType;
Torsion dummy = Torsion.torsionFactory(tors.bonds[0], tors.bonds[1], tors.bonds[2], forceField);
TorsionType newType = dummy.torsionType;
if (oldType != newType) {
sb.append(String.format(" Torsion: %s --> %s \n", tors.torsionType, dummy.torsionType));
tors.torsionType = dummy.torsionType;
}
}
if (DEBUG) {
logger.info(sb.toString());
}
}
use of ffx.potential.parameters.BondType 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();
}
Aggregations