cyrusyc commited on
Commit
e693b09
·
1 Parent(s): d67a19b

improve md doc

Browse files
Files changed (1) hide show
  1. mlip_arena/tasks/md.py +43 -4
mlip_arena/tasks/md.py CHANGED
@@ -193,9 +193,7 @@ def _generate_task_run_name():
193
 
194
 
195
  @task(
196
- name="MD",
197
- task_run_name=_generate_task_run_name,
198
- cache_policy=TASK_SOURCE + INPUTS
199
  )
200
  def run(
201
  atoms: Atoms,
@@ -214,7 +212,44 @@ def run(
214
  traj_interval: int = 1,
215
  restart: bool = True,
216
  ):
217
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  atoms = atoms.copy()
219
 
220
  atoms.calc = calculator
@@ -311,11 +346,15 @@ def run(
311
  if zero_angular_momentum:
312
  ZeroRotation(atoms)
313
 
 
 
314
  md_runner = md_class(
315
  atoms=atoms,
316
  timestep=time_step * units.fs,
317
  **dynamics_kwargs,
318
  )
 
 
319
 
320
  if traj_file is not None:
321
  md_runner.attach(traj.write, interval=traj_interval)
 
193
 
194
 
195
  @task(
196
+ name="MD", task_run_name=_generate_task_run_name, cache_policy=TASK_SOURCE + INPUTS
 
 
197
  )
198
  def run(
199
  atoms: Atoms,
 
212
  traj_interval: int = 1,
213
  restart: bool = True,
214
  ):
215
+ """
216
+ Run a molecular dynamics (MD) simulation using ASE.
217
+
218
+ Parameters:
219
+ atoms (Atoms): The atomic structure to simulate.
220
+ calculator (BaseCalculator): The calculator to use for energy and force calculations.
221
+ ensemble (Literal["nve", "nvt", "npt"], optional): The MD ensemble to use. Defaults to "nvt".
222
+ dynamics (str | MolecularDynamics, optional): The dynamics method to use. Defaults to "langevin".
223
+ time_step (float | None, optional): The time step for the simulation in femtoseconds.
224
+ Defaults to 0.5 fs if hydrogen isotopes are present, otherwise 2.0 fs.
225
+ total_time (float, optional): The total simulation time in femtoseconds. Defaults to 1000 fs.
226
+ temperature (float | Sequence | np.ndarray | None, optional): The temperature schedule in Kelvin.
227
+ Can be a scalar or a sequence. Defaults to 300 K.
228
+ pressure (float | Sequence | np.ndarray | None, optional): The pressure schedule in eV/ų.
229
+ Can be a scalar or a sequence. Defaults to None.
230
+ dynamics_kwargs (dict | None, optional): Additional keyword arguments for the dynamics method. Defaults to None.
231
+ velocity_seed (int | None, optional): Seed for random number generation for initial velocities. Defaults to None.
232
+ zero_linear_momentum (bool, optional): Whether to remove linear momentum from the system. Defaults to True.
233
+ zero_angular_momentum (bool, optional): Whether to remove angular momentum from the system. Defaults to True.
234
+ traj_file (str | Path | None, optional): Path to the trajectory file for saving simulation results. Defaults to None.
235
+ traj_interval (int, optional): Interval for saving trajectory frames. Defaults to 1.
236
+ restart (bool, optional): Whether to restart the simulation from an existing trajectory file. Defaults to True.
237
+
238
+ Returns:
239
+ dict: A dictionary containing the following keys:
240
+ - "atoms" (Atoms): The final atomic structure after the simulation.
241
+ - "runtime" (timedelta): The runtime of the simulation.
242
+ - "n_steps" (int): The number of steps performed in the simulation.
243
+
244
+ Raises:
245
+ ValueError: If an invalid dynamics method is specified or if the dynamics method is incompatible with the ensemble.
246
+
247
+ Notes:
248
+ - The function supports restarting from an existing trajectory file if `restart` is True.
249
+ - For NPT dynamics, the atomic cell is transformed to an upper triangular form to meet ASE's requirements.
250
+ - Temperature and pressure schedules can be specified as sequences or arrays for time-dependent control.
251
+ """
252
+
253
  atoms = atoms.copy()
254
 
255
  atoms.calc = calculator
 
346
  if zero_angular_momentum:
347
  ZeroRotation(atoms)
348
 
349
+ fraction_traceless = dynamics_kwargs.pop("fraction_traceless", 1.0)
350
+
351
  md_runner = md_class(
352
  atoms=atoms,
353
  timestep=time_step * units.fs,
354
  **dynamics_kwargs,
355
  )
356
+ if md_class is NPT:
357
+ md_runner.set_fraction_traceless(fraction_traceless)
358
 
359
  if traj_file is not None:
360
  md_runner.attach(traj.write, interval=traj_interval)