Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unittest for virial and pe/atom #4013

Merged
merged 20 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e1f6632
add unittest for total virial
Yi-FanLi Jul 24, 2024
100786d
Merge branch 'devel' into virial_test
Yi-FanLi Jul 24, 2024
70193dd
add unittest for atomic energy
Yi-FanLi Jul 24, 2024
db1c37c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
721a261
bugfix: lammps variable definition
Yi-FanLi Jul 24, 2024
8dc8123
Merge branch 'virial_test' of github.com:Yi-FanLi/deepmd-kit into vir…
Yi-FanLi Jul 24, 2024
454ab0e
bugfix: eatom should be defined by equal rather than atom
Yi-FanLi Jul 24, 2024
a66bb9f
add missing s
Yi-FanLi Jul 24, 2024
6c39839
pressure x vol = virial
Yi-FanLi Jul 24, 2024
54ae228
Merge branch 'virial_test' of github.com:Yi-FanLi/deepmd-kit into vir…
Yi-FanLi Jul 24, 2024
fea3723
should be division
Yi-FanLi Jul 24, 2024
b3e4725
pressure and centroid/stress/atom are different on a negative sign
Yi-FanLi Jul 24, 2024
c88faf5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
c3a2318
pressure is 6-dim, not 9-dim
Yi-FanLi Jul 24, 2024
ec8b72b
fix merge conflict
Yi-FanLi Jul 24, 2024
2151cd9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
32c569d
add test for pair_deepmd_model_devi_virial
Yi-FanLi Jul 24, 2024
6c6cabf
Merge branch 'virial_test' of github.com:Yi-FanLi/deepmd-kit into vir…
Yi-FanLi Jul 24, 2024
43e24d2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 24, 2024
a0df97e
Merge branch 'devel' into virial_test
Yi-FanLi Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion source/lmp/tests/test_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
]
)

expected_v = -np.array(
expected_v = -np.array( # This minus sign comes from the definition of the compute centroid/stress/atom command in LAMMPS. See https://docs.lammps.org/compute_stress_atom.html
[
-2.912234126853306959e-01,
-3.800610846612756388e-02,
Expand Down Expand Up @@ -321,7 +321,13 @@ def test_pair_deepmd(lammps):
def test_pair_deepmd_virial(lammps):
lammps.pair_style(f"deepmd {pb_file.resolve()}")
lammps.pair_coeff("* *")
lammps.compute("peatom all pe/atom pair")
lammps.compute("pressure all pressure NULL pair")
lammps.compute("virial all centroid/stress/atom NULL pair")
lammps.variable("eatom atom c_peatom")
for ii in range(9):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
lammps.variable(f"pressure{jj} equal c_pressure[{ii+1}]")
for ii in range(9):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
lammps.variable(f"virial{jj} atom c_virial[{ii+1}]")
Expand All @@ -335,6 +341,17 @@ def test_pair_deepmd_virial(lammps):
expected_f[lammps.atoms[ii].id - 1]
)
idx_map = lammps.lmp.numpy.extract_atom("id") - 1
assert np.array(lammps.variables["eatom"].value) == pytest.approx(
expected_ae[idx_map]
)
vol = box[1] * box[3] * box[5]
for ii in range(6):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
assert np.array(
lammps.variables[f"pressure{jj}"].value
) / constants.nktv2p == pytest.approx(
-expected_v[idx_map, jj].sum(axis=0) / vol
)
for ii in range(9):
assert np.array(
lammps.variables[f"virial{ii}"].value
Expand Down Expand Up @@ -372,7 +389,13 @@ def test_pair_deepmd_model_devi_virial(lammps):
f"deepmd {pb_file.resolve()} {pb_file2.resolve()} out_file {md_file.resolve()} out_freq 1 atomic"
)
lammps.pair_coeff("* *")
lammps.compute("peatom all pe/atom pair")
lammps.compute("pressure all pressure NULL pair")
lammps.compute("virial all centroid/stress/atom NULL pair")
lammps.variable("eatom atom c_peatom")
for ii in range(9):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
lammps.variable(f"pressure{jj} equal c_pressure[{ii+1}]")
for ii in range(9):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
lammps.variable(f"virial{jj} atom c_virial[{ii+1}]")
Expand All @@ -386,6 +409,17 @@ def test_pair_deepmd_model_devi_virial(lammps):
expected_f[lammps.atoms[ii].id - 1]
)
idx_map = lammps.lmp.numpy.extract_atom("id") - 1
assert np.array(lammps.variables["eatom"].value) == pytest.approx(
expected_ae[idx_map]
)
vol = box[1] * box[3] * box[5]
for ii in range(6):
jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii]
assert np.array(
lammps.variables[f"pressure{jj}"].value
) / constants.nktv2p == pytest.approx(
-expected_v[idx_map, jj].sum(axis=0) / vol
)
for ii in range(9):
assert np.array(
lammps.variables[f"virial{ii}"].value
Expand Down