use of ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig in project ffx by mjschnie.
the class ExtendedVariableTest method setDebugParameters.
// Setup control of PME lambda derivative calculation.
private ExtendedSystemConfig setDebugParameters() {
// symmetry operators
setProp("esv.allowSymOps", true);
// reciprocal space contributions to field
setProp("esv.recipFieldEffects", true);
setProp("sys.reuseTensors", false);
// polarizability scaling and associated derivative term
setProp("esv.scaleAlpha", true);
setProp("polarization", Polarization.MUTUAL);
setProp("scf-algorithm", SCFAlgorithm.CG);
setProp("use-charges", yes);
setProp("use-dipoles", yes);
setProp("use-quadrupoles", yes);
ExtendedSystemConfig esvConfig = new ExtendedSystemConfig();
switch(interactions) {
default:
case All:
esvConfig.setPermanentWhitelist(null);
esvConfig.setInducedWhitelist(null);
esvConfig.useWhitelists = false;
break;
case OnePermOneInd:
esvConfig.setPermanentWhitelist(new int[] { lys2_nz });
esvConfig.setInducedWhitelist(new int[] { ala3_c });
esvConfig.useWhitelists = true;
break;
case TwoPermOneInd:
esvConfig.setPermanentWhitelist(new int[] { lys2_nz, lys4_nz });
esvConfig.setInducedWhitelist(new int[] { ala3_c });
esvConfig.useWhitelists = true;
break;
case OnePermTwoInd:
esvConfig.setPermanentWhitelist(new int[] { lys2_nz });
esvConfig.setInducedWhitelist(new int[] { ala3_c, lys4_nz });
esvConfig.useWhitelists = true;
break;
case OnePermAllInd:
esvConfig.setPermanentWhitelist(new int[] { lys2_nz });
esvConfig.setInducedWhitelist(allAtoms);
esvConfig.useWhitelists = true;
break;
case AllPermOneInd:
esvConfig.setPermanentWhitelist(allAtoms);
esvConfig.setInducedWhitelist(new int[] { ala3_c });
esvConfig.useWhitelists = true;
break;
}
return esvConfig;
}
use of ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig in project ffx by mjschnie.
the class ExtendedVariableTest method testSmoothness.
/**
* Numerically ensure that the energy and lambda derivatives are smooth all
* along both ESV coordinates in the dilysine system.
*/
public void testSmoothness() {
ExtendedSystemConfig esvConfig = activateAll();
MolecularAssembly mola = setupWithExtended(esvFilename, true, esvConfig);
ForceFieldEnergy ffe = mola.getPotentialEnergy();
ExtendedSystem esvSystem = ffe.getExtendedSystem();
if (resultsOnly) {
utils.setSilentPotential(true);
}
double[][] totalEnergies, totalDerivsA, totalDerivsB;
double[][] vdwEnergies, vdwDerivsA, vdwDerivsB;
double[][] permanentEnergies, permanentDerivsA, permanentDerivsB;
double[][] inducedEnergies, inducedDerivsA, inducedDerivsB;
totalEnergies = new double[11][11];
totalDerivsA = new double[11][11];
totalDerivsB = new double[11][11];
if (smoothnessDecomposition) {
vdwEnergies = new double[11][11];
vdwDerivsA = new double[11][11];
vdwDerivsB = new double[11][11];
permanentEnergies = new double[11][11];
permanentDerivsA = new double[11][11];
permanentDerivsB = new double[11][11];
inducedEnergies = new double[11][11];
inducedDerivsA = new double[11][11];
inducedDerivsB = new double[11][11];
}
for (int idxA = 0; idxA <= 10; idxA++) {
double evA = idxA / 10.0;
for (int idxB = 0; idxB <= 10; idxB++) {
final double evB = idxB / 10.0;
esvSystem.setLambda(0, evA);
esvSystem.setLambda(1, evB);
final double totalEnergy = ffe.energy(true, false);
totalEnergies[idxA][idxB] = ffe.getEnergyComponent(PotentialComponent.ForceFieldEnergy);
totalDerivsA[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.ForceFieldEnergy, 0);
totalDerivsB[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.ForceFieldEnergy, 1);
if (smoothnessDecomposition) {
vdwEnergies[idxA][idxB] = ffe.getEnergyComponent(PotentialComponent.VanDerWaals);
vdwDerivsA[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.VanDerWaals, 0);
vdwDerivsB[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.VanDerWaals, 1);
permanentEnergies[idxA][idxB] = ffe.getEnergyComponent(PotentialComponent.Permanent);
permanentDerivsA[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.Permanent, 0);
permanentDerivsB[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.Permanent, 1);
inducedEnergies[idxA][idxB] = ffe.getEnergyComponent(PotentialComponent.Induced);
inducedDerivsA[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.Induced, 0);
inducedDerivsB[idxA][idxB] = esvSystem.getDerivativeComponent(PotentialComponent.Induced, 1);
}
}
}
/* TODO: improve upon the following arbitrary definition of approximate smoothness. */
final int testRow = 2;
final double min = Arrays.stream(totalEnergies[testRow]).min().getAsDouble();
final double max = Arrays.stream(totalEnergies[testRow]).max().getAsDouble();
final double maxChange = (max - min) * 0.5;
final int maxDirectionSignChanges = 2;
int directionSignChanges = 0;
for (int idxB = 0; idxB < 10; idxB++) {
final double here = totalEnergies[testRow][idxB];
final double next = totalEnergies[testRow][idxB + 1];
final double absChange = Math.abs(next - here);
if (idxB > 0) {
final double prev = totalEnergies[testRow][idxB - 1];
if (Math.signum(next - here) != Math.signum(here - prev)) {
directionSignChanges++;
}
}
if (absChange > maxChange && assertions) {
org.junit.Assert.fail(format("Failed max_change smoothness criterion: %g > %g. (change:%g->%g, range:{%g,%g})", absChange, maxChange, min, max, totalEnergies[testRow][idxB], totalEnergies[testRow][idxB + 1]));
}
}
if (directionSignChanges > maxDirectionSignChanges && assertions) {
org.junit.Assert.fail(format("Failed direction_changes smoothness criterion: %d > %d.", directionSignChanges, maxDirectionSignChanges));
}
sb.append(format(" Smoothness Verification: Total \n"));
sb.append(format(" ******************************** \n"));
printAsTable(totalEnergies, "U_Total", sb);
printAsTable(totalDerivsA, "dU_dEsvA", sb);
printAsTable(totalDerivsB, "dU_dEsvB", sb);
if (smoothnessDecomposition) {
sb.append(format(" Smoothness Verification: VdW \n"));
sb.append(format(" ****************************** \n"));
printAsTable(vdwEnergies, "vanWaals", sb);
printAsTable(vdwDerivsA, "dVdw_dA", sb);
printAsTable(vdwDerivsB, "dVdw_dB", sb);
sb.append(format(" Smoothness Verification: PermReal \n"));
sb.append(format(" *********************************** \n"));
printAsTable(permanentEnergies, "permReal", sb);
printAsTable(permanentDerivsA, "dPRealdA", sb);
printAsTable(permanentDerivsB, "dPRealdB", sb);
sb.append(format(" Smoothness Verification: PermRecip \n"));
sb.append(format(" ************************************ \n"));
printAsTable(inducedEnergies, "permRcp", sb);
printAsTable(inducedDerivsA, "dPRcp_dA", sb);
printAsTable(inducedDerivsB, "dPRcp_dB", sb);
}
utils.setSilentPotential(false);
logger.info(sb.toString());
}
use of ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig in project ffx by mjschnie.
the class ExtendedVariableTest method testEndStates.
/**
* Verify that a lys-lys system with two ESVs can exactly reproduce the
* energy yielded by vanilla energy() calls on mutated PDB files.
*/
public void testEndStates() {
ExtendedSystemConfig esvConfig = activateAll();
MolecularAssembly mola = openResource(stateFilenames[3], true);
ExtendedSystem esvSystem = (esvConfig != null) ? new ExtendedSystem(mola, esvConfig) : new ExtendedSystem(mola);
esvSystem.setConstantPh(7.4);
esvSystem.populate(esvResidueIDs);
mola.getPotentialEnergy().attachExtendedSystem(esvSystem);
ForceFieldEnergy ffe = mola.getPotentialEnergy();
if (resultsOnly) {
utils.setSilentPotential(true);
}
ParticleMeshEwaldQI esvPme = ffe.getPmeQiNode();
final double[] totalEsv = new double[4];
final double[] vdwEsv = new double[4];
final double[] permEsv = new double[4], permRealEsv = new double[4], permSelfEsv = new double[4], permRecipEsv = new double[4];
final double[] directEsv = new double[4];
final double[] mutualEsv = new double[4], indRealEsv = new double[4], indSelfEsv = new double[4], indRecipEsv = new double[4];
final String[] esvStateNames = new String[4];
final double[] decompPolarStateEsv = (decompPolarState == Polarization.MUTUAL) ? mutualEsv : directEsv;
final double[] decompPolarCompEsv = (decompPolarComplement == Polarization.MUTUAL) ? mutualEsv : directEsv;
esvSystem.setLambda(0, 0.0);
esvSystem.setLambda(1, 0.0);
esvStateNames[0] = format("L=%1.0f,%1.0f", esvSystem.getLambda(0), esvSystem.getLambda(1));
esvPme.setPolarization(decompPolarState);
ffe.energy(true, false);
totalEsv[0] = ffe.getTotalEnergy() - esvSystem.getBiasEnergy();
vdwEsv[0] = ffe.getVanDerWaalsEnergy();
permEsv[0] = esvPme.getPermanentEnergy();
permRealEsv[0] = esvPme.getPermRealEnergy();
permSelfEsv[0] = esvPme.getPermSelfEnergy();
permRecipEsv[0] = esvPme.getPermRecipEnergy();
decompPolarStateEsv[0] = esvPme.getPolarizationEnergy();
indRealEsv[0] = esvPme.getIndRealEnergy();
indSelfEsv[0] = esvPme.getIndSelfEnergy();
indRecipEsv[0] = esvPme.getIndRecipEnergy();
ffe.getPmeNode().setPolarization(decompPolarComplement);
ffe.energy(true, false);
decompPolarCompEsv[0] = ffe.getPolarizationEnergy();
ffe.getPmeNode().setPolarization(decompPolarState);
esvSystem.setLambda(0, 0.0);
esvSystem.setLambda(1, 1.0);
esvStateNames[1] = format("L=%1.0f,%1.0f", esvSystem.getLambda(0), esvSystem.getLambda(1));
esvPme.setPolarization(decompPolarState);
ffe.energy(true, false);
totalEsv[1] = ffe.getTotalEnergy() - esvSystem.getBiasEnergy();
vdwEsv[1] = ffe.getVanDerWaalsEnergy();
permEsv[1] = esvPme.getPermanentEnergy();
permRealEsv[1] = esvPme.getPermRealEnergy();
permSelfEsv[1] = esvPme.getPermSelfEnergy();
permRecipEsv[1] = esvPme.getPermRecipEnergy();
decompPolarStateEsv[1] = esvPme.getPolarizationEnergy();
indRealEsv[1] = esvPme.getIndRealEnergy();
indSelfEsv[1] = esvPme.getIndSelfEnergy();
indRecipEsv[1] = esvPme.getIndRecipEnergy();
ffe.getPmeNode().setPolarization(decompPolarComplement);
ffe.energy(true, false);
decompPolarCompEsv[1] = ffe.getPolarizationEnergy();
ffe.getPmeNode().setPolarization(decompPolarState);
esvSystem.setLambda(0, 1.0);
esvSystem.setLambda(1, 0.0);
esvStateNames[2] = format("L=%1.0f,%1.0f", esvSystem.getLambda(0), esvSystem.getLambda(1));
esvPme.setPolarization(decompPolarState);
ffe.energy(true, false);
totalEsv[2] = ffe.getTotalEnergy() - esvSystem.getBiasEnergy();
vdwEsv[2] = ffe.getVanDerWaalsEnergy();
permEsv[2] = esvPme.getPermanentEnergy();
permRealEsv[2] = esvPme.getPermRealEnergy();
permSelfEsv[2] = esvPme.getPermSelfEnergy();
permRecipEsv[2] = esvPme.getPermRecipEnergy();
decompPolarStateEsv[2] = esvPme.getPolarizationEnergy();
indRealEsv[2] = esvPme.getIndRealEnergy();
indSelfEsv[2] = esvPme.getIndSelfEnergy();
indRecipEsv[2] = esvPme.getIndRecipEnergy();
ffe.getPmeNode().setPolarization(decompPolarComplement);
ffe.energy(true, false);
decompPolarCompEsv[2] = ffe.getPolarizationEnergy();
ffe.getPmeNode().setPolarization(decompPolarState);
esvSystem.setLambda(0, 1.0);
esvSystem.setLambda(1, 1.0);
esvStateNames[3] = format("L=%1.0f,%1.0f", esvSystem.getLambda(0), esvSystem.getLambda(1));
esvPme.setPolarization(decompPolarState);
ffe.energy(true, false);
totalEsv[3] = ffe.getTotalEnergy() - esvSystem.getBiasEnergy();
vdwEsv[3] = ffe.getVanDerWaalsEnergy();
permEsv[3] = esvPme.getPermanentEnergy();
permRealEsv[3] = esvPme.getPermRealEnergy();
permSelfEsv[3] = esvPme.getPermSelfEnergy();
permRecipEsv[3] = esvPme.getPermRecipEnergy();
decompPolarStateEsv[3] = esvPme.getPolarizationEnergy();
indRealEsv[3] = esvPme.getIndRealEnergy();
indSelfEsv[3] = esvPme.getIndSelfEnergy();
indRecipEsv[3] = esvPme.getIndRecipEnergy();
ffe.getPmeNode().setPolarization(decompPolarComplement);
ffe.energy(true, false);
decompPolarCompEsv[3] = ffe.getPolarizationEnergy();
ffe.getPmeNode().setPolarization(decompPolarState);
/* Open vanilla end states. */
MolecularAssembly qiMola, cartMola;
ForceFieldEnergy qiPot, cartPot;
final int numStates = stateFilenames.length;
final double[] totalQi = new double[numStates], totalCart = new double[numStates];
final double[] vdwQi = new double[numStates], vdwCart = new double[numStates];
final double[] permQi = new double[numStates], permCart = new double[numStates];
final double[] permRealQi = new double[numStates], permRealCart = new double[numStates];
final double[] permSelfQi = new double[numStates], permSelfCart = new double[numStates];
final double[] permRecipQi = new double[numStates], permRecipCart = new double[numStates];
final double[] mutualQi = new double[numStates], mutualCart = new double[numStates];
final double[] directQi = new double[numStates], directCart = new double[numStates];
final double[] indRealQi = new double[numStates], indRealCart = new double[numStates];
final double[] indSelfQi = new double[numStates], indSelfCart = new double[numStates];
final double[] indRecipQi = new double[numStates], indRecipCart = new double[numStates];
final double[] decompPolarStateQi = (decompPolarState == Polarization.MUTUAL) ? mutualQi : directQi;
final double[] decompPolarCompQi = (decompPolarComplement == Polarization.MUTUAL) ? mutualQi : directQi;
final double[] decompPolarStateCart = (decompPolarState == Polarization.MUTUAL) ? mutualCart : directCart;
final double[] decompPolarCompCart = (decompPolarComplement == Polarization.MUTUAL) ? mutualCart : directCart;
// Get manual (no ESVs) end state energy components from both vanilla-qi and cartesian PME.
for (int i = 0; i < stateFilenames.length; i++) {
String state = stateFilenames[i];
setProp("pme.qi", true);
qiMola = openResource(stateFilenames[i], true);
qiPot = qiMola.getPotentialEnergy();
ParticleMeshEwaldQI qiPme = qiPot.getPmeQiNode();
qiPme.setPolarization(decompPolarState);
qiPot.energy(true, false);
totalQi[i] = qiPot.getTotalEnergy();
vdwQi[i] = qiPot.getVanDerWaalsEnergy();
permQi[i] = qiPme.getPermanentEnergy();
permRealQi[i] = qiPme.getPermRealEnergy();
permSelfQi[i] = qiPme.getPermSelfEnergy();
permRecipQi[i] = qiPme.getPermRecipEnergy();
decompPolarStateQi[i] = qiPme.getPolarizationEnergy();
indRealQi[i] = qiPme.getIndRealEnergy();
indSelfQi[i] = qiPme.getIndSelfEnergy();
indRecipQi[i] = qiPme.getIndRecipEnergy();
qiPme.setPolarization(decompPolarComplement);
qiPot.energy(true, false);
decompPolarCompQi[i] = qiPme.getPolarizationEnergy();
utils.close(qiMola);
setProp("pme.qi", false);
cartMola = openResource(stateFilenames[i], true);
cartPot = cartMola.getPotentialEnergy();
ParticleMeshEwaldCart cartPme = (ParticleMeshEwaldCart) cartPot.getPmeNode();
cartPme.setPolarization(decompPolarState);
cartPot.energy(true, false);
totalCart[i] = cartPot.getTotalEnergy();
vdwCart[i] = cartPot.getVanDerWaalsEnergy();
permCart[i] = cartPme.getPermanentEnergy();
permRealCart[i] = cartPme.getPermRealEnergy();
permSelfCart[i] = cartPme.getPermSelfEnergy();
permRecipCart[i] = cartPme.getPermRecipEnergy();
decompPolarStateCart[i] = cartPme.getPolarizationEnergy();
indRealCart[i] = cartPme.getIndRealEnergy();
indSelfCart[i] = cartPme.getIndSelfEnergy();
indRecipCart[i] = cartPme.getIndRecipEnergy();
cartPme.setPolarization(decompPolarComplement);
cartPot.energy(true, false);
decompPolarCompCart[i] = cartPme.getPolarizationEnergy();
utils.close(cartMola);
if (assertions) {
assertEquals("Total" + i, totalCart[i], totalEsv[i], tolerance);
assertEquals("VanDerWaals" + i, vdwCart[i], vdwEsv[i], tolerance);
assertEquals("Permanent" + i, permCart[i], permEsv[i], tolerance);
assertEquals("Ind.Direct" + i, directCart[i], directEsv[i], tolerance);
assertEquals("Ind.Mutual" + i, mutualCart[i], mutualEsv[i], tolerance);
assertEquals("PermReal" + i, permRealCart[i], permRealEsv[i], tolerance);
assertEquals("PermSelf" + i, permSelfCart[i], permSelfEsv[i], tolerance);
assertEquals("PermRecip" + i, permRecipCart[i], permRecipEsv[i], tolerance);
assertEquals("IndReal" + i, indRealCart[i], indRealEsv[i], tolerance);
assertEquals("IndSelf" + i, indSelfCart[i], indSelfEsv[i], tolerance);
assertEquals("IndRecip" + i, indRecipCart[i], indRecipEsv[i], tolerance);
}
}
sb.append(format(" Two-site End State Analysis \n"));
sb.append(format(" ***************************** \n"));
if (includeManualQiEndStates) {
sb.append(format(" %-27s %-22s %-22s %-22s\n", "Extended System (1 File, QI)", "Manual (4 Files, QI)", "Manual (4 Files, Cart)", "Error (Cart-ESV)"));
} else {
sb.append(format(" %-27s %-22s %-22s\n", "Extended System (1 File, QI)", "Manual (4 Files, Cart)", "Error (Cart-ESV)"));
}
double[][] esvResult = new double[][] { totalEsv, vdwEsv, permEsv, directEsv, mutualEsv, permRealEsv, permSelfEsv, permRecipEsv, indRealEsv, indSelfEsv, indRecipEsv };
double[][] qiResult = new double[][] { totalQi, vdwQi, permQi, directQi, mutualQi, permRealQi, permSelfQi, permRecipQi, indRealQi, indSelfQi, indRecipQi };
double[][] cartResult = new double[][] { totalCart, vdwCart, permCart, directCart, mutualCart, permRealCart, permSelfCart, permRecipCart, indRealCart, indSelfCart, indRecipCart };
String[] names = new String[] { "Total", "VanWaals", "Permanent", "Direct", "Mutual", "PermReal", "PermSelf", "PermRecip", "IndReal", "IndSelf", "IndRecip" };
for (int component = 0; component < names.length; component++) {
for (int state = 0; state < numStates; state++) {
String name = (state == 0) ? names[component] : "";
sb.append(format(" %-27s", format("%-9s %-7.7s %10.5f", name, esvStateNames[state], esvResult[component][state])));
if (includeManualQiEndStates) {
sb.append(format(" %-22s", format("%-7.7s %12.6f", stateFilenames[state], qiResult[component][state])));
}
sb.append(format(" %-22s", format("%-7.7s %12.6f", stateFilenames[state], cartResult[component][state])));
final double error = Math.abs(cartResult[component][state] - esvResult[component][state]);
final String errorStr = (error < errorThreshold) ? format("< %.1e", errorThreshold) : format("%+g", error);
sb.append(format(" %16s\n", errorStr));
}
}
utils.setSilentPotential(false);
logger.info(sb.toString());
}
Aggregations