From ba4f83ac4330b62b45c2c8522e20af400f670332 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sat, 18 May 2024 10:21:15 +0800 Subject: [PATCH] revert shift to termination rename --- .../interfaces/coherent_interfaces.py | 8 +++---- pymatgen/core/surface.py | 24 +++++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/pymatgen/analysis/interfaces/coherent_interfaces.py b/pymatgen/analysis/interfaces/coherent_interfaces.py index d916db14f8a..c7fb9b08736 100644 --- a/pymatgen/analysis/interfaces/coherent_interfaces.py +++ b/pymatgen/analysis/interfaces/coherent_interfaces.py @@ -78,8 +78,8 @@ def _find_matches(self) -> None: reorient_lattice=False, # This is necessary to not screw up the lattice ) - film_slab = film_sg.get_slab(termination=0) - sub_slab = sub_sg.get_slab(termination=0) + film_slab = film_sg.get_slab(shift=0) + sub_slab = sub_sg.get_slab(shift=0) film_vectors = film_slab.lattice.matrix substrate_vectors = sub_slab.lattice.matrix @@ -194,8 +194,8 @@ def get_interfaces( film_shift, sub_shift = self._terminations[termination] - film_slab = film_sg.get_slab(termination=film_shift) - sub_slab = sub_sg.get_slab(termination=sub_shift) + film_slab = film_sg.get_slab(shift=film_shift) + sub_slab = sub_sg.get_slab(shift=sub_shift) for match in self.zsl_matches: # Build film superlattice diff --git a/pymatgen/core/surface.py b/pymatgen/core/surface.py index 204da1339b7..d6b900c4063 100644 --- a/pymatgen/core/surface.py +++ b/pymatgen/core/surface.py @@ -1068,32 +1068,24 @@ def calculate_scaling_factor() -> np.ndarray: def get_slab( self, - termination: float = 0, + shift: float = 0, tol: float = 0.1, energy: float | None = None, - shift: float | None = None, # TODO: remove after 2025-05-13 ) -> Slab: - """[Private method] Generate a slab based on a given termination coordinate - along the lattice c direction. + """[Private method] Generate a slab based on a given termination + coordinate along the lattice c direction. - You should NOT use this method directly. + You should RARELY use this method directly. Args: - termination (float): The coordinate along the lattice c + shift (float): The termination coordinate along the lattice c direction in fractional coordinates. tol (float): Tolerance to determine primitive cell. energy (float): The energy to assign to the slab. - shift (float): Deprecated, confusing. The termination coordinate - along the lattice c direction in fractional coordinates. Returns: Slab: from a shifted oriented unit cell. """ - # Check for usage of deprecated arg "shift" - if shift is not None: - termination = shift - warnings.warn("shift is deprecated in get_slab, please use termination.") - # Calculate total number of layers height = self._proj_height height_per_layer = round(height / self.parent.lattice.d_hkl(self.miller_index), 8) @@ -1115,7 +1107,7 @@ def get_slab( # Shift all atoms to the termination frac_coords = self.oriented_unit_cell.frac_coords - frac_coords = np.array(frac_coords) + np.array([0, 0, -termination])[None, :] + frac_coords = np.array(frac_coords) + np.array([0, 0, -shift])[None, :] frac_coords -= np.floor(frac_coords) # wrap to the [0, 1) range # Scale down z-coordinate by the number of layers @@ -1185,7 +1177,7 @@ def get_slab( struct.frac_coords, self.miller_index, ouc, - termination, + shift, scale_factor, reorient_lattice=self.reorient_lattice, site_properties=struct.site_properties, @@ -1336,7 +1328,7 @@ def get_z_ranges( # As per the docstring this is to sort final Slabs by number # of bonds broken, but this may very likely lead to errors # if the "energy" is used literally (Maybe reset energy to None?) - slab = self.get_slab(termination=termination, tol=tol, energy=bonds_broken) + slab = self.get_slab(shift=termination, tol=tol, energy=bonds_broken) if bonds_broken <= max_broken_bonds: slabs.append(slab)