flashmd 0.2.3__tar.gz → 0.2.4__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.3
3
+ Version: 0.2.4
4
4
  Summary: Accelerated molecular dynamics with large-time-step predictions
5
5
  Author: flashmd developers
6
6
  License: Apache-2.0
@@ -65,14 +65,15 @@ time_step = 64 # 64 fs; also available: 1, 2, 4, 8, 16, 32, 128 fs
65
65
  # Create a structure and initialize velocities
66
66
  atoms = ase.build.bulk("Al", "fcc", cubic=True)
67
67
  MaxwellBoltzmannDistribution(atoms, temperature_K=300)
68
-
69
- # It is generally a good idea to remove any net velocity from the system
70
- atoms.set_velocities(atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum())
68
+ atoms.set_velocities( # it is generally a good idea to remove any net velocity
69
+ atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum()
70
+ )
71
71
 
72
72
  # Load models
73
73
  device="cuda" if torch.cuda.is_available() else "cpu"
74
74
  energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
75
75
 
76
+ # Set the energy model (see below for more precise usage)
76
77
  calculator = MetatomicCalculator(energy_model, device=device)
77
78
  atoms.calc = calculator
78
79
 
@@ -98,6 +99,60 @@ Other available integrators:
98
99
  from flashmd.ase.bussi import Bussi
99
100
  ```
100
101
 
102
+ Common pitfalls
103
+ ---------------
104
+
105
+ Stick to 10-30x what you would use in normal MD for your system! The 64 fs example
106
+ above is good for metals. However,
107
+ - for most materials: try 32 fs (aggressive) or 16 fs (conservative)
108
+ - for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
109
+
110
+
111
+ Companion energy models and exact energy conservation
112
+ -----------------------------------------------------
113
+
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...
118
+
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
+ ```
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.
138
+
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:
142
+
143
+ ```
144
+ from metatomic.torch.ase_calculator import MetatomicCalculator
145
+
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.
155
+
101
156
  Disclaimer
102
157
  ----------
103
158
 
@@ -36,14 +36,15 @@ time_step = 64 # 64 fs; also available: 1, 2, 4, 8, 16, 32, 128 fs
36
36
  # Create a structure and initialize velocities
37
37
  atoms = ase.build.bulk("Al", "fcc", cubic=True)
38
38
  MaxwellBoltzmannDistribution(atoms, temperature_K=300)
39
-
40
- # It is generally a good idea to remove any net velocity from the system
41
- atoms.set_velocities(atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum())
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
42
 
43
43
  # Load models
44
44
  device="cuda" if torch.cuda.is_available() else "cpu"
45
45
  energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
46
46
 
47
+ # Set the energy model (see below for more precise usage)
47
48
  calculator = MetatomicCalculator(energy_model, device=device)
48
49
  atoms.calc = calculator
49
50
 
@@ -69,6 +70,60 @@ Other available integrators:
69
70
  from flashmd.ase.bussi import Bussi
70
71
  ```
71
72
 
73
+ Common pitfalls
74
+ ---------------
75
+
76
+ Stick to 10-30x what you would use in normal MD for your system! The 64 fs example
77
+ above is good for metals. However,
78
+ - for most materials: try 32 fs (aggressive) or 16 fs (conservative)
79
+ - for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
80
+
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 don't need forces.
126
+
72
127
  Disclaimer
73
128
  ----------
74
129
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flashmd"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  requires-python = ">=3.9"
5
5
 
6
6
  readme = "README.md"
@@ -95,6 +95,37 @@ class VelocityVerlet(MolecularDynamics):
95
95
  alpha = np.sqrt(1.0 - (new_energy - old_energy) / old_kinetic_energy)
96
96
  self.atoms.set_momenta(alpha * self.atoms.get_momenta())
97
97
 
98
+ def irun(self, steps=50):
99
+ # We have to override irun to avoid calling MolecularDynamics.irun(), which
100
+ # calls gradients to check convergence (optimizer-like behavior) or to log the
101
+ # forces, depending on the ASE version. This function is a copy of
102
+ # Dynamics.irun(), where the calls to the forces are commented out.
103
+
104
+ # update the maximum number of steps
105
+ self.max_steps = self.nsteps + steps
106
+
107
+ if self.nsteps == 0:
108
+ # For historical reasons we do a magical incantation
109
+ # here with forces, log, observers.
110
+ # self.atoms.get_forces()
111
+ self.log()
112
+ self.call_observers()
113
+
114
+ yield self.nsteps == self.max_steps
115
+
116
+ # run the algorithm until converged or max_steps reached
117
+ while self.nsteps < self.max_steps:
118
+ self.step()
119
+ self.nsteps += 1
120
+ # self.atoms.get_forces()
121
+ self.log()
122
+ self.call_observers()
123
+ yield self.nsteps == self.max_steps
124
+
125
+ def run(self, steps=50):
126
+ # needed for ASE <= 3.26.0; in 3.27.0 Dynamics.run() works well for us
127
+ for _ in self.irun(steps=steps):
128
+ pass
98
129
 
99
130
  def _convert_atoms_to_system(
100
131
  atoms: ase.Atoms, dtype: str, device: str | torch.device
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flashmd
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Accelerated molecular dynamics with large-time-step predictions
5
5
  Author: flashmd developers
6
6
  License: Apache-2.0
@@ -65,14 +65,15 @@ time_step = 64 # 64 fs; also available: 1, 2, 4, 8, 16, 32, 128 fs
65
65
  # Create a structure and initialize velocities
66
66
  atoms = ase.build.bulk("Al", "fcc", cubic=True)
67
67
  MaxwellBoltzmannDistribution(atoms, temperature_K=300)
68
-
69
- # It is generally a good idea to remove any net velocity from the system
70
- atoms.set_velocities(atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum())
68
+ atoms.set_velocities( # it is generally a good idea to remove any net velocity
69
+ atoms.get_velocities() - atoms.get_momenta().sum(axis=0) / atoms.get_masses().sum()
70
+ )
71
71
 
72
72
  # Load models
73
73
  device="cuda" if torch.cuda.is_available() else "cpu"
74
74
  energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step)
75
75
 
76
+ # Set the energy model (see below for more precise usage)
76
77
  calculator = MetatomicCalculator(energy_model, device=device)
77
78
  atoms.calc = calculator
78
79
 
@@ -98,6 +99,60 @@ Other available integrators:
98
99
  from flashmd.ase.bussi import Bussi
99
100
  ```
100
101
 
102
+ Common pitfalls
103
+ ---------------
104
+
105
+ Stick to 10-30x what you would use in normal MD for your system! The 64 fs example
106
+ above is good for metals. However,
107
+ - for most materials: try 32 fs (aggressive) or 16 fs (conservative)
108
+ - for aqueous and/or organic systems: try 16 fs (aggressive) or 8 fs (conservative)
109
+
110
+
111
+ Companion energy models and exact energy conservation
112
+ -----------------------------------------------------
113
+
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...
118
+
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
+ ```
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.
138
+
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:
142
+
143
+ ```
144
+ from metatomic.torch.ase_calculator import MetatomicCalculator
145
+
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.
155
+
101
156
  Disclaimer
102
157
  ----------
103
158
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes