Skip to content

Alchemist and states

fes_ml.alchemical.alchemist.Alchemist

Build and apply a graph of alchemical modifications to an OpenMM system.

Building the graph has three steps:

  1. Inclusion. Starting from the requested modifications, follow pre_dependencies and post_dependencies within each alchemical group. Modifications named in excludes (or the old skip_dependencies) by any included modification of the same group are left out before any edge is made.
  2. Merging. Dependencies of the same kind with the same alchemical atoms are one node, which keeps the ordering edges of every copy. Partly overlapping atoms are an error.
  3. Ordering. Topological order of the dependency edges, with ties broken by each modification's phase and then by name, so the order does not depend on how the lambda schedule is written.

graph property

The graph of alchemical modifications (nodes are Name:group strings).

register_modification(name, modification) staticmethod

Register a modification under name (the Name in Name:group).

modification is a BaseModification subclass (preferred), or, as before, a BaseModificationFactory instance or subclass.

register_modification_factory(name, factory) staticmethod

Register a modification (kept for compatibility; see :meth:register_modification).

add_modification(name, factory)

Add a modification to the Alchemist graph.

Parameters:

Name Type Description Default
name str

The name of the modification.

required
factory BaseModificationFactory

The factory to create the modification.

required

plot_graph()

Plot the graph of the alchemical modifications.

reset_alchemical_graph()

Reset the graph of alchemical modifications.

remove_modification_from_graph(modification)

Remove modification from the graph of alchemical modifications.

Parameters:

Name Type Description Default
modification str

Name of the node to remove

required

modifications()

The modification instances of the graph, in application order.

application_order()

The order in which :meth:apply_modifications applies the modifications.

create_alchemical_graph(lambda_schedule, additional_modifications=None, modifications_kwargs=None, alchemical_groups=None)

Create a graph of alchemical modifications to apply.

Parameters:

Name Type Description Default
lambda_schedule dict

A dictionary of λ values to be applied to the system.

required
additional_modifications list of str

Additional modifications to apply (with no λ value).

None
modifications_kwargs dict

A dictionary of keyword arguments for the modifications. It is not changed. An alchemical_atoms entry sets the atoms of that modification and of the dependencies it brings in (prefer alchemical_groups).

None
alchemical_groups list of int or dict of str to list of int

The atoms of each alchemical group (a list is the default group). When a dictionary is given, every group used in lambda_schedule must be declared.

None

Returns:

Type Description
DiGraph

The graph of the modifications to apply.

apply_modifications(system, alchemical_atoms, modifications_kwargs, *args, **kwargs)

Apply the alchemical modifications to the system.

Parameters:

Name Type Description Default
system System

The system to be modified.

required
alchemical_atoms list of int

The alchemical atoms of modifications that were not given their own.

required
modifications_kwargs dict

A dictionary of keyword arguments for the modifications, keyed by Name:group, or by Name for every group without its own entry: { "modification_name": { "key1": value1, "key2": value2, ... }, ... }

required
args list

Additional arguments to be passed to the modifications.

()
kwargs dict

Additional keyword arguments to be passed to the modifications.

{}

Returns:

Type Description
System

The modified system.

fes_ml.alchemical.alchemical_state.AlchemicalState dataclass

A dataclass representing the alchemical state of a molecular system.

Attributes:

Name Type Description
system System

The OpenMM system associated with the alchemical state.

context Context

The OpenMM context associated with the alchemical state.

integrator Integrator

The OpenMM integrator associated with the alchemical state.

simulation Simulation

The OpenMM simulation associated with the alchemical state.

topology Topology

The OpenMM topology associated with the alchemical state.

modifications dict

Dictionary mapping the name of the alchemical modifications applied to the system to the λ value.

work_dir (str, optional)

Directory with the files the creation strategy wrote for this state (None if removed).

parameters (dict, optional)

Global-parameter values that define this window when it shares its Context with other windows (FES.create_alchemical_states(..., shared_context=True)).

shared (SharedContext, optional)

The shared Context, or None if the state has a Context of its own.

levers (dict, optional)

Callbacks that change lambdas held outside OpenMM (EMLE's calculator), by parameter name.

activate()

Make the Context simulate this window (a no-op unless the Context is shared).

check_integrity()

Check that the state holds OpenMM objects and a modifications dict; raise TypeError if not.

fes_ml.alchemical.groups

Alchemical groups: named sets of atoms that modifications act on.

normalise_alchemical_groups(alchemical_atoms)

Return the alchemical groups as {group: atoms}.

Parameters:

Name Type Description Default
alchemical_atoms list of int or dict of str to list of int

A list is the default group. A dictionary maps group names (as used in "Name:group" keys of the lambda schedule) to atom indices.

required

Raises:

Type Description
ValueError

If a group name is invalid, a group is empty, or two groups partly overlap. Groups must be identical or disjoint.

all_alchemical_atoms(groups)

Sorted union of the atoms of all groups.