Skip to content

Commit

Permalink
Fix bad use of enumerate(start).
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Jun 27, 2024
1 parent 565a8b4 commit a2a86b2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 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 _, itm in enumerate(cycle, start=-1):
edges.append((itm, itm))
for idx, itm in enumerate(cycle):
edges.append((itm, cycle[idx - 1]))
cycles_edges.append(edges)

return cycles_edges
Expand Down
7 changes: 4 additions & 3 deletions src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3460,12 +3460,13 @@ def find_nn_pos_before_site(site_idx: int):
output = []
output_var = []
for idx, site in enumerate(self):
sp = site.specie
if idx == 0:
output.append(f"{site.specie}")
output.append(f"{sp}")
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"{sp} {nn[0] + 1} B{idx}")
output_var.append(f"B{idx}={bond_length:.6f}")
elif idx == 2:
nn = find_nn_pos_before_site(idx)
Expand All @@ -3478,7 +3479,7 @@ def find_nn_pos_before_site(site_idx: int):
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"{sp} {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
6 changes: 3 additions & 3 deletions src/pymatgen/io/cp2k/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2530,9 +2530,9 @@ def from_str(cls, string: str) -> Self:
data["nlcc"] = True
if "GTH" in string:
data["potential_type"] = "GTH"
for idx, char in enumerate(string, start=1):
if char == "Q" and char.isnumeric():
data["electrons"] = int("".join(_ for _ in string[idx:] if _.isnumeric()))
for idx, char in enumerate(string):
if char == "Q" and string[idx + 1].isnumeric():
data["electrons"] = int("".join(_ for _ in string[(idx + 1) :] if _.isnumeric()))

for x in ("LDA", "PADA", "MGGA", "GGA", "HF", "PBE0", "PBE", "BP", "BLYP", "B3LYP", "SCAN"):
if x in string:
Expand Down
10 changes: 5 additions & 5 deletions src/pymatgen/io/lmto.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ def from_str(cls, data: str, sigfigs: int = 8) -> Self:

for cat in ["STRUC", "CLASS", "SITE"]:
fields = struct_lines[cat].split("=")
for idx, field in enumerate(fields, start=1):
for idx, field in enumerate(fields):
token = field.split()[-1]
if token == "ALAT":
a_lat = round(float(fields[idx].split()[0]), sigfigs)
a_lat = round(float(fields[idx + 1].split()[0]), sigfigs)
structure_tokens["ALAT"] = a_lat
elif token == "ATOM":
atom = fields[idx].split()[0]
atom = fields[idx + 1].split()[0]
if not bool(re.match("E[0-9]*$", atom)):
if cat == "CLASS":
structure_tokens["CLASS"].append(atom)
Expand All @@ -197,9 +197,9 @@ 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 + 1].split()])
except ValueError:
arr = np.array([round(float(i), sigfigs) for i in fields[idx].split()[:-1]])
arr = np.array([round(float(i), sigfigs) for i in fields[idx + 1].split()[:-1]])
if token == "PLAT":
structure_tokens["PLAT"] = arr.reshape([3, 3])
elif not bool(re.match("E[0-9]*$", atom)):
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/io/xtb/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def constrains_template(molecule, reference_fnm, constraints) -> str:
atoms_for_mtd = [idx for idx in range(1, len(mol) + 1) if idx not in atoms_to_constrain]
# Write as 1-3,5 instead of 1,2,3,5
interval_list = [atoms_for_mtd[0]]
for idx, val in enumerate(atoms_for_mtd, start=1):
for idx, val in enumerate(atoms_for_mtd):
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 + 1])
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
10 changes: 5 additions & 5 deletions src/pymatgen/symmetry/kpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,15 +1480,15 @@ def _get_key_lines(key_points, bz_as_key_point_inds):
# not the face center point (don't need to check it since it's not
# shared with other facets)
face_center_ind = facet_as_key_point_inds[-1]
for j, ind in enumerate(facet_as_key_point_inds_bndy, start=-1):
for j, ind in enumerate(facet_as_key_point_inds_bndy):
if (
min(ind, ind),
max(ind, ind),
min(ind, facet_as_key_point_inds_bndy[j - 1]),
max(ind, facet_as_key_point_inds_bndy[j - 1]),
) not in key_lines:
key_lines.append(
(
min(ind, ind),
max(ind, ind),
min(ind, facet_as_key_point_inds_bndy[j - 1]),
max(ind, facet_as_key_point_inds_bndy[j - 1]),
)
)
k = j + 2 if j != len(facet_as_key_point_inds_bndy) - 2 else 0
Expand Down

0 comments on commit a2a86b2

Please sign in to comment.