Modifications¶
fes_ml.alchemical.modifications.base_modification.BaseModification
¶
Bases: ABC
Base class for defining modifications to an OpenMM system.
Specifications for modifications in fes-ml:
- A modification alters the base OpenMM system.
- A modification can be independent or dependent on other modifications.
- If modification A requires B, and B must run before A, add B to A's
pre_dependenciesclass-level attribute. - If modification A implies B, and B must run after A, add B to A's
post_dependenciesclass-level attribute. - If B must not be applied to the same alchemical group when A is,
even if another modification requires it, add B to A's
excludes. (skip_dependenciesis the old name and is still read.) - Dependencies belong to the alchemical group of the modification that
requires them, and inherit its
alchemical_atomsunless they are given their own inmodifications_kwargs. - If several modifications require B with the same atoms, B is applied once.
- Modifications are applied in topological order of the dependency
graph. Ties are broken by
phase(see :class:Phase), then by name. - A modification must have a default key controlled by the class-level
attribute
NAME. - A modication can also have a custom name by passing a string
modification_namewhen instantiating the modification. This allows multiple instances of the same modification to coexist in the same system, each with its own parameters. - Modifications can be applied by passing a lambda schedule
dictionary when creating alchemical states. This dictionary
maps
NAMEs to λ values for eachAlchemicalState.
Implementing new modifications:
- To define a new modification, create a subclass of
BaseModificationandBaseModificationFactory. - Every
BaseModificationsubclass must implement the apply method to define the modification on the OpenMM system and override theNAMEclass-level attribute.
lambda_levers
property
¶
Callbacks that change a lambda held outside OpenMM, by name, set by apply (R3).
A shared Context calls them together with Context.setParameter for the same name.
lambda_parameter
property
¶
Global parameter that holds this modification's lambda in the modified System, or None (R3).
With a parameter, another lambda value only needs Context.setParameter; without one,
the lambda is built into the System.
alchemical_group
property
¶
Get the suffix of the current instance name.
Returns:
| Type | Description |
|---|---|
str
|
The suffix part after ':' if present, empty string otherwise. |
lambda_lever_for(group)
classmethod
¶
Name of the external lambda lever of group, or None.
lambda_parameter_for(group)
classmethod
¶
Global parameter holding the lambda of group: the base name, suffixed for named groups.
apply(*args, **kwargs)
abstractmethod
¶
Apply the modification to the system.
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
add_pre_dependency(name, beggining=False)
classmethod
¶
Add a pre-dependency to this modification class (beggining puts it first).
remove_pre_dependency(name)
classmethod
¶
Remove a pre-dependency from this modification class.
add_post_dependency(name, beggining=False)
classmethod
¶
Add a post-dependency to this modification class (beggining puts it first).
remove_post_dependency(name)
classmethod
¶
Remove a post-dependency from this modification class.
find_forces_by_group(system, group)
staticmethod
¶
Find all forces in the system that belong to a given alchemical group.
Notes
Alchemical groups are defined by suffixes in the force names, e.g. LJSoftCore:region1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The OpenMM system to search. |
required |
group
|
str
|
The alchemical group to match, without the colon (e.g. |
required |
Returns:
| Type | Description |
|---|---|
List[Force]
|
List of forces whose names end with the specified alchemical group. |
find_force_by_name(system, force_name)
staticmethod
¶
Find a force in the system by its full name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The OpenMM system to search. |
required |
force_name
|
str
|
The name of the force to find. |
required |
Returns:
| Type | Description |
|---|---|
Force
|
The force with the specified name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no force with the specified name is found. |
fes_ml.alchemical.modifications.base_modification.Phase
¶
Bases: IntEnum
Coarse stage of a modification, used to order modifications that have no dependency between them.
Dependencies always take precedence; the phase only breaks ties, so the order no longer depends on the order of the keys in the lambda schedule.
fes_ml.alchemical.modifications.lj_softcore.LJSoftCoreModification
¶
Bases: BaseModification
Class to add a softcore Lennard-Jones potential to the System.
apply(system, alchemical_atoms, lambda_value=1.0, include_repulsion=True, include_attraction=True, useSwitchingFunction=None, useLongRangeCorrection=None, *args, **kwargs)
¶
Apply the LJ soft core modification to the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to be modified. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the system. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
1.0
|
include_repulsion
|
bool
|
Whether to include the short-range repulsive term (r^-12 component). Default is True. |
True
|
include_attraction
|
bool
|
Whether to include the long-range attractive term (r^-6 component). Default is True. |
True
|
useSwitchingFunction
|
bool
|
Whether to use a switching function for the softcore LJ interactions. If None, the value from the original NonbondedForce will be used. |
None
|
useLongRangeCorrection
|
bool
|
Whether to use long-range dispersion correction for the softcore LJ interactions. If None, the value from the original NonbondedForce will be used. |
None
|
args
|
tuple
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
fes_ml.alchemical.modifications.charge_scaling.ChargeScalingModification
¶
Bases: BaseModification
Class to scale the charges of the alchemical atoms in the System.
lambda_parameter
property
¶
lambda_electrostatics[_<group>] once applied (None if applied with use_global_parameter=False).
apply(system, alchemical_atoms, lambda_value, use_global_parameter=True, *args, **kwargs)
¶
Scale the charges of the alchemical atoms in the System.
Only the intermolecular interactions are affected by this modification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The System to modify. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the System. |
required |
use_global_parameter
|
bool
|
Keep lambda in the global parameter |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The modified System with the charges scaled. |
fes_ml.alchemical.modifications.ml_potential.MLPotentialModification
¶
Bases: MLBaseModification, BaseModification
Class to add a ML potential to the System.
apply(system, alchemical_atoms, topology, name='ani2x', modelPath=None, forceGroup=0, *args, **kwargs)
¶
Add a ML potential to the System.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The System to modify. |
required |
alchemical_atoms
|
list of int
|
The indices of the atoms to model with the ML potential. |
required |
topology
|
Topology
|
The Topology of the System. |
required |
name
|
str
|
The name of the ML potential to use. |
'ani2x'
|
modelPath
|
str
|
The path to the deployed model. |
None
|
forceGroup
|
int
|
The force group to assign the ML potential forces to. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The modified System. |
fes_ml.alchemical.modifications.ml_interpolation.MLInterpolationModification
¶
Bases: MLBaseModification, BaseModification
Class to add a CustomCVForce to interpolate between ML and MM forces.
apply(system, alchemical_atoms, lambda_value, *args, **kwargs)
¶
Apply the ML interpolation modification to the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to be modified. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the system. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
required |
args
|
tuple
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
Notes
This code is heavily inspired on https://github.com/openmm/openmm-ml/blob/main/openmmml/mlpotential.py#L190-L351.
fes_ml.alchemical.modifications.ml_correction.MLCorrectionModification
¶
Bases: MLBaseModification, BaseModification
Class to add a CustomCVForce that is a Δ ML correction.
apply(system, alchemical_atoms, lambda_value, *args, **kwargs)
¶
Apply the ML interpolation modification to the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to be modified. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the system. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
required |
args
|
tuple
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
Notes
This code is heavily inspired on this https://github.com/openmm/openmm-ml/blob/main/openmmml/mlpotential.py#L190-L351.
fes_ml.alchemical.modifications.emle_potential.EMLEPotentialModification
¶
Bases: BaseModification
Modification to add the EMLE potential to the OpenMM System.
apply(system, alchemical_atoms, lambda_value, mols, parm7, mm_charges, openmm_charges=None, backend=None, method='electrostatic', torch_model=False, cutoff='12A', neighbour_list_frequency=0, device=None, *args, **kwargs)
¶
Add the EMLE potential to the OpenMM system.
Note that the charges of the atoms in the alchemical region are set to zero, which may interfere with other modifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The OpenMM System to modify. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the System. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
required |
mols
|
Molecule
|
The molecular system. |
required |
parm7
|
str
|
The path to the topology file. |
required |
mm_charges
|
ndarray
|
The charges of the atoms in the ML region. |
required |
args
|
list
|
Additional arguments to be passed to the EMLE calculator. |
()
|
backend
|
str
|
The backend to use for the EMLE calculation. |
None
|
method
|
str
|
The method to use for the EMLE calculation. |
"electrostatic"
|
torch_model
|
bool
|
Whether to use a PyTorch model for the EMLE calculation. Requires the feature_aev branch of the emle package. |
False
|
cutoff
|
str
|
The cutoff to use for the EMLE calculation. |
"12A"
|
neighbour_list_frequency
|
int
|
The frequency at which to update the neighbour list. |
0
|
device
|
str
|
The device to use for the EMLE calculation. |
None
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the EMLECalculator or EMLE Torch model."" See https://github.com/chemle/emle-engine/blob/main/emle/calculator.py#L399-L519. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The modified OpenMM System with the EMLE potential added. |
fes_ml.alchemical.modifications.custom_lj.CustomLJModification
¶
Bases: BaseModification
Class to modify the Lennard-Jones parameters of the CustomNonbondedForce.
apply(system, alchemical_atoms, lambda_value, original_offxml, lj_offxml, topology_off, alchemical_atoms_only=True, non_alchemical_atoms_only=False, *args, **kwargs)
¶
Interpolate the Lennard-Jones parameters of the alchemical atoms (CustomLJ).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to be modified. |
required |
alchemical_atoms
|
List[int]
|
A list of the indices of the alchemical atoms. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
required |
original_offxml
|
List[str]
|
A list of paths to the original OFFXML files. |
required |
lj_offxml
|
str
|
The path to the OFFXML file with the modified Lennard-Jones parameters. |
required |
topology_off
|
Topology
|
The topology of the system. |
required |
alchemical_atoms_only
|
bool
|
Whether to only apply the modified parameters to the alchemical atoms. |
True
|
non_alchemical_atoms_only
|
bool
|
Whether to only apply the modified parameters to the non-alchemical atoms. |
False
|
args
|
tuple
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
fes_ml.alchemical.modifications.charge_transfer.ChargeTransferModification
¶
Bases: BaseModification
Class to create a charge transfer potential based on a CustomNonbondedForce.
get_is_donor_acceptor(topology, alchemical_atoms, symmetric=False)
staticmethod
¶
Generate per-atom flags for donors and acceptors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topology
|
Topology
|
|
required |
alchemical_atoms
|
list of int
|
List of indices of alchemical atoms. |
required |
symmetric
|
bool
|
If True, CT will be applied symmetrically between alchemical and MM atoms. Otherwise, only from MM to alchemical atoms. Default is False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
is_donor |
list[int]
|
1 if the atom is a hydrogen bonded to N/O, 0 otherwise. |
is_acceptor |
list[int]
|
1 if the atom is N or O, 0 otherwise. |
apply(system, alchemical_atoms, original_offxml, ct_offxml, topology_off, lambda_value=1.0, *args, **kwargs)
¶
Add the charge-transfer term between the alchemical atoms and the rest of the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to be modified. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms in the system. |
required |
ct_offxml
|
str
|
Path to the offxml file containing the charge transfer parameters. |
required |
original_offxml
|
List[str]
|
List of paths to the original offxml files. |
required |
topology_off
|
Topology
|
The OpenFF Topology object of the system. |
required |
lambda_value
|
float
|
The value of the alchemical state parameter. |
1.0
|
args
|
tuple
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Type | Description |
|---|---|
System
|
The modified system. |
fes_ml.alchemical.modifications.intramolecular
¶
Module for classes related to modifications of the intramolecular terms and their factories.
IntraMolecularNonBondedExceptionsModificationFactory
¶
Bases: BaseModificationFactory
Factory for creating IntraMolecularNonBondedModification instances.
create_modification(*args, **kwargs)
¶
Create an instance of IntraMolecularNonBondedModification.
Returns:
| Type | Description |
|---|---|
IntraMolecularNonBondedExceptionsModification
|
The modification to be applied. |
IntraMolecularNonBondedForcesModificationFactory
¶
Bases: BaseModificationFactory
Factory for creating IntraMolecularNonBondedForcesModification instances.
create_modification(*args, **kwargs)
¶
Create an instance of IntraMolecularNonBondedForcesModification.
Returns:
| Type | Description |
|---|---|
IntraMolecularNonBondedForcesModification
|
The modification to be applied. |
IntraMolecularBondedRemovalModificationFactory
¶
Bases: BaseModificationFactory
Factory for creating IntraMolecularBondedRemovalModification instances.
create_modification(*args, **kwargs)
¶
Create an instance of IntraMolecularBondedRemovalModification.
Returns:
| Type | Description |
|---|---|
IntraMolecularBondedRemovalModification
|
The modification to be applied. |
IntraMolecularNonBondedExceptionsModification
¶
Bases: BaseModification
Class to add zeroed exceptions between alchemical atoms.
apply(system, alchemical_atoms, *args, **kwargs)
¶
Add exceptions to the NonbondedForce and CustomNonbondedForces.
Prevents the alchemical atoms from interacting as these interactions are already taken into account by the CustomBondForce.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The System to modify. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The modified System. |
IntraMolecularNonBondedForcesModification
¶
Bases: BaseModification
Class to add intramolecular nonbonded forces as a CustomBondForce.
apply(system, alchemical_atoms, reaction_field=False, *args, **kwargs)
¶
Add the intramolecular nonbonded forces as a CustomBondForce to the System.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The System to modify. |
required |
alchemical_atoms
|
list of int
|
The indices of the alchemical atoms. |
required |
reaction_field
|
bool
|
If True, the energy expression will include a reaction field term. |
False
|
args
|
list
|
Additional arguments to be passed to the modification. |
()
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the modification. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
system |
System
|
The modified System. |
Notes
This code is heavily inspired on REF.
IntraMolecularBondedRemovalModification
¶
Bases: BaseModification
Class to remove bonded interactions (by zeroing them) between alchemical atoms.
apply(system, alchemical_atoms, remove_in_set=True, remove_constraints=True, *args, **kwargs)
¶
Remove all bonded interactions between atoms in a particular set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The system to remove the bonded interactions from. |
required |
alchemical_atoms
|
List[int]
|
The indices of the alchemical atoms. |
required |
remove_in_set
|
bool
|
If True, any bonded term connecting atoms in the specified set is removed. If False, any term that does not connect atoms in the specified set is removed |
True
|
remove_constraints
|
bool
|
If True, remove constraints between pairs of atoms in the set |
True
|
Returns:
| Type | Description |
|---|---|
System
|
A new System with the specified interactions removed. |