From e1f66326d512e3ede92309a0340e0d8523c8aa7b Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 21:54:48 -0400 Subject: [PATCH 01/14] add unittest for total virial --- source/lmp/tests/test_lammps.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 0e7c289f24..4b75cf1822 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -321,7 +321,11 @@ def test_pair_deepmd(lammps): def test_pair_deepmd_virial(lammps): lammps.pair_style(f"deepmd {pb_file.resolve()}") lammps.pair_coeff("* *") + lammps.compute("pressure all pressure NULL pair") lammps.compute("virial all centroid/stress/atom NULL pair") + for ii in range(9): + jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii] + lammps.variable(f"pressure{jj} 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}]") @@ -335,6 +339,10 @@ def test_pair_deepmd_virial(lammps): expected_f[lammps.atoms[ii].id - 1] ) idx_map = lammps.lmp.numpy.extract_atom("id") - 1 + for ii in range(9): + assert np.array( + lammps.variables[f"pressure{ii}"].value + ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0)) for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value From 70193dd4252ffdcb544b1dcdba63023bb75e0e60 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:00:25 -0400 Subject: [PATCH 02/14] add unittest for atomic energy --- source/lmp/tests/test_lammps.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 4b75cf1822..881ca8be76 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -321,8 +321,10 @@ 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} c_pressure[{ii+1}]") @@ -339,6 +341,7 @@ 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]) for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value From db1c37c8a863fe628649b8ba5aa8ad97b7b3df04 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 02:01:14 +0000 Subject: [PATCH 03/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/test_lammps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 881ca8be76..cd4f074729 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -341,7 +341,9 @@ 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]) + assert np.array(lammps.variables["eatom"].value) == pytest.approx( + expected_ae[idx_map] + ) for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value From 721a261e175bcb713ef60d3d6f8bc6aebf184de7 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:18:33 -0400 Subject: [PATCH 04/14] bugfix: lammps variable definition --- source/lmp/tests/test_lammps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 881ca8be76..db78bcae62 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -324,10 +324,10 @@ def test_pair_deepmd_virial(lammps): 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") + lammps.variable("eatom atom vector c_peatom") for ii in range(9): jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii] - lammps.variable(f"pressure{jj} c_pressure[{ii+1}]") + lammps.variable(f"pressure{jj} equal c_presure[{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}]") From 454ab0ecd2408e89659904312e0ba1f940222739 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:31:22 -0400 Subject: [PATCH 05/14] bugfix: eatom should be defined by equal rather than atom --- source/lmp/tests/test_lammps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 7f07461f60..3644fc5e0e 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -324,7 +324,7 @@ def test_pair_deepmd_virial(lammps): 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 vector c_peatom") + 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_presure[{ii+1}]") From a66bb9f366703083b5091dc8a5737d26135542f3 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:41:00 -0400 Subject: [PATCH 06/14] add missing s --- source/lmp/tests/test_lammps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 3644fc5e0e..599ef28a09 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -327,7 +327,7 @@ def test_pair_deepmd_virial(lammps): 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_presure[{ii+1}]") + 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}]") From 6c398392de0f59a83b2a798a3eef08cf53e7fea7 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:47:02 -0400 Subject: [PATCH 07/14] pressure x vol = virial --- source/lmp/tests/test_lammps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 3644fc5e0e..034921ac3c 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -344,10 +344,11 @@ def test_pair_deepmd_virial(lammps): assert np.array(lammps.variables["eatom"].value) == pytest.approx( expected_ae[idx_map] ) + vol = box[1] * box[3] * box[5] for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value - ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0)) + ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0) * vol) for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value From fea3723c618d550a31387f682b4804c1dc566271 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:48:40 -0400 Subject: [PATCH 08/14] should be division --- source/lmp/tests/test_lammps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index a822020112..0041a157b6 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -348,7 +348,7 @@ def test_pair_deepmd_virial(lammps): for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value - ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0) * vol) + ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0) / vol) for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value From b3e4725a2c2a5d3704ef422027b01cfb35b7998c Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 22:55:27 -0400 Subject: [PATCH 09/14] pressure and centroid/stress/atom are different on a negative sign --- source/lmp/tests/test_lammps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 0041a157b6..f291d2f13b 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -348,7 +348,7 @@ def test_pair_deepmd_virial(lammps): for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value - ) / constants.nktv2p == pytest.approx(expected_v[idx_map, ii].sum(axis=0) / vol) + ) / constants.nktv2p == pytest.approx(- expected_v[idx_map, ii].sum(axis=0) / vol) for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value From c88faf53c6ff8a71e3c091e0b49ae1f0d25fd284 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 02:56:08 +0000 Subject: [PATCH 10/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/test_lammps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index f291d2f13b..cd8906b911 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -348,7 +348,9 @@ def test_pair_deepmd_virial(lammps): for ii in range(9): assert np.array( lammps.variables[f"pressure{ii}"].value - ) / constants.nktv2p == pytest.approx(- expected_v[idx_map, ii].sum(axis=0) / vol) + ) / constants.nktv2p == pytest.approx( + -expected_v[idx_map, ii].sum(axis=0) / vol + ) for ii in range(9): assert np.array( lammps.variables[f"virial{ii}"].value From c3a23180697cf33e63e38a183236080f98d8a815 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 23:00:13 -0400 Subject: [PATCH 11/14] pressure is 6-dim, not 9-dim --- source/lmp/tests/test_lammps.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index f291d2f13b..716d27997d 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -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, @@ -345,10 +345,11 @@ def test_pair_deepmd_virial(lammps): expected_ae[idx_map] ) vol = box[1] * box[3] * box[5] - for ii in range(9): + for ii in range(6): + jj = [0, 4, 8, 3, 6, 7, 1, 2, 5][ii] assert np.array( - lammps.variables[f"pressure{ii}"].value - ) / constants.nktv2p == pytest.approx(- expected_v[idx_map, ii].sum(axis=0) / vol) + 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 From 2151cd91f576b076ee4befd4ea04c057e27be3ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 03:02:42 +0000 Subject: [PATCH 12/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/test_lammps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 716d27997d..66962a4078 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -77,7 +77,7 @@ ] ) -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 +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, @@ -349,7 +349,9 @@ def test_pair_deepmd_virial(lammps): 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) + ) / 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 From 32c569d6c3c66b8b0571a6d8414e289c1d04fe93 Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Tue, 23 Jul 2024 23:31:59 -0400 Subject: [PATCH 13/14] add test for pair_deepmd_model_devi_virial --- source/lmp/tests/test_lammps.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 716d27997d..a259d82d5e 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -387,7 +387,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}]") @@ -401,6 +407,15 @@ 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 From 43e24d2684cccdb21bb07b2dccf2d4ecdb7f39d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 03:32:41 +0000 Subject: [PATCH 14/14] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/lmp/tests/test_lammps.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/lmp/tests/test_lammps.py b/source/lmp/tests/test_lammps.py index 07fb81e57f..bc554b1c6a 100644 --- a/source/lmp/tests/test_lammps.py +++ b/source/lmp/tests/test_lammps.py @@ -417,7 +417,9 @@ def test_pair_deepmd_model_devi_virial(lammps): 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) + ) / 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