Skip to content
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

Fix: ignore UP031 #762

Merged
merged 2 commits into from
Dec 4, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.4
rev: v0.8.1
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# -- Project information -----------------------------------------------------

project = "dpdata"
copyright = "2019-%d, DeepModeling " % date.today().year
copyright = "2019-%d, DeepModeling " % date.today().year # noqa: UP031
author = "Han Wang"

# The short X.Y version
Expand Down
8 changes: 4 additions & 4 deletions dpdata/abacus/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_coords_from_dump(dumplines, natoms):
else:
nframes_dump = int(nlines / (total_natoms + 9))
assert nframes_dump > 0, (
"Number of lines in MD_dump file = %d. Number of atoms = %d. The MD_dump file is incomplete."
"Number of lines in MD_dump file = %d. Number of atoms = %d. The MD_dump file is incomplete." # noqa: UP031
% (nlines, total_natoms)
)
cells = np.zeros([nframes_dump, 3, 3])
Expand Down Expand Up @@ -125,7 +125,7 @@ def get_coords_from_dump(dumplines, natoms):
)
iframe += 1
assert iframe == nframes_dump, (
"iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."
"iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump." # noqa: UP031
% (iframe, nframes_dump)
)
stresses *= kbar2evperang3
Expand All @@ -145,7 +145,7 @@ def get_energy(outlines, ndump, dump_freq):
energy.append(np.nan)
nenergy += 1
assert ndump == len(energy), (
"Number of total energies in running_md.log = %d. Number of frames in MD_dump = %d. Please check."
"Number of total energies in running_md.log = %d. Number of frames in MD_dump = %d. Please check." # noqa: UP031
% (len(energy), ndump)
)
energy = np.array(energy)
Expand Down Expand Up @@ -191,7 +191,7 @@ def get_frame(fname):
force = np.delete(force, i - ndump, axis=0)
stress = np.delete(stress, i - ndump, axis=0)
energy = np.delete(energy, i - ndump, axis=0)
unconv_stru += "%d " % i
unconv_stru += "%d " % i # noqa: UP031
ndump = len(energy)
if unconv_stru != "":
warnings.warn(f"Structure {unconv_stru} are unconverged and not collected!")
Expand Down
4 changes: 2 additions & 2 deletions dpdata/abacus/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
natoms_log += int(line.split()[-1])

assert natoms_log > 0 and natoms_log == natoms, (
"ERROR: detected atom number in log file is %d" % natoms
"ERROR: detected atom number in log file is %d" % natoms # noqa: UP031
)

energy = []
Expand Down Expand Up @@ -76,7 +76,7 @@
list(map(lambda x: float(x) * a0, loglines[i + k].split()[1:4]))
)
else:
assert False, "Unrecongnized coordinate type, %s, line:%d" % (
assert False, "Unrecongnized coordinate type, %s, line:%d" % ( # noqa: UP031

Check warning on line 79 in dpdata/abacus/relax.py

View check run for this annotation

Codecov / codecov/patch

dpdata/abacus/relax.py#L79

Added line #L79 was not covered by tests
loglines[i].split()[0],
i,
)
njzjz marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion dpdata/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def check(self, system: System):
elif isinstance(data, list):
if len(shape) and shape[0] != len(data):
raise DataError(
"Length of %s is %d, but expected %d"
"Length of %s is %d, but expected %d" # noqa: UP031
% (self.name, len(data), shape[0])
)
else:
Expand Down
4 changes: 2 additions & 2 deletions dpdata/deepmd/comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def dump(folder, data, set_size=5000, comp_prec=np.float32, remove_sets=True):
for ii in range(nsets):
set_stt = ii * set_size
set_end = (ii + 1) * set_size
set_folder = os.path.join(folder, "set.%03d" % ii)
set_folder = os.path.join(folder, "set.%03d" % ii) # noqa: UP031
os.makedirs(set_folder)
try:
os.remove(os.path.join(folder, "nopbc"))
Expand Down Expand Up @@ -158,5 +158,5 @@ def dump(folder, data, set_size=5000, comp_prec=np.float32, remove_sets=True):
for ii in range(nsets):
set_stt = ii * set_size
set_end = (ii + 1) * set_size
set_folder = os.path.join(folder, "set.%03d" % ii)
set_folder = os.path.join(folder, "set.%03d" % ii) # noqa: UP031
np.save(os.path.join(set_folder, dtype.deepmd_name), ddata[set_stt:set_end])
4 changes: 2 additions & 2 deletions dpdata/deepmd/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
else:
my_type_map = []
for ii in range(ntypes):
my_type_map.append("Type_%d" % ii)
my_type_map.append("Type_%d" % ii) # noqa: UP031

Check warning on line 62 in dpdata/deepmd/hdf5.py

View check run for this annotation

Codecov / codecov/patch

dpdata/deepmd/hdf5.py#L62

Added line #L62 was not covered by tests
assert len(my_type_map) >= len(data["atom_numbs"])
for ii in range(len(data["atom_numbs"])):
data["atom_names"].append(my_type_map[ii])
Expand Down Expand Up @@ -217,7 +217,7 @@
for ii in range(nsets):
set_stt = ii * set_size
set_end = (ii + 1) * set_size
set_folder = g.create_group("set.%03d" % ii)
set_folder = g.create_group("set.%03d" % ii) # noqa: UP031
for dt, prop in data_types.items():
if dt in reshaped_data:
set_folder.create_dataset(
Expand Down
2 changes: 1 addition & 1 deletion dpdata/deepmd/raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
else:
my_type_map = []
for ii in range(ntypes):
my_type_map.append("Type_%d" % ii)
my_type_map.append("Type_%d" % ii) # noqa: UP031

Check warning on line 30 in dpdata/deepmd/raw.py

View check run for this annotation

Codecov / codecov/patch

dpdata/deepmd/raw.py#L30

Added line #L30 was not covered by tests
data["atom_names"] = my_type_map
data["atom_numbs"] = []
for ii, _ in enumerate(data["atom_names"]):
Expand Down
8 changes: 4 additions & 4 deletions dpdata/gaussian/gjf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@
mult_frags.append(detect_multiplicity(np.array(symbols)[idx]))
if use_fragment_guesses:
multiplicity = sum(mult_frags) - frag_numb + 1 - charge % 2
chargekeywords_frag = "%d %d" % (charge, multiplicity) + "".join(
[" %d %d" % (charge, mult_frag) for mult_frag in mult_frags]
chargekeywords_frag = "%d %d" % (charge, multiplicity) + "".join( # noqa: UP031

Check warning on line 189 in dpdata/gaussian/gjf.py

View check run for this annotation

Codecov / codecov/patch

dpdata/gaussian/gjf.py#L189

Added line #L189 was not covered by tests
[" %d %d" % (charge, mult_frag) for mult_frag in mult_frags] # noqa: UP031
)
else:
multi_frags = np.array(mult_frags)
Expand Down Expand Up @@ -239,10 +239,10 @@
for ii, (symbol, coordinate) in enumerate(zip(symbols, coordinates)):
if use_fragment_guesses:
buff.append(
"%s(Fragment=%d) %f %f %f" % (symbol, frag_index[ii] + 1, *coordinate)
"%s(Fragment=%d) %f %f %f" % (symbol, frag_index[ii] + 1, *coordinate) # noqa: UP031
)
else:
buff.append("{} {:f} {:f} {:f}".format(symbol, *coordinate))
buff.append("{} {:f} {:f} {:f}".format(symbol, *coordinate)) # noqa: UP031
if not sys_data.get("nopbc", False):
# PBC condition
cell = sys_data["cells"][0]
Expand Down
2 changes: 1 addition & 1 deletion dpdata/lammps/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def system_data(
system["atom_names"] = []
if type_map is None:
for ii in range(len(system["atom_numbs"])):
system["atom_names"].append("TYPE_%d" % ii)
system["atom_names"].append("TYPE_%d" % ii) # noqa: UP031
else:
assert len(type_map) >= len(system["atom_numbs"])
for ii in range(len(system["atom_numbs"])):
Expand Down
24 changes: 12 additions & 12 deletions dpdata/lammps/lmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
system["atom_names"] = []
if type_map is None:
for ii in range(len(system["atom_numbs"])):
system["atom_names"].append("Type_%d" % ii)
system["atom_names"].append("Type_%d" % ii) # noqa: UP031

Check warning on line 170 in dpdata/lammps/lmp.py

View check run for this annotation

Codecov / codecov/patch

dpdata/lammps/lmp.py#L170

Added line #L170 was not covered by tests
else:
assert len(type_map) >= len(system["atom_numbs"])
for ii in range(len(system["atom_numbs"])):
Expand Down Expand Up @@ -198,27 +198,27 @@
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 += (ptr_float_fmt + " " + ptr_float_fmt + " xlo xhi\n") % (
0,
system["cells"][f_idx][0][0],
)
) # noqa: UP031
ret += (ptr_float_fmt + " " + ptr_float_fmt + " ylo yhi\n") % (
0,
system["cells"][f_idx][1][1],
)
) # noqa: UP031
ret += (ptr_float_fmt + " " + ptr_float_fmt + " zlo zhi\n") % (
0,
system["cells"][f_idx][2][2],
)
) # noqa: UP031
ret += (
ptr_float_fmt + " " + ptr_float_fmt + " " + ptr_float_fmt + " xy xz yz\n"
) % (
system["cells"][f_idx][1][0],
system["cells"][f_idx][2][0],
system["cells"][f_idx][2][1],
)
) # noqa: UP031
ret += "\n"
ret += "Atoms # atomic\n"
ret += "\n"
Expand All @@ -233,7 +233,7 @@
+ " "
+ ptr_float_fmt
+ "\n"
)
) # noqa: UP031

if "spins" in system:
coord_fmt = (
Expand All @@ -247,7 +247,7 @@
+ " "
+ ptr_float_fmt
+ "\n"
)
) # noqa: UP031
spins_norm = np.linalg.norm(system["spins"][f_idx], axis=1)
for ii in range(natoms):
if "spins" in system:
Expand All @@ -262,7 +262,7 @@
system["spins"][f_idx][ii][1] / spins_norm[ii],
system["spins"][f_idx][ii][2] / spins_norm[ii],
spins_norm[ii],
)
) # noqa: UP031
else:
ret += coord_fmt % (
ii + 1,
Expand All @@ -274,15 +274,15 @@
system["spins"][f_idx][ii][1],
system["spins"][f_idx][ii][2] + 1,
spins_norm[ii],
)
) # noqa: UP031
else:
ret += coord_fmt % (
ii + 1,
system["atom_types"][ii] + 1,
system["coords"][f_idx][ii][0] - system["orig"][0],
system["coords"][f_idx][ii][1] - system["orig"][1],
system["coords"][f_idx][ii][2] - system["orig"][2],
)
) # noqa: UP031
return ret


Expand Down
4 changes: 2 additions & 2 deletions dpdata/plugins/amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
labeled_system = dpdata.LabeledSystem()
with tempfile.TemporaryDirectory() as d:
for ii, ss in enumerate(ori_system):
inp_fn = os.path.join(d, "%d.in" % ii)
out_fn = os.path.join(d, "%d.out" % ii)
inp_fn = os.path.join(d, "%d.in" % ii) # noqa: UP031
out_fn = os.path.join(d, "%d.out" % ii) # noqa: UP031

Check warning on line 140 in dpdata/plugins/amber.py

View check run for this annotation

Codecov / codecov/patch

dpdata/plugins/amber.py#L139-L140

Added lines #L139 - L140 were not covered by tests
ss.to("sqm/in", inp_fn, **self.kwargs)
try:
sp.check_output(
Expand Down
4 changes: 2 additions & 2 deletions dpdata/plugins/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
labeled_system = dpdata.LabeledSystem()
with tempfile.TemporaryDirectory() as d:
for ii, ss in enumerate(ori_system):
inp_fn = os.path.join(d, "%d.gjf" % ii)
out_fn = os.path.join(d, "%d.log" % ii)
inp_fn = os.path.join(d, "%d.gjf" % ii) # noqa: UP031
out_fn = os.path.join(d, "%d.log" % ii) # noqa: UP031

Check warning on line 113 in dpdata/plugins/gaussian.py

View check run for this annotation

Codecov / codecov/patch

dpdata/plugins/gaussian.py#L112-L113

Added lines #L112 - L113 were not covered by tests
ss.to("gaussian/gjf", inp_fn, **self.kwargs)
try:
sp.check_output([*self.gaussian_exec.split(), inp_fn])
Expand Down
4 changes: 2 additions & 2 deletions dpdata/pwmat/atomconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def to_system_data(lines):
def from_system_data(system, f_idx=0, skip_zeros=True):
ret = ""
natoms = sum(system["atom_numbs"])
ret += "%d" % natoms
ret += "%d" % natoms # noqa: UP031
ret += "\n"
ret += "LATTICE"
ret += "\n"
Expand Down Expand Up @@ -83,7 +83,7 @@ def from_system_data(system, f_idx=0, skip_zeros=True):
posi_list = []
for jj, ii in zip(atomic_numbers, posis):
ii = np.matmul(ii, np.linalg.inv(system["cells"][0]))
posi_list.append("%d %15.10f %15.10f %15.10f 1 1 1" % (jj, ii[0], ii[1], ii[2]))
posi_list.append("%d %15.10f %15.10f %15.10f 1 1 1" % (jj, ii[0], ii[1], ii[2])) # noqa: UP031
for kk in range(len(posi_list)):
min = kk
for jj in range(kk, len(posi_list)):
Expand Down
4 changes: 2 additions & 2 deletions dpdata/qe/traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load_atom_names(lines, ntypes):
def load_celldm(lines):
celldm = np.zeros(6)
for ii in range(6):
key = "celldm(%d)" % (ii + 1)
key = "celldm(%d)" % (ii + 1) # noqa: UP031
val = load_key(lines, key)
if val is not None:
celldm[ii] = float(val)
Expand Down Expand Up @@ -169,7 +169,7 @@ def load_energy(fname, begin=0, step=1):
data = np.loadtxt(fname)
steps = []
for ii in data[begin::step, 0]:
steps.append("%d" % ii)
steps.append("%d" % ii) # noqa: UP031
with open_file(fname) as fp:
while True:
line = fp.readline()
Expand Down
4 changes: 2 additions & 2 deletions dpdata/rdkit/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@
# copy from FEprep
def mol_edit_log(mol, i, j):
if not mol.HasProp("edit"):
mol.SetProp("edit", "%d_%d" % (i, j))
mol.SetProp("edit", "%d_%d" % (i, j)) # noqa: UP031

Check warning on line 370 in dpdata/rdkit/sanitize.py

View check run for this annotation

Codecov / codecov/patch

dpdata/rdkit/sanitize.py#L370

Added line #L370 was not covered by tests
else:
edited = mol.GetProp("edit")
mol.SetProp("edit", edited + ",%d_%d" % (i, j))
mol.SetProp("edit", edited + ",%d_%d" % (i, j)) # noqa: UP031

Check warning on line 373 in dpdata/rdkit/sanitize.py

View check run for this annotation

Codecov / codecov/patch

dpdata/rdkit/sanitize.py#L373

Added line #L373 was not covered by tests


def kekulize_aromatic_heterocycles(mol_in, assign_formal_charge=True, sanitize=True):
Expand Down
10 changes: 5 additions & 5 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
dd.check(self)
if sum(self.get_atom_numbs()) != self.get_natoms():
raise DataError(
"Sum of atom_numbs (%d) is not equal to natoms (%d)."
"Sum of atom_numbs (%d) is not equal to natoms (%d)." # noqa: UP031
% (sum(self.get_atom_numbs()), self.get_natoms())
)

Expand Down Expand Up @@ -281,8 +281,8 @@
ret = "Data Summary"
ret += "\nUnlabeled System"
ret += "\n-------------------"
ret += "\nFrame Numbers : %d" % self.get_nframes()
ret += "\nAtom Numbers : %d" % self.get_natoms()
ret += "\nFrame Numbers : %d" % self.get_nframes() # noqa: UP031
ret += "\nAtom Numbers : %d" % self.get_natoms() # noqa: UP031

Check warning on line 285 in dpdata/system.py

View check run for this annotation

Codecov / codecov/patch

dpdata/system.py#L284-L285

Added lines #L284 - L285 were not covered by tests
ret += "\nElement List :"
ret += "\n-------------------"
ret += "\n" + " ".join(map(str, self.get_atom_names()))
Expand Down Expand Up @@ -1243,8 +1243,8 @@
ret = "Data Summary"
ret += "\nLabeled System"
ret += "\n-------------------"
ret += "\nFrame Numbers : %d" % self.get_nframes()
ret += "\nAtom Numbers : %d" % self.get_natoms()
ret += "\nFrame Numbers : %d" % self.get_nframes() # noqa: UP031
ret += "\nAtom Numbers : %d" % self.get_natoms() # noqa: UP031

Check warning on line 1247 in dpdata/system.py

View check run for this annotation

Codecov / codecov/patch

dpdata/system.py#L1246-L1247

Added lines #L1246 - L1247 were not covered by tests
status = "Yes" if self.has_virial() else "No"
ret += f"\nIncluding Virials : {status}"
ret += "\nElement List :"
Expand Down
4 changes: 2 additions & 2 deletions dpdata/vasp/poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def from_system_data(system, f_idx=0, skip_zeros=True):
for ii, name in zip(system["atom_numbs"], system["atom_names"]):
if ii == 0:
continue
ret += "%s%d " % (name, ii)
ret += "%s%d " % (name, ii) # noqa: UP031
ret += "\n"
ret += "1.0\n"
for ii in system["cells"][f_idx]:
Expand All @@ -94,7 +94,7 @@ def from_system_data(system, f_idx=0, skip_zeros=True):
for ii in system["atom_numbs"]:
if ii == 0:
continue
ret += "%d " % ii
ret += "%d " % ii # noqa: UP031
ret += "\n"
move = system.get("move", None)
if move is not None and len(move) > 0:
Expand Down
4 changes: 2 additions & 2 deletions dpdata/vasp/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
natoms = len(types)
ntypes = len(eles)
ret = ""
ret += "#N %d %d\n" % (natoms, ntypes - 1)
ret += "#N %d %d\n" % (natoms, ntypes - 1) # noqa: UP031

Check warning on line 61 in dpdata/vasp/xml.py

View check run for this annotation

Codecov / codecov/patch

dpdata/vasp/xml.py#L61

Added line #L61 was not covered by tests
ret += "#C "
for ii in eles:
ret += " " + ii
Expand All @@ -73,7 +73,7 @@
ret += "#F\n"
for ii in range(natoms):
sp = np.matmul(cell.T, posi[ii])
ret += "%d" % (types[ii] - 1)
ret += "%d" % (types[ii] - 1) # noqa: UP031

Check warning on line 76 in dpdata/vasp/xml.py

View check run for this annotation

Codecov / codecov/patch

dpdata/vasp/xml.py#L76

Added line #L76 was not covered by tests
ret += f" {sp[0]:12.6f} {sp[1]:12.6f} {sp[2]:12.6f}"
ret += f" {forc[ii][0]:12.6f} {forc[ii][1]:12.6f} {forc[ii][2]:12.6f}"
ret += "\n"
Expand Down
4 changes: 2 additions & 2 deletions tests/poscars/poscar_ref_oh.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_cell(self):
self.system.data["cells"][0][ii][jj],
ovito_cell[ii][jj],
places=6,
msg="cell[%d][%d] failed" % (ii, jj),
msg="cell[%d][%d] failed" % (ii, jj), # noqa: UP031
)

def test_frame(self):
Expand All @@ -48,5 +48,5 @@ def test_frame(self):
self.system.data["coords"][0][ii][jj],
ovito_posis[ii][jj],
places=6,
msg="posis[%d][%d] failed" % (ii, jj),
msg="posis[%d][%d] failed" % (ii, jj), # noqa: UP031
)
Loading
Loading