How to generate Slab objects from 2D structure files?

SlabGenerator can generate Slabs from bulk Structures. However, if I have some ready-made slab structure files, such as the files for 2D materials, how can I get corresponding Slab objects from the files?

Hi,

this is pretty easy, if you have a pymatgen Structure object already which is also easy to get from a file. At minimum you have to give a miller index for a Slab to initialize from a Structure, but you could specify more, e.g. a correct oriented unit cell and possible a nonzero shift. It really depends what you want your Slab object for.
A simple function that I used before is this:

from pymatgen.core.surface import Slab

def slab_from_structure(miller, structure):
    """Returns a pymatgen.core.surface.Slab from a pymatgen structure.

    Parameters
    ----------
    miller : list of int
        Miller indices given as a list of integers
    structure : pymatgen.core.structure.Structure
        Structure to be converted into a Slab

    Returns
    -------
    pymatgen.core.surface.Slab
        The input structure converted to a Slab

    """
    return Slab(lattice=structure.lattice,
                species=structure.species_and_occu,
                coords=structure.frac_coords,
                miller_index=miller,
                oriented_unit_cell=structure,
                shift=0,
                scale_factor=np.eye(3, dtype=np.int),
                site_properties=structure.site_properties)
2 Likes

Many thanks. Once I find the most proper way to confirm the surface miller index, I will use your function.