Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
349 changes: 110 additions & 239 deletions README.md

Large diffs are not rendered by default.

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
6 changes: 5 additions & 1 deletion dpti/hti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,11 @@ def compute_task(
print(print_format % (e1, de_err[0], de_err[1]))
elif free_energy_type == "gibbs":
if npt is not None:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
# Try jdata.json first, then equi_settings.json for compatibility
try:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
except FileNotFoundError:
npt_in = json.load(open(os.path.join(npt, "equi_settings.json")))
Comment on lines +1334 to +1338
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve resource management while maintaining the fallback logic.

The fallback mechanism from jdata.json to equi_settings.json is a good improvement for compatibility. However, the file opening should use context managers to ensure proper resource cleanup.

Apply this diff to improve resource management:

-            # Try jdata.json first, then equi_settings.json for compatibility
-            try:
-                npt_in = json.load(open(os.path.join(npt, "jdata.json")))
-            except FileNotFoundError:
-                npt_in = json.load(open(os.path.join(npt, "equi_settings.json")))
+            # Try jdata.json first, then equi_settings.json for compatibility
+            try:
+                with open(os.path.join(npt, "jdata.json")) as f:
+                    npt_in = json.load(f)
+            except FileNotFoundError:
+                with open(os.path.join(npt, "equi_settings.json")) as f:
+                    npt_in = json.load(f)
📝 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
# Try jdata.json first, then equi_settings.json for compatibility
try:
npt_in = json.load(open(os.path.join(npt, "jdata.json")))
except FileNotFoundError:
npt_in = json.load(open(os.path.join(npt, "equi_settings.json")))
# Try jdata.json first, then equi_settings.json for compatibility
try:
with open(os.path.join(npt, "jdata.json")) as f:
npt_in = json.load(f)
except FileNotFoundError:
with open(os.path.join(npt, "equi_settings.json")) as f:
npt_in = json.load(f)
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 1336-1336: Consider using 'with' for resource-allocating operations

(R1732)


[refactor] 1338-1338: Consider using 'with' for resource-allocating operations

(R1732)

🤖 Prompt for AI Agents
In dpti/hti.py around lines 1334 to 1338, the code opens JSON files without
using context managers, which can lead to resource leaks. Refactor the file
opening statements to use 'with' blocks for both 'jdata.json' and
'equi_settings.json' to ensure files are properly closed after reading, while
preserving the fallback logic from 'jdata.json' to 'equi_settings.json'.

npt_info = json.load(open(os.path.join(npt, "result.json")))
p = npt_in["pres"]
v = npt_info["v"]
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
18 changes: 9 additions & 9 deletions dpti/hti_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def _ff_angle_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["sigma_0_0"]
sigma_oh = sparam.get("sigma_oh", None) or sparam["sigma_0_1"]
sigma_hh = sparam.get("sigma_hh", None) or sparam["sigma_1_1"]
activation = sparam["activation"]
ret = ""
ret += f"variable EPSILON equal {epsilon:f}\n"
Expand All @@ -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 Expand Up @@ -94,9 +94,9 @@ def _ff_bond_angle_off(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["sigma_0_0"]
sigma_oh = sparam.get("sigma_oh", None) or sparam["sigma_0_1"]
sigma_hh = sparam.get("sigma_hh", None) or sparam["sigma_1_1"]
activation = sparam["activation"]
ret = ""
ret += "variable INV_LAMBDA equal 1-${LAMBDA}\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
3 changes: 3 additions & 0 deletions examples/download_models.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wget https://huggingface.co/Felix5572/Sn-SCAN-Compressed/resolve/main/graph.pb -O Sn_SCAN_compressed.pb
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 she-bang and fail-fast options for predictable execution

Without a she-bang the script’s interpreter is ambiguous (SC2148).
Insert a standard header and strict mode so any network/download failure aborts the script immediately.

+#!/usr/bin/env bash
+# Download compressed DeepPot models required by example workflows
+set -euo pipefail
+
 wget https://huggingface.co/Felix5572/Sn-SCAN-Compressed/resolve/main/graph.pb -O Sn_SCAN_compressed.pb
📝 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
wget https://huggingface.co/Felix5572/Sn-SCAN-Compressed/resolve/main/graph.pb -O Sn_SCAN_compressed.pb
#!/usr/bin/env bash
# Download compressed DeepPot models required by example workflows
set -euo pipefail
wget https://huggingface.co/Felix5572/Sn-SCAN-Compressed/resolve/main/graph.pb -O Sn_SCAN_compressed.pb
🧰 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/download_models.sh at line 1, add a she-bang line (e.g.,
#!/bin/bash) at the top to specify the script interpreter explicitly. Also,
enable fail-fast behavior by adding set -e to the script so it exits immediately
on any command failure, ensuring predictable execution and proper error handling
during the download process.


wget https://huggingface.co/Felix5572/Water-Ice-SCAN-Phase-Dirgram/resolve/main/graph.pb -O H2O-Phase-Diagram-model_compressed.pb
1 change: 1 addition & 0 deletions examples/water_SCAN/H2O-Phase-Diagram-model_compressed.pb
37 changes: 37 additions & 0 deletions examples/water_SCAN/ice04/command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# docker pull yfb222333/dpti-lammps-fep:latest
# docker run -it --gpus all dpti-lammps-fep:latest
# all in /opt/
# all files in /opt/dpti/examples/water_SCAN/ice04/

Comment on lines +1 to +5
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 shebang line for proper shell script execution.

The workflow documentation is excellent and provides clear guidance for users. However, the script should include a shebang line to specify the shell interpreter.

Add this line at the beginning of the file:

+#!/bin/bash
 # docker pull yfb222333/dpti-lammps-fep:latest
 #  docker run -it --gpus all dpti-lammps-fep:latest
 # all in /opt/
 # all files in /opt/dpti/examples/water_SCAN/ice04/
📝 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
# docker pull yfb222333/dpti-lammps-fep:latest
# docker run -it --gpus all dpti-lammps-fep:latest
# all in /opt/
# all files in /opt/dpti/examples/water_SCAN/ice04/
#!/bin/bash
# docker pull yfb222333/dpti-lammps-fep:latest
# docker run -it --gpus all dpti-lammps-fep:latest
# all in /opt/
# all files in /opt/dpti/examples/water_SCAN/ice04/
🧰 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/water_SCAN/ice04/command.sh at the beginning of the file, add a
shebang line such as #!/bin/bash to specify the shell interpreter for proper
script execution.

#NPT
dpti equi gen npt.json -o npt/

# submit jobs `lmp -i in.lammps` for npt/

dpti equi extract ./npt/ -o npt_avg.lmp # extract average

# NVT
dpti equi gen nvt.json -o nvt/

# submit jobs `lmp -i in.lammps` for nvt/

dpti equi extract ./nvt/ -o nvt_last_dump.lmp # extract average

## HTI (hti,hti_liq, hti_water, hti_ice) module
dpti hti_ice gen hti_ice.json -s three-step -o hti/

# submit jobs `lmp -i in.lammps` for subdirs like `hti/0*/task*/`

dpti hti_ice compute ./hti/ -t gibbs --npt ./npt/ # note use NPT simulation usually longer steps, and the P*V value is more accurate

# result txt in ./hti/result

## TI (ti, ti_water) module

dpti ti_water gen path-t.json -o ti_path_t/

# submit jobs `lmp -i in.lammps` for subdirs like `ti_path_t/task*/`

dpti ti_water compute ./ti_path_t/ --hti ./hti/ # HTI simulation (starting point, gibbs free energy value)

# final result for a ti-line txt in ./ti_path_t/result
1 change: 1 addition & 0 deletions examples/water_SCAN/ice04/conf.lmp
1 change: 1 addition & 0 deletions examples/water_SCAN/ice04/graph.pb
52 changes: 52 additions & 0 deletions examples/water_SCAN/ice04/hti_ice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"equi_conf": "nvt_last_dump.lmp",
"ncopies": [
1,
1,
1
],
"lambda_lj_on": [
"0.000:0.100:0.0125",
"0.100:0.200:0.025",
"0.200:1.000:0.2",
"1"
],
"lambda_deep_on": [
"0.0:0.1:0.025",
"0.1:1.0:0.1125",
"1"
],
"lambda_spring_off": [
"0.000:0.750:0.125",
"0.750:0.875:0.0625",
"0.875:1.000:0.03125",
"1"
],
"protect_eps": 1e-08,
"model": "graph.pb",
"model_mass_map": [
16,
2
],
"spring_k": 0.5,
"soft_param": {
"epsilon": 0.02,
"sigma_oo": 3.15,
"sigma_oh": 0.987,
"sigma_hh": 0.987,
"activation": 0.5,
"n": 1.0,
"alpha_lj": 0.5,
"rcut": 6.0,
"_comment": "that's all"
},
"crystal": "frenkel",
"langevin": true,
"nsteps": 200000,
"dt": 0.0005,
"stat_freq": 10,
"stat_skip": 10000,
"stat_bsize": 2000,
"temp": 150.000000,
"_comment": "that's all"
}
Loading
Loading