Package ffx.potential.openmm
Class OpenMMEnergy
java.lang.Object
ffx.potential.ForceFieldEnergy
ffx.potential.openmm.OpenMMEnergy
- All Implemented Interfaces:
CrystalPotential
,OptimizationInterface
,Potential
,LambdaInterface
Compute the potential energy and derivatives using OpenMM.
- Since:
- 1.0
- Author:
- Michael J. Schnieders
-
Nested Class Summary
Nested classes/interfaces inherited from interface ffx.numerics.Potential
Potential.STATE, Potential.VARIABLE_TYPE
-
Field Summary
Fields inherited from class ffx.potential.ForceFieldEnergy
DEFAULT_CONSTRAINT_TOLERANCE, lambdaBondedTerms, lambdaTerm, maxDebugGradient, molecularAssembly, optimizationScaling
-
Constructor Summary
ConstructorDescriptionOpenMMEnergy
(MolecularAssembly molecularAssembly, Platform requestedPlatform, int nThreads) ForceFieldEnergyOpenMM constructor; offloads heavy-duty computation to an OpenMM Platform while keeping track of information locally. -
Method Summary
Modifier and TypeMethodDescriptionboolean
destroy()
Frees up assets associated with this ForceFieldEnergy, such as worker Threads.double
energy
(double[] x) This method is called repeatedly to compute the function energy.double
energy
(double[] x, boolean verbose) This method is called repeatedly to compute the function energy.double
energyAndGradient
(double[] x, double[] g) This method is called repeatedly to compute the function energy and gradient.double
energyAndGradient
(double[] x, double[] g, boolean verbose) This method is called repeatedly to compute the function energy and gradient.double
energyAndGradientFFX
(double[] x, double[] g) Compute the energy and gradient using the pure Java code path.double
energyAndGradientFFX
(double[] x, double[] g, boolean verbose) Compute the energy and gradient using the pure Java code path.double
energyFFX
(double[] x) Compute the energy using the pure Java code path.double
energyFFX
(double[] x, boolean verbose) Compute the energy using the pure Java code path.Returns the Context instance.double
Get the 2nd partial derivative of the energy with respect to lambda.double
getdEdL()
Get the partial derivative of the energy with respect to lambda.void
getdEdXdL
(double[] gradients) Get the gradient of dEdL with respect to each parameter.static int
getDefaultDevice
(org.apache.commons.configuration2.CompositeConfiguration props) Gets the default coprocessor device, ignoring any CUDA_DEVICE over-ride.double[]
getGradient
(double[] g) Re-compute the gradient using OpenMM and return it.boolean
Get the lambdaTerm flag.Returns the MolecularAssembly instance.getOpenMMState
(int mask) Create an immutable OpenMM State.Gets the Platform associated with this force field energy.Get a reference to the System instance.void
Update active atoms.void
setCoordinates
(double[] x) Set FFX and OpenMM coordinates for active atoms.void
setCrystal
(Crystal crystal) Set the Crystal instance that specifies the periodic boundary conditions and symmetry.void
setLambda
(double lambda) Set the current value of the state variable.void
setLambdaTerm
(boolean lambdaTerm) Set the lambdaTerm flag.void
updateContext
(String integratorName, double timeStep, double temperature, boolean forceCreation) Create an OpenMM Context.void
updateParameters
(Atom[] atoms) Update parameters if the Use flags and/or Lambda value has changed.Methods inherited from class ffx.potential.ForceFieldEnergy
applyAllConstraintPositions, applyAllConstraintPositions, attachExtendedSystem, dEdLZeroAtEnds, energy, energy, energyFactory, energyFactory, getAcceleration, getAngleEnergy, getAngleEnergyString, getAngles, getAngles, getAngleTorsionEnergy, getAngleTorsions, getBondEnergy, getBondEnergyString, getBonds, getCavitationEnergy, getConstraints, getCoordinates, getCrystal, getCutoffPlusBuffer, getDispersionEnergy, getElectrostaticEnergy, getEnergyTermState, getEsvBiasEnergy, getExtendedSystem, getGK, getGKEnergy, getImproperTorsionEnergy, getImproperTorsions, getInPlaneAngleEnergyString, getLambda, getMass, getNeutralNetworkEnergy, getNumberofAngles, getNumberofAngleTorsions, getNumberofBonds, getNumberofImproperTorsions, getNumberofOutOfPlaneBends, getNumberofPiOrbitalTorsions, getNumberofStretchBends, getNumberofStretchTorsions, getNumberofTorsions, getNumberofTorsionTorsions, getNumberofUreyBradleys, getNumberOfVariables, getOutOfPlaneBendEnergy, getOutOfPlaneBends, getOutOfPlaneEnergyString, getParallelTeam, getPDBHeaderString, getPermanentInteractions, getPermanentMultipoleEnergy, getPermanentRealSpaceEnergy, getPermanentReciprocalMpoleEnergy, getPermanentReciprocalSelfEnergy, getPiOrbitalTorsionEnergy, getPiOrbitalTorsionEnergyString, getPiOrbitalTorsions, getPmeNode, getPolarizationEnergy, getPreviousAcceleration, getRelativeSolvationEnergy, getRestrainDistances, getRestrainGroups, getRestrainPositions, getRestrainTorsions, getScaling, getSolvationEnergy, getSolvationInteractions, getStrenchBendEnergy, getStretchBendEnergyString, getStretchBends, getStretchTorsionEnergy, getStretchTorsions, getTorsionEnergy, getTorsions, getTorsionTorsionEnergy, getTorsionTorsions, getTotalElectrostaticEnergy, getTotalEnergy, getUreyBradleyEnergy, getUreyBradleys, getVanDerWaalsEnergy, getVanDerWaalsInteractions, getVariableTypes, getVdwNode, getVelocity, logBondedTerms, setAcceleration, setCrystal, setEnergyTermState, setPreviousAcceleration, setPrintOnFailure, setScaling, setVelocity, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ffx.numerics.OptimizationInterface
getUnderlyingPotentials, scaleCoordinates, scaleCoordinatesAndGradient, unscaleCoordinates
Methods inherited from interface ffx.numerics.Potential
writeAdditionalRestartInfo
-
Constructor Details
-
OpenMMEnergy
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
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 interfaceOptimizationInterface
- Overrides:
destroy
in classForceFieldEnergy
- 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 interfaceOptimizationInterface
- Overrides:
energy
in classForceFieldEnergy
- 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 interfaceOptimizationInterface
- Overrides:
energy
in classForceFieldEnergy
- 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 interfaceOptimizationInterface
- Overrides:
energyAndGradient
in classForceFieldEnergy
- 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 interfaceOptimizationInterface
- Overrides:
energyAndGradient
in classForceFieldEnergy
- 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 coordinatesg
- 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 coordinatesg
- 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 coordinatesverbose
- Use verbose logging.- Returns:
- The energy (kcal/mol)
-
getContext
Returns the Context instance.- Returns:
- context
-
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 classForceFieldEnergy
- Parameters:
g
- Gradient array.- Returns:
- an array of
invalid reference
double
-
getPlatform
Gets the Platform associated with this force field energy. For the reference platform, always returns FFX.- Overrides:
getPlatform
in classForceFieldEnergy
- Returns:
- A Platform.
-
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 interfaceLambdaInterface
- Overrides:
getd2EdL2
in classForceFieldEnergy
- Returns:
- d2EdL2
-
getdEdL
public double getdEdL()Get the partial derivative of the energy with respect to lambda.- Specified by:
getdEdL
in interfaceLambdaInterface
- Overrides:
getdEdL
in classForceFieldEnergy
- Returns:
- dEdL
-
getdEdXdL
public void getdEdXdL(double[] gradients) Get the gradient of dEdL with respect to each parameter.- Specified by:
getdEdXdL
in interfaceLambdaInterface
- Overrides:
getdEdXdL
in classForceFieldEnergy
- 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 classForceFieldEnergy
- Parameters:
x
- Atomic coordinates.
-
setCrystal
Set the Crystal instance that specifies the periodic boundary conditions and symmetry.Set the boundary conditions for this calculation.
- Specified by:
setCrystal
in interfaceCrystalPotential
- Overrides:
setCrystal
in classForceFieldEnergy
- 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 interfaceLambdaInterface
- Overrides:
setLambda
in classForceFieldEnergy
- Parameters:
lambda
- a double.
-
updateParameters
Update parameters if the Use flags and/or Lambda value has changed.- Parameters:
atoms
- Atoms in this list are considered.
-