Controlling the vacuum size above a slab

I have used the slab generator without problem in pymatgen in the past, but found that while I could specify a minimum vacuum size, I could not actually specify it. I found that I could do so using ase and translated back and forth from pymatgen to ase to pymatgen, but I was curious is there is a simpler way to control the size of the vacuum layer in pymatgen from the start. The SlabGenerator seems to only allow fixed values of the vacuum and since I want to construct an amorphous cell with a particular density, I need to control the volume of the vacuum region.

from pymatgen.core.structure import Structure, Lattice
from pymatgen.core.periodic_table import Element
lattice_constant = 2.989
lattice = Lattice.from_parameters(lattice_constant,lattice_constant,lattice_constant,90.,90.,90.)
structure = Structure.from_spacegroup("Fm-3m",lattice,[{"Ar":1}],[[0.,0.,0.]])
import ase as ase
from import surface, bulk
from import AseAtomsAdaptor
ase_structure = AseAtomsAdaptor.get_atoms(structure)   # convert the pymatgen structure to an ASE object
ase_surface = surface(ase_structure,(0,0,1),layers=1,vacuum=0)  # define a slab using the Ar cell
ase_surface.set_cell([structure.lattice.a,structure.lattice.b,structure.lattice.c+length]) # make the vacuum gap
newstructure = AseAtomsAdaptor.get_structure(ase_surface)  # convert the structure back to a pymatgen object
1 Like

I ran into the same problem a while back and found a not-so-elegant way to do it within pymatgen, maybe someone else will chime in with a better solution but here’s how I solved it; take the parameters of the Lattice object of your slab, modify c parameter in a way to give you the exact desired vacuum and initialize another Lattice object from that, and finally initialize another Slab or Structure from the attributes of your old structure, and the new lattice object.

If this sounds a bit daunting, I can also share my piece of code that does this.

Thanks for your comment firaty. I would be interested to see the code. Although it is a hack, the ASE version is (for me) very easy to understand and usable. It does seem to me that pymatgen is missing an important feature for constructing vacuum slabs though and it should be addressed.