Skip to content

Commit 744202d

Browse files
Add pet-omatpes-v2 models (#27)
1 parent 32c71ef commit 744202d

File tree

6 files changed

+72
-54
lines changed

6 files changed

+72
-54
lines changed

README.md

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ atoms.set_velocities( # it is generally a good idea to remove any net velocity
4242

4343
# Load models
4444
device="cuda" if torch.cuda.is_available() else "cpu"
45-
energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
45+
energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
4646

4747
# Set the energy model (see below for more precise usage)
4848
calculator = MetatomicCalculator(energy_model, device=device)
@@ -70,6 +70,11 @@ Other available integrators:
7070
from flashmd.ase.bussi import Bussi
7171
```
7272

73+
Along with all FlashMD models, we also provide the potential energy model whose
74+
dynamics they are trained to reproduce. See this short [guide](docs/energy.md) on how to
75+
best use the energy models if you want to enforce exact energy conservation during
76+
FlashMD runs, run traditional MD with the energy model, and more.
77+
7378
Common pitfalls
7479
---------------
7580

@@ -78,52 +83,6 @@ above is good for metals. However,
7883
- for most materials: try 32 fs (aggressive) or 16 fs (conservative)
7984
- for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
8085

81-
82-
Companion energy models and exact energy conservation
83-
-----------------------------------------------------
84-
85-
You might have noticed that ``get_pretrained()`` does not only return a FlashMD model,
86-
but also an energy model, which is itself just a machine-learned interatomic potential.
87-
This is the energy model that the FlashMD model was trained on. You might want to use it
88-
if...
89-
90-
**Case 1**: you want to run FlashMD with exact energy conservation, available through the
91-
integrator's (``dyn`` above) parameter ``rescale_energy=True`` (this is enabled by
92-
default only when targeting the NVE ensemble with ``VelocityVerlet``). In that case,
93-
besides setting this flag, you should attach the energy calculator to the atoms before
94-
running FlashMD, exactly as shown above (and below with the more precise
95-
``do_gradients_with_energy=False`` which will save you memory and computation):
96-
97-
```
98-
from metatomic.torch.ase_calculator import MetatomicCalculator
99-
100-
... # setting up atoms
101-
calculator = MetatomicCalculator(energy_model, device=device, do_gradients_with_energy=False)
102-
atoms.calc = calculator
103-
... # running FlashMD
104-
```
105-
106-
**Case 2**: you want to compute energies after running FlashMD for your own analysis. In
107-
this case, you can create the calculator just like in case 1, but possibly after running
108-
FlashMD and/or in a different script.
109-
110-
**Case 3**: you found something interesting during a FlashMD run and you want to confirm it
111-
with traditional MD. Then, you can just use ASE's MD modules as usual after attaching
112-
the energy calculator:
113-
114-
```
115-
from metatomic.torch.ase_calculator import MetatomicCalculator
116-
117-
... # setting up atoms
118-
calculator = MetatomicCalculator(energy_model, device=device)
119-
atoms.calc = calculator
120-
... # running MD
121-
```
122-
123-
In general, the energy models are slower and have a larger memory footprint compared to
124-
the FlashMD models. As summarized above, you should use `do_gradients_with_energy=False`
125-
to save computation and memory when you do not need forces.
126-
12786
Using FlashMD in LAMMPS
12887
-----------------------
12988

@@ -140,6 +99,12 @@ You can see
14099
for usage examples. i-PI is our most mature interface, and the one that was used to
141100
generate all our published results.
142101

102+
Models
103+
------
104+
105+
See [here](docs/models.md) for the complete list of the models we provide. If you are
106+
new to FlashMD, we recommend starting with the ``pet-omatpes-v2`` models.
107+
143108
Disclaimer
144109
----------
145110

docs/energy.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Companion energy models and exact energy conservation
2+
-----------------------------------------------------
3+
4+
You might have noticed that ``get_pretrained()`` does not only return a FlashMD model,
5+
but also an energy model, which is itself just a machine-learned interatomic potential.
6+
This is the energy model that the FlashMD model was trained on. You might want to use it
7+
if...
8+
9+
**Case 1**: you want to run FlashMD with exact energy conservation, available through the
10+
integrator's (often named ``dyn``) parameter ``rescale_energy=True`` (this is enabled by
11+
default only when targeting the NVE ensemble with ``VelocityVerlet``). In that case,
12+
besides setting this flag, you should attach the energy calculator to the atoms before
13+
running FlashMD, exactly as shown in the opening example (and below with the more precise
14+
``do_gradients_with_energy=False`` which will save you memory and computation):
15+
16+
```
17+
from metatomic.torch.ase_calculator import MetatomicCalculator
18+
19+
... # setting up atoms
20+
calculator = MetatomicCalculator(energy_model, device=device, do_gradients_with_energy=False)
21+
atoms.calc = calculator
22+
... # running FlashMD
23+
```
24+
25+
**Case 2**: you want to compute energies after running FlashMD for your own analysis. In
26+
this case, you can create the calculator just like in case 1, but possibly after running
27+
FlashMD and/or in a different script.
28+
29+
**Case 3**: you found something interesting during a FlashMD run and you want to confirm it
30+
with traditional MD. Then, you can just use ASE's MD modules as usual after attaching
31+
the energy calculator:
32+
33+
```
34+
from metatomic.torch.ase_calculator import MetatomicCalculator
35+
36+
... # setting up atoms
37+
calculator = MetatomicCalculator(energy_model, device=device)
38+
atoms.calc = calculator
39+
... # running MD
40+
```
41+
42+
In general, the energy models are slower and have a larger memory footprint compared to
43+
the FlashMD models. As summarized above, you should use `do_gradients_with_energy=False`
44+
to save computation and memory when you do not need forces.

docs/lammps.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ number you get and match it to the number from the following list:
2828
where you should replace ``ADA89`` with the string you found above. If you do not have
2929
conda yet, we recommend the [Miniforge](https://github.com/conda-forge/miniforge) conda provider.
3030
On HPC systems, it is safer to execute this command on a GPU-enabled compute (or debug)
31-
node, as sometimes nvidia drivers are not present on login nodes and this can prevent
31+
node, as sometimes Nvidia drivers are not present on login nodes and this can prevent
3232
conda from installing the correct GPU libraries.
3333

3434
You are now ready to run FlashMD in LAMMPS!
@@ -50,7 +50,7 @@ trained on. Here is how you can get them in the current directory from Python:
5050
from flashmd import get_pretrained
5151

5252
time_step = 16 # in fs, also available: 1, 2, 4, 8, 32, 64, 128
53-
energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
53+
energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
5454
energy_model.save("mlip.pt")
5555
flashmd_model.save(f"flashmd-{time_step}.pt")
5656
```
@@ -61,8 +61,7 @@ Here below you will see how to run different types of molecular dynamics. In all
6161
you should launch LAMMPS as ``lmp -in in.flashmd -k on g 1 -pk kokkos newton on neigh half -sf kk``
6262
(assuming your input file is named ``in.flashmd``), or ``lmp -in in.flashmd`` if you
6363
want to run without Kokkos acceleration. The following sections will present some input
64-
files that you can take inspiration from. Trivially, we advise you to consult the [LAMMPS
65-
documentation](https://docs.lammps.org) for further explanation of all the parameters.
64+
files that you can take inspiration from.
6665

6766
# NVT (Langevin thermostat)
6867

docs/models.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This is the complete list of FlashMD we make available through this library.
2+
3+
| Name | Available timesteps (fs) | Description |
4+
|---------------------|---------------------------------|-----------------------------------------------------------------------------|
5+
| ``pet-omatpes-v2`` | ``1, 2, 4, 8, 16, 32, 64, 128`` | New version of the ``pet-omatpes`` models, more robust at high temperatures |
6+
| ``pet-omatpes`` | ``1, 2, 4, 8, 16, 32, 64, 128`` | Trained on the MATPES-r2SCAN dataset |

src/flashmd/models.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
from metatomic.torch import AtomisticModel, load_atomistic_model
77

88

9-
AVAILABLE_MLIPS = ["pet-omatpes"]
10-
AVAILABLE_TIME_STEPS = {"pet-omatpes": [1, 2, 4, 8, 16, 32, 64, 128]}
9+
AVAILABLE_MLIPS = ["pet-omatpes", "pet-omatpes-v2"]
10+
AVAILABLE_TIME_STEPS = {
11+
"pet-omatpes": [1, 2, 4, 8, 16, 32, 64, 128],
12+
"pet-omatpes-v2": [1, 2, 4, 8, 16, 32, 64, 128],
13+
}
1114

1215

13-
def get_pretrained(mlip: str = "pet-omatpes", time_step: int = 16) -> AtomisticModel:
16+
def get_pretrained(mlip: str = "pet-omatpes-v2", time_step: int = 16) -> AtomisticModel:
1417
if mlip not in AVAILABLE_MLIPS:
1518
raise ValueError(
1619
f"MLIP '{mlip}' is not available. "

tests/test_models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def test_available_mlips():
88
assert isinstance(AVAILABLE_MLIPS, list)
99
assert len(AVAILABLE_MLIPS) > 0
1010
assert "pet-omatpes" in AVAILABLE_MLIPS
11+
assert "pet-omatpes-v2" in AVAILABLE_MLIPS
1112

1213

1314
def test_available_time_steps():

0 commit comments

Comments
 (0)