Skip to content

Commit e267a05

Browse files
committed
fix: avoid staging GROMACS output names
Coding-Agent: Codex Codex-Version: codex-cli 0.151.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh
1 parent 4e1264e commit e267a05

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

dpgen/generator/run.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,20 @@ def _make_model_devi_native(iter_index, jdata, mdata, conf_systems):
18061806
sys_counter += 1
18071807

18081808

1809+
def _gromacs_input_files(gromacs_settings):
1810+
"""Return only settings whose values name files staged for a GROMACS task."""
1811+
non_input_settings = {
1812+
"traj_filename",
1813+
"mdp_filename",
1814+
"group_name",
1815+
"maxwarn",
1816+
"deffnm",
1817+
}
1818+
return [
1819+
file for key, file in gromacs_settings.items() if key not in non_input_settings
1820+
]
1821+
1822+
18091823
def _make_model_devi_native_gromacs(iter_index, jdata, mdata, conf_systems):
18101824
try:
18111825
from gromacs.fileformats.mdp import MDP
@@ -1868,16 +1882,10 @@ def _make_model_devi_native_gromacs(iter_index, jdata, mdata, conf_systems):
18681882
task_path = os.path.join(work_path, task_name)
18691883
create_path(task_path)
18701884
gromacs_settings = jdata.get("gromacs_settings", "")
1871-
for key, file in gromacs_settings.items():
1872-
if (
1873-
key != "traj_filename"
1874-
and key != "mdp_filename"
1875-
and key != "group_name"
1876-
and key != "maxwarn"
1877-
):
1878-
os.symlink(
1879-
os.path.join(cc, file), os.path.join(task_path, file)
1880-
)
1885+
for file in _gromacs_input_files(gromacs_settings):
1886+
os.symlink(
1887+
os.path.join(cc, file), os.path.join(task_path, file)
1888+
)
18811889
# input.json for DP-Gromacs
18821890
with open(os.path.join(cc, "input.json")) as f:
18831891
input_json = json.load(f)

tests/generator/test_gromacs_engine.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import numpy as np
88

9+
from dpgen.generator.run import _gromacs_input_files
10+
911
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
1012
__package__ = "generator"
1113
dirname = os.path.join(os.path.abspath(os.path.dirname(__file__)), "gromacs")
@@ -43,6 +45,7 @@ def setUp(self):
4345
"ref_filename": "em.tpr",
4446
"model_devi_script": "model_devi.py",
4547
"traj_filename": "deepmd_traj.gro",
48+
"deffnm": "deepmd",
4649
},
4750
"model_devi_dt": 0.001,
4851
"model_devi_f_trust_lo": 0.05,
@@ -80,7 +83,10 @@ def setUp(self):
8083

8184
def _check_dir(self, wdir, post=True):
8285
for key in self.jdata["gromacs_settings"].keys():
83-
if key != "traj_filename":
86+
if key == "deffnm":
87+
# deffnm names generated outputs and must not be staged as input.
88+
self.assertFalse(os.path.exists(os.path.join(wdir, "deepmd")))
89+
elif key != "traj_filename":
8490
self.assertTrue(
8591
os.path.exists(
8692
os.path.join(wdir, self.jdata["gromacs_settings"][key])
@@ -105,6 +111,13 @@ def _copy_outputs(self, path_1, path_2):
105111
)
106112
shutil.copytree(os.path.join(path_1, "traj"), os.path.join(path_2, "traj"))
107113

114+
def test_deffnm_is_not_an_input_file(self):
115+
"""Command/output settings must not be symlinked from the source system."""
116+
input_files = _gromacs_input_files(self.jdata["gromacs_settings"])
117+
118+
self.assertNotIn("deepmd", input_files)
119+
self.assertIn("processed.top", input_files)
120+
108121
@unittest.skipIf(
109122
importlib.util.find_spec("openbabel") is not None,
110123
"when openbabel is found, this test will be skipped. ",

0 commit comments

Comments
 (0)