Skip to content

Commit 7d0871c

Browse files
committed
revert deprecation of center_slab function
1 parent 81f441a commit 7d0871c

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

pymatgen/core/surface.py

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -317,33 +317,6 @@ def is_polar(self, tol_dipole_per_unit_area: float = 1e-3) -> bool:
317317
dip_per_unit_area = self.dipole / self.surface_area
318318
return np.linalg.norm(dip_per_unit_area) > tol_dipole_per_unit_area
319319

320-
def center_slab(self) -> Slab:
321-
"""Relocate the Slab region to the center.
322-
323-
This makes it easier to find surface sites and apply
324-
operations like doping.
325-
326-
TODO (@DanielYang59): need to check if the Slab is continuous
327-
328-
Returns:
329-
Slab: The centered Slab.
330-
"""
331-
# Calculate shift vector
332-
center_of_mass = np.average(
333-
self.frac_coords,
334-
weights=[site.species.weight for site in self],
335-
axis=0,
336-
)
337-
shift = 0.5 - center_of_mass[2]
338-
339-
# Move the slab to the center
340-
self.translate_sites(
341-
indices=list(range(len(self))), # all sites
342-
vector=[0, 0, shift],
343-
)
344-
345-
return self
346-
347320
def get_slab_regions(
348321
self,
349322
blength: float = 3.5,
@@ -826,23 +799,38 @@ def get_equi_sites(slab: Slab, sites: list[int]) -> list[int]:
826799
warnings.warn("Equivalent sites could not be found for some indices. Surface unchanged.")
827800

828801

829-
def center_slab(slab: Slab) -> Slab:
802+
def center_slab(slab: Structure) -> Structure:
830803
"""Relocate the Slab region to the center.
831804
832805
Deprecated, please use the center_slab method of Slab directly.
833806
834807
Args:
835-
slab (Slab): The Slab to center.
808+
slab (Structure): The Slab to center.
836809
837810
Returns:
838-
Slab: The centered Slab.
811+
Structure: The centered Slab.
839812
"""
840-
warnings.warn("Please use the center_slab method of Slab directly.", DeprecationWarning)
813+
# Calculate shift vector
814+
center_of_mass = np.average(
815+
slab.frac_coords,
816+
weights=[site.species.weight for site in slab],
817+
axis=0,
818+
)
819+
shift = 0.5 - center_of_mass[2]
820+
821+
# Move the slab to the center
822+
slab.translate_sites(
823+
indices=list(range(len(slab))), # all sites
824+
vector=[0, 0, shift],
825+
)
841826

842-
return slab.center_slab()
827+
return slab
843828

844829

845-
def get_slab_regions(slab: Slab, blength: float = 3.5) -> list[tuple[float, float]]:
830+
def get_slab_regions(
831+
slab: Slab,
832+
blength: float = 3.5,
833+
) -> list[tuple[float, float]]:
846834
"""Find the z-ranges for the slab region.
847835
848836
Deprecated, please use the get_slab_regions method of Slab directly.

0 commit comments

Comments
 (0)