use of ffx.potential.parameters.ImproperTorsionType in project ffx by mjschnie.
the class ImproperTorsion method improperTorsionFactory.
/**
* ImproperTorsion factory method.
*
* @param atom Create the improper torsion around this atom.
* @param forceField retrieve parameters from this ForceField.
* @return the ImproperTorsion if created, or null otherwise.
*/
public static ArrayList<ImproperTorsion> improperTorsionFactory(Atom atom, ForceField forceField) {
if (atom == null) {
return null;
}
Atom[] atoms = new Atom[4];
atoms[2] = atom;
ArrayList<Bond> bonds = atom.getBonds();
if (bonds == null || bonds.size() != 3) {
return null;
}
for (int i = 0; i < 3; i++) {
Bond bond = bonds.get(i);
Atom atom2 = bond.get1_2(atom);
if (i == 2) {
atoms[3] = atom2;
} else {
atoms[i] = atom2;
}
}
ArrayList<ImproperTorsion> improperTorsions = new ArrayList<>();
Collection<ImproperTorsionType> types = forceField.getImproperTypes();
double units = forceField.getDouble(ForceField.ForceFieldDouble.IMPTORUNIT, 0.5);
for (ImproperTorsionType type : types) {
int[] classes = new int[4];
classes[0] = atoms[0].getAtomType().atomClass;
classes[1] = atoms[1].getAtomType().atomClass;
classes[2] = atoms[2].getAtomType().atomClass;
classes[3] = atoms[3].getAtomType().atomClass;
boolean assigned = type.assigned(classes);
if (assigned) {
// Finalize atom ordering.
if (classes[3] == atoms[3].getAtomType().atomClass || type.atomClasses[3] == 0) {
// do nothing.
} else if (classes[3] == atoms[1].getAtomType().atomClass) {
Atom temp = atoms[3];
atoms[3] = atoms[1];
atoms[1] = temp;
} else {
Atom temp = atoms[0];
atoms[0] = atoms[3];
atoms[3] = temp;
}
if (classes[1] == atoms[1].getAtomType().atomClass || type.atomClasses[1] == 0) {
// do nothing.
} else if (classes[1] == atoms[0].getAtomType().atomClass) {
Atom temp = atoms[1];
atoms[1] = atoms[0];
atoms[0] = temp;
}
ImproperTorsion improperTorsion = new ImproperTorsion(atoms[0], atoms[1], atoms[2], atoms[3]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsions.add(improperTorsion);
int c0 = type.atomClasses[0];
int c1 = type.atomClasses[1];
int c3 = type.atomClasses[3];
if (c0 == c1 && c1 == c3) {
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsion = new ImproperTorsion(atoms[0], atoms[3], atoms[2], atoms[1]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsions.add(improperTorsion);
improperTorsion = new ImproperTorsion(atoms[1], atoms[0], atoms[2], atoms[3]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsions.add(improperTorsion);
improperTorsion = new ImproperTorsion(atoms[1], atoms[3], atoms[2], atoms[0]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsions.add(improperTorsion);
improperTorsion = new ImproperTorsion(atoms[3], atoms[0], atoms[2], atoms[1]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsions.add(improperTorsion);
improperTorsion = new ImproperTorsion(atoms[3], atoms[1], atoms[2], atoms[0]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 1.0 / 6.0;
improperTorsions.add(improperTorsion);
} else if (c0 == c1) {
improperTorsion.scaleFactor = 0.5;
improperTorsion = new ImproperTorsion(atoms[1], atoms[0], atoms[2], atoms[3]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 0.5;
improperTorsions.add(improperTorsion);
} else if (c0 == c3) {
improperTorsion.scaleFactor = 0.5;
improperTorsion = new ImproperTorsion(atoms[3], atoms[1], atoms[2], atoms[0]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 0.5;
improperTorsions.add(improperTorsion);
} else if (c1 == c3) {
improperTorsion.scaleFactor = 0.5;
improperTorsion = new ImproperTorsion(atoms[0], atoms[3], atoms[2], atoms[1]);
improperTorsion.setImproperType(type);
improperTorsion.units = units;
improperTorsion.scaleFactor = 0.5;
improperTorsions.add(improperTorsion);
}
}
}
if (improperTorsions.isEmpty()) {
return null;
}
return improperTorsions;
}
use of ffx.potential.parameters.ImproperTorsionType in project ffx by mjschnie.
the class ForceFieldFilter method parseImproper.
private void parseImproper(String input, String[] tokens) {
if (tokens.length < 8) {
logger.log(Level.WARNING, "Invalid IMPTORS type:\n{0}", input);
return;
}
try {
int[] atomClasses = new int[4];
atomClasses[0] = Integer.parseInt(tokens[1]);
atomClasses[1] = Integer.parseInt(tokens[2]);
atomClasses[2] = Integer.parseInt(tokens[3]);
atomClasses[3] = Integer.parseInt(tokens[4]);
double k = Double.parseDouble(tokens[5]);
double phase = Double.parseDouble(tokens[6]);
int period = Integer.parseInt(tokens[7]);
if (improperTorsionScale > 0.0) {
k = k * improperTorsionScale;
}
ImproperTorsionType improperType = new ImproperTorsionType(atomClasses, k, phase, period);
forceField.addForceFieldType(improperType);
} catch (NumberFormatException e) {
String message = "Exception parsing IMPTORS type:\n" + input + "\n";
logger.log(Level.SEVERE, message, e);
}
}
use of ffx.potential.parameters.ImproperTorsionType in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method addImproperTorsionForce.
private void addImproperTorsionForce() {
ImproperTorsion[] impropers = super.getImproperTorsions();
if (impropers == null || impropers.length < 1) {
return;
}
int nImpropers = impropers.length;
amoebaImproperTorsionForce = OpenMM_PeriodicTorsionForce_create();
for (int i = 0; i < nImpropers; i++) {
ImproperTorsion improperTorsion = impropers[i];
int a1 = improperTorsion.getAtom(0).getXyzIndex() - 1;
int a2 = improperTorsion.getAtom(1).getXyzIndex() - 1;
int a3 = improperTorsion.getAtom(2).getXyzIndex() - 1;
int a4 = improperTorsion.getAtom(3).getXyzIndex() - 1;
ImproperTorsionType improperTorsionType = improperTorsion.improperType;
OpenMM_PeriodicTorsionForce_addTorsion(amoebaImproperTorsionForce, a1, a2, a3, a4, improperTorsionType.periodicity, improperTorsionType.phase * OpenMM_RadiansPerDegree, OpenMM_KJPerKcal * improperTorsion.units * improperTorsion.scaleFactor * improperTorsionType.k);
}
OpenMM_System_addForce(system, amoebaImproperTorsionForce);
logger.log(Level.INFO, " Added improper torsions ({0})", nImpropers);
}
Aggregations