openmmml.models.macepotential.MACEPotentialImpl#

class openmmml.models.macepotential.MACEPotentialImpl(name: str, modelPath)#

This is the MLPotentialImpl implementing the MACE potential.

The MACE potential is constructed using MACE to build a PyTorch model, and then integrated into the OpenMM System using a TorchForce. This implementation supports both foundation models and locally trained MACE models.

To use one of the pre-trained MACE foundation models, specify the model name. For example:

>>> potential = MLPotential('mace-off23-small')

Other available models include ‘mace-off23-medium’, ‘mace-off23-large’, ‘mace-off24-medium’, ‘mace-mpa-0-medium’, ‘mace-omat-0-small’, ‘mace-omat-0-medium’, and ‘mace-omol-0-extra-large’.

To use a locally trained MACE model, provide the path to the model file. For example:

>>> potential = MLPotential('mace', modelPath='MACE.model')

During system creation, you can optionally specify the precision of the model using the precision keyword argument. Supported options are ‘single’ and ‘double’. For example:

>>> system = potential.createSystem(topology, precision='single')

By default, the implementation uses the precision of the loaded MACE model. According to the MACE documentation, ‘single’ precision is recommended for MD (faster but less accurate), while ‘double’ precision is recommended for geometry optimization.

Additionally, you can request computation of the full atomic energy, including the atom self-energy, instead of the default interaction energy, by setting returnEnergyType to ‘energy’. For example:

>>> system = potential.createSystem(topology, returnEnergyType='energy')

The default is to compute the interaction energy, which can be made explicit by setting returnEnergyType='interaction_energy'.

name#

The name of the MACE model.

Type:

str

modelPath#

The path to the locally trained MACE model if name is ‘mace’.

Type:

str

__init__(name: str, modelPath) None#

Initialize the MACEPotentialImpl.

Parameters:
  • name (str) – The name of the MACE model. Options include ‘mace-off23-small’, ‘mace-off23-medium’, ‘mace-off23-large’, ‘mace-off24-medium’, ‘mace-mpa-0-medium’, ‘mace-omat-0-small’, ‘mace-omat-0-medium’, ‘mace-omol-0-extra-large’, and ‘mace’.

  • modelPath (str, optional) – The path to the locally trained MACE model if name is ‘mace’.

Methods

__init__(name, modelPath)

Initialize the MACEPotentialImpl.

addForces(topology, system, atoms, forceGroup)

Add the MACEForce to the OpenMM System.

createMixedSystem(topology, system, atoms, ...)

Creates a mixed system using a potential-specific embedding method.

getMLLongRange()

Returns whether ML interactions are local (False), or long-ranged (True) when periodic boundary conditions are present.

getSupportedEmbeddings()

Retrieves a list of names of supported embedding methods (for the creation of mixed ML/MM systems) specific to this potential.

Attributes

KNOWN_MODELS

addForces(topology: Topology, system: System, atoms: Iterable[int] | None, forceGroup: int, precision: str | None = None, returnEnergyType: str = 'interaction_energy', **args) None#

Add the MACEForce to the OpenMM System.

Parameters:
  • topology (openmm.app.Topology) – The topology of the system.

  • system (openmm.System) – The system to which the force will be added.

  • atoms (iterable of int) – The indices of the atoms to include in the model. If None, all atoms are included.

  • forceGroup (int) – The force group to which the force should be assigned.

  • precision (str, optional) – The precision of the model. Supported options are ‘single’ and ‘double’. If None, the default precision of the model is used.

  • returnEnergyType (str, optional) – Whether to return the interaction energy or the energy including the self-energy. Default is ‘interaction_energy’. Supported options are ‘interaction_energy’ and ‘energy’.

getMLLongRange() bool | None#

Returns whether ML interactions are local (False), or long-ranged (True) when periodic boundary conditions are present. This controls which interactions are included by some ML/MM embedding methods. Consult the documentation for each embedding method for more details. None can be returned if the nature of the interactions is not known by the MLPotentialImpl.

The default implementation of this method, used if a subclass does not override it, always returns None.

createMixedSystem(topology: Topology, system: System, atoms: list[int], forceGroup: int, interpolate: bool, embedding: str, **args) System#

Creates a mixed system using a potential-specific embedding method.

This is invoked by MLPotential.createMixedSystem(). It will only be called with one of the names returned by getSupportedEmbeddings(). If subclasses support any potential-specific embedding methods, they must also provide implementations of those methods by overriding this method. If not, it does not need to be implemented.

Each embedding method is responsible for implementing interpolation; if interpolate is True, a global parameter “lambda_interpolate” should be present in the returned system, with the behavior as described by MLPotential.createMixedSystem().

Parameters:
  • topology (Topology) – the Topology for which to create a System

  • system (System) – a System that models the Topology with a conventional force field

  • atoms (Iterable[int]) – the indices of all atoms whose interactions should be computed with this potential

  • forceGroup (int) – the force group the ML potential’s Forces should be placed in

  • interpolate (bool) – if True, create a System that can smoothly interpolate between the conventional and ML potentials

  • embedding (str) – the name of the embedding method (will always be one in the list returned by the getSupportedEmbeddings() method)

  • args – any additional arguments for the potential or embedding method

Returns:

  • a newly created System object that uses this potential function and the

  • requested embedding method to model the Topology

getSupportedEmbeddings() list[str]#

Retrieves a list of names of supported embedding methods (for the creation of mixed ML/MM systems) specific to this potential. If one of these names is provided instead of providing the name of a generic embedding plugin, embedding will be performed by the potential itself.

This is invoked by MLPotential.createMixedSystem(). If a subclass wishes to define one or more potential-specific embedding methods, it should implement this method; otherwise, it does not need to.