Running Dynamics#
Note
We may drop this part of Cascade as we continue building. Don’t bother learning this yet.
The DynamicsProtocol
class from Cascade propagates a dynamic system
using the learned surrogate and returns copies of the system at many timesteps for use
by the Auditing code.
Create a Dynamics class by defining what happens in each stage of a process as a DynamicsStage
:
Which type of dynamics, as an ASE Dynamics class (e.g., an optimizer or molecular dynamics method)
Maximum number of timesteps. Use
None
to run until convergence is reachedOptions to Dynamics, such as the temperature for molecular dynamics or time per timestep
Options for the run method, such as the convergence threshold
Post-processing function applied after run is complete, which modifies the Atoms object as the list stage.
A dynamics process could have multiple stages, such as an optimization followed by molecular dynamics under several different control conditions.
# Optimization then constant-energy molecular dynamics
dyn_stages = [
DynamicsStage(BFGS, 100, {}, {'fmax': 0.001}, partial(MaxwellBoltzmannDistribution, temperature_K=300)),
DynamicsStage(VelocityVerlet, 100, {'timestep': 0.5}, {}, None)
]
dyn = DynamicsProtocol(stages=dyn_stages)
The Progress
of a single trajectory along the dynamics is defined by which stage it is running
and how many timesteps it has completed along that process.
Run the dynamics by passing the starting state, a surrogate model, and a maximum number of timestep to run. The dynamics process will return whether the current process was completed and a series of snapshots along the trajectory.
start = Progress(atoms)
done, traj = dyn.run_dynamics(start, model_msg, TorchANI(), 100)
Use an auditing strategy to determine whether the surrogate model was reliable during the last call to the dynamics
and, if so, increment the Progress through its update()
method before
continuing to propagate the dynamics.
if audit(traj):
start.update(traj[-1], steps_completed=100, finished_stage=done)
done, traj = dyn.run_dynamics(start, example_model, TorchANI(), 5)