Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions dpti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
"ti",
"ti_water",
"lib",
"workflows",
]
2 changes: 1 addition & 1 deletion dpti/equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def gen_equi_dump_settings(if_dump_avg_posi):
return ret


def gen_equi_ensemble_settings(ens, if_dump_avg_posi):
def gen_equi_ensemble_settings(ens, if_dump_avg_posi=False):
# ens = equi_settings['ens']
ret = ""
if ens == "nvt":
Expand Down
2 changes: 1 addition & 1 deletion dpti/hti_liq.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def make_tasks(iter_name, jdata, if_meam=None):
if model:
copied_model = os.path.join(os.path.abspath(iter_name), "graph.pb")
shutil.copyfile(model, copied_model)
jdata["model"] = copied_model
jdata["model"] = copied_model

cwd = os.getcwd()
os.chdir(iter_name)
Expand Down
6 changes: 3 additions & 3 deletions dpti/hti_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def _ff_deep_on(lamb, model, bparam, sparam):
alpha_lj = sparam["alpha_lj"]
rcut = sparam["rcut"]
epsilon = sparam["epsilon"]
sigma_oo = sparam["sigma_oo"]
sigma_oh = sparam["sigma_oh"]
sigma_hh = sparam["sigma_hh"]
sigma_oo = sparam.get("sigma_oo", None) or sparam.get("sigma_0_0")
sigma_oh = sparam.get("sigma_oh", None) or sparam.get("sigma_0_1")
sigma_hh = sparam.get("sigma_hh", None) or sparam.get("sigma_1_1")
activation = sparam["activation"]
ret = ""
ret += f"variable EPSILON equal {epsilon:f}\n"
Expand Down
4 changes: 2 additions & 2 deletions dpti/ti.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ def _gen_lammps_input(
ret += "compute allmsd all msd\n"
if ens == "nvt":
ret += "thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]\n"
ret += "thermo_modify format 4*8 %20.6f\n"
ret += "thermo_modify format float %20.6f\n"
elif "npt" in ens:
ret += "thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]\n"
ret += "thermo_modify format 4*8 %20.6f\n"
ret += "thermo_modify format float %20.6f\n"
else:
raise RuntimeError(f"unknow ensemble {ens}\n")
ret += "dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z\n"
Expand Down
19 changes: 19 additions & 0 deletions examples/Sn_High_Pressure/command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# NPT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add a shebang and enable strict mode for portability and safety.

Without a shebang, the script may run under an unexpected shell. Enabling strict mode (-euo pipefail) ensures early failure on errors and prevents silent bugs.

Apply this diff:

+#!/usr/bin/env bash
+set -euo pipefail
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# NPT
#!/usr/bin/env bash
set -euo pipefail
# NPT
🧰 Tools
🪛 Shellcheck (0.10.0)

[error] 1-1: Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.

(SC2148)

🤖 Prompt for AI Agents
In examples/Sn_High_Pressure/command.sh at line 1, add a shebang line (e.g.,
#!/bin/bash) at the very top of the script to specify the shell interpreter.
Immediately after the shebang, enable strict mode by adding set -euo pipefail to
ensure the script exits on errors, treats unset variables as errors, and fails
on pipeline errors for better safety and portability.

dpti equi gen npt.json -e npt-xy -t 200 -p 20000 -o NPT_sim/
# cd NPT_sim/new_job/
dpti equi extract ./ -o npt_avg.lmp

# NVT
dpti equi gen equi_settings.json --ensemble nvt -t 200 -p 20000 --conf-npt ./NPT_sim/new_job/ -o NVT_sim/
# cd NVT_sim/new_job/
dpti equi extract ./ -o nvt_last_dump.lmp

# HTI
dpti hti gen hti.json -s three-step -o HTI_sim/
# dpti hti_water gen hti_water.json -o HTI_water/
# dpti hti_ice gen hti_ice.json -s three-step -o HTI_ice/
dpti hti compute ./new_job/ -t gibbs --npt ../NPT_sim/new_job/

# TI
dpti ti gen ti_settings.json -o TI_sim/
dpti ti compute ./TI_sim/new_job/ --hti ../HTI_sim/new_job/
1 change: 1 addition & 0 deletions examples/Sn_High_Pressure/conf.lmp
2 changes: 1 addition & 1 deletion examples/Sn_High_Pressure/hti.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"equi_conf": null,
"equi_conf": "nvt_last_dump.lmp",
"ncopies": [
1,
1,
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark_gdi/deepmd/0/in.lammps
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format 4*8 %20.6f
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark_ti/path-p/in.lammps
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify 4*8 format %20.6f
thermo_modify float format %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} aniso ${PRES} ${PRES} ${TAU_P} couple xy
fix mzero all momentum 10 linear 1 1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark_ti/path-p/task.000006/in.lammps
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format 4*8 %20.6f
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} aniso ${PRES} ${PRES} ${TAU_P} couple xy
fix mzero all momentum 10 linear 1 1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark_ti/path-t/task.000006/in.lammps
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ timestep 0.002
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify 4*8 format %20.6f
thermo_modify float format %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} aniso ${PRES} ${PRES} ${TAU_P} couple xy
fix mzero all momentum 10 linear 1 1 1
Expand Down
2 changes: 1 addition & 1 deletion tests/benchmark_ti_water/new_job/task.000003/in.lammps
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ timestep 0.0005
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format 4*8 %20.6f
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
import sys

from _pytest.config import Config # type: ignore

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, project_root)


def pytest_configure(config: Config) -> None:
"""Print paths information before any test collection starts."""
print("\n" + "=" * 50)
print(f"Running tests from: {os.path.abspath(__file__)}")
print(f"Project root: {project_root}")
print("=" * 50 + "\n")
1 change: 1 addition & 0 deletions tests/graph.pb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# origin file Sn SCAN functional label:continue-2/000 by yfb222333@gmail.com; github:felix5572
# model version 1.2: wget https://deepmd-kit.oss-cn-beijing.aliyuncs.com/graph.pb
# model version 2.0: wget https://deepmd-kit.oss-cn-beijing.aliyuncs.com/graph_Sn_convert_from_1.2_to_2.0.pb
# compressed model: wget https://huggingface.co/Felix5572/Sn-SCAN-Compressed/resolve/main/graph.pb
31 changes: 15 additions & 16 deletions tests/test_hti_ff_spring.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,21 @@ def test_spring_multiple_element(self):
ret2 = dpti.hti._ff_spring(**input)
self.assertEqual(ret1, ret2)


def test_spring_var_spring_multiple_element(self):
input = {"lamb": 0.20, "m_spring_k": [118.71, 207.2], "var_spring": False}
ret1 = textwrap.dedent(
"""\
group type_1 type 1
group type_2 type 2
fix l_spring_1 type_1 spring/self 9.4968000000e+01
fix_modify l_spring_1 energy yes
fix l_spring_2 type_2 spring/self 1.6576000000e+02
fix_modify l_spring_2 energy yes
variable l_spring equal f_l_spring_1+f_l_spring_2
"""
)
ret2 = dpti.hti._ff_spring(**input)
self.assertEqual(ret1, ret2)
def test_spring_var_spring_multiple_element(self):
input = {"lamb": 0.20, "m_spring_k": [118.71, 207.2], "var_spring": False}
ret1 = textwrap.dedent(
"""\
group type_1 type 1
group type_2 type 2
fix l_spring_1 type_1 spring/self 1.1871000000e+02
fix_modify l_spring_1 energy yes
fix l_spring_2 type_2 spring/self 2.0720000000e+02
fix_modify l_spring_2 energy yes
variable l_spring equal f_l_spring_1+f_l_spring_2
"""
)
ret2 = dpti.hti._ff_spring(**input)
self.assertEqual(ret1, ret2)
Comment on lines +53 to +67
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Duplicate scenario & misleading test name

test_spring_var_spring_multiple_element sets var_spring=False, so it exercises the same code path already covered by test_spring_multiple_element.
Either:

  1. Rename to reflect it is a non-varying spring with a different λ, or
  2. Change var_spring to True and update expected constants to k*(1-λ) so the varying-spring branch for multiple elements is actually tested.

Removing redundancy will keep the suite fast and intention-revealing.

🤖 Prompt for AI Agents
In tests/test_hti_ff_spring.py around lines 53 to 67, the test named
test_spring_var_spring_multiple_element sets var_spring to False, duplicating
the code path of test_spring_multiple_element. To fix this, either rename the
test to indicate it tests a non-varying spring with a different lambda value or
change var_spring to True and update the expected output constants to reflect
k*(1-lambda), ensuring the varying spring branch for multiple elements is
actually tested and removing redundancy.



if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ti_gen_lammps_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_deepmd(self, patch_random):
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format 4*8 %20.6f
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_meam(self, patch_random):
thermo ${THERMO_FREQ}
compute allmsd all msd
thermo_style custom step ke pe etotal enthalpy temp press vol c_allmsd[*]
thermo_modify format 4*8 %20.6f
thermo_modify format float %20.6f
dump 1 all custom ${DUMP_FREQ} traj.dump id type x y z
fix 1 all npt temp ${TEMP} ${TEMP} ${TAU_T} iso ${PRES} ${PRES} ${TAU_P}
fix mzero all momentum 10 linear 1 1 1
Expand Down
Loading