Class OpenMMEnergy

java.lang.Object
ffx.potential.ForceFieldEnergy
ffx.potential.openmm.OpenMMEnergy
All Implemented Interfaces:
CrystalPotential, OptimizationInterface, Potential, LambdaInterface

public class OpenMMEnergy extends ForceFieldEnergy
Compute the potential energy and derivatives using OpenMM.
Since:
1.0
Author:
Michael J. Schnieders
  • Constructor Details

    • OpenMMEnergy

      public OpenMMEnergy(MolecularAssembly molecularAssembly, Platform requestedPlatform, int nThreads)
      ForceFieldEnergyOpenMM constructor; offloads heavy-duty computation to an OpenMM Platform while keeping track of information locally.
      Parameters:
      molecularAssembly - Assembly to construct energy for.
      requestedPlatform - requested OpenMM platform to be used.
      nThreads - Number of threads to use in the super class ForceFieldEnergy instance.
  • Method Details

    • getDefaultDevice

      public static int getDefaultDevice(org.apache.commons.configuration2.CompositeConfiguration props)
      Gets the default coprocessor device, ignoring any CUDA_DEVICE over-ride. This is either determined by process rank and the availableDevices/CUDA_DEVICES property, or just 0 if neither property is sets.
      Parameters:
      props - Properties in use.
      Returns:
      Pre-override device index.
    • updateContext

      public void updateContext(String integratorName, double timeStep, double temperature, boolean forceCreation)
      Create an OpenMM Context.

      Context.free() must be called to free OpenMM memory.

      Parameters:
      integratorName - Integrator to use.
      timeStep - Time step.
      temperature - Temperature (K).
      forceCreation - Force a new Context to be created, even if the existing one matches the request.
    • getOpenMMState

      public OpenMMState getOpenMMState(int mask)
      Create an immutable OpenMM State.

      State.free() must be called to free OpenMM memory.

      Parameters:
      mask - The State mask.
      Returns:
      Returns the State.
    • destroy

      public boolean destroy()
      Frees up assets associated with this ForceFieldEnergy, such as worker Threads.
      Specified by:
      destroy in interface OptimizationInterface
      Overrides:
      destroy in class ForceFieldEnergy
      Returns:
      If successful in freeing up assets.
    • energy

      public double energy(double[] x)
      This method is called repeatedly to compute the function energy.
      Specified by:
      energy in interface OptimizationInterface
      Overrides:
      energy in class ForceFieldEnergy
      Parameters:
      x - Input parameters.
      Returns:
      Function value at x.
    • energy

      public double energy(double[] x, boolean verbose)
      This method is called repeatedly to compute the function energy. The verbose flag may not be used by all implementations.
      Specified by:
      energy in interface OptimizationInterface
      Overrides:
      energy in class ForceFieldEnergy
      Parameters:
      x - Input parameters.
      verbose - Display extra information.
      Returns:
      Function value at x
    • energyAndGradient

      public double energyAndGradient(double[] x, double[] g)
      This method is called repeatedly to compute the function energy and gradient.
      Specified by:
      energyAndGradient in interface OptimizationInterface
      Overrides:
      energyAndGradient in class ForceFieldEnergy
      Parameters:
      x - Input parameters.
      g - Output gradients with respect to each parameter.
      Returns:
      Function value at x.
    • energyAndGradient

      public double energyAndGradient(double[] x, double[] g, boolean verbose)
      This method is called repeatedly to compute the function energy and gradient. The verbose flag may not be used by all implementations.
      Specified by:
      energyAndGradient in interface OptimizationInterface
      Overrides:
      energyAndGradient in class ForceFieldEnergy
      Parameters:
      x - Input parameters.
      g - Output gradients with respect to each parameter.
      verbose - Display extra information.
      Returns:
      Function value at x.
    • energyAndGradientFFX

      public double energyAndGradientFFX(double[] x, double[] g)
      Compute the energy and gradient using the pure Java code path.
      Parameters:
      x - Input atomic coordinates
      g - Storage for the gradient vector.
      Returns:
      The energy (kcal/mol)
    • energyAndGradientFFX

      public double energyAndGradientFFX(double[] x, double[] g, boolean verbose)
      Compute the energy and gradient using the pure Java code path.
      Parameters:
      x - Input atomic coordinates
      g - Storage for the gradient vector.
      verbose - Use verbose logging.
      Returns:
      The energy (kcal/mol)
    • energyFFX

      public double energyFFX(double[] x)
      Compute the energy using the pure Java code path.
      Parameters:
      x - Atomic coordinates.
      Returns:
      The energy (kcal/mol)
    • energyFFX

      public double energyFFX(double[] x, boolean verbose)
      Compute the energy using the pure Java code path.
      Parameters:
      x - Input atomic coordinates
      verbose - Use verbose logging.
      Returns:
      The energy (kcal/mol)
    • getContext

      public OpenMMContext getContext()
      Returns the Context instance.
      Returns:
      context
    • getMolecularAssembly

      public MolecularAssembly getMolecularAssembly()
      Returns the MolecularAssembly instance.
      Returns:
      molecularAssembly
    • setLambdaTerm

      public void setLambdaTerm(boolean lambdaTerm)
      Set the lambdaTerm flag.
      Parameters:
      lambdaTerm - The value to set.
    • getLambdaTerm

      public boolean getLambdaTerm()
      Get the lambdaTerm flag.
      Returns:
      lambdaTerm.
    • getGradient

      public double[] getGradient(double[] g)
      Re-compute the gradient using OpenMM and return it.
      Overrides:
      getGradient in class ForceFieldEnergy
      Parameters:
      g - Gradient array.
      Returns:
      an array of
      invalid reference
      double
      objects.
    • getPlatform

      public Platform getPlatform()
      Gets the Platform associated with this force field energy. For the reference platform, always returns FFX.
      Overrides:
      getPlatform in class ForceFieldEnergy
      Returns:
      A Platform.
    • getSystem

      public OpenMMSystem getSystem()
      Get a reference to the System instance.
      Returns:
      Java wrapper to an OpenMM system.
    • getd2EdL2

      public double getd2EdL2()
      Get the 2nd partial derivative of the energy with respect to lambda.
      Specified by:
      getd2EdL2 in interface LambdaInterface
      Overrides:
      getd2EdL2 in class ForceFieldEnergy
      Returns:
      d2EdL2
    • getdEdL

      public double getdEdL()
      Get the partial derivative of the energy with respect to lambda.
      Specified by:
      getdEdL in interface LambdaInterface
      Overrides:
      getdEdL in class ForceFieldEnergy
      Returns:
      dEdL
    • getdEdXdL

      public void getdEdXdL(double[] gradients)
      Get the gradient of dEdL with respect to each parameter.
      Specified by:
      getdEdXdL in interface LambdaInterface
      Overrides:
      getdEdXdL in class ForceFieldEnergy
      Parameters:
      gradients - - A double array of length the number of parameters in the model (commonly 3 * number of atoms).
    • setActiveAtoms

      public void setActiveAtoms()
      Update active atoms.
    • setCoordinates

      public void setCoordinates(double[] x)
      Set FFX and OpenMM coordinates for active atoms.
      Overrides:
      setCoordinates in class ForceFieldEnergy
      Parameters:
      x - Atomic coordinates.
    • setCrystal

      public void setCrystal(Crystal crystal)
      Set the Crystal instance that specifies the periodic boundary conditions and symmetry.

      Set the boundary conditions for this calculation.

      Specified by:
      setCrystal in interface CrystalPotential
      Overrides:
      setCrystal in class ForceFieldEnergy
      Parameters:
      crystal - a Crystal instance.
    • setLambda

      public void setLambda(double lambda)
      Set the current value of the state variable. May be ignored if lambda is not being applied.
      Specified by:
      setLambda in interface LambdaInterface
      Overrides:
      setLambda in class ForceFieldEnergy
      Parameters:
      lambda - a double.
    • updateParameters

      public void updateParameters(@Nullable Atom[] atoms)
      Update parameters if the Use flags and/or Lambda value has changed.
      Parameters:
      atoms - Atoms in this list are considered.