Wrong Oriented Unit Cell when Calling SlabGenerator.get_slab
bug
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.
<img width="897" height="498" alt="Image" src="https://github.com/user-attachments/assets/bf66fe16-1b76-4234-9724-934683de226f" />
This is expected from looking at the logic here, but I think it isn't what we want.
https://github.com/materialsproject/pymatgen/blob/cc57da9bb90cf1e46ff72ca8fe8642514692cb8f/src/pymatgen/core/surface.py#L1179
### 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.
https://github.com/materialsproject/pymatgen/blob/cc57da9bb90cf1e46ff72ca8fe8642514692cb8f/src/pymatgen/core/surface.py#L1179
### Minimal example
```Python
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_
0 条评论