Search in sources :

Example 6 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class PotentialsUtils method energy.

/**
 * Evaluates the energy of a MolecularAssembly and returns its
 * ForceFieldEnergy object.
 *
 * @param assembly To evaluate
 * @return assembly's ForceFieldEnergy.
 */
@Override
public ForceFieldEnergy energy(MolecularAssembly assembly) {
    if (assembly == null) {
        logger.info(" Molecular assembly was null - skipping energy");
        return null;
    } else {
        ForceFieldEnergy energy = assembly.getPotentialEnergy();
        if (energy == null) {
            energy = ForceFieldEnergy.energyFactory(assembly);
            assembly.setPotential(energy);
        }
        energy.energy(false, true);
        return energy;
    }
}
Also used : ForceFieldEnergy(ffx.potential.ForceFieldEnergy)

Example 7 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class ExtendedVariableTest method testDerivatives.

/**
 * Analytic Derivative vs Finite Difference: VdW,PermReal,PermRecip,Total
 */
public void testDerivatives(ExtendedSystemConfig esvConfig) {
    if (esvConfig == null) {
        esvConfig = setDebugParameters();
    }
    MolecularAssembly mola = setupWithExtended(esvFilename, false, esvConfig);
    ForceFieldEnergy ffe = mola.getPotentialEnergy();
    ExtendedSystem esvSystem = ffe.getExtendedSystem();
    if (resultsOnly) {
        utils.setSilentPotential(true);
    }
    final double step = 1e-6;
    for (int i = 0; i < esvSystem.size(); i++) {
        final String esvName = esvSystem.getEsv(i).getName();
        if (!mola.getCrystal().aperiodic()) {
            sb.append(format(" Finite Diff: %5.5s (Crystal)\n", esvName));
        } else {
            sb.append(format(" Finite Diff: %5.5s (Aprodc.)\n", esvName));
        }
        // Reset lambdas.
        for (int k = 0; k < esvSystem.size(); k++) {
            esvSystem.setLambda(k, initialLambda[k]);
        }
        for (double lambda : lambdaValuesToTest) {
            final double center, low, high;
            if (oneSidedFiniteAtExtremes) {
                center = lambda;
                low = (center - step >= 0.0) ? center - step : center;
                high = (center + step <= 1.0) ? center + step : center;
            } else {
                center = (lambda - step < 0.0) ? lambda + step : (lambda + step > 1.0) ? lambda - step : lambda;
                low = center - step;
                high = center + step;
            }
            final double width = high - low;
            // Collect numeric derivative components.
            esvSystem.setLambda(i, low);
            ffe.energy(true, false);
            final double vdwLow = ffe.getEnergyComponent(PotentialComponent.VanDerWaals);
            final double bondedLow = ffe.getEnergyComponent(PotentialComponent.Bonded);
            final double biasLow = ffe.getEnergyComponent(PotentialComponent.pHMD);
            final double permRealLow = ffe.getEnergyComponent(PotentialComponent.PermanentRealSpace);
            final double permSelfLow = ffe.getEnergyComponent(PotentialComponent.PermanentSelf);
            final double permRecipLow = ffe.getEnergyComponent(PotentialComponent.PermanentReciprocal);
            final double indRealLow = ffe.getEnergyComponent(PotentialComponent.InducedRealSpace);
            final double indSelfLow = ffe.getEnergyComponent(PotentialComponent.InducedSelf);
            final double indRecipLow = ffe.getEnergyComponent(PotentialComponent.InducedReciprocal);
            final double totalLow = ffe.getEnergyComponent(PotentialComponent.ForceFieldEnergy);
            esvSystem.setLambda(i, high);
            ffe.energy(true, false);
            final double vdwHigh = ffe.getEnergyComponent(PotentialComponent.VanDerWaals);
            final double bondedHigh = ffe.getEnergyComponent(PotentialComponent.Bonded);
            final double biasHigh = ffe.getEnergyComponent(PotentialComponent.pHMD);
            final double permRealHigh = ffe.getEnergyComponent(PotentialComponent.PermanentRealSpace);
            final double permSelfHigh = ffe.getEnergyComponent(PotentialComponent.PermanentSelf);
            final double permRecipHigh = ffe.getEnergyComponent(PotentialComponent.PermanentReciprocal);
            final double indRealHigh = ffe.getEnergyComponent(PotentialComponent.InducedRealSpace);
            final double indSelfHigh = ffe.getEnergyComponent(PotentialComponent.InducedSelf);
            final double indRecipHigh = ffe.getEnergyComponent(PotentialComponent.InducedReciprocal);
            final double totalHigh = ffe.getEnergyComponent(PotentialComponent.ForceFieldEnergy);
            // Get analytic derivatives from the center.
            esvSystem.setLambda(i, center);
            ffe.energy(true, false);
            final double vdwAna = esvSystem.getDerivativeComponent(PotentialComponent.VanDerWaals, i);
            final double bondedAna = esvSystem.getDerivativeComponent(PotentialComponent.Bonded, i);
            final double biasAna = esvSystem.getDerivativeComponent(PotentialComponent.pHMD, i);
            final double permRealAna = esvSystem.getDerivativeComponent(PotentialComponent.PermanentRealSpace, i);
            final double permSelfAna = esvSystem.getDerivativeComponent(PotentialComponent.PermanentSelf, i);
            final double permRecipAna = esvSystem.getDerivativeComponent(PotentialComponent.PermanentReciprocal, i);
            final double indRealAna = esvSystem.getDerivativeComponent(PotentialComponent.InducedRealSpace, i);
            final double indSelfAna = esvSystem.getDerivativeComponent(PotentialComponent.InducedSelf, i);
            final double indRecipAna = esvSystem.getDerivativeComponent(PotentialComponent.InducedReciprocal, i);
            final double totalAna = esvSystem.getDerivativeComponent(PotentialComponent.ForceFieldEnergy, i);
            // Calculate numeric derivatives and error.
            final double vdwNum = (vdwHigh - vdwLow) / (width);
            final double vdwErr = (vdwAna - vdwNum);
            final double bondedNum = (bondedHigh - bondedLow) / (width);
            final double bondedErr = (bondedAna - bondedNum);
            final double biasNum = (biasHigh - biasLow) / (width);
            final double biasErr = (biasAna - biasNum);
            final double permRealNum = (permRealHigh - permRealLow) / (width);
            final double permRealErr = (permRealAna - permRealNum);
            final double permSelfNum = (permSelfHigh - permSelfLow) / (width);
            final double permSelfErr = (permSelfAna - permSelfNum);
            final double permRecipNum = (permRecipHigh - permRecipLow) / (width);
            final double permRecipErr = (permRecipAna - permRecipNum);
            final double indRealNum = (indRealHigh - indRealLow) / (width);
            final double indRealErr = (indRealAna - indRealNum);
            final double indSelfNum = (indSelfHigh - indSelfLow) / (width);
            final double indSelfErr = (indSelfAna - indSelfNum);
            final double indRecipNum = (indRecipHigh - indRecipLow) / (width);
            final double indRecipErr = (indRecipAna - indRecipNum);
            final double totalNum = (totalHigh - totalLow) / (width);
            final double totalErr = (totalAna - totalNum);
            sb.append(format(" %-28s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s\n", StringUtils.repeat("*", 28), "vdw ", "bonded", "bias", "permReal", "permSelf", "permRecip", "indReal", "indSelf", "indRecip", "total"));
            sb.append(format(" %-28s %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g\n", format("Numeric  @L=%s", esvSystem.getLambdaList()), vdwNum, bondedNum, biasNum, permRealNum, permSelfNum, permRecipNum, indRealNum, indSelfNum, indRecipNum, totalNum));
            sb.append(format(" %-28s %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g %+12.6g\n", format("Analytic @L=%s", esvSystem.getLambdaList()), vdwAna, bondedAna, biasAna, permRealAna, permSelfAna, permRecipAna, indRealAna, indSelfAna, indRecipAna, totalAna));
            sb.append(format(" %-28s %12s %12s %12s %12s %12s %12s %12s %12s %12s %12s\n", "Error:", err(vdwAna, vdwNum), err(bondedAna, bondedNum), err(biasAna, biasNum), err(permRealAna, permRealNum), err(permSelfAna, permSelfNum), err(permRecipAna, permRecipNum), err(indRealAna, indRealNum), err(indSelfAna, indSelfNum), err(indRecipAna, indRecipNum), err(totalAna, totalNum)));
            utils.setSilentPotential(false);
            logger.info(sb.toString());
            if (assertions) {
                assertEquals("VanDerWaals Deriv Error", 0.0, vdwErr, tolerance);
                assertEquals("Bonded Deriv Error", 0.0, bondedErr, tolerance);
                assertEquals("Bias Deriv Error", 0.0, biasErr, tolerance);
                assertEquals("PermReal Deriv Error", 0.0, permRealErr, tolerance);
                assertEquals("PermSelf Deriv Error", 0.0, permSelfErr, tolerance);
                assertEquals("PermRecip Deriv Error", 0.0, permRecipErr, tolerance);
                assertEquals("IndReal Deriv Error", 0.0, indRealErr, tolerance);
                assertEquals("IndSelf Deriv Error", 0.0, indSelfErr, tolerance);
                assertEquals("IndRecip Deriv Error", 0.0, indRecipErr, tolerance);
                assertEquals("Total Deriv Error", 0.0, totalErr, tolerance);
            }
        }
    // lambda loop
    }
// ESV loop
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) ExtendedSystem(ffx.potential.extended.ExtendedSystem) ForceFieldEnergy(ffx.potential.ForceFieldEnergy)

Example 8 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class TimerTest method testTimer.

@Test
public void testTimer() {
    int nEvals = 5;
    boolean gradient = true;
    boolean print = true;
    ForceFieldEnergy energy = molecularAssembly.getPotentialEnergy();
    long minTime = Long.MAX_VALUE;
    long maxTime = Long.MIN_VALUE;
    double sumTime2 = 0.0;
    // Halfway point
    int halfnEvals = (nEvals % 2 == 1) ? (nEvals / 2) : (nEvals / 2) - 1;
    for (int i = 0; i < nEvals; i++) {
        long time = -System.nanoTime();
        energy.energy(gradient, print);
        time += System.nanoTime();
        minTime = time < minTime ? time : minTime;
        if (i >= (int) (nEvals / 2)) {
            maxTime = time > maxTime ? time : maxTime;
            double time2 = time * 1.0E-9;
            sumTime2 += (time2 * time2);
        }
    }
    ++halfnEvals;
    double rmsTime = Math.sqrt(sumTime2 / halfnEvals);
    logger.info(String.format(" Minimum time: %14.5f (sec)", minTime * 1.0E-9));
    logger.info(String.format(" Max time (latter half): %14.5f (sec)", maxTime * 1.0E-9));
    logger.info(String.format(" RMS time (latter half): %14.5f (sec)", rmsTime));
}
Also used : ForceFieldEnergy(ffx.potential.ForceFieldEnergy) Test(org.junit.Test)

Example 9 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class ModelingShell method returnEnergy.

/**
 * <p>
 * returnEnergy</p>
 *
 * @return Current system energy (a double).
 */
public double returnEnergy() {
    if (interrupted) {
        logger.info(" Algorithm interrupted - skipping energy.");
        return 0.0;
    }
    if (terminatableAlgorithm != null) {
        logger.info(" Algorithm already running - skipping energy.");
        return 0.0;
    }
    MolecularAssembly active = mainPanel.getHierarchy().getActive();
    if (active != null) {
        ForceFieldEnergy energy = active.getPotentialEnergy();
        if (energy == null) {
            energy = ForceFieldEnergy.energyFactory(active);
            active.setPotential(energy);
        }
        return energy.energy(false, true);
    }
    logger.warning(" Energy could not be calculated");
    return 0.0;
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) ForceFieldEnergy(ffx.potential.ForceFieldEnergy)

Example 10 with ForceFieldEnergy

use of ffx.potential.ForceFieldEnergy in project ffx by mjschnie.

the class UIDataConverter method convert.

/**
 * Converts the data structure to MolecularAssembly(s).
 */
public void convert() {
    if (timer) {
        startTimer();
    }
    FFXSystem ffxSystem = null;
    // Continue if the file was read in successfully.
    if (conversionFilter.convert()) {
        ffxSystem = (FFXSystem) conversionFilter.getActiveMolecularSystem();
        if (!(conversionFilter instanceof BiojavaFilter)) {
            Utilities.biochemistry(ffxSystem, conversionFilter.getAtomList());
        }
        conversionFilter.applyAtomProperties();
        // Add the system to the multiscale hierarchy.
        mainPanel.getHierarchy().addSystemNode(ffxSystem);
        ForceFieldEnergy energy = ForceFieldEnergy.energyFactory(ffxSystem, conversionFilter.getCoordRestraints());
        ffxSystem.setPotential(energy);
        mainPanel.getHierarchy().setActive(ffxSystem);
        // Check if there are alternate conformers
        if (conversionFilter instanceof BiojavaFilter) {
            BiojavaFilter biojFilter = (BiojavaFilter) conversionFilter;
            List<Character> altLocs = biojFilter.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(String.format("(%s) ", c));
                }
                altLocString.append("]\n");
                logger.info(altLocString.toString());
            }
            /**
             * Alternate conformers may have different chemistry, so they
             * each need to be their own FFX system.
             */
            for (Character c : altLocs) {
                if (c.equals(' ') || c.equals('A')) {
                    continue;
                }
                FFXSystem newSystem = new FFXSystem(ffxSystem.getFile(), "Alternate Location " + c, ffxSystem.getProperties());
                newSystem.setForceField(ffxSystem.getForceField());
                biojFilter.setAltID(newSystem, c);
                biojFilter.clearSegIDs();
                if (biojFilter.convert()) {
                    biojFilter.applyAtomProperties();
                    String fileName = ffxSystem.getFile().getAbsolutePath();
                    newSystem.setName(FilenameUtils.getBaseName(fileName) + " " + c);
                    mainPanel.getHierarchy().addSystemNode(newSystem);
                    energy = ForceFieldEnergy.energyFactory(newSystem, biojFilter.getCoordRestraints());
                    newSystem.setPotential(energy);
                }
            }
        }
    } else {
        logger.warning(String.format(" Failed to convert structure %s", dataStructure.toString()));
    }
    mainPanel.setCursor(Cursor.getDefaultCursor());
    if (timer) {
        stopTimer(ffxSystem);
    }
}
Also used : ForceFieldEnergy(ffx.potential.ForceFieldEnergy) BiojavaFilter(ffx.potential.parsers.BiojavaFilter)

Aggregations

ForceFieldEnergy (ffx.potential.ForceFieldEnergy)25 MolecularAssembly (ffx.potential.MolecularAssembly)11 File (java.io.File)6 ForceField (ffx.potential.parameters.ForceField)5 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)5 ForceFieldFilter (ffx.potential.parsers.ForceFieldFilter)4 PDBFilter (ffx.potential.parsers.PDBFilter)4 ParallelTeam (edu.rit.pj.ParallelTeam)3 Crystal (ffx.crystal.Crystal)3 ReflectionList (ffx.crystal.ReflectionList)3 Resolution (ffx.crystal.Resolution)3 Atom (ffx.potential.bonded.Atom)3 ExtendedSystem (ffx.potential.extended.ExtendedSystem)3 PotentialsUtils (ffx.potential.utils.PotentialsUtils)3 RealSpaceData (ffx.realspace.RealSpaceData)3 RealSpaceEnergy (ffx.realspace.RealSpaceEnergy)3 Test (org.junit.Test)3 HKL (ffx.crystal.HKL)2 ComplexNumber (ffx.numerics.ComplexNumber)2 ExtendedSystemConfig (ffx.potential.extended.ExtendedSystem.ExtendedSystemConfig)2