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!

Hi Peter,

I have a follow-up questions to your answer if you don’t mind. I have generated a slab (attached below) which look symmetric to me because there is a mirror plan perpendicular to c-axis at z=0.5. However, if I used the is_symmetric() method of the Slab object, I got ‘false’. Maybe with a better trained eyes, you can tell me why that slab is not symmetric :slight_smile: ?

import json
from pymatgen.core.surface import Slab

with open('slab_0_termination_1.json') as json_file:
    data = json.load(json_file)
slab = Slab.from_dict(data)
print(slab.is_symmetric())

Thanks a lot.

Best,
Seiha.

slab_0_termination_1.json (19.3 KB)
slab_0_termination_1.cif (3.2 KB)

Hey Seiha, I am getting ‘True’ with your code snippet and as you said, the slab indeed looks symmetric.

Hi, thanks a lot for your reply.
I have double checked and I still get ‘False’ when I run the code snippet. I’m using pymatgen-2021.2.8.1.
Do you have an idea why I get a different result on my computer?

Best,
Seiha.

I am currently using pymatgen 2022.0.6 and it is most likely your pymatgen version causing the issue.

I just checked the history of the pymatgen.core.surface module and looks like at some point is_symmetric() was only using SpaceGroupAnalyzer.is_laue() to determine the symmetry. This older version of is_symmetric() returns ‘False’ for your slab.

1 Like