Skip to content

Commit 20475b6

Browse files
committed
rename single-letter loop vars
1 parent b74a5df commit 20475b6

File tree

25 files changed

+108
-104
lines changed

25 files changed

+108
-104
lines changed

dev_scripts/update_pt_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ def add_electron_affinities():
238238

239239
req = requests.get("https://wikipedia.org/wiki/Electron_affinity_(data_page)")
240240
soup = BeautifulSoup(req.text, "html.parser")
241-
for t in soup.find_all("table"):
242-
if "Hydrogen" in t.text:
241+
for table in soup.find_all("table"):
242+
if "Hydrogen" in table.text:
243243
break
244244
data = []
245-
for tr in t.find_all("tr"):
245+
for tr in table.find_all("tr"):
246246
row = []
247247
for td in tr.find_all("td"):
248248
row.append(td.get_text().strip())

pymatgen/alchemy/materials.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ def extend_transformations(
173173
return_alternatives can be a number, which stipulates the
174174
total number of structures to return.
175175
"""
176-
for t in transformations:
177-
self.append_transformation(t, return_alternatives=return_alternatives)
176+
for trafo in transformations:
177+
self.append_transformation(trafo, return_alternatives=return_alternatives)
178178

179179
def get_vasp_input(self, vasp_input_set: type[VaspInputSet] = MPRelaxSet, **kwargs) -> dict[str, Any]:
180180
"""Returns VASP input as a dict of VASP objects.
181181
182182
Args:
183-
vasp_input_set (pymatgen.io.vasp.sets.VaspInputSet): input set
183+
vasp_input_set (VaspInputSet): input set
184184
to create VASP input files from structures
185185
**kwargs: All keyword args supported by the VASP input set.
186186
"""

pymatgen/alchemy/transmuters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def extend_transformations(self, transformations):
131131
Args:
132132
transformations: Sequence of Transformations
133133
"""
134-
for t in transformations:
135-
self.append_transformation(t)
134+
for trafo in transformations:
135+
self.append_transformation(trafo)
136136

137137
def apply_filter(self, structure_filter):
138138
"""Applies a structure_filter to the list of TransformedStructures

pymatgen/analysis/chemenv/utils/chemenv_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, cls, method, msg):
2525
self.msg = msg
2626

2727
def __str__(self):
28-
return str(self.cls) + ": " + self.method + "\n" + repr(self.msg)
28+
return f"{self.cls}: {self.method}\n{self.msg!r}"
2929

3030

3131
class NeighborsNotComputedChemenvError(AbstractChemenvError):

pymatgen/analysis/graphs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,12 +1251,12 @@ def __rmul__(self, other):
12511251
return self.__mul__(other)
12521252

12531253
@classmethod
1254-
def _edges_to_str(cls, g):
1254+
def _edges_to_str(cls, g) -> str:
12551255
header = "from to to_image "
12561256
header_line = "---- ---- ------------"
12571257
edge_weight_name = g.graph["edge_weight_name"]
12581258
if edge_weight_name:
1259-
print_weights = ["weight"]
1259+
print_weights = True
12601260
edge_label = g.graph["edge_weight_name"]
12611261
edge_weight_units = g.graph["edge_weight_units"]
12621262
if edge_weight_units:
@@ -1266,7 +1266,7 @@ def _edges_to_str(cls, g):
12661266
else:
12671267
print_weights = False
12681268

1269-
s = header + "\n" + header_line + "\n"
1269+
out = f"{header}\n{header_line}\n"
12701270

12711271
edges = list(g.edges(data=True))
12721272

@@ -1275,12 +1275,12 @@ def _edges_to_str(cls, g):
12751275

12761276
if print_weights:
12771277
for u, v, data in edges:
1278-
s += f"{u:4} {v:4} {data.get('to_jimage', (0, 0, 0))!s:12} {data.get('weight', 0):.3e}\n"
1278+
out += f"{u:4} {v:4} {data.get('to_jimage', (0, 0, 0))!s:12} {data.get('weight', 0):.3e}\n"
12791279
else:
12801280
for u, v, data in edges:
1281-
s += f"{u:4} {v:4} {data.get('to_jimage', (0, 0, 0))!s:12}\n"
1281+
out += f"{u:4} {v:4} {data.get('to_jimage', (0, 0, 0))!s:12}\n"
12821282

1283-
return s
1283+
return out
12841284

12851285
def __str__(self):
12861286
out = "Structure Graph"

pymatgen/analysis/local_env.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,15 +2279,15 @@ def __init__(self, types, parameters=None, cutoff=-10.0) -> None:
22792279
pruned using the get_nn method from the
22802280
VoronoiNN class.
22812281
"""
2282-
for t in types:
2283-
if t not in LocalStructOrderParams.__supported_types:
2284-
raise ValueError("Unknown order parameter type (" + t + ")!")
2282+
for typ in types:
2283+
if typ not in LocalStructOrderParams.__supported_types:
2284+
raise ValueError(f"Unknown order parameter type ({typ})!")
22852285
self._types = tuple(types)
22862286

22872287
self._comp_azi = False
22882288
self._params = []
2289-
for i, t in enumerate(self._types):
2290-
d = deepcopy(default_op_params[t]) if default_op_params[t] is not None else None
2289+
for i, typ in enumerate(self._types):
2290+
d = deepcopy(default_op_params[typ]) if default_op_params[typ] is not None else None
22912291
if parameters is None or parameters[i] is None:
22922292
self._params.append(d)
22932293
else:

pymatgen/command_line/gulp_caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def structure_lines(
301301
core_site_desc = f"{specie.symbol} core {' '.join(coord)}\n"
302302
gin += core_site_desc
303303
if (specie in _anions and anion_shell_flg) or (specie in _cations and cation_shell_flg):
304-
shel_site_desc = specie.symbol + " shel " + " ".join(coord) + "\n"
304+
shel_site_desc = f"{specie.symbol} shel {' '.join(coord)}\n"
305305
gin += shel_site_desc
306306
else:
307307
pass

pymatgen/core/tensors.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ def zeroed(self, tol: float = 1e-3):
689689
Returns:
690690
TensorCollection where small values are set to 0.
691691
"""
692-
return self.__class__([t.zeroed(tol) for t in self])
692+
return self.__class__([tensor.zeroed(tol) for tensor in self])
693693

694694
def transform(self, symm_op):
695695
"""Transforms TensorCollection with a symmetry operation.
@@ -699,7 +699,7 @@ def transform(self, symm_op):
699699
Returns:
700700
TensorCollection.
701701
"""
702-
return self.__class__([t.transform(symm_op) for t in self])
702+
return self.__class__([tensor.transform(symm_op) for tensor in self])
703703

704704
def rotate(self, matrix, tol: float = 1e-3):
705705
"""Rotates TensorCollection.
@@ -710,20 +710,20 @@ def rotate(self, matrix, tol: float = 1e-3):
710710
Returns:
711711
TensorCollection.
712712
"""
713-
return self.__class__([t.rotate(matrix, tol) for t in self])
713+
return self.__class__([tensor.rotate(matrix, tol) for tensor in self])
714714

715715
@property
716716
def symmetrized(self):
717717
"""TensorCollection where all tensors are symmetrized."""
718-
return self.__class__([t.symmetrized for t in self])
718+
return self.__class__([tensor.symmetrized for tensor in self])
719719

720720
def is_symmetric(self, tol: float = 1e-5):
721721
""":param tol: tolerance
722722
723723
Returns:
724724
Whether all tensors are symmetric.
725725
"""
726-
return all(t.is_symmetric(tol) for t in self)
726+
return all(tensor.is_symmetric(tol) for tensor in self)
727727

728728
def fit_to_structure(self, structure: Structure, symprec: float = 0.1):
729729
"""Fits all tensors to a Structure.
@@ -734,7 +734,7 @@ def fit_to_structure(self, structure: Structure, symprec: float = 0.1):
734734
Returns:
735735
TensorCollection.
736736
"""
737-
return self.__class__([t.fit_to_structure(structure, symprec) for t in self])
737+
return self.__class__([tensor.fit_to_structure(structure, symprec) for tensor in self])
738738

739739
def is_fit_to_structure(self, structure: Structure, tol: float = 1e-2):
740740
""":param structure: Structure
@@ -743,25 +743,25 @@ def is_fit_to_structure(self, structure: Structure, tol: float = 1e-2):
743743
Returns:
744744
Whether all tensors are fitted to Structure.
745745
"""
746-
return all(t.is_fit_to_structure(structure, tol) for t in self)
746+
return all(tensor.is_fit_to_structure(structure, tol) for tensor in self)
747747

748748
@property
749749
def voigt(self):
750750
"""TensorCollection where all tensors are in Voigt form."""
751-
return [t.voigt for t in self]
751+
return [tensor.voigt for tensor in self]
752752

753753
@property
754754
def ranks(self):
755755
"""Ranks for all tensors."""
756-
return [t.rank for t in self]
756+
return [tensor.rank for tensor in self]
757757

758758
def is_voigt_symmetric(self, tol: float = 1e-6):
759759
""":param tol: tolerance
760760
761761
Returns:
762762
Whether all tensors are voigt symmetric.
763763
"""
764-
return all(t.is_voigt_symmetric(tol) for t in self)
764+
return all(tensor.is_voigt_symmetric(tol) for tensor in self)
765765

766766
@classmethod
767767
def from_voigt(cls, voigt_input_list, base_class=Tensor):
@@ -785,7 +785,7 @@ def convert_to_ieee(self, structure: Structure, initial_fit=True, refine_rotatio
785785
Returns:
786786
TensorCollection.
787787
"""
788-
return self.__class__([t.convert_to_ieee(structure, initial_fit, refine_rotation) for t in self])
788+
return self.__class__([tensor.convert_to_ieee(structure, initial_fit, refine_rotation) for tensor in self])
789789

790790
def round(self, *args, **kwargs):
791791
"""Round all tensors.
@@ -796,12 +796,12 @@ def round(self, *args, **kwargs):
796796
Returns:
797797
TensorCollection.
798798
"""
799-
return self.__class__([t.round(*args, **kwargs) for t in self])
799+
return self.__class__([tensor.round(*args, **kwargs) for tensor in self])
800800

801801
@property
802802
def voigt_symmetrized(self):
803803
"""TensorCollection where all tensors are voigt symmetrized."""
804-
return self.__class__([t.voigt_symmetrized for t in self])
804+
return self.__class__([tensor.voigt_symmetrized for tensor in self])
805805

806806
def as_dict(self, voigt=False):
807807
""":param voigt: Whether to use Voigt form.
@@ -813,7 +813,7 @@ def as_dict(self, voigt=False):
813813
dct = {
814814
"@module": type(self).__module__,
815815
"@class": type(self).__name__,
816-
"tensor_list": [t.tolist() for t in tensor_list],
816+
"tensor_list": [tensor.tolist() for tensor in tensor_list],
817817
}
818818
if voigt:
819819
dct["voigt"] = voigt

pymatgen/electronic_structure/bandstructure.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,7 @@ def get_band_gap(self):
450450

451451
result["transition"] = "-".join(
452452
[
453-
str(c.label)
454-
if c.label is not None
455-
else "(" + ",".join(f"{c.frac_coords[i]:.3f}" for i in range(3)) + ")"
453+
str(c.label) if c.label is not None else f"({','.join(f'{c.frac_coords[i]:.3f}' for i in range(3))})"
456454
for c in [vbm["kpoint"], cbm["kpoint"]]
457455
]
458456
)

pymatgen/electronic_structure/boltztrap2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,12 +735,12 @@ def __init__(
735735

736736
# Derived properties
737737
cond_eff_mass = np.zeros((len(self.temp_r), len(self.mu_r), 3, 3))
738-
for t in range(len(self.temp_r)):
738+
for temp in range(len(self.temp_r)):
739739
for i in range(len(self.mu_r)):
740740
try:
741-
cond_eff_mass[t, i] = (
742-
np.linalg.inv(self.Conductivity_mu[t, i])
743-
* self.Carrier_conc_mu[t, i]
741+
cond_eff_mass[temp, i] = (
742+
np.linalg.inv(self.Conductivity_mu[temp, i])
743+
* self.Carrier_conc_mu[temp, i]
744744
* units.qe_SI**2
745745
/ units.me_SI
746746
* 1e6
@@ -1038,9 +1038,9 @@ def plot_props(
10381038
mu = self.bzt_transP.mu_r_eV
10391039

10401040
if prop_z == "doping" and prop_x == "temp":
1041-
p_array = eval("self.bzt_transP." + props[idx_prop] + "_" + prop_z)
1041+
p_array = eval(f"self.bzt_transP.{props[idx_prop]}_{prop_z}")
10421042
else:
1043-
p_array = eval("self.bzt_transP." + props[idx_prop] + "_" + prop_x)
1043+
p_array = eval(f"self.bzt_transP.{props[idx_prop]}_{prop_x}")
10441044

10451045
if ax is None:
10461046
plt.figure(figsize=(10, 8))

0 commit comments

Comments
 (0)