Skip to content

Commit a970d4f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1b0ac83 commit a970d4f

File tree

11 files changed

+151
-154
lines changed

11 files changed

+151
-154
lines changed

dpgen/auto_test/lib/abacus.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,25 @@ def poscar2stru(poscar, inter_param, stru="STRU"):
161161
else:
162162
atom_mass_dict = inter_param["atom_masses"]
163163
for atom in stru_data["atom_names"]:
164-
assert (
165-
atom in atom_mass_dict
166-
), f"the mass of {atom} is not defined in interaction:atom_masses"
164+
assert atom in atom_mass_dict, (
165+
f"the mass of {atom} is not defined in interaction:atom_masses"
166+
)
167167
atom_mass.append(atom_mass_dict[atom])
168168

169169
if "potcars" in inter_param:
170170
pseudo = []
171171
for atom in stru_data["atom_names"]:
172-
assert (
173-
atom in inter_param["potcars"]
174-
), f"the pseudopotential of {atom} is not defined in interaction:potcars"
172+
assert atom in inter_param["potcars"], (
173+
f"the pseudopotential of {atom} is not defined in interaction:potcars"
174+
)
175175
pseudo.append("./pp_orb/" + inter_param["potcars"][atom].split("/")[-1])
176176

177177
if "orb_files" in inter_param:
178178
orb = []
179179
for atom in stru_data["atom_names"]:
180-
assert (
181-
atom in inter_param["orb_files"]
182-
), f"orbital file of {atom} is not defined in interaction:orb_files"
180+
assert atom in inter_param["orb_files"], (
181+
f"orbital file of {atom} is not defined in interaction:orb_files"
182+
)
183183
orb.append("./pp_orb/" + inter_param["orb_files"][atom].split("/")[-1])
184184

185185
if "deepks_desc" in inter_param:

dpgen/auto_test/reproduce.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def make_repro(
3434
init_data_task_todo = glob.glob(
3535
os.path.join(init_data_path_todo, "task.[0-9]*[0-9]")
3636
)
37-
assert (
38-
len(init_data_task_todo) > 0
39-
), "There is no task in previous calculations path"
37+
assert len(init_data_task_todo) > 0, (
38+
"There is no task in previous calculations path"
39+
)
4040
init_data_task_todo.sort()
4141

4242
task_list = []
@@ -122,9 +122,9 @@ def post_repro(
122122
init_data_task_todo = glob.glob(
123123
os.path.join(init_data_path_todo, "task.[0-9]*[0-9]")
124124
)
125-
assert (
126-
len(init_data_task_todo) > 0
127-
), "There is no task in previous calculations path"
125+
assert len(init_data_task_todo) > 0, (
126+
"There is no task in previous calculations path"
127+
)
128128
init_data_task_todo.sort()
129129

130130
idid = 0

dpgen/data/gen.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,9 @@ def make_abacus_relax(jdata, mdata):
584584
raise RuntimeError("Cannot find any k-points information.")
585585
else:
586586
relax_kpt_path = jdata["relax_kpt"]
587-
assert os.path.isfile(
588-
relax_kpt_path
589-
), f"file {relax_kpt_path} should exists"
587+
assert os.path.isfile(relax_kpt_path), (
588+
f"file {relax_kpt_path} should exists"
589+
)
590590
else:
591591
gamma_param = {"k_points": [1, 1, 1, 0, 0, 0]}
592592
ret_kpt = make_abacus_scf_kpt(gamma_param)
@@ -595,9 +595,9 @@ def make_abacus_relax(jdata, mdata):
595595
raise RuntimeError("Cannot find any k-points information.")
596596
else:
597597
relax_kpt_path = jdata["relax_kpt"]
598-
assert os.path.isfile(
599-
relax_kpt_path
600-
), f"file {relax_kpt_path} should exists"
598+
assert os.path.isfile(relax_kpt_path), (
599+
f"file {relax_kpt_path} should exists"
600+
)
601601

602602
out_dir = jdata["out_dir"]
603603
cwd = os.getcwd()
@@ -779,10 +779,10 @@ def pert_scaled(jdata):
779779
### Loop over each perturbation
780780
for kk in range(pert_numb):
781781
if fp_style == "vasp":
782-
pos_in = f"POSCAR{kk+1}.vasp"
782+
pos_in = f"POSCAR{kk + 1}.vasp"
783783
elif fp_style == "abacus":
784-
pos_in = f"STRU{kk+1}.abacus"
785-
dir_out = f"{kk+1:06d}"
784+
pos_in = f"STRU{kk + 1}.abacus"
785+
dir_out = f"{kk + 1:06d}"
786786
create_path(dir_out)
787787
if fp_style == "vasp":
788788
pos_out = os.path.join(dir_out, "POSCAR")
@@ -814,7 +814,7 @@ def pert_scaled(jdata):
814814
pos_in = "POSCAR"
815815
elif fp_style == "abacus":
816816
pos_in = "STRU"
817-
dir_out = f"{kk+1:06d}"
817+
dir_out = f"{kk + 1:06d}"
818818
create_path(dir_out)
819819
if fp_style == "vasp":
820820
pos_out = os.path.join(dir_out, "POSCAR")
@@ -928,9 +928,9 @@ def make_abacus_md(jdata, mdata):
928928
raise RuntimeError("Cannot find any k-points information.")
929929
else:
930930
md_kpt_path = jdata["md_kpt"]
931-
assert os.path.isfile(
932-
md_kpt_path
933-
), f"file {md_kpt_path} should exists"
931+
assert os.path.isfile(md_kpt_path), (
932+
f"file {md_kpt_path} should exists"
933+
)
934934
else:
935935
ret_kpt = make_abacus_scf_kpt({"k_points": [1, 1, 1, 0, 0, 0]})
936936
else:

dpgen/data/surf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ def pert_scaled(jdata):
525525
poscar_elong(poscar_in, "POSCAR", ll)
526526
sp.check_call(pert_cmd, shell=True)
527527
for kk in range(pert_numb):
528-
pos_in = f"POSCAR{kk+1}.vasp"
529-
dir_out = f"{kk+1:06d}"
528+
pos_in = f"POSCAR{kk + 1}.vasp"
529+
dir_out = f"{kk + 1:06d}"
530530
create_path(dir_out)
531531
pos_out = os.path.join(dir_out, "POSCAR")
532532
poscar_shuffle(pos_in, pos_out)
@@ -535,7 +535,7 @@ def pert_scaled(jdata):
535535
### Handle special case (unperturbed ?)
536536
kk = -1
537537
pos_in = "POSCAR"
538-
dir_out = f"{kk+1:06d}"
538+
dir_out = f"{kk + 1:06d}"
539539
create_path(dir_out)
540540
pos_out = os.path.join(dir_out, "POSCAR")
541541
poscar_shuffle(pos_in, pos_out)

dpgen/generator/lib/abacus_scf.py

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
4545
fp_params["kspacing"] = [
4646
float(i) for i in fp_params["kspacing"].split()
4747
]
48-
assert (
49-
len(fp_params["kspacing"])
50-
in [
51-
1,
52-
3,
53-
]
54-
), "'kspacing' only accept a float, or a list of one or three float, or a string of one or three float"
48+
assert len(fp_params["kspacing"]) in [
49+
1,
50+
3,
51+
], (
52+
"'kspacing' only accept a float, or a list of one or three float, or a string of one or three float"
53+
)
5554
ret += "kspacing "
5655
for ikspacing in fp_params["kspacing"]:
5756
assert ikspacing >= 0, "'kspacing' should be non-negative."
@@ -78,9 +77,9 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
7877
elif key == "gamma_only":
7978
if isinstance(fp_params["gamma_only"], str):
8079
fp_params["gamma_only"] = int(eval(fp_params["gamma_only"]))
81-
assert (
82-
fp_params["gamma_only"] == 0 or fp_params["gamma_only"] == 1
83-
), "'gamma_only' should be either 0 or 1."
80+
assert fp_params["gamma_only"] == 0 or fp_params["gamma_only"] == 1, (
81+
"'gamma_only' should be either 0 or 1."
82+
)
8483
ret += "gamma_only %d\n" % fp_params["gamma_only"] # noqa: UP031
8584
elif key == "mixing_type":
8685
assert fp_params["mixing_type"] in [
@@ -93,22 +92,22 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
9392
ret += "mixing_type {}\n".format(fp_params["mixing_type"])
9493
elif key == "mixing_beta":
9594
fp_params["mixing_beta"] = float(fp_params["mixing_beta"])
96-
assert (
97-
fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1
98-
), "'mixing_beta' should between 0 and 1."
95+
assert fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1, (
96+
"'mixing_beta' should between 0 and 1."
97+
)
9998
ret += "mixing_beta {:f}\n".format(fp_params["mixing_beta"])
10099
elif key == "symmetry":
101100
if isinstance(fp_params["symmetry"], str):
102101
fp_params["symmetry"] = int(eval(fp_params["symmetry"]))
103-
assert (
104-
fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1
105-
), "'symmetry' should be either 0 or 1."
102+
assert fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1, (
103+
"'symmetry' should be either 0 or 1."
104+
)
106105
ret += "symmetry %d\n" % fp_params["symmetry"] # noqa: UP031
107106
elif key == "nbands":
108107
fp_params["nbands"] = int(fp_params["nbands"])
109-
assert fp_params["nbands"] > 0 and isinstance(
110-
fp_params["nbands"], int
111-
), "'nbands' should be a positive integer."
108+
assert fp_params["nbands"] > 0 and isinstance(fp_params["nbands"], int), (
109+
"'nbands' should be a positive integer."
110+
)
112111
ret += "nbands %d\n" % fp_params["nbands"] # noqa: UP031
113112
elif key == "nspin":
114113
fp_params["nspin"] = int(fp_params["nspin"])
@@ -119,51 +118,49 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
119118
), "'nspin' can anly take 1, 2 or 4"
120119
ret += "nspin %d\n" % fp_params["nspin"] # noqa: UP031
121120
elif key == "ks_solver":
122-
assert (
123-
fp_params["ks_solver"]
124-
in [
125-
"cg",
126-
"dav",
127-
"lapack",
128-
"genelpa",
129-
"hpseps",
130-
"scalapack_gvx",
131-
]
132-
), "'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'."
121+
assert fp_params["ks_solver"] in [
122+
"cg",
123+
"dav",
124+
"lapack",
125+
"genelpa",
126+
"hpseps",
127+
"scalapack_gvx",
128+
], (
129+
"'ks_sover' should in 'cgx', 'dav', 'lapack', 'genelpa', 'hpseps', 'scalapack_gvx'."
130+
)
133131
ret += "ks_solver {}\n".format(fp_params["ks_solver"])
134132
elif key == "smearing_method":
135-
assert (
136-
fp_params["smearing_method"]
137-
in [
138-
"gauss",
139-
"gaussian",
140-
"fd",
141-
"fixed",
142-
"mp",
143-
"mp2",
144-
"mv",
145-
]
146-
), "'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. "
133+
assert fp_params["smearing_method"] in [
134+
"gauss",
135+
"gaussian",
136+
"fd",
137+
"fixed",
138+
"mp",
139+
"mp2",
140+
"mv",
141+
], (
142+
"'smearing_method' should in 'gauss', 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. "
143+
)
147144
ret += "smearing_method {}\n".format(fp_params["smearing_method"])
148145
elif key == "smearing_sigma":
149146
fp_params["smearing_sigma"] = float(fp_params["smearing_sigma"])
150-
assert (
151-
fp_params["smearing_sigma"] >= 0
152-
), "'smearing_sigma' should be non-negative."
147+
assert fp_params["smearing_sigma"] >= 0, (
148+
"'smearing_sigma' should be non-negative."
149+
)
153150
ret += "smearing_sigma {:f}\n".format(fp_params["smearing_sigma"])
154151
elif key == "cal_force":
155152
if isinstance(fp_params["cal_force"], str):
156153
fp_params["cal_force"] = int(eval(fp_params["cal_force"]))
157-
assert (
158-
fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1
159-
), "'cal_force' should be either 0 or 1."
154+
assert fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1, (
155+
"'cal_force' should be either 0 or 1."
156+
)
160157
ret += "cal_force %d\n" % fp_params["cal_force"] # noqa: UP031
161158
elif key == "cal_stress":
162159
if isinstance(fp_params["cal_stress"], str):
163160
fp_params["cal_stress"] = int(eval(fp_params["cal_stress"]))
164-
assert (
165-
fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1
166-
), "'cal_stress' should be either 0 or 1."
161+
assert fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1, (
162+
"'cal_stress' should be either 0 or 1."
163+
)
167164
ret += "cal_stress %d\n" % fp_params["cal_stress"] # noqa: UP031
168165
# paras for deepks
169166
elif key == "deepks_out_labels":
@@ -180,16 +177,16 @@ def make_abacus_scf_input(fp_params, extra_file_path=""):
180177
fp_params["deepks_descriptor_lmax"] = int(
181178
fp_params["deepks_descriptor_lmax"]
182179
)
183-
assert (
184-
fp_params["deepks_descriptor_lmax"] >= 0
185-
), "'deepks_descriptor_lmax' should be a positive integer."
180+
assert fp_params["deepks_descriptor_lmax"] >= 0, (
181+
"'deepks_descriptor_lmax' should be a positive integer."
182+
)
186183
ret += "deepks_descriptor_lmax %d\n" % fp_params["deepks_descriptor_lmax"] # noqa: UP031
187184
elif key == "deepks_scf":
188185
if isinstance(fp_params["deepks_scf"], str):
189186
fp_params["deepks_scf"] = int(eval(fp_params["deepks_scf"]))
190-
assert (
191-
fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1
192-
), "'deepks_scf' should be either 0 or 1."
187+
assert fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1, (
188+
"'deepks_scf' should be either 0 or 1."
189+
)
193190
ret += "deepks_scf %d\n" % fp_params["deepks_scf"] # noqa: UP031
194191
elif key == "deepks_model":
195192
ret += "deepks_model {}\n".format(
@@ -228,9 +225,9 @@ def make_abacus_scf_stru(
228225

229226
ret = "ATOMIC_SPECIES\n"
230227
for iatom in range(len(atom_names)):
231-
assert (
232-
atom_names[iatom] in type_map
233-
), f"element {atom_names[iatom]} is not defined in type_map"
228+
assert atom_names[iatom] in type_map, (
229+
f"element {atom_names[iatom]} is not defined in type_map"
230+
)
234231
idx = type_map.index(atom_names[iatom])
235232
if "atom_masses" not in sys_data:
236233
ret += (

dpgen/generator/lib/calypso_run_opt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def read_stress_fmax():
9494
try:
9595
f = open("input.dat")
9696
except Exception:
97-
assert os.path.exists(
98-
"../input.dat"
99-
), f" now we are in {os.getcwd()}, do not find ../input.dat"
97+
assert os.path.exists("../input.dat"), (
98+
f" now we are in {os.getcwd()}, do not find ../input.dat"
99+
)
100100
f = open("../input.dat")
101101
lines = f.readlines()
102102
f.close()

dpgen/generator/lib/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def symlink_user_forward_files(mdata, task_type, work_path, task_format=None):
102102
task_format = {"train": "0*", "model_devi": "task.*", "fp": "task.*"}
103103
# "init_relax" : "sys-*", "init_md" : "sys-*/scale*/00*"
104104
for file in user_forward_files:
105-
assert os.path.isfile(
106-
file
107-
), f"user_forward_file {file} of {task_type} stage doesn't exist. "
105+
assert os.path.isfile(file), (
106+
f"user_forward_file {file} of {task_type} stage doesn't exist. "
107+
)
108108
tasks = glob.glob(os.path.join(work_path, task_format[task_type]))
109109
for task in tasks:
110110
if os.path.isfile(os.path.join(task, os.path.basename(file))):

0 commit comments

Comments
 (0)