Skip to content

Commit 26e0006

Browse files
committed
unit test
1 parent 02679af commit 26e0006

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

mlip_arena/tasks/md.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,42 @@ def run(
337337
traj = Trajectory(traj_file, "w", atoms)
338338

339339
if not np.isnan(t_schedule).any():
340-
MaxwellBoltzmannDistribution(
341-
atoms=atoms,
342-
temperature_K=t_schedule[last_step],
343-
rng=np.random.default_rng(seed=velocity_seed),
344-
)
340+
if atoms.get_temperature() == 0.0:
341+
MaxwellBoltzmannDistribution(
342+
atoms=atoms,
343+
temperature_K=t_schedule[0],
344+
rng=np.random.default_rng(seed=velocity_seed),
345+
)
346+
else:
347+
atoms.set_momenta(
348+
atoms.get_momenta() * np.sqrt(
349+
t_schedule[0] / atoms.get_temperature()
350+
)
351+
)
345352

346353
if zero_linear_momentum:
347354
Stationary(atoms)
348355
if zero_angular_momentum:
349356
ZeroRotation(atoms)
357+
else:
358+
if not np.isnan(t_schedule).any():
359+
if atoms.get_temperature() == 0.0:
360+
MaxwellBoltzmannDistribution(
361+
atoms=atoms,
362+
temperature_K=t_schedule[0],
363+
rng=np.random.default_rng(seed=velocity_seed),
364+
)
365+
else:
366+
atoms.set_momenta(
367+
atoms.get_momenta() * np.sqrt(
368+
t_schedule[0] / atoms.get_temperature()
369+
)
370+
)
371+
372+
if zero_linear_momentum:
373+
Stationary(atoms)
374+
if zero_angular_momentum:
375+
ZeroRotation(atoms)
350376

351377
fraction_traceless = dynamics_kwargs.pop("fraction_traceless", 1.0)
352378

mlip_arena/tasks/viscosity.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def run(
254254
)
255255
atoms = result["atoms"]
256256

257+
# rescale temperature and volume
258+
257259
# Second stage: NVE equilibration
258260

259261
if nve_eq_time > 0:
@@ -355,9 +357,9 @@ def store_stress(dyn: MolecularDynamics):
355357
"viscosity": {
356358
"units": "mPa·s",
357359
"components": {
358-
"pxy": viscosity_components[0] * 1e3,
359-
"pxz": viscosity_components[1] * 1e3,
360-
"pyz": viscosity_components[2] * 1e3,
360+
"xy": viscosity_components[0] * 1e3,
361+
"xz": viscosity_components[1] * 1e3,
362+
"yz": viscosity_components[2] * 1e3,
361363
},
362364
"average": eta_mPa_s,
363365
"final": eta_mPa_s.mean(),

tests/test_viscosity.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import numpy as np
2+
from ase.build import bulk
3+
from ase.calculators.lj import LennardJones
4+
5+
from mlip_arena.tasks.viscosity import run as VISCOSITY
6+
7+
8+
def test_task_run():
9+
"""Test the viscosity task."""
10+
atoms = bulk("Cu", "fcc", a=3.6, cubic=True) * (2, 2, 2)
11+
12+
atoms.positions = atoms.positions + 0.5 * np.random.rand(*atoms.positions.shape)
13+
14+
calculator = LennardJones(
15+
epsilon=0.01, sigma=(atoms.get_volume() / len(atoms)) ** (1 / 3)
16+
)
17+
18+
result = VISCOSITY(
19+
atoms,
20+
calculator=calculator,
21+
temperature=1250,
22+
pressure=0,
23+
npt_eq_time=100,
24+
nve_eq_time=100,
25+
prod_time=100,
26+
)
27+
assert isinstance(result, dict)
28+
assert "viscosity" in result
29+
assert isinstance(result["viscosity"]["average"], float)

0 commit comments

Comments
 (0)