From 7e18559e3b52920b7d250052b325bea0e1d45dfb Mon Sep 17 00:00:00 2001 From: njzjz-bot Date: Mon, 24 Aug 2026 03:37:17 +0800 Subject: [PATCH] fix: generate MEAM and EAM-alloy commands Fixes #1896 Coding-Agent: Codex Codex-Version: codex-cli 0.149.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh --- dpgen/auto_test/Lammps.py | 2 +- dpgen/auto_test/lib/lammps.py | 2 +- tests/auto_test/test_lammps.py | 28 +++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/dpgen/auto_test/Lammps.py b/dpgen/auto_test/Lammps.py index adb793d35..b594122da 100644 --- a/dpgen/auto_test/Lammps.py +++ b/dpgen/auto_test/Lammps.py @@ -54,7 +54,7 @@ def set_model_param(self): } elif self.inter_type == "meam": model_name = list(map(os.path.basename, self.model)) - self.model_param = {"model_name": [model_name], "param_type": self.type_map} + self.model_param = {"model_name": model_name, "param_type": self.type_map} else: model_name = os.path.basename(self.model) self.model_param = {"model_name": [model_name], "param_type": self.type_map} diff --git a/dpgen/auto_test/lib/lammps.py b/dpgen/auto_test/lib/lammps.py index 26c95bcca..ab1607462 100644 --- a/dpgen/auto_test/lib/lammps.py +++ b/dpgen/auto_test/lib/lammps.py @@ -148,7 +148,7 @@ def inter_eam_fs(param): # 06/08 eam.fs interaction def inter_eam_alloy(param): # 06/08 eam.alloy interaction ret = "" line = "pair_style eam/alloy \n" - line += "pair_coeff * * {} ".format(param["model_name"]) + line += "pair_coeff * * {} ".format(param["model_name"][0]) for ii in param["param_type"]: line += ii + " " line += "\n" diff --git a/tests/auto_test/test_lammps.py b/tests/auto_test/test_lammps.py index 39a38dee5..0978d0cc6 100644 --- a/tests/auto_test/test_lammps.py +++ b/tests/auto_test/test_lammps.py @@ -11,7 +11,7 @@ from dpgen.auto_test.common_equi import make_equi, run_equi from dpgen.auto_test.Lammps import Lammps -from dpgen.auto_test.lib.lammps import inter_deepmd +from dpgen.auto_test.lib.lammps import inter_deepmd, inter_eam_alloy, inter_meam from .context import setUpModule # noqa: F401 @@ -72,6 +72,32 @@ def test_set_model_param(self): } self.assertEqual(model_param, self.Lammps.model_param) + def test_meam_model_parameters_generate_two_file_command(self): + interaction = { + "type": "meam", + "model": ["lammps_input/meam.lib", "lammps_input/Al.meam"], + "type_map": {"Al": 0}, + } + calculator = Lammps(interaction, self.source_path + "/Al-fcc.vasp") + calculator.set_model_param() + + self.assertEqual(calculator.model_param["model_name"], ["meam.lib", "Al.meam"]) + command = inter_meam(calculator.model_param) + self.assertIn("pair_coeff * * meam.lib Al Al.meam Al", command) + + def test_eam_alloy_command_uses_plain_filename(self): + interaction = { + "type": "eam_alloy", + "model": "lammps_input/Al.eam.alloy", + "type_map": {"Al": 0}, + } + calculator = Lammps(interaction, self.source_path + "/Al-fcc.vasp") + calculator.set_model_param() + + command = inter_eam_alloy(calculator.model_param) + self.assertIn("pair_coeff * * Al.eam.alloy Al", command) + self.assertNotIn("['Al.eam.alloy']", command) + def test_make_potential_files(self): cwd = os.getcwd() abs_equi_path = os.path.abspath(self.equi_path)