use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class PotentialsFileOpener method run.
/**
* At present, parses the PDB, XYZ, INT, or ARC file from the constructor
* and creates MolecularAssembly and properties objects.
*/
@Override
public void run() {
int numFiles = allFiles.length;
for (int i = 0; i < numFiles; i++) {
File fileI = allFiles[i];
Path pathI = allPaths[i];
MolecularAssembly assembly = new MolecularAssembly(pathI.toString());
assembly.setFile(fileI);
CompositeConfiguration properties = Keyword.loadProperties(fileI);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
String[] patches = properties.getStringArray("patch");
for (String patch : patches) {
logger.info(" Attempting to read force field patch from " + patch + ".");
CompositeConfiguration patchConfiguration = new CompositeConfiguration();
try {
patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath());
} catch (IOException e) {
logger.log(Level.INFO, " Error loading {0}.", patch);
}
patchConfiguration.addProperty("parameters", patch);
forceFieldFilter = new ForceFieldFilter(patchConfiguration);
ForceField patchForceField = forceFieldFilter.parse();
forceField.append(patchForceField);
if (RotamerLibrary.addRotPatch(patch)) {
logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch));
}
}
assembly.setForceField(forceField);
if (new PDBFileFilter().acceptDeep(fileI)) {
filter = new PDBFilter(fileI, assembly, forceField, properties);
} else if (new XYZFileFilter().acceptDeep(fileI)) {
filter = new XYZFilter(fileI, assembly, forceField, properties);
} else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) {
filter = new INTFilter(fileI, assembly, forceField, properties);
} else {
throw new IllegalArgumentException(String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString()));
}
/* If on-open mutations requested, add them to filter. */
if (mutationsToApply != null && !mutationsToApply.isEmpty()) {
if (!(filter instanceof PDBFilter)) {
throw new UnsupportedOperationException("Applying mutations during open only supported by PDB filter atm.");
}
((PDBFilter) filter).mutate(mutationsToApply);
}
if (filter.readFile()) {
if (!(filter instanceof PDBFilter)) {
Utilities.biochemistry(assembly, filter.getAtomList());
}
filter.applyAtomProperties();
assembly.finalize(true, forceField);
// ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
ForceFieldEnergy energy;
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
assembly.setPotential(energy);
assemblies.add(assembly);
propertyList.add(properties);
if (filter instanceof PDBFilter) {
PDBFilter pdbFilter = (PDBFilter) filter;
List<Character> altLocs = pdbFilter.getAltLocs();
if (altLocs.size() > 1 || altLocs.get(0) != ' ') {
StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ ");
for (Character c : altLocs) {
// Do not report the root conformer.
if (c == ' ') {
continue;
}
altLocString.append(format("(%s) ", c));
}
altLocString.append("]\n");
logger.info(altLocString.toString());
}
/**
* Alternate conformers may have different chemistry, so
* they each need to be their own MolecularAssembly.
*/
for (Character c : altLocs) {
if (c.equals(' ') || c.equals('A')) {
continue;
}
MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString());
newAssembly.setForceField(assembly.getForceField());
pdbFilter.setAltID(newAssembly, c);
pdbFilter.clearSegIDs();
if (pdbFilter.readFile()) {
String fileName = assembly.getFile().getAbsolutePath();
newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c);
filter.applyAtomProperties();
newAssembly.finalize(true, assembly.getForceField());
// energy = ForceFieldEnergy.energyFactory(newAssembly, filter.getCoordRestraints());
if (nThreads > 0) {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints(), nThreads);
} else {
energy = ForceFieldEnergy.energyFactory(assembly, filter.getCoordRestraints());
}
newAssembly.setPotential(energy);
assemblies.add(newAssembly);
}
}
}
} else {
logger.warning(String.format(" Failed to read file %s", fileI.toString()));
}
}
activeAssembly = assemblies.get(0);
activeProperties = propertyList.get(0);
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class ForceFieldFilter method main.
/**
* Parse a Force Field parameter file and echo the results with slashes.
*
* @param args an array of {@link java.lang.String} objects.
* @throws java.lang.Exception if any.
*/
public static void main(String[] args) throws Exception {
if (args == null || args.length < 1) {
System.out.println("Usage: ForceFieldFilter <file.prm>");
System.exit(-1);
}
CompositeConfiguration properties = Keyword.loadProperties(null);
properties.setProperty("parameters", args[0]);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
if (forceField != null) {
forceField.print();
}
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class ForceFieldFilterTest method testParse.
/**
* Test of parse method, of class ForceFieldFilter.
*/
@Test
public void testParse() {
CompositeConfiguration properties = Keyword.loadProperties(null);
ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
ForceField forceField = forceFieldFilter.parse();
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class ForceFieldEnergy method energyFactory.
/**
* Static factory method to create a ForceFieldEnergy, possibly via FFX or
* OpenMM implementations.
*
* @param assembly To create FFE over
* @param restraints Harmonic restraints
* @param numThreads Number of threads to use for FFX energy
* @return A ForceFieldEnergy on some Platform
*/
public static ForceFieldEnergy energyFactory(MolecularAssembly assembly, List<CoordRestraint> restraints, int numThreads) {
ForceField ffield = assembly.getForceField();
String platformString = toEnumForm(ffield.getString(ForceFieldString.PLATFORM, "FFX"));
try {
Platform platform = Platform.valueOf(platformString);
switch(platform) {
case OMM:
// Should be split from the code once we figure out how to specify a kernel.
case OMM_REF:
case OMM_CUDA:
try {
ForceFieldEnergyOpenMM openMMEnergy = new ForceFieldEnergyOpenMM(assembly, platform, restraints, numThreads);
return openMMEnergy;
} catch (Exception ex) {
logger.warning(format(" Exception creating ForceFieldEnergyOpenMM: %s", ex));
ex.printStackTrace();
ForceFieldEnergy ffxEnergy = assembly.getPotentialEnergy();
if (ffxEnergy == null) {
ffxEnergy = new ForceFieldEnergy(assembly, restraints, numThreads);
assembly.setPotential(ffxEnergy);
}
return ffxEnergy;
}
case OMM_OPENCL:
case OMM_OPTCPU:
logger.warning(format(" Platform %s not supported; defaulting to FFX", platform));
case FFX:
default:
ForceFieldEnergy ffxEnergy = assembly.getPotentialEnergy();
if (ffxEnergy == null) {
ffxEnergy = new ForceFieldEnergy(assembly, restraints, numThreads);
assembly.setPotential(ffxEnergy);
}
return ffxEnergy;
}
} catch (IllegalArgumentException | NullPointerException ex) {
logger.warning(format(" String %s did not match a known energy implementation", platformString));
ForceFieldEnergy ffxEnergy = assembly.getPotentialEnergy();
if (ffxEnergy == null) {
ffxEnergy = new ForceFieldEnergy(assembly, restraints, numThreads);
assembly.setPotential(ffxEnergy);
}
return ffxEnergy;
}
}
use of ffx.potential.parameters.ForceField in project ffx by mjschnie.
the class ForceFieldEnergyOpenMM method addAmoebaMultipoleForce.
private void addAmoebaMultipoleForce() {
ParticleMeshEwald pme = super.getPmeNode();
if (pme == null) {
return;
}
int[][] axisAtom = pme.getAxisAtoms();
double dipoleConversion = OpenMM_NmPerAngstrom;
double quadrupoleConversion = OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom;
double polarityConversion = OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom * OpenMM_NmPerAngstrom;
double dampingFactorConversion = sqrt(OpenMM_NmPerAngstrom);
amoebaMultipoleForce = OpenMM_AmoebaMultipoleForce_create();
double polarScale = 1.0;
if (pme.getPolarizationType() != Polarization.MUTUAL) {
OpenMM_AmoebaMultipoleForce_setPolarizationType(amoebaMultipoleForce, OpenMM_AmoebaMultipoleForce_Direct);
if (pme.getPolarizationType() == Polarization.NONE) {
polarScale = 0.0;
}
} else {
ForceField forceField = molecularAssembly.getForceField();
String algorithm = forceField.getString(ForceField.ForceFieldString.SCF_ALGORITHM, "CG");
ParticleMeshEwald.SCFAlgorithm scfAlgorithm;
try {
algorithm = algorithm.replaceAll("-", "_").toUpperCase();
scfAlgorithm = ParticleMeshEwald.SCFAlgorithm.valueOf(algorithm);
} catch (Exception e) {
scfAlgorithm = ParticleMeshEwald.SCFAlgorithm.CG;
}
switch(scfAlgorithm) {
case EPT:
logger.info(" Using extrapolated perturbation theory approximation instead of full SCF calculations. Not supported in FFX reference implementation.");
OpenMM_AmoebaMultipoleForce_setPolarizationType(amoebaMultipoleForce, OpenMM_AmoebaMultipoleForce_Extrapolated);
PointerByReference exptCoefficients = OpenMM_DoubleArray_create(4);
OpenMM_DoubleArray_set(exptCoefficients, 0, -0.154);
OpenMM_DoubleArray_set(exptCoefficients, 1, 0.017);
OpenMM_DoubleArray_set(exptCoefficients, 2, 0.657);
OpenMM_DoubleArray_set(exptCoefficients, 3, 0.475);
OpenMM_AmoebaMultipoleForce_setExtrapolationCoefficients(amoebaMultipoleForce, exptCoefficients);
OpenMM_DoubleArray_destroy(exptCoefficients);
break;
case CG:
case SOR:
default:
OpenMM_AmoebaMultipoleForce_setPolarizationType(amoebaMultipoleForce, OpenMM_AmoebaMultipoleForce_Mutual);
break;
}
}
PointerByReference dipoles = OpenMM_DoubleArray_create(3);
PointerByReference quadrupoles = OpenMM_DoubleArray_create(9);
Atom[] atoms = molecularAssembly.getAtomArray();
int nAtoms = atoms.length;
for (int i = 0; i < nAtoms; i++) {
Atom atom = atoms[i];
MultipoleType multipoleType = atom.getMultipoleType();
PolarizeType polarType = atom.getPolarizeType();
/**
* Define the frame definition.
*/
int axisType = OpenMM_AmoebaMultipoleForce_NoAxisType;
switch(multipoleType.frameDefinition) {
case ZONLY:
axisType = OpenMM_AmoebaMultipoleForce_ZOnly;
break;
case ZTHENX:
axisType = OpenMM_AmoebaMultipoleForce_ZThenX;
break;
case BISECTOR:
axisType = OpenMM_AmoebaMultipoleForce_Bisector;
break;
case ZTHENBISECTOR:
axisType = OpenMM_AmoebaMultipoleForce_ZBisect;
break;
case TRISECTOR:
axisType = OpenMM_AmoebaMultipoleForce_ThreeFold;
break;
default:
break;
}
double useFactor = 1.0;
if (!atoms[i].getUse() || !atoms[i].getElectrostatics()) {
// if (!atoms[i].getUse()) {
useFactor = 0.0;
}
// Should be 1.0 at this point.
double lambdaScale = lambda;
if (!atom.applyLambda()) {
lambdaScale = 1.0;
}
useFactor *= lambdaScale;
/**
* Load local multipole coefficients.
*/
for (int j = 0; j < 3; j++) {
OpenMM_DoubleArray_set(dipoles, j, multipoleType.dipole[j] * dipoleConversion * useFactor);
}
int l = 0;
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
OpenMM_DoubleArray_set(quadrupoles, l++, multipoleType.quadrupole[j][k] * quadrupoleConversion * useFactor / 3.0);
}
}
// int zaxis = 0;
int zaxis = 1;
// int xaxis = 0;
int xaxis = 1;
// int yaxis = 0;
int yaxis = 1;
int[] refAtoms = axisAtom[i];
if (refAtoms != null) {
zaxis = refAtoms[0];
if (refAtoms.length > 1) {
xaxis = refAtoms[1];
if (refAtoms.length > 2) {
yaxis = refAtoms[2];
}
}
} else {
axisType = OpenMM_AmoebaMultipoleForce_NoAxisType;
logger.info(String.format(" Atom type %s", atom.getAtomType().toString()));
}
double charge = multipoleType.charge * useFactor;
/**
* Add the multipole.
*/
OpenMM_AmoebaMultipoleForce_addMultipole(amoebaMultipoleForce, charge, dipoles, quadrupoles, axisType, zaxis, xaxis, yaxis, polarType.thole, polarType.pdamp * dampingFactorConversion, polarType.polarizability * polarityConversion * polarScale);
}
OpenMM_DoubleArray_destroy(dipoles);
OpenMM_DoubleArray_destroy(quadrupoles);
Crystal crystal = super.getCrystal();
if (!crystal.aperiodic()) {
OpenMM_AmoebaMultipoleForce_setNonbondedMethod(amoebaMultipoleForce, OpenMM_AmoebaMultipoleForce_PME);
OpenMM_AmoebaMultipoleForce_setCutoffDistance(amoebaMultipoleForce, pme.getEwaldCutoff() * OpenMM_NmPerAngstrom);
OpenMM_AmoebaMultipoleForce_setAEwald(amoebaMultipoleForce, pme.getEwaldCoefficient() / OpenMM_NmPerAngstrom);
double ewaldTolerance = 1.0e-04;
OpenMM_AmoebaMultipoleForce_setEwaldErrorTolerance(amoebaMultipoleForce, ewaldTolerance);
PointerByReference gridDimensions = OpenMM_IntArray_create(3);
ReciprocalSpace recip = pme.getReciprocalSpace();
OpenMM_IntArray_set(gridDimensions, 0, recip.getXDim());
OpenMM_IntArray_set(gridDimensions, 1, recip.getYDim());
OpenMM_IntArray_set(gridDimensions, 2, recip.getZDim());
OpenMM_AmoebaMultipoleForce_setPmeGridDimensions(amoebaMultipoleForce, gridDimensions);
OpenMM_IntArray_destroy(gridDimensions);
} else {
OpenMM_AmoebaMultipoleForce_setNonbondedMethod(amoebaMultipoleForce, OpenMM_AmoebaMultipoleForce_NoCutoff);
}
OpenMM_AmoebaMultipoleForce_setMutualInducedMaxIterations(amoebaMultipoleForce, 500);
OpenMM_AmoebaMultipoleForce_setMutualInducedTargetEpsilon(amoebaMultipoleForce, pme.getPolarEps());
int[][] ip11 = pme.getPolarization11();
int[][] ip12 = pme.getPolarization12();
int[][] ip13 = pme.getPolarization13();
ArrayList<Integer> list12 = new ArrayList<>();
ArrayList<Integer> list13 = new ArrayList<>();
ArrayList<Integer> list14 = new ArrayList<>();
PointerByReference covalentMap = OpenMM_IntArray_create(0);
for (int i = 0; i < nAtoms; i++) {
Atom ai = atoms[i];
list12.clear();
list13.clear();
list14.clear();
for (Bond bond : ai.getBonds()) {
int index = bond.get1_2(ai).getIndex() - 1;
OpenMM_IntArray_append(covalentMap, index);
list12.add(index);
}
OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i, OpenMM_AmoebaMultipoleForce_Covalent12, covalentMap);
OpenMM_IntArray_resize(covalentMap, 0);
for (Angle angle : ai.getAngles()) {
Atom ak = angle.get1_3(ai);
if (ak != null) {
int index = ak.getIndex() - 1;
if (!list12.contains(index)) {
list13.add(index);
OpenMM_IntArray_append(covalentMap, index);
}
}
}
OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i, OpenMM_AmoebaMultipoleForce_Covalent13, covalentMap);
OpenMM_IntArray_resize(covalentMap, 0);
for (Torsion torsion : ai.getTorsions()) {
Atom ak = torsion.get1_4(ai);
if (ak != null) {
int index = ak.getIndex() - 1;
if (!list12.contains(index) && !list13.contains(index)) {
list14.add(index);
OpenMM_IntArray_append(covalentMap, index);
}
}
}
OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i, OpenMM_AmoebaMultipoleForce_Covalent14, covalentMap);
OpenMM_IntArray_resize(covalentMap, 0);
for (Atom ak : ai.get1_5s()) {
int index = ak.getIndex() - 1;
if (!list12.contains(index) && !list13.contains(index) && !list14.contains(index)) {
OpenMM_IntArray_append(covalentMap, index);
}
}
OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i, OpenMM_AmoebaMultipoleForce_Covalent15, covalentMap);
OpenMM_IntArray_resize(covalentMap, 0);
for (int j = 0; j < ip11[i].length; j++) {
OpenMM_IntArray_append(covalentMap, ip11[i][j]);
}
OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i, OpenMM_AmoebaMultipoleForce_PolarizationCovalent11, covalentMap);
OpenMM_IntArray_resize(covalentMap, 0);
// for (int j = 0; j < ip12[i].length; j++) {
// OpenMM_IntArray_append(covalentMap, ip12[i][j]);
// }
// OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i,
// OpenMM_AmoebaMultipoleForce_PolarizationCovalent12, covalentMap);
// OpenMM_IntArray_resize(covalentMap, 0);
//
// for (int j = 0; j < ip13[i].length; j++) {
// OpenMM_IntArray_append(covalentMap, ip13[i][j]);
// }
// OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i,
// OpenMM_AmoebaMultipoleForce_PolarizationCovalent13, covalentMap);
// OpenMM_IntArray_resize(covalentMap, 0);
//
// OpenMM_AmoebaMultipoleForce_setCovalentMap(amoebaMultipoleForce, i,
// OpenMM_AmoebaMultipoleForce_PolarizationCovalent14, covalentMap);
}
OpenMM_IntArray_destroy(covalentMap);
OpenMM_System_addForce(system, amoebaMultipoleForce);
OpenMM_Force_setForceGroup(amoebaMultipoleForce, 1);
logger.log(Level.INFO, " Added polarizable multipole force.");
GeneralizedKirkwood gk = super.getGK();
if (gk != null) {
addGKForce();
}
}
Aggregations