Skip to content

Commit a3d7ace

Browse files
feat: add cp2k support for skipping bad box (#1830)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Automatically detects and skips configurations with invalid box geometry during processing. * **Improvements** * Adds end-of-run summary reporting the number of skipped and remaining configurations. * Ensures post-processing output files remain linked and available after run. * **Bug Fixes** * Removes redundant file-handling operations to improve reliability and resource cleanup. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Ming-Yu Guo <gmy721212@163.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9e3b4f0 commit a3d7ace

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

dpgen/generator/run.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,26 +3771,46 @@ def make_fp_cp2k(iter_index, jdata):
37713771
else:
37723772
fp_params = jdata["fp_params"]
37733773
cwd = os.getcwd()
3774+
3775+
# skip bad box criteria
3776+
skip_bad_box = jdata.get("fp_skip_bad_box")
3777+
count_bad_box = 0
3778+
37743779
for ii in fp_tasks:
37753780
os.chdir(ii)
37763781
sys_data = dpdata.System("POSCAR").data
37773782
# make input for every task
37783783
# if fp_params exits, make keys
3784+
if skip_bad_box is not None:
3785+
# Check the box directly from POSCAR
3786+
skip = check_bad_box("POSCAR", skip_bad_box, fmt="vasp/poscar")
3787+
if skip:
3788+
count_bad_box += 1
3789+
os.chdir(cwd)
3790+
shutil.rmtree(ii) # Clean up inconsistent task directory
3791+
continue
3792+
37793793
if fp_params:
37803794
cp2k_input = make_cp2k_input(sys_data, fp_params)
37813795
else:
37823796
# else read from user input
37833797
cp2k_input = make_cp2k_input_from_external(sys_data, exinput_path)
37843798
with open("input.inp", "w") as fp:
37853799
fp.write(cp2k_input)
3786-
fp.close()
37873800
# make coord.xyz used by cp2k for every task
37883801
cp2k_coord = make_cp2k_xyz(sys_data)
37893802
with open("coord.xyz", "w") as fp:
37903803
fp.write(cp2k_coord)
3791-
fp.close()
37923804
os.chdir(cwd)
37933805

3806+
if count_bad_box > 0:
3807+
dlog.info(
3808+
f"skipped {count_bad_box:6d} confs with bad box, {len(fp_tasks) - count_bad_box:6d} remains"
3809+
)
3810+
3811+
# link pp files
3812+
_link_fp_vasp_pp(iter_index, jdata)
3813+
37943814

37953815
def make_fp_pwmat(iter_index, jdata):
37963816
# abs path for fp_incar if it exists

0 commit comments

Comments
 (0)