Skip to content

Instantly share code, notes, and snippets.

@HojeChun
Last active July 24, 2023 05:39
Show Gist options
  • Save HojeChun/315635aabc32a354c6c03c671a6732c9 to your computer and use it in GitHub Desktop.
Save HojeChun/315635aabc32a354c6c03c671a6732c9 to your computer and use it in GitHub Desktop.
Get Slab
from typing import Tuple
from pymatgen.io.vasp.inputs import Poscar
from pymatgen.core.surface import SlabGenerator
from pymatgen.core.structure import Structure
from typing import Optional, Tuple
def make_slab(poscar_file: str, miller_index: Tuple[int], output_filename:Optional[str]=None, slab_thickness=10, vacuum_thickness=10, center_slab=True):
struc = Structure.from_file(poscar_file)
slab_gen = SlabGenerator(struc, miller_index = miller_index, min_slab_size=slab_thickness, min_vacuum_size=vacuum_thickness, center_slab=center_slab)
slabs = slab_gen.get_slabs()
print(f'Number of possible slabs: {len(slabs)}')
oriented_cell = slab_gen.oriented_unit_cell
if output_filename is not None:
Poscar(slabs[0]).write_file(output_filename)
Poscar(oriented_cell).write_file(output_filename.split(".")[0]+"_o."+output_filename.split(".")[1])
return slabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment