From 7adbd6aafc0e392ee9c2bdbc05f21de19d634214 Mon Sep 17 00:00:00 2001 From: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com> Date: Thu, 5 Dec 2024 01:49:26 +0800 Subject: [PATCH 01/12] Fix: ignore UP031 (#1683) --- .pre-commit-config.yaml | 2 +- doc/conf.py | 2 +- dpgen/__init__.py | 6 +- dpgen/auto_test/EOS.py | 2 +- dpgen/auto_test/Elastic.py | 2 +- dpgen/auto_test/Gamma.py | 21 +++--- dpgen/auto_test/Interstitial.py | 25 ++++--- dpgen/auto_test/Surface.py | 8 +- dpgen/auto_test/VASP.py | 6 +- dpgen/auto_test/Vacancy.py | 2 +- dpgen/auto_test/common_prop.py | 6 +- dpgen/auto_test/lib/abacus.py | 2 +- dpgen/auto_test/lib/lammps.py | 22 +++--- dpgen/auto_test/lib/lmp.py | 8 +- dpgen/auto_test/lib/mfp_eosfit.py | 50 ++++++------- dpgen/auto_test/lib/pwscf.py | 10 +-- dpgen/auto_test/lib/siesta.py | 14 ++-- dpgen/auto_test/lib/utils.py | 2 +- dpgen/auto_test/lib/vasp.py | 32 ++++---- dpgen/auto_test/refine.py | 4 +- dpgen/auto_test/reproduce.py | 2 +- dpgen/collect/collect.py | 4 +- dpgen/data/gen.py | 36 ++++----- dpgen/data/reaction.py | 2 +- dpgen/data/surf.py | 14 ++-- dpgen/data/tools/bcc.py | 2 +- dpgen/data/tools/cessp2force_lin.py | 4 +- dpgen/data/tools/create_random_disturb.py | 6 +- dpgen/data/tools/diamond.py | 2 +- dpgen/data/tools/fcc.py | 2 +- dpgen/data/tools/hcp.py | 2 +- dpgen/data/tools/io_lammps.py | 8 +- dpgen/data/tools/sc.py | 2 +- dpgen/generator/lib/abacus_scf.py | 22 +++--- dpgen/generator/lib/calypso_check_outcar.py | 2 +- dpgen/generator/lib/calypso_run_model_devi.py | 8 +- dpgen/generator/lib/calypso_run_opt.py | 2 +- dpgen/generator/lib/gaussian.py | 6 +- dpgen/generator/lib/lammps.py | 16 ++-- dpgen/generator/lib/make_calypso.py | 18 ++--- dpgen/generator/lib/pwmat.py | 2 +- dpgen/generator/lib/pwscf.py | 12 +-- dpgen/generator/lib/run_calypso.py | 59 ++++++++------- dpgen/generator/lib/siesta.py | 14 ++-- dpgen/generator/lib/utils.py | 4 +- dpgen/generator/run.py | 72 +++++++++--------- dpgen/simplify/simplify.py | 8 +- dpgen/tools/collect_data.py | 4 +- dpgen/tools/relabel.py | 12 +-- dpgen/tools/stat_sys.py | 4 +- .../auto_test/data.vasp.kp.gf/make_kp_test.py | 2 +- tests/generator/comp_sys.py | 16 ++-- .../gromacs/model_devi_case/model_devi.py | 2 +- tests/generator/test_make_fp.py | 73 +++++++++++-------- tests/generator/test_make_md.py | 39 ++++++---- tests/generator/test_make_train.py | 36 +++++---- 56 files changed, 393 insertions(+), 352 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c344eafe..b52b0adb6 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.7.4 + rev: v0.8.1 hooks: - id: ruff args: ["--fix"] diff --git a/doc/conf.py b/doc/conf.py index 54e0f6389..3f82ac7c6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -19,7 +19,7 @@ # -- Project information ----------------------------------------------------- project = "DP-GEN" -copyright = "2020-%d, DeepModeling" % date.today().year +copyright = "2020-%d, DeepModeling" % date.today().year # noqa: UP031 author = "DeepModeling" diff --git a/dpgen/__init__.py b/dpgen/__init__.py index 6e6e10229..aac426e4a 100644 --- a/dpgen/__init__.py +++ b/dpgen/__init__.py @@ -48,11 +48,11 @@ def info(): ]: try: mm = __import__(modui) - print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0])) + print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0])) # noqa: UP031 except ImportError: - print("%10s %10s Not Found" % (modui, "")) + print("%10s %10s Not Found" % (modui, "")) # noqa: UP031 except AttributeError: - print("%10s %10s unknown version or path" % (modui, "")) + print("%10s %10s unknown version or path" % (modui, "")) # noqa: UP031 print() # reference diff --git a/dpgen/auto_test/EOS.py b/dpgen/auto_test/EOS.py index 3593b2f72..56d5b5a1b 100644 --- a/dpgen/auto_test/EOS.py +++ b/dpgen/auto_test/EOS.py @@ -198,7 +198,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): # vol = vol / 100.0 vol = self.vol_start + task_num * self.vol_step # task_num = int((vol - self.vol_start) / self.vol_step) - output_task = os.path.join(path_to_work, "task.%06d" % task_num) + output_task = os.path.join(path_to_work, "task.%06d" % task_num) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) if self.inter_param["type"] == "abacus": diff --git a/dpgen/auto_test/Elastic.py b/dpgen/auto_test/Elastic.py index 6a1f6f9df..85c500d03 100644 --- a/dpgen/auto_test/Elastic.py +++ b/dpgen/auto_test/Elastic.py @@ -162,7 +162,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): print("gen with norm " + str(norm_strains)) print("gen with shear " + str(shear_strains)) for ii in range(n_dfm): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ diff --git a/dpgen/auto_test/Gamma.py b/dpgen/auto_test/Gamma.py index 68bafe5e1..4ea93693e 100644 --- a/dpgen/auto_test/Gamma.py +++ b/dpgen/auto_test/Gamma.py @@ -223,7 +223,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.symlink(os.path.relpath(equi_contcar), POSCAR) # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(all_slabs)): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in ["INCAR", "POTCAR", POSCAR, "conf.lmp", "in.lammps"]: @@ -232,9 +232,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): task_list.append(output_task) # print("# %03d generate " % ii, output_task) print( - "# %03d generate " % ii, + "# %03d generate " % ii, # noqa: UP031 output_task, - " \t %d atoms" % self.atom_num, + " \t %d atoms" % self.atom_num, # noqa: UP031 ) # make confs all_slabs[ii].to("POSCAR.tmp", "POSCAR") @@ -472,12 +472,15 @@ def _compute_lower(self, output_file, all_tasks, all_res): ) miller_index = loadfn(os.path.join(ii, "miller.json")) - ptr_data += "%-25s %7.2f %7.3f %8.3f %8.3f\n" % ( - str(miller_index) + "-" + structure_dir + ":", - int(ii[-4:]) / self.n_steps, - sfe, - epa, - equi_epa_slab, + ptr_data += ( + "%-25s %7.2f %7.3f %8.3f %8.3f\n" # noqa: UP031 + % ( + str(miller_index) + "-" + structure_dir + ":", + int(ii[-4:]) / self.n_steps, + sfe, + epa, + equi_epa_slab, + ) ) res_data[int(ii[-4:]) / self.n_steps] = [sfe, epa, equi_epa] diff --git a/dpgen/auto_test/Interstitial.py b/dpgen/auto_test/Interstitial.py index a3658af11..a4b06ae1c 100644 --- a/dpgen/auto_test/Interstitial.py +++ b/dpgen/auto_test/Interstitial.py @@ -222,7 +222,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(dss)): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ @@ -262,7 +262,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): super_latt_param = float(pos_line[2].split()[0]) - output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss))) + output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss))) # noqa: UP031 os.makedirs(output_task1, exist_ok=True) os.chdir(output_task1) task_list.append(output_task1) @@ -283,7 +283,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.chdir(cwd) output_task2 = os.path.join( - path_to_work, "task.%06d" % (len(dss) + 1) + path_to_work, + "task.%06d" % (len(dss) + 1), # noqa: UP031 ) os.makedirs(output_task2, exist_ok=True) os.chdir(output_task2) @@ -305,7 +306,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.chdir(cwd) output_task3 = os.path.join( - path_to_work, "task.%06d" % (len(dss) + 2) + path_to_work, + "task.%06d" % (len(dss) + 2), # noqa: UP031 ) os.makedirs(output_task3, exist_ok=True) os.chdir(output_task3) @@ -346,7 +348,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): replace_label = idx output_task4 = os.path.join( - path_to_work, "task.%06d" % (len(dss) + 3) + path_to_work, + "task.%06d" % (len(dss) + 3), # noqa: UP031 ) os.makedirs(output_task4, exist_ok=True) os.chdir(output_task4) @@ -380,7 +383,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.chdir(cwd) output_task5 = os.path.join( - path_to_work, "task.%06d" % (len(dss) + 4) + path_to_work, + "task.%06d" % (len(dss) + 4), # noqa: UP031 ) os.makedirs(output_task5, exist_ok=True) os.chdir(output_task5) @@ -414,7 +418,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.chdir(cwd) output_task6 = os.path.join( - path_to_work, "task.%06d" % (len(dss) + 5) + path_to_work, + "task.%06d" % (len(dss) + 5), # noqa: UP031 ) os.makedirs(output_task6, exist_ok=True) os.chdir(output_task6) @@ -453,7 +458,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): if self.inter_param["type"] == "abacus": for ii in range(total_task): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.chdir(output_task) abacus.poscar2stru("POSCAR", self.inter_param, "STRU") os.remove("POSCAR") @@ -478,8 +483,8 @@ def post_process(self, task_list): type_num = type_map[insert_ele] + 1 conf_line[2] = str(len(type_map_list)) + " atom types" conf_line[-2] = ( - "%6.d" % int(insert_line.split()[0]) - + "%7.d" % type_num + "%6.d" % int(insert_line.split()[0]) # noqa: UP031 + + "%7.d" % type_num # noqa: UP031 + f"{float(insert_line.split()[2]):16.10f}" + f"{float(insert_line.split()[3]):16.10f}" + f"{float(insert_line.split()[4]):16.10f}" diff --git a/dpgen/auto_test/Surface.py b/dpgen/auto_test/Surface.py index 85108036d..6bf7dd0f3 100644 --- a/dpgen/auto_test/Surface.py +++ b/dpgen/auto_test/Surface.py @@ -198,7 +198,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.symlink(os.path.relpath(equi_contcar), POSCAR) # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(all_slabs)): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ @@ -213,9 +213,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): os.remove(jj) task_list.append(output_task) print( - "# %03d generate " % ii, + "# %03d generate " % ii, # noqa: UP031 output_task, - " \t %d atoms" % len(all_slabs[ii].sites), + " \t %d atoms" % len(all_slabs[ii].sites), # noqa: UP031 ) # make confs all_slabs[ii].to("POSCAR.tmp", "POSCAR") @@ -270,7 +270,7 @@ def _compute_lower(self, output_file, all_tasks, all_res): evac = (task_result["energies"][-1] - equi_epa * natoms) / AA * Cf miller_index = loadfn(os.path.join(ii, "miller.json")) - ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % ( + ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % ( # noqa: UP031 str(miller_index) + "-" + structure_dir + ":", evac, epa, diff --git a/dpgen/auto_test/VASP.py b/dpgen/auto_test/VASP.py index 2c2171f8c..72376da4b 100644 --- a/dpgen/auto_test/VASP.py +++ b/dpgen/auto_test/VASP.py @@ -112,7 +112,7 @@ def make_input_file(self, output_dir, task_type, task_param): isif = 2 if not ("NSW" in incar and incar.get("NSW") == nsw): dlog.info( - "%s setting NSW to %d" + "%s setting NSW to %d" # noqa: UP031 % (self.make_input_file.__name__, nsw) ) incar["NSW"] = nsw @@ -121,7 +121,7 @@ def make_input_file(self, output_dir, task_type, task_param): if not ("ISIF" in incar and incar.get("ISIF") == isif): dlog.info( - "%s setting ISIF to %d" % (self.make_input_file.__name__, isif) + "%s setting ISIF to %d" % (self.make_input_file.__name__, isif) # noqa: UP031 ) incar["ISIF"] = isif @@ -129,7 +129,7 @@ def make_input_file(self, output_dir, task_type, task_param): nsw = 0 if not ("NSW" in incar and incar.get("NSW") == nsw): dlog.info( - "%s setting NSW to %d" % (self.make_input_file.__name__, nsw) + "%s setting NSW to %d" % (self.make_input_file.__name__, nsw) # noqa: UP031 ) incar["NSW"] = nsw diff --git a/dpgen/auto_test/Vacancy.py b/dpgen/auto_test/Vacancy.py index ef120ca13..af2a3a6aa 100644 --- a/dpgen/auto_test/Vacancy.py +++ b/dpgen/auto_test/Vacancy.py @@ -187,7 +187,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False): # task_poscar = os.path.join(output, 'POSCAR') for ii in range(len(dss)): - output_task = os.path.join(path_to_work, "task.%06d" % ii) + output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ diff --git a/dpgen/auto_test/common_prop.py b/dpgen/auto_test/common_prop.py index 2af2e566b..fd60b2bcf 100644 --- a/dpgen/auto_test/common_prop.py +++ b/dpgen/auto_test/common_prop.py @@ -102,7 +102,7 @@ def run_property(confs, inter_param, property_list, mdata): # conf_dirs.sort() processes = len(property_list) pool = Pool(processes=processes) - print("Submit job via %d processes" % processes) + print("Submit job via %d processes" % processes) # noqa: UP031 conf_dirs = [] for conf in confs: conf_dirs.extend(glob.glob(conf)) @@ -181,8 +181,8 @@ def run_property(confs, inter_param, property_list, mdata): for ii in range(len(multiple_ret)): if not multiple_ret[ii].successful(): print("ERROR:", multiple_ret[ii].get()) - raise RuntimeError("Job %d is not successful!" % ii) - print("%d jobs are finished" % len(multiple_ret)) + raise RuntimeError("Job %d is not successful!" % ii) # noqa: UP031 + print("%d jobs are finished" % len(multiple_ret)) # noqa: UP031 def worker( diff --git a/dpgen/auto_test/lib/abacus.py b/dpgen/auto_test/lib/abacus.py index ba2b6fa32..afdbda556 100644 --- a/dpgen/auto_test/lib/abacus.py +++ b/dpgen/auto_test/lib/abacus.py @@ -333,7 +333,7 @@ def final_stru(abacus_path): if lines[-i][1:27] == "STEP OF MOLECULAR DYNAMICS": max_step = int(lines[-i].split()[-1]) break - return "OUT.%s/STRU_MD_%d" % (suffix, max_step) + return "OUT.%s/STRU_MD_%d" % (suffix, max_step) # noqa: UP031 elif calculation == "scf": return "STRU" else: diff --git a/dpgen/auto_test/lib/lammps.py b/dpgen/auto_test/lib/lammps.py index 2813da357..26c95bcca 100644 --- a/dpgen/auto_test/lib/lammps.py +++ b/dpgen/auto_test/lib/lammps.py @@ -181,7 +181,7 @@ def make_lammps_eval(conf, type_map, interaction, param): ret += "box tilt large\n" ret += f"read_data {conf}\n" for ii in range(len(type_map)): - ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) + ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031 ret += "neigh_modify every 1 delay 0 check no\n" ret += interaction(param) ret += "compute mype all pe\n" @@ -239,7 +239,7 @@ def make_lammps_equi( ret += "box tilt large\n" ret += f"read_data {conf}\n" for ii in range(len(type_map)): - ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) + ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031 ret += "neigh_modify every 1 delay 0 check no\n" ret += interaction(param) ret += "compute mype all pe\n" @@ -251,11 +251,11 @@ def make_lammps_equi( ret += "min_style cg\n" if change_box: ret += "fix 1 all box/relax iso 0.0 \n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "fix 1 all box/relax aniso 0.0 \n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "fix 1 all box/relax tri 0.0 \n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "variable N equal count(all)\n" ret += "variable V equal vol\n" ret += 'variable E equal "c_mype"\n' @@ -296,7 +296,7 @@ def make_lammps_elastic( ret += "box tilt large\n" ret += f"read_data {conf}\n" for ii in range(len(type_map)): - ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) + ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031 ret += "neigh_modify every 1 delay 0 check no\n" ret += interaction(param) ret += "compute mype all pe\n" @@ -306,7 +306,7 @@ def make_lammps_elastic( ) ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" ret += "min_style cg\n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "variable N equal count(all)\n" ret += "variable V equal vol\n" ret += 'variable E equal "c_mype"\n' @@ -361,7 +361,7 @@ def make_lammps_press_relax( ret += "box tilt large\n" ret += f"read_data {conf}\n" for ii in range(len(type_map)): - ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) + ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031 ret += "neigh_modify every 1 delay 0 check no\n" ret += interaction(param) ret += "compute mype all pe\n" @@ -372,9 +372,9 @@ def make_lammps_press_relax( ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n" ret += "min_style cg\n" ret += "fix 1 all box/relax iso ${Px} \n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "fix 1 all box/relax aniso ${Px} \n" - ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) + ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031 ret += "variable N equal count(all)\n" ret += "variable V equal vol\n" ret += 'variable E equal "c_mype"\n' @@ -409,7 +409,7 @@ def make_lammps_phonon( ret += f"read_data {conf}\n" ntypes = len(masses) for ii in range(ntypes): - ret += "mass %d %f\n" % (ii + 1, masses[ii]) + ret += "mass %d %f\n" % (ii + 1, masses[ii]) # noqa: UP031 ret += "neigh_modify every 1 delay 0 check no\n" ret += interaction(param) return ret diff --git a/dpgen/auto_test/lib/lmp.py b/dpgen/auto_test/lib/lmp.py index 11ade094e..abee4fef4 100644 --- a/dpgen/auto_test/lib/lmp.py +++ b/dpgen/auto_test/lib/lmp.py @@ -145,7 +145,7 @@ def system_data(lines): system["atom_numbs"] = get_natoms_vec(lines) system["atom_names"] = [] for ii in range(len(system["atom_numbs"])): - system["atom_names"].append("Type_%d" % ii) + system["atom_names"].append("Type_%d" % ii) # noqa: UP031 lohi, tilt = get_lmpbox(lines) orig, cell = lmpbox2box(lohi, tilt) system["orig"] = np.array(orig) @@ -165,8 +165,8 @@ def from_system_data(system): ret += "\n" natoms = sum(system["atom_numbs"]) ntypes = len(system["atom_numbs"]) - ret += "%d atoms\n" % natoms - ret += "%d atom types\n" % ntypes + ret += "%d atoms\n" % natoms # noqa: UP031 + ret += "%d atom types\n" % ntypes # noqa: UP031 ret += "0 {:f} xlo xhi\n".format(system["cell"][0][0]) ret += "0 {:f} ylo yhi\n".format(system["cell"][1][1]) ret += "0 {:f} zlo zhi\n".format(system["cell"][2][2]) @@ -179,7 +179,7 @@ def from_system_data(system): ret += "Atoms # atomic\n" ret += "\n" for ii in range(natoms): - ret += "%d %d %f %f %f\n" % ( + ret += "%d %d %f %f %f\n" % ( # noqa: UP031 ii + 1, system["atom_types"][ii], system["coordinates"][ii][0] - system["orig"][0], diff --git a/dpgen/auto_test/lib/mfp_eosfit.py b/dpgen/auto_test/lib/mfp_eosfit.py index 12adc9e65..0b33e2c35 100755 --- a/dpgen/auto_test/lib/mfp_eosfit.py +++ b/dpgen/auto_test/lib/mfp_eosfit.py @@ -1111,7 +1111,7 @@ def read_vlp(fin, fstart, fend): os.sys.exit(-1) lines = open(fin).readlines() nline = len(lines) - print("\n** Totally, there are %d data points reading..." % nline) + print("\n** Totally, there are %d data points reading..." % nline) # noqa: UP031 vol = [] cella = [] cellb = [] @@ -1157,13 +1157,13 @@ def read_vlp(fin, fstart, fend): fend = tmp if fend > nline: print( - "\n** EoSfit fit range exceed available data numbers, Reset it to be %d now." + "\n** EoSfit fit range exceed available data numbers, Reset it to be %d now." # noqa: UP031 % nline ) fend = nline if fstart > nline: print( - "EoSfit fit range exceed available data numbers, Reset it to be 1: %d now." + "EoSfit fit range exceed available data numbers, Reset it to be 1: %d now." # noqa: UP031 % nline ) fstart = 1 @@ -1196,7 +1196,7 @@ def read_velp(fin, fstart, fend): os.sys.exit(-1) lines = open(fin).readlines() nline = len(lines) - print("\n** Totally, there are %d data points reading..." % nline) + print("\n** Totally, there are %d data points reading..." % nline) # noqa: UP031 vol = [] eng = [] cella = [] @@ -1237,13 +1237,13 @@ def read_velp(fin, fstart, fend): fend = tmp if fend > nline: print( - "\n** EoSfit fit range exceed available data numbers, Reset it to be %d now." + "\n** EoSfit fit range exceed available data numbers, Reset it to be %d now." # noqa: UP031 % nline ) fend = -1 if fstart > nline: print( - "EoSfit fit range exceed available data numbers, Reset it to be 1: %d now." + "EoSfit fit range exceed available data numbers, Reset it to be 1: %d now." # noqa: UP031 % nline ) fstart = 1 @@ -1319,14 +1319,14 @@ def ext_vec( sca = ext_splint(vol, cellca) # define extrapolate range - print("\n** Vext_start = %f, Vext_end = %f, N_ext = %d" % (vols, vole, ndata)) + print("\n** Vext_start = %f, Vext_end = %f, N_ext = %d" % (vols, vole, ndata)) # noqa: UP031 vol_ext = np.linspace(vols, vole, ndata) en_ext = eval(func)(vol_ext, pars) # en_ext = np.zeros(ndata) fout = "ext_ve_" + func + ".dat" fw = open(fout, "w+") - fw.write("%d\n" % ndata) + fw.write("%d\n" % ndata) # noqa: UP031 for i in range(ndata): vx = vol_ext[i] ex = en_ext[i] @@ -1389,7 +1389,7 @@ def ext_velp( vol, eng, cella, cellb, cellc, cellba, cellca = read_velp(fin, fstart, fend) # define extrapolate range - print("\n** Vext_start = %f, Vext_end = %f, N_ext = %d" % (vols, vole, ndata)) + print("\n** Vext_start = %f, Vext_end = %f, N_ext = %d" % (vols, vole, ndata)) # noqa: UP031 vv = np.linspace(vols, vole, ndata) # spline order = 3 by default @@ -1436,7 +1436,7 @@ def ext_velp( # get vba.dat fw = open(fout, "w+") fw.write( - "#%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s\n" + "#%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s\n" # noqa: UP031 % ("volume", "eng", "cella", "cellb", "cellc", "b/a", "c/a", "cext/aext") ) for i in range(ndata): @@ -1504,15 +1504,15 @@ def lsqfit_eos( if fe > ndata: fe = ndata print( - "\n[WARNING]: f_end exceed available data numbers, Reset it to be %d now." + "\n[WARNING]: f_end exceed available data numbers, Reset it to be %d now." # noqa: UP031 % ndata ) if fs > ndata: print( - "\n[WARNING]: f_start exceed available data numbers, Reset it to be 1: %d now." + "\n[WARNING]: f_start exceed available data numbers, Reset it to be 1: %d now." # noqa: UP031 % ndata ) - print("and Reset f_end to be %d now." % ndata) + print("and Reset f_end to be %d now." % ndata) # noqa: UP031 fs = 1 fe = ndata @@ -1524,7 +1524,7 @@ def lsqfit_eos( vol = vol[fs - 1 : fe] en = en[fs - 1 : fe] - print("\n%d/%d data was used in the fitting ...\n" % (num, ndata)) + print("\n%d/%d data was used in the fitting ...\n" % (num, ndata)) # noqa: UP031 # ************************************************************************* # fit it: step 1. @@ -1550,27 +1550,27 @@ def lsqfit_eos( # ************************************************************************* print("*" * 80) - print(">> fitted parameters (with %d iterations):" % nfev) + print(">> fitted parameters (with %d iterations):" % nfev) # noqa: UP031 # p0 = [e0, b0, bp, v0, bpp] if func == "morse_AB": e0, A, B, v0 = popt - print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "A", "B", "E0(eV)")) + print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "A", "B", "E0(eV)")) # noqa: UP031 print(f"{v0:12f}\t{A:12f}\t{B:12f}\t{e0:12f}\n") elif func == "morse_3p": e0, A, v0 = popt B = 0.5 * A - print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "A", "B", "E0(eV)")) + print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "A", "B", "E0(eV)")) # noqa: UP031 print(f"{v0:12f}\t{A:12f}\t{B:12f}\t{e0:12f}\n") elif func in ["mie", "mie_simple"]: e0, m, n, v0 = popt - print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "m", "n", "E0(eV)")) + print("%12s\t%12s\t%12s\t%12s" % ("V0(A**3)", "m", "n", "E0(eV)")) # noqa: UP031 print(f"{v0:12f}\t{m:12f}\t{n:12f}\t{e0:12f}\n") elif func == "morse_6p": e0, b0, bp, v0, bpp, m, n = calc_props_morse_6p(popt) b0 = eV2GPa * b0 bpp = bpp / eV2GPa print( - "%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s" + "%12s\t%12s\t%12s\t%12s\t%12s\t%12s\t%12s" # noqa: UP031 % ("V0(A**3)", "B0(GPa)", "Bp", "E0(eV)", "Bpp(1/GPa)", "m", "n") ) print(f"{v0:12f}\t{b0:12f}\t{bp:12f}\t{e0:12f}\t{bpp:12f}\t{m:12f}\t{n:12f}\n") @@ -1578,7 +1578,7 @@ def lsqfit_eos( e0, b0, bp, v0, n = calc_props_SJX_5p(popt) b0 = eV2GPa * b0 print( - "%12s\t%12s\t%12s\t%12s\t%12s" + "%12s\t%12s\t%12s\t%12s\t%12s" # noqa: UP031 % ("V0(A**3)", "B0(GPa)", "Bp", "E0(eV)", "n") ) print(f"{v0:12f}\t{b0:12f}\t{bp:12f}\t{e0:12f}\t{n:12f}\n") @@ -1588,7 +1588,7 @@ def lsqfit_eos( b0 = eV2GPa * b0 bpp = bpp / eV2GPa print( - "%12s\t%12s\t%12s\t%12s\t%12s" + "%12s\t%12s\t%12s\t%12s\t%12s" # noqa: UP031 % ("V0(A**3)", "B0(GPa)", "Bp", "E0(eV)", "Bpp(1/GPa)") ) print(f"{v0:12f}\t{b0:12f}\t{bp:12f}\t{e0:12f}\t{bpp:12f}\n") @@ -1597,7 +1597,7 @@ def lsqfit_eos( b0 = eV2GPa * b0 bpp = bpp / eV2GPa print( - "%12s\t%12s\t%12s\t%12s\t%12s" + "%12s\t%12s\t%12s\t%12s\t%12s" # noqa: UP031 % ("V0(A**3)", "B0(GPa)", "Bp", "E0(eV)", "Bpp(1/GPa)") ) print(f"{v0:12f}\t{b0:12f}\t{bp:12f}\t{e0:12f}\t{bpp:12f}\n") @@ -1644,11 +1644,11 @@ def lsqfit_eos( fve = open(func + "_ve_fit.dat", "w+") fvp = open(func + "_vp_fit.dat", "w+") fve.write( - "#%20s\t%20s\t%20s\t%20s\n" + "#%20s\t%20s\t%20s\t%20s\n" # noqa: UP031 % ("volume(A**3)", "energy(fit)", "energy(cal)", "dE(%)") ) fvp.write( - "#%20s\t%20s\t%20s\t%20s\n" + "#%20s\t%20s\t%20s\t%20s\n" # noqa: UP031 % ("volume(A**3)", "pressure(GPa)", "pressure(Mbar)", "pressure(kbar)") ) for i in range(len(vol)): @@ -1774,7 +1774,7 @@ def parse_argument(): print("ERROR, range setting must be a positive value!") exit(1) if ExtNum % 2 == 0: - print("[WARNING]: ndata = %d, reset it to be %d" % (ExtNum, ExtNum + 1)) + print("[WARNING]: ndata = %d, reset it to be %d" % (ExtNum, ExtNum + 1)) # noqa: UP031 ExtNum = ExtNum + 1 ext_velp(fin, fs, fe, ExtVS, ExtVE, ExtNum, order=EORDER, method="unispl") else: diff --git a/dpgen/auto_test/lib/pwscf.py b/dpgen/auto_test/lib/pwscf.py index 988510f46..9f4ec0bb9 100644 --- a/dpgen/auto_test/lib/pwscf.py +++ b/dpgen/auto_test/lib/pwscf.py @@ -20,8 +20,8 @@ def _make_pwscf_01_runctrl(sys_data, ecut, ediff, smearing, degauss): ret += "/\n" ret += "&system\n" ret += "ibrav= 0,\n" - ret += "nat = %d,\n" % tot_natoms - ret += "ntyp = %d,\n" % ntypes + ret += "nat = %d,\n" % tot_natoms # noqa: UP031 + ret += "ntyp = %d,\n" % ntypes # noqa: UP031 ret += "vdw_corr = 'TS',\n" ret += f"ecutwfc = {ecut:f},\n" ret += f"ts_vdw_econv_thr={ediff:e},\n" @@ -50,7 +50,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 += "%s %d %s\n" % (atom_names[ii], atom_masses[ii], pps[ii]) # noqa: UP031 return ret @@ -95,9 +95,9 @@ def _make_pwscf_04_kpoints(sys_data, kspacing): ret = "" ret += "K_POINTS { automatic }\n" for ii in range(3): - ret += "%d " % kpoints[ii] + ret += "%d " % kpoints[ii] # noqa: UP031 for ii in range(3): - ret += "%d " % _kshift(kpoints[ii]) + ret += "%d " % _kshift(kpoints[ii]) # noqa: UP031 ret += "\n" return ret diff --git a/dpgen/auto_test/lib/siesta.py b/dpgen/auto_test/lib/siesta.py index 314dc8f2d..3f1b41c6a 100644 --- a/dpgen/auto_test/lib/siesta.py +++ b/dpgen/auto_test/lib/siesta.py @@ -8,8 +8,8 @@ def _make_siesta_01_common(sys_data, ecut, ediff, mixingWeight, NumberPulay): ret = "" ret += "SystemName system\n" ret += "SystemLabel system\n" - ret += "NumberOfAtoms %d" % tot_natoms - ret += "\nNumberOfSpecies %d\n" % ntypes + ret += "NumberOfAtoms %d" % tot_natoms # noqa: UP031 + ret += "\nNumberOfSpecies %d\n" % ntypes # noqa: UP031 ret += "\n" ret += "WriteForces T\n" ret += "WriteCoorStep T\n" @@ -22,7 +22,7 @@ def _make_siesta_01_common(sys_data, ecut, ediff, mixingWeight, NumberPulay): ret += f"DM.MixingWeight {mixingWeight:f}\n" ret += f"DM.Tolerance {ediff:e}\n" ret += "DM.UseSaveDM true\n" - ret += "DM.NumberPulay %d\n" % NumberPulay + ret += "DM.NumberPulay %d\n" % NumberPulay # noqa: UP031 ret += "MD.UseSaveXV T\n\n" ret += "XC.functional GGA\n" @@ -70,15 +70,15 @@ def _make_siesta_03_kpoint(sys_data, kspacing): ] ret = "" ret += "%block kgrid_Monkhorst_Pack\n" - ret += "%d" % kpoints[0] + ret += "%d" % kpoints[0] # noqa: UP031 ret += "\t0\t0\t0.0\n" ret += "0\t" - ret += "%d" % kpoints[1] + ret += "%d" % kpoints[1] # noqa: UP031 ret += "\t0\t0.0\n" ret += "0\t0\t" - ret += "%d" % kpoints[2] + ret += "%d" % kpoints[2] # noqa: UP031 ret += "\t0.0\n" ret += "%endblock kgrid_Monkhorst_Pack\n" @@ -108,7 +108,7 @@ def _make_siesta_04_ucVectorCoord(sys_data): cc = 0 for ii in range(ntypes): for jj in range(atom_numbs[ii]): - ret += "%f %f %f %d %s\n" % ( + ret += "%f %f %f %d %s\n" % ( # noqa: UP031 coordinates[cc][0], coordinates[cc][1], coordinates[cc][2], diff --git a/dpgen/auto_test/lib/utils.py b/dpgen/auto_test/lib/utils.py index 1fd4f7af7..57311a3c3 100644 --- a/dpgen/auto_test/lib/utils.py +++ b/dpgen/auto_test/lib/utils.py @@ -20,7 +20,7 @@ def create_path(path): dirname = os.path.dirname(path) counter = 0 while True: - bk_dirname = dirname + ".bk%03d" % counter + bk_dirname = dirname + ".bk%03d" % counter # noqa: UP031 if not os.path.isdir(bk_dirname): shutil.move(dirname, bk_dirname) break diff --git a/dpgen/auto_test/lib/vasp.py b/dpgen/auto_test/lib/vasp.py index c51cb3f27..12bc1219c 100644 --- a/dpgen/auto_test/lib/vasp.py +++ b/dpgen/auto_test/lib/vasp.py @@ -269,22 +269,22 @@ def make_vasp_static_incar( isif = 2 ret = "" ret += "PREC=A\n" - ret += "ENCUT=%d\n" % ecut + ret += "ENCUT=%d\n" % ecut # noqa: UP031 ret += "# ISYM=0\n" ret += "ALGO=normal\n" ret += f"EDIFF={ediff:e}\n" ret += "EDIFFG=-0.01\n" ret += "LREAL=A\n" - ret += "NPAR=%d\n" % npar - ret += "KPAR=%d\n" % kpar + ret += "NPAR=%d\n" % npar # noqa: UP031 + ret += "KPAR=%d\n" % kpar # noqa: UP031 ret += "\n" - ret += "ISMEAR=%d\n" % ismear + ret += "ISMEAR=%d\n" % ismear # noqa: UP031 ret += f"SIGMA={sigma:f}\n" ret += "\n" ret += "ISTART=0\n" ret += "ICHARG=2\n" ret += "NELMIN=6\n" - ret += "ISIF=%d\n" % isif + ret += "ISIF=%d\n" % isif # noqa: UP031 ret += "IBRION=-1\n" ret += "\n" ret += "NSW=0\n" @@ -319,23 +319,23 @@ def make_vasp_relax_incar( isif = _compute_isif(relax_ion, relax_shape, relax_volume) ret = "" ret += "PREC=A\n" - ret += "ENCUT=%d\n" % ecut + ret += "ENCUT=%d\n" % ecut # noqa: UP031 ret += "# ISYM=0\n" ret += "ALGO=normal\n" ret += f"EDIFF={ediff:e}\n" ret += "EDIFFG=-0.01\n" ret += "LREAL=A\n" - ret += "NPAR=%d\n" % npar - ret += "KPAR=%d\n" % kpar + ret += "NPAR=%d\n" % npar # noqa: UP031 + ret += "KPAR=%d\n" % kpar # noqa: UP031 ret += "\n" - ret += "ISMEAR=%d\n" % ismear + ret += "ISMEAR=%d\n" % ismear # noqa: UP031 ret += f"SIGMA={sigma:f}\n" ret += "\n" ret += "ISTART=0\n" ret += "ICHARG=2\n" ret += "NELM=100\n" ret += "NELMIN=6\n" - ret += "ISIF=%d\n" % isif + ret += "ISIF=%d\n" % isif # noqa: UP031 ret += "IBRION=2\n" ret += "\n" ret += "NSW=50\n" @@ -360,22 +360,22 @@ def make_vasp_phonon_incar( isif = 2 ret = "" ret += "PREC=A\n" - ret += "ENCUT=%d\n" % ecut + ret += "ENCUT=%d\n" % ecut # noqa: UP031 ret += "# ISYM=0\n" ret += "ALGO=normal\n" ret += f"EDIFF={ediff:e}\n" ret += "EDIFFG=-0.01\n" ret += "LREAL=A\n" # ret += 'NPAR=%d\n' % npar - ret += "KPAR=%d\n" % kpar + ret += "KPAR=%d\n" % kpar # noqa: UP031 ret += "\n" - ret += "ISMEAR=%d\n" % ismear + ret += "ISMEAR=%d\n" % ismear # noqa: UP031 ret += f"SIGMA={sigma:f}\n" ret += "\n" ret += "ISTART=0\n" ret += "ICHARG=2\n" ret += "NELMIN=4\n" - ret += "ISIF=%d\n" % isif + ret += "ISIF=%d\n" % isif # noqa: UP031 ret += "IBRION=8\n" ret += "\n" ret += "NSW=1\n" @@ -478,7 +478,7 @@ def _make_vasp_kp_gamma(kpoints): ret += "Automatic mesh\n" ret += "0\n" ret += "Gamma\n" - ret += "%d %d %d\n" % (kpoints[0], kpoints[1], kpoints[2]) + ret += "%d %d %d\n" % (kpoints[0], kpoints[1], kpoints[2]) # noqa: UP031 ret += "0 0 0\n" return ret @@ -488,7 +488,7 @@ def _make_vasp_kp_mp(kpoints): ret += "K-Points\n" ret += " 0\n" ret += "Monkhorst Pack\n" - ret += "%d %d %d\n" % (kpoints[0], kpoints[1], kpoints[2]) + ret += "%d %d %d\n" % (kpoints[0], kpoints[1], kpoints[2]) # noqa: UP031 ret += " 0 0 0\n" return ret diff --git a/dpgen/auto_test/refine.py b/dpgen/auto_test/refine.py index cd0fcd8f0..a851fc1f6 100644 --- a/dpgen/auto_test/refine.py +++ b/dpgen/auto_test/refine.py @@ -20,7 +20,7 @@ def make_refine(init_from_suffix, output_suffix, path_to_work): task_list = [] for ii in range(task_num): - output_task = os.path.join(output, "task.%06d" % ii) + output_task = os.path.join(output, "task.%06d" % ii) # noqa: UP031 os.makedirs(output_task, exist_ok=True) os.chdir(output_task) for jj in [ @@ -35,7 +35,7 @@ def make_refine(init_from_suffix, output_suffix, path_to_work): if os.path.exists(jj): os.remove(jj) task_list.append(output_task) - init_from_task = os.path.join(init_from, "task.%06d" % ii) + init_from_task = os.path.join(init_from, "task.%06d" % ii) # noqa: UP031 if not os.path.exists(init_from_task): raise FileNotFoundError( "the initial task directory does not exist for refine" diff --git a/dpgen/auto_test/reproduce.py b/dpgen/auto_test/reproduce.py index 47c266d61..a2b919a5d 100644 --- a/dpgen/auto_test/reproduce.py +++ b/dpgen/auto_test/reproduce.py @@ -60,7 +60,7 @@ def make_repro( for jj in range(nframe): if property_type == "interstitial": print(insert_element, file=fout_element) - output_task = os.path.join(path_to_work, "task.%06d" % task_num) + output_task = os.path.join(path_to_work, "task.%06d" % task_num) # noqa: UP031 task_num += 1 task_list.append(output_task) os.makedirs(output_task, exist_ok=True) diff --git a/dpgen/collect/collect.py b/dpgen/collect/collect.py index 133bab561..db2a6a163 100644 --- a/dpgen/collect/collect.py +++ b/dpgen/collect/collect.py @@ -26,7 +26,7 @@ def collect_data( if verbose: max_str_len = max([len(str(ii)) for ii in sys_configs]) max_form_len = 16 - ptr_fmt = "%%%ds %%%ds natoms %%6d nframes %%6d" % ( + ptr_fmt = "%%%ds %%%ds natoms %%6d nframes %%6d" % ( # noqa: UP031 max_str_len + 5, max_form_len, ) @@ -43,7 +43,7 @@ def collect_data( numb_sys = len(sys_configs) model_devi_jobs = jdata.get("model_devi_jobs", {}) numb_jobs = len(model_devi_jobs) - iters = ["iter.%06d" % ii for ii in range(numb_jobs)] + iters = ["iter.%06d" % ii for ii in range(numb_jobs)] # noqa: UP031 # loop over iters to collect data for ii in range(len(iters)): iter_data = glob.glob(os.path.join(iters[ii], "02.fp", "data.[0-9]*[0-9]")) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 68667645f..3e6940a86 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -39,7 +39,7 @@ def create_path(path, back=False): dirname = os.path.dirname(path) counter = 0 while True: - bk_dirname = dirname + ".bk%03d" % counter + bk_dirname = dirname + ".bk%03d" % counter # noqa: UP031 if not os.path.isdir(bk_dirname): shutil.move(dirname, bk_dirname) break @@ -83,18 +83,18 @@ def out_dir_name(jdata): if from_poscar: from_poscar_path = jdata["from_poscar_path"] poscar_name = os.path.basename(from_poscar_path) - cell_str = "%02d" % (super_cell[0]) + cell_str = "%02d" % (super_cell[0]) # noqa: UP031 for ii in range(1, len(super_cell)): - cell_str = cell_str + ("x%02d" % super_cell[ii]) + cell_str = cell_str + ("x%02d" % super_cell[ii]) # noqa: UP031 return poscar_name + "." + cell_str else: cell_type = jdata["cell_type"] ele_str = "" for ii in elements: ele_str = ele_str + ii.lower() - cell_str = "%02d" % (super_cell[0]) + cell_str = "%02d" % (super_cell[0]) # noqa: UP031 for ii in range(1, len(super_cell)): - cell_str = cell_str + ("x%02d" % super_cell[ii]) + cell_str = cell_str + ("x%02d" % super_cell[ii]) # noqa: UP031 return ele_str + "." + cell_type + "." + cell_str @@ -368,7 +368,7 @@ def make_super_cell_poscar(jdata): dlog.info(natoms_list) comb_name = "sys-" for idx, ii in enumerate(natoms_list): - comb_name += "%04d" % ii + comb_name += "%04d" % ii # noqa: UP031 if idx != len(natoms_list) - 1: comb_name += "-" path_work = os.path.join(path_sc, comb_name) @@ -419,7 +419,7 @@ def make_super_cell_STRU(jdata): dlog.info(natoms_list) comb_name = "sys-" for idx, ii in enumerate(natoms_list): - comb_name += "%04d" % ii + comb_name += "%04d" % ii # noqa: UP031 if idx != len(natoms_list) - 1: comb_name += "-" path_work = os.path.join(path_sc, comb_name) @@ -479,7 +479,7 @@ def place_element(jdata): continue comb_name = "sys-" for idx, jj in enumerate(ii): - comb_name += "%04d" % jj + comb_name += "%04d" % jj # noqa: UP031 if idx != len(ii) - 1: comb_name += "-" path_pos_in = path_sc @@ -507,7 +507,7 @@ def place_element_ABACUS(jdata, supercell_stru): continue comb_name = "sys-" for idx, jj in enumerate(ii): - comb_name += "%04d" % jj + comb_name += "%04d" % jj # noqa: UP031 if idx != len(ii) - 1: comb_name += "-" # path_pos_in = path_sc @@ -875,13 +875,13 @@ def make_vasp_md(jdata, mdata): path_work = path_md 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_work, "%06d" % kk) + path_work = os.path.join(path_work, "%06d" % kk) # noqa: UP031 create_path(path_work) os.chdir(path_work) path_pos = path_ps path_pos = os.path.join(path_pos, ii) path_pos = os.path.join(path_pos, f"scale-{jj:.3f}") - path_pos = os.path.join(path_pos, "%06d" % kk) + path_pos = os.path.join(path_pos, "%06d" % kk) # noqa: UP031 init_pos = os.path.join(path_pos, "POSCAR") shutil.copy2(init_pos, "POSCAR") file_incar = os.path.join(path_md, "INCAR") @@ -996,13 +996,13 @@ def make_abacus_md(jdata, mdata): path_work = path_md 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_work, "%06d" % kk) + path_work = os.path.join(path_work, "%06d" % kk) # noqa: UP031 create_path(path_work) os.chdir(path_work) path_pos = path_ps path_pos = os.path.join(path_pos, ii) path_pos = os.path.join(path_pos, f"scale-{jj:.3f}") - path_pos = os.path.join(path_pos, "%06d" % kk) + path_pos = os.path.join(path_pos, "%06d" % kk) # noqa: UP031 init_pos = os.path.join(path_pos, "STRU") if "kspacing" not in standard_incar: file_kpt = os.path.join(path_md, "KPT") @@ -1071,7 +1071,7 @@ def coll_vasp_md(jdata): valid_outcars = [] for jj in scale: for kk in range(pert_numb): - path_work = os.path.join(f"scale-{jj:.3f}", "%06d" % kk) + path_work = os.path.join(f"scale-{jj:.3f}", "%06d" % kk) # noqa: UP031 outcar = os.path.join(path_work, "OUTCAR") # dlog.info("OUTCAR",outcar) if os.path.isfile(outcar): @@ -1202,7 +1202,7 @@ def coll_abacus_md(jdata): valid_outcars = [] for jj in scale: for kk in range(pert_numb + 1): - path_work = os.path.join(f"scale-{jj:.3f}", "%06d" % kk) + path_work = os.path.join(f"scale-{jj:.3f}", "%06d" % kk) # noqa: UP031 print(f"path_work = {path_work}") # outcar = os.path.join(path_work, 'OUT.ABACUS/') outcar = path_work @@ -1492,8 +1492,8 @@ def gen_init_bulk(args): 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("MD steps in PARAM is %d" % (md_nstep_jdata)) # noqa: UP031 + dlog.info("MD steps in md_incar is %d" % (nsw_steps)) # noqa: UP031 dlog.info("DP-GEN will use settings in md_incar!") jdata["md_nstep"] = nsw_steps except KeyError: @@ -1568,7 +1568,7 @@ def gen_init_bulk(args): elif jdata["init_fp_style"] == "ABACUS": coll_abacus_md(jdata) else: - raise RuntimeError("unknown stage %d" % stage) + raise RuntimeError("unknown stage %d" % stage) # noqa: UP031 if __name__ == "__main__": diff --git a/dpgen/data/reaction.py b/dpgen/data/reaction.py index b71e78c1f..46cde2ff8 100644 --- a/dpgen/data/reaction.py +++ b/dpgen/data/reaction.py @@ -222,7 +222,7 @@ def gen_init_reaction(args): with open(record) as frec: for line in frec: iter_rec = int(line.strip()) - dlog.info("continue from task %02d" % iter_rec) + dlog.info("continue from task %02d" % iter_rec) # noqa: UP031 for ii in range(numb_task): sepline(str(ii), "-") if ii <= iter_rec: diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 34fc5a2d1..3fba6a14b 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -31,7 +31,7 @@ def create_path(path): dirname = os.path.dirname(path) counter = 0 while True: - bk_dirname = dirname + ".bk%03d" % counter + bk_dirname = dirname + ".bk%03d" % counter # noqa: UP031 if not os.path.isdir(bk_dirname): shutil.move(dirname, bk_dirname) break @@ -77,9 +77,9 @@ def out_dir_name(jdata): if from_poscar: from_poscar_path = jdata["from_poscar_path"] poscar_name = os.path.basename(from_poscar_path) - cell_str = "%02d" % (super_cell[0]) + cell_str = "%02d" % (super_cell[0]) # noqa: UP031 for ii in range(1, len(super_cell)): - cell_str = cell_str + ("x%02d" % super_cell[ii]) + cell_str = cell_str + ("x%02d" % super_cell[ii]) # noqa: UP031 return poscar_name + "." + cell_str else: cell_type = jdata["cell_type"] @@ -89,9 +89,9 @@ def out_dir_name(jdata): ele_str = "surf." for ii in elements: ele_str = ele_str + ii.lower() - cell_str = "%02d" % (super_cell[0]) + cell_str = "%02d" % (super_cell[0]) # noqa: UP031 for ii in range(1, len(super_cell)): - cell_str = cell_str + ("x%02d" % super_cell[ii]) + cell_str = cell_str + ("x%02d" % super_cell[ii]) # noqa: UP031 return ele_str + "." + cell_type + "." + cell_str @@ -337,7 +337,7 @@ def place_element(jdata): continue comb_name = "sys-" for idx, jj in enumerate(ii): - comb_name += "%04d" % jj + comb_name += "%04d" % jj # noqa: UP031 if idx != len(ii) - 1: comb_name += "-" path_work = os.path.join(path_surf, comb_name) @@ -632,7 +632,7 @@ def gen_init_surf(args): make_scale(jdata) pert_scaled(jdata) else: - raise RuntimeError("unknown stage %d" % stage) + raise RuntimeError("unknown stage %d" % stage) # noqa: UP031 if __name__ == "__main__": diff --git a/dpgen/data/tools/bcc.py b/dpgen/data/tools/bcc.py index 08554f472..5dd8a6610 100644 --- a/dpgen/data/tools/bcc.py +++ b/dpgen/data/tools/bcc.py @@ -18,7 +18,7 @@ def poscar_unit(latt): 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 += "X\n" - ret += "%d\n" % numb_atoms() + ret += "%d\n" % numb_atoms() # noqa: UP031 ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" ret += f"{0.5:.16f} {0.5:.16f} {0.5:.16f}\n" diff --git a/dpgen/data/tools/cessp2force_lin.py b/dpgen/data/tools/cessp2force_lin.py index f08f7e721..1f942e31d 100755 --- a/dpgen/data/tools/cessp2force_lin.py +++ b/dpgen/data/tools/cessp2force_lin.py @@ -162,7 +162,7 @@ def process_outcar_file_v5_dev( fw.write(f" {data[i][1][j]}") fw.write("\n") fw.write( - "## force file generated from file %s config %d\n" + "## force file generated from file %s config %d\n" # noqa: UP031 % (outcars[i], count) ) fw.write(f"#X {box_x[0]:13.8f} {box_x[1]:13.8f} {box_x[2]:13.8f}\n") @@ -179,7 +179,7 @@ def process_outcar_file_v5_dev( fw.flush() for adata in atom_data: fw.write( - "%d %11.7g %11.7g %11.7g %11.7g %11.7g %11.7g\n" + "%d %11.7g %11.7g %11.7g %11.7g %11.7g %11.7g\n" # noqa: UP031 % ( adata[0], adata[1], diff --git a/dpgen/data/tools/create_random_disturb.py b/dpgen/data/tools/create_random_disturb.py index b3cefb07f..957e20872 100755 --- a/dpgen/data/tools/create_random_disturb.py +++ b/dpgen/data/tools/create_random_disturb.py @@ -74,7 +74,7 @@ def create_disturbs_ase( dpos[i, :] = dr if write_d: dnorm = np.linalg.norm(dr) - fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) + fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) # noqa: UP031 fw.flush() pos = pos0 + dpos atoms_d.set_positions(pos) @@ -136,7 +136,7 @@ def create_disturbs_ase_dev( dpos[i, :] = dr if write_d: dnorm = np.linalg.norm(dr) - fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) + fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) # noqa: UP031 fw.flush() # random flux for volumes @@ -207,7 +207,7 @@ def create_disturbs_abacus_dev( dpos[i, :] = dr if write_d: dnorm = np.linalg.norm(dr) - fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) + fw.write("%d\t%f\t%f\t%f\t%f\n" % (i + 1, dr[0], dr[1], dr[2], dnorm)) # noqa: UP031 fw.flush() # random flux for volumes diff --git a/dpgen/data/tools/diamond.py b/dpgen/data/tools/diamond.py index e258a5aa6..419e059a5 100644 --- a/dpgen/data/tools/diamond.py +++ b/dpgen/data/tools/diamond.py @@ -23,7 +23,7 @@ def poscar_unit(latt): 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 += "X\n" - ret += "%d\n" % numb_atoms() + ret += "%d\n" % numb_atoms() # noqa: UP031 ret += "Direct\n" ret += f"{0.12500000000000:.16f} {0.12500000000000:.16f} {0.12500000000000:.16f}\n" ret += f"{0.87500000000000:.16f} {0.87500000000000:.16f} {0.87500000000000:.16f}\n" diff --git a/dpgen/data/tools/fcc.py b/dpgen/data/tools/fcc.py index 3e9815851..08f2abe8b 100644 --- a/dpgen/data/tools/fcc.py +++ b/dpgen/data/tools/fcc.py @@ -18,7 +18,7 @@ def poscar_unit(latt): 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 += "X\n" - ret += "%d\n" % numb_atoms() + ret += "%d\n" % numb_atoms() # noqa: UP031 ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" ret += f"{0.5:.16f} {0.5:.16f} {0.0:.16f}\n" diff --git a/dpgen/data/tools/hcp.py b/dpgen/data/tools/hcp.py index d552cdcc2..fe9aa3e4f 100644 --- a/dpgen/data/tools/hcp.py +++ b/dpgen/data/tools/hcp.py @@ -21,7 +21,7 @@ def poscar_unit(latt): 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 += "X\n" - ret += "%d\n" % numb_atoms() + ret += "%d\n" % numb_atoms() # noqa: UP031 ret += "Direct\n" ret += f"{0:.16f} {0:.16f} {0:.16f}\n" ret += f"{1.0 / 3:.16f} {1.0 / 3:.16f} {1.0 / 2:.16f}\n" diff --git a/dpgen/data/tools/io_lammps.py b/dpgen/data/tools/io_lammps.py index f23045905..d0ef50c5a 100755 --- a/dpgen/data/tools/io_lammps.py +++ b/dpgen/data/tools/io_lammps.py @@ -164,12 +164,12 @@ def ase2lammpsdata(atoms, typeids=None, fout="out.lmp"): # write number of atoms natoms = atoms.get_global_number_of_atoms() - fw.write("%d atoms\n" % natoms) + fw.write("%d atoms\n" % natoms) # noqa: UP031 fw.write("\n") # write number of types ntypes = get_atoms_ntypes(atoms) - fw.write("%d atom types\n" % ntypes) + fw.write("%d atom types\n" % ntypes) # noqa: UP031 fw.write("\n") # write cell information @@ -196,7 +196,7 @@ def ase2lammpsdata(atoms, typeids=None, fout="out.lmp"): fw.write("Masses\n") fw.write("\n") for i in range(ntypes): - fw.write("%d\t%f\n" % (i + 1, masses[i])) + fw.write("%d\t%f\n" % (i + 1, masses[i])) # noqa: UP031 fw.flush() fw.write("\n") @@ -219,7 +219,7 @@ def ase2lammpsdata(atoms, typeids=None, fout="out.lmp"): # typeid = ase.data.atomic_numbers[cs] # typeid as their atomic # numbers fw.write( - "%d\t%d\t%f\t%f\t%f\n" % (i + 1, typeid, pos[i][0], pos[i][1], pos[i][2]) + "%d\t%d\t%f\t%f\t%f\n" % (i + 1, typeid, pos[i][0], pos[i][1], pos[i][2]) # noqa: UP031 ) fw.flush() fw.close() diff --git a/dpgen/data/tools/sc.py b/dpgen/data/tools/sc.py index c298c2cf3..a5754b9a5 100644 --- a/dpgen/data/tools/sc.py +++ b/dpgen/data/tools/sc.py @@ -18,7 +18,7 @@ def poscar_unit(latt): 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 += "X\n" - ret += "%d\n" % numb_atoms() + ret += "%d\n" % numb_atoms() # noqa: UP031 ret += "Direct\n" ret += f"{0.0:.16f} {0.0:.16f} {0.0:.16f}\n" return ret diff --git a/dpgen/generator/lib/abacus_scf.py b/dpgen/generator/lib/abacus_scf.py index 24f59f6b4..376c64eb0 100644 --- a/dpgen/generator/lib/abacus_scf.py +++ b/dpgen/generator/lib/abacus_scf.py @@ -65,7 +65,7 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): assert fp_params["scf_nmax"] >= 0 and isinstance( fp_params["scf_nmax"], int ), "'scf_nmax' should be a positive integer." - ret += "scf_nmax %d\n" % fp_params["scf_nmax"] + ret += "scf_nmax %d\n" % fp_params["scf_nmax"] # noqa: UP031 elif key == "basis_type": assert fp_params["basis_type"] in [ "pw", @@ -81,7 +81,7 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): assert ( fp_params["gamma_only"] == 0 or fp_params["gamma_only"] == 1 ), "'gamma_only' should be either 0 or 1." - ret += "gamma_only %d\n" % fp_params["gamma_only"] + ret += "gamma_only %d\n" % fp_params["gamma_only"] # noqa: UP031 elif key == "mixing_type": assert fp_params["mixing_type"] in [ "plain", @@ -103,13 +103,13 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): assert ( fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1 ), "'symmetry' should be either 0 or 1." - ret += "symmetry %d\n" % fp_params["symmetry"] + ret += "symmetry %d\n" % fp_params["symmetry"] # noqa: UP031 elif key == "nbands": fp_params["nbands"] = int(fp_params["nbands"]) assert fp_params["nbands"] > 0 and isinstance( fp_params["nbands"], int ), "'nbands' should be a positive integer." - ret += "nbands %d\n" % fp_params["nbands"] + ret += "nbands %d\n" % fp_params["nbands"] # noqa: UP031 elif key == "nspin": fp_params["nspin"] = int(fp_params["nspin"]) assert ( @@ -117,7 +117,7 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): or fp_params["nspin"] == 2 or fp_params["nspin"] == 4 ), "'nspin' can anly take 1, 2 or 4" - ret += "nspin %d\n" % fp_params["nspin"] + ret += "nspin %d\n" % fp_params["nspin"] # noqa: UP031 elif key == "ks_solver": assert ( fp_params["ks_solver"] @@ -157,14 +157,14 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): assert ( fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1 ), "'cal_force' should be either 0 or 1." - ret += "cal_force %d\n" % fp_params["cal_force"] + ret += "cal_force %d\n" % fp_params["cal_force"] # noqa: UP031 elif key == "cal_stress": if isinstance(fp_params["cal_stress"], str): fp_params["cal_stress"] = int(eval(fp_params["cal_stress"])) assert ( fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1 ), "'cal_stress' should be either 0 or 1." - ret += "cal_stress %d\n" % fp_params["cal_stress"] + ret += "cal_stress %d\n" % fp_params["cal_stress"] # noqa: UP031 # paras for deepks elif key == "deepks_out_labels": if isinstance(fp_params["deepks_out_labels"], str): @@ -175,7 +175,7 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): fp_params["deepks_out_labels"] == 0 or fp_params["deepks_out_labels"] == 1 ), "'deepks_out_labels' should be either 0 or 1." - ret += "deepks_out_labels %d\n" % fp_params["deepks_out_labels"] + ret += "deepks_out_labels %d\n" % fp_params["deepks_out_labels"] # noqa: UP031 elif key == "deepks_descriptor_lmax": fp_params["deepks_descriptor_lmax"] = int( fp_params["deepks_descriptor_lmax"] @@ -183,14 +183,14 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): assert ( fp_params["deepks_descriptor_lmax"] >= 0 ), "'deepks_descriptor_lmax' should be a positive integer." - ret += "deepks_descriptor_lmax %d\n" % fp_params["deepks_descriptor_lmax"] + ret += "deepks_descriptor_lmax %d\n" % fp_params["deepks_descriptor_lmax"] # noqa: UP031 elif key == "deepks_scf": if isinstance(fp_params["deepks_scf"], str): fp_params["deepks_scf"] = int(eval(fp_params["deepks_scf"])) assert ( fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1 ), "'deepks_scf' should be either 0 or 1." - ret += "deepks_scf %d\n" % fp_params["deepks_scf"] + ret += "deepks_scf %d\n" % fp_params["deepks_scf"] # noqa: UP031 elif key == "deepks_model": ret += "deepks_model {}\n".format( os.path.join( @@ -272,7 +272,7 @@ def make_abacus_scf_stru( ret += "0.0\n" ret += str(atom_numbs[iele]) + "\n" for iatom in range(atom_numbs[iele]): - ret += "%.12f %.12f %.12f %d %d %d\n" % ( + ret += "%.12f %.12f %.12f %d %d %d\n" % ( # noqa: UP031 coord[natom_tot, 0], coord[natom_tot, 1], coord[natom_tot, 2], diff --git a/dpgen/generator/lib/calypso_check_outcar.py b/dpgen/generator/lib/calypso_check_outcar.py index fbb63994f..88de0efdd 100644 --- a/dpgen/generator/lib/calypso_check_outcar.py +++ b/dpgen/generator/lib/calypso_check_outcar.py @@ -50,7 +50,7 @@ def Write_Outcar(element, ele, volume, lat, pos, ene, force, stress, pstress): f.write("VRHFIN =" + str(x) + "\n") f.write("ions per type =") for x in element: - f.write("%5d" % ele[x]) + f.write("%5d" % ele[x]) # noqa: UP031 f.write( "\nDirection XX YY ZZ XY YZ ZX\n" ) diff --git a/dpgen/generator/lib/calypso_run_model_devi.py b/dpgen/generator/lib/calypso_run_model_devi.py index bb3394763..d5f2e24f4 100644 --- a/dpgen/generator/lib/calypso_run_model_devi.py +++ b/dpgen/generator/lib/calypso_run_model_devi.py @@ -14,14 +14,14 @@ def write_model_devi_out(devi, fname): assert devi.shape[1] == 8 # assert devi.shape[1] == 7 - header = "%5s" % "step" + header = "%5s" % "step" # noqa: UP031 for item in "vf": - header += "%16s%16s%16s" % ( + header += "%16s%16s%16s" % ( # noqa: UP031 f"max_devi_{item}", f"min_devi_{item}", f"avg_devi_{item}", ) - header += "%16s" % "min_dis" + header += "%16s" % "min_dis" # noqa: UP031 np.savetxt( fname, devi, @@ -52,7 +52,7 @@ def Modd(all_models, type_map): num_per_task = math.ceil(nnum / 500) for temp in range(num_per_task): - task_name = os.path.join(cwd, "task.%03d.%03d" % (num, temp)) + task_name = os.path.join(cwd, "task.%03d.%03d" % (num, temp)) # noqa: UP031 put_poscar = os.path.join(task_name, "traj") if not os.path.exists(task_name): os.mkdir(task_name) diff --git a/dpgen/generator/lib/calypso_run_opt.py b/dpgen/generator/lib/calypso_run_opt.py index 49b503be4..fc7cf899a 100644 --- a/dpgen/generator/lib/calypso_run_opt.py +++ b/dpgen/generator/lib/calypso_run_opt.py @@ -55,7 +55,7 @@ def Write_Outcar(element, ele, volume, lat, pos, ene, force, stress, pstress): f.write("VRHFIN =" + str(x) + "\n") f.write("ions per type =") for x in element: - f.write("%5d" % ele[x]) + f.write("%5d" % ele[x]) # noqa: UP031 f.write( "\nDirection XX YY ZZ XY YZ ZX\n" ) diff --git a/dpgen/generator/lib/gaussian.py b/dpgen/generator/lib/gaussian.py index 421f15b84..329f2bb06 100644 --- a/dpgen/generator/lib/gaussian.py +++ b/dpgen/generator/lib/gaussian.py @@ -154,8 +154,8 @@ def make_gaussian_input(sys_data, fp_params): mult_frags.append(detect_multiplicity(np.array(symbols)[idx])) if use_fragment_guesses: multiplicity = sum(mult_frags) - frag_numb + 1 - chargekeywords_frag = "%d %d" % (charge, multiplicity) + "".join( - [" %d %d" % (charge, mult_frag) for mult_frag in mult_frags] + chargekeywords_frag = "%d %d" % (charge, multiplicity) + "".join( # noqa: UP031 + [" %d %d" % (charge, mult_frag) for mult_frag in mult_frags] # noqa: UP031 ) else: multi_frags = np.array(mult_frags) @@ -190,7 +190,7 @@ def make_gaussian_input(sys_data, fp_params): for ii, (symbol, coordinate) in enumerate(zip(symbols, coordinates)): if use_fragment_guesses: buff.append( - "%s(Fragment=%d) %f %f %f" % (symbol, frag_index[ii] + 1, *coordinate) + "%s(Fragment=%d) %f %f %f" % (symbol, frag_index[ii] + 1, *coordinate) # noqa: UP031 ) else: buff.append("{} {:f} {:f} {:f}".format(symbol, *coordinate)) diff --git a/dpgen/generator/lib/lammps.py b/dpgen/generator/lib/lammps.py index 052b75a0f..3145f331f 100644 --- a/dpgen/generator/lib/lammps.py +++ b/dpgen/generator/lib/lammps.py @@ -49,7 +49,7 @@ def make_lammps_input( raise RuntimeError( "the frame style ele_temp and atom style ele_temp should not be set at the same time" ) - ret = "variable NSTEPS equal %d\n" % nsteps + ret = "variable NSTEPS equal %d\n" % nsteps # noqa: UP031 if nbeads is not None: if nbeads <= 0: raise ValueError( @@ -58,11 +58,11 @@ def make_lammps_input( power = 1 while power < nbeads: power *= 10 - ret += "variable ibead uloop %d pad\n" % (power - 1) + ret += "variable ibead uloop %d pad\n" % (power - 1) # noqa: UP031 if nbeads is not None: ret += "atom_modify map yes\n" - ret += "variable THERMO_FREQ equal %d\n" % trj_freq - ret += "variable DUMP_FREQ equal %d\n" % trj_freq + ret += "variable THERMO_FREQ equal %d\n" % trj_freq # noqa: UP031 + ret += "variable DUMP_FREQ equal %d\n" % trj_freq # noqa: UP031 ret += f"variable TEMP equal {temp:f}\n" if nbeads is not None: ret += "variable TEMP_NBEADS equal %f\n" % (temp * nbeads) @@ -83,7 +83,7 @@ def make_lammps_input( ret += "\n" ret += "neighbor 1.0 bin\n" if neidelay is not None: - ret += "neigh_modify delay %d\n" % neidelay + ret += "neigh_modify delay %d\n" % neidelay # noqa: UP031 ret += "\n" ret += "box tilt large\n" if nbeads is None: @@ -92,7 +92,7 @@ def make_lammps_input( ret += f'if "${{restart}} > 0" then "read_restart dpgen.restart${{ibead}}.*" else "read_data {conf_file}"\n' ret += "change_box all triclinic\n" for jj in range(len(mass_map)): - ret += "mass %d %f\n" % (jj + 1, mass_map[jj]) + ret += "mass %d %f\n" % (jj + 1, mass_map[jj]) # noqa: UP031 graph_list = "" for ii in graphs: graph_list += ii + " " @@ -141,12 +141,12 @@ def make_lammps_input( if pka_e is None: if nbeads is None: ret += ( - 'if "${restart} == 0" then "velocity all create ${TEMP} %d"' + 'if "${restart} == 0" then "velocity all create ${TEMP} %d"' # noqa: UP031 % (random.randrange(max_seed - 1) + 1) ) else: ret += ( - 'if "${restart} == 0" then "velocity all create ${TEMP_NBEADS} %d"' + 'if "${restart} == 0" then "velocity all create ${TEMP_NBEADS} %d"' # noqa: UP031 % (random.randrange(max_seed - 1) + 1) ) else: diff --git a/dpgen/generator/lib/make_calypso.py b/dpgen/generator/lib/make_calypso.py index 59e4f263d..42d5e7f69 100644 --- a/dpgen/generator/lib/make_calypso.py +++ b/dpgen/generator/lib/make_calypso.py @@ -29,7 +29,7 @@ def make_calypso_input( assert nameofatoms is not None ret += "SystemName = {}\n".format("".join(nameofatoms)) ret += "# Number of different atomic species in the simulation.\n" - ret += "NumberOfSpecies = %d\n" % (len(nameofatoms)) + ret += "NumberOfSpecies = %d\n" % (len(nameofatoms)) # noqa: UP031 ret += "# Element symbols of the different chemical species.\n" ret += "NameOfAtoms = {}\n".format(" ".join(nameofatoms)) ret += "# Number of atoms for each chemical species in one formula unit. \n" @@ -54,7 +54,7 @@ def make_calypso_input( assert len(distanceofion[0]) == len(nameofatoms) ret += "@DistanceOfIon \n" for temp in distanceofion: - ret += "%4s \n" % (" ".join(list(map(str, temp)))) + ret += "%4s \n" % (" ".join(list(map(str, temp)))) # noqa: UP031 ret += "@End\n" ret += "# It determines which algorithm should be adopted in the simulation.\n" ret += "Ialgo = 2\n" @@ -67,10 +67,10 @@ def make_calypso_input( "# The population size. Normally, it has a larger number for larger systems.\n" ) assert popsize is not None and isinstance(popsize, int) - ret += "PopSize = %d\n" % (popsize) + ret += "PopSize = %d\n" % (popsize) # noqa: UP031 assert maxstep is not None and isinstance(maxstep, int) ret += "# The Max step for iteration\n" - ret += "MaxStep = %d\n" % (maxstep) + ret += "MaxStep = %d\n" % (maxstep) # noqa: UP031 ret += "#It determines which method should be adopted in generation the random structure. \n" ret += "GenType= 1 \n" ret += "# 1 under symmetric constraints\n" @@ -80,7 +80,7 @@ def make_calypso_input( ret += "# If GenType=3 or 4, it determined the small unit to grow the whole structure\n" ret += "# It determines which local optimization method should be interfaced in the simulation.\n" assert icode is not None and isinstance(icode, int) - ret += "ICode= %d\n" % (icode) + ret += "ICode= %d\n" % (icode) # noqa: UP031 ret += "# ICode= 1 interfaced with VASP\n" ret += "# ICode= 2 interfaced with SIESTA\n" ret += "# ICode= 3 interfaced with GULP\n" @@ -122,7 +122,7 @@ def make_calypso_input( ret += "# The Variation Range for each type atom \n" ret += "@CtrlRange\n" for ttemp in ctrlrange: - ret += "%4s \n" % (" ".join(list(map(str, ttemp)))) + ret += "%4s \n" % (" ".join(list(map(str, ttemp)))) # noqa: UP031 ret += "@end\n" ret += "###################End Parameters for VSC ##########################\n" return ret @@ -226,14 +226,14 @@ def _make_model_devi_native_calypso(iter_index, model_devi_jobs, calypso_run_opt def write_model_devi_out(devi, fname): assert devi.shape[1] == 8 # assert devi.shape[1] == 7 - header = "%5s" % "step" + header = "%5s" % "step" # noqa: UP031 for item in "vf": - header += "%16s%16s%16s" % ( + header += "%16s%16s%16s" % ( # noqa: UP031 f"max_devi_{item}", f"min_devi_{item}", f"avg_devi_{item}", ) - header += "%16s" % "min_dis" + header += "%16s" % "min_dis" # noqa: UP031 np.savetxt( fname, devi, diff --git a/dpgen/generator/lib/pwmat.py b/dpgen/generator/lib/pwmat.py index 6e3e10805..983426aa7 100644 --- a/dpgen/generator/lib/pwmat.py +++ b/dpgen/generator/lib/pwmat.py @@ -12,7 +12,7 @@ def _reciprocal_box(box): def _make_pwmat_kp_mp(kpoints): ret = "" - ret += "%d %d %d 0 0 0 " % (kpoints[0], kpoints[1], kpoints[2]) + ret += "%d %d %d 0 0 0 " % (kpoints[0], kpoints[1], kpoints[2]) # noqa: UP031 return ret diff --git a/dpgen/generator/lib/pwscf.py b/dpgen/generator/lib/pwscf.py index ffbf19a44..0883456cc 100644 --- a/dpgen/generator/lib/pwscf.py +++ b/dpgen/generator/lib/pwscf.py @@ -32,8 +32,8 @@ def make_pwscf_01_runctrl_dict(sys_data, idict): lines.append("&system") lines += _convert_dict(idict["system"]) lines.append("ibrav=0,") - lines.append("nat=%d," % tot_natoms) - lines.append("ntyp=%d," % ntypes) + lines.append("nat=%d," % tot_natoms) # noqa: UP031 + lines.append("ntyp=%d," % ntypes) # noqa: UP031 lines.append("/") if "electrons" in idict: lines.append("&electrons") @@ -62,8 +62,8 @@ def _make_pwscf_01_runctrl(sys_data, ecut, ediff, smearing, degauss): ret += f"ts_vdw_econv_thr={str(ediff)},\n" ret += "nosym=.TRUE.,\n" ret += "ibrav=0,\n" - ret += "nat=%d,\n" % tot_natoms - ret += "ntyp=%d,\n" % ntypes + ret += "nat=%d,\n" % tot_natoms # noqa: UP031 + ret += "ntyp=%d,\n" % ntypes # noqa: UP031 if degauss is not None: ret += f"degauss={degauss:f},\n" if smearing is not None: @@ -136,9 +136,9 @@ def _make_pwscf_04_kpoints(sys_data, kspacing): else: ret += "K_POINTS { automatic }\n" for ii in range(3): - ret += "%d " % kpoints[ii] + ret += "%d " % kpoints[ii] # noqa: UP031 for ii in range(3): - ret += "%d " % _kshift(kpoints[ii]) + ret += "%d " % _kshift(kpoints[ii]) # noqa: UP031 ret += "\n" return ret diff --git a/dpgen/generator/lib/run_calypso.py b/dpgen/generator/lib/run_calypso.py index 0e4744471..dbff1f0cb 100644 --- a/dpgen/generator/lib/run_calypso.py +++ b/dpgen/generator/lib/run_calypso.py @@ -80,7 +80,7 @@ def gen_structures( ftag.close() os.remove("step") fstep = open("step", "w") - fstep.write("%12s" % str(PickUpStep)) + fstep.write("%12s" % str(PickUpStep)) # noqa: UP031 fstep.close() else: PickUpStep = 1 @@ -103,24 +103,25 @@ def gen_structures( for pop in range(ii * int(popsize), (ii + 1) * int(popsize)): try: - os.mkdir("task.%03d" % pop) + os.mkdir("task.%03d" % pop) # noqa: UP031 except Exception: - shutil.rmtree("task.%03d" % pop) - os.mkdir("task.%03d" % pop) + shutil.rmtree("task.%03d" % pop) # noqa: UP031 + os.mkdir("task.%03d" % pop) # noqa: UP031 shutil.copyfile( "calypso_run_opt.py", - os.path.join("task.%03d" % pop, "calypso_run_opt.py"), + os.path.join("task.%03d" % pop, "calypso_run_opt.py"), # noqa: UP031 ) shutil.copyfile( "check_outcar.py", - os.path.join("task.%03d" % pop, "check_outcar.py"), + os.path.join("task.%03d" % pop, "check_outcar.py"), # noqa: UP031 ) shutil.copyfile( f"POSCAR_{str(pop - ii * int(popsize) + 1)}", - os.path.join("task.%03d" % (pop), "POSCAR"), + os.path.join("task.%03d" % (pop), "POSCAR"), # noqa: UP031 ) shutil.copyfile( - "input.dat", os.path.join("task.%03d" % pop, "input.dat") + "input.dat", + os.path.join("task.%03d" % pop, "input.dat"), # noqa: UP031 ) # for iii in range(1,popsize+1): # shutil.copyfile('POSCAR_%s'%str(iii),os.path.join('task.%03d'%(iii-1),'POSCAR')) @@ -166,25 +167,25 @@ def gen_structures( os.path.join(sstep, f"POSCAR_{str(jjj + 1 - ii * int(popsize))}"), ) shutil.copyfile( - os.path.join("task.%03d" % (jjj), "OUTCAR"), + os.path.join("task.%03d" % (jjj), "OUTCAR"), # noqa: UP031 os.path.join(sstep, f"OUTCAR_{str(jjj + 1 - ii * int(popsize))}"), ) shutil.copyfile( - os.path.join("task.%03d" % (jjj), "CONTCAR"), + os.path.join("task.%03d" % (jjj), "CONTCAR"), # noqa: UP031 os.path.join(sstep, f"CONTCAR_{str(jjj + 1 - ii * int(popsize))}"), ) # to run calypso directory shutil.copyfile( - os.path.join("task.%03d" % (jjj), "OUTCAR"), + os.path.join("task.%03d" % (jjj), "OUTCAR"), # noqa: UP031 f"OUTCAR_{str(jjj + 1 - ii * int(popsize))}", ) shutil.copyfile( - os.path.join("task.%03d" % (jjj), "CONTCAR"), + os.path.join("task.%03d" % (jjj), "CONTCAR"), # noqa: UP031 f"CONTCAR_{str(jjj + 1 - ii * int(popsize))}", ) # to traj shutil.copyfile( - os.path.join("task.%03d" % (jjj), "traj.traj"), + os.path.join("task.%03d" % (jjj), "traj.traj"), # noqa: UP031 os.path.join("traj", f"{str(jjj + 1)}.traj"), ) @@ -232,24 +233,25 @@ def gen_structures( for idx, name in enumerate(name_list): shutil.copyfile(name, "POSCAR_%s" % (idx + 1)) try: - os.mkdir("task.%04d" % (idx + 1)) + os.mkdir("task.%04d" % (idx + 1)) # noqa: UP031 except Exception: - shutil.rmtree("task.%04d" % (idx + 1)) - os.mkdir("task.%04d" % (idx + 1)) + shutil.rmtree("task.%04d" % (idx + 1)) # noqa: UP031 + os.mkdir("task.%04d" % (idx + 1)) # noqa: UP031 shutil.copyfile( "calypso_run_opt.py", - os.path.join("task.%04d" % (idx + 1), "calypso_run_opt.py"), + os.path.join("task.%04d" % (idx + 1), "calypso_run_opt.py"), # noqa: UP031 ) shutil.copyfile( "check_outcar.py", - os.path.join("task.%04d" % (idx + 1), "check_outcar.py"), + os.path.join("task.%04d" % (idx + 1), "check_outcar.py"), # noqa: UP031 ) shutil.copyfile( f"POSCAR_{str(idx + 1)}", - os.path.join("task.%04d" % (idx + 1), "POSCAR"), + os.path.join("task.%04d" % (idx + 1), "POSCAR"), # noqa: UP031 ) shutil.copyfile( - "input.dat", os.path.join("task.%04d" % (idx + 1), "input.dat") + "input.dat", + os.path.join("task.%04d" % (idx + 1), "input.dat"), # noqa: UP031 ) # sys.exit() @@ -293,25 +295,25 @@ def gen_structures( os.path.join("opt", f"POSCAR_{str(jjj + 1)}"), ) shutil.copyfile( - os.path.join("task.%04d" % (jjj + 1), "OUTCAR"), + os.path.join("task.%04d" % (jjj + 1), "OUTCAR"), # noqa: UP031 os.path.join("opt", f"OUTCAR_{str(jjj + 1)}"), ) shutil.copyfile( - os.path.join("task.%04d" % (jjj + 1), "CONTCAR"), + os.path.join("task.%04d" % (jjj + 1), "CONTCAR"), # noqa: UP031 os.path.join("opt", f"CONTCAR_{str(jjj + 1)}"), ) # to run calypso directory shutil.copyfile( - os.path.join("task.%04d" % (jjj + 1), "OUTCAR"), + os.path.join("task.%04d" % (jjj + 1), "OUTCAR"), # noqa: UP031 f"OUTCAR_{str(jjj + 1)}", ) shutil.copyfile( - os.path.join("task.%04d" % (jjj + 1), "CONTCAR"), + os.path.join("task.%04d" % (jjj + 1), "CONTCAR"), # noqa: UP031 f"CONTCAR_{str(jjj + 1)}", ) # to traj shutil.copyfile( - os.path.join("task.%04d" % (jjj + 1), "traj.traj"), + os.path.join("task.%04d" % (jjj + 1), "traj.traj"), # noqa: UP031 os.path.join("traj", f"{str(jjj + 1)}.traj"), ) @@ -338,7 +340,8 @@ def gen_main(iter_index, jdata, mdata, caly_run_opt_list, gen_idx): work_path = os.path.join(iter_name, model_devi_name) current_gen_path = os.path.join( - work_path, "%s.%03d" % (calypso_run_opt_name, int(gen_idx)) + work_path, + "%s.%03d" % (calypso_run_opt_name, int(gen_idx)), # noqa: UP031 ) if current_gen_path not in caly_run_opt_list: dlog.info( @@ -404,7 +407,7 @@ def analysis(iter_index, jdata, calypso_model_devi_path): write_vasp( os.path.join( traj_pos_path, - "%d.%03d.%03d.poscar" % (int(press_num), int(traj_num), int(idx)), + "%d.%03d.%03d.poscar" % (int(press_num), int(traj_num), int(idx)), # noqa: UP031 ), traj, ) @@ -430,7 +433,7 @@ def analysis(iter_index, jdata, calypso_model_devi_path): split_lists = glob.glob(os.path.join(deepmd_data_path, "*")) for i, split_list in enumerate(split_lists): - strus_path = os.path.join(calypso_model_devi_path, "%03d.structures" % i) + strus_path = os.path.join(calypso_model_devi_path, "%03d.structures" % i) # noqa: UP031 if not os.path.exists(strus_path): shutil.copytree(split_list, strus_path) else: diff --git a/dpgen/generator/lib/siesta.py b/dpgen/generator/lib/siesta.py index d0277347c..7ca725011 100644 --- a/dpgen/generator/lib/siesta.py +++ b/dpgen/generator/lib/siesta.py @@ -9,8 +9,8 @@ def _make_siesta_01_common(sys_data, fp_params): ret = "" ret += "SystemName system\n" ret += "SystemLabel system\n" - ret += "NumberOfAtoms %d\n" % tot_natoms - ret += "NumberOfSpecies %d\n" % ntypes + ret += "NumberOfAtoms %d\n" % tot_natoms # noqa: UP031 + ret += "NumberOfSpecies %d\n" % ntypes # noqa: UP031 ret += "\n" ret += "WriteForces T\n" ret += "WriteCoorStep T\n" @@ -30,7 +30,7 @@ def _make_siesta_01_common(sys_data, fp_params): ret += f"DM.MixingWeight {mixingWeight:f}\n" if "NumberPulay" in fp_params.keys(): NumberPulay = fp_params["NumberPulay"] - ret += "DM.NumberPulay %d\n" % NumberPulay + ret += "DM.NumberPulay %d\n" % NumberPulay # noqa: UP031 ret += "DM.UseSaveDM true\n" ret += "XC.functional GGA\n" ret += "XC.authors PBE\n" @@ -78,15 +78,15 @@ def _make_siesta_03_kpoint(sys_data, fp_param): ret = "" ret += "%block kgrid_Monkhorst_Pack\n" - ret += "%d" % kpoints[0] + ret += "%d" % kpoints[0] # noqa: UP031 ret += "\t0\t0\t0.0\n" ret += "0\t" - ret += "%d" % kpoints[1] + ret += "%d" % kpoints[1] # noqa: UP031 ret += "\t0\t0.0\n" ret += "0\t0\t" - ret += "%d" % kpoints[2] + ret += "%d" % kpoints[2] # noqa: UP031 ret += "\t0.0\n" ret += "%endblock kgrid_Monkhorst_Pack\n" @@ -118,7 +118,7 @@ def _make_siesta_04_ucVectorCoord(sys_data): cc = 0 for ii in range(ntypes): for jj in range(atom_numbs[ii]): - ret += "%f %f %f %d %s\n" % ( + ret += "%f %f %f %d %s\n" % ( # noqa: UP031 coordinates[cc][0], coordinates[cc][1], coordinates[cc][2], diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index 6b9b3683f..9757d5368 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -23,7 +23,7 @@ def create_path(path): dirname = os.path.dirname(path) counter = 0 while True: - bk_dirname = dirname + ".bk%03d" % counter + bk_dirname = dirname + ".bk%03d" % counter # noqa: UP031 if not os.path.isdir(bk_dirname): shutil.move(dirname, bk_dirname) break @@ -74,7 +74,7 @@ def log_task(message): def record_iter(record, ii, jj): with open(record, "a") as frec: - frec.write("%d %d\n" % (ii, jj)) + frec.write("%d %d\n" % (ii, jj)) # noqa: UP031 def symlink_user_forward_files(mdata, task_type, work_path, task_format=None): diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 0dd3fb02f..3cdf05a24 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -202,7 +202,7 @@ def copy_model(numb_model, prv_iter_index, cur_iter_index, suffix=".pb"): os.symlink(os.path.relpath(prv_train_task), train_task_fmt % ii) os.symlink( os.path.join(train_task_fmt % ii, f"frozen_model{suffix}"), - "graph.%03d%s" % (ii, suffix), + "graph.%03d%s" % (ii, suffix), # noqa: UP031 ) os.chdir(cwd) with open(os.path.join(cur_train_path, "copied"), "w") as fp: @@ -338,7 +338,7 @@ def make_train_dp(iter_index, jdata, mdata): and iter_index > 0 and _check_skip_train(model_devi_jobs[iter_index - 1]) ): - log_task("skip training at step %d " % (iter_index - 1)) + log_task("skip training at step %d " % (iter_index - 1)) # noqa: UP031 copy_model(numb_models, iter_index - 1, iter_index, suffix) return else: @@ -432,7 +432,7 @@ def make_train_dp(iter_index, jdata, mdata): number_old_frames += nframes if nframes < fp_task_min: log_task( - "nframes (%d) in data sys %s is too small, skip" % (nframes, jj) + "nframes (%d) in data sys %s is too small, skip" % (nframes, jj) # noqa: UP031 ) continue for sys_single in sys_paths: @@ -513,7 +513,7 @@ def make_train_dp(iter_index, jdata, mdata): jinput["training"]["stop_batch"] = training_reuse_stop_batch if Version("1") <= Version(mdata["deepmd_version"]) < Version("2"): jinput["training"]["auto_prob_style"] = ( - "prob_sys_size; 0:%d:%f; %d:%d:%f" + "prob_sys_size; 0:%d:%f; %d:%d:%f" # noqa: UP031 % ( old_range, training_reuse_old_ratio, @@ -524,7 +524,7 @@ def make_train_dp(iter_index, jdata, mdata): ) elif Version("2") <= Version(mdata["deepmd_version"]) < Version("3"): jinput["training"]["training_data"]["auto_prob"] = ( - "prob_sys_size; 0:%d:%f; %d:%d:%f" + "prob_sys_size; 0:%d:%f; %d:%d:%f" # noqa: UP031 % ( old_range, training_reuse_old_ratio, @@ -649,7 +649,7 @@ def make_train_dp(iter_index, jdata, mdata): iter0_models += [os.path.abspath(ii) for ii in model_is] if training_init_model: assert numb_models == len(iter0_models), ( - "training_iter0_model should be provided, and the number of models should be equal to %d" + "training_iter0_model should be provided, and the number of models should be equal to %d" # noqa: UP031 % numb_models ) for ii in range(len(iter0_models)): @@ -953,7 +953,7 @@ def post_train_dp(iter_index, jdata, mdata): if jdata.get("dp_compress", False): model_name = f"frozen_model_compressed{suffix}" - ofile = os.path.join(work_path, "graph.%03d%s" % (ii, suffix)) + ofile = os.path.join(work_path, "graph.%03d%s" % (ii, suffix)) # noqa: UP031 task_file = os.path.join(train_task_fmt % ii, model_name) if os.path.isfile(ofile): os.remove(ofile) @@ -1067,7 +1067,7 @@ def find_only_one_key(lmp_lines, key): if len(words) >= nkey and words[:nkey] == key: found.append(idx) if len(found) > 1: - raise RuntimeError("found %d keywords %s" % (len(found), key)) + raise RuntimeError("found %d keywords %s" % (len(found), key)) # noqa: UP031 if len(found) == 0: raise RuntimeError(f"failed to find keyword {key}") return found[0] @@ -1079,14 +1079,14 @@ def revise_lmp_input_model( idx = find_only_one_key(lmp_lines, ["pair_style", "deepmd"]) graph_list = " ".join(task_model_list) if Version(deepmd_version) < Version("1"): - lmp_lines[idx] = "pair_style deepmd %s %d model_devi.out\n" % ( + lmp_lines[idx] = "pair_style deepmd %s %d model_devi.out\n" % ( # noqa: UP031 graph_list, trj_freq, ) else: if use_ele_temp == 0: lmp_lines[idx] = ( - "pair_style deepmd %s out_freq %d out_file model_devi.out\n" + "pair_style deepmd %s out_freq %d out_file model_devi.out\n" # noqa: UP031 % ( graph_list, trj_freq, @@ -1094,7 +1094,7 @@ def revise_lmp_input_model( ) elif use_ele_temp == 1: lmp_lines[idx] = ( - "pair_style deepmd %s out_freq %d out_file model_devi.out fparam ${ELE_TEMP}\n" + "pair_style deepmd %s out_freq %d out_file model_devi.out fparam ${ELE_TEMP}\n" # noqa: UP031 % ( graph_list, trj_freq, @@ -1107,12 +1107,12 @@ def revise_lmp_input_dump(lmp_lines, trj_freq, model_devi_merge_traj=False): idx = find_only_one_key(lmp_lines, ["dump", "dpgen_dump"]) if model_devi_merge_traj: lmp_lines[idx] = ( - "dump dpgen_dump all custom %d all.lammpstrj id type x y z\n" + "dump dpgen_dump all custom %d all.lammpstrj id type x y z\n" # noqa: UP031 % trj_freq ) else: lmp_lines[idx] = ( - "dump dpgen_dump all custom %d traj/*.lammpstrj id type x y z\n" + "dump dpgen_dump all custom %d traj/*.lammpstrj id type x y z\n" # noqa: UP031 % trj_freq ) @@ -1236,10 +1236,10 @@ def make_model_devi(iter_index, jdata, mdata): # calypso_run_opt_path = ['gen_struc_analy.000','gen_struc_analy.001'] for temp_idx in range(number_of_pressure): calypso_run_opt_path.append( - "%s.%03d" % (_calypso_run_opt_path, temp_idx) + "%s.%03d" % (_calypso_run_opt_path, temp_idx) # noqa: UP031 ) elif not jdata.get("vsc", False): - calypso_run_opt_path.append("%s.%03d" % (_calypso_run_opt_path, 0)) + calypso_run_opt_path.append("%s.%03d" % (_calypso_run_opt_path, 0)) # noqa: UP031 # mode 2: control each iteration to generate structures in specific way # by providing model_devi_jobs key @@ -1251,7 +1251,7 @@ def make_model_devi(iter_index, jdata, mdata): pressures_list = cur_job.get("PSTRESS", [0.0001]) for temp_idx in range(len(pressures_list)): calypso_run_opt_path.append( - "%s.%03d" % (_calypso_run_opt_path, temp_idx) + "%s.%03d" % (_calypso_run_opt_path, temp_idx) # noqa: UP031 ) # to different directory # calypso_run_opt_path = ['gen_struc_analy.000','gen_struc_analy.001','gen_struc_analy.002',] @@ -1885,7 +1885,7 @@ def _make_model_devi_amber( # link parm file for ii, pp in enumerate(parm7): - os.symlink(pp, os.path.join(work_path, "qmmm%d.parm7" % ii)) + os.symlink(pp, os.path.join(work_path, "qmmm%d.parm7" % ii)) # noqa: UP031 # TODO: consider writing input in json instead of a given file # mdin mdin = jdata["mdin"] @@ -1899,7 +1899,7 @@ def _make_model_devi_amber( for ii, pp in enumerate(mdin): with ( open(pp) as f, - open(os.path.join(work_path, "init%d.mdin" % ii), "w") as fw, + open(os.path.join(work_path, "init%d.mdin" % ii), "w") as fw, # noqa: UP031 ): mdin_str = f.read() # freq, nstlim, qm_region, qm_theory, qm_charge, rcut, graph @@ -1919,7 +1919,7 @@ def _make_model_devi_amber( # graph for jj, mm in enumerate(task_model_list): # replace graph - mdin_str = mdin_str.replace("@GRAPH_FILE%d@" % jj, mm) + mdin_str = mdin_str.replace("@GRAPH_FILE%d@" % jj, mm) # noqa: UP031 fw.write(mdin_str) # disang - list disang = jdata["disang"] @@ -1975,7 +1975,7 @@ def _make_model_devi_amber( for ii, rr in enumerate(r): if isinstance(rr, Iterable) and not isinstance(rr, str): raise RuntimeError( - "rr should not be iterable! sys: %d rr: %s r: %s" + "rr should not be iterable! sys: %d rr: %s r: %s" # noqa: UP031 % (sys_idx[sys_counter], str(rr), str(r)) ) tl = tl.replace("RVAL" + str(ii + 1), str(rr)) @@ -2074,7 +2074,7 @@ def run_md_model_devi(iter_index, jdata, mdata): grp_name = gromacs_settings.get("group_name", "Other") trj_freq = cur_job.get("trj_freq", 10) - command = "%s grompp -f %s -p %s -c %s -o %s -maxwarn %d" % ( + command = "%s grompp -f %s -p %s -c %s -o %s -maxwarn %d" % ( # noqa: UP031 model_devi_exec, mdp_filename, topol_filename, @@ -2405,12 +2405,12 @@ def _select_by_model_devi_standard( else: if model_devi_engine == "calypso": dlog.info( - "ase opt traj %s frame %d with f devi %f does not belong to either accurate, candidiate and failed " + "ase opt traj %s frame %d with f devi %f does not belong to either accurate, candidiate and failed " # noqa: UP031 % (tt, ii, all_conf[ii][4]) ) else: raise RuntimeError( - "md traj %s frame %d with f devi %f does not belong to either accurate, candidiate and failed, it should not happen" + "md traj %s frame %d with f devi %f does not belong to either accurate, candidiate and failed, it should not happen" # noqa: UP031 % (tt, ii, all_conf[ii][4]) ) else: @@ -3080,7 +3080,7 @@ def make_pwmat_input(jdata, filename): fp.write("job=scf\n") fp_pp_files = jdata["fp_pp_files"] for idx, ii in enumerate(fp_pp_files): - fp.write("IN.PSP%d = %s\n" % (idx + 1, ii)) + fp.write("IN.PSP%d = %s\n" % (idx + 1, ii)) # noqa: UP031 if "OUT.MLMD" in input or "out.mlmd" in input: return input else: @@ -3760,7 +3760,7 @@ def make_fp_amber_diff(iter_index: int, jdata: dict): .replace("%qm_region%", qm_region[ii]) .replace("%qm_charge%", str(qm_charge[ii])) ) - with open("low_level%d.mdin" % ii, "w") as f: + with open("low_level%d.mdin" % ii, "w") as f: # noqa: UP031 f.write(mdin_new_str) mdin_new_str = ( @@ -3768,18 +3768,18 @@ def make_fp_amber_diff(iter_index: int, jdata: dict): .replace("%qm_region%", qm_region[ii]) .replace("%qm_charge%", str(qm_charge[ii])) ) - with open("high_level%d.mdin" % ii, "w") as f: + with open("high_level%d.mdin" % ii, "w") as f: # noqa: UP031 f.write(mdin_new_str) parm7 = jdata["parm7"] parm7_prefix = jdata.get("parm7_prefix", "") parm7 = [os.path.join(parm7_prefix, pp) for pp in parm7] for ii, pp in enumerate(parm7): - os.symlink(pp, "qmmm%d.parm7" % ii) + os.symlink(pp, "qmmm%d.parm7" % ii) # noqa: UP031 rst7_prefix = jdata.get("sys_configs_prefix", "") for ii, ss in enumerate(jdata["sys_configs"]): - os.symlink(os.path.join(rst7_prefix, ss[0]), "init%d.rst7" % ii) + os.symlink(os.path.join(rst7_prefix, ss[0]), "init%d.rst7" % ii) # noqa: UP031 with open("qm_region", "w") as f: f.write("\n".join(qm_region)) @@ -4204,7 +4204,7 @@ def post_fp_check_fail(iter_index, jdata, rfailed=None): nfail = ntask - nframe rfail = float(nfail) / float(ntask) - dlog.info("failed tasks: %6d in %6d %6.2f %% " % (nfail, ntask, rfail * 100.0)) + dlog.info("failed tasks: %6d in %6d %6.2f %% " % (nfail, ntask, rfail * 100.0)) # noqa: UP031 if rfail > ratio_failed: raise RuntimeError("find too many unsuccessfully terminated jobs") @@ -4296,11 +4296,11 @@ def post_fp_vasp(iter_index, jdata, rfailed=None): if tcount == 0: rfail = 0.0 - dlog.info("failed frame: %6d in %6d " % (icount, tcount)) + dlog.info("failed frame: %6d in %6d " % (icount, tcount)) # noqa: UP031 else: rfail = float(icount) / float(tcount) dlog.info( - "failed frame: %6d in %6d %6.2f %% " % (icount, tcount, rfail * 100.0) + "failed frame: %6d in %6d %6.2f %% " % (icount, tcount, rfail * 100.0) # noqa: UP031 ) if rfail > ratio_failed: @@ -4535,11 +4535,11 @@ def post_fp_cp2k(iter_index, jdata, rfailed=None): if tcount == 0: rfail = 0.0 - dlog.info("failed frame: %6d in %6d " % (tcount - icount, tcount)) + dlog.info("failed frame: %6d in %6d " % (tcount - icount, tcount)) # noqa: UP031 else: rfail = float(tcount - icount) / float(tcount) dlog.info( - "failed frame: %6d in %6d %6.2f %% " + "failed frame: %6d in %6d %6.2f %% " # noqa: UP031 % (tcount - icount, tcount, rfail * 100.0) ) @@ -4783,7 +4783,7 @@ def run_iter(param_file, machine_file): iter_rec = [int(x) for x in line.split()] if len(iter_rec) == 0: raise ValueError("There should not be blank lines in record.dpgen.") - dlog.info("continue from iter %03d task %02d" % (iter_rec[0], iter_rec[1])) + dlog.info("continue from iter %03d task %02d" % (iter_rec[0], iter_rec[1])) # noqa: UP031 cont = True ii = -1 @@ -4796,7 +4796,7 @@ def run_iter(param_file, machine_file): for jj in range(numb_task): if ii * max_tasks + jj <= iter_rec[0] * max_tasks + iter_rec[1]: continue - task_name = "task %02d" % jj + task_name = "task %02d" % jj # noqa: UP031 sepline(f"{iter_name} {task_name}", "-") if jj == 0: log_iter("make_train", ii, jj) @@ -4829,7 +4829,7 @@ def run_iter(param_file, machine_file): log_iter("post_fp", ii, jj) post_fp(ii, jdata) else: - raise RuntimeError("unknown task %d, something wrong" % jj) + raise RuntimeError("unknown task %d, something wrong" % jj) # noqa: UP031 record_iter(record, ii, jj) diff --git a/dpgen/simplify/simplify.py b/dpgen/simplify/simplify.py index 30b3472ac..2bc88e1f8 100644 --- a/dpgen/simplify/simplify.py +++ b/dpgen/simplify/simplify.py @@ -124,7 +124,7 @@ def init_model_dp(iter_index, jdata, mdata): iter0_models += [os.path.abspath(ii) for ii in model_is] numb_models = jdata["numb_models"] assert numb_models == len(iter0_models), ( - "training_iter0_model_path should be provided, and the number of models should be equal to %d" + "training_iter0_model_path should be provided, and the number of models should be equal to %d" # noqa: UP031 % numb_models ) work_path = os.path.join(make_iter_name(iter_index), train_name) @@ -553,7 +553,7 @@ def run_iter(param_file, machine_file): with open(record) as frec: for line in frec: iter_rec = [int(x) for x in line.split()] - dlog.info("continue from iter %03d task %02d" % (iter_rec[0], iter_rec[1])) + dlog.info("continue from iter %03d task %02d" % (iter_rec[0], iter_rec[1])) # noqa: UP031 cont = True ii = -1 @@ -566,7 +566,7 @@ def run_iter(param_file, machine_file): for jj in range(numb_task): if ii * max_tasks + jj <= iter_rec[0] * max_tasks + iter_rec[1]: continue - task_name = "task %02d" % jj + task_name = "task %02d" % jj # noqa: UP031 sepline(f"{iter_name} {task_name}", "-") jdata["model_devi_jobs"] = [{} for _ in range(ii + 1)] if ii == 0 and jj < 6 and (jj >= 3 or not jdata.get("init_data_sys", [])): @@ -617,7 +617,7 @@ def run_iter(param_file, machine_file): else: post_fp(ii, jdata) else: - raise RuntimeError("unknown task %d, something wrong" % jj) + raise RuntimeError("unknown task %d, something wrong" % jj) # noqa: UP031 record_iter(record, ii, jj) diff --git a/dpgen/tools/collect_data.py b/dpgen/tools/collect_data.py index 511dacc24..9c4a18847 100755 --- a/dpgen/tools/collect_data.py +++ b/dpgen/tools/collect_data.py @@ -31,7 +31,7 @@ def collect_data(target_folder, param_file, output, verbose=True): sys = jdata["sys_configs"] if verbose: max_str_len = max([len(str(ii)) for ii in sys]) - ptr_fmt = "%%%ds %%6d" % (max_str_len + 5) + ptr_fmt = "%%%ds %%6d" % (max_str_len + 5) # noqa: UP031 # collect systems from iter dirs coll_sys = [[] for ii in sys] numb_sys = len(sys) @@ -50,7 +50,7 @@ def collect_data(target_folder, param_file, output, verbose=True): if len(ii) == 0: continue # link iter data dirs - out_sys_path = os.path.join(output, "system.%03d" % idx) + out_sys_path = os.path.join(output, "system.%03d" % idx) # noqa: UP031 os.makedirs(out_sys_path, exist_ok=True) cwd_ = os.getcwd() os.chdir(out_sys_path) diff --git a/dpgen/tools/relabel.py b/dpgen/tools/relabel.py index 9b64a3edd..78d5c689e 100755 --- a/dpgen/tools/relabel.py +++ b/dpgen/tools/relabel.py @@ -117,14 +117,14 @@ def create_init_tasks(target_folder, param_file, output, fp_json, verbose=True): os.path.join(init_data_prefix, ii), fmt="deepmd/npy", type_map=type_map ) nframes = sys.get_nframes() - sys_dir = os.path.join(output, "init_system.%03d" % idx) + sys_dir = os.path.join(output, "init_system.%03d" % idx) # noqa: UP031 os.makedirs(sys_dir, exist_ok=True) if verbose: print("# working on " + sys_dir) with open(os.path.join(sys_dir, "record"), "w") as fp: fp.write(os.path.join(init_data_prefix, ii) + "\n") for ff in range(nframes): - task_dir = os.path.join(sys_dir, "task.%06d" % ff) + task_dir = os.path.join(sys_dir, "task.%06d" % ff) # noqa: UP031 os.makedirs(task_dir, exist_ok=True) sys.to_vasp_poscar(os.path.join(task_dir, "POSCAR"), frame_idx=ff) # make fp @@ -192,7 +192,7 @@ def create_tasks( ) iter_tasks.sort() if verbose: - print("# check iter " + ii + " with %6d tasks" % len(iter_tasks)) + print("# check iter " + ii + " with %6d tasks" % len(iter_tasks)) # noqa: UP031 for jj in iter_tasks: sys_idx = int(os.path.basename(jj).split(".")[-2]) sys_tasks[sys_idx].append(jj) @@ -215,7 +215,7 @@ def create_tasks( os.path.join(ii, "01.model_devi", linked_keys[-3], "input.lammps") ) human_record = ( - "iter: %s system: %s model_devi_task: %s frame: %6d fp_task: %s ens: %s temp: %10.2f pres: %10.2f" + "iter: %s system: %s model_devi_task: %s frame: %6d fp_task: %s ens: %s temp: %10.2f pres: %10.2f" # noqa: UP031 % ( task_record_keys[1], task_record_keys[3], @@ -243,14 +243,14 @@ def create_tasks( if fp_style == "siesta": copy_pp_files(output, fp_pp_path, fp_pp_files) for si in range(numb_sys): - sys_dir = os.path.join(output, "system.%03d" % si) + sys_dir = os.path.join(output, "system.%03d" % si) # noqa: UP031 if verbose: print("# working on " + sys_dir) for tt, rr in zip(sys_tasks[si], sys_tasks_record[si]): # copy poscar source_path = os.path.join((f"iter.{rr.split()[1]}/02.fp"), rr.split()[9]) source_file = os.path.join(source_path, "POSCAR") - target_path = os.path.join(sys_dir, "task.%06d" % sys_tasks_cc[si]) + target_path = os.path.join(sys_dir, "task.%06d" % sys_tasks_cc[si]) # noqa: UP031 sys_tasks_cc[si] += 1 os.makedirs(target_path, exist_ok=True) target_file = os.path.join(target_path, "POSCAR") diff --git a/dpgen/tools/stat_sys.py b/dpgen/tools/stat_sys.py index c2f704bb1..b687bbe4f 100644 --- a/dpgen/tools/stat_sys.py +++ b/dpgen/tools/stat_sys.py @@ -39,7 +39,7 @@ def stat_sys(target_folder, param_file="param.json", verbose=True, mute=False): ) iter_tasks.sort() if verbose: - print("# check iter " + ii + " with %6d tasks" % len(iter_tasks)) + print("# check iter " + ii + " with %6d tasks" % len(iter_tasks)) # noqa: UP031 for jj in iter_tasks: sys_idx = int(os.path.basename(jj).split(".")[-2]) sys_tasks_count[sys_idx] += 1 @@ -72,7 +72,7 @@ def stat_sys(target_folder, param_file="param.json", verbose=True, mute=False): for ii in sys_tasks_all: ii.sort() max_str_len = max([len(str(ii)) for ii in sys]) - sys_fmt = "%%%ds %%6d" % (max_str_len + 1) + sys_fmt = "%%%ds %%6d" % (max_str_len + 1) # noqa: UP031 blank = max_str_len - 50 str_blk = "" for ii in range(blank): diff --git a/tests/auto_test/data.vasp.kp.gf/make_kp_test.py b/tests/auto_test/data.vasp.kp.gf/make_kp_test.py index dddf45840..7006d0709 100644 --- a/tests/auto_test/data.vasp.kp.gf/make_kp_test.py +++ b/tests/auto_test/data.vasp.kp.gf/make_kp_test.py @@ -22,5 +22,5 @@ def make_one(out_dir): ntest = 30 for ii in range(ntest): - out_dir = "test.%03d" % ii + out_dir = "test.%03d" % ii # noqa: UP031 make_one(out_dir) diff --git a/tests/generator/comp_sys.py b/tests/generator/comp_sys.py index db37ad843..5f91ff9b8 100644 --- a/tests/generator/comp_sys.py +++ b/tests/generator/comp_sys.py @@ -19,7 +19,7 @@ def test_cell(testCase, system_1, system_2, places=5): system_1.data["cells"][ff][ii][jj], system_2.data["cells"][ff][ii][jj], places=places, - msg="cell[%d][%d][%d] failed" % (ff, ii, jj), + msg="cell[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) @@ -36,7 +36,7 @@ def test_coord(testCase, system_1, system_2, places=5): system_1.data["coords"][ff][ii][jj] / tmp_cell_norm[ff][jj], system_2.data["coords"][ff][ii][jj] / tmp_cell_norm[ff][jj], places=places, - msg="coord[%d][%d][%d] failed" % (ff, ii, jj), + msg="coord[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) @@ -77,7 +77,7 @@ def test_cell(self): self.system_1.data["cells"][ff][ii][jj], self.system_2.data["cells"][ff][ii][jj], places=self.places, - msg="cell[%d][%d][%d] failed" % (ff, ii, jj), + msg="cell[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) def test_coord(self): @@ -98,7 +98,7 @@ def test_coord(self): self.system_2.data["coords"][ff][ii][jj] / tmp_cell_norm[ff][jj], places=self.places, - msg="coord[%d][%d][%d] failed" % (ff, ii, jj), + msg="coord[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) @@ -111,7 +111,7 @@ def test_energy(self): self.system_1.data["energies"][ff], self.system_2.data["energies"][ff], places=self.e_places, - msg="energies[%d] failed" % (ff), + msg="energies[%d] failed" % (ff), # noqa: UP031 ) else: self.assertAlmostEqual( @@ -119,7 +119,7 @@ def test_energy(self): / self.system_2.data["energies"][ff], 1.0, places=self.e_places, - msg="energies[%d] failed" % (ff), + msg="energies[%d] failed" % (ff), # noqa: UP031 ) def test_force(self): @@ -131,7 +131,7 @@ def test_force(self): self.system_1.data["forces"][ff][ii][jj], self.system_2.data["forces"][ff][ii][jj], places=self.f_places, - msg="forces[%d][%d][%d] failed" % (ff, ii, jj), + msg="forces[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) def test_virial(self): @@ -145,5 +145,5 @@ def test_virial(self): self.system_1["virials"][ff][ii][jj], self.system_2["virials"][ff][ii][jj], places=self.v_places, - msg="virials[%d][%d][%d] failed" % (ff, ii, jj), + msg="virials[%d][%d][%d] failed" % (ff, ii, jj), # noqa: UP031 ) diff --git a/tests/generator/gromacs/model_devi_case/model_devi.py b/tests/generator/gromacs/model_devi_case/model_devi.py index 7ce46e301..d9b2273e6 100755 --- a/tests/generator/gromacs/model_devi_case/model_devi.py +++ b/tests/generator/gromacs/model_devi_case/model_devi.py @@ -52,6 +52,6 @@ def write_model_devi_out(system, models, fname=None, trj_freq=10): if not os.path.isdir("traj"): os.mkdir("traj") for i in range(system.get_nframes()): - system[i].to_gromacs_gro("traj/%d.gromacstrj" % (trj_freq * i)) + system[i].to_gromacs_gro("traj/%d.gromacstrj" % (trj_freq * i)) # noqa: UP031 models = [DP(f"../graph.{ii:03}.pb") for ii in range(4)] write_model_devi_out(system, models, "model_devi.out", trj_freq) diff --git a/tests/generator/test_make_fp.py b/tests/generator/test_make_fp.py index aa01ab5f1..b117efdb0 100644 --- a/tests/generator/test_make_fp.py +++ b/tests/generator/test_make_fp.py @@ -236,7 +236,7 @@ def _write_lammps_dump(sys, dump_file, f_idx=0): fp.write("ITEM: ATOMS id type x y z\n") for ii in range(natoms): fp.write( - "%d %d %f %f %f\n" + "%d %d %f %f %f\n" # noqa: UP031 % (ii + 1, atype[ii] + 1, coord[ii][0], coord[ii][1], coord[ii][2]) ) @@ -263,12 +263,15 @@ def _make_fake_md(idx, md_descript, atom_types, type_map, ele_temp=None): sys.data["coords"] = coords sys.data["cells"] = cells task_dir = os.path.join( - "iter.%06d" % idx, "01.model_devi", "task.%03d.%06d" % (sidx, midx) + "iter.%06d" % idx, # noqa: UP031 + "01.model_devi", + "task.%03d.%06d" % (sidx, midx), # noqa: UP031 ) os.makedirs(os.path.join(task_dir, "traj"), exist_ok=True) for ii in range(nframes): _write_lammps_dump( - sys, os.path.join(task_dir, "traj", "%d.lammpstrj" % ii) + sys, + os.path.join(task_dir, "traj", "%d.lammpstrj" % ii), # noqa: UP031 ) md_out = np.zeros([nframes, 7]) md_out[:, 0] = np.arange(nframes) @@ -301,7 +304,9 @@ def _make_fake_md_merge_traj(idx, md_descript, atom_types, type_map, ele_temp=No sys.data["coords"] = coords sys.data["cells"] = cells task_dir = os.path.join( - "iter.%06d" % idx, "01.model_devi", "task.%03d.%06d" % (sidx, midx) + "iter.%06d" % idx, # noqa: UP031 + "01.model_devi", + "task.%03d.%06d" % (sidx, midx), # noqa: UP031 ) cwd = os.getcwd() os.makedirs(task_dir, exist_ok=True) @@ -327,7 +332,7 @@ def _make_fake_md_merge_traj(idx, md_descript, atom_types, type_map, ele_temp=No def _check_poscars(testCase, idx, fp_task_max, type_map): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 candi_files = glob.glob(os.path.join(fp_path, "candidate.shuffled.*.out")) candi_files.sort() sys_idx = [str(os.path.basename(ii).split(".")[2]) for ii in candi_files] @@ -342,9 +347,11 @@ def _check_poscars(testCase, idx, fp_task_max, type_map): f_idx = f_idx[:fp_task_max] cc = 0 for tt, ff in zip(md_task, f_idx): - traj_file = os.path.join(tt, "traj", "%d.lammpstrj" % int(ff)) + traj_file = os.path.join(tt, "traj", "%d.lammpstrj" % int(ff)) # noqa: UP031 poscar_file = os.path.join( - fp_path, "task.%03d.%06d" % (int(sidx), cc), "POSCAR" + fp_path, + "task.%03d.%06d" % (int(sidx), cc), # noqa: UP031 + "POSCAR", # noqa: UP031 ) cc += 1 sys0 = dpdata.System(traj_file, fmt="lammps/dump", type_map=type_map) @@ -353,7 +360,7 @@ def _check_poscars(testCase, idx, fp_task_max, type_map): def _check_poscars_merge_traj(testCase, idx, fp_task_max, type_map): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 candi_files = glob.glob(os.path.join(fp_path, "candidate.shuffled.*.out")) candi_files.sort() sys_idx = [str(os.path.basename(ii).split(".")[2]) for ii in candi_files] @@ -373,7 +380,9 @@ def _check_poscars_merge_traj(testCase, idx, fp_task_max, type_map): for tt, ff in zip(md_task, f_idx): traj_file = os.path.join(tt, "all.lammpstrj") poscar_file = os.path.join( - fp_path, "task.%03d.%06d" % (int(sidx), cc), "POSCAR" + fp_path, + "task.%03d.%06d" % (int(sidx), cc), # noqa: UP031 + "POSCAR", # noqa: UP031 ) cc += 1 sys0 = dpdata.System(traj_file, fmt="lammps/dump", type_map=type_map) @@ -390,14 +399,14 @@ def _check_poscars_merge_traj(testCase, idx, fp_task_max, type_map): def _check_kpoints_exists(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: testCase.assertTrue(os.path.isfile(os.path.join(ii, "KPOINTS"))) def _check_kpoints(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: kpoints = Kpoints.from_file(os.path.join(os.path.join(ii, "KPOINTS"))) @@ -422,7 +431,7 @@ def _check_kpoints(testCase, idx): def _check_incar_exists(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 # testCase.assertTrue(os.path.isfile(os.path.join(fp_path, 'INCAR'))) tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: @@ -431,7 +440,7 @@ def _check_incar_exists(testCase, idx): def _check_potcar(testCase, idx, fp_pp_path, fp_pp_files): nfile = len(fp_pp_files) - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 for ii in range(nfile): testCase.assertTrue(os.path.isfile(os.path.join(fp_pp_path, fp_pp_files[ii]))) tasks = glob.glob(os.path.join(fp_path, "task.*")) @@ -454,7 +463,7 @@ def _trust_limitation_check(sys_idx, lim): sys_lim = lim return sys_lim - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 candi_files = glob.glob(os.path.join(fp_path, "candidate.shuffled.*.out")) candi_files.sort() sys_idx = [str(os.path.basename(ii).split(".")[2]) for ii in candi_files] @@ -477,7 +486,7 @@ def _trust_limitation_check(sys_idx, lim): def _check_incar(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) cwd = os.getcwd() for ii in tasks: @@ -489,7 +498,7 @@ def _check_incar(testCase, idx): def _check_incar_ele_temp(testCase, idx, ele_temp): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) cwd = os.getcwd() for ii in tasks: @@ -525,7 +534,7 @@ def _check_incar_ele_temp(testCase, idx, ele_temp): def _check_pwscf_input_head(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "input") @@ -540,7 +549,7 @@ def _check_pwscf_input_head(testCase, idx): def _check_abacus_input(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "INPUT") @@ -551,7 +560,7 @@ def _check_abacus_input(testCase, idx): def _check_abacus_kpt(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "KPT") @@ -562,7 +571,7 @@ def _check_abacus_kpt(testCase, idx): def _check_siesta_input_head(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "input") @@ -577,7 +586,7 @@ def _check_siesta_input_head(testCase, idx): def _check_gaussian_input_head(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "input") @@ -592,7 +601,7 @@ def _check_gaussian_input_head(testCase, idx): def _check_cp2k_input_head(testCase, idx, ref_out): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "input.inp") @@ -609,7 +618,7 @@ def _check_cp2k_input_head(testCase, idx, ref_out): def _check_pwmat_input(testCase, idx): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) cwd = os.getcwd() for ii in tasks: @@ -622,7 +631,7 @@ def _check_pwmat_input(testCase, idx): def _check_symlink_user_forward_files(testCase, idx, file): - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) cwd = os.getcwd() for ii in tasks: @@ -702,7 +711,7 @@ def test_make_fp_pwscf_old(self): class TestMakeFPABACUS(unittest.TestCase): def _check_pp(self, idx, fp_pp_path, fp_pp_files): nfile = len(fp_pp_files) - fp_path = os.path.join("iter.%06d" % idx, "02.fp") + fp_path = os.path.join("iter.%06d" % idx, "02.fp") # noqa: UP031 for ii in range(nfile): self.assertTrue(os.path.isfile(os.path.join(fp_pp_path, fp_pp_files[ii]))) tasks = glob.glob(os.path.join(fp_path, "task.*")) @@ -783,7 +792,7 @@ def test_make_fp_abacus_kspacing(self): elif "kspacing" in iline: input_ref[ii] = "kspacing 0.040000 0.050000 0.060000" - fp_path = os.path.join("iter.%06d" % 0, "02.fp", "INPUT") + fp_path = os.path.join("iter.%06d" % 0, "02.fp", "INPUT") # noqa: UP031 tasks = glob.glob(os.path.join(fp_path, "task.*")) for ii in tasks: ifile = os.path.join(ii, "INPUT") @@ -840,7 +849,9 @@ def test_make_fp_amber_diff(self): jdata = json.load(fp) jdata["mdin_prefix"] = os.path.abspath(jdata["mdin_prefix"]) task_dir = os.path.join( - "iter.%06d" % 0, "01.model_devi", "task.%03d.%06d" % (0, 0) + "iter.%06d" % 0, # noqa: UP031 + "01.model_devi", + "task.%03d.%06d" % (0, 0), # noqa: UP031 ) os.makedirs(task_dir, exist_ok=True) with open(os.path.join(task_dir, "rc.mdout"), "w") as f: @@ -1353,7 +1364,7 @@ def test_make_fp_custom(self): fp_task_max = jdata["fp_task_max"] type_map = jdata["type_map"] - fp_path = os.path.join("iter.%06d" % 0, "02.fp") + fp_path = os.path.join("iter.%06d" % 0, "02.fp") # noqa: UP031 candi_files = glob.glob(os.path.join(fp_path, "candidate.shuffled.*.out")) candi_files.sort() sys_idx = [str(os.path.basename(ii).split(".")[2]) for ii in candi_files] @@ -1367,9 +1378,11 @@ def test_make_fp_custom(self): md_task = md_task[:fp_task_max] f_idx = f_idx[:fp_task_max] for cc, (tt, ff) in enumerate(zip(md_task, f_idx)): - traj_file = os.path.join(tt, "traj", "%d.lammpstrj" % int(ff)) + traj_file = os.path.join(tt, "traj", "%d.lammpstrj" % int(ff)) # noqa: UP031 input_file = os.path.join( - fp_path, "task.%03d.%06d" % (int(sidx), cc), input_fn + fp_path, + "task.%03d.%06d" % (int(sidx), cc), # noqa: UP031 + input_fn, # noqa: UP031 ) system1 = dpdata.System(traj_file, "lammps/dump", type_map=type_map) system2 = dpdata.System(input_file, input_fmt, type_map=type_map) diff --git a/tests/generator/test_make_md.py b/tests/generator/test_make_md.py index 22c867a53..6f5cf177d 100644 --- a/tests/generator/test_make_md.py +++ b/tests/generator/test_make_md.py @@ -37,23 +37,24 @@ def _make_fake_models(idx, numb_models): - train_dir = os.path.join("iter.%06d" % idx, "00.train") + train_dir = os.path.join("iter.%06d" % idx, "00.train") # noqa: UP031 os.makedirs(train_dir, exist_ok=True) pwd = os.getcwd() os.chdir(train_dir) for ii in range(numb_models): - os.makedirs("%03d" % ii, exist_ok=True) - with open(os.path.join("%03d" % ii, "forzen_model.pb"), "w") as fp: + os.makedirs("%03d" % ii, exist_ok=True) # noqa: UP031 + with open(os.path.join("%03d" % ii, "forzen_model.pb"), "w") as fp: # noqa: UP031 fp.write(str(ii)) - if not os.path.isfile("graph.%03d.pb" % ii): + if not os.path.isfile("graph.%03d.pb" % ii): # noqa: UP031 os.symlink( - os.path.join("%03d" % ii, "forzen_model.pb"), "graph.%03d.pb" % ii + os.path.join("%03d" % ii, "forzen_model.pb"), # noqa: UP031 + "graph.%03d.pb" % ii, # noqa: UP031 # noqa: UP031 ) os.chdir(pwd) def _check_confs(testCase, idx, jdata): - md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") + md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") # noqa: UP031 tasks = glob.glob(os.path.join(md_dir, "task.*")) tasks.sort() cur_job = jdata["model_devi_jobs"][idx] @@ -81,8 +82,8 @@ def _check_confs(testCase, idx, jdata): def _check_pb(testCase, idx): - md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") - tr_dir = os.path.join("iter.%06d" % idx, "00.train") + md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") # noqa: UP031 + tr_dir = os.path.join("iter.%06d" % idx, "00.train") # noqa: UP031 md_pb = glob.glob(os.path.join(md_dir, "grapb*pb")) tr_pb = glob.glob(os.path.join(tr_dir, "grapb*pb")) md_pb.sort() @@ -92,7 +93,7 @@ def _check_pb(testCase, idx): def _check_traj_dir(testCase, idx): - md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") + md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") # noqa: UP031 tasks = glob.glob(os.path.join(md_dir, "task.*")) tasks.sort() for ii in tasks: @@ -110,7 +111,7 @@ def _get_lammps_pt(lmp_input): def _check_pt(testCase, idx, jdata): - md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") + md_dir = os.path.join("iter.%06d" % idx, "01.model_devi") # noqa: UP031 tasks = glob.glob(os.path.join(md_dir, "task.*")) tasks.sort() cur_job = jdata["model_devi_jobs"][idx] @@ -132,7 +133,7 @@ def _check_pt(testCase, idx, jdata): for ss in ii: for tt in temps: for pp in press: - task_dir = os.path.join(md_dir, "task.%03d.%06d" % (sidx, count)) + task_dir = os.path.join(md_dir, "task.%03d.%06d" % (sidx, count)) # noqa: UP031 lt, lp = _get_lammps_pt(os.path.join(task_dir, "input.lammps")) testCase.assertAlmostEqual(lt, tt) testCase.assertAlmostEqual(lp, pp) @@ -362,7 +363,7 @@ def test_make_model_devi(self): _check_confs(self, 0, jdata) _check_traj_dir(self, 0) # check the first task - md_dir = os.path.join("iter.%06d" % 0, "01.model_devi") + md_dir = os.path.join("iter.%06d" % 0, "01.model_devi") # noqa: UP031 tasks = glob.glob(os.path.join(md_dir, "task.*")) tasks.sort() # each system contains 2 frames @@ -486,7 +487,7 @@ def test_make_model_devi_null(self): _check_confs(self, 0, jdata) _check_traj_dir(self, 0) # check the first task - md_dir = os.path.join("iter.%06d" % 0, "01.model_devi") + md_dir = os.path.join("iter.%06d" % 0, "01.model_devi") # noqa: UP031 tasks = glob.glob(os.path.join(md_dir, "task.*")) # 4 accounts for 2 systems each with 2 frames self.assertEqual(len(tasks), (4)) @@ -697,7 +698,10 @@ def test_restart_from_iter(self): restart_text = "This is the fake restart file to test `restart_from_iter`" with open( os.path.join( - "iter.%06d" % 0, "01.model_devi", "task.000.000000", "rc.rst7" + "iter.%06d" % 0, # noqa: UP031 + "01.model_devi", + "task.000.000000", + "rc.rst7", ), "w", ) as fw: @@ -708,13 +712,16 @@ def test_restart_from_iter(self): self._check_input(1) with open( os.path.join( - "iter.%06d" % 1, "01.model_devi", "task.000.000000", "init.rst7" + "iter.%06d" % 1, # noqa: UP031 + "01.model_devi", + "task.000.000000", + "init.rst7", ) ) as f: assert f.read() == restart_text def _check_input(self, iter_idx: int): - md_dir = os.path.join("iter.%06d" % iter_idx, "01.model_devi") + md_dir = os.path.join("iter.%06d" % iter_idx, "01.model_devi") # noqa: UP031 assert os.path.isfile(os.path.join(md_dir, "init0.mdin")) assert os.path.isfile(os.path.join(md_dir, "qmmm0.parm7")) tasks = glob.glob(os.path.join(md_dir, "task.*")) diff --git a/tests/generator/test_make_train.py b/tests/generator/test_make_train.py index 04d091368..e14819a24 100644 --- a/tests/generator/test_make_train.py +++ b/tests/generator/test_make_train.py @@ -49,7 +49,7 @@ def _comp_sys_files(sys0, sys1): def _comp_init_data(testCase, iter_idx, init_data_prefix, init_data_sys): for ii in init_data_sys: sys0 = os.path.join(init_data_prefix, ii) - sys1 = os.path.join("iter.%06d" % iter_idx, "00.train", "data.init", ii) + sys1 = os.path.join("iter.%06d" % iter_idx, "00.train", "data.init", ii) # noqa: UP031 testCase.assertTrue( _comp_sys_files(sys0, sys1), f"systems {sys0} {sys1} are not identical", @@ -58,7 +58,7 @@ def _comp_init_data(testCase, iter_idx, init_data_prefix, init_data_sys): def _check_numb_models(testCase, iter_idx, numb_models): models = glob.glob( - os.path.join("iter.%06d" % iter_idx, "00.train", "[0-9][0-9][0-9]") + os.path.join("iter.%06d" % iter_idx, "00.train", "[0-9][0-9][0-9]") # noqa: UP031 ) testCase.assertTrue(len(models), numb_models) @@ -80,7 +80,7 @@ def _check_model_inputs(testCase, iter_idx, jdata): init_batch_size.append(sys_batch_size[sys_idx]) for kk in range(numb_models): with open( - os.path.join("iter.%06d" % iter_idx, "00.train", "%03d" % kk, train_param) + os.path.join("iter.%06d" % iter_idx, "00.train", "%03d" % kk, train_param) # noqa: UP031 # noqa: UP031 ) as fp: jdata0 = json.load(fp) # keys except 'systems', 'batch_size', 'seed' should be identical @@ -136,7 +136,7 @@ def _check_model_inputs_v1(testCase, iter_idx, jdata, reuse=False): init_batch_size.append(sys_batch_size[sys_idx]) for kk in range(numb_models): with open( - os.path.join("iter.%06d" % iter_idx, "00.train", "%03d" % kk, train_param) + os.path.join("iter.%06d" % iter_idx, "00.train", "%03d" % kk, train_param) # noqa: UP031 # noqa: UP031 ) as fp: jdata0 = json.load(fp) # keys except 'systems', 'batch_size', 'seed' should be identical @@ -204,10 +204,12 @@ def _check_model_inputs_v1(testCase, iter_idx, jdata, reuse=False): def _make_fake_fp(iter_idx, sys_idx, nframes): for ii in range(nframes): dirname = os.path.join( - "iter.%06d" % iter_idx, "02.fp", "task.%03d.%06d" % (sys_idx, ii) + "iter.%06d" % iter_idx, # noqa: UP031 + "02.fp", + "task.%03d.%06d" % (sys_idx, ii), # noqa: UP031 ) os.makedirs(dirname, exist_ok=True) - dirname = os.path.join("iter.%06d" % iter_idx, "02.fp", "data.%03d" % sys_idx) + dirname = os.path.join("iter.%06d" % iter_idx, "02.fp", "data.%03d" % sys_idx) # noqa: UP031 # noqa: UP031 os.makedirs(dirname, exist_ok=True) tmp_sys = dpdata.LabeledSystem("out_data_post_fp_vasp/02.fp/task.000.000000/OUTCAR") tmp_sys1 = tmp_sys.sub_system([0]) @@ -219,10 +221,10 @@ def _make_fake_fp(iter_idx, sys_idx, nframes): def _check_pb_link(testCase, iter_idx, numb_models): pwd = os.getcwd() - os.chdir(os.path.join("iter.%06d" % iter_idx, "00.train")) + os.chdir(os.path.join("iter.%06d" % iter_idx, "00.train")) # noqa: UP031 for ii in range(numb_models): - lnk = os.readlink("graph.%03d.pb" % ii) - testCase.assertEqual(lnk, os.path.join("%03d" % ii, "frozen_model.pb")) + lnk = os.readlink("graph.%03d.pb" % ii) # noqa: UP031 + testCase.assertEqual(lnk, os.path.join("%03d" % ii, "frozen_model.pb")) # noqa: UP031 os.chdir(pwd) @@ -414,7 +416,7 @@ def test_1_data_v1_h5(self): ) # check models inputs with open( - os.path.join("iter.%06d" % 1, "00.train", "%03d" % 0, "input.json") + os.path.join("iter.%06d" % 1, "00.train", "%03d" % 0, "input.json") # noqa: UP031 # noqa: UP031 ) as fp: jdata0 = json.load(fp) self.assertEqual( @@ -484,7 +486,7 @@ def test_1_data_v1_one_h5(self): ) # check models inputs with open( - os.path.join("iter.%06d" % 1, "00.train", "%03d" % 0, "input.json") + os.path.join("iter.%06d" % 1, "00.train", "%03d" % 0, "input.json") # noqa: UP031 # noqa: UP031 ) as fp: jdata0 = json.load(fp) self.assertEqual( @@ -543,7 +545,11 @@ def test_training_finetune_model(self): self.assertTrue( os.path.isfile( os.path.join( - "iter.000000", "00.train", "%03d" % ii, "old", "init.pb" + "iter.000000", + "00.train", + "%03d" % ii, # noqa: UP031 + "old", + "init.pb", ) ) ) @@ -594,7 +600,11 @@ def test_training_init_frozen_model(self): self.assertTrue( os.path.isfile( os.path.join( - "iter.000000", "00.train", "%03d" % ii, "old", "init.pb" + "iter.000000", + "00.train", + "%03d" % ii, # noqa: UP031 + "old", + "init.pb", ) ) ) From 577d3360814c3afd3c0c0d3e4196551918defd77 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:06:44 +0800 Subject: [PATCH 02/12] [pre-commit.ci] pre-commit autoupdate (#1679) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.1 → v0.8.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.1...v0.8.2) 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 b52b0adb6..d3134a332 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.8.1 + rev: v0.8.2 hooks: - id: ruff args: ["--fix"] From d337f117afe46c2cb7f4656c6d2edabfd78e823c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:49:10 -0500 Subject: [PATCH 03/12] [pre-commit.ci] pre-commit autoupdate (#1689) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.2 → v0.8.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.2...v0.8.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 d3134a332..d56729681 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.8.2 + rev: v0.8.3 hooks: - id: ruff args: ["--fix"] From af4f861e9ee0224ecb5cca3c48b9a24af1111632 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 22 Dec 2024 19:27:34 -0500 Subject: [PATCH 04/12] fix: bump the upper bound of deepmd version (#1691) Fix #1688. Though I am not sure whether we should have an upper version. ## Summary by CodeRabbit - **New Features** - Enhanced support for `deepmd` library versions 1.x to 3.x. - Improved handling of model deviation tasks with refined logic for training conditions. - Updated file management for better input/output file linking across tasks. - **Bug Fixes** - Clarified error messages for unsupported library versions. - **Documentation** - Updated documentation strings for argument compatibility and function behavior. - **Refactor** - Adjusted function signatures to accommodate new parameters and improved logic. --- dpgen/generator/arginfo.py | 8 ++++---- dpgen/generator/run.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dpgen/generator/arginfo.py b/dpgen/generator/arginfo.py index f437dbc8f..2e31a1f85 100644 --- a/dpgen/generator/arginfo.py +++ b/dpgen/generator/arginfo.py @@ -297,8 +297,8 @@ def model_devi_jobs_args() -> list[Argument]: doc_taup = "Coupling time of barostat (ps)." doc_model_devi_f_trust_lo = "Lower bound of forces for the selection. If dict, should be set for each index in sys_idx, respectively." doc_model_devi_f_trust_hi = "Upper bound of forces for the selection. If dict, should be set for each index in sys_idx, respectively." - doc_model_devi_v_trust_lo = "Lower bound of virial for the selection. If dict, should be set for each index in sys_idx, respectively. Should be used with DeePMD-kit v2.x." - doc_model_devi_v_trust_hi = "Upper bound of virial for the selection. If dict, should be set for each index in sys_idx, respectively. Should be used with DeePMD-kit v2.x." + doc_model_devi_v_trust_lo = "Lower bound of virial for the selection. If dict, should be set for each index in sys_idx, respectively. Should be used with DeePMD-kit v2 or above." + doc_model_devi_v_trust_hi = "Upper bound of virial for the selection. If dict, should be set for each index in sys_idx, respectively. Should be used with DeePMD-kit v2 or above." args = [ model_devi_jobs_template_args(), @@ -351,8 +351,8 @@ def model_devi_lmp_args() -> list[Argument]: doc_model_devi_skip = "Number of structures skipped for fp in each MD." doc_model_devi_f_trust_lo = "Lower bound of forces for the selection. If list or dict, should be set for each index in sys_configs, respectively." 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_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 or above." + 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 or above." 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\ diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 3cdf05a24..99fa37f86 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -474,7 +474,7 @@ def make_train_dp(iter_index, jdata, mdata): raise RuntimeError("invalid setting for use_ele_temp " + str(use_ele_temp)) elif Version(mdata["deepmd_version"]) >= Version("2") and Version( mdata["deepmd_version"] - ) < Version("3"): + ) < Version("4"): # 2.x jinput["training"].setdefault("training_data", {}) jinput["training"]["training_data"]["systems"] = init_data_sys @@ -497,7 +497,7 @@ def make_train_dp(iter_index, jdata, mdata): raise RuntimeError("invalid setting for use_ele_temp " + str(use_ele_temp)) else: raise RuntimeError( - "DP-GEN currently only supports for DeePMD-kit 1.x or 2.x version!" + "DP-GEN currently only supports for DeePMD-kit 1.x to 3.x version!" ) # set training reuse model if auto_ratio: @@ -522,7 +522,7 @@ def make_train_dp(iter_index, jdata, mdata): 1.0 - training_reuse_old_ratio, ) ) - elif Version("2") <= Version(mdata["deepmd_version"]) < Version("3"): + elif Version("2") <= Version(mdata["deepmd_version"]) < Version("4"): jinput["training"]["training_data"]["auto_prob"] = ( "prob_sys_size; 0:%d:%f; %d:%d:%f" # noqa: UP031 % ( @@ -571,7 +571,7 @@ def make_train_dp(iter_index, jdata, mdata): # set random seed for each model if Version(mdata["deepmd_version"]) >= Version("1") and Version( mdata["deepmd_version"] - ) < Version("3"): + ) < Version("4"): # 1.x if "descriptor" not in jinput["model"]: pass @@ -595,7 +595,7 @@ def make_train_dp(iter_index, jdata, mdata): jinput["training"]["seed"] = random.randrange(sys.maxsize) % (2**32) else: raise RuntimeError( - "DP-GEN currently only supports for DeePMD-kit 1.x or 2.x version!" + "DP-GEN currently only supports for DeePMD-kit 1.x to 3.x version!" ) # set model activation function if model_devi_activation_func is not None: @@ -785,7 +785,7 @@ def run_train_dp(iter_index, jdata, mdata): commands = [] if Version(mdata["deepmd_version"]) >= Version("1") and Version( mdata["deepmd_version"] - ) < Version("3"): + ) < Version("4"): # 1.x ## Commands are like `dp train` and `dp freeze` ## train_command should not be None @@ -818,7 +818,7 @@ def run_train_dp(iter_index, jdata, mdata): commands.append(f"{train_command} compress") else: raise RuntimeError( - "DP-GEN currently only supports for DeePMD-kit 1.x or 2.x version!" + "DP-GEN currently only supports for DeePMD-kit 1.x to 3.x version!" ) # _tasks = [os.path.basename(ii) for ii in all_task] @@ -1695,7 +1695,7 @@ def _make_model_devi_native_gromacs(iter_index, jdata, mdata, conf_systems): # only support for deepmd v2.0 if Version(mdata["deepmd_version"]) < Version("2.0"): raise RuntimeError( - "Only support deepmd-kit 2.x for model_devi_engine='gromacs'" + "Only support deepmd-kit v2 or above for model_devi_engine='gromacs'" ) model_devi_jobs = jdata["model_devi_jobs"] if iter_index >= len(model_devi_jobs): From 255f268678dbd2dd776eff0a780d781f3cb6f48a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 12:19:38 +0800 Subject: [PATCH 05/12] [pre-commit.ci] pre-commit autoupdate (#1694) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.3 → v0.8.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.3...v0.8.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 d56729681..acf546bda 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.8.3 + rev: v0.8.4 hooks: - id: ruff args: ["--fix"] From 99b16e7b3e384f9ed02dfb711f6f2bd40f1c51e9 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 7 Jan 2025 17:48:09 +0800 Subject: [PATCH 06/12] fix(CI): remove `CI` env var to fix the CI (#1704) xref: https://github.com/materialsproject/pymatgen/issues/4243#issuecomment-2573310051 ## Summary by CodeRabbit - **Chores** - Updated GitHub Actions workflow configuration with a minor environment variable adjustment to support testing processes. --------- Signed-off-by: Jinzhe Zeng --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5800408c2..e76e5f74d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,10 @@ jobs: - name: Install dependencies run: uv pip install --system -e .[test] - name: Test - run: coverage run --source=./dpgen -m unittest -v && coverage report + run: | + # https://github.com/materialsproject/pymatgen/issues/4243#issuecomment-2573310051 + unset CI + coverage run --source=./dpgen -m unittest -v && coverage report - uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From b9b71a4cc27a039cd3d5f5b969520787a4b6a341 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 14 Jan 2025 12:06:44 +0800 Subject: [PATCH 07/12] Revert "fix(CI): remove `CI` env var to fix the CI" (#1705) Reverts deepmodeling/dpgen#1704 See https://github.com/materialsproject/pymatgen/issues/4243#issuecomment-2581664182 ## Summary by CodeRabbit - **Chores** - Updated GitHub Actions workflow configuration for testing. - Simplified test execution process in the CI pipeline. --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e76e5f74d..5800408c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,10 +21,7 @@ jobs: - name: Install dependencies run: uv pip install --system -e .[test] - name: Test - run: | - # https://github.com/materialsproject/pymatgen/issues/4243#issuecomment-2573310051 - unset CI - coverage run --source=./dpgen -m unittest -v && coverage report + run: coverage run --source=./dpgen -m unittest -v && coverage report - uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 8e9532d667948e435fcb4f80faf37fccd6c4737e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:51:10 +0800 Subject: [PATCH 08/12] [pre-commit.ci] pre-commit autoupdate (#1703) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.4 → v0.9.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.4...v0.9.1) --------- 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/abacus.py | 18 ++-- dpgen/auto_test/reproduce.py | 12 +-- dpgen/data/gen.py | 26 +++--- dpgen/data/surf.py | 6 +- dpgen/generator/lib/abacus_scf.py | 117 ++++++++++++------------- dpgen/generator/lib/calypso_run_opt.py | 6 +- dpgen/generator/lib/utils.py | 6 +- dpgen/generator/run.py | 56 ++++++------ tests/data/test_coll_abacus.py | 6 +- tests/generator/test_make_md.py | 4 +- tests/generator/test_post_fp.py | 48 +++++----- 12 files changed, 152 insertions(+), 155 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index acf546bda..fc68ebde7 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.8.4 + rev: v0.9.1 hooks: - id: ruff args: ["--fix"] diff --git a/dpgen/auto_test/lib/abacus.py b/dpgen/auto_test/lib/abacus.py index afdbda556..6d097dbaa 100644 --- a/dpgen/auto_test/lib/abacus.py +++ b/dpgen/auto_test/lib/abacus.py @@ -161,25 +161,25 @@ def poscar2stru(poscar, inter_param, stru="STRU"): else: atom_mass_dict = inter_param["atom_masses"] for atom in stru_data["atom_names"]: - assert ( - atom in atom_mass_dict - ), f"the mass of {atom} is not defined in interaction:atom_masses" + assert atom in atom_mass_dict, ( + f"the mass of {atom} is not defined in interaction:atom_masses" + ) atom_mass.append(atom_mass_dict[atom]) if "potcars" in inter_param: pseudo = [] for atom in stru_data["atom_names"]: - assert ( - atom in inter_param["potcars"] - ), f"the pseudopotential of {atom} is not defined in interaction:potcars" + assert atom in inter_param["potcars"], ( + f"the pseudopotential of {atom} is not defined in interaction:potcars" + ) pseudo.append("./pp_orb/" + inter_param["potcars"][atom].split("/")[-1]) if "orb_files" in inter_param: orb = [] for atom in stru_data["atom_names"]: - assert ( - atom in inter_param["orb_files"] - ), f"orbital file of {atom} is not defined in interaction:orb_files" + assert atom in inter_param["orb_files"], ( + f"orbital file of {atom} is not defined in interaction:orb_files" + ) orb.append("./pp_orb/" + inter_param["orb_files"][atom].split("/")[-1]) if "deepks_desc" in inter_param: diff --git a/dpgen/auto_test/reproduce.py b/dpgen/auto_test/reproduce.py index a2b919a5d..87a14d202 100644 --- a/dpgen/auto_test/reproduce.py +++ b/dpgen/auto_test/reproduce.py @@ -34,9 +34,9 @@ def make_repro( init_data_task_todo = glob.glob( os.path.join(init_data_path_todo, "task.[0-9]*[0-9]") ) - assert ( - len(init_data_task_todo) > 0 - ), "There is no task in previous calculations path" + assert len(init_data_task_todo) > 0, ( + "There is no task in previous calculations path" + ) init_data_task_todo.sort() task_list = [] @@ -122,9 +122,9 @@ def post_repro( init_data_task_todo = glob.glob( os.path.join(init_data_path_todo, "task.[0-9]*[0-9]") ) - assert ( - len(init_data_task_todo) > 0 - ), "There is no task in previous calculations path" + assert len(init_data_task_todo) > 0, ( + "There is no task in previous calculations path" + ) init_data_task_todo.sort() idid = 0 diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 3e6940a86..484749ed7 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -584,9 +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) @@ -595,9 +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() @@ -779,10 +779,10 @@ def pert_scaled(jdata): ### Loop over each perturbation for kk in range(pert_numb): if fp_style == "vasp": - pos_in = f"POSCAR{kk+1}.vasp" + pos_in = f"POSCAR{kk + 1}.vasp" elif fp_style == "abacus": - pos_in = f"STRU{kk+1}.abacus" - dir_out = f"{kk+1: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") @@ -814,7 +814,7 @@ def pert_scaled(jdata): pos_in = "POSCAR" elif fp_style == "abacus": pos_in = "STRU" - dir_out = f"{kk+1:06d}" + dir_out = f"{kk + 1:06d}" create_path(dir_out) if fp_style == "vasp": pos_out = os.path.join(dir_out, "POSCAR") @@ -928,9 +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: diff --git a/dpgen/data/surf.py b/dpgen/data/surf.py index 3fba6a14b..3af1e9d60 100644 --- a/dpgen/data/surf.py +++ b/dpgen/data/surf.py @@ -525,8 +525,8 @@ 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+1}.vasp" - dir_out = f"{kk+1: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) @@ -535,7 +535,7 @@ def pert_scaled(jdata): ### Handle special case (unperturbed ?) kk = -1 pos_in = "POSCAR" - dir_out = f"{kk+1:06d}" + dir_out = f"{kk + 1:06d}" create_path(dir_out) pos_out = os.path.join(dir_out, "POSCAR") poscar_shuffle(pos_in, pos_out) diff --git a/dpgen/generator/lib/abacus_scf.py b/dpgen/generator/lib/abacus_scf.py index 376c64eb0..96262620e 100644 --- a/dpgen/generator/lib/abacus_scf.py +++ b/dpgen/generator/lib/abacus_scf.py @@ -45,13 +45,12 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): fp_params["kspacing"] = [ float(i) for i in fp_params["kspacing"].split() ] - assert ( - len(fp_params["kspacing"]) - in [ - 1, - 3, - ] - ), "'kspacing' only accept a float, or a list of one or three float, or a string of one or three float" + assert len(fp_params["kspacing"]) in [ + 1, + 3, + ], ( + "'kspacing' only accept a float, or a list of one or three float, or a string of one or three float" + ) ret += "kspacing " for ikspacing in fp_params["kspacing"]: assert ikspacing >= 0, "'kspacing' should be non-negative." @@ -78,9 +77,9 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): elif key == "gamma_only": if isinstance(fp_params["gamma_only"], str): fp_params["gamma_only"] = int(eval(fp_params["gamma_only"])) - assert ( - fp_params["gamma_only"] == 0 or fp_params["gamma_only"] == 1 - ), "'gamma_only' should be either 0 or 1." + assert fp_params["gamma_only"] == 0 or fp_params["gamma_only"] == 1, ( + "'gamma_only' should be either 0 or 1." + ) ret += "gamma_only %d\n" % fp_params["gamma_only"] # noqa: UP031 elif key == "mixing_type": assert fp_params["mixing_type"] in [ @@ -93,22 +92,22 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): ret += "mixing_type {}\n".format(fp_params["mixing_type"]) elif key == "mixing_beta": fp_params["mixing_beta"] = float(fp_params["mixing_beta"]) - assert ( - fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1 - ), "'mixing_beta' should between 0 and 1." + assert fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1, ( + "'mixing_beta' should between 0 and 1." + ) ret += "mixing_beta {:f}\n".format(fp_params["mixing_beta"]) elif key == "symmetry": if isinstance(fp_params["symmetry"], str): fp_params["symmetry"] = int(eval(fp_params["symmetry"])) - assert ( - fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1 - ), "'symmetry' should be either 0 or 1." + assert fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1, ( + "'symmetry' should be either 0 or 1." + ) ret += "symmetry %d\n" % fp_params["symmetry"] # noqa: UP031 elif key == "nbands": fp_params["nbands"] = int(fp_params["nbands"]) - assert fp_params["nbands"] > 0 and isinstance( - fp_params["nbands"], int - ), "'nbands' should be a positive integer." + assert fp_params["nbands"] > 0 and isinstance(fp_params["nbands"], int), ( + "'nbands' should be a positive integer." + ) ret += "nbands %d\n" % fp_params["nbands"] # noqa: UP031 elif key == "nspin": fp_params["nspin"] = int(fp_params["nspin"]) @@ -119,51 +118,49 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): ), "'nspin' can anly take 1, 2 or 4" ret += "nspin %d\n" % fp_params["nspin"] # noqa: UP031 elif key == "ks_solver": - assert ( - fp_params["ks_solver"] - in [ - "cg", - "dav", - "lapack", - "genelpa", - "hpseps", - "scalapack_gvx", - ] - ), "'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'." + assert fp_params["ks_solver"] in [ + "cg", + "dav", + "lapack", + "genelpa", + "hpseps", + "scalapack_gvx", + ], ( + "'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'." + ) ret += "ks_solver {}\n".format(fp_params["ks_solver"]) elif key == "smearing_method": - assert ( - fp_params["smearing_method"] - in [ - "gauss", - "gaussian", - "fd", - "fixed", - "mp", - "mp2", - "mv", - ] - ), "'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. " + assert fp_params["smearing_method"] in [ + "gauss", + "gaussian", + "fd", + "fixed", + "mp", + "mp2", + "mv", + ], ( + "'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. " + ) ret += "smearing_method {}\n".format(fp_params["smearing_method"]) elif key == "smearing_sigma": fp_params["smearing_sigma"] = float(fp_params["smearing_sigma"]) - assert ( - fp_params["smearing_sigma"] >= 0 - ), "'smearing_sigma' should be non-negative." + assert fp_params["smearing_sigma"] >= 0, ( + "'smearing_sigma' should be non-negative." + ) ret += "smearing_sigma {:f}\n".format(fp_params["smearing_sigma"]) elif key == "cal_force": if isinstance(fp_params["cal_force"], str): fp_params["cal_force"] = int(eval(fp_params["cal_force"])) - assert ( - fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1 - ), "'cal_force' should be either 0 or 1." + assert fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1, ( + "'cal_force' should be either 0 or 1." + ) ret += "cal_force %d\n" % fp_params["cal_force"] # noqa: UP031 elif key == "cal_stress": if isinstance(fp_params["cal_stress"], str): fp_params["cal_stress"] = int(eval(fp_params["cal_stress"])) - assert ( - fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1 - ), "'cal_stress' should be either 0 or 1." + assert fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1, ( + "'cal_stress' should be either 0 or 1." + ) ret += "cal_stress %d\n" % fp_params["cal_stress"] # noqa: UP031 # paras for deepks elif key == "deepks_out_labels": @@ -180,16 +177,16 @@ def make_abacus_scf_input(fp_params, extra_file_path=""): fp_params["deepks_descriptor_lmax"] = int( fp_params["deepks_descriptor_lmax"] ) - assert ( - fp_params["deepks_descriptor_lmax"] >= 0 - ), "'deepks_descriptor_lmax' should be a positive integer." + assert fp_params["deepks_descriptor_lmax"] >= 0, ( + "'deepks_descriptor_lmax' should be a positive integer." + ) ret += "deepks_descriptor_lmax %d\n" % fp_params["deepks_descriptor_lmax"] # noqa: UP031 elif key == "deepks_scf": if isinstance(fp_params["deepks_scf"], str): fp_params["deepks_scf"] = int(eval(fp_params["deepks_scf"])) - assert ( - fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1 - ), "'deepks_scf' should be either 0 or 1." + assert fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1, ( + "'deepks_scf' should be either 0 or 1." + ) ret += "deepks_scf %d\n" % fp_params["deepks_scf"] # noqa: UP031 elif key == "deepks_model": ret += "deepks_model {}\n".format( @@ -228,9 +225,9 @@ def make_abacus_scf_stru( ret = "ATOMIC_SPECIES\n" for iatom in range(len(atom_names)): - assert ( - atom_names[iatom] in type_map - ), f"element {atom_names[iatom]} is not defined in type_map" + assert atom_names[iatom] in type_map, ( + f"element {atom_names[iatom]} is not defined in type_map" + ) idx = type_map.index(atom_names[iatom]) if "atom_masses" not in sys_data: ret += ( diff --git a/dpgen/generator/lib/calypso_run_opt.py b/dpgen/generator/lib/calypso_run_opt.py index fc7cf899a..1bc765af1 100644 --- a/dpgen/generator/lib/calypso_run_opt.py +++ b/dpgen/generator/lib/calypso_run_opt.py @@ -94,9 +94,9 @@ def read_stress_fmax(): try: f = open("input.dat") except Exception: - assert os.path.exists( - "../input.dat" - ), f" now we are in {os.getcwd()}, do not find ../input.dat" + assert os.path.exists("../input.dat"), ( + f" now we are in {os.getcwd()}, do not find ../input.dat" + ) f = open("../input.dat") lines = f.readlines() f.close() diff --git a/dpgen/generator/lib/utils.py b/dpgen/generator/lib/utils.py index 9757d5368..68e0c6cb3 100644 --- a/dpgen/generator/lib/utils.py +++ b/dpgen/generator/lib/utils.py @@ -102,9 +102,9 @@ def symlink_user_forward_files(mdata, task_type, work_path, task_format=None): task_format = {"train": "0*", "model_devi": "task.*", "fp": "task.*"} # "init_relax" : "sys-*", "init_md" : "sys-*/scale*/00*" for file in user_forward_files: - assert os.path.isfile( - file - ), f"user_forward_file {file} of {task_type} stage doesn't exist. " + assert os.path.isfile(file), ( + f"user_forward_file {file} of {task_type} stage doesn't exist. " + ) tasks = glob.glob(os.path.join(work_path, task_format[task_type])) for task in tasks: if os.path.isfile(os.path.join(task, os.path.basename(file))): diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 99fa37f86..8cacb0e87 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -2042,7 +2042,7 @@ def run_md_model_devi(iter_index, jdata, mdata): else: num_digits = np.ceil(np.log10(nbeads + 1)).astype(int) backward_files += [ - f"model_devi{i+1:0{num_digits}d}.out" for i in range(nbeads) + 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: @@ -2116,11 +2116,7 @@ def run_md_model_devi(iter_index, jdata, mdata): ] elif model_devi_engine == "amber": commands = [ - ( - "TASK=$(basename $(pwd)) && " - "SYS1=${TASK:5:3} && " - "SYS=$((10#$SYS1)) && " - ) + ("TASK=$(basename $(pwd)) && SYS1=${TASK:5:3} && SYS=$((10#$SYS1)) && ") + model_devi_exec + ( " -O -p ../qmmm$SYS.parm7 -c init.rst7 -i ../init$SYS.mdin -o rc.mdout -r rc.rst7 -x rc.nc -inf rc.mdinfo -ref init.rst7" @@ -2263,7 +2259,9 @@ def _read_model_devi_file( assert all( model_devi_content.shape[0] == model_devi_contents[0].shape[0] for model_devi_content in model_devi_contents - ), r"Not all beads generated the same number of lines in the model_devi${ibead}.out file. Check your pimd task carefully." + ), ( + r"Not all beads generated the same number of lines in the model_devi${ibead}.out file. Check your pimd task carefully." + ) last_step = model_devi_contents[0][-1, 0] for ibead in range(1, num_beads): model_devi_contents[ibead][:, 0] = model_devi_contents[ibead][ @@ -2286,7 +2284,7 @@ def _read_model_devi_file( for ibead in range(num_beads): traj_files = glob.glob( os.path.join( - task_path, "traj", f"*lammpstrj{ibead+1:0{num_digits}d}" + task_path, "traj", f"*lammpstrj{ibead + 1:0{num_digits}d}" ) ) traj_files_sorted.append( @@ -2302,7 +2300,9 @@ def _read_model_devi_file( assert all( len(traj_list) == len(traj_files_sorted[0]) for traj_list in traj_files_sorted - ), "Not all beads generated the same number of frames. Check your pimd task carefully." + ), ( + "Not all beads generated the same number of frames. Check your pimd task carefully." + ) for ibead in range(num_beads): for itraj in range(len(traj_files_sorted[0])): base_path, original_filename = os.path.split( @@ -2311,7 +2311,7 @@ def _read_model_devi_file( frame_number = int(original_filename.split(".")[0]) new_filename = os.path.join( base_path, - f"{frame_number + ibead * (int(last_step)+1):d}.lammpstrj", + f"{frame_number + ibead * (int(last_step) + 1):d}.lammpstrj", ) os.rename(traj_files_sorted[ibead][itraj], new_filename) model_devi = np.loadtxt(os.path.join(task_path, "model_devi.out")) @@ -3247,9 +3247,9 @@ def sys_link_fp_vasp_pp(iter_index, jdata): fp_pp_path = os.path.abspath(fp_pp_path) type_map = jdata["type_map"] assert os.path.exists(fp_pp_path) - assert len(fp_pp_files) == len( - type_map - ), "size of fp_pp_files should be the same as the size of type_map" + assert len(fp_pp_files) == len(type_map), ( + "size of fp_pp_files should be the same as the size of type_map" + ) iter_name = make_iter_name(iter_index) work_path = os.path.join(iter_name, fp_name) @@ -3306,9 +3306,9 @@ def _link_fp_abacus_pporb_descript(iter_index, jdata): model_file = os.path.join( fp_pp_path, os.path.split(fp_dpks_model)[1] ) # only the filename - assert os.path.isfile( - model_file - ), f"Can not find the deepks model file {model_file}, which is defined in {ii}/INPUT" + assert os.path.isfile(model_file), ( + f"Can not find the deepks model file {model_file}, which is defined in {ii}/INPUT" + ) os.symlink(model_file, fp_dpks_model) # link to the model file # get pp, orb, descriptor filenames from STRU @@ -3323,9 +3323,9 @@ def _link_fp_abacus_pporb_descript(iter_index, jdata): if orb_files_stru: assert "fp_orb_files" in jdata, "need to define fp_orb_files in jdata" if descriptor_file_stru: - assert ( - "fp_dpks_descriptor" in jdata - ), "need to define fp_dpks_descriptor in jdata" + assert "fp_dpks_descriptor" in jdata, ( + "need to define fp_dpks_descriptor in jdata" + ) for idx, iatom in enumerate(atom_names): type_map_idx = type_map.index(iatom) @@ -3335,21 +3335,21 @@ def _link_fp_abacus_pporb_descript(iter_index, jdata): ) if pp_files_stru: src_file = os.path.join(fp_pp_path, jdata["fp_pp_files"][type_map_idx]) - assert os.path.isfile( - src_file - ), f"Can not find the pseudopotential file {src_file}" + assert os.path.isfile(src_file), ( + f"Can not find the pseudopotential file {src_file}" + ) os.symlink(src_file, pp_files_stru[idx]) if orb_files_stru: src_file = os.path.join(fp_pp_path, jdata["fp_orb_files"][type_map_idx]) - assert os.path.isfile( - src_file - ), f"Can not find the orbital file {src_file}" + assert os.path.isfile(src_file), ( + f"Can not find the orbital file {src_file}" + ) os.symlink(src_file, orb_files_stru[idx]) if descriptor_file_stru: src_file = os.path.join(fp_pp_path, jdata["fp_dpks_descriptor"]) - assert os.path.isfile( - src_file - ), f"Can not find the descriptor file {src_file}" + assert os.path.isfile(src_file), ( + f"Can not find the descriptor file {src_file}" + ) os.symlink(src_file, descriptor_file_stru) os.chdir(cwd) diff --git a/tests/data/test_coll_abacus.py b/tests/data/test_coll_abacus.py index 63e2d6e7d..2f8e2a59c 100644 --- a/tests/data/test_coll_abacus.py +++ b/tests/data/test_coll_abacus.py @@ -22,9 +22,9 @@ def setUp(self): with open(abacus_param_file) as fp: jdata = json.load(fp) self.odir = out_dir_name(jdata) - assert os.path.isdir( - "out_data_02_md_abacus" - ), "out data for post fp vasp should exist" + assert os.path.isdir("out_data_02_md_abacus"), ( + "out data for post fp vasp should exist" + ) if os.path.isdir(self.odir): shutil.rmtree(self.odir) shutil.copytree("out_data_02_md_abacus", self.odir) diff --git a/tests/generator/test_make_md.py b/tests/generator/test_make_md.py index 6f5cf177d..8b9f0449b 100644 --- a/tests/generator/test_make_md.py +++ b/tests/generator/test_make_md.py @@ -280,7 +280,7 @@ def test_read_model_devi_file_pimd(self): 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") as fp: + 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]) @@ -291,7 +291,7 @@ def test_read_model_devi_file_pimd(self): 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"), + os.path.join(path, f"model_devi{i + 1}.out"), model_devi_array, fmt="%.12e", ) diff --git a/tests/generator/test_post_fp.py b/tests/generator/test_post_fp.py index 72251328d..8446a30e1 100644 --- a/tests/generator/test_post_fp.py +++ b/tests/generator/test_post_fp.py @@ -31,9 +31,9 @@ class TestPostFPVasp(unittest.TestCase): def setUp(self): - assert os.path.isdir( - "out_data_post_fp_vasp" - ), "out data for post fp vasp should exist" + assert os.path.isdir("out_data_post_fp_vasp"), ( + "out data for post fp vasp should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_vasp", "iter.000000") @@ -183,9 +183,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 2 - assert os.path.isdir( - "out_data_post_fp_pwscf" - ), "out data for post fp pwscf should exist" + assert os.path.isdir("out_data_post_fp_pwscf"), ( + "out data for post fp pwscf should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_pwscf", "iter.000000") @@ -204,9 +204,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 2 - assert os.path.isdir( - "out_data_post_fp_abacus" - ), "out data for post fp pwscf should exist" + assert os.path.isdir("out_data_post_fp_abacus"), ( + "out data for post fp pwscf should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_abacus", "iter.000000") @@ -228,9 +228,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 5 - assert os.path.isdir( - "out_data_post_fp_siesta" - ), "out data for post fp siesta should exist" + assert os.path.isdir("out_data_post_fp_siesta"), ( + "out data for post fp siesta should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_siesta", "iter.000000") @@ -249,9 +249,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 5 - assert os.path.isdir( - "out_data_post_fp_gaussian" - ), "out data for post fp gaussian should exist" + assert os.path.isdir("out_data_post_fp_gaussian"), ( + "out data for post fp gaussian should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_gaussian", "iter.000000") @@ -270,9 +270,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 5 - assert os.path.isdir( - "out_data_post_fp_cp2k" - ), "out data for post fp cp2k should exist" + assert os.path.isdir("out_data_post_fp_cp2k"), ( + "out data for post fp cp2k should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_cp2k", "iter.000000") @@ -291,9 +291,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 2 - assert os.path.isdir( - "out_data_post_fp_pwmat" - ), "out data for post fp pwmat should exist" + assert os.path.isdir("out_data_post_fp_pwmat"), ( + "out data for post fp pwmat should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") shutil.copytree("out_data_post_fp_pwmat", "iter.000000") @@ -339,9 +339,9 @@ def setUp(self): self.e_places = 5 self.f_places = 5 self.v_places = 2 - assert os.path.isdir( - "out_data_post_fp_pwmat" - ), "out data for post fp pwmat should exist" + assert os.path.isdir("out_data_post_fp_pwmat"), ( + "out data for post fp pwmat should exist" + ) if os.path.isdir("iter.000000"): shutil.rmtree("iter.000000") with open(param_custom_fp_file) as fp: From 2158dba241f664a4e61e33da79548172a9b98fd4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 08:53:44 +0800 Subject: [PATCH 09/12] [pre-commit.ci] pre-commit autoupdate (#1709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.1 → v0.9.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.1...v0.9.2) 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 fc68ebde7..3315eb212 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.9.1 + rev: v0.9.2 hooks: - id: ruff args: ["--fix"] From 674fbb04658c9371d0bb85e1340879c8e191303a Mon Sep 17 00:00:00 2001 From: Peng Xingliang <91927439+pxlxingliang@users.noreply.github.com> Date: Fri, 21 Feb 2025 10:13:39 +0800 Subject: [PATCH 10/12] fix bug in reading abacus stru (#1714) Fix the bug induced by the update of dpdata. Now the reading and writing of ABACUS STRU is by a more general dpdata/abacus interface, and remove some redundant codes. This commit is based on dpdata commit https://github.com/deepmodeling/dpdata/pull/793, and it is valid after that commit is merged. related issue: https://github.com/deepmodeling/dpgen/issues/1711 ## Summary by CodeRabbit - **Refactor** - Streamlined the workflow for generating atomic structure data by removing redundant parameters and centralizing functionality. - Improved handling of atomic data structures for more efficient processing and organization. - **Tests** - Enhanced the precision of validations by refining comparisons to focus on key attributes, ensuring more robust result accuracy. - Corrected the method name for improved clarity in the test suite. - Added a new key to the test data structure for enhanced functionality in subsequent tests. --------- Co-authored-by: root Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dpgen/auto_test/lib/abacus.py | 2 +- dpgen/data/gen.py | 1 + dpgen/data/tools/create_random_disturb.py | 1 + dpgen/generator/lib/abacus_scf.py | 252 +++++++--------------- dpgen/generator/run.py | 1 - tests/auto_test/test_abacus.py | 18 +- tests/data/test_gen_bulk_abacus.py | 1 + 7 files changed, 92 insertions(+), 184 deletions(-) diff --git a/dpgen/auto_test/lib/abacus.py b/dpgen/auto_test/lib/abacus.py index 6d097dbaa..05ebd5cc1 100644 --- a/dpgen/auto_test/lib/abacus.py +++ b/dpgen/auto_test/lib/abacus.py @@ -4,7 +4,7 @@ import dpdata import numpy as np -from dpdata.abacus.scf import make_unlabeled_stru +from dpdata.abacus.stru import make_unlabeled_stru from dpdata.utils import uniq_atom_names from dpdata.vasp import poscar as dpdata_poscar diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 484749ed7..f0a88bcb4 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -145,6 +145,7 @@ def stru_ele(supercell_stru, stru_out, eles, natoms, jdata, path_work): dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"]) supercell_stru["atom_masses"] = jdata["atom_masses"] supercell_stru["atom_names"] = eles + supercell_stru["atom_types"] = np.array(supercell_stru["types"]) stru_text = make_abacus_scf_stru( supercell_stru, pp_file_names, diff --git a/dpgen/data/tools/create_random_disturb.py b/dpgen/data/tools/create_random_disturb.py index 957e20872..fd6e0faec 100755 --- a/dpgen/data/tools/create_random_disturb.py +++ b/dpgen/data/tools/create_random_disturb.py @@ -192,6 +192,7 @@ def create_disturbs_abacus_dev( stru = get_abacus_STRU(fin) natoms = sum(stru["atom_numbs"]) cell0 = stru["cells"] + stru["masses"] = stru["atom_masses"] # in dpdata, it is masses that should be used. # creat nfile ofmt files. for fid in range(1, nfile + 1): diff --git a/dpgen/generator/lib/abacus_scf.py b/dpgen/generator/lib/abacus_scf.py index 96262620e..f04dbdd96 100644 --- a/dpgen/generator/lib/abacus_scf.py +++ b/dpgen/generator/lib/abacus_scf.py @@ -3,7 +3,7 @@ import re import numpy as np -from dpdata.abacus.scf import get_cell, get_coords, get_nele_from_stru +from dpdata.abacus.stru import get_frame_from_stru, make_unlabeled_stru from dpgen.auto_test.lib import vasp @@ -208,90 +208,37 @@ def make_abacus_scf_stru( fp_pp_files, fp_orb_files=None, fp_dpks_descriptor=None, - fp_params=None, type_map=None, pporb="", # pull all pp orb dpks files to pporb folder ): - atom_names = sys_data["atom_names"] - atom_numbs = sys_data["atom_numbs"] - if type_map is None: - type_map = atom_names - - assert len(atom_names) == len(atom_numbs), "Please check the name of atoms. " - cell = sys_data["cells"].reshape([3, 3]) - coord = sys_data["coords"].reshape([sum(atom_numbs), 3]) - # volume = np.linalg.det(cell) - # lattice_const = np.power(volume, 1/3) - - ret = "ATOMIC_SPECIES\n" - for iatom in range(len(atom_names)): - assert atom_names[iatom] in type_map, ( - f"element {atom_names[iatom]} is not defined in type_map" - ) - idx = type_map.index(atom_names[iatom]) - if "atom_masses" not in sys_data: - ret += ( - atom_names[iatom] - + " 1.00 " - + os.path.join(pporb, fp_pp_files[idx]) - + "\n" - ) - else: - ret += ( - atom_names[iatom] - + " {:.3f} ".format(sys_data["atom_masses"][iatom]) - + os.path.join(pporb, fp_pp_files[idx]) - + "\n" - ) - - if fp_params is not None and "lattice_constant" in fp_params: - ret += "\nLATTICE_CONSTANT\n" - ret += ( - str(fp_params["lattice_constant"]) + "\n\n" - ) # in Bohr, in this way coord and cell are in Angstrom - else: - ret += "\nLATTICE_CONSTANT\n" - ret += str(1 / bohr2ang) + "\n\n" - - ret += "LATTICE_VECTORS\n" - for ix in range(3): - for iy in range(3): - ret += str(cell[ix][iy]) + " " - ret += "\n" - ret += "\n" - - ret += "ATOMIC_POSITIONS\n" - ret += "Cartesian # Cartesian(Unit is LATTICE_CONSTANT)\n" - # ret += "\n" - natom_tot = 0 - for iele in range(len(atom_names)): - ret += atom_names[iele] + "\n" - ret += "0.0\n" - ret += str(atom_numbs[iele]) + "\n" - for iatom in range(atom_numbs[iele]): - ret += "%.12f %.12f %.12f %d %d %d\n" % ( # noqa: UP031 - coord[natom_tot, 0], - coord[natom_tot, 1], - coord[natom_tot, 2], - 1, - 1, - 1, - ) - natom_tot += 1 - assert natom_tot == sum(atom_numbs) - + sys_data_copy = copy.deepcopy(sys_data) + # re-construct the path of files by pporb + file name + fp_pp_files = [os.path.join(pporb, i) for i in fp_pp_files] if fp_orb_files is not None: - ret += "\nNUMERICAL_ORBITAL\n" - assert len(fp_orb_files) == len(type_map) - for iatom in range(len(atom_names)): - idx = type_map.index(atom_names[iatom]) - ret += os.path.join(pporb, fp_orb_files[idx]) + "\n" - + fp_orb_files = [os.path.join(pporb, i) for i in fp_orb_files] if fp_dpks_descriptor is not None: - ret += "\nNUMERICAL_DESCRIPTOR\n" - ret += os.path.join(pporb, fp_dpks_descriptor) + "\n" + fp_dpks_descriptor = os.path.join(pporb, fp_dpks_descriptor) + + # we need to make sure that the shape of cells and coords are the same + # and if they are 2D, we need to convert them to 3D + cells = np.array(sys_data["cells"]) + coords = np.array(sys_data["coords"]) + assert len(cells.shape) == len(coords.shape), ( + "cells and coords should have the same shape." + ) - return ret + if len(cells.shape) == 2: + sys_data_copy["cells"] = np.array([cells]) + sys_data_copy["coords"] = np.array([coords]) + c = make_unlabeled_stru( + sys_data_copy, + 0, + pp_file=fp_pp_files, + numerical_orbital=fp_orb_files, + numerical_descriptor=fp_dpks_descriptor, + ) + + return c def get_abacus_input_parameters(INPUT): @@ -306,106 +253,37 @@ def get_abacus_input_parameters(INPUT): return input_parameters -def get_mass_from_STRU(geometry_inlines, atom_names): - nele = get_nele_from_stru(geometry_inlines) - assert nele > 0 - mass_list = [0 for i in atom_names] - pp_file_list = [i for i in atom_names] - for iline, line in enumerate(geometry_inlines): - if line.split() == []: - continue - if "ATOMIC_SPECIES" == line.split()[0]: - for iele1 in range(1, 1 + nele): - for iele2 in range(nele): - if geometry_inlines[iline + iele1].split()[0] == atom_names[iele2]: - mass_list[iele2] = float( - geometry_inlines[iline + iele1].split()[1] - ) - pp_file_list[iele2] = geometry_inlines[iline + iele1].split()[2] - for iele in range(len(mass_list)): - assert mass_list[iele] > 0 - return mass_list, pp_file_list - - -def get_natoms_from_stru(geometry_inlines): - key_words_list = [ - "ATOMIC_SPECIES", - "NUMERICAL_ORBITAL", - "LATTICE_CONSTANT", - "LATTICE_VECTORS", - "ATOMIC_POSITIONS", - "NUMERICAL_DESCRIPTOR", - ] - keyword_sequence = [] - keyword_line_index = [] - atom_names = [] - atom_numbs = [] - tmp_line = [] - for i in geometry_inlines: - if i.strip() != "": - tmp_line.append(i) - for iline, line in enumerate(tmp_line): - if line.split() == []: - continue - have_key_word = False - for keyword in key_words_list: - if keyword in line and keyword == line.split()[0]: - keyword_sequence.append(keyword) - keyword_line_index.append(iline) - assert len(keyword_line_index) == len(keyword_sequence) - assert len(keyword_sequence) > 0 - keyword_line_index.append(len(tmp_line)) - for idx, keyword in enumerate(keyword_sequence): - if keyword == "ATOMIC_POSITIONS": - iline = keyword_line_index[idx] + 2 - while iline < keyword_line_index[idx + 1] - 1: - atom_names.append(tmp_line[iline].split()[0]) - atom_numbs.append(int(tmp_line[iline + 2].split()[0])) - iline += 3 + atom_numbs[-1] - return atom_names, atom_numbs - - -def get_additional_from_STRU(geometry_inlines, nele): - dpks_descriptor_kw = "NUMERICAL_DESCRIPTOR" - orb_file_kw = "NUMERICAL_ORBITAL" - dpks_descriptor = None - orb_file = None - for iline in range(len(geometry_inlines)): - if len(geometry_inlines[iline]) > 0: - if orb_file_kw == geometry_inlines[iline].split()[0]: - orb_file = [] - for iele in range(nele): - orb_file.append(geometry_inlines[iline + iele + 1].strip()) - if dpks_descriptor_kw == geometry_inlines[iline].split()[0]: - dpks_descriptor = geometry_inlines[iline + 1].strip() - return orb_file, dpks_descriptor - - -def get_abacus_STRU(STRU, INPUT=None, n_ele=None): - # read in geometry from STRU file. n_ele is the number of elements. - # Either n_ele or INPUT should be provided. - with open(STRU) as fp: - geometry_inlines = fp.read().split("\n") - for iline, line in enumerate(geometry_inlines): - if line.split() == [] or len(line) == 0: - del geometry_inlines[iline] - geometry_inlines.append("") - celldm, cell = get_cell(geometry_inlines) - atom_names, natoms, types, coords = get_coords(celldm, cell, geometry_inlines) - masses, pp_files = get_mass_from_STRU(geometry_inlines, atom_names) - orb_files, dpks_descriptor = get_additional_from_STRU(geometry_inlines, len(masses)) - data = {} - data["atom_names"] = atom_names - data["atom_numbs"] = natoms - 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["pp_files"] = pp_files - data["orb_files"] = orb_files - data["dpks_descriptor"] = dpks_descriptor +def get_abacus_STRU(STRU): + """Read STRU file and return a dictionary containing the structure information. + + Args: + STRU (str): The path of STRU file. + + Returns + ------- + dict: A dictionary containing the structure information. + { + "atom_names": list of str, + "atom_numbs": list of int, + "atom_masses": list of float, + "coords": np.ndarray, + "cells": np.ndarray, + "pp_files": list of str, + "orb_files": list of str, + "dpks_descriptor": str, + } + """ + data = get_frame_from_stru(STRU) + data["atom_masses"] = data.pop("masses") + data["cells"] = data.pop("cells")[0] + data["coords"] = data.pop("coords")[0] + assert "pp_files" in data, "pp_files should be provided in STRU file." + if None in data["pp_files"]: + data["pp_files"] = None + if "orb_files" not in data: + data["orb_files"] = None + if "dpks_descriptor" not in data: + data["dpks_descriptor"] = None return data @@ -419,7 +297,21 @@ def make_supercell_abacus(from_struct, super_cell): # ) for idx_atm in from_struct["atom_types"]: new_types += [idx_atm] * super_cell[0] * super_cell[1] * super_cell[2] - to_struct["atom_types"] = new_types + to_struct["atom_types"] = np.array(new_types) + + # expand move, spins + for ikey in ["move", "spins"]: + if ikey in from_struct: + new_list = [] + for ia in range(sum(from_struct["atom_numbs"])): + new_list += ( + [from_struct[ikey][0][ia]] + * super_cell[0] + * super_cell[1] + * super_cell[2] + ) + to_struct[ikey] = np.array([new_list]) + to_atom_num = ( sum(from_struct["atom_numbs"]) * super_cell[0] * super_cell[1] * super_cell[2] ) diff --git a/dpgen/generator/run.py b/dpgen/generator/run.py index 8cacb0e87..0f6953721 100644 --- a/dpgen/generator/run.py +++ b/dpgen/generator/run.py @@ -3569,7 +3569,6 @@ def make_fp_abacus_scf(iter_index, jdata): fp_pp_files, fp_orb_files, fp_dpks_descriptor, - fp_params, type_map=jdata["type_map"], pporb=pporb_path, ) diff --git a/tests/auto_test/test_abacus.py b/tests/auto_test/test_abacus.py index 28099e821..d4944497e 100644 --- a/tests/auto_test/test_abacus.py +++ b/tests/auto_test/test_abacus.py @@ -216,7 +216,7 @@ def test_make_input_file_kspacing_three_value(self): kpt = f1.read().strip().split("\n")[-1].split() self.assertEqual(kpt, ["9", "5", "3", "0", "0", "0"]) - def test_compuate(self): + def test_compute(self): ret = self.ABACUS.compute(os.path.join(self.equi_path)) self.assertIsNone(ret) shutil.copy( @@ -247,7 +247,21 @@ def compare_dict(dict1, dict2): else: self.assertTrue(dict1[key] == dict2[key]) - compare_dict(ret, ret_ref.as_dict()) + compare_keys = [ + "atom_numbs", + "atom_names", + "atom_types", + "cells", + "coords", + "energies", + "forces", + "virials", + "stress", + ] + compare_dict( + {k: ret["data"][k] for k in compare_keys}, + {k: ret_ref.data[k] for k in compare_keys}, + ) class TestABACUSDeepKS(unittest.TestCase): diff --git a/tests/data/test_gen_bulk_abacus.py b/tests/data/test_gen_bulk_abacus.py index 520589829..728a6964e 100644 --- a/tests/data/test_gen_bulk_abacus.py +++ b/tests/data/test_gen_bulk_abacus.py @@ -76,6 +76,7 @@ def test(self): def testSTRU(self): jdata = self.jdata jdata["from_poscar_path"] = "./Cu.STRU" + jdata["potcars"] = ["abacus.in/Cu_ONCV_PBE-1.0.upf"] make_super_cell_STRU(jdata) make_abacus_relax(jdata, {"fp_resources": {}}) make_scale_ABACUS(jdata) From ac7010acb04da10179117e8c71f291583c4de3b4 Mon Sep 17 00:00:00 2001 From: Peng Xingliang <91927439+pxlxingliang@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:49:49 +0800 Subject: [PATCH 11/12] bump the dpdata version to 0.2.23 (#1720) ## Summary by CodeRabbit - **Chores** - Updated the minimum required version for a key dependency to ensure access to the latest enhancements and fixes. Co-authored-by: root --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 12a9cb329..36c4575e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ ] dependencies = [ 'numpy>=1.14.3', - 'dpdata>=0.2.17', + 'dpdata>=0.2.23', 'cp2kdata>=0.6.6', 'pymatgen>=2022.11.1', 'ase', From bc70e21fac2b12fa710972560da674096e9ea754 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 05:52:47 +0000 Subject: [PATCH 12/12] [pre-commit.ci] pre-commit autoupdate (#1712) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.9.2 → v0.9.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.2...v0.9.6) 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 3315eb212..234821eeb 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.9.2 + rev: v0.9.6 hooks: - id: ruff args: ["--fix"]