Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1703)
Browse files Browse the repository at this point in the history
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.4 →
v0.9.1](astral-sh/ruff-pre-commit@v0.8.4...v0.9.1)
<!--pre-commit.ci end-->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jan 14, 2025
1 parent b9b71a4 commit 8e9532d
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
18 changes: 9 additions & 9 deletions dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions dpgen/auto_test/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
117 changes: 57 additions & 60 deletions dpgen/generator/lib/abacus_scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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 [
Expand All @@ -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"])
Expand All @@ -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":
Expand All @@ -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(
Expand Down Expand Up @@ -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 += (
Expand Down
6 changes: 3 additions & 3 deletions dpgen/generator/lib/calypso_run_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions dpgen/generator/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))):
Expand Down
Loading

0 comments on commit 8e9532d

Please sign in to comment.