Class MolecularDynamics

java.lang.Object
ffx.algorithms.dynamics.MolecularDynamics
All Implemented Interfaces:
Terminatable, Runnable
Direct Known Subclasses:
MolecularDynamicsOpenMM

public class MolecularDynamics extends Object implements Runnable, Terminatable
Run NVE, NVT, or NPT molecular dynamics.
Since:
1.0
Author:
Michael J. Schnieders
  • Field Details

    • molecularAssembly

      protected MolecularAssembly[] molecularAssembly
      MolecularAssembly to run dynamics on.

      For dual or quad topology simulations, this is an array of length 2 or 4.

    • algorithmListener

      protected final AlgorithmListener algorithmListener
      An Algorithm Listener to send updates to the GUI.
    • state

      protected final SystemState state
      Stores the current molecular dynamics state.
    • initialState

      protected UnmodifiableState initialState
      State of the system as of the last init call (and start of the last dynamics run).
    • dt

      protected double dt
      The time step (picoseconds).

      The method setTimeStep should always be used to set this value.

    • initVelocities

      protected boolean initVelocities
      Flag to indicate velocities should be initialized.
    • automaticWriteouts

      protected boolean automaticWriteouts
      Whether 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 totalSimTime
      The total simulation time.
    • restartInterval

      protected double restartInterval
      Time between writing out restart/checkpoint files in picoseconds.
    • restartFrequency

      protected int restartFrequency
      Time steps between writing out restart/checkpoint files. Set by the init method.
    • trajectoryFrequency

      protected int trajectoryFrequency
      Time steps between adding a frame to the trajectory file. Set by the init method.
    • logFrequency

      protected int logFrequency
      Time steps between logging information to the screen. Set by the init method.
    • fileType

      protected String fileType
      File type to use when saving files.
    • done

      protected boolean done
      Flag to indicate a run has finished.
  • Constructor Details

  • 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 - a MolecularAssembly object.
      potentialEnergy - a Potential object.
      listener - a AlgorithmListener object.
      requestedThermostat - a ThermostatEnum object.
      requestedIntegrator - a IntegratorEnum 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 - a MolecularAssembly object.
      potentialEnergy - a Potential object.
      listener - a AlgorithmListener object.
      requestedThermostat - a ThermostatEnum object.
      requestedIntegrator - a IntegratorEnum object.
      engine - a MDEngine object.
      Returns:
      a MolecularDynamics object.
    • addAssembly

      public void addAssembly(MolecularAssembly assembly)
      Adds a MolecularAssembly to be tracked by this MolecularDynamics. Note: does not affect the underlying Potential.
      Parameters:
      assembly - A MolecularAssembly to be tracked.
    • attachExtendedSystem

      public void attachExtendedSystem(ExtendedSystem system, double reportFreq)
      attachExtendedSystem.
      Parameters:
      system - a ExtendedSystem 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 steps
      timeStep - Time step in femtoseconds
      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.
      fileType - XYZ or ARC to save to .arc, PDB for .pdb files
      restartInterval - Interval between writing new restart files in picoseconds.
      dyn - A File 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 steps
      timeStep - 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 - A File object to write the restart file to.
    • getAssemblyArray

      public MolecularAssembly[] getAssemblyArray()
      Returns the MolecularAssembly array.
      Returns:
      A copy of the MolecularAssembly array.
    • getDynFile

      public File 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

      public Thermostat getThermostat()
      Getter for the field thermostat.
      Returns:
      a Thermostat object.
    • setThermostat

      public void setThermostat(Thermostat thermostat)
      Setter for the field thermostat.
      Parameters:
      thermostat - a Thermostat 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

      public MDVerbosity getVerbosityLevel()
    • setVerbosityLevel

      public void setVerbosityLevel(MDVerbosity level)
    • 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 steps
      timeStep - Time step in femtoseconds
      loggingInterval - 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 files
      restartInterval - Interval between writing new restart files in picoseconds.
      temperature - Temperature in Kelvins.
      initVelocities - Initialize new velocities from a Maxwell-Boltzmann distribution.
      dyn - A File 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 steps
      timeStep - Time step in femtoseconds
      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 - A File object to write the restart file to.
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • 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

      public void setFallbackDynFile(File fallback)
      Sets the "fallback" .dyn file to write to if none is passed to the dynamic method.
      Parameters:
      fallback - Fallback dynamics restart file.
    • setFileType

      public void setFileType(String fileType)
      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

      public void setRestartFrequency(double restartInterval) throws IllegalArgumentException
      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

      public void setArchiveFiles(File[] archiveFiles)
      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 the Terminatable algorithm has reached a clean termination point. For example, between minimize or molecular dynamics steps.
      Specified by:
      terminate in interface Terminatable
    • writeFilesForStep

      public EnumSet<MDWriteAction> 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.
      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

      protected void appendSnapshot(String[] extraLines)
      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

      public void revertState() throws Exception
      Revert the state of the MolecularDynamics instance to the stored MDState.
      Throws:
      Exception - is thrown if the stored state is null.