From 65aac64db089746fa374124795c4708c61968f94 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 6 Nov 2024 02:26:24 -0500 Subject: [PATCH] fix(lmp): add `pair_deepmd_index` key to `is_key` function in dplr (#4313) Fix #4273. Tests are added in this PR. * Modify `is_key` function to include `keys.push_back("pair_deepmd_index")` Update tests in `test_dplr.py` to include `pair_deepmd_index` command * Add `pair_deepmd_index 0` to various `lammps.fix` commands in the test cases ## Summary by CodeRabbit - **New Features** - Introduced a new key, `pair_deepmd_index`, enhancing the `FixDPLR` class for improved pair validation in simulations. - **Bug Fixes** - Updated error handling to ensure robustness when the new `pair_deepmd_index` is not provided. - **Tests** - Modified test parameters to include `pair_deepmd_index 0`, ensuring compatibility with the new functionality while maintaining existing validations. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- source/lmp/fix_dplr.cpp | 1 + source/lmp/tests/test_dplr.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 34fd2515ed..3e59c6b2db 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -30,6 +30,7 @@ static bool is_key(const string &input) { keys.push_back("type_associate"); keys.push_back("bond_type"); keys.push_back("efield"); + keys.push_back("pair_deepmd_index"); for (int ii = 0; ii < keys.size(); ++ii) { if (input == keys[ii]) { return true; diff --git a/source/lmp/tests/test_dplr.py b/source/lmp/tests/test_dplr.py index 2dd3531894..ed28bbd6d4 100644 --- a/source/lmp/tests/test_dplr.py +++ b/source/lmp/tests/test_dplr.py @@ -387,7 +387,9 @@ def test_pair_deepmd_lr(lammps): lammps.special_bonds("lj/coul 1 1 1 angle no") lammps.kspace_style("pppm/dplr 1e-5") lammps.kspace_modify(f"gewald {beta:.2f} diff ik mesh {mesh:d} {mesh:d} {mesh:d}") - lammps.fix(f"0 all dplr model {pb_file.resolve()} type_associate 1 3 bond_type 1") + lammps.fix( + f"0 all dplr model {pb_file.resolve()} type_associate 1 3 bond_type 1 pair_deepmd_index 0" + ) lammps.fix_modify("0 virial yes") lammps.run(0) for ii in range(8):