Skip to content

Commit

Permalink
clean up docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 30, 2024
1 parent 06abd50 commit 689c093
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if TYPE_CHECKING:
from collections.abc import Generator, Iterator
from typing import Any, ClassVar
from typing import Any, ClassVar, Literal

from typing_extensions import Self

Expand Down Expand Up @@ -774,17 +774,25 @@ def to_reduced_dict(self) -> dict[str, float]:
def to_weight_dict(self) -> dict[str, float]:
"""
Returns:
dict[str, float] with weight fraction of each component {"Ti": 0.90, "V": 0.06, "Al": 0.04}.
dict[str, float]: weight fractions of each component, e.g. {"Ti": 0.90, "V": 0.06, "Al": 0.04}.
"""
return {str(el): self.get_wt_fraction(el) for el in self.elements}

@property
def to_data_dict(self) -> dict[str, Any]:
def to_data_dict(
self,
) -> dict[
Literal["reduced_cell_composition", "unit_cell_composition", "reduced_cell_formula", "elements", "nelements"],
Any,
]:
"""
Returns:
A dict with many keys and values relating to Composition/Formula,
including reduced_cell_composition, unit_cell_composition,
reduced_cell_formula, elements and nelements.
dict with the following keys:
- reduced_cell_composition
- unit_cell_composition
- reduced_cell_formula
- elements
- nelements.
"""
return {
"reduced_cell_composition": self.reduced_composition,
Expand All @@ -802,7 +810,7 @@ def charge(self) -> float | None:
"""
warnings.warn(
"Composition.charge is experimental and may produce incorrect results. Use with "
"caution and open a GitHub issue pinging @janosh to report bad behavior."
"caution and open a GitHub issue pinging @janosh to report bad behavior.",
)
oxi_states = [getattr(specie, "oxi_state", None) for specie in self]
if {*oxi_states} <= {0, None}:
Expand All @@ -818,7 +826,7 @@ def charge_balanced(self) -> bool | None:
"""
warnings.warn(
"Composition.charge_balanced is experimental and may produce incorrect results. "
"Use with caution and open a GitHub issue pinging @janosh to report bad behavior."
"Use with caution and open a GitHub issue pinging @janosh to report bad behavior.",
)
if self.charge is None:
if {getattr(el, "oxi_state", None) for el in self} == {0}:
Expand Down Expand Up @@ -917,7 +925,7 @@ def replace(self, elem_map: dict[str, str | dict[str, float]]) -> Self:
if el in self:
warnings.warn(
f"Same element ({el}) in both the keys and values of the substitution!"
"This can be ambiguous, so be sure to check your result."
"This can be ambiguous, so be sure to check your result.",
)

return type(self)(new_comp)
Expand Down

0 comments on commit 689c093

Please sign in to comment.