openmmml.models.torchmdnetpotential.TorchMDNetPotentialImpl#
- class openmmml.models.torchmdnetpotential.TorchMDNetPotentialImpl(name: str, modelPath: str, lengthScale: float, energyScale: float)#
This is the MLPotentialImpl implementing the TorchMDNet potential.
The TorchMDNet potential is constructed using torchmdnet to build a PyTorch model, and then integrated into the OpenMM System using a TorchForce. To use it, specify the model by name and provide the path to a model.
>>> potential = MLPotential('torchmdnet', modelPath=<model_file_path>)
The default energy and length scales assume a model is trained with positions in angstroms and energies in eV. If this is not the case you can specify the length and energy scales by passing the factors that convert the model distance to nm and the energy to kJ/mol, for example:
>>> potential = MLPotential('torchmdnet', modelPath=<model_file_path>, lengthScale=0.1 # angstrom to nm, energyScale=4.184 # kcal/mol to kJ/mol)
During system creation you can enable CUDA graphs for a speed-up for small molecules:
>>> system = potential.createSystem(pdb.topology, cudaGraphs=True)
The default is to enable this for TensorNet models.
You can also specify the molecule’s total charge:
>>> system = potential.createSystem(pdb.topology, charge=0)
Pretained AceFF models can be used directly:
>>> potential = MLPotential('aceff-1.0')
>>> potential = MLPotential('aceff-1.1')
- __init__(name: str, modelPath: str, lengthScale: float, energyScale: float) None#
Initialize the TorchMDNetPotentialImpl.
- Parameters:
name (str) – The name of the model. ‘torchmdnet’ for a local model file, or pretrained models are available: ‘aceff-1.0’ or ‘aceff-1.1’.
modelPath (str, optional) – The path to the locally trained torchmdnet model if
nameis ‘torchmdnet’.lengthScale (float) – The length conversion factor from the model units to nanometers. If not specified the default is 0.1 which corresponds to a model in angstrom
energyScale (float) – The energy conversion factor from the model units to kJ/mol. If not specified the default is 96.4916 which corresponds to a model in eV.
Methods
__init__(name, modelPath, lengthScale, ...)Initialize the TorchMDNetPotentialImpl.
addForces(topology, system, atoms, ...)Add Force objects to a System to implement the potential function.
- addForces(topology: Topology, system: System, atoms: Iterable[int] | None, forceGroup: int, **args)#
Add Force objects to a System to implement the potential function.
This is invoked by MLPotential.createSystem(). Subclasses must implement it to create the requested potential function.
- Parameters:
topology (Topology) – the Topology from which the System is being created
system (System) – the System that is being created
atoms (Optional[Iterable[int]]) – the indices of atoms the potential should be applied to, or None if it should be applied to the entire System
forceGroup (int) – the force group that any newly added Forces should be in
args – any additional keyword arguments that were provided to createSystem() are passed to this method. This allows subclasses to customize their behavior based on extra arguments.