Skip to content

Commit

Permalink
Merge branch 'devel' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghan-iapcm authored Dec 5, 2024
2 parents 18e3505 + 7adbd6a commit 13b6897
Show file tree
Hide file tree
Showing 55 changed files with 392 additions and 351 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# -- Project information -----------------------------------------------------

project = "DP-GEN"
copyright = "2020-%d, DeepModeling" % date.today().year
copyright = "2020-%d, DeepModeling" % date.today().year # noqa: UP031
author = "DeepModeling"


Expand Down
6 changes: 3 additions & 3 deletions dpgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def info():
]:
try:
mm = __import__(modui)
print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0]))
print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0])) # noqa: UP031
except ImportError:
print("%10s %10s Not Found" % (modui, ""))
print("%10s %10s Not Found" % (modui, "")) # noqa: UP031
except AttributeError:
print("%10s %10s unknown version or path" % (modui, ""))
print("%10s %10s unknown version or path" % (modui, "")) # noqa: UP031
print()

# reference
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/EOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# vol = vol / 100.0
vol = self.vol_start + task_num * self.vol_step
# task_num = int((vol - self.vol_start) / self.vol_step)
output_task = os.path.join(path_to_work, "task.%06d" % task_num)
output_task = os.path.join(path_to_work, "task.%06d" % task_num) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
if self.inter_param["type"] == "abacus":
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/Elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
print("gen with norm " + str(norm_strains))
print("gen with shear " + str(shear_strains))
for ii in range(n_dfm):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down
21 changes: 12 additions & 9 deletions dpgen/auto_test/Gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.symlink(os.path.relpath(equi_contcar), POSCAR)
# task_poscar = os.path.join(output, 'POSCAR')
for ii in range(len(all_slabs)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in ["INCAR", "POTCAR", POSCAR, "conf.lmp", "in.lammps"]:
Expand All @@ -232,9 +232,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
task_list.append(output_task)
# print("# %03d generate " % ii, output_task)
print(
"# %03d generate " % ii,
"# %03d generate " % ii, # noqa: UP031
output_task,
" \t %d atoms" % self.atom_num,
" \t %d atoms" % self.atom_num, # noqa: UP031
)
# make confs
all_slabs[ii].to("POSCAR.tmp", "POSCAR")
Expand Down Expand Up @@ -472,12 +472,15 @@ def _compute_lower(self, output_file, all_tasks, all_res):
)

miller_index = loadfn(os.path.join(ii, "miller.json"))
ptr_data += "%-25s %7.2f %7.3f %8.3f %8.3f\n" % (
str(miller_index) + "-" + structure_dir + ":",
int(ii[-4:]) / self.n_steps,
sfe,
epa,
equi_epa_slab,
ptr_data += (
"%-25s %7.2f %7.3f %8.3f %8.3f\n" # noqa: UP031
% (
str(miller_index) + "-" + structure_dir + ":",
int(ii[-4:]) / self.n_steps,
sfe,
epa,
equi_epa_slab,
)
)
res_data[int(ii[-4:]) / self.n_steps] = [sfe, epa, equi_epa]

Expand Down
25 changes: 15 additions & 10 deletions dpgen/auto_test/Interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# task_poscar = os.path.join(output, 'POSCAR')

for ii in range(len(dss)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down Expand Up @@ -262,7 +262,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

super_latt_param = float(pos_line[2].split()[0])

output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss)))
output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss))) # noqa: UP031
os.makedirs(output_task1, exist_ok=True)
os.chdir(output_task1)
task_list.append(output_task1)
Expand All @@ -283,7 +283,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task2 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 1)
path_to_work,
"task.%06d" % (len(dss) + 1), # noqa: UP031
)
os.makedirs(output_task2, exist_ok=True)
os.chdir(output_task2)
Expand All @@ -305,7 +306,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task3 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 2)
path_to_work,
"task.%06d" % (len(dss) + 2), # noqa: UP031
)
os.makedirs(output_task3, exist_ok=True)
os.chdir(output_task3)
Expand Down Expand Up @@ -346,7 +348,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
replace_label = idx

output_task4 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 3)
path_to_work,
"task.%06d" % (len(dss) + 3), # noqa: UP031
)
os.makedirs(output_task4, exist_ok=True)
os.chdir(output_task4)
Expand Down Expand Up @@ -380,7 +383,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task5 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 4)
path_to_work,
"task.%06d" % (len(dss) + 4), # noqa: UP031
)
os.makedirs(output_task5, exist_ok=True)
os.chdir(output_task5)
Expand Down Expand Up @@ -414,7 +418,8 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.chdir(cwd)

output_task6 = os.path.join(
path_to_work, "task.%06d" % (len(dss) + 5)
path_to_work,
"task.%06d" % (len(dss) + 5), # noqa: UP031
)
os.makedirs(output_task6, exist_ok=True)
os.chdir(output_task6)
Expand Down Expand Up @@ -453,7 +458,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):

if self.inter_param["type"] == "abacus":
for ii in range(total_task):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.chdir(output_task)
abacus.poscar2stru("POSCAR", self.inter_param, "STRU")
os.remove("POSCAR")
Expand All @@ -478,8 +483,8 @@ def post_process(self, task_list):
type_num = type_map[insert_ele] + 1
conf_line[2] = str(len(type_map_list)) + " atom types"
conf_line[-2] = (
"%6.d" % int(insert_line.split()[0])
+ "%7.d" % type_num
"%6.d" % int(insert_line.split()[0]) # noqa: UP031
+ "%7.d" % type_num # noqa: UP031
+ f"{float(insert_line.split()[2]):16.10f}"
+ f"{float(insert_line.split()[3]):16.10f}"
+ f"{float(insert_line.split()[4]):16.10f}"
Expand Down
8 changes: 4 additions & 4 deletions dpgen/auto_test/Surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.symlink(os.path.relpath(equi_contcar), POSCAR)
# task_poscar = os.path.join(output, 'POSCAR')
for ii in range(len(all_slabs)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand All @@ -213,9 +213,9 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
os.remove(jj)
task_list.append(output_task)
print(
"# %03d generate " % ii,
"# %03d generate " % ii, # noqa: UP031
output_task,
" \t %d atoms" % len(all_slabs[ii].sites),
" \t %d atoms" % len(all_slabs[ii].sites), # noqa: UP031
)
# make confs
all_slabs[ii].to("POSCAR.tmp", "POSCAR")
Expand Down Expand Up @@ -270,7 +270,7 @@ def _compute_lower(self, output_file, all_tasks, all_res):
evac = (task_result["energies"][-1] - equi_epa * natoms) / AA * Cf

miller_index = loadfn(os.path.join(ii, "miller.json"))
ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % (
ptr_data += "%-25s %7.3f %8.3f %8.3f\n" % ( # noqa: UP031
str(miller_index) + "-" + structure_dir + ":",
evac,
epa,
Expand Down
6 changes: 3 additions & 3 deletions dpgen/auto_test/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def make_input_file(self, output_dir, task_type, task_param):
isif = 2
if not ("NSW" in incar and incar.get("NSW") == nsw):
dlog.info(
"%s setting NSW to %d"
"%s setting NSW to %d" # noqa: UP031
% (self.make_input_file.__name__, nsw)
)
incar["NSW"] = nsw
Expand All @@ -121,15 +121,15 @@ def make_input_file(self, output_dir, task_type, task_param):

if not ("ISIF" in incar and incar.get("ISIF") == isif):
dlog.info(
"%s setting ISIF to %d" % (self.make_input_file.__name__, isif)
"%s setting ISIF to %d" % (self.make_input_file.__name__, isif) # noqa: UP031
)
incar["ISIF"] = isif

elif cal_type == "static":
nsw = 0
if not ("NSW" in incar and incar.get("NSW") == nsw):
dlog.info(
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw)
"%s setting NSW to %d" % (self.make_input_file.__name__, nsw) # noqa: UP031
)
incar["NSW"] = nsw

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 @@ -187,7 +187,7 @@ def make_confs(self, path_to_work, path_to_equi, refine=False):
# task_poscar = os.path.join(output, 'POSCAR')

for ii in range(len(dss)):
output_task = os.path.join(path_to_work, "task.%06d" % ii)
output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031
os.makedirs(output_task, exist_ok=True)
os.chdir(output_task)
for jj in [
Expand Down
6 changes: 3 additions & 3 deletions dpgen/auto_test/common_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run_property(confs, inter_param, property_list, mdata):
# conf_dirs.sort()
processes = len(property_list)
pool = Pool(processes=processes)
print("Submit job via %d processes" % processes)
print("Submit job via %d processes" % processes) # noqa: UP031
conf_dirs = []
for conf in confs:
conf_dirs.extend(glob.glob(conf))
Expand Down Expand Up @@ -181,8 +181,8 @@ def run_property(confs, inter_param, property_list, mdata):
for ii in range(len(multiple_ret)):
if not multiple_ret[ii].successful():
print("ERROR:", multiple_ret[ii].get())
raise RuntimeError("Job %d is not successful!" % ii)
print("%d jobs are finished" % len(multiple_ret))
raise RuntimeError("Job %d is not successful!" % ii) # noqa: UP031
print("%d jobs are finished" % len(multiple_ret)) # noqa: UP031


def worker(
Expand Down
2 changes: 1 addition & 1 deletion dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def final_stru(abacus_path):
if lines[-i][1:27] == "STEP OF MOLECULAR DYNAMICS":
max_step = int(lines[-i].split()[-1])
break
return "OUT.%s/STRU_MD_%d" % (suffix, max_step)
return "OUT.%s/STRU_MD_%d" % (suffix, max_step) # noqa: UP031
elif calculation == "scf":
return "STRU"
else:
Expand Down
22 changes: 11 additions & 11 deletions dpgen/auto_test/lib/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def make_lammps_eval(conf, type_map, interaction, param):
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand Down Expand Up @@ -239,7 +239,7 @@ def make_lammps_equi(
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -251,11 +251,11 @@ def make_lammps_equi(
ret += "min_style cg\n"
if change_box:
ret += "fix 1 all box/relax iso 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "fix 1 all box/relax aniso 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "fix 1 all box/relax tri 0.0 \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -296,7 +296,7 @@ def make_lammps_elastic(
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -306,7 +306,7 @@ def make_lammps_elastic(
)
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
ret += "min_style cg\n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -361,7 +361,7 @@ def make_lammps_press_relax(
ret += "box tilt large\n"
ret += f"read_data {conf}\n"
for ii in range(len(type_map)):
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass)
ret += "mass %d %.3f\n" % (ii + 1, Element(type_map_list[ii]).mass) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
ret += "compute mype all pe\n"
Expand All @@ -372,9 +372,9 @@ def make_lammps_press_relax(
ret += "dump 1 all custom 100 dump.relax id type xs ys zs fx fy fz\n"
ret += "min_style cg\n"
ret += "fix 1 all box/relax iso ${Px} \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "fix 1 all box/relax aniso ${Px} \n"
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval)
ret += "minimize %e %e %d %d\n" % (etol, ftol, maxiter, maxeval) # noqa: UP031
ret += "variable N equal count(all)\n"
ret += "variable V equal vol\n"
ret += 'variable E equal "c_mype"\n'
Expand Down Expand Up @@ -409,7 +409,7 @@ def make_lammps_phonon(
ret += f"read_data {conf}\n"
ntypes = len(masses)
for ii in range(ntypes):
ret += "mass %d %f\n" % (ii + 1, masses[ii])
ret += "mass %d %f\n" % (ii + 1, masses[ii]) # noqa: UP031
ret += "neigh_modify every 1 delay 0 check no\n"
ret += interaction(param)
return ret
Expand Down
8 changes: 4 additions & 4 deletions dpgen/auto_test/lib/lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def system_data(lines):
system["atom_numbs"] = get_natoms_vec(lines)
system["atom_names"] = []
for ii in range(len(system["atom_numbs"])):
system["atom_names"].append("Type_%d" % ii)
system["atom_names"].append("Type_%d" % ii) # noqa: UP031
lohi, tilt = get_lmpbox(lines)
orig, cell = lmpbox2box(lohi, tilt)
system["orig"] = np.array(orig)
Expand All @@ -165,8 +165,8 @@ def from_system_data(system):
ret += "\n"
natoms = sum(system["atom_numbs"])
ntypes = len(system["atom_numbs"])
ret += "%d atoms\n" % natoms
ret += "%d atom types\n" % ntypes
ret += "%d atoms\n" % natoms # noqa: UP031
ret += "%d atom types\n" % ntypes # noqa: UP031
ret += "0 {:f} xlo xhi\n".format(system["cell"][0][0])
ret += "0 {:f} ylo yhi\n".format(system["cell"][1][1])
ret += "0 {:f} zlo zhi\n".format(system["cell"][2][2])
Expand All @@ -179,7 +179,7 @@ def from_system_data(system):
ret += "Atoms # atomic\n"
ret += "\n"
for ii in range(natoms):
ret += "%d %d %f %f %f\n" % (
ret += "%d %d %f %f %f\n" % ( # noqa: UP031
ii + 1,
system["atom_types"][ii],
system["coordinates"][ii][0] - system["orig"][0],
Expand Down
Loading

0 comments on commit 13b6897

Please sign in to comment.