Skip to content

Commit 28bd5df

Browse files
committed
format "Returns:" doc strings for dicts
1 parent c1a610c commit 28bd5df

File tree

12 files changed

+30
-41
lines changed

12 files changed

+30
-41
lines changed

pymatgen/alchemy/transmuters.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ def __getitem__(self, index):
7373
return self.transformed_structures[index]
7474

7575
def __getattr__(self, name):
76-
return [getattr(x, name) for x in self.transformed_structures]
76+
return [getattr(ts, name) for ts in self.transformed_structures]
7777

7878
def __len__(self):
7979
return len(self.transformed_structures)
8080

8181
def __str__(self):
8282
output = ["Current structures", "------------"]
83-
for x in self.transformed_structures:
84-
output.append(str(x.final_structure))
83+
for ts in self.transformed_structures:
84+
output.append(str(ts.final_structure))
8585
return "\n".join(output)
8686

8787
def undo_last_change(self) -> None:
@@ -90,17 +90,17 @@ def undo_last_change(self) -> None:
9090
Raises:
9191
IndexError if already at the oldest change.
9292
"""
93-
for x in self.transformed_structures:
94-
x.undo_last_change()
93+
for ts in self.transformed_structures:
94+
ts.undo_last_change()
9595

9696
def redo_next_change(self) -> None:
9797
"""Redo the last undone transformation in the TransformedStructure.
9898
9999
Raises:
100100
IndexError if already at the latest change.
101101
"""
102-
for x in self.transformed_structures:
103-
x.redo_next_change()
102+
for ts in self.transformed_structures:
103+
ts.redo_next_change()
104104

105105
def append_transformation(self, transformation, extend_collection=False, clear_redo=True):
106106
"""Append a transformation to all TransformedStructures.
@@ -122,15 +122,15 @@ def append_transformation(self, transformation, extend_collection=False, clear_r
122122
if self.ncores and transformation.use_multiprocessing:
123123
with Pool(self.ncores) as p:
124124
# need to condense arguments into single tuple to use map
125-
z = ((x, transformation, extend_collection, clear_redo) for x in self.transformed_structures)
125+
z = ((ts, transformation, extend_collection, clear_redo) for ts in self.transformed_structures)
126126
trafo_new_structs = p.map(_apply_transformation, z, 1)
127127
self.transformed_structures = []
128128
for ts in trafo_new_structs:
129129
self.transformed_structures.extend(ts)
130130
else:
131131
new_structures = []
132-
for x in self.transformed_structures:
133-
new = x.append_transformation(transformation, extend_collection, clear_redo=clear_redo)
132+
for ts in self.transformed_structures:
133+
new = ts.append_transformation(transformation, extend_collection, clear_redo=clear_redo)
134134
if new is not None:
135135
new_structures += new
136136
self.transformed_structures += new_structures

pymatgen/analysis/interface_reactions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ def get_kinks(self) -> list[tuple[int, float, float, Reaction, float]]:
187187

188188
def plot(self, backend: Literal["plotly", "matplotlib"] = "plotly") -> Figure | plt.Figure:
189189
"""
190-
Plots reaction energy as a function of mixing ratio x in self.c1 - self.c2
191-
tie line.
190+
Plots reaction energy as a function of mixing ratio x in self.c1 - self.c2 tie line.
192191
193192
Args:
194193
backend ("plotly" | "matplotlib"): Plotting library used to create the plot. Defaults to

pymatgen/analysis/phase_diagram.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,15 @@ def _get_all_facets_and_simplexes(self, comp):
632632

633633
return all_facets
634634

635-
def _get_facet_chempots(self, facet):
635+
def _get_facet_chempots(self, facet: list[int]) -> dict[Element, float]:
636636
"""
637637
Calculates the chemical potentials for each element within a facet.
638638
639639
Args:
640-
facet: Facet of the phase diagram.
640+
facet (list): Indices of the entries in the facet.
641641
642642
Returns:
643-
{element: chempot} for all elements in the phase diagram.
643+
dict[Element, float]: Chemical potentials for each element in the facet.
644644
"""
645645
comp_list = [self.qhull_entries[idx].composition for idx in facet]
646646
energy_list = [self.qhull_entries[idx].energy_per_atom for idx in facet]
@@ -1255,8 +1255,9 @@ def get_chempot_range_stability_phase(self, target_comp, open_elt):
12551255
open_elt: Element that you want to constrain to be max or min
12561256
12571257
Returns:
1258-
{Element: (mu_min, mu_max)}: Chemical potentials are given in
1259-
"absolute" values (i.e., not referenced to 0)
1258+
dict[Element, (float, float)]: A dictionary of the form {Element: (min_mu, max_mu)}
1259+
where min_mu and max_mu are the minimum and maximum chemical potentials
1260+
for the given element (as "absolute" values, i.e. not referenced to 0).
12601261
"""
12611262
mu_ref = np.array([self.el_refs[elem].energy_per_atom for elem in self.elements if elem != open_elt])
12621263
chempot_ranges = self.get_chempot_range_map([elem for elem in self.elements if elem != open_elt])

pymatgen/analysis/wulff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(self, lattice: Lattice, miller_list, e_surf_list, symprec=1e-5):
159159
logger.debug(len(self.facets))
160160

161161
# 3. consider the dual condition
162-
dual_pts = [x.dual_pt for x in self.facets]
162+
dual_pts = [facet.dual_pt for facet in self.facets]
163163
dual_convex = ConvexHull(dual_pts)
164164
dual_cv_simp = dual_convex.simplices
165165
# simplices (ndarray of ints, shape (n_facet, n_dim))

pymatgen/core/composition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def get_reduced_formula_and_factor(self, iupac_ordering: bool = False) -> tuple[
377377
A pretty normalized formula and a multiplicative factor, i.e.,
378378
Li4Fe4P4O16 returns (LiFePO4, 4).
379379
"""
380-
all_int = all(abs(x - round(x)) < Composition.amount_tolerance for x in self.values())
380+
all_int = all(abs(val - round(val)) < Composition.amount_tolerance for val in self.values())
381381
if not all_int:
382382
return self.formula.replace(" ", ""), 1
383383
el_amt_dict = {key: int(round(val)) for key, val in self.get_el_amt_dict().items()}
@@ -578,7 +578,7 @@ def anonymized_formula(self) -> str:
578578
anonymized_formula ABC3.
579579
"""
580580
reduced = self.element_composition
581-
if all(x == int(x) for x in self.values()):
581+
if all(val == int(val) for val in self.values()):
582582
reduced /= gcd(*(int(i) for i in self.values()))
583583

584584
anon = ""

pymatgen/core/ion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def get_reduced_formula_and_factor(self, iupac_ordering: bool = False, hydrates:
124124
tuple[str, float]: A pretty normalized formula and a multiplicative factor, i.e.,
125125
H4O4 returns ('H2O2', 2.0).
126126
"""
127-
all_int = all(abs(x - round(x)) < Composition.amount_tolerance for x in self.values())
127+
all_int = all(abs(val - round(val)) < Composition.amount_tolerance for val in self.values())
128128
if not all_int:
129129
return self.formula.replace(" ", ""), 1
130130

pymatgen/core/periodic_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def min_oxidation_state(self) -> float:
361361
@property
362362
def oxidation_states(self) -> tuple[int, ...]:
363363
"""Tuple of all known oxidation states."""
364-
return tuple(int(x) for x in self._data.get("Oxidation states", []))
364+
return tuple(map(int, self._data.get("Oxidation states", [])))
365365

366366
@property
367367
def common_oxidation_states(self) -> tuple[int, ...]:

pymatgen/electronic_structure/cohp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def has_antibnd_states_below_efermi(self, spin=None, limit=0.01):
163163
limit: -COHP smaller -limit will be considered.
164164
"""
165165
populations = self.cohp
166-
n_energies_below_efermi = len([x for x in self.energies if x <= self.efermi])
166+
n_energies_below_efermi = len([energy for energy in self.energies if energy <= self.efermi])
167167

168168
if populations is None:
169169
return None
@@ -1020,10 +1020,10 @@ def summed_icohp(self):
10201020

10211021
@property
10221022
def summed_orbital_icohp(self):
1023-
"""Sums orbitals-resolved ICOHPs of both spin channels for spin-plarized compounds.
1023+
"""Sums orbital-resolved ICOHPs of both spin channels for spin-polarized compounds.
10241024
10251025
Returns:
1026-
{"str(Orbital1)-str(Ortibal2)": icohp value in eV}.
1026+
dict[str, float]: "str(Orbital1)-str(Ortibal2)" mapped to ICOHP value in eV.
10271027
"""
10281028
orbital_icohp = {}
10291029
for orb, item in self._orbitals.items():

pymatgen/io/lammps/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def restore_site_properties(self, site_property: str = "ff_map", filename: str |
418418
bma = BabelMolAdaptor.from_file(filename, "pdb")
419419
pbm = pybel.Molecule(bma._ob_mol)
420420

421-
assert len(pbm.residues) == sum(x["number"] for x in self.param_list)
421+
assert len(pbm.residues) == sum(param["number"] for param in self.param_list)
422422

423423
packed_mol = self.convert_obatoms_to_molecule(
424424
pbm.residues[0].atoms,

pymatgen/io/nwchem.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -570,19 +570,8 @@ def parse_tddft(self):
570570
Parses TDDFT roots. Adapted from nw_spectrum.py script.
571571
572572
Returns:
573-
{
574-
"singlet": [
575-
{
576-
"energy": float,
577-
"osc_strength: float
578-
}
579-
],
580-
"triplet": [
581-
{
582-
"energy": float
583-
}
584-
]
585-
}
573+
dict[str, list]: A dict of the form {"singlet": [dict, ...], "triplet": [dict, ...]} where
574+
each sub-dict is of the form {"energy": float, "osc_strength": float}.
586575
"""
587576
start_tag = "Convergence criterion met"
588577
end_tag = "Excited state energy"

0 commit comments

Comments
 (0)