Skip to content

Commit

Permalink
add Structure/Molecule.sites setter, move @Property to SiteCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jul 31, 2023
1 parent 71b7aec commit a70f4c4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ class SiteCollection(collections.abc.Sequence, metaclass=ABCMeta):
DISTANCE_TOLERANCE = 0.5

@property
@abstractmethod
def sites(self) -> tuple[Site, ...]:
"""Returns a tuple of sites."""
def sites(self) -> Sequence[Site]:
"""Returns an iterator for the sites in the Structure."""
return self._sites

@sites.setter
def sites(self, sites: Sequence[PeriodicSite]) -> None:
"""Sets the sites in the Structure."""
# use tuple for immutable IStructure/IMolecule, else use list
self._sites = tuple(sites) if isinstance(self, (IStructure, IMolecule)) else list(sites)

@abstractmethod
def get_distance(self, i: int, j: int) -> float:
Expand Down Expand Up @@ -1205,11 +1211,6 @@ def distance_matrix(self) -> np.ndarray:
"""
return self.lattice.get_all_distances(self.frac_coords, self.frac_coords)

@property
def sites(self) -> tuple[PeriodicSite, ...]:
"""Returns an iterator for the sites in the Structure."""
return self._sites

@property
def lattice(self) -> Lattice:
"""Lattice of the structure."""
Expand Down

0 comments on commit a70f4c4

Please sign in to comment.