flashmd 0.2.5__tar.gz → 0.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {flashmd-0.2.5 → flashmd-0.2.7}/PKG-INFO +58 -67
  2. flashmd-0.2.7/README.md +152 -0
  3. {flashmd-0.2.5 → flashmd-0.2.7}/pyproject.toml +37 -2
  4. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/__init__.py +3 -1
  5. flashmd-0.2.7/src/flashmd/ase/__init__.py +26 -0
  6. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/ase/bussi.py +9 -7
  7. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/ase/langevin.py +17 -9
  8. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/ase/velocity_verlet.py +13 -13
  9. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/ipi.py +12 -11
  10. flashmd-0.2.7/src/flashmd/models.py +102 -0
  11. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/stepper.py +4 -5
  12. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd.egg-info/PKG-INFO +58 -67
  13. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd.egg-info/SOURCES.txt +4 -2
  14. flashmd-0.2.7/src/flashmd.egg-info/requires.txt +8 -0
  15. flashmd-0.2.7/tests/test_energy.py +29 -0
  16. flashmd-0.2.7/tests/test_models.py +65 -0
  17. flashmd-0.2.7/tests/test_readme.py +37 -0
  18. flashmd-0.2.5/README.md +0 -165
  19. flashmd-0.2.5/src/flashmd/ase/__init__.py +0 -0
  20. flashmd-0.2.5/src/flashmd/ase/npt.py +0 -0
  21. flashmd-0.2.5/src/flashmd/models.py +0 -61
  22. flashmd-0.2.5/src/flashmd.egg-info/requires.txt +0 -3
  23. {flashmd-0.2.5 → flashmd-0.2.7}/LICENSE +0 -0
  24. {flashmd-0.2.5 → flashmd-0.2.7}/setup.cfg +0 -0
  25. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd/constraints.py +0 -0
  26. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd.egg-info/dependency_links.txt +0 -0
  27. {flashmd-0.2.5 → flashmd-0.2.7}/src/flashmd.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashmd
3
- Version: 0.2.5
3
+ Version: 0.2.7
4
4
  Summary: Accelerated molecular dynamics with large-time-step predictions
5
5
  Author: flashmd developers
6
6
  License: Apache-2.0
@@ -22,9 +22,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
22
  Requires-Python: >=3.9
23
23
  Description-Content-Type: text/markdown
24
24
  License-File: LICENSE
25
- Requires-Dist: metatrain==2025.12
25
+ Requires-Dist: metatrain==2026.1
26
26
  Requires-Dist: ase
27
27
  Requires-Dist: huggingface_hub
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Requires-Dist: mypy; extra == "dev"
28
32
  Dynamic: license-file
29
33
 
30
34
  FlashMD: universal long-stride molecular dynamics
@@ -32,13 +36,13 @@ FlashMD: universal long-stride molecular dynamics
32
36
 
33
37
  This repository contains custom integrators to run MD trajectories with FlashMD models. These models are
34
38
  designed to learn and predict molecular dynamics trajectories using long strides, therefore allowing
35
- very large time steps. Before using this method, make sure you are aware of its limitations, which are
39
+ very large time steps. When using this method, make sure you are aware of its limitations, which are
36
40
  discussed in [this preprint](http://arxiv.org/abs/2505.19350).
37
41
 
38
42
  The pre-trained models we make available are trained to reproduce ab-initio MD at the r2SCAN level of theory.
39
43
 
40
- Quickstart
41
- ----------
44
+ ASE Quickstart (see below for LAMMPS)
45
+ -------------------------------------
42
46
 
43
47
  You can install the package with
44
48
 
@@ -46,16 +50,16 @@ You can install the package with
46
50
  pip install flashmd
47
51
  ```
48
52
 
49
- After installation, you can run accelerated molecular dynamics with ASE as follows:
53
+ After installation, you can run accelerated molecular dynamics as follows:
50
54
 
51
55
  ```py
52
56
  import ase.build
53
57
  import ase.units
54
- from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
55
58
  import torch
56
- from metatomic.torch.ase_calculator import MetatomicCalculator
59
+ from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
57
60
 
58
61
  from flashmd import get_pretrained
62
+ from flashmd.ase import EnergyCalculator
59
63
  from flashmd.ase.langevin import Langevin
60
64
 
61
65
 
@@ -70,11 +74,11 @@ atoms.set_velocities( # it is generally a good idea to remove any net velocity
70
74
  )
71
75
 
72
76
  # Load models
73
- device="cuda" if torch.cuda.is_available() else "cpu"
74
- energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
77
+ device = "cuda" if torch.cuda.is_available() else "cpu"
78
+ energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
75
79
 
76
- # Set the energy model (see below for more precise usage)
77
- calculator = MetatomicCalculator(energy_model, device=device)
80
+ # Set the energy model (optional, see below for more precise usage)
81
+ calculator = EnergyCalculator(energy_model, device=device)
78
82
  atoms.calc = calculator
79
83
 
80
84
  # Run MD
@@ -84,9 +88,9 @@ dyn = Langevin(
84
88
  temperature_K=300,
85
89
  time_constant=100*ase.units.fs,
86
90
  model=flashmd_model,
87
- device=device
91
+ device=device,
88
92
  )
89
- dyn.run(1000)
93
+ dyn.run(1000) # this is 64 ps!
90
94
  ```
91
95
 
92
96
  [The first time you use this code and call the `get_pretrained` function, the
@@ -99,6 +103,11 @@ Other available integrators:
99
103
  from flashmd.ase.bussi import Bussi
100
104
  ```
101
105
 
106
+ Along with all FlashMD models, we also provide the potential energy model whose
107
+ dynamics they are trained to reproduce. See this short [guide](docs/energy.md) on how to
108
+ best use the energy models if you want to enforce exact energy conservation during
109
+ FlashMD runs, run traditional MD with the energy model, and more.
110
+
102
111
  Common pitfalls
103
112
  ---------------
104
113
 
@@ -107,77 +116,59 @@ above is good for metals. However,
107
116
  - for most materials: try 32 fs (aggressive) or 16 fs (conservative)
108
117
  - for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
109
118
 
119
+ Using FlashMD in LAMMPS
120
+ -----------------------
110
121
 
111
- Companion energy models and exact energy conservation
112
- -----------------------------------------------------
122
+ LAMMPS can allow you to run FlashMD with better computational and memory efficiency.
123
+ Furthermore, it will give you access to more sophisticated types of simulations, such as
124
+ simulations in the NPT ensemble and metadynamics. See [here](docs/lammps.md) for a guide
125
+ on using FlashMD in LAMMPS.
113
126
 
114
- You might have noticed that ``get_pretrained()`` does not only return a FlashMD model,
115
- but also an energy model, which is itself just a machine-learned interatomic potential.
116
- This is the energy model that the FlashMD model was trained on. You might want to use it
117
- if...
127
+ Using FlashMD in i-PI
128
+ ---------------------
118
129
 
119
- Case 1: you want to run FlashMD with exact energy conservation, available through the
120
- integrator's (``dyn`` above) parameter ``rescale_energy=True`` (this is enabled by
121
- default only when targeting the NVE ensemble with ``VelocityVerlet``). In that case,
122
- besides setting this flag, you should attach the energy calculator to the atoms before
123
- running FlashMD, exactly as shown above (and below with the more precise
124
- ``do_gradients_with_energy=False`` which will save you memory and computation):
125
-
126
- ```
127
- from metatomic.torch.ase_calculator import MetatomicCalculator
128
-
129
- ... # setting up atoms
130
- calculator = MetatomicCalculator(energy_model, device=device, do_gradients_with_energy=False)
131
- atoms.calc = calculator
132
- ... # running FlashMD
133
- ```
130
+ You can see
131
+ [this cookbook recipe](https://atomistic-cookbook.org/examples/flashmd/flashmd-demo.html)
132
+ for usage examples. i-PI is our most mature interface, and the one that was used to
133
+ generate all our published results.
134
134
 
135
- Case 2: you want to compute energies after running FlashMD for your own analysis. In
136
- this case, you can create the calculator just like in case 1, but possibly after running
137
- FlashMD and/or in a different script.
135
+ Models
136
+ ------
138
137
 
139
- Case 3: you found something interesting during a FlashMD run and you want to confirm it
140
- with traditional MD. Then, you can just use ASE's MD modules as usual after attaching
141
- the energy calculator:
138
+ See [here](docs/models.md) for the complete list of the models we provide. If you are
139
+ new to FlashMD, we recommend starting with the ``pet-omatpes-v2`` models.
142
140
 
143
- ```
144
- from metatomic.torch.ase_calculator import MetatomicCalculator
141
+ Training/fine-tuning your own FlashMD models
142
+ --------------------------------------------
145
143
 
146
- ... # setting up atoms
147
- calculator = MetatomicCalculator(energy_model, device=device)
148
- atoms.calc = calculator
149
- ... # running MD
150
- ```
151
-
152
- In general, the energy models are slower and have a larger memory footprint compared to
153
- the FlashMD models. As summarized above, you should use `do_gradients_with_energy=False`
154
- to save computation and memory when you don't need forces.
144
+ FlashMD models can be trained from the metatrain library. This
145
+ [tutorial](https://docs.metatensor.org/metatrain/latest/generated_examples/1-advanced/04-flashmd.html)
146
+ shows how to train your own FlashMD model, either from scratch or by fine-tuning of one of our universal models.
155
147
 
156
148
  Disclaimer
157
149
  ----------
158
150
 
159
- This is experimental software and should only be used if you know what you're doing.
160
- We recommend using the i-PI integrators for any serious work and/or if you need to perform
161
- constant-pressure (NPT) molecular dynamics. You can see
162
- [this cookbook recipe](https://atomistic-cookbook.org/examples/flashmd/flashmd-demo.html)
163
- for a usage example.
164
- Given that the main issue we observe in direct MD trajectories is loss of equipartition
165
- of energy between different degrees of freedom, we recommend using a local Langevin
166
- thermostat, and to monitor the temperature of different atomic types or different
167
- parts of the simulated system.
151
+ This is experimental software and should only be used if you know what you are doing.
152
+ Given that the main issue we observe in FlashMD is loss of equipartition
153
+ of energy between different degrees of freedom, we recommend using a Langevin
154
+ thermostat, possibly monitoring the temperature of different atomic types or different
155
+ parts of the simulated system. For the time being, we also recommend checking all
156
+ FlashMD-powered findings with traditional MD. The energy models that were used to train
157
+ FlashMD, and that we make available in this repository, can be used for this purpose.
168
158
 
169
159
 
170
160
  Publication
171
161
  -----------
172
162
 
173
- If you found FlashMD useful, you can cite the corresponding article:
163
+ If you found FlashMD useful, you can cite the corresponding [article](https://arxiv.org/abs/2505.19350):
174
164
 
175
165
  ```
176
- @article{FlashMD,
177
- title={FlashMD: long-stride, universal prediction of molecular dynamics},
178
- author={Bigi, Filippo and Chong, Sanggyu and Kristiadi, Agustinus and Ceriotti, Michele},
179
- journal={arXiv preprint arXiv:2505.19350},
180
- year={2025}
166
+ @inproceedings{FlashMD,
167
+ title = {FlashMD: long-stride, universal prediction of molecular dynamics},
168
+ author = {Bigi, Filippo and Chong, Sanggyu and Kristiadi, Agustinus and Ceriotti, Michele},
169
+ booktitle = {Advances in Neural Information Processing Systems},
170
+ year = {2025},
171
+ url = {https://arxiv.org/abs/2505.19350}
181
172
  }
182
173
  ```
183
174
 
@@ -0,0 +1,152 @@
1
+ FlashMD: universal long-stride molecular dynamics
2
+ =================================================
3
+
4
+ This repository contains custom integrators to run MD trajectories with FlashMD models. These models are
5
+ designed to learn and predict molecular dynamics trajectories using long strides, therefore allowing
6
+ very large time steps. When using this method, make sure you are aware of its limitations, which are
7
+ discussed in [this preprint](http://arxiv.org/abs/2505.19350).
8
+
9
+ The pre-trained models we make available are trained to reproduce ab-initio MD at the r2SCAN level of theory.
10
+
11
+ ASE Quickstart (see below for LAMMPS)
12
+ -------------------------------------
13
+
14
+ You can install the package with
15
+
16
+ ```bash
17
+ pip install flashmd
18
+ ```
19
+
20
+ After installation, you can run accelerated molecular dynamics as follows:
21
+
22
+ ```py
23
+ import ase.build
24
+ import ase.units
25
+ import torch
26
+ from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
27
+
28
+ from flashmd import get_pretrained
29
+ from flashmd.ase import EnergyCalculator
30
+ from flashmd.ase.langevin import Langevin
31
+
32
+
33
+ # Choose your time step (go for 10-30x what you would use in normal MD for your system)
34
+ time_step = 64 # 64 fs; also available: 1, 2, 4, 8, 16, 32, 128 fs
35
+
36
+ # Create a structure and initialize velocities
37
+ atoms = ase.build.bulk("Al", "fcc", cubic=True)
38
+ MaxwellBoltzmannDistribution(atoms, temperature_K=300)
39
+ atoms.set_velocities( # it is generally a good idea to remove any net velocity
40
+ atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum()
41
+ )
42
+
43
+ # Load models
44
+ device = "cuda" if torch.cuda.is_available() else "cpu"
45
+ energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
46
+
47
+ # Set the energy model (optional, see below for more precise usage)
48
+ calculator = EnergyCalculator(energy_model, device=device)
49
+ atoms.calc = calculator
50
+
51
+ # Run MD
52
+ dyn = Langevin(
53
+ atoms=atoms,
54
+ timestep=time_step*ase.units.fs,
55
+ temperature_K=300,
56
+ time_constant=100*ase.units.fs,
57
+ model=flashmd_model,
58
+ device=device,
59
+ )
60
+ dyn.run(1000) # this is 64 ps!
61
+ ```
62
+
63
+ [The first time you use this code and call the `get_pretrained` function, the
64
+ pre-trained models will be downloaded. This might take a bit.]
65
+
66
+ Other available integrators:
67
+
68
+ ```py
69
+ from flashmd.ase.velocity_verlet import VelocityVerlet
70
+ from flashmd.ase.bussi import Bussi
71
+ ```
72
+
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
+
78
+ Common pitfalls
79
+ ---------------
80
+
81
+ Stick to 10-30x what you would use in normal MD for your system! The 64 fs example
82
+ above is good for metals. However,
83
+ - for most materials: try 32 fs (aggressive) or 16 fs (conservative)
84
+ - for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
85
+
86
+ Using FlashMD in LAMMPS
87
+ -----------------------
88
+
89
+ LAMMPS can allow you to run FlashMD with better computational and memory efficiency.
90
+ Furthermore, it will give you access to more sophisticated types of simulations, such as
91
+ simulations in the NPT ensemble and metadynamics. See [here](docs/lammps.md) for a guide
92
+ on using FlashMD in LAMMPS.
93
+
94
+ Using FlashMD in i-PI
95
+ ---------------------
96
+
97
+ You can see
98
+ [this cookbook recipe](https://atomistic-cookbook.org/examples/flashmd/flashmd-demo.html)
99
+ for usage examples. i-PI is our most mature interface, and the one that was used to
100
+ generate all our published results.
101
+
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
+
108
+ Training/fine-tuning your own FlashMD models
109
+ --------------------------------------------
110
+
111
+ FlashMD models can be trained from the metatrain library. This
112
+ [tutorial](https://docs.metatensor.org/metatrain/latest/generated_examples/1-advanced/04-flashmd.html)
113
+ shows how to train your own FlashMD model, either from scratch or by fine-tuning of one of our universal models.
114
+
115
+ Disclaimer
116
+ ----------
117
+
118
+ This is experimental software and should only be used if you know what you are doing.
119
+ Given that the main issue we observe in FlashMD is loss of equipartition
120
+ of energy between different degrees of freedom, we recommend using a Langevin
121
+ thermostat, possibly monitoring the temperature of different atomic types or different
122
+ parts of the simulated system. For the time being, we also recommend checking all
123
+ FlashMD-powered findings with traditional MD. The energy models that were used to train
124
+ FlashMD, and that we make available in this repository, can be used for this purpose.
125
+
126
+
127
+ Publication
128
+ -----------
129
+
130
+ If you found FlashMD useful, you can cite the corresponding [article](https://arxiv.org/abs/2505.19350):
131
+
132
+ ```
133
+ @inproceedings{FlashMD,
134
+ title = {FlashMD: long-stride, universal prediction of molecular dynamics},
135
+ author = {Bigi, Filippo and Chong, Sanggyu and Kristiadi, Agustinus and Ceriotti, Michele},
136
+ booktitle = {Advances in Neural Information Processing Systems},
137
+ year = {2025},
138
+ url = {https://arxiv.org/abs/2505.19350}
139
+ }
140
+ ```
141
+
142
+ Reproducing the results in the article is supported with FlashMD v0.1.2:
143
+
144
+ ```bash
145
+ pip install flashmd==0.1.2 ase==3.24.0 pet-mad==1.4.3
146
+ ```
147
+
148
+ and using the "PET-MAD" models (PBEsol) from https://huggingface.co/lab-cosmo/flashmd.
149
+ Note that the results were obtained through the i-PI interface.
150
+
151
+ Instructions and material to reproduce the results in the paper are available on
152
+ Materials Cloud at https://doi.org/10.24435/materialscloud:b7-xq.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flashmd"
3
- version = "0.2.5"
3
+ version = "0.2.7"
4
4
  requires-python = ">=3.9"
5
5
 
6
6
  readme = "README.md"
@@ -9,7 +9,7 @@ description = "Accelerated molecular dynamics with large-time-step predictions"
9
9
  authors = [{name = "flashmd developers"}]
10
10
 
11
11
  dependencies = [
12
- "metatrain==2025.12",
12
+ "metatrain==2026.1",
13
13
  "ase",
14
14
  "huggingface_hub",
15
15
  ]
@@ -44,5 +44,40 @@ build-backend = "setuptools.build_meta"
44
44
  [tool.setuptools.packages.find]
45
45
  where = ["src"]
46
46
 
47
+ [project.optional-dependencies]
48
+ dev = [
49
+ "pytest",
50
+ "ruff",
51
+ "mypy",
52
+ ]
53
+
47
54
  [tool.ruff]
48
55
  line-length = 88
56
+
57
+ [tool.ruff.lint]
58
+ select = ["E", "F", "B", "I"]
59
+ ignore = ["B018", "B904", "E501"]
60
+
61
+ [tool.ruff.lint.per-file-ignores]
62
+ "**/{tests}/*" = ["D"]
63
+
64
+ [tool.ruff.lint.isort]
65
+ lines-after-imports = 2
66
+ known-first-party = ["flashmd"]
67
+
68
+ [tool.ruff.format]
69
+ docstring-code-format = true
70
+
71
+ [tool.mypy]
72
+ follow_imports = 'skip'
73
+ ignore_missing_imports = true
74
+ disable_error_code = ["union-attr"]
75
+
76
+ [tool.pytest.ini_options]
77
+ markers = [
78
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
79
+ ]
80
+ filterwarnings = [
81
+ "error",
82
+ "ignore:custom data:UserWarning",
83
+ ]
@@ -1,5 +1,7 @@
1
+ import warnings
2
+
1
3
  from .models import get_pretrained as get_pretrained
4
+ from .models import save_checkpoint as save_checkpoint
2
5
 
3
- import warnings
4
6
 
5
7
  warnings.filterwarnings("ignore", category=UserWarning, message="custom data")
@@ -0,0 +1,26 @@
1
+ import tempfile
2
+
3
+ from metatomic.torch import AtomisticModel
4
+ from metatomic.torch.ase_calculator import MetatomicCalculator
5
+
6
+
7
+ class EnergyCalculator(MetatomicCalculator):
8
+ """
9
+ ASE calculator for energy predictions using a metatomic AtomisticModel.
10
+
11
+ Slightly modified to save the model to a temporary file to ensure compatibility
12
+ with ase.io.Trajectory.
13
+ """
14
+
15
+ def __init__(self, model, *args, **kwargs):
16
+ # save the model to a path otherwise it won't work with ase.io.Trajectory
17
+ # which calls todict on the calculator
18
+
19
+ if isinstance(model, AtomisticModel):
20
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pt") as f:
21
+ path = f.name
22
+ model.save(path)
23
+ else:
24
+ path = model
25
+
26
+ super().__init__(path, *args, **kwargs)
@@ -1,10 +1,10 @@
1
- from .velocity_verlet import VelocityVerlet
2
- import ase.units
3
- from typing import List
4
- from metatomic.torch import AtomisticModel
5
- import torch
6
1
  import ase
2
+ import ase.units
7
3
  import numpy as np
4
+ import torch
5
+ from metatomic.torch import AtomisticModel
6
+
7
+ from .velocity_verlet import VelocityVerlet
8
8
 
9
9
 
10
10
  class Bussi(VelocityVerlet):
@@ -13,14 +13,16 @@ class Bussi(VelocityVerlet):
13
13
  atoms: ase.Atoms,
14
14
  timestep: float,
15
15
  temperature_K: float,
16
- model: AtomisticModel | List[AtomisticModel],
16
+ model: AtomisticModel,
17
17
  time_constant: float = 10.0 * ase.units.fs,
18
18
  device: str | torch.device = "auto",
19
19
  rescale_energy: bool = False,
20
20
  random_rotation: bool = False,
21
21
  **kwargs,
22
22
  ):
23
- super().__init__(atoms, timestep, model, device, rescale_energy, random_rotation, **kwargs)
23
+ super().__init__(
24
+ atoms, timestep, model, device, rescale_energy, random_rotation, **kwargs
25
+ )
24
26
 
25
27
  self.temperature_K = temperature_K
26
28
  self.time_constant = time_constant
@@ -1,10 +1,10 @@
1
- from .velocity_verlet import VelocityVerlet
2
- import ase.units
3
- from typing import List
4
- from metatomic.torch import AtomisticModel
5
- import torch
6
1
  import ase
2
+ import ase.units
7
3
  import numpy as np
4
+ import torch
5
+ from metatomic.torch import AtomisticModel
6
+
7
+ from .velocity_verlet import VelocityVerlet
8
8
 
9
9
 
10
10
  class Langevin(VelocityVerlet):
@@ -13,7 +13,7 @@ class Langevin(VelocityVerlet):
13
13
  atoms: ase.Atoms,
14
14
  timestep: float,
15
15
  temperature_K: float,
16
- model: AtomisticModel | List[AtomisticModel],
16
+ model: AtomisticModel,
17
17
  time_constant: float = 100.0 * ase.units.fs,
18
18
  fixcm: bool = True,
19
19
  device: str | torch.device = "auto",
@@ -21,13 +21,18 @@ class Langevin(VelocityVerlet):
21
21
  random_rotation: bool = False,
22
22
  **kwargs,
23
23
  ):
24
- super().__init__(atoms, timestep, model, device, rescale_energy, random_rotation, **kwargs)
24
+ super().__init__(
25
+ atoms, timestep, model, device, rescale_energy, random_rotation, **kwargs
26
+ )
25
27
 
26
28
  self.temperature_K = temperature_K
27
29
  self.friction = 1.0 / time_constant
28
30
  self.fixcm = fixcm
29
31
  if self.fixcm:
30
- self.atoms.set_velocities(self.atoms.get_velocities() - self.atoms.get_momenta().sum(axis=0) / self.atoms.get_masses().sum())
32
+ self.atoms.set_velocities(
33
+ self.atoms.get_velocities()
34
+ - self.atoms.get_momenta().sum(axis=0) / self.atoms.get_masses().sum()
35
+ )
31
36
 
32
37
  def step(self):
33
38
  self.apply_langevin_half_step()
@@ -43,4 +48,7 @@ class Langevin(VelocityVerlet):
43
48
  ) * np.random.randn(*old_momenta.shape)
44
49
  self.atoms.set_momenta(new_momenta)
45
50
  if self.fixcm:
46
- self.atoms.set_velocities(self.atoms.get_velocities() - self.atoms.get_momenta().sum(axis=0) / self.atoms.get_masses().sum())
51
+ self.atoms.set_velocities(
52
+ self.atoms.get_velocities()
53
+ - self.atoms.get_momenta().sum(axis=0) / self.atoms.get_masses().sum()
54
+ )
@@ -1,23 +1,22 @@
1
- from ase.md.md import MolecularDynamics
2
- from typing import List
3
- from metatomic.torch import AtomisticModel
4
- from metatensor.torch import Labels, TensorBlock, TensorMap
1
+ import ase
5
2
  import ase.units
3
+ import numpy as np
6
4
  import torch
5
+ from ase.md.md import MolecularDynamics
6
+ from metatensor.torch import Labels, TensorBlock, TensorMap
7
+ from metatomic.torch import AtomisticModel, System
7
8
  from metatomic.torch.ase_calculator import _ase_to_torch_data
8
- from metatomic.torch import System
9
- import ase
10
- from ..stepper import FlashMDStepper
11
- import numpy as np
12
9
  from scipy.spatial.transform import Rotation
13
10
 
11
+ from ..stepper import FlashMDStepper
12
+
14
13
 
15
14
  class VelocityVerlet(MolecularDynamics):
16
15
  def __init__(
17
16
  self,
18
17
  atoms: ase.Atoms,
19
18
  timestep: float,
20
- model: AtomisticModel | List[AtomisticModel],
19
+ model: AtomisticModel,
21
20
  device: str | torch.device = "auto",
22
21
  rescale_energy: bool = True,
23
22
  random_rotation: bool = False,
@@ -66,8 +65,8 @@ class VelocityVerlet(MolecularDynamics):
66
65
  system.positions = system.positions @ R.T
67
66
  # change momentum TensorMap in place
68
67
  system.get_data("momenta").block().values[:] = (
69
- (system.get_data("momenta").block().values.squeeze(-1) @ R.T).unsqueeze(-1)
70
- )
68
+ system.get_data("momenta").block().values.squeeze(-1) @ R.T
69
+ ).unsqueeze(-1)
71
70
 
72
71
  new_system = self.stepper.step(system)
73
72
 
@@ -76,8 +75,8 @@ class VelocityVerlet(MolecularDynamics):
76
75
  new_system.cell = old_cell
77
76
  new_system.positions = new_system.positions @ R
78
77
  new_system.get_data("momenta").block().values[:] = (
79
- (new_system.get_data("momenta").block().values.squeeze(-1) @ R).unsqueeze(-1)
80
- )
78
+ new_system.get_data("momenta").block().values.squeeze(-1) @ R
79
+ ).unsqueeze(-1)
81
80
 
82
81
  self.atoms.set_positions(new_system.positions.detach().cpu().numpy())
83
82
  self.atoms.set_momenta(
@@ -127,6 +126,7 @@ class VelocityVerlet(MolecularDynamics):
127
126
  for _ in self.irun(steps=steps):
128
127
  pass
129
128
 
129
+
130
130
  def _convert_atoms_to_system(
131
131
  atoms: ase.Atoms, dtype: str, device: str | torch.device
132
132
  ) -> System:
@@ -1,17 +1,16 @@
1
+ import ase.data
2
+ import ase.units
3
+ import numpy as np
4
+ import torch
5
+ from ipi.engine.motion.dynamics import NPTIntegrator, NVEIntegrator, NVTIntegrator
1
6
  from ipi.utils.depend import dstrip
2
- from ipi.utils.units import Constants
3
- from ipi.utils.messages import verbosity, info
4
7
  from ipi.utils.mathtools import random_rotation as random_rotation_matrix
5
- from ipi.engine.motion.dynamics import NVEIntegrator, NVTIntegrator, NPTIntegrator
8
+ from ipi.utils.messages import info, verbosity
9
+ from ipi.utils.units import Constants
10
+ from metatensor.torch import Labels, TensorBlock, TensorMap
11
+ from metatomic.torch import System
6
12
 
7
13
  from flashmd.stepper import FlashMDStepper
8
- import ase.units
9
- import torch
10
- import numpy as np
11
- import ase.data
12
-
13
- from metatomic.torch import System
14
- from metatensor.torch import Labels, TensorBlock, TensorMap
15
14
 
16
15
 
17
16
  def get_standard_vv_step(
@@ -56,7 +55,9 @@ def get_standard_vv_step(
56
55
  return vv_step
57
56
 
58
57
 
59
- def get_flashmd_vv_step(sim, model, device, rescale_energy=False, random_rotation=False):
58
+ def get_flashmd_vv_step(
59
+ sim, model, device, rescale_energy=False, random_rotation=False
60
+ ):
60
61
  capabilities = model.capabilities()
61
62
 
62
63
  model_timestep = float(model.module.timestep)