Skip to content

Running simulations

FES creates the alchemical states, runs them, and checkpoints the run.

from fes_ml import FES

fes = FES(output_prefix="run", checkpoint_frequency=10)
fes.create_alchemical_states(lambda_schedule=schedule, alchemical_atoms=ligand, strategy_name="sire",
                             top_file="system.prm7", crd_file="system.rst7")
fes.minimize(max_iterations=1000)
fes.equilibrate(100_000)
U_kln = fes.run_production_batch(niterations=1000, nsteps=1000)
  • minimize(tolerance=..., max_iterations=0, window=None) minimises every state, or one window.
  • equilibrate(nsteps, window=None) runs nsteps of dynamics on every state, or one window.
  • run_production_batch(niterations, nsteps) samples every state in turn. After each block of nsteps it evaluates the configuration in every state, so U_kln[k][l][n] is the reduced potential (energy / kT) of sample n from state k evaluated in state l.
  • Each window also writes its samples to <output_prefix>_window_<k>.h5. See Output files and analysis to get the free energy with MBAR.

One window per job

To spread the windows over several jobs or GPUs, run one window in each:

fes.run_single_state(niterations=1000, nsteps=1000, window=6)  # writes <output_prefix>_window_6.h5

Every job still creates all the states, because each sample is evaluated in all of them.

One Context for all windows

With shared_context=True, fes-ml builds one System and one OpenMM Context, and each window is a set of λ global-parameter values:

fes.create_alchemical_states(lambda_schedule=schedule, alchemical_atoms=ligand, strategy_name="sire",
                             top_file="system.prm7", crd_file="system.rst7", shared_context=True)

The states are created once instead of once per window, and use the GPU memory of one Context; with ML potentials, one copy of the model. Each window still keeps its own coordinates and velocities: they are saved and restored when the Context switches window. Every λ that changes between windows must be a global parameter (see λ schedules), and None is not allowed in the schedule, since leaving a modification out changes the System.

Checkpoints and restarts

Every checkpoint_frequency iterations, FES writes <output_prefix>.pickle and the OpenMM state of the running window. With restart=True (the default), a new FES with the same output_prefix reads the checkpoint and continues where the run stopped:

fes = FES(output_prefix="run", restart=True, recreate_alchemical_states=True)
U_kln = fes.run_production_batch(1000, 1000)

With recreate_alchemical_states=True the states are created again from the arguments stored in the checkpoint; otherwise call create_alchemical_states yourself before continuing.

The checkpoint holds plain data: progress counters, the reduced potentials so far, positions and box (NumPy, nm) and the arguments that created the states. It does not depend on the attributes of FES, and checkpoints written by older fes-ml versions are still read.

Provenance

Each time a window starts or restarts, FES adds a record to <output_prefix>_provenance.json and to the checkpoint. A record has:

  • the versions of fes-ml, OpenMM, NumPy, Sire, OpenFF and the ML packages, and the git commit of fes-ml when it is installed from a checkout;
  • the host, the date, CUDA_VISIBLE_DEVICES and the Slurm job ID;
  • the platform of the window and its properties, for example the precision and the device;
  • the integrator: type, step size, temperature, friction and random seed. A seed of 0 means that OpenMM chose a random seed, which it does not report;
  • the forces of the System, with the settings that change energies, for example the cutoff, the PME tolerance and the dispersion correction;
  • the lambda schedule, the alchemical atoms and the options of the modifications and the strategy.

Use these records to find the results that a bug in one version changes. When a run restarts with other package versions, another fes-ml commit, or another platform or integrator, FES logs a warning. fes.provenance gives the records of a run.

Working files

Each state is built in its own directory tmp_fes_ml_<strategy>_* in the current directory. It is kept by default; pass keep_tmp_files=False to remove it once the state is built. Pass work_dir=... to use your own directory; that one is never deleted. AlchemicalState.work_dir says where a state's files are.

Multiple time stepping

fes_ml.MTS sets up multiple-time-step integration, so that the expensive ML forces are evaluated less often than the MM forces; see the API reference.