Search in sources :

Example 1 with ParticleMeshEwaldCart

use of ffx.potential.nonbonded.ParticleMeshEwaldCart 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());
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) ParticleMeshEwaldCart(ffx.potential.nonbonded.ParticleMeshEwaldCart) ExtendedSystem(ffx.potential.extended.ExtendedSystem) ForceFieldEnergy(ffx.potential.ForceFieldEnergy) ParticleMeshEwaldQI(ffx.potential.nonbonded.ParticleMeshEwaldQI) ExtendedSystemConfig(ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig)

Aggregations

ForceFieldEnergy (ffx.potential.ForceFieldEnergy)1 MolecularAssembly (ffx.potential.MolecularAssembly)1 ExtendedSystem (ffx.potential.extended.ExtendedSystem)1 ExtendedSystemConfig (ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig)1 ParticleMeshEwaldCart (ffx.potential.nonbonded.ParticleMeshEwaldCart)1 ParticleMeshEwaldQI (ffx.potential.nonbonded.ParticleMeshEwaldQI)1