From 75e995f3b125380208a212bbafe3eb0f5f03bb72 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 3 Nov 2023 01:26:23 -0400 Subject: [PATCH 01/34] exclude docs and tests from sdist (#1385) According to https://pypi.org/project/dpgen/0.12.0/#files, these files are too large. Signed-off-by: Jinzhe Zeng --- MANIFEST.in | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 000000000..955ea233c --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +prune conda +prune doc +prune tests +prune examples From 89b4e7f850af6a4e37ae25d005a03aeedfa66b1f Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 3 Nov 2023 01:27:50 -0400 Subject: [PATCH 02/34] tests: add UT for run_model_devi (#1386) Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/generator/test_make_md.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/generator/test_make_md.py b/tests/generator/test_make_md.py index bf09508ee..1b845fd4f 100644 --- a/tests/generator/test_make_md.py +++ b/tests/generator/test_make_md.py @@ -205,6 +205,37 @@ def test_make_model_devi_nopbc_nvt(self): _check_pt(self, 0, jdata) # shutil.rmtree('iter.000000') + def test_run_model_devi(self): + if os.path.isdir("iter.000000"): + shutil.rmtree("iter.000000") + with open(param_file) as fp: + jdata = json.load(fp) + _make_fake_models(0, jdata["numb_models"]) + make_model_devi(0, jdata, {}) + with tempfile.TemporaryDirectory() as remote_root: + run_model_devi( + 0, + jdata, + { + "api_version": "1.0", + "model_devi_command": ( + "test -f input.lammps" + "&& touch model_devi.out log.lammps traj/0.lammpstrj" + "&& echo lmp" + ), + "model_devi_machine": { + "batch_type": "shell", + "local_root": "./", + "remote_root": remote_root, + "context_type": "local", + }, + "model_devi_resources": { + "group_size": 1, + }, + "model_devi_group_size": 1, + }, + ) + def test_run_model_devi_pimd(self): if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") From 1bb42c96c60c426298b934cd8978ef585c35d09e Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 6 Nov 2023 22:58:32 -0500 Subject: [PATCH 03/34] docs: add links to external documentation (#1392) Fix #1384. Signed-off-by: Jinzhe Zeng --- dpgen/generator/arginfo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dpgen/generator/arginfo.py b/dpgen/generator/arginfo.py index e1d220e42..e0b13e4c1 100644 --- a/dpgen/generator/arginfo.py +++ b/dpgen/generator/arginfo.py @@ -90,7 +90,7 @@ def training_args() -> list[Argument]: doc_numb_models = "Number of models to be trained in 00.train. 4 is recommend." doc_training_iter0_model_path = "The model used to init the first iter training. Number of element should be equal to numb_models." doc_training_init_model = "Iteration > 0, the model parameters will be initilized from the model trained at the previous iteration. Iteration == 0, the model parameters will be initialized from training_iter0_model_path." - doc_default_training_param = "Training parameters for deepmd-kit in 00.train. You can find instructions from here: (https://github.com/deepmodeling/deepmd-kit)." + doc_default_training_param = "Training parameters for deepmd-kit in 00.train. You can find instructions from `DeePMD-kit documentation `_." doc_dp_train_skip_neighbor_stat = "Append --skip-neighbor-stat flag to dp train." doc_dp_compress = "Use dp compress to compress the model." doc_training_reuse_iter = "The minimal index of iteration that continues training models from old models of last iteration." @@ -221,8 +221,8 @@ def model_devi_jobs_template_args() -> Argument: "Through user-defined template, any freedom (function) that is permitted by the engine " "software could be inherited (invoked) in the workflow." ) - doc_template_lmp = "The path to input.lammps template" - doc_template_plm = "The path to input.plumed template" + doc_template_lmp = "The path to input.lammps template. Instructions can be found in `LAMMPS documentation `_." + doc_template_plm = "The path to input.plumed template. Instructions can be found in `PLUMED documentation `_." args = [ Argument("lmp", str, optional=True, doc=doc_template_lmp), From eebdb3726b3bf43b16a7fca1f6f042654b2b67dc Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 6 Nov 2023 22:59:19 -0500 Subject: [PATCH 04/34] throw error if training_iter0_model_path is not found (#1391) Fix #622. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/generator/run.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 034918efc..8e6da1d7d 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -632,7 +632,10 @@ def make_train(iter_index, jdata, mdata): % numb_models ) for ii in range(len(iter0_models)): - old_model_files = glob.glob(os.path.join(iter0_models[ii], "model.ckpt*")) + old_model_path = os.path.join(iter0_models[ii], "model.ckpt*") + old_model_files = glob.glob(old_model_path) + if not len(old_model_files): + raise FileNotFoundError(f"{old_model_path} not found!") _link_old_models(work_path, old_model_files, ii) copied_models = next( ( From f0cf34798eb3872f5e9af0eddf2f3e35fd59d948 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:04:25 +0800 Subject: [PATCH 05/34] [pre-commit.ci] pre-commit autoupdate (#1394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.3 → v0.1.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.3...v0.1.4) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- dpgen/auto_test/lib/lammps.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75592b2db..a12105c2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.1.4 hooks: - id: ruff args: ["--fix"] diff --git a/dpgen/auto_test/lib/lammps.py b/dpgen/auto_test/lib/lammps.py index a1e387232..947f5df7f 100644 --- a/dpgen/auto_test/lib/lammps.py +++ b/dpgen/auto_test/lib/lammps.py @@ -189,9 +189,7 @@ def make_lammps_eval(conf, type_map, interaction, param): ret += ( "thermo_style custom step pe pxx pyy pzz pxy pxz pyz lx ly lz vol c_mype\n" ) - ret += ( - "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" - ) # 06/09 give dump.relax + ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" # 06/09 give dump.relax ret += "run 0\n" ret += "variable N equal count(all)\n" ret += "variable V equal vol\n" From 5219416c9238563a049cbb613551a12e0b408c46 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 9 Nov 2023 20:09:40 -0500 Subject: [PATCH 06/34] breaking: use `shlex.quote` to quote shell commands (#1396) Single quotes (`'`) can be automatically escaped. One does not need to escape single quotes in `command` manually anymore. To those who have escaped single quotes in `command` manually, this is a breaking change. Signed-off-by: Jinzhe Zeng --- dpgen/generator/run.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 8e6da1d7d..e1c255db6 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -19,6 +19,7 @@ import queue import random import re +import shlex import shutil import sys import warnings @@ -766,7 +767,7 @@ def run_train(iter_index, jdata, mdata): init_flag = " --finetune old/init.pb" command = f"{train_command} train {train_input_file}{extra_flags}" command = f"{{ if [ ! -f model.ckpt.index ]; then {command}{init_flag}; else {command} --restart model.ckpt; fi }}" - command = "/bin/sh -c '%s'" % command + command = "/bin/sh -c %s" % shlex.quote(command) commands.append(command) command = "%s freeze" % train_command commands.append(command) @@ -1944,7 +1945,7 @@ def run_md_model_devi(iter_index, jdata, mdata): command = f"{{ if [ ! -f dpgen.restart.10000 ]; then {model_devi_exec} -i input.lammps -v restart 0; else {model_devi_exec} -i input.lammps -v restart 1; fi }}" else: command = f"{{ all_exist=true; for i in $(seq -w 1 {nbeads}); do [[ ! -f dpgen.restart${{i}}.10000 ]] && {{ all_exist=false; break; }}; done; $all_exist && {{ {model_devi_exec} -p {nbeads}x1 -i input.lammps -v restart 1; }} || {{ {model_devi_exec} -p {nbeads}x1 -i input.lammps -v restart 0; }} }}" - command = "/bin/bash -c '%s'" % command + command = "/bin/bash -c %s" % shlex.quote(command) commands = [command] forward_files = ["conf.lmp", "input.lammps"] From 5fdb2ae8ae31475e2c0a2b46efdf759bd4c1a7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Thu, 9 Nov 2023 20:21:45 -0500 Subject: [PATCH 07/34] pwscf: write floaing point number for atomic masses (#1387) write floating point number for atomic masses in QE input files --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/generator/lib/pwscf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpgen/generator/lib/pwscf.py b/dpgen/generator/lib/pwscf.py index c4a86fc80..3e1ac5e00 100644 --- a/dpgen/generator/lib/pwscf.py +++ b/dpgen/generator/lib/pwscf.py @@ -88,7 +88,7 @@ def _make_pwscf_02_species(sys_data, pps): assert ntypes == len(atom_masses) assert ntypes == len(pps) for ii in range(ntypes): - ret += "%s %d %s\n" % (atom_names[ii], atom_masses[ii], pps[ii]) + ret += f"{atom_names[ii]} {atom_masses[ii]} {pps[ii]}\n" return ret From 362785343234ad379edc28b6836db17223fdbb32 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:33:58 +0800 Subject: [PATCH 08/34] [pre-commit.ci] pre-commit autoupdate (#1401) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.4 → v0.1.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.4...v0.1.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a12105c2c..2ceaa3919 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.4 + rev: v0.1.5 hooks: - id: ruff args: ["--fix"] From b8d72f3db67e3d10b053af373d1be80073061348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Sun, 19 Nov 2023 19:56:37 -0500 Subject: [PATCH 09/34] fp: add document and example for Quantum Espresso (#1405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add doc and exmple for pwscf (Quantum Espresso). --------- Signed-off-by: Yifan Li李一帆 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng --- dpgen/generator/arginfo.py | 43 +- .../dp2.x-lammps-pwscf/Al/Al_ONCV_PBE_sr.upf | 1 + .../Al/param_al_all_gpu-deepmd-kit-2.x.json | 452 ++++++++++++++++++ .../dp2.x-lammps-pwscf/CH4/H_ONCV_PBE_sr.upf | 1 + .../dp2.x-lammps-pwscf/CH4/O_ONCV_PBE_sr.upf | 1 + .../CH4/param_CH4_deepmd-kit-2.x.json | 160 +++++++ .../param_CH4_deepmd-kit-2.0.1.json | 157 ++++++ tests/test_check_examples.py | 20 + 8 files changed, 832 insertions(+), 3 deletions(-) create mode 100644 examples/run/dp2.x-lammps-pwscf/Al/Al_ONCV_PBE_sr.upf create mode 100644 examples/run/dp2.x-lammps-pwscf/Al/param_al_all_gpu-deepmd-kit-2.x.json create mode 100644 examples/run/dp2.x-lammps-pwscf/CH4/H_ONCV_PBE_sr.upf create mode 100644 examples/run/dp2.x-lammps-pwscf/CH4/O_ONCV_PBE_sr.upf create mode 100644 examples/run/dp2.x-lammps-pwscf/CH4/param_CH4_deepmd-kit-2.x.json create mode 100644 examples/run/dp2.x-lammps-pwscf/param_CH4_deepmd-kit-2.0.1.json diff --git a/dpgen/generator/arginfo.py b/dpgen/generator/arginfo.py index e0b13e4c1..70167e4b4 100644 --- a/dpgen/generator/arginfo.py +++ b/dpgen/generator/arginfo.py @@ -790,13 +790,14 @@ def fp_style_cp2k_args() -> list[Argument]: ] +# amber/diff def fp_style_amber_diff_args() -> list[Argument]: """Arguments for FP style amber/diff. Returns ------- list[dargs.Argument] - list of Gaussian fp style arguments + list of amber/diff fp style arguments """ doc_fp_params_gaussian = "Parameters for FP calculation." doc_high_level = ( @@ -827,13 +828,49 @@ def fp_style_amber_diff_args() -> list[Argument]: ] +# pwscf +def fp_style_pwscf_args() -> list[Argument]: + """Arguments for FP style pwscf (Quantum Espresso). + + Returns + ------- + list[dargs.Argument] + list of pwscf fp style arguments + """ + doc_fp_pp_path = "Directory of psuedo-potential file to be used for 02.fp exists." + doc_fp_pp_files = "Psuedo-potential file to be used for 02.fp. Note that the order of elements should correspond to the order in type_map." + doc_user_fp_params = "Parameters for pwscf calculation. Find details at https://www.quantum-espresso.org/Doc/INPUT_PW.html. When user_fp_params is set, the settings in fp_params will be ignored. If one wants to use user_fp_params, kspacing must be set in user_fp_params. kspacing is the spacing between kpoints, and helps to determin KPOINTS in pwscf." + doc_fp_params = ( + "Parameters for pwscf calculation. It has lower priority than user_fp_params." + ) + doc_ecut = "ecutwfc in pwscf." + doc_ediff = "conv_thr and ts_vdw_econv_thr in pwscf." + doc_kspacing = "The spacing between kpoints. Helps to determin KPOINTS in pwscf." + doc_smearing = "smearing in pwscf." + doc_sigma = "degauss in pwscf." + + args = [ + Argument("ecut", float, optional=False, doc=doc_ecut), + Argument("ediff", float, optional=False, doc=doc_ediff), + Argument("smearing", str, optional=False, doc=doc_smearing), + Argument("sigma", float, optional=False, doc=doc_sigma), + Argument("kspacing", float, optional=False, doc=doc_kspacing), + ] + return [ + Argument("fp_pp_path", str, optional=False, doc=doc_fp_pp_path), + Argument("fp_pp_files", list[str], optional=False, doc=doc_fp_pp_files), + Argument("fp_params", dict, args, [], optional=True, doc=doc_fp_params), + Argument("user_fp_params", dict, optional=True, doc=doc_user_fp_params), + ] + + def fp_style_custom_args() -> list[Argument]: """Arguments for FP style custom. Returns ------- list[dargs.Argument] - list of Gaussian fp style arguments + list of custom fp style arguments """ doc_fp_params_custom = "Parameters for FP calculation." doc_input_fmt = "Input dpdata format of the custom FP code. Such format should only need the first argument as the file name." @@ -883,7 +920,7 @@ def fp_style_variant_type_args() -> Variant: "amber/diff", dict, fp_style_amber_diff_args(), doc=doc_amber_diff ), Argument("pwmat", dict, [], doc="TODO: add doc"), - Argument("pwscf", dict, [], doc="TODO: add doc"), + Argument("pwscf", dict, fp_style_pwscf_args()), Argument("custom", dict, fp_style_custom_args(), doc=doc_custom), ], optional=False, diff --git a/examples/run/dp2.x-lammps-pwscf/Al/Al_ONCV_PBE_sr.upf b/examples/run/dp2.x-lammps-pwscf/Al/Al_ONCV_PBE_sr.upf new file mode 100644 index 000000000..e819ad123 --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/Al/Al_ONCV_PBE_sr.upf @@ -0,0 +1 @@ +You may download the needed pseudopotential files online. An example is https://github.com/pipidog/ONCVPSP. diff --git a/examples/run/dp2.x-lammps-pwscf/Al/param_al_all_gpu-deepmd-kit-2.x.json b/examples/run/dp2.x-lammps-pwscf/Al/param_al_all_gpu-deepmd-kit-2.x.json new file mode 100644 index 000000000..535a81d4c --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/Al/param_al_all_gpu-deepmd-kit-2.x.json @@ -0,0 +1,452 @@ +{ + "type_map": [ + "Al" + ], + "mass_map": [ + 27 + ], + "init_data_prefix": "/data1/yfb222333/2_dpgen_gpu_multi/init/", + "init_data_sys": [ + "al.fcc.02x02x02/02.md/sys-0032/deepmd", + "al.hcp.02x02x02/02.md/sys-0016/deepmd", + "al.bcc.02x02x02/02.md/sys-0016/deepmd" + ], + "sys_configs": [ + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00000[0-4]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00000[5-9]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00001*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00002*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00003*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00004*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00005*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00006*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00007*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.fcc.02x02x02/01.scale_pert/sys-0032/scale-1.000/00008*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00000[0-4]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00000[5-9]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00001*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00002*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00003*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00004*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00005*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00006*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00007*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.hcp.02x02x02/01.scale_pert/sys-0016/scale-1.000/00008*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00000[0-4]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00000[5-9]/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00001*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00002*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00003*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00004*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00005*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00006*/POSCAR" + ], + [ + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00007*/POSCAR", + "/data1/yfb222333/2_dpgen_gpu_multi/init/al.bcc.02x02x02/01.scale_pert/sys-0016/scale-1.000/00008*/POSCAR" + ] + ], + "_comment1": " 00.train ", + "numb_models": 4, + "default_training_param": { + "model": { + "_comment2": " model parameters", + "type_map": [ + "Al" + ], + "descriptor": { + "type": "se_a", + "sel": [ + 300 + ], + "rcut_smth": 2.0, + "rcut": 8.0, + "neuron": [ + 240, + 240, + 240 + ], + "resnet_dt": true, + "axis_neuron": 12, + "seed": 1 + }, + "fitting_net": { + "neuron": [ + 25, + 50, + 100 + ], + "resnet_dt": false, + "sedd": 1 + } + }, + "learning_rate": { + "type": "exp", + "start_lr": 0.001, + "decay_steps": 2000, + "stop_lr": 0.0005987369392383787 + }, + "loss": { + "start_pref_e": 0.02, + "limit_pref_e": 2, + "start_pref_f": 1000, + "limit_pref_f": 1, + "start_pref_v": 0.0, + "limit_pref_v": 0.0 + }, + "training": { + "coord_norm": true, + "type_fitting_net": false, + "_comment3": " traing controls", + "stop_batch": 20000, + "seed": 0, + "_comment4": " display and restart", + "_comment5": " frequencies counted in batch", + "disp_file": "lcurve.out", + "disp_freq": 2000, + "save_freq": 2000, + "save_ckpt": "model.ckpt", + "disp_training": true, + "time_training": true, + "profiling": false, + "profiling_file": "timeline.json", + "_comment6": "that's all", + "training_data": { + "systems": [], + "set_prefix": "set", + "batch_size": 1 + } + } + }, + "_comment7": " 01.model_devi ", + "_comment8": "model_devi_skip: the first x of the recorded frames", + "model_devi_dt": 0.002, + "model_devi_skip": 0, + "model_devi_f_trust_lo": 0.05, + "model_devi_f_trust_hi": 0.2, + "model_devi_clean_traj": false, + "model_devi_jobs": [ + { + "_idx": 0, + "ensemble": "npt", + "nsteps": 1000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 0, + 8, + 16 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 1, + "ensemble": "npt", + "nsteps": 1000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 1, + 9, + 17 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 2, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 2, + 10, + 18 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 3, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 3, + 11, + 19 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 4, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 4, + 12, + 20 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 5, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 5, + 13, + 21 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 6, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 6, + 14, + 22 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 7, + "ensemble": "npt", + "nsteps": 3000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 7, + 15, + 23 + ], + "temps": [ + 50, + 132.0, + 198.0, + 264.0 + ], + "trj_freq": 10 + }, + { + "_idx": 8, + "ensemble": "npt", + "nsteps": 1000, + "press": [ + 1.0, + 10.0, + 100.0, + 1000.0, + 5000.0, + 10000.0, + 20000.0, + 50000.0 + ], + "sys_idx": [ + 0, + 8, + 16 + ], + "temps": [ + 330.0, + 396.0, + 462.0, + 528.0, + 594.0 + ], + "trj_freq": 10 + } + ], + "fp_style": "pwscf", + "user_fp_params": { + "control": { + "calculation": "scf", + "tprnfor": true, + "outdir": "./", + "disk_io": "none", + "pseudo_dir": "./" + }, + "system": { + "ecutwfc": 110, + "input_dft": "revpbe", + "edir": 1, + "emaxpos": 0.6, + "vdw_corr": "dft-d3", + "ntyp": 1, + "nat": 192, + "ibrav": 0 + }, + "electrons": { + "electron_maxstep": 1000, + "mixing_beta": 0.5 + }, + "kspacing": 999 + }, + "shuffle_poscar": false, + "fp_task_max": 2000, + "fp_task_min": 5, + "fp_pp_path": "./", + "fp_pp_files": [ + "Al_ONCV_PBE_sr.upf" + ], + "_comment": " that's all " +} diff --git a/examples/run/dp2.x-lammps-pwscf/CH4/H_ONCV_PBE_sr.upf b/examples/run/dp2.x-lammps-pwscf/CH4/H_ONCV_PBE_sr.upf new file mode 100644 index 000000000..e819ad123 --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/CH4/H_ONCV_PBE_sr.upf @@ -0,0 +1 @@ +You may download the needed pseudopotential files online. An example is https://github.com/pipidog/ONCVPSP. diff --git a/examples/run/dp2.x-lammps-pwscf/CH4/O_ONCV_PBE_sr.upf b/examples/run/dp2.x-lammps-pwscf/CH4/O_ONCV_PBE_sr.upf new file mode 100644 index 000000000..e819ad123 --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/CH4/O_ONCV_PBE_sr.upf @@ -0,0 +1 @@ +You may download the needed pseudopotential files online. An example is https://github.com/pipidog/ONCVPSP. diff --git a/examples/run/dp2.x-lammps-pwscf/CH4/param_CH4_deepmd-kit-2.x.json b/examples/run/dp2.x-lammps-pwscf/CH4/param_CH4_deepmd-kit-2.x.json new file mode 100644 index 000000000..103179a7b --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/CH4/param_CH4_deepmd-kit-2.x.json @@ -0,0 +1,160 @@ +{ + "type_map": [ + "H", + "C" + ], + "mass_map": [ + 1, + 12 + ], + "init_data_prefix": "/data1/yfb222333/2_dpgen_gpu_multi", + "init_data_sys": [ + "CH4.POSCAR.01x01x01/02.md/sys-0004-0001/deepmd" + ], + "sys_configs_prefix": "/data1/yfb222333/2_dpgen_gpu_multi", + "sys_configs": [ + [ + "CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale*/00000*/POSCAR" + ], + [ + "CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale*/00001*/POSCAR" + ] + ], + "_comment1": " that's all ", + "numb_models": 4, + "default_training_param": { + "model": { + "type_map": [ + "H", + "C" + ], + "descriptor": { + "type": "se_a", + "sel": [ + 16, + 4 + ], + "rcut_smth": 0.5, + "rcut": 5, + "neuron": [ + 120, + 120, + 120 + ], + "resnet_dt": true, + "axis_neuron": 12, + "seed": 1 + }, + "fitting_net": { + "neuron": [ + 25, + 50, + 100 + ], + "resnet_dt": false, + "seed": 1 + } + }, + "learning_rate": { + "type": "exp", + "start_lr": 0.001, + "decay_steps": 100, + "stop_lr": 0.0003584859224085419 + }, + "loss": { + "start_pref_e": 0.02, + "limit_pref_e": 2, + "start_pref_f": 1000, + "limit_pref_f": 1, + "start_pref_v": 0.0, + "limit_pref_v": 0.0 + }, + "training": { + "stop_batch": 2000, + "disp_file": "lcurve.out", + "disp_freq": 1000, + "save_freq": 1000, + "save_ckpt": "model.ckpt", + "disp_training": true, + "time_training": true, + "profiling": false, + "profiling_file": "timeline.json", + "_comment2": "that's all", + "training_data": { + "set_prefix": "set", + "batch_size": 1 + } + } + }, + "model_devi_dt": 0.002, + "model_devi_skip": 0, + "model_devi_f_trust_lo": 0.05, + "model_devi_f_trust_hi": 0.15, + "model_devi_clean_traj": true, + "model_devi_jobs": [ + { + "sys_idx": [ + 0 + ], + "temps": [ + 100 + ], + "press": [ + 1.0 + ], + "trj_freq": 10, + "nsteps": 300, + "ensemble": "nvt", + "_idx": "00" + }, + { + "sys_idx": [ + 1 + ], + "temps": [ + 100 + ], + "press": [ + 1.0 + ], + "trj_freq": 10, + "nsteps": 3000, + "ensemble": "nvt", + "_idx": "01" + } + ], + "fp_style": "pwscf", + "user_fp_params": { + "control": { + "calculation": "scf", + "tprnfor": true, + "outdir": "./", + "disk_io": "none", + "pseudo_dir": "./" + }, + "system": { + "ecutwfc": 110, + "input_dft": "revpbe", + "edir": 1, + "emaxpos": 0.6, + "vdw_corr": "dft-d3", + "ntyp": 2, + "nat": 5, + "ibrav": 0 + }, + "electrons": { + "electron_maxstep": 1000, + "mixing_beta": 0.5 + }, + "kspacing": 999 + }, + "shuffle_poscar": false, + "fp_task_max": 2000, + "fp_task_min": 5, + "fp_pp_path": "./", + "fp_pp_files": [ + "C_ONCV_PBE_sr.upf", + "H_ONCV_PBE_sr.upf" + ], + "_comment": " that's all " +} diff --git a/examples/run/dp2.x-lammps-pwscf/param_CH4_deepmd-kit-2.0.1.json b/examples/run/dp2.x-lammps-pwscf/param_CH4_deepmd-kit-2.0.1.json new file mode 100644 index 000000000..4de2c3751 --- /dev/null +++ b/examples/run/dp2.x-lammps-pwscf/param_CH4_deepmd-kit-2.0.1.json @@ -0,0 +1,157 @@ +{ + "type_map": [ + "H", + "C" + ], + "mass_map": [ + 1, + 12 + ], + "init_data_prefix": "./", + "init_data_sys": [ + "CH4.POSCAR.01x01x01/02.md/sys-0004-0001/deepmd" + ], + "sys_configs_prefix": "./", + "sys_configs": [ + [ + "CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale*/00000*/POSCAR" + ], + [ + "CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale*/00001*/POSCAR" + ] + ], + "_comment1": " that's all ", + "numb_models": 4, + "default_training_param": { + "model": { + "type_map": [ + "H", + "C" + ], + "descriptor": { + "type": "se_a", + "sel": [ + 16, + 4 + ], + "rcut_smth": 0.5, + "rcut": 5.0, + "neuron": [ + 120, + 120, + 120 + ], + "resnet_dt": true, + "axis_neuron": 12, + "seed": 1 + }, + "fitting_net": { + "neuron": [ + 25, + 50, + 100 + ], + "resnet_dt": false, + "seed": 1 + } + }, + "learning_rate": { + "type": "exp", + "start_lr": 0.001, + "decay_steps": 100 + }, + "loss": { + "start_pref_e": 0.02, + "limit_pref_e": 2, + "start_pref_f": 1000, + "limit_pref_f": 1, + "start_pref_v": 0.0, + "limit_pref_v": 0.0 + }, + "training": { + "set_prefix": "set", + "numb_steps": 2000, + "batch_size": 1, + "disp_file": "lcurve.out", + "disp_freq": 1000, + "save_freq": 1000, + "save_ckpt": "model.ckpt", + "disp_training": true, + "time_training": true, + "profiling": false, + "profiling_file": "timeline.json", + "_comment2": "that's all" + } + }, + "model_devi_dt": 0.002, + "model_devi_skip": 0, + "model_devi_f_trust_lo": 0.05, + "model_devi_f_trust_hi": 0.15, + "model_devi_clean_traj": true, + "model_devi_jobs": [ + { + "sys_idx": [ + 0 + ], + "temps": [ + 100 + ], + "press": [ + 1.0 + ], + "trj_freq": 10, + "nsteps": 300, + "ensemble": "nvt", + "_idx": "00" + }, + { + "sys_idx": [ + 1 + ], + "temps": [ + 100 + ], + "press": [ + 1.0 + ], + "trj_freq": 10, + "nsteps": 3000, + "ensemble": "nvt", + "_idx": "01" + } + ], + "fp_style": "pwscf", + "user_fp_params": { + "control": { + "calculation": "scf", + "tprnfor": true, + "outdir": "./", + "disk_io": "none", + "pseudo_dir": "./" + }, + "system": { + "ecutwfc": 110, + "input_dft": "revpbe", + "edir": 1, + "emaxpos": 0.6, + "vdw_corr": "dft-d3", + "ntyp": 2, + "nat": 5, + "ibrav": 0 + }, + "electrons": { + "electron_maxstep": 1000, + "mixing_beta": 0.5 + }, + "kspacing": 999 + }, + "shuffle_poscar": false, + "fp_task_max": 2000, + "fp_task_min": 5, + "fp_pp_path": "./CH4", + "fp_pp_files": [ + "C_ONCV_PBE_sr.upf", + "H_ONCV_PBE_sr.upf" + ], + "_comment": " that's all " +} diff --git a/tests/test_check_examples.py b/tests/test_check_examples.py index 8522e8568..cbbae79b6 100644 --- a/tests/test_check_examples.py +++ b/tests/test_check_examples.py @@ -45,6 +45,10 @@ run_jdata, p_examples / "run" / "dp2.x-lammps-vasp" / "param_CH4_deepmd-kit-2.0.1.json", ), + ( + run_jdata, + p_examples / "run" / "dp2.x-lammps-pwscf" / "param_CH4_deepmd-kit-2.0.1.json", + ), ( run_jdata, p_examples / "run" / "dp2.x-lammps-cp2k" / "param_CH4_deepmd-kit-2.0.1.json", @@ -66,6 +70,22 @@ / "Al" / "param_al_all_gpu-deepmd-kit-2.x.json", ), + ( + run_jdata, + p_examples + / "run" + / "dp2.x-lammps-pwscf" + / "CH4" + / "param_CH4_deepmd-kit-2.x.json", + ), + ( + run_jdata, + p_examples + / "run" + / "dp2.x-lammps-pwscf" + / "Al" + / "param_al_all_gpu-deepmd-kit-2.x.json", + ), (run_jdata, p_examples / "run" / "dp2.x-lammps-vasp-et" / "param_elet.json"), ( run_jdata, From 3709f8c49963f17d032ef71fd1ccbbe57a41dded Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Nov 2023 10:04:18 +0800 Subject: [PATCH 10/34] [pre-commit.ci] pre-commit autoupdate (#1407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.5 → v0.1.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.5...v0.1.6) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2ceaa3919..a0ac5d765 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.5 + rev: v0.1.6 hooks: - id: ruff args: ["--fix"] From 1d04cbc820fc0fc81ab6e78a56593b805b094844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Mon, 20 Nov 2023 21:09:01 -0500 Subject: [PATCH 11/34] model devi: download LAMMPS log files for pimd (#1406) put LAMMPS's log files in backward_files for pimd --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/generator/run.py | 1 + tests/generator/test_make_md.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index e1c255db6..f8eacdb91 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -1957,6 +1957,7 @@ def run_md_model_devi(iter_index, jdata, mdata): backward_files += [ f"model_devi{i+1:0{num_digits}d}.out" for i in range(nbeads) ] + backward_files += [f"log.lammps.{i:d}" for i in range(nbeads)] if model_devi_merge_traj: backward_files += ["all.lammpstrj"] else: diff --git a/tests/generator/test_make_md.py b/tests/generator/test_make_md.py index 1b845fd4f..4cf36dfec 100644 --- a/tests/generator/test_make_md.py +++ b/tests/generator/test_make_md.py @@ -252,7 +252,7 @@ def test_run_model_devi_pimd(self): { "api_version": "1.0", "model_devi_command": ( - "touch model_devi1.out model_devi2.out model_devi3.out model_devi4.out" + "touch model_devi1.out model_devi2.out model_devi3.out model_devi4.out log.lammps.0 log.lammps.1 log.lammps.2 log.lammps.3" "&& echo lmp" ), "model_devi_machine": { From a0beb29581bd96f7e65d9d4da7a1e8934db5d85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Tue, 28 Nov 2023 00:00:21 -0500 Subject: [PATCH 12/34] dpgen simplify: add document for fp style pwscf (#1413) add document for pwscf in dpgen simplify --- dpgen/simplify/arginfo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dpgen/simplify/arginfo.py b/dpgen/simplify/arginfo.py index 2fb4547f7..516b27e60 100644 --- a/dpgen/simplify/arginfo.py +++ b/dpgen/simplify/arginfo.py @@ -8,6 +8,7 @@ fp_style_cp2k_args, fp_style_custom_args, fp_style_gaussian_args, + fp_style_pwscf_args, fp_style_siesta_args, fp_style_vasp_args, training_args, @@ -112,6 +113,7 @@ def fp_style_variant_type_args() -> Variant: doc_fp_style = "Software for First Principles, if `labeled` is false." doc_fp_style_none = "No fp." doc_fp_style_vasp = "VASP." + doc_fp_style_pwscf = "pwscf (Quantum Espresso)." doc_fp_style_gaussian = "Gaussian. The command should be set as `g16 < input`." doc_custom = ( "Custom FP code. You need to provide the input and output file format and name. " @@ -136,7 +138,7 @@ def fp_style_variant_type_args() -> Variant: # "amber/diff", dict, fp_style_amber_diff_args(), doc=doc_amber_diff # ), Argument("pwmat", dict, [], doc="TODO: add doc"), - Argument("pwscf", dict, [], doc="TODO: add doc"), + Argument("pwscf", dict, fp_style_pwscf_args(), doc=doc_fp_style_pwscf), Argument("custom", dict, fp_style_custom_args(), doc=doc_custom), ], optional=True, From d90939caf643dff1e208d80223bff7e842879780 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 7 Dec 2023 20:07:41 -0500 Subject: [PATCH 13/34] only log the current iteration when restarting (#1420) The current behavior is that all previous iterations are logged. --------- Signed-off-by: Jinzhe Zeng --- dpgen/generator/run.py | 2 ++ dpgen/simplify/simplify.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index f8eacdb91..e97263307 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -4732,6 +4732,8 @@ def run_iter(param_file, machine_file): ii = -1 while cont: ii += 1 + if ii < iter_rec[0]: + continue iter_name = make_iter_name(ii) sepline(iter_name, "=") for jj in range(numb_task): diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 98de7c5a8..a69ffe12e 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -550,6 +550,8 @@ def run_iter(param_file, machine_file): ii = -1 while cont: ii += 1 + if ii < iter_rec[0]: + continue iter_name = make_iter_name(ii) sepline(iter_name, "=") for jj in range(numb_task): From c3d8f96646f5ee809c3964172a711f5918927ecb Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 11 Dec 2023 00:24:45 -0500 Subject: [PATCH 14/34] support collecting MultiSystems (#1422) Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/collect/collect.py | 5 ++++- tests/test_collect.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/test_collect.py diff --git a/dpgen/collect/collect.py b/dpgen/collect/collect.py index 808341e6f..ab1cc9406 100644 --- a/dpgen/collect/collect.py +++ b/dpgen/collect/collect.py @@ -8,6 +8,7 @@ import dpdata from dpgen.generator.run import data_system_fmt +from dpgen.util import expand_sys_str def collect_data( @@ -18,7 +19,8 @@ def collect_data( # goto input cwd = os.getcwd() os.chdir(target_folder) - jdata = json.load(open(param_file)) + with open(param_file) as fp: + jdata = json.load(fp) sys_configs_prefix = jdata.get("sys_configs_prefix", "") sys_configs = jdata.get("sys_configs", []) if verbose: @@ -46,6 +48,7 @@ def collect_data( for ii in range(len(iters)): iter_data = glob.glob(os.path.join(iters[ii], "02.fp", "data.[0-9]*[0-9]")) iter_data.sort() + iter_data = sum([expand_sys_str(ii) for ii in iter_data], []) for jj in iter_data: sys = dpdata.LabeledSystem(jj, fmt="deepmd/npy") if merge: diff --git a/tests/test_collect.py b/tests/test_collect.py new file mode 100644 index 000000000..434f2c0ea --- /dev/null +++ b/tests/test_collect.py @@ -0,0 +1,33 @@ +import json +import tempfile +import unittest +from pathlib import Path + +import dpdata + +from dpgen.collect.collect import collect_data + + +class TestCollectData(unittest.TestCase): + def setUp(self): + self.data = dpdata.LabeledSystem( + Path(__file__).parent / "generator" / "data" / "deepmd", fmt="deepmd/npy" + ) + + def test_collect_data(self): + with tempfile.TemporaryDirectory() as inpdir, tempfile.TemporaryDirectory() as outdir, tempfile.NamedTemporaryFile() as param_file: + self.data.to_deepmd_npy(Path(inpdir) / "iter.000000" / "02.fp" / "data.000") + self.data.to_deepmd_npy( + Path(inpdir) / "iter.000001" / "02.fp" / "data.000" / "aa" + ) + self.data.to_deepmd_npy( + Path(inpdir) / "iter.000001" / "02.fp" / "data.000" / "bb" + ) + with open(param_file.name, "w") as fp: + json.dump( + {"sys_configs": ["sys1"], "model_devi_jobs": [{}, {}, {}]}, fp + ) + + collect_data(inpdir, param_file.name, outdir, verbose=True) + ms = dpdata.MultiSystems().from_deepmd_npy(outdir) + self.assertEqual(ms.get_nframes(), self.data.get_nframes() * 3) From 4fe903e74f68757083b486a65b14cd48fa25d4c5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Dec 2023 09:08:22 +0800 Subject: [PATCH 15/34] [pre-commit.ci] pre-commit autoupdate (#1424) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.6 → v0.1.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.6...v0.1.7) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a0ac5d765..6d450f53f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.1.7 hooks: - id: ruff args: ["--fix"] From 63febb2de7eba34afd7e5648891666d8a19187f3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Dec 2023 09:37:52 +0800 Subject: [PATCH 16/34] [pre-commit.ci] pre-commit autoupdate (#1430) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.7 → v0.1.8](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.7...v0.1.8) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6d450f53f..33f9e8d6e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 + rev: v0.1.8 hooks: - id: ruff args: ["--fix"] From be88ceac5a6d7f3fe02ddc0b6b322962f88c593d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Dec 2023 07:47:17 +0800 Subject: [PATCH 17/34] [pre-commit.ci] pre-commit autoupdate (#1436) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.8 → v0.1.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.8...v0.1.9) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 33f9e8d6e..0f82267e4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.8 + rev: v0.1.9 hooks: - id: ruff args: ["--fix"] From 0ffe628eb1c322a11a262a3aeadf2e9de42a4f52 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:17:05 +0800 Subject: [PATCH 18/34] [pre-commit.ci] pre-commit autoupdate (#1447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.9 → v0.1.11](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.9...v0.1.11) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f82267e4..cddd9eb3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.1.11 hooks: - id: ruff args: ["--fix"] From 5a57e112045336ab9b98dd756343981b8da00aed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 11:27:02 +0800 Subject: [PATCH 19/34] [pre-commit.ci] pre-commit autoupdate (#1453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.11 → v0.1.13](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.11...v0.1.13) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- dpgen/generator/arginfo.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cddd9eb3e..1c92407a8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.11 + rev: v0.1.13 hooks: - id: ruff args: ["--fix"] diff --git a/dpgen/generator/arginfo.py b/dpgen/generator/arginfo.py index 70167e4b4..9ed6ba887 100644 --- a/dpgen/generator/arginfo.py +++ b/dpgen/generator/arginfo.py @@ -325,10 +325,12 @@ def model_devi_lmp_args() -> list[Argument]: doc_model_devi_f_trust_hi = "Upper bound of forces for the selection. If list or dict, should be set for each index in sys_configs, respectively." doc_model_devi_v_trust_lo = "Lower bound of virial for the selection. If list or dict, should be set for each index in sys_configs, respectively. Should be used with DeePMD-kit v2.x." doc_model_devi_v_trust_hi = "Upper bound of virial for the selection. If list or dict, should be set for each index in sys_configs, respectively. Should be used with DeePMD-kit v2.x." - doc_model_devi_adapt_trust_lo = "Adaptively determines the lower trust levels of force and virial. This option should be used together with model_devi_numb_candi_f, model_devi_numb_candi_v and optionally with model_devi_perc_candi_f and model_devi_perc_candi_v. dpgen will make two sets:\n\n\ + doc_model_devi_adapt_trust_lo = ( + "Adaptively determines the lower trust levels of force and virial. This option should be used together with model_devi_numb_candi_f, model_devi_numb_candi_v and optionally with model_devi_perc_candi_f and model_devi_perc_candi_v. dpgen will make two sets:\n\n\ - 1. From the frames with force model deviation lower than model_devi_f_trust_hi, select max(model_devi_numb_candi_f, model_devi_perc_candi_f*n_frames) frames with largest force model deviation. \n\n\ - 2. From the frames with virial model deviation lower than model_devi_v_trust_hi, select max(model_devi_numb_candi_v, model_devi_perc_candi_v*n_frames) frames with largest virial model deviation. \n\n\ The union of the two sets is made as candidate dataset." + ) doc_model_devi_numb_candi_f = "See model_devi_adapt_trust_lo." doc_model_devi_numb_candi_v = "See model_devi_adapt_trust_lo." doc_model_devi_perc_candi_f = "See model_devi_adapt_trust_lo." From 73926506688ac8f8939f065056e83ac51fb2601f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:24:35 +0800 Subject: [PATCH 20/34] [pre-commit.ci] pre-commit autoupdate (#1458) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.13 → v0.1.14](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.13...v0.1.14) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1c92407a8..44d707af3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.13 + rev: v0.1.14 hooks: - id: ruff args: ["--fix"] From a01acaadaaf5d28a14c47e905614ffadc59171ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Thu, 29 Feb 2024 16:13:07 -0500 Subject: [PATCH 21/34] Fix UTs destroyed by pymatgen's update (#1471) There are 2 changes in pymatgen which destroy the previous unittests: 1. https://github.com/materialsproject/pymatgen/pull/3542 Previously we set the type of DummySpecies to "Type", which is forbidden by pymatgen through this PR. Here we replace "Type" with "X". 2. https://github.com/materialsproject/pymatgen/pull/3561 The functions from_string and get_string have been replaced with from_str and get_str. We should keep up to date with these changes. --- dpgen/data/surf.py | 5 ++++- dpgen/data/tools/bcc.py | 2 +- dpgen/data/tools/diamond.py | 2 +- dpgen/data/tools/fcc.py | 2 +- dpgen/data/tools/hcp.py | 2 +- dpgen/data/tools/sc.py | 2 +- tests/generator/test_make_fp.py | 24 ++++++++++++++++++------ 7 files changed, 27 insertions(+), 12 deletions(-) diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 5194af5b3..2590f9a6b 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -415,7 +415,10 @@ def poscar_scale(poscar_in, poscar_out, scale): except AttributeError: poscar = Poscar.from_str("".join(lines)) with open(poscar_out, "w") as fout: - fout.write(poscar.get_string(direct=False)) + try: + fout.write(poscar.get_string(direct=False)) + except AttributeError: + fout.write(poscar.get_str(direct=False)) def make_scale(jdata): diff --git a/dpgen/data/tools/bcc.py b/dpgen/data/tools/bcc.py index 9c471e36b..3ba99aa6f 100644 --- a/dpgen/data/tools/bcc.py +++ b/dpgen/data/tools/bcc.py @@ -17,7 +17,7 @@ def poscar_unit(latt): ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n" ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n" ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n" - ret += "Type\n" + ret += "X\n" ret += "%d\n" % numb_atoms() ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" diff --git a/dpgen/data/tools/diamond.py b/dpgen/data/tools/diamond.py index f4a2b52a3..f7d82d01e 100644 --- a/dpgen/data/tools/diamond.py +++ b/dpgen/data/tools/diamond.py @@ -22,7 +22,7 @@ def poscar_unit(latt): ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n" ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n" ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n" - ret += "Type\n" + ret += "X\n" ret += "%d\n" % numb_atoms() ret += "Direct\n" ret += f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n" diff --git a/dpgen/data/tools/fcc.py b/dpgen/data/tools/fcc.py index 80f0b476b..a89ef5385 100644 --- a/dpgen/data/tools/fcc.py +++ b/dpgen/data/tools/fcc.py @@ -17,7 +17,7 @@ def poscar_unit(latt): ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n" ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n" ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n" - ret += "Type\n" + ret += "X\n" ret += "%d\n" % numb_atoms() ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" diff --git a/dpgen/data/tools/hcp.py b/dpgen/data/tools/hcp.py index aeea4afc3..bfd2fa3c4 100644 --- a/dpgen/data/tools/hcp.py +++ b/dpgen/data/tools/hcp.py @@ -20,7 +20,7 @@ def poscar_unit(latt): ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n" ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n" ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n" - ret += "Type\n" + ret += "X\n" ret += "%d\n" % numb_atoms() ret += "Direct\n" ret += f"{0:.16f} {0:.16f} {0:.16f}\n" diff --git a/dpgen/data/tools/sc.py b/dpgen/data/tools/sc.py index fff019d6d..fdcbe0107 100644 --- a/dpgen/data/tools/sc.py +++ b/dpgen/data/tools/sc.py @@ -17,7 +17,7 @@ def poscar_unit(latt): ret += f"{box[0][0]:.16f} {box[0][1]:.16f} {box[0][2]:.16f}\n" ret += f"{box[1][0]:.16f} {box[1][1]:.16f} {box[1][2]:.16f}\n" ret += f"{box[2][0]:.16f} {box[2][1]:.16f} {box[2][2]:.16f}\n" - ret += "Type\n" + ret += "X\n" ret += "%d\n" % numb_atoms() ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" diff --git a/tests/generator/test_make_fp.py b/tests/generator/test_make_fp.py index 7c9699e6d..e22199569 100644 --- a/tests/generator/test_make_fp.py +++ b/tests/generator/test_make_fp.py @@ -414,7 +414,10 @@ def _check_kpoints(testCase, idx): ret = make_kspacing_kpoints( os.path.join(os.path.join(ii, "POSCAR")), kspacing, gamma ) - kpoints_ref = Kpoints.from_string(ret) + try: + kpoints_ref = Kpoints.from_string(ret) + except AttributeError: + kpoints_ref = Kpoints.from_str(ret) testCase.assertEqual(repr(kpoints), repr(kpoints_ref)) @@ -496,12 +499,21 @@ def _check_incar_ele_temp(testCase, idx, ele_temp): tidx = int(bname.split(".")[2]) with open("INCAR") as fp: incar = fp.read() - incar0 = Incar.from_string(incar) + try: + incar0 = Incar.from_string(incar) + except AttributeError: + incar0 = Incar.from_str(incar) # make_fake_md: the frames in a system shares the same ele_temp - incar1 = Incar.from_string( - vasp_incar_ele_temp_ref - % (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt) - ) + try: + incar1 = Incar.from_string( + vasp_incar_ele_temp_ref + % (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt) + ) + except AttributeError: + incar1 = Incar.from_str( + vasp_incar_ele_temp_ref + % (ele_temp[sidx][0] * pc.Boltzmann / pc.electron_volt) + ) for ii in incar0.keys(): # skip checking nbands... if ii == "NBANDS": From aefcbc2bc560c4afca199984802145da6481c7f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:17:48 +0000 Subject: [PATCH 22/34] [pre-commit.ci] pre-commit autoupdate (#1465) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.14...v0.2.2) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 44d707af3..37ff00ae1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.2.2 hooks: - id: ruff args: ["--fix"] From b1ea0e9d4047f4aeb4b9bbe0bd34f696a1c39b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Thu, 29 Feb 2024 22:22:37 -0500 Subject: [PATCH 23/34] Bugfix for pimd: sorting model_devi files (#1470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous regular expression did not sort the multiple model_devi.out files in pimd correctly. As a result, the correspondence between the model_devi files and the trajectory files was wrong. Since the wrong configurations were picked, the model_devi accuracy cannot be improved to a very high level when pimd is used. This PR fixes the bug. --------- Signed-off-by: Yifan Li李一帆 Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jinzhe Zeng --- dpgen/generator/run.py | 9 +++++---- tests/generator/test_make_md.py | 27 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index e97263307..8c571e190 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -2168,10 +2168,11 @@ def _read_model_devi_file( model_devi_merge_traj: bool = False, ): model_devi_files = glob.glob(os.path.join(task_path, "model_devi*.out")) - model_devi_files_sorted = sorted( - model_devi_files, key=lambda x: int(re.search(r"(\d+)", x).group(1)) - ) - if len(model_devi_files_sorted) > 1: + if len(model_devi_files) > 1: + model_devi_files_sorted = sorted( + model_devi_files, + key=lambda x: int(re.search(r"model_devi(\d+)\.out", x).group(1)), + ) with open(model_devi_files_sorted[0]) as f: first_line = f.readline() if not (first_line.startswith("#")): diff --git a/tests/generator/test_make_md.py b/tests/generator/test_make_md.py index 4cf36dfec..22c867a53 100644 --- a/tests/generator/test_make_md.py +++ b/tests/generator/test_make_md.py @@ -2,6 +2,7 @@ import glob import json import os +import re import shutil import sys import unittest @@ -274,22 +275,36 @@ def test_read_model_devi_file_pimd(self): if os.path.isdir(path): shutil.rmtree(path) os.makedirs(path, exist_ok=True) + path = os.path.join(path, "iter.000000/01.model_devi/task.000.000000") os.makedirs(os.path.join(path, "traj"), exist_ok=True) for i in range(4): for j in range(0, 5, 2): - with open(os.path.join(path, f"traj/{j}.lammpstrj{i+1}"), "a"): - pass + with open(os.path.join(path, f"traj/{j}.lammpstrj{i+1}"), "a") as fp: + fp.write(f"{i} {j}\n") model_devi_array = np.zeros([3, 7]) model_devi_array[:, 0] = np.array([0, 2, 4]) + model_devi_total_array = np.zeros([12, 7]) + total_steps = np.array([0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19]) + model_devi_total_array[:, 0] = total_steps for i in range(4): + model_devi_array[:, 4] = 0.1 * (i + 1) * np.arange(1, 4) + model_devi_total_array[i * 3 : (i + 1) * 3, 4] = model_devi_array[:, 4] np.savetxt( - os.path.join(path, f"model_devi{i+1}.out"), model_devi_array, fmt="%d" + os.path.join(path, f"model_devi{i+1}.out"), + model_devi_array, + fmt="%.12e", ) _read_model_devi_file(path) - model_devi_total_array = np.zeros([12, 7]) - total_steps = np.array([0, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19]) - model_devi_total_array[:, 0] = total_steps model_devi_out = np.loadtxt(os.path.join(path, "model_devi.out")) + traj_files = glob.glob(os.path.join(path, "traj/*.lammpstrj")) + traj_files = sorted( + traj_files, key=lambda x: int(re.search(r"(\d+).lammpstrj", x).group(1)) + ) + for idx, traj in enumerate(traj_files): + traj_content = np.loadtxt(traj) + ibead = idx // 3 + istep = (idx % 3) * 2 + np.testing.assert_array_almost_equal(traj_content, np.array([ibead, istep])) np.testing.assert_array_almost_equal(model_devi_out, model_devi_total_array) for istep in total_steps: self.assertTrue( From e7b4311d976bf8eb10bc7ca3275888ad38c00b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yifan=20Li=E6=9D=8E=E4=B8=80=E5=B8=86?= Date: Sat, 2 Mar 2024 20:26:48 -0500 Subject: [PATCH 24/34] keep original model_devi.out files for pimd (#1472) --- dpgen/generator/run.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 8c571e190..d0157145f 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -2185,8 +2185,6 @@ def _read_model_devi_file( model_devi_content.shape[0] == model_devi_contents[0].shape[0] for model_devi_content in model_devi_contents ), "Not all beads generated the same number of lines in the model_devi$\{ibead\}.out file. Check your pimd task carefully." - for file in model_devi_files_sorted: - os.remove(file) last_step = model_devi_contents[0][-1, 0] for ibead in range(1, num_beads): model_devi_contents[ibead][:, 0] = model_devi_contents[ibead][ From cbecd99b691e0f7a3fe2f6799dc4ce5c6e87d80c Mon Sep 17 00:00:00 2001 From: Yoh <32323458+yohsama@users.noreply.github.com> Date: Thu, 7 Mar 2024 03:04:53 +0800 Subject: [PATCH 25/34] issue1475: a small bug of iterdict (generator/lib/cp2k.py) (#1476) 1. The flag in iterdict (generator/lib/cp2k.py) now contains the parent section name, and fix the problem that the content of multiple sections with the same name will only be inserted into the first section. 2. Add indent for sections. now the input generate by make_cp2k_input is look like this: ``` &GLOBAL PROJECT DPGEN PREFERRED_DIAG_LIBRARY SCALAPACK &END GLOBAL &FORCE_EVAL METHOD QS STRESS_TENSOR ANALYTICAL &DFT #FORCE_EVAL BASIS_SET_FILE_NAME EMSL_BASIS_SETS POTENTIAL_FILE_NAME POTENTIAL CHARGE 0 UKS TRUE &MGRID #DFT #FORCE_EVAL CUTOFF 800 REL_CUTOFF 55 NGRIDS 4 &END MGRID #DFT #FORCE_EVAL &QS #DFT #FORCE_EVAL EPS_DEFAULT 1.0E-12 METHOD GAPW &END QS #DFT #FORCE_EVAL &SCF #DFT #FORCE_EVAL SCF_GUESS ATOMIC EPS_SCF 1.0E-6 MAX_SCF 50 &MIXING #SCF #DFT #FORCE_EVAL METHOD BROYDEN_MIXING &END MIXING #SCF #DFT #FORCE_EVAL &PRINT #SCF #DFT #FORCE_EVAL &RESTART OFF &END RESTART #PRINT #SCF #DFT #FORCE_EVAL &END PRINT #SCF #DFT #FORCE_EVAL ADD_MOS -1 -1 &END SCF #DFT #FORCE_EVAL &XC #DFT #FORCE_EVAL &XC_FUNCTIONAL B3LYP &END XC_FUNCTIONAL #XC #DFT #FORCE_EVAL &HF #XC #DFT #FORCE_EVAL &MEMORY #HF #XC #DFT #FORCE_EVAL MAX_MEMORY 2000 &END MEMORY #HF #XC #DFT #FORCE_EVAL &END HF #XC #DFT #FORCE_EVAL &END XC #DFT #FORCE_EVAL &POISSON #DFT #FORCE_EVAL PERIODIC NONE POISSON_SOLVER MULTIPOLE &END POISSON #DFT #FORCE_EVAL RELAX_MULTIPLICITY 0.00001 &END DFT #FORCE_EVAL &SUBSYS #FORCE_EVAL &CELL #SUBSYS #FORCE_EVAL A 14.39252 0. 0. B 0. 20.281213 0. C 0. 0. 15.801355 PERIODIC NONE &END CELL #SUBSYS #FORCE_EVAL &COORD #SUBSYS #FORCE_EVAL @include coord.xyz &END COORD #SUBSYS #FORCE_EVAL &KIND Cl BASIS_SET 6-311G** POTENTIAL ALL &END KIND #SUBSYS #FORCE_EVAL &KIND H BASIS_SET 6-311G** POTENTIAL ALL &END KIND #SUBSYS #FORCE_EVAL &KIND C BASIS_SET 6-311G** POTENTIAL ALL &END KIND #SUBSYS #FORCE_EVAL &END SUBSYS #FORCE_EVAL &PRINT #FORCE_EVAL &FORCES ON &END FORCES #PRINT #FORCE_EVAL &STRESS_TENSOR ON &END STRESS_TENSOR #PRINT #FORCE_EVAL &END PRINT #FORCE_EVAL &END FORCE_EVAL ``` --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/generator/lib/cp2k.py | 47 +++++++----- tests/generator/cp2k_test_ref.inp | 114 +++++++++++++++--------------- 2 files changed, 87 insertions(+), 74 deletions(-) diff --git a/dpgen/generator/lib/cp2k.py b/dpgen/generator/lib/cp2k.py index 4ab9ae4c5..a73a94d7a 100644 --- a/dpgen/generator/lib/cp2k.py +++ b/dpgen/generator/lib/cp2k.py @@ -48,13 +48,15 @@ def update_dict(old_d, update_d): old_d[k] = update_d[k] -def iterdict(d, out_list, flag=None): - """:doc: a recursive expansion of dictionary into cp2k input +def iterdict(d, out_list, flag=None, indent=0): + """ + :doc: a recursive expansion of dictionary into cp2k input :k: current key :v: current value :d: current dictionary under expansion :flag: used to record dictionary state. if flag is None, it means we are in top level dict. flag is a string. + :indent: intent for current section. """ for k, v in d.items(): k = str(k) # cast key into string @@ -64,16 +66,17 @@ def iterdict(d, out_list, flag=None): if flag is None: out_list.append("&" + k) out_list.append("&END " + k) - iterdict(v, out_list, k) + iterdict(v, out_list, k, indent + 2) # flag is not None, now it has name of section else: - index = out_list.index("&END " + flag) - out_list.insert(index, "&" + k) - out_list.insert(index + 1, "&END " + k) - iterdict(v, out_list, k) + index = out_list.index(" " * (indent - 2) + "&END " + flag) + out_list.insert(index, " " * indent + "&" + k + " #" + flag) + out_list.insert(index + 1, " " * indent + "&END " + k + " #" + flag) + # the flag now contains its parent section name, separed by "#". + iterdict(v, out_list, k + " #" + flag, indent + 2) elif isinstance(v, list): # print("we have encountered the repeat section!") - index = out_list.index("&" + flag) + index = out_list.index(" " * (indent - 2) + "&" + flag) # delete the current constructed repeat section del out_list[index : index + 2] # do a loop over key and corresponding list @@ -83,14 +86,22 @@ def iterdict(d, out_list, flag=None): k_tmp_list.append(str(k_tmp)) v_list_tmp_list.append(v_tmp) for repeat_keyword in zip(*v_list_tmp_list): - out_list.insert(index, "&" + flag) - out_list.insert(index + 1, "&END " + flag) + out_list.insert(index, " " * (indent - 2) + "&" + flag) + out_list.insert(index + 1, " " * (indent - 2) + "&END " + flag) for idx, k_tmp in enumerate(k_tmp_list): if k_tmp == "_": - out_list[index] = "&" + flag + " " + repeat_keyword[idx] + out_list[index] = ( + " " * (indent - 2) + + "&" + + flag.split(" #")[0] + + " " + + repeat_keyword[idx] + ) else: - out_list.insert(index + 1, k_tmp + " " + repeat_keyword[idx]) - + out_list.insert( + index + 1, + " " * (indent) + k_tmp + " " + repeat_keyword[idx], + ) break else: @@ -100,12 +111,14 @@ def iterdict(d, out_list, flag=None): print(k, ":", v) else: if k == "_": - index = out_list.index("&" + flag) - out_list[index] = "&" + flag + " " + v + index = out_list.index(" " * (indent - 2) + "&" + flag) + out_list[index] = ( + " " * (indent - 2) + "&" + flag.split(" #")[0] + " " + v + ) else: - index = out_list.index("&END " + flag) - out_list.insert(index, k + " " + v) + index = out_list.index(" " * (indent - 2) + "&END " + flag) + out_list.insert(index, " " * indent + k + " " + v) def make_cp2k_input(sys_data, fp_params): diff --git a/tests/generator/cp2k_test_ref.inp b/tests/generator/cp2k_test_ref.inp index 6197bbb97..164964c61 100644 --- a/tests/generator/cp2k_test_ref.inp +++ b/tests/generator/cp2k_test_ref.inp @@ -1,60 +1,60 @@ &GLOBAL -PROJECT DPGEN + PROJECT DPGEN &END GLOBAL &FORCE_EVAL -METHOD QS -STRESS_TENSOR ANALYTICAL -&DFT -BASIS_SET_FILE_NAME ./cp2k_basis_pp_file/BASIS_MOLOPT -POTENTIAL_FILE_NAME ./cp2k_basis_pp_file/GTH_POTENTIALS -CHARGE 0 -UKS F -MULTIPLICITY 1 -&MGRID -CUTOFF 400 -REL_CUTOFF 50 -NGRIDS 4 -&END MGRID -&QS -EPS_DEFAULT 1.0E-12 -&END QS -&SCF -SCF_GUESS ATOMIC -EPS_SCF 1.0E-6 -MAX_SCF 50 -&OT -MINIMIZER DIIS -PRECONDITIONER FULL_SINGLE_INVERSE -&END OT -&END SCF -&XC -&XC_FUNCTIONAL PBE -&END XC_FUNCTIONAL -&END XC -&END DFT -&SUBSYS -&CELL -&END CELL -&COORD -@include coord.xyz -&END COORD -&KIND H -BASIS_SET DZVP-MOLOPT-GTH -POTENTIAL GTH-PBE-q1 -&END KIND -&KIND C -BASIS_SET DZVP-MOLOPT-GTH -POTENTIAL GTH-PBE-q4 -&END KIND -&KIND N -BASIS_SET DZVP-MOLOPT-GTH -POTENTIAL GTH-PBE-q5 -&END KIND -&END SUBSYS -&PRINT -&FORCES ON -&END FORCES -&STRESS_TENSOR ON -&END STRESS_TENSOR -&END PRINT -&END FORCE_EVAL + METHOD QS + STRESS_TENSOR ANALYTICAL + &DFT #FORCE_EVAL + BASIS_SET_FILE_NAME ./cp2k_basis_pp_file/BASIS_MOLOPT + POTENTIAL_FILE_NAME ./cp2k_basis_pp_file/GTH_POTENTIALS + CHARGE 0 + UKS F + MULTIPLICITY 1 + &MGRID #DFT #FORCE_EVAL + CUTOFF 400 + REL_CUTOFF 50 + NGRIDS 4 + &END MGRID #DFT #FORCE_EVAL + &QS #DFT #FORCE_EVAL + EPS_DEFAULT 1.0E-12 + &END QS #DFT #FORCE_EVAL + &SCF #DFT #FORCE_EVAL + SCF_GUESS ATOMIC + EPS_SCF 1.0E-6 + MAX_SCF 50 + &OT #SCF #DFT #FORCE_EVAL + MINIMIZER DIIS + PRECONDITIONER FULL_SINGLE_INVERSE + &END OT #SCF #DFT #FORCE_EVAL + &END SCF #DFT #FORCE_EVAL + &XC #DFT #FORCE_EVAL + &XC_FUNCTIONAL PBE + &END XC_FUNCTIONAL #XC #DFT #FORCE_EVAL + &END XC #DFT #FORCE_EVAL + &END DFT #FORCE_EVAL + &SUBSYS #FORCE_EVAL + &CELL #SUBSYS #FORCE_EVAL + &END CELL #SUBSYS #FORCE_EVAL + &COORD #SUBSYS #FORCE_EVAL + @include coord.xyz + &END COORD #SUBSYS #FORCE_EVAL + &KIND H + BASIS_SET DZVP-MOLOPT-GTH + POTENTIAL GTH-PBE-q1 + &END KIND #SUBSYS #FORCE_EVAL + &KIND C + BASIS_SET DZVP-MOLOPT-GTH + POTENTIAL GTH-PBE-q4 + &END KIND #SUBSYS #FORCE_EVAL + &KIND N + BASIS_SET DZVP-MOLOPT-GTH + POTENTIAL GTH-PBE-q5 + &END KIND #SUBSYS #FORCE_EVAL + &END SUBSYS #FORCE_EVAL + &PRINT #FORCE_EVAL + &FORCES ON + &END FORCES #PRINT #FORCE_EVAL + &STRESS_TENSOR ON + &END STRESS_TENSOR #PRINT #FORCE_EVAL + &END PRINT #FORCE_EVAL +&END FORCE_EVAL \ No newline at end of file From 1737bf606166577d29d3089ce6bc861d4ceef0e5 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 11 Mar 2024 23:23:45 -0400 Subject: [PATCH 26/34] docs: fix author name (#1480) Fix my name at https://docs.deepmodeling.com/projects/dpgen/en/latest/credits.html. An incorrect name, "Jinzh Zeng", was used in a commit. See https://git-scm.com/docs/gitmailmap for the principle. I didn't fix other people's names, but they can do the same thing as this PR. --- .mailmap | 1 + 1 file changed, 1 insertion(+) create mode 100644 .mailmap diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000..6e14badd6 --- /dev/null +++ b/.mailmap @@ -0,0 +1 @@ +Jinzhe Zeng From 7471da827e1917b8e21103d6afb76ead0531e45a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:12:48 -0400 Subject: [PATCH 27/34] [pre-commit.ci] pre-commit autoupdate (#1483) --- .pre-commit-config.yaml | 2 +- dpgen/auto_test/lib/mfp_eosfit.py | 15 +---- dpgen/auto_test/lib/pwscf.py | 7 +-- dpgen/auto_test/reproduce.py | 7 +-- dpgen/data/tools/ovito_file_convert.py | 1 + dpgen/generator/lib/abacus_scf.py | 6 +- dpgen/generator/lib/lammps.py | 6 +- dpgen/generator/lib/pwscf.py | 7 +-- dpgen/generator/run.py | 83 ++++++++++---------------- dpgen/gui.py | 1 + dpgen/simplify/simplify.py | 12 ++-- tests/test_check_examples.py | 1 + tests/test_collect.py | 6 +- 13 files changed, 54 insertions(+), 100 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37ff00ae1..e1a247bca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.3.2 hooks: - id: ruff args: ["--fix"] diff --git a/dpgen/auto_test/lib/mfp_eosfit.py b/dpgen/auto_test/lib/mfp_eosfit.py index c28b5651f..227012844 100755 --- a/dpgen/auto_test/lib/mfp_eosfit.py +++ b/dpgen/auto_test/lib/mfp_eosfit.py @@ -1441,16 +1441,7 @@ def ext_velp( ) for i in range(ndata): fw.write( - "{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\n".format( - vv[i], - ee[i], - cellaa[i], - cellbb[i], - cellcc[i], - cellbaba[i], - cellcaca[i], - cellca_cal[i], - ) + f"{vv[i]:12.6f}\t{ee[i]:12.6f}\t{cellaa[i]:12.6f}\t{cellbb[i]:12.6f}\t{cellcc[i]:12.6f}\t{cellbaba[i]:12.6f}\t{cellcaca[i]:12.6f}\t{cellca_cal[i]:12.6f}\n" ) fw.flush() fw.close() @@ -1662,9 +1653,7 @@ def lsqfit_eos( ) for i in range(len(vol)): fve.write( - "{:20f}\t{:20f}\t{:20f}\t{:20f}\n".format( - vol[i], repro_en[i], en[i], 100 * np.abs((en[i] - repro_en[i]) / en[i]) - ) + f"{vol[i]:20f}\t{repro_en[i]:20f}\t{en[i]:20f}\t{100 * np.abs((en[i] - repro_en[i]) / en[i]):20f}\n" ) fve.flush() p_tmp = repro_press[i] diff --git a/dpgen/auto_test/lib/pwscf.py b/dpgen/auto_test/lib/pwscf.py index eb3efddcd..e53384003 100644 --- a/dpgen/auto_test/lib/pwscf.py +++ b/dpgen/auto_test/lib/pwscf.py @@ -72,12 +72,7 @@ def _make_pwscf_03_config(sys_data): cc = 0 for ii in range(ntypes): for jj in range(atom_numbs[ii]): - ret += "{} {:f} {:f} {:f}\n".format( - atom_names[ii], - coordinates[cc][0], - coordinates[cc][1], - coordinates[cc][2], - ) + ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n" cc += 1 return ret diff --git a/dpgen/auto_test/reproduce.py b/dpgen/auto_test/reproduce.py index ada3102fb..47c266d61 100644 --- a/dpgen/auto_test/reproduce.py +++ b/dpgen/auto_test/reproduce.py @@ -153,12 +153,7 @@ def post_repro( output_ener_tot.extend(output_task_result["energies"]) init_epa = init_ener[jj - idid] / natoms - ptr_data += "{} {:7.3f} {:7.3f} {:7.3f}\n".format( - ii, - init_epa, - output_epa, - output_epa - init_epa, - ) + ptr_data += f"{ii} {init_epa:7.3f} {output_epa:7.3f} {output_epa - init_epa:7.3f}\n" idid += nframe output_ener = np.array(output_ener) output_ener = np.reshape(output_ener, [-1, 1]) diff --git a/dpgen/data/tools/ovito_file_convert.py b/dpgen/data/tools/ovito_file_convert.py index 252b70b22..b22f7e44d 100755 --- a/dpgen/data/tools/ovito_file_convert.py +++ b/dpgen/data/tools/ovito_file_convert.py @@ -2,6 +2,7 @@ """This Script is adapted from Alexander Stukowski, the author of OVITO. See: http://forum.ovito.org/index.php?topic=131.0 for details. """ + import argparse from ovito.io import export_file, import_file diff --git a/dpgen/generator/lib/abacus_scf.py b/dpgen/generator/lib/abacus_scf.py index 561d84500..744147e88 100644 --- a/dpgen/generator/lib/abacus_scf.py +++ b/dpgen/generator/lib/abacus_scf.py @@ -401,9 +401,9 @@ def get_abacus_STRU(STRU, INPUT=None, n_ele=None): data["atom_types"] = types data["cells"] = cell data["coords"] = coords - data[ - "atom_masses" - ] = masses # Notice that this key is not defined in dpdata system. + data["atom_masses"] = ( + masses # Notice that this key is not defined in dpdata system. + ) data["pp_files"] = pp_files data["orb_files"] = orb_files data["dpks_descriptor"] = dpks_descriptor diff --git a/dpgen/generator/lib/lammps.py b/dpgen/generator/lib/lammps.py index d9ff4a493..d96415a3f 100644 --- a/dpgen/generator/lib/lammps.py +++ b/dpgen/generator/lib/lammps.py @@ -169,11 +169,7 @@ def make_lammps_input( pka_vec = _sample_sphere() pka_vec *= pka_vn ret += "group first id 1\n" - ret += 'if "${{restart}} == 0" then "velocity first set {:f} {:f} {:f}"\n'.format( - pka_vec[0], - pka_vec[1], - pka_vec[2], - ) + ret += f'if "${{restart}} == 0" then "velocity first set {pka_vec[0]:f} {pka_vec[1]:f} {pka_vec[2]:f}"\n' ret += "fix 2 all momentum 1 linear 1 1 1\n" ret += "\n" if ensemble.split("-")[0] == "npt": diff --git a/dpgen/generator/lib/pwscf.py b/dpgen/generator/lib/pwscf.py index 3e1ac5e00..ebd8a2dc0 100644 --- a/dpgen/generator/lib/pwscf.py +++ b/dpgen/generator/lib/pwscf.py @@ -110,12 +110,7 @@ def _make_pwscf_03_config(sys_data): cc = 0 for ii in range(ntypes): for jj in range(atom_numbs[ii]): - ret += "{} {:f} {:f} {:f}\n".format( - atom_names[ii], - coordinates[cc][0], - coordinates[cc][1], - coordinates[cc][2], - ) + ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n" cc += 1 return ret diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index d0157145f..6d9f1c4e4 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -591,21 +591,21 @@ def make_train(iter_index, jdata, mdata): if ( len(np.array(model_devi_activation_func).shape) == 2 ): # 2-dim list for emd/fitting net-resolved assignment of actF - jinput["model"]["descriptor"][ - "activation_function" - ] = model_devi_activation_func[ii][0] - jinput["model"]["fitting_net"][ - "activation_function" - ] = model_devi_activation_func[ii][1] + jinput["model"]["descriptor"]["activation_function"] = ( + model_devi_activation_func[ii][0] + ) + jinput["model"]["fitting_net"]["activation_function"] = ( + model_devi_activation_func[ii][1] + ) if ( len(np.array(model_devi_activation_func).shape) == 1 ): # for backward compatibility, 1-dim list, not net-resolved - jinput["model"]["descriptor"][ - "activation_function" - ] = model_devi_activation_func[ii] - jinput["model"]["fitting_net"][ - "activation_function" - ] = model_devi_activation_func[ii] + jinput["model"]["descriptor"]["activation_function"] = ( + model_devi_activation_func[ii] + ) + jinput["model"]["fitting_net"]["activation_function"] = ( + model_devi_activation_func[ii] + ) # dump the input.json with open(os.path.join(task_path, train_input_file), "w") as outfile: json.dump(jinput, outfile, indent=4) @@ -1042,9 +1042,9 @@ def revise_lmp_input_dump(lmp_lines, trj_freq, model_devi_merge_traj=False): def revise_lmp_input_plm(lmp_lines, in_plm, out_plm="output.plumed"): idx = find_only_one_key(lmp_lines, ["fix", "dpgen_plm"]) - lmp_lines[ - idx - ] = f"fix dpgen_plm all plumed plumedfile {in_plm} outfile {out_plm}\n" + lmp_lines[idx] = ( + f"fix dpgen_plm all plumed plumedfile {in_plm} outfile {out_plm}\n" + ) return lmp_lines @@ -1815,9 +1815,10 @@ def _make_model_devi_amber( nsteps = jdata["nsteps"] for ii, pp in enumerate(mdin): - with open(pp) as f, open( - os.path.join(work_path, "init%d.mdin" % ii), "w" - ) as fw: + with ( + open(pp) as f, + open(os.path.join(work_path, "init%d.mdin" % ii), "w") as fw, + ): mdin_str = f.read() # freq, nstlim, qm_region, qm_theory, qm_charge, rcut, graph mdin_str = ( @@ -1883,9 +1884,10 @@ def _make_model_devi_amber( if not isinstance(r, Iterable) or isinstance(r, str): r = [r] # disang file should include RVAL, RVAL2, ... - with open(disang[sys_idx[sys_counter]]) as f, open( - "TEMPLATE.disang", "w" - ) as fw: + with ( + open(disang[sys_idx[sys_counter]]) as f, + open("TEMPLATE.disang", "w") as fw, + ): tl = f.read() for ii, rr in enumerate(r): if isinstance(rr, Iterable) and not isinstance(rr, str): @@ -1999,14 +2001,7 @@ def run_md_model_devi(iter_index, jdata, mdata): if ndx_filename: command += f'&& echo -e "{grp_name}\\n{grp_name}\\n" | {model_devi_exec} trjconv -s {ref_filename} -f {deffnm}.trr -n {ndx_filename} -o {traj_filename} -pbc mol -ur compact -center' else: - command += '&& echo -e "{}\\n{}\\n" | {} trjconv -s {} -f {}.trr -o {} -pbc mol -ur compact -center'.format( - grp_name, - grp_name, - model_devi_exec, - ref_filename, - deffnm, - traj_filename, - ) + command += f'&& echo -e "{grp_name}\\n{grp_name}\\n" | {model_devi_exec} trjconv -s {ref_filename} -f {deffnm}.trr -o {traj_filename} -pbc mol -ur compact -center' command += "&& if [ ! -d traj ]; then \n mkdir traj; fi\n" command += f"python -c \"import dpdata;system = dpdata.System('{traj_filename}', fmt='gromacs/gro'); [system.to_gromacs_gro('traj/%d.gromacstrj' % (i * {trj_freq}), frame_idx=i) for i in range(system.get_nframes())]; system.to_deepmd_npy('traj_deepmd')\"" command += f"&& dp model-devi -m ../graph.000.pb ../graph.001.pb ../graph.002.pb ../graph.003.pb -s traj_deepmd -o model_devi.out -f {trj_freq}" @@ -2508,9 +2503,7 @@ def _make_fp_vasp_inner( tot = len(summaryfmax) - nan_num candi_num = tot - acc_num - fail_num dlog.info( - "summary accurate_ratio: {:8.4f}% candidata_ratio: {:8.4f}% failed_ratio: {:8.4f}% in {:d} structures".format( - acc_num * 100 / tot, candi_num * 100 / tot, fail_num * 100 / tot, tot - ) + f"summary accurate_ratio: {acc_num * 100 / tot:8.4f}% candidata_ratio: {candi_num * 100 / tot:8.4f}% failed_ratio: {fail_num * 100 / tot:8.4f}% in {tot:d} structures" ) # -------------------------------------------------------------------------------------------------------------------------------------- @@ -2662,9 +2655,7 @@ def _trust_limitation_check(sys_idx, lim): continue for cc_key, cc_value in counter.items(): dlog.info( - "system {:s} {:9s} : {:6d} in {:6d} {:6.2f} %".format( - ss, cc_key, cc_value, fp_sum, cc_value / fp_sum * 100 - ) + f"system {ss:s} {cc_key:9s} : {cc_value:6d} in {fp_sum:6d} {cc_value / fp_sum * 100:6.2f} %" ) random.shuffle(fp_candidate) if detailed_report_make_fp: @@ -2738,15 +2729,7 @@ def _trust_limitation_check(sys_idx, lim): numb_task = 0 # ---------------------------------------------------------------------------- dlog.info( - "system {:s} accurate_ratio: {:8.4f} thresholds: {:6.4f} and {:6.4f} eff. task min and max {:4d} {:4d} number of fp tasks: {:6d}".format( - ss, - accurate_ratio, - fp_accurate_soft_threshold, - fp_accurate_threshold, - fp_task_min, - this_fp_task_max, - numb_task, - ) + f"system {ss:s} accurate_ratio: {accurate_ratio:8.4f} thresholds: {fp_accurate_soft_threshold:6.4f} and {fp_accurate_threshold:6.4f} eff. task min and max {fp_task_min:4d} {this_fp_task_max:4d} number of fp tasks: {numb_task:6d}" ) # make fp tasks @@ -2878,21 +2861,15 @@ def _trust_limitation_check(sys_idx, lim): os.chdir(cwd) if count_bad_box > 0: dlog.info( - "system {:s} skipped {:6d} confs with bad box, {:6d} remains".format( - ss, count_bad_box, numb_task - count_bad_box - ) + f"system {ss:s} skipped {count_bad_box:6d} confs with bad box, {numb_task - count_bad_box:6d} remains" ) if count_bad_cluster > 0: dlog.info( - "system {:s} skipped {:6d} confs with bad cluster, {:6d} remains".format( - ss, count_bad_cluster, numb_task - count_bad_cluster - ) + f"system {ss:s} skipped {count_bad_cluster:6d} confs with bad cluster, {numb_task - count_bad_cluster:6d} remains" ) if model_devi_engine == "calypso": dlog.info( - "summary accurate_ratio: {:8.4f}% candidata_ratio: {:8.4f}% failed_ratio: {:8.4f}% in {:d} structures".format( - acc_num * 100 / tot, candi_num * 100 / tot, fail_num * 100 / tot, tot - ) + f"summary accurate_ratio: {acc_num * 100 / tot:8.4f}% candidata_ratio: {candi_num * 100 / tot:8.4f}% failed_ratio: {fail_num * 100 / tot:8.4f}% in {tot:d} structures" ) if cluster_cutoff is None: cwd = os.getcwd() diff --git a/dpgen/gui.py b/dpgen/gui.py index f116ee246..4f92d43ec 100644 --- a/dpgen/gui.py +++ b/dpgen/gui.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """DP-GUI entrypoint.""" + import argparse diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index a69ffe12e..eec08e8bf 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -8,6 +8,7 @@ 01: calculate model deviations of the rest dataset, pick up data with proper model deviaiton 02: fp (optional, if the original dataset do not have fp data, same as generator) """ + import glob import logging import os @@ -336,9 +337,10 @@ def post_model_devi(iter_index, jdata, mdata): "reach a place that should NOT be reached..." ) else: - with open(os.path.join(work_path, detail_file_name)) as f, open( - os.path.join(work_path, true_error_file_name) - ) as f_err: + with ( + open(os.path.join(work_path, detail_file_name)) as f, + open(os.path.join(work_path, true_error_file_name)) as f_err, + ): for line, line_err in zip(f, f_err): if line.startswith("# data.rest.old"): name = (line.split()[1]).split("/")[-1] @@ -389,9 +391,7 @@ def post_model_devi(iter_index, jdata, mdata): fp_sum = sum(counter.values()) for cc_key, cc_value in counter.items(): dlog.info( - "{:9s} : {:6d} in {:6d} {:6.2f} %".format( - cc_key, cc_value, fp_sum, cc_value / fp_sum * 100 - ) + f"{cc_key:9s} : {cc_value:6d} in {fp_sum:6d} {cc_value / fp_sum * 100:6.2f} %" ) if counter["candidate"] == 0 and counter["failed"] > 0: diff --git a/tests/test_check_examples.py b/tests/test_check_examples.py index cbbae79b6..3033740f2 100644 --- a/tests/test_check_examples.py +++ b/tests/test_check_examples.py @@ -1,6 +1,7 @@ """This module ensures input in the examples directory could pass the argument checking. """ + import json import unittest from pathlib import Path diff --git a/tests/test_collect.py b/tests/test_collect.py index 434f2c0ea..99979697d 100644 --- a/tests/test_collect.py +++ b/tests/test_collect.py @@ -15,7 +15,11 @@ def setUp(self): ) def test_collect_data(self): - with tempfile.TemporaryDirectory() as inpdir, tempfile.TemporaryDirectory() as outdir, tempfile.NamedTemporaryFile() as param_file: + with ( + tempfile.TemporaryDirectory() as inpdir, + tempfile.TemporaryDirectory() as outdir, + tempfile.NamedTemporaryFile() as param_file, + ): self.data.to_deepmd_npy(Path(inpdir) / "iter.000000" / "02.fp" / "data.000") self.data.to_deepmd_npy( Path(inpdir) / "iter.000001" / "02.fp" / "data.000" / "aa" From 9185b546405340f4a746d076bca688f8068417da Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sat, 16 Mar 2024 21:12:31 -0400 Subject: [PATCH 28/34] docs: add the link for how to setup the conda environment (#1484) Signed-off-by: Jinzhe Zeng --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb5ef39bc..b75939c2e 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ Yuzhi Zhang, Haidi Wang, Weijie Chen, Jinzhe Zeng, Linfeng Zhang, Han Wang, and ## Download and Install -DP-GEN only supports Python 3.9 and above. You can use one of the following methods to install DP-GEN: +DP-GEN only supports Python 3.9 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install DP-GEN: - Install via pip: `pip install dpgen` -- Install via conda: `conda install -c conda-forge dpgen`` +- Install via conda: `conda install -c conda-forge dpgen` - Install from source code: `git clone https://github.com/deepmodeling/dpgen && pip install ./dpgen` To test if the installation is successful, you may execute From 34db0234d960e9a780184904d1c3541bdc4ba205 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 23:10:30 -0400 Subject: [PATCH 29/34] [pre-commit.ci] pre-commit autoupdate (#1486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.2 → v0.3.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.2...v0.3.3) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e1a247bca..eb2ab6c04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.2 + rev: v0.3.3 hooks: - id: ruff args: ["--fix"] From 78288e63419267240cf14ed23fea9ae2985546d0 Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Sun, 24 Mar 2024 21:51:48 -0400 Subject: [PATCH 30/34] CI: Setup Dependabot for GitHub Actions (#1492) See https://github.com/njzjz-bot/njzjz-bot/issues/2. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: Jinzhe Zeng --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..5855aef6c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + target-branch: "devel" From 3e93f85004148d36e0909463a19dade5d68ddf1f Mon Sep 17 00:00:00 2001 From: "A bot of @njzjz" <48687836+njzjz-bot@users.noreply.github.com> Date: Sun, 24 Mar 2024 21:51:57 -0400 Subject: [PATCH 31/34] CI: Bump codecov/codecov-action from v3 to v4 (#1491) See https://github.com/njzjz-bot/njzjz-bot/issues/1. Co-authored-by: Jinzhe Zeng --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index acb7d8a4b..716008b30 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,9 @@ jobs: run: pip install -e .[test] - name: Test run: coverage run --source=./dpgen -m unittest -v && coverage report - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} pass: needs: [build] runs-on: ubuntu-latest From e381d17a7b9f9aaa4a882bf8e25bb2ad619a782f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 21:36:47 +0000 Subject: [PATCH 32/34] [pre-commit.ci] pre-commit autoupdate (#1495) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.3 → v0.3.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.3...v0.3.4) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb2ab6c04..60b576273 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.3 + rev: v0.3.4 hooks: - id: ruff args: ["--fix"] From bff4e0f4998c76bae0943fc39bdfa3d82d128179 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:34:22 +0800 Subject: [PATCH 33/34] [pre-commit.ci] pre-commit autoupdate (#1499) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.4 → v0.3.5](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.4...v0.3.5) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60b576273..d1f8d1449 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,7 +28,7 @@ repos: # Python - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.4 + rev: v0.3.5 hooks: - id: ruff args: ["--fix"] From 53668e67c626e43ee1ac11ab728b07a354a706ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 08:30:50 +0800 Subject: [PATCH 34/34] [pre-commit.ci] pre-commit autoupdate (#1504) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1f8d1449..c61a7fea0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: # there are many log files in tests # TODO: seperate py files and log files