Skip to content

Commit

Permalink
Revert "New ruff fixes."
Browse files Browse the repository at this point in the history
This reverts commit ea8c3c5.
  • Loading branch information
shyuep committed Jun 27, 2024
1 parent 3a473ec commit a745041
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,8 +2419,8 @@ def find_rings(self, including=None) -> list[list[tuple[int, int]]]:

for cycle in cycles_nodes:
edges = []
for _idx, itm in enumerate(cycle, start=-1):
edges.append((itm, itm))
for idx, itm in enumerate(cycle, start=-1):
edges.append((cycle[idx], itm))
cycles_edges.append(edges)

return cycles_edges
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3465,20 +3465,20 @@ def find_nn_pos_before_site(site_idx: int):
elif idx == 1:
nn = find_nn_pos_before_site(idx)
bond_length = self.get_distance(idx, nn[0])
output.append(f"{site.specie} {nn[0] + 1} B{idx}")
output.append(f"{self[idx].specie} {nn[0] + 1} B{idx}")
output_var.append(f"B{idx}={bond_length:.6f}")
elif idx == 2:
nn = find_nn_pos_before_site(idx)
bond_length = self.get_distance(idx, nn[0])
angle = self.get_angle(idx, nn[0], nn[1])
output.append(f"{site.specie} {nn[0] + 1} B{idx} {nn[1] + 1} A{idx}")
output.append(f"{self[idx].specie} {nn[0] + 1} B{idx} {nn[1] + 1} A{idx}")
output_var.extend((f"B{idx}={bond_length:.6f}", f"A{idx}={angle:.6f}"))
else:
nn = find_nn_pos_before_site(idx)
bond_length = self.get_distance(idx, nn[0])
angle = self.get_angle(idx, nn[0], nn[1])
dih = self.get_dihedral(idx, nn[0], nn[1], nn[2])
output.append(f"{site.specie} {nn[0] + 1} B{idx} {nn[1] + 1} A{idx} {nn[2] + 1} D{idx}")
output.append(f"{self[idx].specie} {nn[0] + 1} B{idx} {nn[1] + 1} A{idx} {nn[2] + 1} D{idx}")
output_var.extend((f"B{idx}={bond_length:.6f}", f"A{idx}={angle:.6f}", f"D{idx}={dih:.6f}"))
return "\n".join(output) + "\n\n" + "\n".join(output_var)

Expand Down
2 changes: 2 additions & 0 deletions src/pymatgen/io/abinit/netcdf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#

"""Wrapper for netCDF readers."""

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/io/abinit/pseudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def read_ppdesc(self, filename):

if pspcod == 7:
# PAW -> need to know the format pspfmt
tokens = line.split()
tokens = lines[lineno].split()
pspfmt, _creatorID = tokens[:2]

ppdesc = ppdesc._replace(format=pspfmt)
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/io/adf.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def remove_subkey(self, subkey):
"""
if len(self.subkeys) > 0:
key = subkey if isinstance(subkey, str) else subkey.key
for idx, sk in enumerate(self.subkeys):
if sk.key == key:
for idx, subkey in enumerate(self.subkeys):
if subkey.key == key:
self.subkeys.pop(idx)
break

Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/io/cp2k/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ def from_str(cls, string: str) -> Self:
if "GTH" in string:
data["potential_type"] = "GTH"
for idx, char in enumerate(string, start=1):
if char == "Q" and char.isnumeric():
if char == "Q" and string[idx].isnumeric():
data["electrons"] = int("".join(_ for _ in string[idx:] if _.isnumeric()))

for x in ("LDA", "PADA", "MGGA", "GGA", "HF", "PBE0", "PBE", "BP", "BLYP", "B3LYP", "SCAN"):
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/io/lmto.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def from_str(cls, data: str, sigfigs: int = 8) -> Self:
pass
elif token in ["PLAT", "POS"]:
try:
arr = np.array([round(float(i), sigfigs) for i in field.split()])
arr = np.array([round(float(i), sigfigs) for i in fields[idx].split()])
except ValueError:
arr = np.array([round(float(i), sigfigs) for i in fields[idx].split()[:-1]])
if token == "PLAT":
Expand Down
6 changes: 3 additions & 3 deletions src/pymatgen/io/vasp/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def _parse_vasp_array(elem) -> list[list[float]]:
def _parse_from_incar(filename: PathLike, key: str) -> Any:
"""Helper function to parse a parameter from the INCAR."""
dirname = os.path.dirname(filename)
for fn in os.listdir(dirname):
if re.search("INCAR", fn):
for filename in os.listdir(dirname):
if re.search("INCAR", filename):
warnings.warn(f"INCAR found. Using {key} from INCAR.")
incar = Incar.from_file(os.path.join(dirname, fn))
incar = Incar.from_file(os.path.join(dirname, filename))
return incar.get(key, None)
return None

Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/io/xtb/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def constrains_template(molecule, reference_fnm, constraints) -> str:
if val + 1 not in atoms_for_mtd:
interval_list.append(val)
if idx != len(atoms_for_mtd):
interval_list.append(val)
interval_list.append(atoms_for_mtd[idx])
allowed_mtd_string = ",".join(
[f"{interval_list[i]}-{interval_list[i + 1]}" for i in range(len(interval_list)) if i % 2 == 0]
)
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/io/xtb/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def _parse_crest_output(self):
value = None
if entry and "-" in entry:
option = entry[1:]
if i < len(split_cmd) and "-" not in entry:
value = entry
if i < len(split_cmd) and "-" not in split_cmd[i]:
value = split_cmd[i]
self.cmd_options[option] = value
# Get input charge for decorating parsed molecules
chg = 0
Expand Down
1 change: 1 addition & 0 deletions src/pymatgen/phonon/thermal_displacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def visualize_directionality_quality_criterion(
raise ValueError("Illegal which_structure value.")

with open(filename, mode="w", encoding="utf-8") as file:
#
file.write("#VESTA_FORMAT_VERSION 3.5.4\n \n \n")
file.write("CRYSTAL\n\n")
file.write("TITLE\n")
Expand Down
8 changes: 4 additions & 4 deletions src/pymatgen/symmetry/kpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,13 +1482,13 @@ def _get_key_lines(key_points, bz_as_key_point_inds):
face_center_ind = facet_as_key_point_inds[-1]
for j, ind in enumerate(facet_as_key_point_inds_bndy, start=-1):
if (
min(ind, ind),
max(ind, ind),
min(ind, facet_as_key_point_inds_bndy[j]),
max(ind, facet_as_key_point_inds_bndy[j]),
) not in key_lines:
key_lines.append(
(
min(ind, ind),
max(ind, ind),
min(ind, facet_as_key_point_inds_bndy[j]),
max(ind, facet_as_key_point_inds_bndy[j]),
)
)
k = j + 2 if j != len(facet_as_key_point_inds_bndy) - 2 else 0
Expand Down
4 changes: 2 additions & 2 deletions tests/io/abinit/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def test_api(self):
assert len(multi) == 1
assert multi.ndtset == 1
assert multi.isnc
for _i, inp in enumerate(multi):
assert list(inp) == list(inp)
for i, inp in enumerate(multi):
assert list(inp) == list(multi[i])

multi.addnew_from(0)
assert multi.ndtset == 2
Expand Down

0 comments on commit a745041

Please sign in to comment.