Skip to content

Commit 5e1c57c

Browse files
Include units in test driver arguments
1 parent 0200ef4 commit 5e1c57c

3 files changed

Lines changed: 1778 additions & 1775 deletions

File tree

test_driver/helper_functions.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import numpy.typing as npt
99

1010

11-
def run_lammps(modelname: str, temperature: float, pressure: float, timestep: float, number_sampling_timesteps: int,
12-
species: List[str], msd_threshold: float, lammps_command: str,
11+
def run_lammps(modelname: str, temperature_K: float, pressure_bar: float, timestep_ps: float,
12+
number_sampling_timesteps: int, species: List[str],
13+
msd_threshold_angstrom_squared_per_hundred_timesteps: float, lammps_command: str,
1314
random_seed: int) -> Tuple[str, str, str, str]:
1415
"""
1516
Run LAMMPS NPT simulation with the given parameters.
@@ -23,24 +24,24 @@ def run_lammps(modelname: str, temperature: float, pressure: float, timestep: fl
2324
:param modelname:
2425
Name of the OpenKIM interatomic model.
2526
:type modelname: str
26-
:param temperature:
27+
:param temperature_K:
2728
Target temperature in Kelvin.
28-
:type temperature: float
29-
:param pressure:
29+
:type temperature_K: float
30+
:param pressure_bar:
3031
Target pressure in bars.
31-
:type pressure: float
32-
:param timestep:
32+
:type pressure_bar: float
33+
:param timestep_ps:
3334
Timestep in picoseconds.
34-
:type timestep: float
35+
:type timestep_ps: float
3536
:param number_sampling_timesteps:
3637
Number of timesteps for sampling thermodynamic quantities.
3738
:type number_sampling_timesteps: int
3839
:param species:
3940
List of chemical species in the system.
4041
:type species: List[str]
41-
:param msd_threshold:
42+
:param msd_threshold_angstrom_squared_per_hundred_timesteps:
4243
Mean squared displacement threshold for vaporization in Angstroms^2 per 100*timestep.
43-
:type msd_threshold: float
44+
:type msd_threshold_angstrom_squared_per_hundred_timesteps: float
4445
:param lammps_command:
4546
Command to run LAMMPS (e.g., "mpirun -np 4 lmp_mpi" or "lmp").
4647
:type lammps_command: str
@@ -53,26 +54,26 @@ def run_lammps(modelname: str, temperature: float, pressure: float, timestep: fl
5354
file.
5455
:rtype: Tuple[str, str, str, str]
5556
"""
56-
pdamp = timestep * 100.0
57-
tdamp = timestep * 1000.0
57+
pdamp = timestep_ps * 100.0
58+
tdamp = timestep_ps * 1000.0
5859

5960
log_filename = "output/lammps.log"
6061
restart_filename = "output/final_configuration.restart"
6162
variables = {
6263
"modelname": modelname,
63-
"temperature": temperature,
64+
"temperature": temperature_K,
6465
"temperature_seed": random_seed,
6566
"temperature_damping": tdamp,
66-
"pressure": pressure,
67+
"pressure": pressure_bar,
6768
"pressure_damping": pdamp,
68-
"timestep": timestep,
69+
"timestep": timestep_ps,
6970
"number_sampling_timesteps": number_sampling_timesteps,
7071
"species": " ".join(species),
7172
"average_position_filename": "output/average_position.dump.*",
7273
"average_cell_filename": "output/average_cell.dump",
7374
"write_restart_filename": restart_filename,
7475
"trajectory_filename": "output/trajectory.lammpstrj",
75-
"msd_threshold": msd_threshold
76+
"msd_threshold": msd_threshold_angstrom_squared_per_hundred_timesteps
7677
}
7778

7879
command = (

test_driver/test_driver.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111

1212
class TestDriver(SingleCrystalTestDriver):
13-
def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repeat: Sequence[int] = (0, 0, 0),
14-
lammps_command = "lmp", msd_threshold: float = 0.1, random_seed: int = 1, **kwargs) -> None:
13+
def _calculate(self, timestep_ps: float, number_sampling_timesteps: int = 100, repeat: Sequence[int] = (0, 0, 0),
14+
lammps_command = "lmp", msd_threshold_angstrom_squared_per_hundred_timesteps: float = 0.1,
15+
random_seed: int = 1, **kwargs) -> None:
1516
"""
1617
Compute crystal structure at constant pressure and temperature (NPT) with a Lammps molecular-dynamics simulation.
1718
@@ -32,10 +33,10 @@ def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repe
3233
3334
All output files are written to the "output" directory.
3435
35-
:param timestep:
36+
:param timestep_ps:
3637
Time step in picoseconds.
3738
Should be bigger than zero.
38-
:type timestep: float
39+
:type timestep_ps: float
3940
:param number_sampling_timesteps:
4041
Sample thermodynamic variables every number_sampling_timesteps timesteps in Lammps.
4142
Should be bigger than zero.
@@ -51,11 +52,11 @@ def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repe
5152
Command to run Lammps.
5253
Default is "lmp".
5354
:type lammps_command: str
54-
:param msd_threshold:
55+
:param msd_threshold_angstrom_squared_per_hundred_timesteps:
5556
Mean-squared displacement threshold in Angstroms^2 per 100*timestep to detect melting or vaporization.
5657
Default is 0.1.
5758
Should be bigger than zero.
58-
:type msd_threshold: float
59+
:type msd_threshold_angstrom_squared_per_hundred_timesteps: float
5960
:param random_seed:
6061
Random seed for Lammps simulation.
6162
Default is 1.
@@ -93,7 +94,7 @@ def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repe
9394
raise ValueError("The off-diagonal entries of the stress tensor have to be zero so that a hydrostatic "
9495
"pressure is used.")
9596

96-
if not timestep > 0.0:
97+
if not timestep_ps > 0.0:
9798
raise ValueError("Timestep has to be larger than zero.")
9899

99100
if not number_sampling_timesteps > 0:
@@ -105,7 +106,7 @@ def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repe
105106
if not all(r >= 0 for r in repeat):
106107
raise RuntimeError("All number of repeats must be bigger than zero.")
107108

108-
if not msd_threshold > 0.0:
109+
if not msd_threshold_angstrom_squared_per_hundred_timesteps > 0.0:
109110
raise RuntimeError("The mean-squared displacement threshold has to be bigger than zero.")
110111

111112
if not random_seed > 0:
@@ -172,8 +173,9 @@ def _calculate(self, timestep: float, number_sampling_timesteps: int = 100, repe
172173

173174
# Run single Lammps simulation.
174175
log_filename, restart_filename, average_position_filename, average_cell_filename = run_lammps(
175-
self.kim_model_name, temperature_K, pressure_bar, timestep, number_sampling_timesteps, species,
176-
msd_threshold, lammps_command=lammps_command, random_seed=random_seed)
176+
self.kim_model_name, temperature_K, pressure_bar, timestep_ps, number_sampling_timesteps, species,
177+
msd_threshold_angstrom_squared_per_hundred_timesteps, lammps_command=lammps_command,
178+
random_seed=random_seed)
177179

178180
# Check that crystal did not melt or vaporize.
179181
with open(log_filename, "r") as f:

0 commit comments

Comments
 (0)