FES and sampling¶
fes_ml.fes.FES
¶
A class to perform free energy calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
alchemical_states |
list of AlchemicalState
|
List of alchemical states. |
output_prefix |
str
|
Prefix for the output files. |
checkpoint_frequency |
int
|
Frequency to save the state of the object. |
checkpoint_file |
str
|
Path to the checkpoint file. |
_iter |
int
|
Current iteration. |
_alc_id |
int
|
Current alchemical state id. |
_positions |
postions vectors
|
Current positions. |
_pbc |
pbc vectors
|
Current periodic box vectors. |
_U_kl |
list of list float
|
Potential energies sampled at a single state k and evaluated at all states l. |
_U_kln |
list of list of list float
|
Potential energies sampled at a all states k and evaluated at all states l. |
_create_alchemical_states_args |
tuple
|
Arguments to recreate the alchemical states upon deserialization. |
_create_alchemical_states_kwargs |
dict
|
Keyword arguments to recreate the alchemical states upon deserialization. |
_lambda_schedule |
dict
|
Dictionary with the λ values for the alchemical states. |
_alchemical_atoms |
list of int
|
List of atom indices to be alchemically modified. |
provenance_file
property
¶
The JSON file with the provenance records of the run.
provenance
property
¶
The provenance records of the run: one for each start or restart of a window.
create_alchemical_states(lambda_schedule, alchemical_atoms=None, modifications_kwargs=None, strategy_name=None, *args, **kwargs)
¶
Create a batch of alchemical states for the given λ values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lambda_schedule
|
dict
|
Dictionary with the λ values for the alchemical states. |
required |
alchemical_atoms
|
list of int or dict of str to list of int
|
Atom indices to be alchemically modified, or a dictionary mapping alchemical
group names (the |
None
|
modifications_kwargs
|
dict
|
A dictionary of keyword arguments for the modifications. It is structured as follows: { "modification_name": { "key1": value1, "key2": value2, ... }, ... } |
None
|
strategy_name
|
str
|
The name of the strategy that builds the System: "openff" (SMILES or SDF input)
or "sire" (Amber topology and coordinates in |
'openff'
|
Returns:
| Name | Type | Description |
|---|---|---|
alchemical_states |
list of AlchemicalState
|
List of alchemical states. |
set_velocities(temperature, window=None, alchemical_state=None)
¶
Set the velocities of the alchemical states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
Quantity or float
|
Temperature of the system in Kelvin. |
required |
window
|
int
|
Window index. |
None
|
alchemical_state
|
AlchemicalState
|
Alchemical state to set the velocities. |
None
|
minimize(tolerance=10 * _unit.kilojoules_per_mole / _unit.nanometer, max_iterations=0, reporter=None, window=None, alchemical_state=None)
¶
Minimize
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
Quantity
|
The energy tolerance to which the system should be minimized. |
10 * kilojoules_per_mole / nanometer
|
max_iterations
|
int
|
The maximum number of iterations to run the minimization. |
0
|
reporter
|
OpenMM Minimization Report
|
A reporter object to report the minimization progress. See http://docs.openmm.org/latest/api-python/generated/openmm.openmm.MinimizationReporter.html |
None
|
window
|
int
|
Window index. |
None
|
alchemical_state
|
AlchemicalState
|
Alchemical state to minimize. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
alchemical_states |
list of AlchemicalState
|
List of alchemical states. |
equilibrate(nsteps, alchemical_state=None, window=None, reporters=None)
¶
Equilibrate batch of alchemical states..
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nsteps
|
int
|
Number of steps to run each equilibration. |
required |
window
|
int
|
Window index. |
None
|
alchemical_state
|
AlchemicalState
|
Alchemical state to equilibrate. |
None
|
reporters
|
list of OpenMM reporters, or function
|
Reporters for the simulation. A list goes to every window. A function gets the
window index and gives the reporters of that window, for example
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
alchemical_states |
list of AlchemicalState
|
List of alchemical states. |
run_single_state(niterations, nsteps, alchemical_state=None, window=None, reporters=None)
¶
Run a simulation for a given alchemical state or window index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
niterations
|
int
|
Number of iterations to run the simulations. |
required |
nsteps
|
int
|
Number of steps per iteration. |
required |
alchemical_state
|
AlchemicalState
|
Alchemical state to run the simulation. |
None
|
window
|
int
|
Window index. alchemical_state takes precedence over window. |
None
|
reporters
|
list of OpenMM reporters, or function
|
Reporters for the simulation. A list goes to every window. A function gets the
window index and gives the reporters of that window, for example
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
U_kl |
list of list float
|
Potential energies of the sampled configurations evaluated for the various alchemical states. |
run_production_batch(niterations, nsteps, reporters=None)
¶
Run simulations for all alchemical states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
niterations
|
int
|
Number of iterations to run the simulations. |
required |
nsteps
|
int
|
Number of steps per iteration. |
required |
reporters
|
list of OpenMM reporters, or function
|
Reporters for the simulation. A list goes to every window. A function gets the
window index and gives the reporters of that window, for example
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
u_kln |
ndarray
|
Array with the potential energies of the simulations. |
fes_ml.checkpoint
¶
Checkpoints of a free-energy run, as plain data (R4).
A checkpoint stores what is needed to resume: progress counters, the reduced potentials sampled
so far, the last configuration (NumPy arrays in nm), and the arguments that created the
alchemical states. It no longer pickles the FES object, so renaming an attribute of FES
cannot break restarts. The file is still a pickle, because the creation arguments may hold
arbitrary objects (integrators, quantities). Checkpoints written by older versions, which pickled
FES.__dict__, are read too.
fes_ml.sampling
¶
Energy evaluation shared by the samplers, and λ windows that share one OpenMM Context (R3, R4).
SharedContext
¶
One OpenMM Context that serves several λ windows (R3).
Each window is a set of global-parameter values. Switching window with :meth:activate saves the
coordinates and velocities of the window that was active and restores those of the new one, so
each window keeps its own trajectory, as it would with its own Context.
thermal_energy(state)
¶
kT (per mole) at the temperature of the state's integrator.
reduced_potentials(states, positions, box_vectors, kT)
¶
Reduced potential energy u = U / kT of one configuration in every state.
States that share a Context get the configuration once and are evaluated by changing the global parameters; the parameters of the window that Context simulates are restored afterwards.
fes_ml.mts.MTS
¶
Class with various utility functions for the Multiple Timestep (MTS) integrator.
create_integrator(dt, groups, temperature=298.15 * _unit.kelvin, friction=1.0 / _unit.picosecond, type='langevin')
¶
Create the MTS integrator.
For more information on the MTS integrator, see the OpenMM documentation: - Langevin: http://docs.openmm.org/latest/api-python/generated/openmm.mtsintegrator.MTSLangevinIntegrator.html - MTS: http://docs.openmm.org/7.0.0/api-python/generated/simtk.openmm.mtsintegrator.MTSIntegrator.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
Union[float, Quantity]
|
The largest (outermost) integration timestep. |
required |
groups
|
List[Tuple[int, int]]
|
A list of tuples defining the force groups. The first element of each tuple is the force group index, and the second element is the number of times that force group should be evaluated in one time step. 0 should be the slowest force group. |
required |
temperature
|
Union[float, Quantity]
|
The temperature of the system. |
298.15 * kelvin
|
friction
|
Union[float, Quantity]
|
The friction coefficient. |
1.0 / picosecond
|
type
|
str
|
The type of integrator. Options are "langevin" or "mts". |
'langevin'
|
Returns:
| Name | Type | Description |
|---|---|---|
integrator |
Any
|
MTS integrator. |
set_force_groups(alchemical_states=None, force_group_dict=None, set_reciprocal_space_force_groups=None)
¶
Set the force groups for the alchemical states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alchemical_states
|
list of AlchemicalState
|
List of alchemical states to set the force groups. If not provided, the alchemical states set in the object initialization are used. |
None
|
force_group_dict
|
dict
|
Dictionary with the force group for each force. |
None
|
set_reciprocal_space_force_groups
|
Optional[int]
|
Which group to set the reciprocal space force group to. By default, this is not set seperately. |
None
|
Notes
- If a group is not provided, all forces are set to the fastest force group.
fes_ml.log.config_logger(banner=True)
¶
Print log messages to stdout (root logger), at the level in FES_ML_LOG_LEVEL (default INFO).
Messages from other packages are shown too, unless FES_ML_FILTER_LOGGERS=1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
banner
|
bool
|
Log the fes-ml banner with the version. |
True
|
fes_ml.provenance
¶
Provenance: how a result was made.
A free energy depends on more than the input files: the versions of fes-ml, OpenMM, Sire and the
ML packages, the platform and its precision, the integrator and its seed, and the settings of the
forces in the System. :func:collect records these as plain JSON data, so that you can find the
results that a bug in one version changes, and so that windows from different setups are not mixed.
package_versions(packages=PACKAGES)
¶
The installed version of each package in packages.
git_commit(path=None)
¶
The commit of the git checkout that holds path (fes-ml by default), with +dirty for local changes.
force_summary(force)
¶
The settings of a force that change its energy.
system_summary(system)
¶
The size of a System and the settings of its forces.
integrator_summary(integrator)
¶
The type, step size, temperature, friction and seed of an integrator.
platform_summary(context)
¶
The platform of a Context and the values of its properties, such as the precision and the device.
jsonable(value)
¶
value as JSON data. Quantities keep their unit, and other objects become their repr.
collect(alchemical_states=None, settings=None)
¶
Record how a result is made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alchemical_states
|
list of AlchemicalState
|
The states of the run. The record has the platform, the integrator and a summary of the System of each state. |
None
|
settings
|
dict
|
The settings of the run, for example the arguments of |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
JSON data. |
differences(old, new)
¶
The differences between two records that can change energies: package versions, the fes-ml commit, and the platform and integrator of each state. Hosts, dates and run lengths are not compared.
write(records, path)
¶
Write provenance records as JSON. The file is replaced in one step, so a crash does not leave half a file.