Package ffx.algorithms.dynamics
Class MolecularDynamics
java.lang.Object
ffx.algorithms.dynamics.MolecularDynamics
- All Implemented Interfaces:
Terminatable
,Runnable
- Direct Known Subclasses:
MolecularDynamicsOpenMM
Run NVE, NVT, or NPT molecular dynamics.
- Since:
- 1.0
- Author:
- Michael J. Schnieders
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AlgorithmListener
An Algorithm Listener to send updates to the GUI.protected boolean
Whether MD handles writing restart/trajectory files itself (true), or will be commanded by another class (false) to do it.protected boolean
Flag to indicate a run has finished.protected double
The time step (picoseconds).protected String
File type to use when saving files.protected UnmodifiableState
State of the system as of the last init call (and start of the last dynamics run).protected boolean
Flag to indicate velocities should be initialized.protected int
Time steps between logging information to the screen.protected MolecularAssembly[]
MolecularAssembly to run dynamics on.protected int
Time steps between writing out restart/checkpoint files.protected double
Time between writing out restart/checkpoint files in picoseconds.protected final SystemState
Stores the current molecular dynamics state.protected double
The total simulation time.protected int
Time steps between adding a frame to the trajectory file. -
Constructor Summary
ConstructorDescriptionMolecularDynamics
(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator) Constructor for MolecularDynamics. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAssembly
(MolecularAssembly assembly) Adds a MolecularAssembly to be tracked by this MolecularDynamics.protected void
appendSnapshot
(String[] extraLines) Append a snapshot to the trajectory file.void
attachExtendedSystem
(ExtendedSystem system, double reportFreq) attachExtendedSystem.void
dynamic
(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, File dyn) Blocking molecular dynamics.void
dynamic
(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, String fileType, double restartInterval, File dyn) Blocking molecular dynamics.static MolecularDynamics
dynamicsFactory
(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator) Method that determines whether a dynamics is done by the java implementation native to ffx or the OpenMM implementationstatic MolecularDynamics
dynamicsFactory
(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator, MDEngine engine) dynamicsFactory.Returns the MolecularAssembly array.double[]
Get the coordinates.Returns the associated dynamics file.double
Gets the kinetic energy at the start of the last dynamics run.double
Gets the potential energy at the start of the last dynamics run.double
Gets the temperature at the start of the last dynamics run.double
Gets the total energy at the start of the last dynamics run.int
getIntervalSteps.double
Get the system kinetic energy.double
Get the system potential energy.double
Get the current temperature of the systemGetter for the fieldthermostat
.double
getTimeStep.double
Get the total system energy (kinetic plus potential).void
init
(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, File dyn) A version of init with the original method header.void
init
(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, String fileType, double restartInterval, double temperature, boolean initVelocities, File dyn) initprotected long
logThermoForTime
(long step, long time) Checks if thermodynamics must be logged.void
Revert the state of the MolecularDynamics instance to the stored MDState.void
run()
void
setArchiveFiles
(File[] archiveFiles) Set the archive file for each MolecularAssembly.void
setAutomaticWriteouts
(boolean autoWriteout) Enable or disable automatic writeout of trajectory snapshots and restart files.void
setCoordinates
(double[] coords) Set the coordinates.void
setFallbackDynFile
(File fallback) Sets the "fallback" .dyn file to write to if none is passed to the dynamic method.void
setFileType
(String fileType) Method to set file type from groovy scripts.void
setIntervalSteps
(int intervalSteps) No-op; FFX does not need to occasionally return information from FFX.void
setNonEquilibriumLambda
(boolean nonEquilibrium, int nEQSteps) Enables non-equilibrium lambda dynamics.void
setObtainVelAcc
(boolean obtainVA) Not meaningful for FFX dynamics (no need to obtain velocities/accelerations from a different program, especially one running on a GPU).void
setRestartFrequency
(double restartInterval) Method to set the Restart Frequency.void
setThermostat
(Thermostat thermostat) Setter for the fieldthermostat
.void
setVerbosityLevel
(MDVerbosity level) void
Store the current state of the molecular dynamics simulation in a MDState record.void
This should be implemented as a blocking interrupt; when the method returns theTerminatable
algorithm has reached a clean termination point.writeFilesForStep
(long step, boolean trySnapshot, boolean tryRestart) Write restart and trajectory files if the provided step matches the frequency and that file type is requested.writeFilesForStep
(long step, boolean trySnapshot, boolean tryRestart, String[] extraLines) Write restart and trajectory files if the provided step matches the frequency and that file type is requested.void
Write out a restart file.
-
Field Details
-
molecularAssembly
MolecularAssembly to run dynamics on.For dual or quad topology simulations, this is an array of length 2 or 4.
-
algorithmListener
An Algorithm Listener to send updates to the GUI. -
state
Stores the current molecular dynamics state. -
initialState
State of the system as of the last init call (and start of the last dynamics run). -
dt
protected double dtThe time step (picoseconds).The method
setTimeStep
should always be used to set this value. -
initVelocities
protected boolean initVelocitiesFlag to indicate velocities should be initialized. -
automaticWriteouts
protected boolean automaticWriteoutsWhether MD handles writing restart/trajectory files itself (true), or will be commanded by another class (false) to do it. The latter is true for MC-OST, for example. -
totalSimTime
protected double totalSimTimeThe total simulation time. -
restartInterval
protected double restartIntervalTime between writing out restart/checkpoint files in picoseconds. -
restartFrequency
protected int restartFrequencyTime steps between writing out restart/checkpoint files. Set by the init method. -
trajectoryFrequency
protected int trajectoryFrequencyTime steps between adding a frame to the trajectory file. Set by the init method. -
logFrequency
protected int logFrequencyTime steps between logging information to the screen. Set by the init method. -
fileType
File type to use when saving files. -
done
protected boolean doneFlag to indicate a run has finished.
-
-
Constructor Details
-
MolecularDynamics
public MolecularDynamics(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator) Constructor for MolecularDynamics.- Parameters:
assembly
- aMolecularAssembly
object.potentialEnergy
- aPotential
object.listener
- aAlgorithmListener
object.requestedThermostat
- aThermostatEnum
object.requestedIntegrator
- aIntegratorEnum
object.
-
-
Method Details
-
dynamicsFactory
public static MolecularDynamics dynamicsFactory(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator) Method that determines whether a dynamics is done by the java implementation native to ffx or the OpenMM implementation- Parameters:
assembly
- aMolecularAssembly
object.potentialEnergy
- aPotential
object.listener
- aAlgorithmListener
object.requestedThermostat
- aThermostatEnum
object.requestedIntegrator
- aIntegratorEnum
object.- Returns:
- a
MolecularDynamics
object.
-
dynamicsFactory
public static MolecularDynamics dynamicsFactory(MolecularAssembly assembly, Potential potentialEnergy, AlgorithmListener listener, ThermostatEnum requestedThermostat, IntegratorEnum requestedIntegrator, MDEngine engine) dynamicsFactory.- Parameters:
assembly
- aMolecularAssembly
object.potentialEnergy
- aPotential
object.listener
- aAlgorithmListener
object.requestedThermostat
- aThermostatEnum
object.requestedIntegrator
- aIntegratorEnum
object.engine
- aMDEngine
object.- Returns:
- a
MolecularDynamics
object.
-
addAssembly
Adds a MolecularAssembly to be tracked by this MolecularDynamics. Note: does not affect the underlying Potential.- Parameters:
assembly
- A MolecularAssembly to be tracked.
-
attachExtendedSystem
attachExtendedSystem.- Parameters:
system
- aExtendedSystem
object.
-
setNonEquilibriumLambda
public void setNonEquilibriumLambda(boolean nonEquilibrium, int nEQSteps) Enables non-equilibrium lambda dynamics.- Parameters:
nonEquilibrium
- True if non-equilibrium lambda dynamics should be enabled.nEQSteps
- Number of lambda steps.
-
dynamic
public void dynamic(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, String fileType, double restartInterval, File dyn) Blocking molecular dynamics. When this method returns, the MD run is done.- Parameters:
nSteps
- Number of MD stepstimeStep
- Time step in femtosecondsloggingInterval
- Interval between printing/logging information in picoseconds.trajectoryInterval
- Interval between adding a frame to the trajectory file in picoseconds.temperature
- Temperature in Kelvins.initVelocities
- Initialize new velocities from a Maxwell-Boltzmann distribution.fileType
- XYZ or ARC to save to .arc, PDB for .pdb filesrestartInterval
- Interval between writing new restart files in picoseconds.dyn
- AFile
object to write the restart file to.
-
dynamic
public void dynamic(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, File dyn) Blocking molecular dynamics. When this method returns, the MD run is done.- Parameters:
nSteps
- Number of MD stepstimeStep
- Time step (fsec)loggingInterval
- Interval between printing/logging information in picoseconds.trajectoryInterval
- Interval between adding a frame to the trajectory file in picoseconds.temperature
- Temperature in Kelvins.initVelocities
- Initialize new velocities from a Maxwell-Boltzmann distribution.dyn
- AFile
object to write the restart file to.
-
getAssemblyArray
Returns the MolecularAssembly array.- Returns:
- A copy of the MolecularAssembly array.
-
getDynFile
Returns the associated dynamics file.- Returns:
- Dynamics restart File.
-
getInitialKineticEnergy
public double getInitialKineticEnergy()Gets the kinetic energy at the start of the last dynamics run.- Returns:
- Kinetic energy at the start of the run.
-
getInitialPotentialEnergy
public double getInitialPotentialEnergy()Gets the potential energy at the start of the last dynamics run.- Returns:
- potential energy at the start of the run.
-
getInitialTemperature
public double getInitialTemperature()Gets the temperature at the start of the last dynamics run.- Returns:
- temperature at the start of the run.
-
getInitialTotalEnergy
public double getInitialTotalEnergy()Gets the total energy at the start of the last dynamics run.- Returns:
- total energy at the start of the run.
-
getIntervalSteps
public int getIntervalSteps()getIntervalSteps.- Returns:
- Always 1 for this implementation.
-
setIntervalSteps
public void setIntervalSteps(int intervalSteps) No-op; FFX does not need to occasionally return information from FFX.- Parameters:
intervalSteps
- Ignored.
-
getKineticEnergy
public double getKineticEnergy()Get the system kinetic energy.- Returns:
- kinetic energy.
-
getPotentialEnergy
public double getPotentialEnergy()Get the system potential energy.- Returns:
- potential energy.
-
getTemperature
public double getTemperature()Get the current temperature of the system- Returns:
- currentTemperature
-
getThermostat
Getter for the fieldthermostat
.- Returns:
- a
Thermostat
object.
-
setThermostat
Setter for the fieldthermostat
.- Parameters:
thermostat
- aThermostat
object.
-
getTimeStep
public double getTimeStep()getTimeStep.- Returns:
- Time step in picoseconds.
-
getTotalEnergy
public double getTotalEnergy()Get the total system energy (kinetic plus potential).- Returns:
- total energy.
-
getVerbosityLevel
-
setVerbosityLevel
-
init
public void init(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, String fileType, double restartInterval, double temperature, boolean initVelocities, File dyn) init- Parameters:
nSteps
- Number of MD stepstimeStep
- Time step in femtosecondsloggingInterval
- Interval between printing/logging information in picoseconds.trajectoryInterval
- Interval between adding a frame to the trajectory file in picoseconds.fileType
- XYZ or ARC to save to .arc, PDB for .pdb filesrestartInterval
- Interval between writing new restart files in picoseconds.temperature
- Temperature in Kelvins.initVelocities
- Initialize new velocities from a Maxwell-Boltzmann distribution.dyn
- AFile
object to write the restart file to.
-
init
public void init(long nSteps, double timeStep, double loggingInterval, double trajectoryInterval, double temperature, boolean initVelocities, File dyn) A version of init with the original method header. Redirects to the new method with default values for added parameters. Needed by (at least) ReplicaExchange, which calls this directly.- Parameters:
nSteps
- Number of MD stepstimeStep
- Time step in femtosecondsloggingInterval
- Interval between printing/logging information in picoseconds.trajectoryInterval
- Interval between adding a frame to the trajectory file in picoseconds.temperature
- Temperature in Kelvins.initVelocities
- Initialize new velocities from a Maxwell-Boltzmann distribution.dyn
- AFile
object to write the restart file to.
-
run
public void run() -
setAutomaticWriteouts
public void setAutomaticWriteouts(boolean autoWriteout) Enable or disable automatic writeout of trajectory snapshots and restart files.Primarily intended for use with MC-OST, which handles the timing itself.
- Parameters:
autoWriteout
- Whether to automatically write out trajectory and restart files.
-
setFallbackDynFile
Sets the "fallback" .dyn file to write to if none is passed to the dynamic method.- Parameters:
fallback
- Fallback dynamics restart file.
-
setFileType
Method to set file type from groovy scripts.- Parameters:
fileType
- the type of snapshot files to write.
-
setObtainVelAcc
public void setObtainVelAcc(boolean obtainVA) Not meaningful for FFX dynamics (no need to obtain velocities/accelerations from a different program, especially one running on a GPU). Is a no-op.- Parameters:
obtainVA
- Not meaningful for this implementation.
-
setRestartFrequency
Method to set the Restart Frequency.- Parameters:
restartInterval
- Time in ps between writing restart files.- Throws:
IllegalArgumentException
- If restart frequency is not a positive number
-
setArchiveFiles
Set the archive file for each MolecularAssembly.- Parameters:
archiveFiles
- An array of archive files.
-
terminate
public void terminate()This should be implemented as a blocking interrupt; when the method returns theTerminatable
algorithm has reached a clean termination point. For example, between minimize or molecular dynamics steps.- Specified by:
terminate
in interfaceTerminatable
-
writeFilesForStep
Write restart and trajectory files if the provided step matches the frequency and that file type is requested.- Parameters:
step
- Step to write files (if any) for.trySnapshot
- If false, do not write snapshot even if the time step is correct.tryRestart
- If false, do not write a restart file even if the time step is correct.- Returns:
- EnumSet of actions taken by this method.
-
writeFilesForStep
public EnumSet<MDWriteAction> writeFilesForStep(long step, boolean trySnapshot, boolean tryRestart, String[] extraLines) Write restart and trajectory files if the provided step matches the frequency and that file type is requested.- Parameters:
step
- Step to write files (if any) for.trySnapshot
- If false, do not write snapshot even if the time step is correct.tryRestart
- If false, do not write a restart file even if the time step is correct.extraLines
- Additional lines to append into the comments section of the snapshot (or null).- Returns:
- EnumSet of actions taken by this method.
-
writeRestart
public void writeRestart()Write out a restart file. -
appendSnapshot
Append a snapshot to the trajectory file.- Parameters:
extraLines
- Strings of meta-data to include.
-
logThermoForTime
protected long logThermoForTime(long step, long time) Checks if thermodynamics must be logged. If logged, current time is returned, else the time passed in is returned.- Parameters:
step
- Time step to possibly log thermodynamics for.time
- Clock time (in nsec) thermodynamics was last logged.- Returns:
- Either current time (if logged), else the time variable passed in.
-
setCoordinates
public void setCoordinates(double[] coords) Set the coordinates.- Parameters:
coords
- The coordinates to copy into MD coordinates array.
-
getCoordinates
public double[] getCoordinates()Get the coordinates.- Returns:
- A copy of the current coordinates are returned.
-
storeState
public void storeState()Store the current state of the molecular dynamics simulation in a MDState record. -
revertState
Revert the state of the MolecularDynamics instance to the stored MDState.- Throws:
Exception
- is thrown if the stored state is null.
-