Skip to content

Commit 6ea3913

Browse files
committed
run pre-commit
1 parent 16c1520 commit 6ea3913

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+350
-370
lines changed

dpgen/auto_test/ABACUS.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, inter_parameter, path_to_poscar):
2626
def make_potential_files(self, output_dir):
2727
stru = os.path.abspath(os.path.join(output_dir, "STRU"))
2828
if not os.path.isfile(stru):
29-
raise FileNotFoundError("No file %s" % stru)
29+
raise FileNotFoundError(f"No file {stru}")
3030
stru_data = abacus_scf.get_abacus_STRU(stru)
3131
atom_names = stru_data["atom_names"]
3232
orb_files = stru_data["orb_files"]
@@ -58,7 +58,7 @@ def make_potential_files(self, output_dir):
5858
)
5959
if atomname not in self.potcars:
6060
raise RuntimeError(
61-
"please specify the pseudopotential file of '%s'" % atomname
61+
f"please specify the pseudopotential file of '{atomname}'"
6262
)
6363
pp_orb_file.append([pp_files[iatom], self.potcars[atomname]])
6464

@@ -70,7 +70,7 @@ def make_potential_files(self, output_dir):
7070
)
7171
if atomname not in self.orbfile:
7272
raise RuntimeError(
73-
"please specify the orbital file of '%s'" % atomname
73+
f"please specify the orbital file of '{atomname}'"
7474
)
7575
pp_orb_file.append([orb_files[iatom], self.orbfile[atomname]])
7676
elif self.orbfile:
@@ -105,7 +105,7 @@ def make_potential_files(self, output_dir):
105105

106106
src_file = os.path.join(pp_dir, file_param)
107107
if not os.path.isfile(src_file):
108-
raise RuntimeError("Can not find file %s" % src_file)
108+
raise RuntimeError(f"Can not find file {src_file}")
109109
tar_file = os.path.join("pp_orb", filename_in_stru)
110110
if os.path.isfile(tar_file):
111111
os.remove(tar_file)
@@ -138,8 +138,7 @@ def make_input_file(self, output_dir, task_type, task_param):
138138
incar_prop = os.path.abspath(cal_setting["input_prop"])
139139
incar = abacus_scf.get_abacus_input_parameters(incar_prop)
140140
dlog.info(
141-
"Detected 'input_prop' in 'relaxation', use %s as INPUT, and ignore 'cal_setting'"
142-
% incar_prop
141+
f"Detected 'input_prop' in 'relaxation', use {incar_prop} as INPUT, and ignore 'cal_setting'"
143142
)
144143

145144
# revise INCAR based on the INCAR provided in the "interaction"
@@ -195,9 +194,8 @@ def make_input_file(self, output_dir, task_type, task_param):
195194
dlog.info("'basis_type' is not defined, set to be 'pw'!")
196195
self.modify_input(incar, "basis_type", "pw")
197196
if "lcao" in incar["basis_type"].lower() and not self.if_define_orb_file:
198-
mess = (
199-
"The basis_type is %s, but not define orbital file!!!"
200-
% incar["basis_type"]
197+
mess = "The basis_type is {}, but not define orbital file!!!".format(
198+
incar["basis_type"]
201199
)
202200
raise RuntimeError(mess)
203201
if "deepks_model" in incar:

dpgen/auto_test/EOS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, parameter, inter_param=None):
8181
def make_confs(self, path_to_work, path_to_equi, refine=False):
8282
path_to_work = os.path.abspath(path_to_work)
8383
if os.path.exists(path_to_work):
84-
dlog.warning("%s already exists" % path_to_work)
84+
dlog.warning(f"{path_to_work} already exists")
8585
else:
8686
os.makedirs(path_to_work)
8787
path_to_equi = os.path.abspath(path_to_equi)
@@ -177,7 +177,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
177177

178178
if not os.path.isfile(equi_contcar):
179179
raise RuntimeError(
180-
"Can not find %s, please do relaxation first" % equi_contcar
180+
f"Can not find {equi_contcar}, please do relaxation first"
181181
)
182182

183183
if self.inter_param["type"] == "abacus":

dpgen/auto_test/Elastic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, parameter, inter_param=None):
5555
def make_confs(self, path_to_work, path_to_equi, refine=False):
5656
path_to_work = os.path.abspath(path_to_work)
5757
if os.path.exists(path_to_work):
58-
dlog.warning("%s already exists" % path_to_work)
58+
dlog.warning(f"{path_to_work} already exists")
5959
else:
6060
os.makedirs(path_to_work)
6161
path_to_equi = os.path.abspath(path_to_equi)
@@ -288,10 +288,10 @@ def _compute_lower(self, output_file, all_tasks, all_res):
288288
res_data["GV"] = GV
289289
res_data["EV"] = EV
290290
res_data["uV"] = uV
291-
ptr_data += "# Bulk Modulus BV = %.2f GPa\n" % BV
292-
ptr_data += "# Shear Modulus GV = %.2f GPa\n" % GV
293-
ptr_data += "# Youngs Modulus EV = %.2f GPa\n" % EV
294-
ptr_data += "# Poission Ratio uV = %.2f\n " % uV
291+
ptr_data += f"# Bulk Modulus BV = {BV:.2f} GPa\n"
292+
ptr_data += f"# Shear Modulus GV = {GV:.2f} GPa\n"
293+
ptr_data += f"# Youngs Modulus EV = {EV:.2f} GPa\n"
294+
ptr_data += f"# Poission Ratio uV = {uV:.2f}\n "
295295

296296
dumpfn(res_data, output_file, indent=4)
297297

dpgen/auto_test/Gamma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, parameter, inter_param=None):
9696
def make_confs(self, path_to_work, path_to_equi, refine=False):
9797
path_to_work = os.path.abspath(path_to_work)
9898
if os.path.exists(path_to_work):
99-
dlog.warning("%s already exists" % path_to_work)
99+
dlog.warning(f"{path_to_work} already exists")
100100
else:
101101
os.makedirs(path_to_work)
102102
path_to_equi = os.path.abspath(path_to_equi)

dpgen/auto_test/Interstitial.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
269269
print(self.insert_ele[0], file=fout)
270270
dumpfn(self.supercell, "supercell.json")
271271
pos_line[chl] = (
272-
"%.6f" % float(latt_param / 4 / super_latt_param)
272+
f"{float(latt_param / 4 / super_latt_param):.6f}"
273273
+ " "
274-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
274+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
275275
+ " 0.000000 "
276276
+ self.insert_ele[0]
277277
)
@@ -291,9 +291,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
291291
print(self.insert_ele[0], file=fout)
292292
dumpfn(self.supercell, "supercell.json")
293293
pos_line[chl] = (
294-
"%.6f" % float(latt_param / 2 / super_latt_param)
294+
f"{float(latt_param / 2 / super_latt_param):.6f}"
295295
+ " "
296-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
296+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
297297
+ " 0.000000 "
298298
+ self.insert_ele[0]
299299
)
@@ -313,11 +313,11 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
313313
print(self.insert_ele[0], file=fout)
314314
dumpfn(self.supercell, "supercell.json")
315315
pos_line[chl] = (
316-
"%.6f" % float(latt_param / 4 / super_latt_param)
316+
f"{float(latt_param / 4 / super_latt_param):.6f}"
317317
+ " "
318-
+ "%.6f" % float(latt_param / 4 / super_latt_param)
318+
+ f"{float(latt_param / 4 / super_latt_param):.6f}"
319319
+ " "
320-
+ "%.6f" % float(latt_param / 4 / super_latt_param)
320+
+ f"{float(latt_param / 4 / super_latt_param):.6f}"
321321
+ " "
322322
+ self.insert_ele[0]
323323
)
@@ -354,20 +354,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
354354
print(self.insert_ele[0], file=fout)
355355
dumpfn(self.supercell, "supercell.json")
356356
pos_line[chl] = (
357-
"%.6f" % float(latt_param / 3 / super_latt_param)
357+
f"{float(latt_param / 3 / super_latt_param):.6f}"
358358
+ " "
359-
+ "%.6f" % float(latt_param / 3 / super_latt_param)
359+
+ f"{float(latt_param / 3 / super_latt_param):.6f}"
360360
+ " "
361-
+ "%.6f" % float(latt_param / 3 / super_latt_param)
361+
+ f"{float(latt_param / 3 / super_latt_param):.6f}"
362362
+ " "
363363
+ self.insert_ele[0]
364364
)
365365
pos_line[replace_label] = (
366-
"%.6f" % float(latt_param / 3 * 2 / super_latt_param)
366+
f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
367367
+ " "
368-
+ "%.6f" % float(latt_param / 3 * 2 / super_latt_param)
368+
+ f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
369369
+ " "
370-
+ "%.6f" % float(latt_param / 3 * 2 / super_latt_param)
370+
+ f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
371371
+ " "
372372
+ self.insert_ele[0]
373373
)
@@ -388,24 +388,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
388388
print(self.insert_ele[0], file=fout)
389389
dumpfn(self.supercell, "supercell.json")
390390
pos_line[chl] = (
391-
"%.6f"
392-
% float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param)
391+
f"{float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
393392
+ " "
394-
+ "%.6f"
395-
% float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param)
393+
+ f"{float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
396394
+ " "
397-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
395+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
398396
+ " "
399397
+ self.insert_ele[0]
400398
)
401399
pos_line[replace_label] = (
402-
"%.6f"
403-
% float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param)
400+
f"{float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
404401
+ " "
405-
+ "%.6f"
406-
% float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param)
402+
+ f"{float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
407403
+ " "
408-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
404+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
409405
+ " "
410406
+ self.insert_ele[0]
411407
)
@@ -426,20 +422,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
426422
print(self.insert_ele[0], file=fout)
427423
dumpfn(self.supercell, "supercell.json")
428424
pos_line[chl] = (
429-
"%.6f" % float(latt_param / 2 / super_latt_param)
425+
f"{float(latt_param / 2 / super_latt_param):.6f}"
430426
+ " "
431-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
427+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
432428
+ " "
433-
+ "%.6f" % float((latt_param - 2.1) / 2 / super_latt_param)
429+
+ f"{float((latt_param - 2.1) / 2 / super_latt_param):.6f}"
434430
+ " "
435431
+ self.insert_ele[0]
436432
)
437433
pos_line[replace_label] = (
438-
"%.6f" % float(latt_param / 2 / super_latt_param)
434+
f"{float(latt_param / 2 / super_latt_param):.6f}"
439435
+ " "
440-
+ "%.6f" % float(latt_param / 2 / super_latt_param)
436+
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
441437
+ " "
442-
+ "%.6f" % float((latt_param + 2.1) / 2 / super_latt_param)
438+
+ f"{float((latt_param + 2.1) / 2 / super_latt_param):.6f}"
443439
+ " "
444440
+ self.insert_ele[0]
445441
)
@@ -483,9 +479,9 @@ def post_process(self, task_list):
483479
conf_line[-2] = (
484480
"%6.d" % int(insert_line.split()[0])
485481
+ "%7.d" % type_num
486-
+ "%16.10f" % float(insert_line.split()[2])
487-
+ "%16.10f" % float(insert_line.split()[3])
488-
+ "%16.10f" % float(insert_line.split()[4])
482+
+ f"{float(insert_line.split()[2]):16.10f}"
483+
+ f"{float(insert_line.split()[3]):16.10f}"
484+
+ f"{float(insert_line.split()[4]):16.10f}"
489485
)
490486
with open(conf, "w+") as fout:
491487
for jj in conf_line:

dpgen/auto_test/Surface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def __init__(self, parameter, inter_param=None):
8787
def make_confs(self, path_to_work, path_to_equi, refine=False):
8888
path_to_work = os.path.abspath(path_to_work)
8989
if os.path.exists(path_to_work):
90-
dlog.warning("%s already exists" % path_to_work)
90+
dlog.warning(f"{path_to_work} already exists")
9191
else:
9292
os.makedirs(path_to_work)
9393
path_to_equi = os.path.abspath(path_to_equi)

dpgen/auto_test/Vacancy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, parameter, inter_param=None):
7979
def make_confs(self, path_to_work, path_to_equi, refine=False):
8080
path_to_work = os.path.abspath(path_to_work)
8181
if os.path.exists(path_to_work):
82-
dlog.warning("%s already exists" % path_to_work)
82+
dlog.warning(f"{path_to_work} already exists")
8383
else:
8484
os.makedirs(path_to_work)
8585
path_to_equi = os.path.abspath(path_to_equi)

dpgen/auto_test/common_equi.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def make_equi(confs, inter_param, relax_param):
2727
else:
2828
ele_list = [key for key in inter_param["potcars"].keys()]
2929
# ele_list = inter_param['type_map']
30-
dlog.debug("ele_list %s" % ":".join(ele_list))
30+
dlog.debug("ele_list {}".format(":".join(ele_list)))
3131
conf_dirs = []
3232
for conf in confs:
3333
conf_dirs.extend(glob.glob(conf))
@@ -45,8 +45,8 @@ def make_equi(confs, inter_param, relax_param):
4545
for ii in conf_dirs:
4646
os.chdir(ii)
4747
crys_type = ii.split("/")[-1]
48-
dlog.debug("crys_type: %s" % crys_type)
49-
dlog.debug("pwd: %s" % os.getcwd())
48+
dlog.debug(f"crys_type: {crys_type}")
49+
dlog.debug(f"pwd: {os.getcwd()}")
5050
if crys_type == "std-fcc":
5151
if not os.path.exists("POSCAR"):
5252
crys.fcc1(ele_list[element_label]).to("POSCAR", "POSCAR")
@@ -77,7 +77,7 @@ def make_equi(confs, inter_param, relax_param):
7777
# ...
7878
for ii in conf_dirs:
7979
crys_type = ii.split("/")[-1]
80-
dlog.debug("crys_type: %s" % crys_type)
80+
dlog.debug(f"crys_type: {crys_type}")
8181

8282
if "mp-" in crys_type and not os.path.exists(os.path.join(ii, "POSCAR")):
8383
get_structure(crys_type).to("POSCAR", os.path.join(ii, "POSCAR"))
@@ -130,7 +130,7 @@ def make_equi(confs, inter_param, relax_param):
130130

131131
for ii in task_dirs:
132132
poscar = os.path.join(ii, "POSCAR")
133-
dlog.debug("task_dir %s" % ii)
133+
dlog.debug(f"task_dir {ii}")
134134
inter = make_calculator(inter_param, poscar)
135135
inter.make_potential_files(ii)
136136
inter.make_input_file(ii, "relaxation", relax_param)
@@ -162,7 +162,7 @@ def run_equi(confs, inter_param, mdata):
162162
elif inter_type in lammps_task_type:
163163
mdata = convert_mdata(mdata, ["model_devi"])
164164
else:
165-
raise RuntimeError("unknown task %s, something wrong" % inter_type)
165+
raise RuntimeError(f"unknown task {inter_type}, something wrong")
166166

167167
# dispatch the tasks
168168
# POSCAR here is useless
@@ -173,12 +173,12 @@ def run_equi(confs, inter_param, mdata):
173173
# backward_files += logs
174174
machine, resources, command, group_size = util.get_machine_info(mdata, inter_type)
175175
work_path = os.getcwd()
176-
print("%s --> Runing... " % (work_path))
176+
print(f"{work_path} --> Runing... ")
177177

178178
api_version = mdata.get("api_version", "1.0")
179179
if Version(api_version) < Version("1.0"):
180180
raise RuntimeError(
181-
"API version %s has been removed. Please upgrade to 1.0." % api_version
181+
f"API version {api_version} has been removed. Please upgrade to 1.0."
182182
)
183183
elif Version(api_version) >= Version("1.0"):
184184
submission = make_submission(

dpgen/auto_test/common_prop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def run_property(confs, inter_param, property_list, mdata):
155155
elif inter_type in lammps_task_type:
156156
mdata = convert_mdata(mdata, ["model_devi"])
157157
else:
158-
raise RuntimeError("unknown task %s, something wrong" % inter_type)
158+
raise RuntimeError(f"unknown task {inter_type}, something wrong")
159159

160160
work_path = path_to_work
161161
all_task = tmp_task_list
@@ -199,7 +199,7 @@ def worker(
199199
api_version = mdata.get("api_version", "1.0")
200200
if Version(api_version) < Version("1.0"):
201201
raise RuntimeError(
202-
"API version %s has been removed. Please upgrade to 1.0." % api_version
202+
f"API version {api_version} has been removed. Please upgrade to 1.0."
203203
)
204204
elif Version(api_version) >= Version("1.0"):
205205
submission = make_submission(

dpgen/auto_test/gen_confs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _main():
134134
)
135135
args = parser.parse_args()
136136

137-
print("generate %s" % (args.elements))
137+
print(f"generate {args.elements}")
138138
if len(args.elements) == 1:
139139
gen_element(args.elements[0], args.key)
140140
# gen_element_std(args.elements[0])

0 commit comments

Comments
 (0)