# Question about generate symmetric slab

Hi,
Recently I try to generate symmetric slab by `pymatgen.core.surface.SlabGenerator`. The codes are as follows:

``````from pymatgen.core.surface import Slab, SlabGenerator, generate_all_slabs, get_symmetrically_distinct_miller_indices
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.ext.matproj import MPRester
from pymatgen.io.vasp.inputs import Poscar
mpr = MPRester('Bw7HdCARiXvzEWJK')

struct = mpr.get_structure_by_material_id('mp-979459')
struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure()
formula = struct.composition.reduced_formula
print(f'The material used to cleave surface:{formula}')

ls = get_symmetrically_distinct_miller_indices(struct, 1, return_hkil=False)
for i in ls:
slab = SlabGenerator(struct, miller_index=i, min_slab_size=25,min_vacuum_size=15.0, lll_reduce=True, center_slab=True)
print(i,len(slab.get_slabs(symmetrize=True)))
for n, slabs in enumerate(slab.get_slabs(bonds=None, ftol=0.1, tol=0.1, max_broken_bonds=0,symmetrize=True,repair=True)):
slabs.make_supercell([[1,0,0],[0,1,0],[0,0,1]])
name = str(i).split(',')[0][1]+str(i).split(',')[1][1]+str(i).split(',')[2][1]
open(formula+'_'+name +'_' + str(n+1) + '.vasp', 'w').write(str(Poscar(slabs)))

>>>The material used to cleave surface:Sm5Mg
(1, 1, 1) 0
(1, 1, 0) 0
(1, 0, 1) 0
(1, 0, 0) 0
(1, 0, -1) 0
(0, 0, 1) 0
``````

when I use parameter `symmetrize=True` in `SlabGenerator.get_slabs`, I found it can not produce symmetric surface and return an empty slab list. However, in most of other cases (MgO,LiMg2… ), it can work. I also notice this phenomenon only occurs in some specific pretty formula, such as X5Mg, Mg2X, Mg15X (X represents another element)…

If I use `symmetrize=False`, I can generate slabs but I prefer the symmetric ones. What cause this and how to solve it?

Thanks
Yaowei

Hello Yaowei,

A slab that does not have at least one of the following symmetries cannot be made symmetric.

• Mirror or glide plane parallel to the surface
• Inversion symmetry
• 2-fold rotation or screw axis along the surface

Hope this helps!

Best,
Peter

Edit: Make sure to not share your MP API key publicly!