From d5b058f527cb62d0e1a68f930692c83b0d314593 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Mon, 27 May 2024 20:40:25 +0900 Subject: [PATCH 01/22] Simplify API version message --- dpgen/data/gen.py | 142 ++++++++++++++++++------------------- dpgen/generator/run.py | 108 ++++++++++++++-------------- dpgen/simplify/simplify.py | 35 +++++---- 3 files changed, 140 insertions(+), 145 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index aa13a8688..1c0485f6e 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -1158,27 +1158,26 @@ def run_vasp_relax(jdata, mdata): # relax_run_tasks.append(ii) run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["fp_machine"], - mdata["fp_resources"], - commands=[fp_command], - work_path=work_dir, - run_tasks=run_tasks, - group_size=fp_group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog="fp.log", - errlog="fp.log", - ) - submission.run_submission() + submission = make_submission( + mdata["fp_machine"], + mdata["fp_resources"], + commands=[fp_command], + work_path=work_dir, + run_tasks=run_tasks, + group_size=fp_group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog="fp.log", + errlog="fp.log", + ) + submission.run_submission() def coll_abacus_md(jdata): @@ -1298,27 +1297,26 @@ def run_abacus_relax(jdata, mdata): # relax_run_tasks.append(ii) run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["fp_machine"], - mdata["fp_resources"], - commands=[fp_command], - work_path=work_dir, - run_tasks=run_tasks, - group_size=fp_group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog="fp.log", - errlog="fp.log", - ) - submission.run_submission() + submission = make_submission( + mdata["fp_machine"], + mdata["fp_resources"], + commands=[fp_command], + work_path=work_dir, + run_tasks=run_tasks, + group_size=fp_group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog="fp.log", + errlog="fp.log", + ) + submission.run_submission() def run_vasp_md(jdata, mdata): @@ -1359,27 +1357,27 @@ def run_vasp_md(jdata, mdata): run_tasks = [ii.replace(work_dir + "/", "") for ii in md_run_tasks] # dlog.info("md_work_dir", work_dir) # dlog.info("run_tasks",run_tasks) - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["fp_machine"], - mdata["fp_resources"], - commands=[fp_command], - work_path=work_dir, - run_tasks=run_tasks, - group_size=fp_group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog="fp.log", - errlog="fp.log", - ) - submission.run_submission() + submission = make_submission( + mdata["fp_machine"], + mdata["fp_resources"], + commands=[fp_command], + work_path=work_dir, + run_tasks=run_tasks, + group_size=fp_group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog="fp.log", + errlog="fp.log", + ) + submission.run_submission() def run_abacus_md(jdata, mdata): @@ -1435,27 +1433,27 @@ def run_abacus_md(jdata, mdata): run_tasks = [ii.replace(work_dir + "/", "") for ii in md_run_tasks] # dlog.info("md_work_dir", work_dir) # dlog.info("run_tasks",run_tasks) - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["fp_machine"], - mdata["fp_resources"], - commands=[fp_command], - work_path=work_dir, - run_tasks=run_tasks, - group_size=fp_group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog="fp.log", - errlog="fp.log", - ) - submission.run_submission() + submission = make_submission( + mdata["fp_machine"], + mdata["fp_resources"], + commands=[fp_command], + work_path=work_dir, + run_tasks=run_tasks, + group_size=fp_group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog="fp.log", + errlog="fp.log", + ) + submission.run_submission() def gen_init_bulk(args): diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index dbc387c05..36ebd2a43 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -874,31 +874,30 @@ def run_train(iter_index, jdata, mdata): except Exception: train_group_size = 1 - api_version = mdata.get("api_version", "1.0") - user_forward_files = mdata.get("train" + "_user_forward_files", []) forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("train" + "_user_backward_files", []) - if Version(api_version) < Version("1.0"): + + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["train_machine"], - mdata["train_resources"], - commands=commands, - work_path=work_path, - run_tasks=run_tasks, - group_size=train_group_size, - forward_common_files=trans_comm_data, - forward_files=forward_files, - backward_files=backward_files, - outlog="train.log", - errlog="train.log", - ) - submission.run_submission() + submission = make_submission( + mdata["train_machine"], + mdata["train_resources"], + commands=commands, + work_path=work_path, + run_tasks=run_tasks, + group_size=train_group_size, + forward_common_files=trans_comm_data, + forward_files=forward_files, + backward_files=backward_files, + outlog="train.log", + errlog="train.log", + ) + submission.run_submission() def post_train(iter_index, jdata, mdata): @@ -2090,31 +2089,31 @@ def run_md_model_devi(iter_index, jdata, mdata): user_forward_files = mdata.get("model_devi" + "_user_forward_files", []) forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("model_devi" + "_user_backward_files", []) - api_version = mdata.get("api_version", "1.0") if len(run_tasks) == 0: raise RuntimeError( "run_tasks for model_devi should not be empty! Please check your files." ) - if Version(api_version) < Version("1.0"): + + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["model_devi_machine"], - mdata["model_devi_resources"], - commands=commands, - work_path=work_path, - run_tasks=run_tasks, - group_size=model_devi_group_size, - forward_common_files=model_names, - forward_files=forward_files, - backward_files=backward_files, - outlog="model_devi.log", - errlog="model_devi.log", - ) - submission.run_submission() + submission = make_submission( + mdata["model_devi_machine"], + mdata["model_devi_resources"], + commands=commands, + work_path=work_path, + run_tasks=run_tasks, + group_size=model_devi_group_size, + forward_common_files=model_names, + forward_files=forward_files, + backward_files=backward_files, + outlog="model_devi.log", + errlog="model_devi.log", + ) + submission.run_submission() def run_model_devi(iter_index, jdata, mdata): @@ -3964,27 +3963,26 @@ def run_fp_inner( forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("fp" + "_user_backward_files", []) - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["fp_machine"], - mdata["fp_resources"], - commands=[fp_command], - work_path=work_path, - run_tasks=run_tasks, - group_size=fp_group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog=log_file, - errlog=log_file, - ) - submission.run_submission() + submission = make_submission( + mdata["fp_machine"], + mdata["fp_resources"], + commands=[fp_command], + work_path=work_path, + run_tasks=run_tasks, + group_size=fp_group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog=log_file, + errlog=log_file, + ) + submission.run_submission() def run_fp(iter_index, jdata, mdata): diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 0ff09d87e..2e2cb49e3 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -255,27 +255,26 @@ def run_model_devi(iter_index, jdata, mdata): commands.append(command_true_error) backward_files.append(true_error_file_name) - api_version = mdata.get("api_version", "1.0") - if Version(api_version) < Version("1.0"): + ### Submit the jobs + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - mdata["model_devi_machine"], - mdata["model_devi_resources"], - commands=commands, - work_path=work_path, - run_tasks=run_tasks, - group_size=model_devi_group_size, - forward_common_files=model_names, - forward_files=forward_files, - backward_files=backward_files, - outlog="model_devi.log", - errlog="model_devi.log", - ) - submission.run_submission() + submission = make_submission( + mdata["model_devi_machine"], + mdata["model_devi_resources"], + commands=commands, + work_path=work_path, + run_tasks=run_tasks, + group_size=model_devi_group_size, + forward_common_files=model_names, + forward_files=forward_files, + backward_files=backward_files, + outlog="model_devi.log", + errlog="model_devi.log", + ) + submission.run_submission() def post_model_devi(iter_index, jdata, mdata): From 8c4210bffbc52e1719e37975a5c747e6a4c02bea Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Mon, 27 May 2024 21:11:31 +0900 Subject: [PATCH 02/22] u --- dpgen/data/gen.py | 23 +++++------------------ dpgen/generator/lib/utils.py | 9 +++++++++ dpgen/generator/run.py | 16 ++++------------ dpgen/simplify/simplify.py | 7 ++----- dpgen/util.py | 2 +- 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 1c0485f6e..ca178fa10 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -10,7 +10,6 @@ import dpdata import numpy as np -from packaging.version import Version from pymatgen.core import Structure from pymatgen.io.vasp import Incar @@ -28,7 +27,7 @@ make_abacus_scf_stru, make_supercell_abacus, ) -from dpgen.generator.lib.utils import symlink_user_forward_files +from dpgen.generator.lib.utils import symlink_user_forward_files, check_api_version from dpgen.generator.lib.vasp import incar_upper from dpgen.remote.decide_machine import convert_mdata from dpgen.util import load_file @@ -1159,10 +1158,7 @@ def run_vasp_relax(jdata, mdata): run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["fp_machine"], @@ -1298,10 +1294,7 @@ def run_abacus_relax(jdata, mdata): run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["fp_machine"], @@ -1359,10 +1352,7 @@ def run_vasp_md(jdata, mdata): # dlog.info("run_tasks",run_tasks) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["fp_machine"], @@ -1435,10 +1425,7 @@ def run_abacus_md(jdata, mdata): # dlog.info("run_tasks",run_tasks) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["fp_machine"], diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index 4eaf4ad87..328a1493d 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -5,6 +5,7 @@ import os import re import shutil +from packaging.version import Version iter_format = "%06d" task_format = "%02d" @@ -110,3 +111,11 @@ def symlink_user_forward_files(mdata, task_type, work_path, task_format=None): abs_file = os.path.abspath(file) os.symlink(abs_file, os.path.join(task, os.path.basename(file))) return + + +def check_api_version(mdata): + if Version(mdata.get("api_version", "1.0")) < Version("1.0"): + raise RuntimeError( + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." + ) + return diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 36ebd2a43..2ac780614 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -84,6 +84,7 @@ make_iter_name, record_iter, symlink_user_forward_files, + check_api_version, ) from dpgen.generator.lib.vasp import ( incar_upper, @@ -879,10 +880,7 @@ def run_train(iter_index, jdata, mdata): backward_files += mdata.get("train" + "_user_backward_files", []) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["train_machine"], @@ -2095,10 +2093,7 @@ def run_md_model_devi(iter_index, jdata, mdata): ) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["model_devi_machine"], @@ -3964,10 +3959,7 @@ def run_fp_inner( backward_files += mdata.get("fp" + "_user_backward_files", []) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["fp_machine"], diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 2e2cb49e3..5ab366bfa 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -18,7 +18,6 @@ import dpdata import numpy as np -from packaging.version import Version from dpgen import dlog from dpgen.dispatcher.Dispatcher import make_submission @@ -29,6 +28,7 @@ log_iter, make_iter_name, record_iter, + check_api_version, ) from dpgen.generator.run import ( _get_model_suffix, @@ -256,10 +256,7 @@ def run_model_devi(iter_index, jdata, mdata): backward_files.append(true_error_file_name) ### Submit the jobs - if Version(mdata.get("api_version", "1.0")) < Version("1.0"): - raise RuntimeError( - "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." - ) + check_api_version(mdata) submission = make_submission( mdata["model_devi_machine"], diff --git a/dpgen/util.py b/dpgen/util.py index 73453d74b..811d3044d 100644 --- a/dpgen/util.py +++ b/dpgen/util.py @@ -34,7 +34,7 @@ def sepline(ch="-", sp="-", screen=False): def box_center(ch="", fill=" ", sp="|"): r"""Put the string at the center of | |.""" strs = ch.center(MaxLength, fill) - dlog.info(sp + strs[1 : len(strs) - 1 :] + sp) + dlog.info(sp + strs[1: len(strs) - 1:] + sp) def expand_sys_str(root_dir: Union[str, Path]) -> list[str]: From cb6e88e888df10c424a1751887c020cb6b8672ab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 May 2024 12:11:43 +0000 Subject: [PATCH 03/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/gen.py | 2 +- dpgen/generator/lib/utils.py | 1 + dpgen/generator/run.py | 2 +- dpgen/simplify/simplify.py | 2 +- dpgen/util.py | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index ca178fa10..65c1d6448 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -27,7 +27,7 @@ make_abacus_scf_stru, make_supercell_abacus, ) -from dpgen.generator.lib.utils import symlink_user_forward_files, check_api_version +from dpgen.generator.lib.utils import check_api_version, symlink_user_forward_files from dpgen.generator.lib.vasp import incar_upper from dpgen.remote.decide_machine import convert_mdata from dpgen.util import load_file diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index 328a1493d..da214a1df 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -5,6 +5,7 @@ import os import re import shutil + from packaging.version import Version iter_format = "%06d" diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 2ac780614..e60ed29c5 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -78,13 +78,13 @@ ) from dpgen.generator.lib.siesta import make_siesta_input from dpgen.generator.lib.utils import ( + check_api_version, create_path, log_iter, log_task, make_iter_name, record_iter, symlink_user_forward_files, - check_api_version, ) from dpgen.generator.lib.vasp import ( incar_upper, diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 5ab366bfa..1b5bcad12 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -24,11 +24,11 @@ # TODO: maybe the following functions can be moved to dpgen.util from dpgen.generator.lib.utils import ( + check_api_version, create_path, log_iter, make_iter_name, record_iter, - check_api_version, ) from dpgen.generator.run import ( _get_model_suffix, diff --git a/dpgen/util.py b/dpgen/util.py index 811d3044d..73453d74b 100644 --- a/dpgen/util.py +++ b/dpgen/util.py @@ -34,7 +34,7 @@ def sepline(ch="-", sp="-", screen=False): def box_center(ch="", fill=" ", sp="|"): r"""Put the string at the center of | |.""" strs = ch.center(MaxLength, fill) - dlog.info(sp + strs[1: len(strs) - 1:] + sp) + dlog.info(sp + strs[1 : len(strs) - 1 :] + sp) def expand_sys_str(root_dir: Union[str, Path]) -> list[str]: From e1d7c0cc5762566929aad6d363dd56b5da97ca63 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Tue, 28 May 2024 14:55:46 +0900 Subject: [PATCH 04/22] u --- dpgen/data/gen.py | 8 ++++---- dpgen/generator/lib/utils.py | 1 + dpgen/generator/run.py | 6 +++--- dpgen/simplify/simplify.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 65c1d6448..4d24f9fd7 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -1157,7 +1157,7 @@ def run_vasp_relax(jdata, mdata): # relax_run_tasks.append(ii) run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( @@ -1293,7 +1293,7 @@ def run_abacus_relax(jdata, mdata): # relax_run_tasks.append(ii) run_tasks = [os.path.basename(ii) for ii in relax_run_tasks] - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( @@ -1351,7 +1351,7 @@ def run_vasp_md(jdata, mdata): # dlog.info("md_work_dir", work_dir) # dlog.info("run_tasks",run_tasks) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( @@ -1424,7 +1424,7 @@ def run_abacus_md(jdata, mdata): # dlog.info("md_work_dir", work_dir) # dlog.info("run_tasks",run_tasks) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index da214a1df..390dfe276 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -115,6 +115,7 @@ def symlink_user_forward_files(mdata, task_type, work_path, task_format=None): def check_api_version(mdata): + """Check if the API version in metadata is at least 1.0.""" if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index e60ed29c5..1e3e0e3fa 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -879,7 +879,7 @@ def run_train(iter_index, jdata, mdata): forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("train" + "_user_backward_files", []) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( @@ -2092,7 +2092,7 @@ def run_md_model_devi(iter_index, jdata, mdata): "run_tasks for model_devi should not be empty! Please check your files." ) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( @@ -3958,7 +3958,7 @@ def run_fp_inner( forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("fp" + "_user_backward_files", []) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 1b5bcad12..02fe54d79 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -255,7 +255,7 @@ def run_model_devi(iter_index, jdata, mdata): commands.append(command_true_error) backward_files.append(true_error_file_name) - ### Submit the jobs + ### Submit jobs check_api_version(mdata) submission = make_submission( From ee5b52a3ed997eb8c53be1c3f99364cd2ae1189d Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Tue, 28 May 2024 15:08:11 +0900 Subject: [PATCH 05/22] Update Dispatcher.py --- dpgen/dispatcher/Dispatcher.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/dpgen/dispatcher/Dispatcher.py b/dpgen/dispatcher/Dispatcher.py index 08ee6474c..ccfc64b35 100644 --- a/dpgen/dispatcher/Dispatcher.py +++ b/dpgen/dispatcher/Dispatcher.py @@ -138,21 +138,20 @@ def make_submission_compat( """ if Version(api_version) < Version("1.0"): raise RuntimeError( - f"API version {api_version} has been removed. Please upgrade to 1.0." + "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." ) - elif Version(api_version) >= Version("1.0"): - submission = make_submission( - machine, - resources, - commands=commands, - work_path=work_path, - run_tasks=run_tasks, - group_size=group_size, - forward_common_files=forward_common_files, - forward_files=forward_files, - backward_files=backward_files, - outlog=outlog, - errlog=errlog, - ) - submission.run_submission() + submission = make_submission( + machine, + resources, + commands=commands, + work_path=work_path, + run_tasks=run_tasks, + group_size=group_size, + forward_common_files=forward_common_files, + forward_files=forward_files, + backward_files=backward_files, + outlog=outlog, + errlog=errlog, + ) + submission.run_submission() From ba027fd6ec55ac9a6d20249ca32887abfec90351 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Tue, 28 May 2024 15:31:07 +0900 Subject: [PATCH 06/22] Update utils.py --- dpgen/generator/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index 390dfe276..6b9b3683f 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -115,7 +115,7 @@ def symlink_user_forward_files(mdata, task_type, work_path, task_format=None): def check_api_version(mdata): - """Check if the API version in metadata is at least 1.0.""" + """Check if the API version in mdata is at least 1.0.""" if Version(mdata.get("api_version", "1.0")) < Version("1.0"): raise RuntimeError( "API version below 1.0 is no longer supported. Please upgrade to version 1.0 or newer." From 155898a87fab6f4fc77f8d60d10c470891b1cc90 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 09:37:56 +0900 Subject: [PATCH 07/22] u --- dpgen/data/gen.py | 63 ++++++----------------- dpgen/data/tools/create_random_disturb.py | 5 +- 2 files changed, 19 insertions(+), 49 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 4d24f9fd7..0e55422bf 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -726,8 +726,8 @@ def make_scale_ABACUS(jdata): def pert_scaled(jdata): - if "init_fp_style" not in jdata: - jdata["init_fp_style"] = "VASP" + ### Extract data from jdata + jdata["init_fp_style"] = jdata.get("init_fp_style", "VASP") out_dir = jdata["out_dir"] scale = jdata["scale"] pert_box = jdata["pert_box"] @@ -744,6 +744,7 @@ def pert_scaled(jdata): if "from_poscar" in jdata: from_poscar = jdata["from_poscar"] + ### Get the current working directory and the system path cwd = os.getcwd() path_sp = os.path.join(out_dir, global_dirname_03) assert os.path.isdir(path_sp) @@ -752,35 +753,31 @@ def pert_scaled(jdata): sys_pe.sort() os.chdir(cwd) - pert_cmd = os.path.dirname(__file__) - pert_cmd = os.path.join(pert_cmd, "tools") - pert_cmd = os.path.join(pert_cmd, "create_random_disturb.py") + ### Construct the perturbation command + python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") fp_style = "vasp" poscar_name = "POSCAR" if jdata["init_fp_style"] == "ABACUS": fp_style = "abacus" poscar_name = "STRU" - pert_cmd = ( - sys.executable - + " " - + pert_cmd - + " -etmax %f -ofmt %s %s %d %f > /dev/null" - % (pert_box, fp_style, poscar_name, pert_numb, pert_atom) - ) + + pert_cmd = sys.executable + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" + + ### Loop over each system and scale for ii in sys_pe: for jj in scale: - path_work = path_sp - path_work = os.path.join(path_work, ii) - path_work = os.path.join(path_work, f"scale-{jj:.3f}") + path_work = os.path.join(path_sp, ii, f"scale-{jj:.3f}") assert os.path.isdir(path_work) os.chdir(path_work) sp.check_call(pert_cmd, shell=True) + + ### Loop over each perturbation for kk in range(pert_numb): if fp_style == "vasp": - pos_in = "POSCAR%d.vasp" % (kk + 1) + pos_in = f"POSCAR{kk}.vasp" elif fp_style == "abacus": - pos_in = "STRU%d.abacus" % (kk + 1) - dir_out = "%06d" % (kk + 1) + pos_in = f"STRU{kk}.abacus" + dir_out = f"{kk:06d}" create_path(dir_out) if fp_style == "vasp": pos_out = os.path.join(dir_out, "POSCAR") @@ -805,35 +802,7 @@ def pert_scaled(jdata): else: shutil.copy2(pos_in, pos_out) os.remove(pos_in) - kk = -1 - if fp_style == "vasp": - pos_in = "POSCAR" - elif fp_style == "abacus": - pos_in = "STRU" - dir_out = "%06d" % (kk + 1) - create_path(dir_out) - if fp_style == "vasp": - pos_out = os.path.join(dir_out, "POSCAR") - elif fp_style == "abacus": - pos_out = os.path.join(dir_out, "STRU") - if not from_poscar: - if fp_style == "vasp": - poscar_shuffle(pos_in, pos_out) - elif fp_style == "abacus": - stru_in = get_abacus_STRU(pos_in) - stru_out = shuffle_stru_data(stru_in) - with open(pos_out, "w") as fp: - fp.write( - make_abacus_scf_stru( - stru_out, - pp_file, - orb_file_names, - dpks_descriptor_name, - type_map=jdata["elements"], - ) - ) - else: - shutil.copy2(pos_in, pos_out) + os.chdir(cwd) diff --git a/dpgen/data/tools/create_random_disturb.py b/dpgen/data/tools/create_random_disturb.py index b3cefb07f..70102a21f 100755 --- a/dpgen/data/tools/create_random_disturb.py +++ b/dpgen/data/tools/create_random_disturb.py @@ -123,7 +123,8 @@ def create_disturbs_ase_dev( cell0 = atoms.get_cell() # creat nfile ofmt files. - for fid in range(1, nfile + 1): + # for fid in range(1, nfile + 1): # C.Thang Nguyen: Why not start from 0? + for fid in range(nfile): # Use copy(), otherwise it will modify the input atoms every time. atoms_d = atoms.copy() @@ -194,7 +195,7 @@ def create_disturbs_abacus_dev( cell0 = stru["cells"] # creat nfile ofmt files. - for fid in range(1, nfile + 1): + for fid in range(nfile): # Use copy(), otherwise it will modify the input atoms every time. stru_d = stru.copy() From bbe0fc53455a792d80837fc5ce608d0a5c684223 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 00:53:06 +0000 Subject: [PATCH 08/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/gen.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 0e55422bf..b89a17189 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -754,14 +754,19 @@ def pert_scaled(jdata): os.chdir(cwd) ### Construct the perturbation command - python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") + python_exec = os.path.join( + os.path.dirname(__file__), "tools", "create_random_disturb.py" + ) fp_style = "vasp" poscar_name = "POSCAR" if jdata["init_fp_style"] == "ABACUS": fp_style = "abacus" poscar_name = "STRU" - pert_cmd = sys.executable + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" + pert_cmd = ( + sys.executable + + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" + ) ### Loop over each system and scale for ii in sys_pe: From 4e9bcd3bf5ab35bee3136c239dd99528e37547df Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 10:00:56 +0900 Subject: [PATCH 09/22] Update gen.py --- dpgen/data/gen.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 0e55422bf..e9c4197d2 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -727,7 +727,7 @@ def make_scale_ABACUS(jdata): def pert_scaled(jdata): ### Extract data from jdata - jdata["init_fp_style"] = jdata.get("init_fp_style", "VASP") + init_fp_style = jdata.get("init_fp_style", "VASP") out_dir = jdata["out_dir"] scale = jdata["scale"] pert_box = jdata["pert_box"] @@ -754,13 +754,14 @@ def pert_scaled(jdata): os.chdir(cwd) ### Construct the perturbation command - python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") - fp_style = "vasp" - poscar_name = "POSCAR" - if jdata["init_fp_style"] == "ABACUS": + if init_fp_style == "VASP": + fp_style = "vasp" + poscar_name = "POSCAR" + elif init_fp_style == "ABACUS": fp_style = "abacus" poscar_name = "STRU" + python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") pert_cmd = sys.executable + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" ### Loop over each system and scale From c0f302bae7f130ff725502bbc21f8514d5c631f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 01:02:48 +0000 Subject: [PATCH 10/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/gen.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index e9c4197d2..c00932a4b 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -761,8 +761,13 @@ def pert_scaled(jdata): fp_style = "abacus" poscar_name = "STRU" - python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") - pert_cmd = sys.executable + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" + python_exec = os.path.join( + os.path.dirname(__file__), "tools", "create_random_disturb.py" + ) + pert_cmd = ( + sys.executable + + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" + ) ### Loop over each system and scale for ii in sys_pe: From 2444446527ec69a3504e03fd06fa6175566bb47e Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 10:10:55 +0900 Subject: [PATCH 11/22] Update gen.py --- dpgen/data/gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index c00932a4b..34bc54861 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -727,7 +727,6 @@ def make_scale_ABACUS(jdata): def pert_scaled(jdata): ### Extract data from jdata - init_fp_style = jdata.get("init_fp_style", "VASP") out_dir = jdata["out_dir"] scale = jdata["scale"] pert_box = jdata["pert_box"] @@ -754,6 +753,7 @@ def pert_scaled(jdata): os.chdir(cwd) ### Construct the perturbation command + init_fp_style = jdata.get("init_fp_style", "VASP") if init_fp_style == "VASP": fp_style = "vasp" poscar_name = "POSCAR" From 72088724366f80beb9d4717b02bc885eaf9521e1 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 10:23:43 +0900 Subject: [PATCH 12/22] Update gen.py --- dpgen/data/gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 34bc54861..45bef0cf8 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -841,7 +841,7 @@ def make_vasp_md(jdata, mdata): for ii in sys_ps: for jj in scale: - for kk in range(pert_numb + 1): + for kk in range(pert_numb): path_work = path_md path_work = os.path.join(path_work, ii) path_work = os.path.join(path_work, f"scale-{jj:.3f}") @@ -962,7 +962,7 @@ def make_abacus_md(jdata, mdata): for ii in sys_ps: for jj in scale: - for kk in range(pert_numb + 1): + for kk in range(pert_numb): path_work = path_md path_work = os.path.join(path_work, ii) path_work = os.path.join(path_work, f"scale-{jj:.3f}") From ee921da45e8267ed4f070e96c7973022b4bb3daa Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 10:40:26 +0900 Subject: [PATCH 13/22] u --- dpgen/data/surf.py | 30 ++++++++++++------------------ tests/data/test_gen_bulk.py | 2 +- tests/data/test_gen_bulk_abacus.py | 2 +- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index a3a60d039..3ef7a03c9 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -501,26 +501,25 @@ def pert_scaled(jdata): sys_pe.sort() os.chdir(cwd) + python_exec = os.path.join( + os.path.dirname(__file__), "tools", "create_random_disturb.py" + ) pert_cmd = ( sys.executable - + " " - + os.path.join(ROOT_PATH, "data/tools/create_random_disturb.py") - ) - pert_cmd += " -etmax %f -ofmt vasp POSCAR %d %f > /dev/null" % ( - pert_box, - pert_numb, - pert_atom, + + f" {python_exec} -etmax {pert_box} -ofmt vasp POSCAR {pert_numb} {pert_atom} > /dev/null" ) + + ### Loop over each system and scale for ii in sys_pe: for jj in scale: - path_scale = path_sp - path_scale = os.path.join(path_scale, ii) - path_scale = os.path.join(path_scale, f"scale-{jj:.3f}") + path_scale = os.path.join(path_sp, ii, f"scale-{jj:.3f}") assert os.path.isdir(path_scale) os.chdir(path_scale) dlog.info(os.getcwd()) poscar_in = os.path.join(path_scale, "POSCAR") assert os.path.isfile(poscar_in) + + ### Loop over each perturbation for ll in elongs: path_elong = path_scale path_elong = os.path.join(path_elong, f"elong-{ll:3.3f}") @@ -529,18 +528,13 @@ def pert_scaled(jdata): poscar_elong(poscar_in, "POSCAR", ll) sp.check_call(pert_cmd, shell=True) for kk in range(pert_numb): - pos_in = "POSCAR%d.vasp" % (kk + 1) - dir_out = "%06d" % (kk + 1) + pos_in = f"POSCAR{kk}.vasp" + dir_out = f"{kk:06d}" create_path(dir_out) pos_out = os.path.join(dir_out, "POSCAR") poscar_shuffle(pos_in, pos_out) os.remove(pos_in) - kk = -1 - pos_in = "POSCAR" - dir_out = "%06d" % (kk + 1) - create_path(dir_out) - pos_out = os.path.join(dir_out, "POSCAR") - poscar_shuffle(pos_in, pos_out) + os.chdir(cwd) diff --git a/tests/data/test_gen_bulk.py b/tests/data/test_gen_bulk.py index 64df71bc8..3c4cddf33 100644 --- a/tests/data/test_gen_bulk.py +++ b/tests/data/test_gen_bulk.py @@ -69,7 +69,7 @@ def test(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb + 1) + self.assertEqual(len(perts), self.pert_numb) if __name__ == "__main__": diff --git a/tests/data/test_gen_bulk_abacus.py b/tests/data/test_gen_bulk_abacus.py index 520589829..3e9bc3ba1 100644 --- a/tests/data/test_gen_bulk_abacus.py +++ b/tests/data/test_gen_bulk_abacus.py @@ -103,7 +103,7 @@ def testSTRU(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb + 1) + self.assertEqual(len(perts), self.pert_numb) if __name__ == "__main__": From 69b32fbe72130b0ef71aebc23fdba44203e446e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 30 May 2024 01:40:36 +0000 Subject: [PATCH 14/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/surf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 3ef7a03c9..e036e659e 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -23,7 +23,7 @@ import dpgen.data.tools.fcc as fcc import dpgen.data.tools.hcp as hcp import dpgen.data.tools.sc as sc -from dpgen import ROOT_PATH, dlog +from dpgen import dlog from dpgen.dispatcher.Dispatcher import make_submission_compat from dpgen.generator.lib.utils import symlink_user_forward_files from dpgen.remote.decide_machine import convert_mdata From 6fe378f1c0681a086b54f293fed3b008ca0174da Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 30 May 2024 10:53:22 +0900 Subject: [PATCH 15/22] u --- tests/data/test_disturb_abacus.py | 2 +- tests/data/test_gen_bulk_abacus.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data/test_disturb_abacus.py b/tests/data/test_disturb_abacus.py index 365d3e723..d806208ea 100644 --- a/tests/data/test_disturb_abacus.py +++ b/tests/data/test_disturb_abacus.py @@ -17,7 +17,7 @@ class TestPertAbacus(unittest.TestCase): def setUp(self): - create_disturbs_abacus_dev(abacus_stru_file, 1) + create_disturbs_abacus_dev(abacus_stru_file, 2) def tearDown(self): if os.path.isfile("STRU.hcp1.abacus"): diff --git a/tests/data/test_gen_bulk_abacus.py b/tests/data/test_gen_bulk_abacus.py index 3e9bc3ba1..c2c87902b 100644 --- a/tests/data/test_gen_bulk_abacus.py +++ b/tests/data/test_gen_bulk_abacus.py @@ -71,7 +71,7 @@ def test(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb + 1) + self.assertEqual(len(perts), self.pert_numb) def testSTRU(self): jdata = self.jdata From f634e0143fed9c6b78f28133ed622032859e41b0 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Fri, 31 May 2024 08:19:14 +0900 Subject: [PATCH 16/22] Update surf.py --- dpgen/data/surf.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index e036e659e..60feeeec5 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -354,15 +354,16 @@ def make_vasp_relax(jdata): out_dir = jdata["out_dir"] potcars = jdata["potcars"] cwd = os.getcwd() - work_dir = os.path.join(out_dir, global_dirname_02) assert os.path.isdir(work_dir) work_dir = os.path.abspath(work_dir) + if os.path.isfile(os.path.join(work_dir, "INCAR")): os.remove(os.path.join(work_dir, "INCAR")) if os.path.isfile(os.path.join(work_dir, "POTCAR")): os.remove(os.path.join(work_dir, "POTCAR")) shutil.copy2(jdata["relax_incar"], os.path.join(work_dir, "INCAR")) + out_potcar = os.path.join(work_dir, "POTCAR") with open(out_potcar, "w") as outfile: for fname in potcars: @@ -440,15 +441,12 @@ def make_scale(jdata): for jj in scale: if skip_relax: pos_src = os.path.join(os.path.join(init_path, ii), "POSCAR") - assert os.path.isfile(pos_src) else: - try: - pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") - assert os.path.isfile(pos_src) - except Exception: - raise RuntimeError( - "not file %s, vasp relaxation should be run before scale poscar" - ) + pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") + if not os.path.isfile(pos_src): + raise RuntimeError( + f"file {pos_src} not found, vasp relaxation should be run before scale poscar" + ) scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, f"scale-{jj:.3f}") create_path(scale_path) @@ -501,6 +499,7 @@ def pert_scaled(jdata): sys_pe.sort() os.chdir(cwd) + ### Construct the perturbation command python_exec = os.path.join( os.path.dirname(__file__), "tools", "create_random_disturb.py" ) @@ -521,8 +520,7 @@ def pert_scaled(jdata): ### Loop over each perturbation for ll in elongs: - path_elong = path_scale - path_elong = os.path.join(path_elong, f"elong-{ll:3.3f}") + path_elong = os.path.join(path_scale, f"elong-{ll:3.3f}") create_path(path_elong) os.chdir(path_elong) poscar_elong(poscar_in, "POSCAR", ll) From 95313c7a298b002763e46085c2ed892c37e5e2f3 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:36:11 +0900 Subject: [PATCH 17/22] u --- dpgen/data/gen.py | 37 +++++++++++++++++++++-- dpgen/data/surf.py | 12 ++++++-- dpgen/data/tools/create_random_disturb.py | 5 ++- tests/data/test_disturb_abacus.py | 2 +- tests/data/test_gen_bulk.py | 2 +- tests/data/test_gen_bulk_abacus.py | 4 +-- 6 files changed, 50 insertions(+), 12 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 45bef0cf8..493ff0ca7 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -780,10 +780,10 @@ def pert_scaled(jdata): ### Loop over each perturbation for kk in range(pert_numb): if fp_style == "vasp": - pos_in = f"POSCAR{kk}.vasp" + pos_in = f"POSCAR{kk+1}.vasp" elif fp_style == "abacus": - pos_in = f"STRU{kk}.abacus" - dir_out = f"{kk:06d}" + pos_in = f"STRU{kk+1}.abacus" + dir_out = f"{kk+1:06d}" create_path(dir_out) if fp_style == "vasp": pos_out = os.path.join(dir_out, "POSCAR") @@ -809,6 +809,37 @@ def pert_scaled(jdata): shutil.copy2(pos_in, pos_out) os.remove(pos_in) + ### Handle special case (unperturbed ?) + kk = -1 + if fp_style == "vasp": + pos_in = "POSCAR" + elif fp_style == "abacus": + pos_in = "STRU" + dir_out = f"{kk+1:06d}" + create_path(dir_out) + if fp_style == "vasp": + pos_out = os.path.join(dir_out, "POSCAR") + elif fp_style == "abacus": + pos_out = os.path.join(dir_out, "STRU") + if not from_poscar: + if fp_style == "vasp": + poscar_shuffle(pos_in, pos_out) + elif fp_style == "abacus": + stru_in = get_abacus_STRU(pos_in) + stru_out = shuffle_stru_data(stru_in) + with open(pos_out, "w") as fp: + fp.write( + make_abacus_scf_stru( + stru_out, + pp_file, + orb_file_names, + dpks_descriptor_name, + type_map=jdata["elements"], + ) + ) + else: + shutil.copy2(pos_in, pos_out) + os.chdir(cwd) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 60feeeec5..c952c411d 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -526,13 +526,21 @@ def pert_scaled(jdata): poscar_elong(poscar_in, "POSCAR", ll) sp.check_call(pert_cmd, shell=True) for kk in range(pert_numb): - pos_in = f"POSCAR{kk}.vasp" - dir_out = f"{kk:06d}" + pos_in = f"POSCAR{kk+1}.vasp" + dir_out = f"{kk+1:06d}" create_path(dir_out) pos_out = os.path.join(dir_out, "POSCAR") poscar_shuffle(pos_in, pos_out) os.remove(pos_in) + ### Handle special case (unperturbed ?) + kk = -1 + pos_in = "POSCAR" + dir_out = f"{kk+1:06d}" + create_path(dir_out) + pos_out = os.path.join(dir_out, "POSCAR") + poscar_shuffle(pos_in, pos_out) + os.chdir(cwd) diff --git a/dpgen/data/tools/create_random_disturb.py b/dpgen/data/tools/create_random_disturb.py index 70102a21f..b3cefb07f 100755 --- a/dpgen/data/tools/create_random_disturb.py +++ b/dpgen/data/tools/create_random_disturb.py @@ -123,8 +123,7 @@ def create_disturbs_ase_dev( cell0 = atoms.get_cell() # creat nfile ofmt files. - # for fid in range(1, nfile + 1): # C.Thang Nguyen: Why not start from 0? - for fid in range(nfile): + for fid in range(1, nfile + 1): # Use copy(), otherwise it will modify the input atoms every time. atoms_d = atoms.copy() @@ -195,7 +194,7 @@ def create_disturbs_abacus_dev( cell0 = stru["cells"] # creat nfile ofmt files. - for fid in range(nfile): + for fid in range(1, nfile + 1): # Use copy(), otherwise it will modify the input atoms every time. stru_d = stru.copy() diff --git a/tests/data/test_disturb_abacus.py b/tests/data/test_disturb_abacus.py index d806208ea..365d3e723 100644 --- a/tests/data/test_disturb_abacus.py +++ b/tests/data/test_disturb_abacus.py @@ -17,7 +17,7 @@ class TestPertAbacus(unittest.TestCase): def setUp(self): - create_disturbs_abacus_dev(abacus_stru_file, 2) + create_disturbs_abacus_dev(abacus_stru_file, 1) def tearDown(self): if os.path.isfile("STRU.hcp1.abacus"): diff --git a/tests/data/test_gen_bulk.py b/tests/data/test_gen_bulk.py index 3c4cddf33..64df71bc8 100644 --- a/tests/data/test_gen_bulk.py +++ b/tests/data/test_gen_bulk.py @@ -69,7 +69,7 @@ def test(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb) + self.assertEqual(len(perts), self.pert_numb + 1) if __name__ == "__main__": diff --git a/tests/data/test_gen_bulk_abacus.py b/tests/data/test_gen_bulk_abacus.py index c2c87902b..520589829 100644 --- a/tests/data/test_gen_bulk_abacus.py +++ b/tests/data/test_gen_bulk_abacus.py @@ -71,7 +71,7 @@ def test(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb) + self.assertEqual(len(perts), self.pert_numb + 1) def testSTRU(self): jdata = self.jdata @@ -103,7 +103,7 @@ def testSTRU(self): self.assertEqual(len(scales), self.scale_numb) for scale in scales: perts = glob.glob(os.path.join(scale, "[0-9]*")) - self.assertEqual(len(perts), self.pert_numb) + self.assertEqual(len(perts), self.pert_numb + 1) if __name__ == "__main__": From d226d87e60af1529257ba9c1938f7b75c25d5830 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:40:47 +0900 Subject: [PATCH 18/22] Update gen.py --- dpgen/data/gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 493ff0ca7..ba53af78e 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -872,7 +872,7 @@ def make_vasp_md(jdata, mdata): for ii in sys_ps: for jj in scale: - for kk in range(pert_numb): + for kk in range(pert_numb + 1): path_work = path_md path_work = os.path.join(path_work, ii) path_work = os.path.join(path_work, f"scale-{jj:.3f}") @@ -993,7 +993,7 @@ def make_abacus_md(jdata, mdata): for ii in sys_ps: for jj in scale: - for kk in range(pert_numb): + for kk in range(pert_numb + 1): path_work = path_md path_work = os.path.join(path_work, ii) path_work = os.path.join(path_work, f"scale-{jj:.3f}") From f0083a19e26f25f3694a4473e71424c8ab3bc957 Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:43:07 +0900 Subject: [PATCH 19/22] Update surf.py --- dpgen/data/surf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index c952c411d..8001b6863 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -23,7 +23,7 @@ import dpgen.data.tools.fcc as fcc import dpgen.data.tools.hcp as hcp import dpgen.data.tools.sc as sc -from dpgen import dlog +from dpgen import ROOT_PATH, dlog from dpgen.dispatcher.Dispatcher import make_submission_compat from dpgen.generator.lib.utils import symlink_user_forward_files from dpgen.remote.decide_machine import convert_mdata From d6d1d127bc75b919e2fd1795549fa0ceac9d48f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 20 Jun 2024 04:43:22 +0000 Subject: [PATCH 20/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/surf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 8001b6863..c952c411d 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -23,7 +23,7 @@ import dpgen.data.tools.fcc as fcc import dpgen.data.tools.hcp as hcp import dpgen.data.tools.sc as sc -from dpgen import ROOT_PATH, dlog +from dpgen import dlog from dpgen.dispatcher.Dispatcher import make_submission_compat from dpgen.generator.lib.utils import symlink_user_forward_files from dpgen.remote.decide_machine import convert_mdata From 0a0dcb3046952423911b48503c864ba3590f7d4b Mon Sep 17 00:00:00 2001 From: Thang Nguyen <46436648+thangckt@users.noreply.github.com> Date: Sat, 24 Aug 2024 04:03:24 +0900 Subject: [PATCH 21/22] u --- dpgen/data/gen.py | 73 ++++++++++++---------------------------------- dpgen/data/surf.py | 37 ++++++----------------- 2 files changed, 27 insertions(+), 83 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 996c4d8b9..10ff69c8c 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -167,9 +167,7 @@ def stru_ele(supercell_stru, stru_out, eles, natoms, jdata, path_work): os.path.join(path_work, orb_file_names[ipp]), ) if "dpks_descriptor" in jdata: - os.symlink( - absolute_dpks_descriptor_path, os.path.join(path_work, dpks_descriptor_name) - ) + os.symlink(absolute_dpks_descriptor_path, os.path.join(path_work, dpks_descriptor_name)) def poscar_natoms(lines): @@ -255,9 +253,7 @@ def poscar_scale_abacus(poscar_in, poscar_out, scale, jdata): orb_file_names = [os.path.basename(a) for a in jdata["orb_files"]] if "dpks_descriptor" in jdata: dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"]) - ret = make_abacus_scf_stru( - stru, pp_files, orb_file_names, dpks_descriptor_name, type_map=jdata["elements"] - ) + ret = make_abacus_scf_stru(stru, pp_files, orb_file_names, dpks_descriptor_name, type_map=jdata["elements"]) # ret = make_abacus_scf_stru(stru, pp_files) with open(poscar_out, "w") as fp: fp.write(ret) @@ -572,9 +568,7 @@ def make_vasp_relax(jdata, mdata): def make_abacus_relax(jdata, mdata): relax_incar = jdata["relax_incar"] - standard_incar = get_abacus_input_parameters( - relax_incar - ) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters(relax_incar) # a dictionary in which all of the values are strings if "kspacing" not in standard_incar: if "gamma_only" in standard_incar: if isinstance(standard_incar["gamma_only"], str): @@ -584,9 +578,7 @@ def make_abacus_relax(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: relax_kpt_path = jdata["relax_kpt"] - assert os.path.isfile( - relax_kpt_path - ), f"file {relax_kpt_path} should exists" + assert os.path.isfile(relax_kpt_path), f"file {relax_kpt_path} should exists" else: gamma_param = {"k_points": [1, 1, 1, 0, 0, 0]} ret_kpt = make_abacus_scf_kpt(gamma_param) @@ -595,9 +587,7 @@ def make_abacus_relax(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: relax_kpt_path = jdata["relax_kpt"] - assert os.path.isfile( - relax_kpt_path - ), f"file {relax_kpt_path} should exists" + assert os.path.isfile(relax_kpt_path), f"file {relax_kpt_path} should exists" out_dir = jdata["out_dir"] cwd = os.getcwd() @@ -675,9 +665,7 @@ def make_scale(jdata): else: pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") if not os.path.isfile(pos_src): - raise RuntimeError( - f"file {pos_src} not found, vasp relaxation should be run before scale poscar" - ) + raise RuntimeError(f"file {pos_src} not found, vasp relaxation should be run before scale poscar") scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, f"scale-{jj:.3f}") create_path(scale_path) @@ -763,13 +751,8 @@ def pert_scaled(jdata): fp_style = "abacus" poscar_name = "STRU" - python_exec = os.path.join( - os.path.dirname(__file__), "tools", "create_random_disturb.py" - ) - pert_cmd = ( - sys.executable - + f" {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" - ) + python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") + pert_cmd = f"{sys.executable} {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" ### Loop over each system and scale for ii in sys_pe: @@ -917,9 +900,7 @@ def make_vasp_md(jdata, mdata): def make_abacus_md(jdata, mdata): md_incar = jdata["md_incar"] - standard_incar = get_abacus_input_parameters( - md_incar - ) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters(md_incar) # a dictionary in which all of the values are strings # assert("md_kpt" in jdata or "kspacing" in standard_incar or "gamma_only" in standard_incar) \ # "Cannot find any k-points information." if "kspacing" not in standard_incar: @@ -931,9 +912,7 @@ def make_abacus_md(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: md_kpt_path = jdata["md_kpt"] - assert os.path.isfile( - md_kpt_path - ), f"file {md_kpt_path} should exists" + assert os.path.isfile(md_kpt_path), f"file {md_kpt_path} should exists" else: ret_kpt = make_abacus_scf_kpt({"k_points": [1, 1, 1, 0, 0, 0]}) else: @@ -981,9 +960,7 @@ def make_abacus_md(jdata, mdata): if "dpks_descriptor" in jdata: dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"]) dpks_descriptor_abspath = os.path.abspath(jdata["dpks_descriptor"]) - shutil.copy2( - dpks_descriptor_abspath, os.path.join(path_md, dpks_descriptor_name) - ) + shutil.copy2(dpks_descriptor_abspath, os.path.join(path_md, dpks_descriptor_name)) if "dpks_model" in jdata: dpks_model_name = os.path.basename(jdata["dpks_model"]) dpks_model_abspath = os.path.abspath(jdata["dpks_model"]) @@ -1019,9 +996,7 @@ def make_abacus_md(jdata, mdata): pass try: for pp_file in [os.path.basename(a) for a in jdata["potcars"]]: - os.symlink( - os.path.relpath(os.path.join(path_md, pp_file)), pp_file - ) + os.symlink(os.path.relpath(os.path.join(path_md, pp_file)), pp_file) if "orb_files" in jdata: for orb_file in orb_file_names: os.symlink( @@ -1035,9 +1010,7 @@ def make_abacus_md(jdata, mdata): ) if "dpks_descriptor" in jdata: os.symlink( - os.path.relpath( - os.path.join(path_md, dpks_descriptor_name) - ), + os.path.relpath(os.path.join(path_md, dpks_descriptor_name)), dpks_descriptor_name, ) except FileExistsError: @@ -1222,9 +1195,7 @@ def coll_abacus_md(jdata): ) ) else: - dlog.info( - f"WARNING : in directory {os.getcwd()} NO running_md.log file found." - ) + dlog.info(f"WARNING : in directory {os.getcwd()} NO running_md.log file found.") arg_cvt = " " if len(valid_outcars) == 0: raise RuntimeError( @@ -1276,9 +1247,7 @@ def run_abacus_relax(jdata, mdata): if "dpks_model" in jdata: dpks_model_name = [os.path.basename(jdata["dpks_model"])] relax_incar = jdata["relax_incar"] - standard_incar = get_abacus_input_parameters( - relax_incar - ) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters(relax_incar) # a dictionary in which all of the values are strings forward_files = ["STRU", "INPUT"] if "kspacing" not in standard_incar: forward_files = ["STRU", "INPUT", "KPT"] @@ -1398,9 +1367,7 @@ def run_abacus_md(jdata, mdata): if "dpks_model" in jdata: dpks_model_name = [os.path.basename(jdata["dpks_model"])] md_incar = jdata["md_incar"] - standard_incar = get_abacus_input_parameters( - md_incar - ) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters(md_incar) # a dictionary in which all of the values are strings forward_files = ["STRU", "INPUT"] if "kspacing" not in standard_incar: forward_files = ["STRU", "INPUT", "KPT"] @@ -1492,9 +1459,7 @@ def gen_init_bulk(args): nsw_steps = int(standard_incar["md_nstep"]) if nsw_flag: if nsw_steps != md_nstep_jdata: - dlog.info( - "WARNING: your set-up for MD steps in PARAM and md_incar are not consistent!" - ) + dlog.info("WARNING: your set-up for MD steps in PARAM and md_incar are not consistent!") dlog.info("MD steps in PARAM is %d" % (md_nstep_jdata)) dlog.info("MD steps in md_incar is %d" % (nsw_steps)) dlog.info("DP-GEN will use settings in md_incar!") @@ -1575,9 +1540,7 @@ def gen_init_bulk(args): if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Generating initial data for bulk systems." - ) + parser = argparse.ArgumentParser(description="Generating initial data for bulk systems.") parser.add_argument("PARAM", type=str, help="parameter file, json/yaml format") parser.add_argument( "MACHINE", diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 3bfac11d6..fde45cc20 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -182,9 +182,7 @@ def poscar_elong(poscar_in, poscar_out, elong, shift_center=True): z_mean = cart_coords[:, 2].mean() z_shift = st.lattice.c / 2 - z_mean cart_coords[:, 2] = cart_coords[:, 2] + z_shift - nst = Structure( - st.lattice, st.species, coords=cart_coords, coords_are_cartesian=True - ) + nst = Structure(st.lattice, st.species, coords=cart_coords, coords_are_cartesian=True) nst.to(poscar_out, "poscar") else: with open(poscar_out, "w") as fout: @@ -265,15 +263,11 @@ def make_super_cell_pymatgen(jdata): os.chdir(path_cur_surf) # slabgen = SlabGenerator(ss, miller, z_min, 1e-3) if user_layer_numb: - slab = general_surface.surface( - ss, indices=miller, vacuum=vacuum_min, layers=user_layer_numb - ) + slab = general_surface.surface(ss, indices=miller, vacuum=vacuum_min, layers=user_layer_numb) else: # build slab according to z_min value for layer_numb in range(1, max_layer_numb + 1): - slab = general_surface.surface( - ss, indices=miller, vacuum=vacuum_min, layers=layer_numb - ) + slab = general_surface.surface(ss, indices=miller, vacuum=vacuum_min, layers=layer_numb) if slab.cell.lengths()[-1] >= z_min: break if layer_numb == max_layer_numb: @@ -446,9 +440,7 @@ def make_scale(jdata): else: pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") if not os.path.isfile(pos_src): - raise RuntimeError( - f"file {pos_src} not found, vasp relaxation should be run before scale poscar" - ) + raise RuntimeError(f"file {pos_src} not found, vasp relaxation should be run before scale poscar") scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, f"scale-{jj:.3f}") create_path(scale_path) @@ -470,9 +462,7 @@ def pert_scaled(jdata): elongs = np.arange(vacuum_resol[0], vacuum_max, vacuum_resol[0]) elif len(vacuum_resol) == 2: mid_point = jdata.get("mid_point") - head_elongs = np.arange( - vacuum_resol[0], mid_point, vacuum_resol[0] - ).tolist() + head_elongs = np.arange(vacuum_resol[0], mid_point, vacuum_resol[0]).tolist() tail_elongs = np.arange(mid_point, vacuum_max, vacuum_resol[1]).tolist() elongs = np.unique(head_elongs + tail_elongs).tolist() else: @@ -502,13 +492,8 @@ def pert_scaled(jdata): os.chdir(cwd) ### Construct the perturbation command - python_exec = os.path.join( - os.path.dirname(__file__), "tools", "create_random_disturb.py" - ) - pert_cmd = ( - sys.executable - + f" {python_exec} -etmax {pert_box} -ofmt vasp POSCAR {pert_numb} {pert_atom} > /dev/null" - ) + python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") + pert_cmd = f"{sys.executable} {python_exec} -etmax {pert_box} -ofmt vasp POSCAR {pert_numb} {pert_atom} > /dev/null" ### Loop over each system and scale for ii in sys_pe: @@ -571,9 +556,7 @@ def run_vasp_relax(jdata, mdata): work_path_list = glob.glob(os.path.join(work_dir, "surf-*")) task_format = {"fp": "sys-*"} for work_path in work_path_list: - symlink_user_forward_files( - mdata=mdata, task_type="fp", work_path=work_path, task_format=task_format - ) + symlink_user_forward_files(mdata=mdata, task_type="fp", work_path=work_path, task_format=task_format) user_forward_files = mdata.get("fp" + "_user_forward_files", []) forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("fp" + "_user_backward_files", []) @@ -639,9 +622,7 @@ def gen_init_surf(args): if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Generating initial data for surface systems." - ) + parser = argparse.ArgumentParser(description="Generating initial data for surface systems.") parser.add_argument("PARAM", type=str, help="parameter file, json/yaml format") parser.add_argument( "MACHINE", From cc0efbd539ff0c3f4537645c38eb2bdcb6092d54 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Aug 2024 19:03:37 +0000 Subject: [PATCH 22/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/gen.py | 68 ++++++++++++++++++++++++++++++++++------------ dpgen/data/surf.py | 32 ++++++++++++++++------ 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 10ff69c8c..68667645f 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -167,7 +167,9 @@ def stru_ele(supercell_stru, stru_out, eles, natoms, jdata, path_work): os.path.join(path_work, orb_file_names[ipp]), ) if "dpks_descriptor" in jdata: - os.symlink(absolute_dpks_descriptor_path, os.path.join(path_work, dpks_descriptor_name)) + os.symlink( + absolute_dpks_descriptor_path, os.path.join(path_work, dpks_descriptor_name) + ) def poscar_natoms(lines): @@ -253,7 +255,9 @@ def poscar_scale_abacus(poscar_in, poscar_out, scale, jdata): orb_file_names = [os.path.basename(a) for a in jdata["orb_files"]] if "dpks_descriptor" in jdata: dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"]) - ret = make_abacus_scf_stru(stru, pp_files, orb_file_names, dpks_descriptor_name, type_map=jdata["elements"]) + ret = make_abacus_scf_stru( + stru, pp_files, orb_file_names, dpks_descriptor_name, type_map=jdata["elements"] + ) # ret = make_abacus_scf_stru(stru, pp_files) with open(poscar_out, "w") as fp: fp.write(ret) @@ -568,7 +572,9 @@ def make_vasp_relax(jdata, mdata): def make_abacus_relax(jdata, mdata): relax_incar = jdata["relax_incar"] - standard_incar = get_abacus_input_parameters(relax_incar) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters( + relax_incar + ) # a dictionary in which all of the values are strings if "kspacing" not in standard_incar: if "gamma_only" in standard_incar: if isinstance(standard_incar["gamma_only"], str): @@ -578,7 +584,9 @@ def make_abacus_relax(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: relax_kpt_path = jdata["relax_kpt"] - assert os.path.isfile(relax_kpt_path), f"file {relax_kpt_path} should exists" + assert os.path.isfile( + relax_kpt_path + ), f"file {relax_kpt_path} should exists" else: gamma_param = {"k_points": [1, 1, 1, 0, 0, 0]} ret_kpt = make_abacus_scf_kpt(gamma_param) @@ -587,7 +595,9 @@ def make_abacus_relax(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: relax_kpt_path = jdata["relax_kpt"] - assert os.path.isfile(relax_kpt_path), f"file {relax_kpt_path} should exists" + assert os.path.isfile( + relax_kpt_path + ), f"file {relax_kpt_path} should exists" out_dir = jdata["out_dir"] cwd = os.getcwd() @@ -665,7 +675,9 @@ def make_scale(jdata): else: pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") if not os.path.isfile(pos_src): - raise RuntimeError(f"file {pos_src} not found, vasp relaxation should be run before scale poscar") + raise RuntimeError( + f"file {pos_src} not found, vasp relaxation should be run before scale poscar" + ) scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, f"scale-{jj:.3f}") create_path(scale_path) @@ -751,7 +763,9 @@ def pert_scaled(jdata): fp_style = "abacus" poscar_name = "STRU" - python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") + python_exec = os.path.join( + os.path.dirname(__file__), "tools", "create_random_disturb.py" + ) pert_cmd = f"{sys.executable} {python_exec} -etmax {pert_box} -ofmt {fp_style} {poscar_name} {pert_numb} {pert_atom} > /dev/null" ### Loop over each system and scale @@ -900,7 +914,9 @@ def make_vasp_md(jdata, mdata): def make_abacus_md(jdata, mdata): md_incar = jdata["md_incar"] - standard_incar = get_abacus_input_parameters(md_incar) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters( + md_incar + ) # a dictionary in which all of the values are strings # assert("md_kpt" in jdata or "kspacing" in standard_incar or "gamma_only" in standard_incar) \ # "Cannot find any k-points information." if "kspacing" not in standard_incar: @@ -912,7 +928,9 @@ def make_abacus_md(jdata, mdata): raise RuntimeError("Cannot find any k-points information.") else: md_kpt_path = jdata["md_kpt"] - assert os.path.isfile(md_kpt_path), f"file {md_kpt_path} should exists" + assert os.path.isfile( + md_kpt_path + ), f"file {md_kpt_path} should exists" else: ret_kpt = make_abacus_scf_kpt({"k_points": [1, 1, 1, 0, 0, 0]}) else: @@ -960,7 +978,9 @@ def make_abacus_md(jdata, mdata): if "dpks_descriptor" in jdata: dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"]) dpks_descriptor_abspath = os.path.abspath(jdata["dpks_descriptor"]) - shutil.copy2(dpks_descriptor_abspath, os.path.join(path_md, dpks_descriptor_name)) + shutil.copy2( + dpks_descriptor_abspath, os.path.join(path_md, dpks_descriptor_name) + ) if "dpks_model" in jdata: dpks_model_name = os.path.basename(jdata["dpks_model"]) dpks_model_abspath = os.path.abspath(jdata["dpks_model"]) @@ -996,7 +1016,9 @@ def make_abacus_md(jdata, mdata): pass try: for pp_file in [os.path.basename(a) for a in jdata["potcars"]]: - os.symlink(os.path.relpath(os.path.join(path_md, pp_file)), pp_file) + os.symlink( + os.path.relpath(os.path.join(path_md, pp_file)), pp_file + ) if "orb_files" in jdata: for orb_file in orb_file_names: os.symlink( @@ -1010,7 +1032,9 @@ def make_abacus_md(jdata, mdata): ) if "dpks_descriptor" in jdata: os.symlink( - os.path.relpath(os.path.join(path_md, dpks_descriptor_name)), + os.path.relpath( + os.path.join(path_md, dpks_descriptor_name) + ), dpks_descriptor_name, ) except FileExistsError: @@ -1195,7 +1219,9 @@ def coll_abacus_md(jdata): ) ) else: - dlog.info(f"WARNING : in directory {os.getcwd()} NO running_md.log file found.") + dlog.info( + f"WARNING : in directory {os.getcwd()} NO running_md.log file found." + ) arg_cvt = " " if len(valid_outcars) == 0: raise RuntimeError( @@ -1247,7 +1273,9 @@ def run_abacus_relax(jdata, mdata): if "dpks_model" in jdata: dpks_model_name = [os.path.basename(jdata["dpks_model"])] relax_incar = jdata["relax_incar"] - standard_incar = get_abacus_input_parameters(relax_incar) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters( + relax_incar + ) # a dictionary in which all of the values are strings forward_files = ["STRU", "INPUT"] if "kspacing" not in standard_incar: forward_files = ["STRU", "INPUT", "KPT"] @@ -1367,7 +1395,9 @@ def run_abacus_md(jdata, mdata): if "dpks_model" in jdata: dpks_model_name = [os.path.basename(jdata["dpks_model"])] md_incar = jdata["md_incar"] - standard_incar = get_abacus_input_parameters(md_incar) # a dictionary in which all of the values are strings + standard_incar = get_abacus_input_parameters( + md_incar + ) # a dictionary in which all of the values are strings forward_files = ["STRU", "INPUT"] if "kspacing" not in standard_incar: forward_files = ["STRU", "INPUT", "KPT"] @@ -1459,7 +1489,9 @@ def gen_init_bulk(args): nsw_steps = int(standard_incar["md_nstep"]) if nsw_flag: if nsw_steps != md_nstep_jdata: - dlog.info("WARNING: your set-up for MD steps in PARAM and md_incar are not consistent!") + dlog.info( + "WARNING: your set-up for MD steps in PARAM and md_incar are not consistent!" + ) dlog.info("MD steps in PARAM is %d" % (md_nstep_jdata)) dlog.info("MD steps in md_incar is %d" % (nsw_steps)) dlog.info("DP-GEN will use settings in md_incar!") @@ -1540,7 +1572,9 @@ def gen_init_bulk(args): if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Generating initial data for bulk systems.") + parser = argparse.ArgumentParser( + description="Generating initial data for bulk systems." + ) parser.add_argument("PARAM", type=str, help="parameter file, json/yaml format") parser.add_argument( "MACHINE", diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index fde45cc20..34fc5a2d1 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -182,7 +182,9 @@ def poscar_elong(poscar_in, poscar_out, elong, shift_center=True): z_mean = cart_coords[:, 2].mean() z_shift = st.lattice.c / 2 - z_mean cart_coords[:, 2] = cart_coords[:, 2] + z_shift - nst = Structure(st.lattice, st.species, coords=cart_coords, coords_are_cartesian=True) + nst = Structure( + st.lattice, st.species, coords=cart_coords, coords_are_cartesian=True + ) nst.to(poscar_out, "poscar") else: with open(poscar_out, "w") as fout: @@ -263,11 +265,15 @@ def make_super_cell_pymatgen(jdata): os.chdir(path_cur_surf) # slabgen = SlabGenerator(ss, miller, z_min, 1e-3) if user_layer_numb: - slab = general_surface.surface(ss, indices=miller, vacuum=vacuum_min, layers=user_layer_numb) + slab = general_surface.surface( + ss, indices=miller, vacuum=vacuum_min, layers=user_layer_numb + ) else: # build slab according to z_min value for layer_numb in range(1, max_layer_numb + 1): - slab = general_surface.surface(ss, indices=miller, vacuum=vacuum_min, layers=layer_numb) + slab = general_surface.surface( + ss, indices=miller, vacuum=vacuum_min, layers=layer_numb + ) if slab.cell.lengths()[-1] >= z_min: break if layer_numb == max_layer_numb: @@ -440,7 +446,9 @@ def make_scale(jdata): else: pos_src = os.path.join(os.path.join(init_path, ii), "CONTCAR") if not os.path.isfile(pos_src): - raise RuntimeError(f"file {pos_src} not found, vasp relaxation should be run before scale poscar") + raise RuntimeError( + f"file {pos_src} not found, vasp relaxation should be run before scale poscar" + ) scale_path = os.path.join(work_path, ii) scale_path = os.path.join(scale_path, f"scale-{jj:.3f}") create_path(scale_path) @@ -462,7 +470,9 @@ def pert_scaled(jdata): elongs = np.arange(vacuum_resol[0], vacuum_max, vacuum_resol[0]) elif len(vacuum_resol) == 2: mid_point = jdata.get("mid_point") - head_elongs = np.arange(vacuum_resol[0], mid_point, vacuum_resol[0]).tolist() + head_elongs = np.arange( + vacuum_resol[0], mid_point, vacuum_resol[0] + ).tolist() tail_elongs = np.arange(mid_point, vacuum_max, vacuum_resol[1]).tolist() elongs = np.unique(head_elongs + tail_elongs).tolist() else: @@ -492,7 +502,9 @@ def pert_scaled(jdata): os.chdir(cwd) ### Construct the perturbation command - python_exec = os.path.join(os.path.dirname(__file__), "tools", "create_random_disturb.py") + python_exec = os.path.join( + os.path.dirname(__file__), "tools", "create_random_disturb.py" + ) pert_cmd = f"{sys.executable} {python_exec} -etmax {pert_box} -ofmt vasp POSCAR {pert_numb} {pert_atom} > /dev/null" ### Loop over each system and scale @@ -556,7 +568,9 @@ def run_vasp_relax(jdata, mdata): work_path_list = glob.glob(os.path.join(work_dir, "surf-*")) task_format = {"fp": "sys-*"} for work_path in work_path_list: - symlink_user_forward_files(mdata=mdata, task_type="fp", work_path=work_path, task_format=task_format) + symlink_user_forward_files( + mdata=mdata, task_type="fp", work_path=work_path, task_format=task_format + ) user_forward_files = mdata.get("fp" + "_user_forward_files", []) forward_files += [os.path.basename(file) for file in user_forward_files] backward_files += mdata.get("fp" + "_user_backward_files", []) @@ -622,7 +636,9 @@ def gen_init_surf(args): if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Generating initial data for surface systems.") + parser = argparse.ArgumentParser( + description="Generating initial data for surface systems." + ) parser.add_argument("PARAM", type=str, help="parameter file, json/yaml format") parser.add_argument( "MACHINE",