Skip to content

Wrong Oriented Unit Cell when Calling SlabGenerator.get_slab #4597

@ThomasWarford

Description

@ThomasWarford

I will put in a PR for this.

Python version

Python 3.11.0

Pymatgen version

Version: 2025.10.7 (current master branch)

Operating system version

No response

Current behavior

For MgO(111): a and b differ for the orientated unit cell and slab. The number of atoms per layer in the OUC is 4 whilst for the slab it is 1.

Image

This is expected from looking at the logic here, but I think it isn't what we want.

ouc = ouc if (slab_l.a == ouc.lattice.a and slab_l.b == ouc.lattice.b) else self.oriented_unit_cell

Expected Behavior

I believe the a and b lattice vectors of the OUC should be identical to those of the slab, with c in the same direction as the c vector of the slab. I might be mistaken here.

ouc = ouc if (slab_l.a == ouc.lattice.a and slab_l.b == ouc.lattice.b) else self.oriented_unit_cell

Minimal example

from pymatgen.core import Lattice, Structure
from pymatgen.core.surface import SlabGenerator

# Rocksalt MgO conventional cell
bulk = Structure.from_spacegroup(
    "Fm-3m",
    Lattice.cubic(4.194),
    ["Mg", "O"],
    [[0, 0, 0], [0.5, 0.5, 0.5]],
)

gen = SlabGenerator(
    initial_structure=bulk,
    miller_index=(1, 1, 1),
    min_slab_size=10,
    min_vacuum_size=20,
    primitive=True,
    lll_reduce=False,
    center_slab=False,
    max_normal_search=None,
)

slab = gen.get_slabs()[0]

sl = slab.lattice
ol = slab.oriented_unit_cell.lattice

print("slab a,b,gamma:", sl.a, sl.b, sl.gamma, sl.alpha, sl.beta)
print("ouc  a,b,gamma:", ol.a, ol.b, ol.gamma, ol.alpha, ol.beta)
print("a/b match:", sl.a == ol.a and sl.b == ol.b)

Relevant files to reproduce this bug

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions