Skip to content

Commit 7471da8

Browse files
[pre-commit.ci] pre-commit autoupdate (#1483)
1 parent 1737bf6 commit 7471da8

File tree

13 files changed

+54
-100
lines changed

13 files changed

+54
-100
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828

2929
# Python
3030
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
rev: v0.2.2
31+
rev: v0.3.2
3232
hooks:
3333
- id: ruff
3434
args: ["--fix"]

dpgen/auto_test/lib/mfp_eosfit.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,16 +1441,7 @@ def ext_velp(
14411441
)
14421442
for i in range(ndata):
14431443
fw.write(
1444-
"{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\t{:12.6f}\n".format(
1445-
vv[i],
1446-
ee[i],
1447-
cellaa[i],
1448-
cellbb[i],
1449-
cellcc[i],
1450-
cellbaba[i],
1451-
cellcaca[i],
1452-
cellca_cal[i],
1453-
)
1444+
f"{vv[i]:12.6f}\t{ee[i]:12.6f}\t{cellaa[i]:12.6f}\t{cellbb[i]:12.6f}\t{cellcc[i]:12.6f}\t{cellbaba[i]:12.6f}\t{cellcaca[i]:12.6f}\t{cellca_cal[i]:12.6f}\n"
14541445
)
14551446
fw.flush()
14561447
fw.close()
@@ -1662,9 +1653,7 @@ def lsqfit_eos(
16621653
)
16631654
for i in range(len(vol)):
16641655
fve.write(
1665-
"{:20f}\t{:20f}\t{:20f}\t{:20f}\n".format(
1666-
vol[i], repro_en[i], en[i], 100 * np.abs((en[i] - repro_en[i]) / en[i])
1667-
)
1656+
f"{vol[i]:20f}\t{repro_en[i]:20f}\t{en[i]:20f}\t{100 * np.abs((en[i] - repro_en[i]) / en[i]):20f}\n"
16681657
)
16691658
fve.flush()
16701659
p_tmp = repro_press[i]

dpgen/auto_test/lib/pwscf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ def _make_pwscf_03_config(sys_data):
7272
cc = 0
7373
for ii in range(ntypes):
7474
for jj in range(atom_numbs[ii]):
75-
ret += "{} {:f} {:f} {:f}\n".format(
76-
atom_names[ii],
77-
coordinates[cc][0],
78-
coordinates[cc][1],
79-
coordinates[cc][2],
80-
)
75+
ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n"
8176
cc += 1
8277
return ret
8378

dpgen/auto_test/reproduce.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,7 @@ def post_repro(
153153
output_ener_tot.extend(output_task_result["energies"])
154154

155155
init_epa = init_ener[jj - idid] / natoms
156-
ptr_data += "{} {:7.3f} {:7.3f} {:7.3f}\n".format(
157-
ii,
158-
init_epa,
159-
output_epa,
160-
output_epa - init_epa,
161-
)
156+
ptr_data += f"{ii} {init_epa:7.3f} {output_epa:7.3f} {output_epa - init_epa:7.3f}\n"
162157
idid += nframe
163158
output_ener = np.array(output_ener)
164159
output_ener = np.reshape(output_ener, [-1, 1])

dpgen/data/tools/ovito_file_convert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""This Script is adapted from Alexander Stukowski, the author of OVITO.
33
See: http://forum.ovito.org/index.php?topic=131.0 for details.
44
"""
5+
56
import argparse
67

78
from ovito.io import export_file, import_file

dpgen/generator/lib/abacus_scf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ def get_abacus_STRU(STRU, INPUT=None, n_ele=None):
401401
data["atom_types"] = types
402402
data["cells"] = cell
403403
data["coords"] = coords
404-
data[
405-
"atom_masses"
406-
] = masses # Notice that this key is not defined in dpdata system.
404+
data["atom_masses"] = (
405+
masses # Notice that this key is not defined in dpdata system.
406+
)
407407
data["pp_files"] = pp_files
408408
data["orb_files"] = orb_files
409409
data["dpks_descriptor"] = dpks_descriptor

dpgen/generator/lib/lammps.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,7 @@ def make_lammps_input(
169169
pka_vec = _sample_sphere()
170170
pka_vec *= pka_vn
171171
ret += "group first id 1\n"
172-
ret += 'if "${{restart}} == 0" then "velocity first set {:f} {:f} {:f}"\n'.format(
173-
pka_vec[0],
174-
pka_vec[1],
175-
pka_vec[2],
176-
)
172+
ret += f'if "${{restart}} == 0" then "velocity first set {pka_vec[0]:f} {pka_vec[1]:f} {pka_vec[2]:f}"\n'
177173
ret += "fix 2 all momentum 1 linear 1 1 1\n"
178174
ret += "\n"
179175
if ensemble.split("-")[0] == "npt":

dpgen/generator/lib/pwscf.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ def _make_pwscf_03_config(sys_data):
110110
cc = 0
111111
for ii in range(ntypes):
112112
for jj in range(atom_numbs[ii]):
113-
ret += "{} {:f} {:f} {:f}\n".format(
114-
atom_names[ii],
115-
coordinates[cc][0],
116-
coordinates[cc][1],
117-
coordinates[cc][2],
118-
)
113+
ret += f"{atom_names[ii]} {coordinates[cc][0]:f} {coordinates[cc][1]:f} {coordinates[cc][2]:f}\n"
119114
cc += 1
120115
return ret
121116

dpgen/generator/run.py

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -591,21 +591,21 @@ def make_train(iter_index, jdata, mdata):
591591
if (
592592
len(np.array(model_devi_activation_func).shape) == 2
593593
): # 2-dim list for emd/fitting net-resolved assignment of actF
594-
jinput["model"]["descriptor"][
595-
"activation_function"
596-
] = model_devi_activation_func[ii][0]
597-
jinput["model"]["fitting_net"][
598-
"activation_function"
599-
] = model_devi_activation_func[ii][1]
594+
jinput["model"]["descriptor"]["activation_function"] = (
595+
model_devi_activation_func[ii][0]
596+
)
597+
jinput["model"]["fitting_net"]["activation_function"] = (
598+
model_devi_activation_func[ii][1]
599+
)
600600
if (
601601
len(np.array(model_devi_activation_func).shape) == 1
602602
): # for backward compatibility, 1-dim list, not net-resolved
603-
jinput["model"]["descriptor"][
604-
"activation_function"
605-
] = model_devi_activation_func[ii]
606-
jinput["model"]["fitting_net"][
607-
"activation_function"
608-
] = model_devi_activation_func[ii]
603+
jinput["model"]["descriptor"]["activation_function"] = (
604+
model_devi_activation_func[ii]
605+
)
606+
jinput["model"]["fitting_net"]["activation_function"] = (
607+
model_devi_activation_func[ii]
608+
)
609609
# dump the input.json
610610
with open(os.path.join(task_path, train_input_file), "w") as outfile:
611611
json.dump(jinput, outfile, indent=4)
@@ -1042,9 +1042,9 @@ def revise_lmp_input_dump(lmp_lines, trj_freq, model_devi_merge_traj=False):
10421042

10431043
def revise_lmp_input_plm(lmp_lines, in_plm, out_plm="output.plumed"):
10441044
idx = find_only_one_key(lmp_lines, ["fix", "dpgen_plm"])
1045-
lmp_lines[
1046-
idx
1047-
] = f"fix dpgen_plm all plumed plumedfile {in_plm} outfile {out_plm}\n"
1045+
lmp_lines[idx] = (
1046+
f"fix dpgen_plm all plumed plumedfile {in_plm} outfile {out_plm}\n"
1047+
)
10481048
return lmp_lines
10491049

10501050

@@ -1815,9 +1815,10 @@ def _make_model_devi_amber(
18151815
nsteps = jdata["nsteps"]
18161816

18171817
for ii, pp in enumerate(mdin):
1818-
with open(pp) as f, open(
1819-
os.path.join(work_path, "init%d.mdin" % ii), "w"
1820-
) as fw:
1818+
with (
1819+
open(pp) as f,
1820+
open(os.path.join(work_path, "init%d.mdin" % ii), "w") as fw,
1821+
):
18211822
mdin_str = f.read()
18221823
# freq, nstlim, qm_region, qm_theory, qm_charge, rcut, graph
18231824
mdin_str = (
@@ -1883,9 +1884,10 @@ def _make_model_devi_amber(
18831884
if not isinstance(r, Iterable) or isinstance(r, str):
18841885
r = [r]
18851886
# disang file should include RVAL, RVAL2, ...
1886-
with open(disang[sys_idx[sys_counter]]) as f, open(
1887-
"TEMPLATE.disang", "w"
1888-
) as fw:
1887+
with (
1888+
open(disang[sys_idx[sys_counter]]) as f,
1889+
open("TEMPLATE.disang", "w") as fw,
1890+
):
18891891
tl = f.read()
18901892
for ii, rr in enumerate(r):
18911893
if isinstance(rr, Iterable) and not isinstance(rr, str):
@@ -1999,14 +2001,7 @@ def run_md_model_devi(iter_index, jdata, mdata):
19992001
if ndx_filename:
20002002
command += f'&& echo -e "{grp_name}\\n{grp_name}\\n" | {model_devi_exec} trjconv -s {ref_filename} -f {deffnm}.trr -n {ndx_filename} -o {traj_filename} -pbc mol -ur compact -center'
20012003
else:
2002-
command += '&& echo -e "{}\\n{}\\n" | {} trjconv -s {} -f {}.trr -o {} -pbc mol -ur compact -center'.format(
2003-
grp_name,
2004-
grp_name,
2005-
model_devi_exec,
2006-
ref_filename,
2007-
deffnm,
2008-
traj_filename,
2009-
)
2004+
command += f'&& echo -e "{grp_name}\\n{grp_name}\\n" | {model_devi_exec} trjconv -s {ref_filename} -f {deffnm}.trr -o {traj_filename} -pbc mol -ur compact -center'
20102005
command += "&& if [ ! -d traj ]; then \n mkdir traj; fi\n"
20112006
command += f"python -c \"import dpdata;system = dpdata.System('{traj_filename}', fmt='gromacs/gro'); [system.to_gromacs_gro('traj/%d.gromacstrj' % (i * {trj_freq}), frame_idx=i) for i in range(system.get_nframes())]; system.to_deepmd_npy('traj_deepmd')\""
20122007
command += f"&& dp model-devi -m ../graph.000.pb ../graph.001.pb ../graph.002.pb ../graph.003.pb -s traj_deepmd -o model_devi.out -f {trj_freq}"
@@ -2508,9 +2503,7 @@ def _make_fp_vasp_inner(
25082503
tot = len(summaryfmax) - nan_num
25092504
candi_num = tot - acc_num - fail_num
25102505
dlog.info(
2511-
"summary accurate_ratio: {:8.4f}% candidata_ratio: {:8.4f}% failed_ratio: {:8.4f}% in {:d} structures".format(
2512-
acc_num * 100 / tot, candi_num * 100 / tot, fail_num * 100 / tot, tot
2513-
)
2506+
f"summary accurate_ratio: {acc_num * 100 / tot:8.4f}% candidata_ratio: {candi_num * 100 / tot:8.4f}% failed_ratio: {fail_num * 100 / tot:8.4f}% in {tot:d} structures"
25142507
)
25152508
# --------------------------------------------------------------------------------------------------------------------------------------
25162509

@@ -2662,9 +2655,7 @@ def _trust_limitation_check(sys_idx, lim):
26622655
continue
26632656
for cc_key, cc_value in counter.items():
26642657
dlog.info(
2665-
"system {:s} {:9s} : {:6d} in {:6d} {:6.2f} %".format(
2666-
ss, cc_key, cc_value, fp_sum, cc_value / fp_sum * 100
2667-
)
2658+
f"system {ss:s} {cc_key:9s} : {cc_value:6d} in {fp_sum:6d} {cc_value / fp_sum * 100:6.2f} %"
26682659
)
26692660
random.shuffle(fp_candidate)
26702661
if detailed_report_make_fp:
@@ -2738,15 +2729,7 @@ def _trust_limitation_check(sys_idx, lim):
27382729
numb_task = 0
27392730
# ----------------------------------------------------------------------------
27402731
dlog.info(
2741-
"system {:s} accurate_ratio: {:8.4f} thresholds: {:6.4f} and {:6.4f} eff. task min and max {:4d} {:4d} number of fp tasks: {:6d}".format(
2742-
ss,
2743-
accurate_ratio,
2744-
fp_accurate_soft_threshold,
2745-
fp_accurate_threshold,
2746-
fp_task_min,
2747-
this_fp_task_max,
2748-
numb_task,
2749-
)
2732+
f"system {ss:s} accurate_ratio: {accurate_ratio:8.4f} thresholds: {fp_accurate_soft_threshold:6.4f} and {fp_accurate_threshold:6.4f} eff. task min and max {fp_task_min:4d} {this_fp_task_max:4d} number of fp tasks: {numb_task:6d}"
27502733
)
27512734
# make fp tasks
27522735

@@ -2878,21 +2861,15 @@ def _trust_limitation_check(sys_idx, lim):
28782861
os.chdir(cwd)
28792862
if count_bad_box > 0:
28802863
dlog.info(
2881-
"system {:s} skipped {:6d} confs with bad box, {:6d} remains".format(
2882-
ss, count_bad_box, numb_task - count_bad_box
2883-
)
2864+
f"system {ss:s} skipped {count_bad_box:6d} confs with bad box, {numb_task - count_bad_box:6d} remains"
28842865
)
28852866
if count_bad_cluster > 0:
28862867
dlog.info(
2887-
"system {:s} skipped {:6d} confs with bad cluster, {:6d} remains".format(
2888-
ss, count_bad_cluster, numb_task - count_bad_cluster
2889-
)
2868+
f"system {ss:s} skipped {count_bad_cluster:6d} confs with bad cluster, {numb_task - count_bad_cluster:6d} remains"
28902869
)
28912870
if model_devi_engine == "calypso":
28922871
dlog.info(
2893-
"summary accurate_ratio: {:8.4f}% candidata_ratio: {:8.4f}% failed_ratio: {:8.4f}% in {:d} structures".format(
2894-
acc_num * 100 / tot, candi_num * 100 / tot, fail_num * 100 / tot, tot
2895-
)
2872+
f"summary accurate_ratio: {acc_num * 100 / tot:8.4f}% candidata_ratio: {candi_num * 100 / tot:8.4f}% failed_ratio: {fail_num * 100 / tot:8.4f}% in {tot:d} structures"
28962873
)
28972874
if cluster_cutoff is None:
28982875
cwd = os.getcwd()

dpgen/gui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: LGPL-3.0-or-later
22
"""DP-GUI entrypoint."""
3+
34
import argparse
45

56

0 commit comments

Comments
 (0)