use of ffx.potential.parameters.TorsionTorsionType in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method addTorsionTorsionForce.
private void addTorsionTorsionForce() {
TorsionTorsion[] torsionTorsions = super.getTorsionTorsions();
if (torsionTorsions == null || torsionTorsions.length < 1) {
return;
}
/**
* Load the torsion-torsions.
*/
int nTypes = 0;
LinkedHashMap<String, TorsionTorsionType> torTorTypes = new LinkedHashMap<>();
int nTorsionTorsions = torsionTorsions.length;
amoebaTorsionTorsionForce = OpenMM_AmoebaTorsionTorsionForce_create();
for (int i = 0; i < nTorsionTorsions; i++) {
TorsionTorsion torsionTorsion = torsionTorsions[i];
int ia = torsionTorsion.getAtom(0).getXyzIndex() - 1;
int ib = torsionTorsion.getAtom(1).getXyzIndex() - 1;
int ic = torsionTorsion.getAtom(2).getXyzIndex() - 1;
int id = torsionTorsion.getAtom(3).getXyzIndex() - 1;
int ie = torsionTorsion.getAtom(4).getXyzIndex() - 1;
TorsionTorsionType torsionTorsionType = torsionTorsion.torsionTorsionType;
String key = torsionTorsionType.getKey();
/**
* Check if the TorTor parameters have already been added to the
* Hash.
*/
int gridIndex = 0;
if (torTorTypes.containsKey(key)) {
/**
* If the TorTor has been added, get its (ordered) index in the
* Hash.
*/
int index = 0;
for (String entry : torTorTypes.keySet()) {
if (entry.equalsIgnoreCase(key)) {
gridIndex = index;
break;
} else {
index++;
}
}
} else {
/**
* Add the new TorTor.
*/
torTorTypes.put(key, torsionTorsionType);
gridIndex = nTypes;
nTypes++;
}
Atom atom = torsionTorsion.getChiralAtom();
int iChiral = -1;
if (atom != null) {
iChiral = atom.getXyzIndex() - 1;
}
OpenMM_AmoebaTorsionTorsionForce_addTorsionTorsion(amoebaTorsionTorsionForce, ia, ib, ic, id, ie, iChiral, gridIndex);
}
/**
* Load the Torsion-Torsion parameters.
*/
PointerByReference values = OpenMM_DoubleArray_create(6);
int gridIndex = 0;
for (String key : torTorTypes.keySet()) {
TorsionTorsionType torTorType = torTorTypes.get(key);
int nx = torTorType.nx;
int ny = torTorType.ny;
double[] tx = torTorType.tx;
double[] ty = torTorType.ty;
double[] f = torTorType.energy;
double[] dx = torTorType.dx;
double[] dy = torTorType.dy;
double[] dxy = torTorType.dxy;
/**
* Create the 3D grid.
*/
PointerByReference grid3D = OpenMM_3D_DoubleArray_create(nx, ny, 6);
int xIndex = 0;
int yIndex = 0;
for (int j = 0; j < nx * ny; j++) {
int addIndex = 0;
OpenMM_DoubleArray_set(values, addIndex++, tx[xIndex]);
OpenMM_DoubleArray_set(values, addIndex++, ty[yIndex]);
OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * f[j]);
OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dx[j]);
OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dy[j]);
OpenMM_DoubleArray_set(values, addIndex++, OpenMM_KJPerKcal * dxy[j]);
OpenMM_3D_DoubleArray_set(grid3D, yIndex, xIndex, values);
xIndex++;
if (xIndex == nx) {
xIndex = 0;
yIndex++;
}
}
OpenMM_AmoebaTorsionTorsionForce_setTorsionTorsionGrid(amoebaTorsionTorsionForce, gridIndex++, grid3D);
OpenMM_3D_DoubleArray_destroy(grid3D);
}
OpenMM_DoubleArray_destroy(values);
OpenMM_System_addForce(system, amoebaTorsionTorsionForce);
logger.log(Level.INFO, " Added Torsion-Torsions ({0})", nTorsionTorsions);
}
use of ffx.potential.parameters.TorsionTorsionType in project ffx by mjschnie.
the class ForceFieldFilter method parseTorsionTorsion.
private void parseTorsionTorsion(String input, String[] tokens, BufferedReader br) {
if (tokens.length < 8) {
logger.log(Level.WARNING, "Invalid TORTORS type:\n{0}", input);
return;
}
try {
int[] atomClasses = new int[5];
for (int i = 0; i < 5; i++) {
atomClasses[i] = Integer.parseInt(tokens[i + 1]);
}
int[] gridPoints = new int[2];
gridPoints[0] = Integer.parseInt(tokens[6]);
gridPoints[1] = Integer.parseInt(tokens[7]);
int points = gridPoints[0] * gridPoints[1];
double[] torsion1 = new double[points];
double[] torsion2 = new double[points];
double[] energy = new double[points];
for (int i = 0; i < points; i++) {
input = br.readLine();
tokens = input.trim().split(" +");
if (tokens.length != 3) {
logger.log(Level.WARNING, "Invalid TORTORS type:\n{0}", input);
return;
}
torsion1[i] = Double.parseDouble(tokens[0]);
torsion2[i] = Double.parseDouble(tokens[1]);
energy[i] = Double.parseDouble(tokens[2]);
}
TorsionTorsionType torsionTorsionType = new TorsionTorsionType(atomClasses, gridPoints, torsion1, torsion2, energy);
forceField.addForceFieldType(torsionTorsionType);
} catch (NumberFormatException | IOException e) {
String message = "Exception parsing TORTORS type:\n" + input + "\n";
logger.log(Level.SEVERE, message, e);
}
}
use of ffx.potential.parameters.TorsionTorsionType in project ffx by mjschnie.
the class TorsionTorsion method torsionTorsionFactory.
/**
* @param firstBond the first Bond.
* @param angle the Angle.
* @param lastBond the last Bond.
* @param forceField the ForceField parameters to apply.
* @return the new TorsionTorsion, or null.
*/
public static TorsionTorsion torsionTorsionFactory(Bond firstBond, Angle angle, Bond lastBond, ForceField forceField) {
int[] c5 = new int[5];
Atom atom1 = angle.atoms[0];
Atom atom3 = angle.atoms[2];
c5[0] = firstBond.get1_2(atom1).getAtomType().atomClass;
c5[1] = atom1.getAtomType().atomClass;
c5[2] = angle.atoms[1].getAtomType().atomClass;
c5[3] = atom3.getAtomType().atomClass;
c5[4] = lastBond.get1_2(atom3).getAtomType().atomClass;
String key = TorsionTorsionType.sortKey(c5);
boolean reversed = false;
TorsionTorsionType torsionTorsionType = forceField.getTorsionTorsionType(key);
if (torsionTorsionType == null) {
key = TorsionTorsionType.reverseKey(c5);
torsionTorsionType = forceField.getTorsionTorsionType(key);
reversed = true;
}
if (torsionTorsionType == null) {
return null;
}
TorsionTorsion torsionTorsion = new TorsionTorsion(firstBond, angle, lastBond, reversed);
torsionTorsion.torsionTorsionType = torsionTorsionType;
return torsionTorsion;
}
use of ffx.potential.parameters.TorsionTorsionType in project ffx by mjschnie.
the class ForceFieldFilter method parseTorsionTorsion.
private void parseTorsionTorsion(String input, String[] tokens) {
if (tokens.length < 8) {
logger.log(Level.WARNING, "Invalid TORTORS type:\n{0}", input);
return;
}
try {
int[] atomClasses = new int[5];
for (int i = 0; i < 5; i++) {
atomClasses[i] = Integer.parseInt(tokens[i + 1]);
}
int[] gridPoints = new int[2];
gridPoints[0] = new Integer(tokens[6]);
gridPoints[1] = new Integer(tokens[7]);
int points = gridPoints[0] * gridPoints[1];
int numTokens = points * 3 + 8;
if (tokens.length < numTokens) {
logger.log(Level.WARNING, "Invalid TORTORS type:\n{0}", input);
return;
}
double[] torsion1 = new double[points];
double[] torsion2 = new double[points];
double[] energy = new double[points];
int index = 8;
for (int i = 0; i < points; i++) {
torsion1[i] = new Double(tokens[index++]);
torsion2[i] = new Double(tokens[index++]);
energy[i] = new Double(tokens[index++]);
}
TorsionTorsionType torsionTorsionType = new TorsionTorsionType(atomClasses, gridPoints, torsion1, torsion2, energy);
forceField.addForceFieldType(torsionTorsionType);
} catch (NumberFormatException e) {
String message = "Exception parsing TORTORS type:\n" + input + "\n";
logger.log(Level.SEVERE, message, e);
}
}
Aggregations