Package ffx.potential

Class ForceFieldEnergyOpenMM

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

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

    • enforcePBC

      public final int enforcePBC
      Whether to enforce periodic boundary conditions when obtaining new States.
  • Constructor Details

    • ForceFieldEnergyOpenMM

      protected ForceFieldEnergyOpenMM(MolecularAssembly molecularAssembly, ForceFieldEnergy.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

    • createContext

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

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

      Parameters:
      integratorString - 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.
    • createState

      public ForceFieldEnergyOpenMM.State createState(boolean positions, boolean energies, boolean forces, boolean velocities)
      Create an immutable OpenMM State.

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

      Parameters:
      positions - Retrieve positions.
      energies - Retrieve energies.
      forces - Retrieve forces.
      velocities - Retrieve velocities.
      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 ForceFieldEnergyOpenMM.Context getContext()
      Returns the Context instance.
      Returns:
      context
    • 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 ForceFieldEnergy.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 ForceFieldEnergyOpenMM.System 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 boundary conditions for this calculation.

      Specified by:
      setCrystal in interface CrystalPotential
      Overrides:
      setCrystal in class ForceFieldEnergy
    • 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(Atom[] atoms)
      Update parameters if the Use flags and/or Lambda value has changed.
      Parameters:
      atoms - Atoms in this list are considered.