# Surface Setup

This section is related to the geometry optimization section. To run a geometry optimization calculation, the slab needs to be defined in the script. Some examples of defining metal and metal oxide surfaces are given here.

This first example is a complete geometry optimization script. To set up a different slab, the part defining the slab (line 14) should be modified.

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40``` ```#!/usr/bin/python from ase import Atoms from ase.calculators.vasp import Vasp from ase.constraints import FixAtoms from ase.optimize import QuasiNewton from ase.lattice.surface import hcp0001 from ase.io import write,read #A simple Ru(0001) surface. Surface element, size and #vacuum are specified in the parentheses #define slab slab = hcp0001('Ru', size=(3,3,2), vacuum=10) #define adsorbate molecule = Atoms('CO', [(0., 0., 0.), (0., 0., 1.16)]) #add adsorbate to the surface add_adsorbate(slab, molecule, 1.7, ‘hcp’) #read in the input file fName = 'input.xyz' slab = read(fName) #set slab coordinates from input file slab.set_positions(slab.get_positions()) #set up calculator calc = Vasp(xc='PBE',lreal='Auto',kpts=[2,2,1], ismear=1,sigma=0.2,algo='fast',istart=0,npar=8) slab.set_calculator(calc) #freeze all layers below top layer mask = [atom.tag > 1 for atom in slab] slab.set_constraint(FixAtoms(mask=mask)) #run optimization dyn = QuasiNewton(slab, trajectory='CO-Ru.traj') dyn.run(fmax=0.05) #(eV/A) #write output write('outPut.xyz', slab) ```

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39``` ```#CeO2(111) surface #Lattice constant a = 5.46745036711 #Coordinates of the unit-cell atoms in fractional #coordinates (the fractional coordinates can be #found in the link given in external link section) CeO2 = Atoms([ Atom('Ce', (0., 0., 0.)), Atom('Ce', (0., 0.5, 0.5)), Atom('Ce', (0.5, 0., 0.5)), Atom('Ce', (0.5, 0.5, 0.)), Atom('O', (0.75, 0.25, 0.25)), Atom('O', (0.25, 0.75, 0.75)), Atom('O', (0.75, 0.75, 0.75)), Atom('O', (0.25, 0.25, 0.25)), Atom('O', (0.25, 0.25, 0.75)), Atom('O', (0.75, 0.75, 0.25)), Atom('O', (0.25, 0.75, 0.25)), Atom('O', (0.75, 0.25, 0.75)) ]) #Defining lattice size in a, b and c directions. #In this case, they are all equal. cell = [(a, 0., 0.), (0., a, 0.), (0., 0., a)] #Scales the atomic positions with the unit cell CeO2.set_cell(cell, scale_atoms=True) #(1,1,1) is the slab type. There are 2 unit cells along #z direction slab = surface(CeO2, (1, 1, 1), 2) #Repeating the slab 2 unit cells in x and 1 unit cell #in y directions slab = slab.repeat((2,1,1)) slab.center(vacuum=10, axis=2) ```

 ```1 2 3 4 5``` ```#Building a gold surface with one of the atoms replaced #by Pd slab = fcc111('Au', size=(3,3,4), vacuum=10) slab.set_chemical_symbols('AuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuAuPdAuAuAuAu') ```