Skip to content

Commit 3c1e9d3

Browse files
authored
Converted MACE to use PythonForce (#114)
* Fixed errors in documentation * Converted MACE to use PythonForce * More test cases
1 parent cc19b74 commit 3c1e9d3

6 files changed

Lines changed: 145 additions & 250 deletions

File tree

doc/userguide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ are supported.
8181
| `mace-off23-small`<br>`mace-off23-medium`<br>`mace-off23-large`<br>`mace-off24-medium` | Pretrained [MACE-OFF](https://pubs.acs.org/doi/10.1021/jacs.4c07099) models |
8282
| `mace-mpa-0-medium` | Pretrained [MACE-MPA-0](https://github.com/ACEsuit/mace-foundations) model |
8383
| `mace-omat-0-small`<br>`mace-omat-0-medium` | Pretrained [MACE-OMAT-0](https://github.com/ACEsuit/mace-foundations) models |
84+
| `mace-omol-0-extra-large` | Pretrained MACE-OMOL-0 model |
8485
| `mace` | Custom MACE models specified with the `modelPath` argument |
8586

8687
When creating MACE models, the following keyword arguments to the `MLPotential` constructor are supported.
@@ -95,6 +96,9 @@ When using MACE models, the following extra keyword arguments to `createSystem()
9596
| --- | --- |
9697
| `precision` | The numerical precision of the model. Supported options are `'single'` and `'double'`. If `None`, the default precision of the model is used. |
9798
| `returnEnergyType` | Whether to return the interaction energy or the energy including the self-energy. The default is `'interaction_energy'`. Supported options are `'interaction_energy'` and `'energy'`. |
99+
| `device` | The PyTorch device to perform calculations on, either a `torch.device` object or a string (such as `'cuda'` or `'cpu'`.) If omitted, a device is chosen automatically. |
100+
| `charge` | The total charge of the system. If omitted, it is assumed to be 0. This is only used by MACE-OMOL-0. For other models it is ignored. |
101+
| `multiplicity` | The spin multiplicity of the system. If omitted, it is assumed to be 1. This is only used by MACE-OMOL-0. For other models it is ignored. |
98102

99103
### AIMNet2
100104

openmmml/mlpotential.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ def addForces(self,
115115
"""
116116
raise NotImplementedError('Subclasses must implement addForces()')
117117

118+
def _getTorchDevice(self, args):
119+
"""This is a utility routine for use by subclasses that are implemented with PyTorch. It selects what device
120+
to use, which can either by specified by the user with the 'device' argument, or chosen automatically based on
121+
the available hardware."""
122+
import torch
123+
if 'device' in args:
124+
device = args['device']
125+
if isinstance(device, str):
126+
device = torch.device(device)
127+
return device
128+
if torch.cuda.is_available():
129+
return torch.device('cuda')
130+
return torch.device('cpu')
131+
118132

119133
class MLPotential(object):
120134
"""A potential function that can be used in simulations.

0 commit comments

Comments
 (0)