Skip to content

Commit

Permalink
rearrange dunder methods to the top
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Feb 19, 2025
1 parent 389ec50 commit a60c9f0
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions src/pymatgen/symmetry/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any

from typing_extensions import Self

Expand All @@ -19,12 +20,12 @@

class SymmetrizedStructure(Structure):
"""This class represents a symmetrized structure, i.e. a structure
where the spacegroup and symmetry operations are defined. This class is
where the space group and symmetry operations are defined. This class is
typically not called but instead is typically obtained by calling
pymatgen.symmetry.analyzer.SpacegroupAnalyzer.get_symmetrized_structure.
Attributes:
equivalent_indices (list[List[int]]): A list of lists of indices of the sites in the structure that are
equivalent_indices (list[list[int]]): Indices of the sites in the structure that are
considered equivalent based on the symmetry operations of the space group.
"""

Expand Down Expand Up @@ -67,33 +68,6 @@ def __init__(
self.wyckoff_letters = wyckoff_letters
self.wyckoff_symbols = [f"{len(symb)}{symb[0]}" for symb in wyckoff_symbols]

def copy(self) -> Self:
"""Make a copy of the SymmetrizedStructure."""
return type(self)(
self,
spacegroup=self.spacegroup,
equivalent_positions=self.site_labels,
wyckoff_letters=self.wyckoff_letters,
)

def find_equivalent_sites(self, site: PeriodicSite) -> list[PeriodicSite]:
"""Find all symmetrically equivalent sites for a particular site.
Args:
site (PeriodicSite): A site in the structure
Raises:
ValueError: if site is not in the structure.
Returns:
list[PeriodicSite]: all symmetrically equivalent sites.
"""
for sites in self.equivalent_sites:
if site in sites:
return sites

raise ValueError("Site not in structure")

def __repr__(self) -> str:
return str(self)

Expand Down Expand Up @@ -123,7 +97,34 @@ def __str__(self) -> str:
outs.append(tabulate(data, headers=["#", "SP", "a", "b", "c", "Wyckoff", *keys]))
return "\n".join(outs)

def as_dict(self):
def copy(self) -> Self:
"""Make a copy of the SymmetrizedStructure."""
return type(self)(
self,
spacegroup=self.spacegroup,
equivalent_positions=self.site_labels,
wyckoff_letters=self.wyckoff_letters,
)

def find_equivalent_sites(self, site: PeriodicSite) -> list[PeriodicSite]:
"""Find all symmetrically equivalent sites for a particular site.
Args:
site (PeriodicSite): A site in the structure.
Raises:
ValueError: if site is not in the structure.
Returns:
list[PeriodicSite]: all symmetrically equivalent sites.
"""
for sites in self.equivalent_sites:
if site in sites:
return sites

raise ValueError("Site not in structure")

def as_dict(self) -> dict[str, Any]:
"""MSONable dict."""
structure = Structure.from_sites(self.sites)
return {
Expand All @@ -134,7 +135,7 @@ def as_dict(self):
}

@classmethod
def from_dict(cls, dct: dict) -> Self:
def from_dict(cls, dct: dict[str, Any]) -> Self:
"""
Args:
dct (dict): Dict representation.
Expand Down

0 comments on commit a60c9f0

Please sign in to comment.