flashmd 0.2.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashmd
3
- Version: 0.2.6
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
@@ -55,11 +55,11 @@ After installation, you can run accelerated molecular dynamics as follows:
55
55
  ```py
56
56
  import ase.build
57
57
  import ase.units
58
- from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
59
58
  import torch
60
- from metatomic.torch.ase_calculator import MetatomicCalculator
59
+ from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
61
60
 
62
61
  from flashmd import get_pretrained
62
+ from flashmd.ase import EnergyCalculator
63
63
  from flashmd.ase.langevin import Langevin
64
64
 
65
65
 
@@ -74,11 +74,11 @@ atoms.set_velocities( # it is generally a good idea to remove any net velocity
74
74
  )
75
75
 
76
76
  # Load models
77
- device="cuda" if torch.cuda.is_available() else "cpu"
78
- energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
77
+ device = "cuda" if torch.cuda.is_available() else "cpu"
78
+ energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
79
79
 
80
- # Set the energy model (see below for more precise usage)
81
- 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)
82
82
  atoms.calc = calculator
83
83
 
84
84
  # Run MD
@@ -88,9 +88,9 @@ dyn = Langevin(
88
88
  temperature_K=300,
89
89
  time_constant=100*ase.units.fs,
90
90
  model=flashmd_model,
91
- device=device
91
+ device=device,
92
92
  )
93
- dyn.run(1000)
93
+ dyn.run(1000) # this is 64 ps!
94
94
  ```
95
95
 
96
96
  [The first time you use this code and call the `get_pretrained` function, the
@@ -22,11 +22,11 @@ After installation, you can run accelerated molecular dynamics as follows:
22
22
  ```py
23
23
  import ase.build
24
24
  import ase.units
25
- from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
26
25
  import torch
27
- from metatomic.torch.ase_calculator import MetatomicCalculator
26
+ from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
28
27
 
29
28
  from flashmd import get_pretrained
29
+ from flashmd.ase import EnergyCalculator
30
30
  from flashmd.ase.langevin import Langevin
31
31
 
32
32
 
@@ -41,11 +41,11 @@ atoms.set_velocities( # it is generally a good idea to remove any net velocity
41
41
  )
42
42
 
43
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)
44
+ device = "cuda" if torch.cuda.is_available() else "cpu"
45
+ energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
46
46
 
47
- # Set the energy model (see below for more precise usage)
48
- calculator = MetatomicCalculator(energy_model, device=device)
47
+ # Set the energy model (optional, see below for more precise usage)
48
+ calculator = EnergyCalculator(energy_model, device=device)
49
49
  atoms.calc = calculator
50
50
 
51
51
  # Run MD
@@ -55,9 +55,9 @@ dyn = Langevin(
55
55
  temperature_K=300,
56
56
  time_constant=100*ase.units.fs,
57
57
  model=flashmd_model,
58
- device=device
58
+ device=device,
59
59
  )
60
- dyn.run(1000)
60
+ dyn.run(1000) # this is 64 ps!
61
61
  ```
62
62
 
63
63
  [The first time you use this code and call the `get_pretrained` function, the
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flashmd"
3
- version = "0.2.6"
3
+ version = "0.2.7"
4
4
  requires-python = ">=3.9"
5
5
 
6
6
  readme = "README.md"
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashmd
3
- Version: 0.2.6
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
@@ -55,11 +55,11 @@ After installation, you can run accelerated molecular dynamics as follows:
55
55
  ```py
56
56
  import ase.build
57
57
  import ase.units
58
- from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
59
58
  import torch
60
- from metatomic.torch.ase_calculator import MetatomicCalculator
59
+ from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
61
60
 
62
61
  from flashmd import get_pretrained
62
+ from flashmd.ase import EnergyCalculator
63
63
  from flashmd.ase.langevin import Langevin
64
64
 
65
65
 
@@ -74,11 +74,11 @@ atoms.set_velocities( # it is generally a good idea to remove any net velocity
74
74
  )
75
75
 
76
76
  # Load models
77
- device="cuda" if torch.cuda.is_available() else "cpu"
78
- energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
77
+ device = "cuda" if torch.cuda.is_available() else "cpu"
78
+ energy_model, flashmd_model = get_pretrained("pet-omatpes-v2", time_step)
79
79
 
80
- # Set the energy model (see below for more precise usage)
81
- 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)
82
82
  atoms.calc = calculator
83
83
 
84
84
  # Run MD
@@ -88,9 +88,9 @@ dyn = Langevin(
88
88
  temperature_K=300,
89
89
  time_constant=100*ase.units.fs,
90
90
  model=flashmd_model,
91
- device=device
91
+ device=device,
92
92
  )
93
- dyn.run(1000)
93
+ dyn.run(1000) # this is 64 ps!
94
94
  ```
95
95
 
96
96
  [The first time you use this code and call the `get_pretrained` function, the
@@ -15,5 +15,6 @@ src/flashmd/ase/__init__.py
15
15
  src/flashmd/ase/bussi.py
16
16
  src/flashmd/ase/langevin.py
17
17
  src/flashmd/ase/velocity_verlet.py
18
+ tests/test_energy.py
18
19
  tests/test_models.py
19
20
  tests/test_readme.py
@@ -0,0 +1,29 @@
1
+ import ase.build
2
+ import ase.io
3
+ import ase.units
4
+ import torch
5
+ from ase.md import VelocityVerlet
6
+
7
+ from flashmd import get_pretrained
8
+ from flashmd.ase import EnergyCalculator
9
+
10
+
11
+ def test_md(monkeypatch, tmp_path):
12
+ """Test that a short MD run completes without errors with a Trajectory file."""
13
+ monkeypatch.chdir(tmp_path)
14
+
15
+ atoms = ase.build.bulk("Al", "fcc", cubic=True)
16
+
17
+ time_step = 64
18
+ device = "cuda" if torch.cuda.is_available() else "cpu"
19
+ energy_model, _ = get_pretrained("pet-omatpes-v2", time_step)
20
+ calculator = EnergyCalculator(
21
+ energy_model, device=device, do_gradients_with_energy=False
22
+ )
23
+ atoms.calc = calculator
24
+
25
+ dyn = VelocityVerlet(atoms=atoms, timestep=time_step * ase.units.fs)
26
+ traj = ase.io.Trajectory("test_md.traj", "w", atoms)
27
+ dyn.attach(traj.write)
28
+ dyn.run(10)
29
+ traj.close()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes