From a60c9f0ed012eb6e8c3adb83b308689ebceca165 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Wed, 19 Feb 2025 17:00:14 +0100 Subject: [PATCH] rearrange dunder methods to the top --- src/pymatgen/symmetry/structure.py | 63 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/pymatgen/symmetry/structure.py b/src/pymatgen/symmetry/structure.py index c44da9aa8fe..32a5e941676 100644 --- a/src/pymatgen/symmetry/structure.py +++ b/src/pymatgen/symmetry/structure.py @@ -11,6 +11,7 @@ if TYPE_CHECKING: from collections.abc import Sequence + from typing import Any from typing_extensions import Self @@ -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. """ @@ -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) @@ -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 { @@ -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.