Skip to content

fix pre-commit errors #1540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions dpgen/auto_test/ABACUS.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, inter_parameter, path_to_poscar):
def make_potential_files(self, output_dir):
stru = os.path.abspath(os.path.join(output_dir, "STRU"))
if not os.path.isfile(stru):
raise FileNotFoundError("No file %s" % stru)
raise FileNotFoundError(f"No file {stru}")
stru_data = abacus_scf.get_abacus_STRU(stru)
atom_names = stru_data["atom_names"]
orb_files = stru_data["orb_files"]
Expand Down Expand Up @@ -58,7 +58,7 @@ def make_potential_files(self, output_dir):
)
if atomname not in self.potcars:
raise RuntimeError(
"please specify the pseudopotential file of '%s'" % atomname
f"please specify the pseudopotential file of '{atomname}'"
)
pp_orb_file.append([pp_files[iatom], self.potcars[atomname]])

Expand All @@ -70,7 +70,7 @@ def make_potential_files(self, output_dir):
)
if atomname not in self.orbfile:
raise RuntimeError(
"please specify the orbital file of '%s'" % atomname
f"please specify the orbital file of '{atomname}'"
)
pp_orb_file.append([orb_files[iatom], self.orbfile[atomname]])
elif self.orbfile:
Expand Down Expand Up @@ -105,7 +105,7 @@ def make_potential_files(self, output_dir):

src_file = os.path.join(pp_dir, file_param)
if not os.path.isfile(src_file):
raise RuntimeError("Can not find file %s" % src_file)
raise RuntimeError(f"Can not find file {src_file}")
tar_file = os.path.join("pp_orb", filename_in_stru)
if os.path.isfile(tar_file):
os.remove(tar_file)
Expand Down Expand Up @@ -138,8 +138,7 @@ def make_input_file(self, output_dir, task_type, task_param):
incar_prop = os.path.abspath(cal_setting["input_prop"])
incar = abacus_scf.get_abacus_input_parameters(incar_prop)
dlog.info(
"Detected 'input_prop' in 'relaxation', use %s as INPUT, and ignore 'cal_setting'"
% incar_prop
f"Detected 'input_prop' in 'relaxation', use {incar_prop} as INPUT, and ignore 'cal_setting'"
)

# revise INCAR based on the INCAR provided in the "interaction"
Expand Down Expand Up @@ -195,9 +194,8 @@ def make_input_file(self, output_dir, task_type, task_param):
dlog.info("'basis_type' is not defined, set to be 'pw'!")
self.modify_input(incar, "basis_type", "pw")
if "lcao" in incar["basis_type"].lower() and not self.if_define_orb_file:
mess = (
"The basis_type is %s, but not define orbital file!!!"
% incar["basis_type"]
mess = "The basis_type is {}, but not define orbital file!!!".format(
incar["basis_type"]
)
raise RuntimeError(mess)
if "deepks_model" in incar:
Expand Down
4 changes: 2 additions & 2 deletions dpgen/auto_test/EOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
dlog.warning("%s already exists" % path_to_work)
dlog.warning(f"{path_to_work} already exists")
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down Expand Up @@ -177,7 +177,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

if not os.path.isfile(equi_contcar):
raise RuntimeError(
"Can not find %s, please do relaxation first" % equi_contcar
f"Can not find {equi_contcar}, please do relaxation first"
)

if self.inter_param["type"] == "abacus":
Expand Down
10 changes: 5 additions & 5 deletions dpgen/auto_test/Elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
dlog.warning("%s already exists" % path_to_work)
dlog.warning(f"{path_to_work} already exists")
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down Expand Up @@ -288,10 +288,10 @@ def _compute_lower(self, output_file, all_tasks, all_res):
res_data["GV"] = GV
res_data["EV"] = EV
res_data["uV"] = uV
ptr_data += "# Bulk Modulus BV = %.2f GPa\n" % BV
ptr_data += "# Shear Modulus GV = %.2f GPa\n" % GV
ptr_data += "# Youngs Modulus EV = %.2f GPa\n" % EV
ptr_data += "# Poission Ratio uV = %.2f\n " % uV
ptr_data += f"# Bulk Modulus BV = {BV:.2f} GPa\n"
ptr_data += f"# Shear Modulus GV = {GV:.2f} GPa\n"
ptr_data += f"# Youngs Modulus EV = {EV:.2f} GPa\n"
ptr_data += f"# Poission Ratio uV = {uV:.2f}\n "

dumpfn(res_data, output_file, indent=4)

Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
dlog.warning("%s already exists" % path_to_work)
dlog.warning(f"{path_to_work} already exists")
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down
60 changes: 28 additions & 32 deletions dpgen/auto_test/Interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f" % float(latt_param / 4 / super_latt_param)
f"{float(latt_param / 4 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " 0.000000 "
+ self.insert_ele[0]
)
Expand All @@ -291,9 +291,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f" % float(latt_param / 2 / super_latt_param)
f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " 0.000000 "
+ self.insert_ele[0]
)
Expand All @@ -313,11 +313,11 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f" % float(latt_param / 4 / super_latt_param)
f"{float(latt_param / 4 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 4 / super_latt_param)
+ f"{float(latt_param / 4 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 4 / super_latt_param)
+ f"{float(latt_param / 4 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
Expand Down Expand Up @@ -354,20 +354,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f" % float(latt_param / 3 / super_latt_param)
f"{float(latt_param / 3 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 3 / super_latt_param)
+ f"{float(latt_param / 3 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 3 / super_latt_param)
+ f"{float(latt_param / 3 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
pos_line[replace_label] = (
"%.6f" % float(latt_param / 3 * 2 / super_latt_param)
f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 3 * 2 / super_latt_param)
+ f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 3 * 2 / super_latt_param)
+ f"{float(latt_param / 3 * 2 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
Expand All @@ -388,24 +388,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f"
% float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param)
f"{float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f"
% float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param)
+ f"{float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
pos_line[replace_label] = (
"%.6f"
% float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param)
f"{float((latt_param - 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f"
% float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param)
+ f"{float((latt_param + 2.1 / 2**0.5) / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
Expand All @@ -426,20 +422,20 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print(self.insert_ele[0], file=fout)
dumpfn(self.supercell, "supercell.json")
pos_line[chl] = (
"%.6f" % float(latt_param / 2 / super_latt_param)
f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float((latt_param - 2.1) / 2 / super_latt_param)
+ f"{float((latt_param - 2.1) / 2 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
pos_line[replace_label] = (
"%.6f" % float(latt_param / 2 / super_latt_param)
f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float(latt_param / 2 / super_latt_param)
+ f"{float(latt_param / 2 / super_latt_param):.6f}"
+ " "
+ "%.6f" % float((latt_param + 2.1) / 2 / super_latt_param)
+ f"{float((latt_param + 2.1) / 2 / super_latt_param):.6f}"
+ " "
+ self.insert_ele[0]
)
Expand Down Expand Up @@ -483,9 +479,9 @@ def post_process(self, task_list):
conf_line[-2] = (
"%6.d" % int(insert_line.split()[0])
+ "%7.d" % type_num
+ "%16.10f" % float(insert_line.split()[2])
+ "%16.10f" % float(insert_line.split()[3])
+ "%16.10f" % float(insert_line.split()[4])
+ f"{float(insert_line.split()[2]):16.10f}"
+ f"{float(insert_line.split()[3]):16.10f}"
+ f"{float(insert_line.split()[4]):16.10f}"
)
with open(conf, "w+") as fout:
for jj in conf_line:
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
dlog.warning("%s already exists" % path_to_work)
dlog.warning(f"{path_to_work} already exists")
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, parameter, inter_param=None):
def make_confs(self, path_to_work, path_to_equi, refine=False):
path_to_work = os.path.abspath(path_to_work)
if os.path.exists(path_to_work):
dlog.warning("%s already exists" % path_to_work)
dlog.warning(f"{path_to_work} already exists")
else:
os.makedirs(path_to_work)
path_to_equi = os.path.abspath(path_to_equi)
Expand Down
16 changes: 8 additions & 8 deletions dpgen/auto_test/common_equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def make_equi(confs, inter_param, relax_param):
else:
ele_list = [key for key in inter_param["potcars"].keys()]
# ele_list = inter_param['type_map']
dlog.debug("ele_list %s" % ":".join(ele_list))
dlog.debug("ele_list {}".format(":".join(ele_list)))
conf_dirs = []
for conf in confs:
conf_dirs.extend(glob.glob(conf))
Expand All @@ -45,8 +45,8 @@ def make_equi(confs, inter_param, relax_param):
for ii in conf_dirs:
os.chdir(ii)
crys_type = ii.split("/")[-1]
dlog.debug("crys_type: %s" % crys_type)
dlog.debug("pwd: %s" % os.getcwd())
dlog.debug(f"crys_type: {crys_type}")
dlog.debug(f"pwd: {os.getcwd()}")
if crys_type == "std-fcc":
if not os.path.exists("POSCAR"):
crys.fcc1(ele_list[element_label]).to("POSCAR", "POSCAR")
Expand Down Expand Up @@ -77,7 +77,7 @@ def make_equi(confs, inter_param, relax_param):
# ...
for ii in conf_dirs:
crys_type = ii.split("/")[-1]
dlog.debug("crys_type: %s" % crys_type)
dlog.debug(f"crys_type: {crys_type}")

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

for ii in task_dirs:
poscar = os.path.join(ii, "POSCAR")
dlog.debug("task_dir %s" % ii)
dlog.debug(f"task_dir {ii}")
inter = make_calculator(inter_param, poscar)
inter.make_potential_files(ii)
inter.make_input_file(ii, "relaxation", relax_param)
Expand Down Expand Up @@ -162,7 +162,7 @@ def run_equi(confs, inter_param, mdata):
elif inter_type in lammps_task_type:
mdata = convert_mdata(mdata, ["model_devi"])
else:
raise RuntimeError("unknown task %s, something wrong" % inter_type)
raise RuntimeError(f"unknown task {inter_type}, something wrong")

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

api_version = mdata.get("api_version", "1.0")
if Version(api_version) < Version("1.0"):
raise RuntimeError(
"API version %s has been removed. Please upgrade to 1.0." % api_version
f"API version {api_version} has been removed. Please upgrade to 1.0."
)
elif Version(api_version) >= Version("1.0"):
submission = make_submission(
Expand Down
4 changes: 2 additions & 2 deletions dpgen/auto_test/common_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def run_property(confs, inter_param, property_list, mdata):
elif inter_type in lammps_task_type:
mdata = convert_mdata(mdata, ["model_devi"])
else:
raise RuntimeError("unknown task %s, something wrong" % inter_type)
raise RuntimeError(f"unknown task {inter_type}, something wrong")

work_path = path_to_work
all_task = tmp_task_list
Expand Down Expand Up @@ -199,7 +199,7 @@ def worker(
api_version = mdata.get("api_version", "1.0")
if Version(api_version) < Version("1.0"):
raise RuntimeError(
"API version %s has been removed. Please upgrade to 1.0." % api_version
f"API version {api_version} has been removed. Please upgrade to 1.0."
)
elif Version(api_version) >= Version("1.0"):
submission = make_submission(
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/gen_confs.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _main():
)
args = parser.parse_args()

print("generate %s" % (args.elements))
print(f"generate {args.elements}")
if len(args.elements) == 1:
gen_element(args.elements[0], args.key)
# gen_element_std(args.elements[0])
Expand Down
Loading