def generator(group): structures = [] for position in ["ontop", "bridge"]: slab = fcc111("Au", size=group["repeats"].value(), vacuum=10.0) add_adsorbate(slab, "Au", 3, position=position) slab = fixBelow(slab, slab.positions[:, 2].min() + 1e-2) slab.set_calculator(EMT()) structures.append(slab) return structures
def asesurf2xxyz(symb, lattice, index, size=(1,1,3), vac=15.0, orthogonal=0): """ An interface function for ase.lattice.surface Usage: >>> atoms = asesurf2xxyz(symb, lattice, index, size, vac=15.0, orthogonal=0)) Parameters: symb: atomic symbol lattice: 'fcc', 'bcc', or 'hcp0001' index: '100', '111' or '110' (if lattice is 'hcp0001', this will not work.) size: the number of atoms per each vector Optional Parameters: vac (default: 15.0 angstron): the thickness of space normal to the surface orthogonal (default: False) : if True, two lateral cell vectors will be orthogonal. Example: >>> Fe_100_1x1 = asesurf2xxyz('Fe', 'bcc', '100', (1,1,2)) >>> Au_111_2x2 = asesurf2xxyz('Au', 'fcc', '111', (1,1,3)) """ if lattice == 'fcc': if index == '100': at_ase = AS.fcc100(symb, size, vacuum=vac) elif index == '111': at_ase = AS.fcc111(symb, size, orthogonal=orthogonal, vacuum=vac) elif index == '110': at_ase = AS.fcc110(symb, size, vacuum=vac) else: raise ValueError, "100, 111, or 110 surface is supported." elif lattice == 'bcc': if index == '100': at_ase = AS.bcc100(symb, size, vacuum=vac) elif index == '111': at_ase = AS.bcc111(symb, size, orthogonal=orthogonal, vacuum=vac) elif index == '110': at_ase = AS.bcc110(symb, size, orthogonal=orthogonal, vacuum=vac) else: raise ValueError, "100, 111, or 110 surface is supported." elif lattice == 'hcp0001': at_ase = AS.hcp0001(symb, size, orthogonal=orthogonal, vacuum=vac) else: raise ValueError, "fcc, bcc, or hcp0001 surface is supported." symbols = at_ase.get_chemical_symbols() posits = at_ase.get_positions() cell = at_ase.get_cell() pbc = at_ase.get_pbc() atoms = []; i=0 for sym in symbols: temp_at = Atom(sym, list(posits[i])) atoms.append(temp_at.copy()); i+=1 at_xxyz = AtomsSystem(atoms, cell=cell, pbc=pbc) return at_xxyz
def asesurf2xxyz(symb, lattice, index, size=(1,1,3), vac=15.0, orthogonal=0): """ An interface function for ase.lattice.surface Usage: >>> atoms = asesurf2xxyz(symb, lattice, index, size, vac=15.0, orthogonal=0)) Parameters: symb: atomic symbol lattice: 'fcc', 'bcc', or 'hcp0001' index: '100', '111' or '110' (if lattice is 'hcp0001', this will not work.) size: the number of atoms per each vector Optional Parameters: vac (default: 15.0 angstron): the thickness of space normal to the surface orthogonal (default: False) : if True, two lateral cell vectors will be orthogonal. Example: >>> Fe_100_1x1 = asesurf2xxyz('Fe', 'bcc', '100', (1,1,2)) >>> Au_111_2x2 = asesurf2xxyz('Au', 'fcc', '111', (1,1,3)) """ if lattice == 'fcc': if index == '100': at_ase = AS.fcc100(symb, size, vacuum=vac) elif index == '111': at_ase = AS.fcc111(symb, size, orthogonal=orthogonal, vacuum=vac) elif index == '110': at_ase = AS.fcc110(symb, size, vacuum=vac) else: raise ValueError("100, 111, or 110 surface is supported.") elif lattice == 'bcc': if index == '100': at_ase = AS.bcc100(symb, size, vacuum=vac) elif index == '111': at_ase = AS.bcc111(symb, size, orthogonal=orthogonal, vacuum=vac) elif index == '110': at_ase = AS.bcc110(symb, size, orthogonal=orthogonal, vacuum=vac) else: raise ValueError("100, 111, or 110 surface is supported.") elif lattice == 'hcp0001': at_ase = AS.hcp0001(symb, size, orthogonal=orthogonal, vacuum=vac) else: raise ValueError("fcc, bcc, or hcp0001 surface is supported.") symbols = at_ase.get_chemical_symbols() posits = at_ase.get_positions() cell = at_ase.get_cell() pbc = at_ase.get_pbc() atoms = []; i=0 for sym in symbols: temp_at = Atom(sym, list(posits[i])) atoms.append(temp_at.copy()); i+=1 at_xxyz = AtomsSystem(atoms, cell=cell, pbc=pbc) return at_xxyz
def get_surface_slabs(symbol, surfacetype, surfacesize, layers, latticeconstants, vacuum=10.0): images = [] if surfacetype == 'fcc100' or surfacetype == 'fcc111': nlayeratoms = surfacesize[0] * surfacesize[1] if isinstance(latticeconstants, (list, tuple)): if not len(latticeconstants) == 1: raise ValueError("Too many latticeconstants") a = latticeconstants[0] else: a = latticeconstants elif surfacetype == 'hcp0001': nlayeratoms = surfacesize[0] * surfacesize[1] if isinstance(latticeconstants, (list, tuple)): if not len(latticeconstants) == 2: raise ValueError("Latticeconstants must be on the form [a, c]") a = latticeconstants[0] c = latticeconstants[1] else: raise ValueError("Latticeconstants must be on the form [a, c]") else: raise ValueError("Surface type '%s' is not supported" % (surfacetype, )) for n in layers: size = surfacesize + (n, ) if surfacetype == 'fcc100': images.append(fcc100(symbol=symbol, size=size, a=a, vacuum=vacuum)) elif surfacetype == 'fcc111': images.append( fcc111(symbol=symbol, size=size, a=a, vacuum=vacuum, orthogonal=True)) elif surfacetype == 'hcp0001': images.append( hcp0001(symbol=symbol, size=size, a=a, c=c, vacuum=vacuum, orthogonal=True)) return images, nlayeratoms
def get_atoms(): zpos = cos(134.3/2.0*pi/180.0)*1.197 xpos = sin(134.3/2.0*pi/180.0)*1.19 no2 =Atoms('CO', positions=[(-xpos+1.2,0,-zpos), (-xpos+1.2,-1.1,-zpos)]) # Surface slab slab =fcc111('Au', size=(2, 2, 4),vacuum=2*5, orthogonal = True ) slab.center() add_adsorbate(slab,no2,1.5,'bridge') slab.set_pbc((True,True,False)) #constraints constraint = FixAtoms(mask=[(a.tag == 4) or (a.tag == 3) or (a.tag==2) for a in slab]) slab.set_constraint(constraint) return slab
def get_atoms(): zpos = cos(134.3 / 2.0 * pi / 180.0) * 1.197 xpos = sin(134.3 / 2.0 * pi / 180.0) * 1.19 no2 = Atoms('CO', positions=[(-xpos + 1.2, 0, -zpos), (-xpos + 1.2, -1.1, -zpos)]) # Surface slab slab = fcc111('Au', size=(2, 2, 4), vacuum=2 * 5, orthogonal=True) slab.center() add_adsorbate(slab, no2, 1.5, 'bridge') slab.set_pbc((True, True, False)) #constraints constraint = FixAtoms(mask=[(a.tag == 4) or (a.tag == 3) or (a.tag == 2) for a in slab]) slab.set_constraint(constraint) return slab
def main(argv=[]): kwargs = getArgs(argv) elm = kwargs['element'] a = kwargs['lattice_constant'] size = kwargs['size'] orth = kwargs['orthogonal'] vac = kwargs['vacuum'] / 2 # applies to both sides of the slab fix = kwargs['fix'] pad = kwargs['pad'] slab = fcc111(elm, size=size, a=a, orthogonal=orth, vacuum=vac) # adjust cell minA = min([p[2] for p in slab.get_positions() if p[2] > 0]) slab.translate((0, 0, -1 * minA)) # set contraints constraint = FixAtoms(mask=[a.tag < fix for a in slab]) slab.set_constraint(constraint) # write POSCAR write('POSCAR' + pad, slab, format='vasp', direct=True)
def get_surface_slabs(symbol, surfacetype, surfacesize, layers, latticeconstants, vacuum=10.0): images = [] if surfacetype == 'fcc100' or surfacetype == 'fcc111': nlayeratoms = surfacesize[0] * surfacesize[1] if isinstance(latticeconstants, (list, tuple)): if not len(latticeconstants) == 1: raise ValueError("Too many latticeconstants") a = latticeconstants[0] else: a = latticeconstants elif surfacetype == 'hcp0001': nlayeratoms = surfacesize[0] * surfacesize[1] if isinstance(latticeconstants, (list, tuple)): if not len(latticeconstants) == 2: raise ValueError("Latticeconstants must be on the form [a, c]") a = latticeconstants[0] c = latticeconstants[1] else: raise ValueError("Latticeconstants must be on the form [a, c]") else: raise ValueError("Surface type '%s' is not supported" % (surfacetype,)) for n in layers: size = surfacesize + (n,) if surfacetype == 'fcc100': images.append(fcc100(symbol=symbol, size=size, a=a, vacuum=vacuum)) elif surfacetype == 'fcc111': images.append(fcc111(symbol=symbol, size=size, a=a, vacuum=vacuum, orthogonal=True)) elif surfacetype == 'hcp0001': images.append(hcp0001(symbol=symbol, size=size, a=a, c=c, vacuum=vacuum, orthogonal=True)) return images, nlayeratoms
from ase.lattice.surface import fcc111, hcp0001 from ase.lattice.hexagonal import * from ase import io from os import system import math POSCAR_string = "B N Al" lattice_constant_Al = 4.050 a_lattice_constant_BN = 2.5040 c_lattice_constant_BN = 6.6612 slab = fcc111('Al', size=(7, 7, 3), a=lattice_constant_Al, orthogonal=False, vacuum=0.0) bn = hcp0001('B', size=(8, 8, 2), a=a_lattice_constant_BN, c=0.0000001, vacuum=0.0) cell = bn.get_cell() #cell[2][2]=20.0 bn.translate([0, 0, 10]) num_each = bn.get_number_of_atoms() / 2 bn.set_atomic_numbers([5] * num_each + [7] * num_each) bn.extend(slab)
from ase.calculators.emt import EMT from ase.constraints import FixBondLengths from ase.optimize import BFGS, QuasiNewton from ase.neb import SingleCalculatorNEB from ase.lattice.surface import fcc111, add_adsorbate from math import sqrt, cos, sin for mic in [ False, True ]: zpos = cos(134.3/2.0*pi/180.0)*1.197 xpos = sin(134.3/2.0*pi/180.0)*1.19 co2 = Atoms('COO', positions=[(-xpos+1.2,0,-zpos), (-xpos+1.2,-1.1,-zpos), (-xpos+1.2,1.1,-zpos)]) slab = fcc111('Au', size=(2, 2, 4), vacuum=2*5, orthogonal=True) slab.center() add_adsorbate(slab,co2,1.5,'bridge') slab.set_pbc((True,True,False)) d0 = co2.get_distance(-3, -2) d1 = co2.get_distance(-3, -1) calc = EMT() slab.set_calculator(calc) if mic: # Remap into the cell so bond is actually wrapped. slab.set_scaled_positions(slab.get_scaled_positions()%1.0) constraint = FixBondLengths([[-3,-2],[-3,-1]], mic=True, atoms=slab) else: constraint = FixBondLengths([[-3,-2],[-3,-1]]) slab.set_constraint(constraint)
#!/usr/bin/env python from ase.calculators.aims import Aims from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms from ase import Atoms, Atom from ase.io import write atoms = fcc111('Pt', size=(1, 1, 4), vacuum=5.0) atoms.cell = atoms.cell*2.809/2.77185858 constraint = FixAtoms(mask=[atom.position[2] < (atoms.cell[2][2]/2.0 + 0.5) for atom in atoms]) atoms.set_constraint(constraint) write('images/pt-slab-114-relax.png', atoms, show_unit_cell=2) calc = Aims(label='surfaces/pt-slab-114-relax', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', kpts=(3, 3, 1), sc_accuracy_etot=1e-5, sc_accuracy_eev=1e-2, sc_accuracy_rho=1e-4, sc_accuracy_forces=1e-2, relax_geometry = 'bfgs 1.e-3') atoms.set_calculator(calc) print('energy = {0} eV'.format(atoms.get_potential_energy())) print('Forces') print('=======') print(atoms.get_forces()) for i in range(1, len(atoms)):
from ase import units from ase.md import MDLogger T = 100. # temperature folder = 'data' nk = 1 r0list = linspace(20,300,50) fric = 0.002 # equilibration time tau = 10 fs/fric mdsteps = 1000 d = 2.934 for R in r0list: print 'radius',R name=(folder,'%.1f' %R) atoms = fcc111('Au',size=(2,2,1),a=sqrt(2)*d) L = atoms.get_cell().diagonal() atoms. set_cell(L) angle = L[1]/R atoms.rotate('y',pi/2) atoms.translate( (-atoms[0].x,0,0) ) atoms.translate((R,0,0)) atoms = Atoms(atoms=atoms,container='Wedge') atoms.set_container(angle=angle,height=L[0],physical=False,pbcz=True) calc = Hotbit(SCC=False,txt='%s/optimization_%s.cal' %name,kpts=(nk,1,nk),physical_k=False) atoms.set_calculator(calc) traj = PickleTrajectory( 'md_R%.3f-T%.0f.traj' %(R,T),'w',atoms) dyn = Langevin(atoms,dt*units.fs,units.kB*T,fric)
from ase import * from math import asin, pi, sqrt from gpaw import GPAW from ase.lattice.surface import fcc111 # Define geometry of slab + BF4: slab = fcc111('Au', size=(2, 2, 3),orthogonal=True) slab.center(axis=2, vacuum=12) d=0.8 tFB1 = Atoms([Atom('B', (0, 0, 0)), Atom('F', (d, d, d)), Atom('F', (-d, -d, d)), Atom('F', (-d, d, -d)), Atom('F', (d, -d, -d))]) tFB1.rotate('y',pi/4,center=(0, 0, 0)) tFB1.rotate('x',asin(1/sqrt(3))+pi,center=(0, 0, 0)) tFB1.rotate('z',pi/3,center=(0, 0, 0)) tFB1.translate(slab.positions[5]+(0.,0.,5.118)) slab += tFB1 # Fix second and third layers: mask = [atom.tag > 1 for atom in slab] #print mask slab.set_constraint(constraints.FixAtoms(mask=mask)) # Initial state: calc = GPAW(h=0.16, kpts=(4, 4, 1), txt='22.txt',parallel={'domain':4}, xc='RPBE') slab.set_calculator(calc) qn=optimize.QuasiNewton(slab,trajectory='22.traj',restart='22.pckl') qn.run(fmax=0.05)
#!/usr/bin/env python from ase.lattice.surface import fcc111 atoms = fcc111('Al', size=(2, 2, 4), vacuum=10.0) print([atom.z for atom in atoms]) print [atom.z <= 13 for atom in atoms]
from ase.lattice.surface import fcc111 from ase.io import write slab = fcc111('Al', size=(2, 2, 3), vacuum=10.0) write('images/Al-slab.png', slab, rotation='90x', show_unit_cell=2)
from vasp import Vasp from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms atoms = fcc111("Pt", size=(2, 2, 3), vacuum=10.0) # note this function only works when atoms are created by the surface module. add_adsorbate(atoms, "O", height=1.2, position="hcp") constraint = FixAtoms(mask=[atom.symbol != "O" for atom in atoms]) atoms.set_constraint(constraint) from ase.io import write write("images/Pt-hcp-o-site.png", atoms, show_unit_cell=2) print( Vasp("surfaces/Pt-slab-O-hcp", xc="PBE", kpts=[4, 4, 1], encut=350, ibrion=2, nsw=25, atoms=atoms).potential_energy )
from ase import Atoms from ase.calculators.emt import EMT from ase.constraints import FixAtoms from ase.optimize import QuasiNewton from ase.lattice.surface import fcc111, add_adsorbate h = 1.85 d = 1.10 slab = fcc111('Cu', size=(4, 4, 2), vacuum=10.0) slab.set_calculator(EMT()) e_slab = slab.get_potential_energy() molecule = Atoms('2N', positions=[(0., 0., 0.), (0., 0., d)]) molecule.set_calculator(EMT()) e_N2 = molecule.get_potential_energy() add_adsorbate(slab, molecule, h, 'ontop') constraint = FixAtoms(mask=[a.symbol != 'N' for a in slab]) slab.set_constraint(constraint) dyn = QuasiNewton(slab, trajectory='N2Cu.traj') dyn.run(fmax=0.05) print('Adsorption energy:', e_slab + e_N2 - slab.get_potential_energy())
from jasp import * from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms from ase.io import write atoms = fcc111('Pt', size=(1, 1, 3), vacuum=10.0) # note this function only works when atoms are created by the surface module. add_adsorbate(atoms, 'O', height=1.2, position='fcc') constraint = FixAtoms(mask=[atom.symbol != 'O' for atom in atoms]) atoms.set_constraint(constraint) write('images/Pt-o-fcc-1ML.png', atoms, show_unit_cell=2) with jasp('surfaces/Pt-slab-1x1-O-fcc', xc='PBE', kpts=(8, 8, 1), encut=350, ibrion=2, nsw=25, atoms=atoms) as calc: print atoms.get_potential_energy()
from ase import Atoms from ase.lattice.surface import fcc111, add_adsorbate from ase.calculators.emt import EMT from ase.constraints import FixAtoms from ase.optimize import QuasiNewton from ase.io import write # Find the initial and final states for the reaction. # Set up a (4 x 4) two layer slab of Cu: slab = fcc111('Cu',size=(4,4,2)) slab.set_pbc((1,1,0)) # Initial state. # Add the N2 molecule oriented at 60 degrees: d = 1.10 # N2 bond length N2mol = Atoms('N2',positions=[[0.0,0.0,0.0],[0.5*3**0.5*d,0.5*d,0.0]]) add_adsorbate(slab,N2mol,height=1.0,position='fcc') # Use the EMT calculator for the forces and energies: slab.set_calculator(EMT()) # We don't want to worry about the Cu degrees of freedom, # so fix these atoms: mask = [atom.symbol == 'Cu' for atom in slab] slab.set_constraint(FixAtoms(mask=mask))
from ase import Atoms from ase.visualize import view from ase.calculators.vasp import Vasp from ase.calculators.emt import EMT from ase.constraints import FixAtoms from ase.optimize import QuasiNewton from ase.lattice.surface import fcc111, add_adsorbate from ase.io import write from ase.io.trajectory import PickleTrajectory import io import os #Date: 4/17/15 #sets up the slab and molecule slab = fcc111('Pd', size=(3, 3, 2), vacuum=10) molecule = Atoms('CO', [(0., 0., 0.), (0., 0., 1.13)]) add_adsorbate(slab, molecule, 1.7, 'ontop') #sets up the calculator calc = EMT() slab.set_calculator(calc) #runs optimization dyn = QuasiNewton(slab, trajectory='CO-Pd-ontop.traj') dyn.run(fmax=0.05) #writes the trajectory file in .xyz format traj = PickleTrajectory("CO-Pd-ontop.traj") nsteps = dyn.get_number_of_steps() string = 'structure'
try: from ase.calculators.d3ef import d3ef except ImportError: fortran = False def testforce(system, fortran=False, bj=False): system.set_calculator(D3(fortran=fortran, bj=bj)) f1 = system.get_forces() f2 = numeric_forces(system, d=0.0001) assert abs(f1 - f2).max() < 1e-6 waterdim = create_s22_system('Water_dimer') slab = fcc111('Au', (1, 1, 4), vacuum=7.5) testforce(waterdim, fortran=False, bj=False) #testforce(slab, fortran=False, bj=False) # This is too slow! testforce(waterdim, fortran=False, bj=True) #testforce(slab, fortran=False, bj=True) # This is too slow! if fortran: testforce(waterdim, fortran=True, bj=False) testforce(slab, fortran=True, bj=False) testforce(waterdim, fortran=True, bj=True) testforce(slab, fortran=True, bj=True)
import numpy from ase import io from ase import Atoms from ase.visualize import view from ase.lattice.surface import fcc111 #lattice_constant = 4.01 # http://www.hindawi.com/journals/apc/2011/305634/ GGA-PBE lattice_constant = 3.975 # vasp, Pt@PBE # experiment is 3.92 #lattice_constant = 4.1839615096998237 #lattice_constant = 4.06 # this is what I get for the 18e psp from Paratec slab = fcc111('Pt', size=(4, 4, 9), a=lattice_constant, vacuum=0.0, orthogonal=True) print 'used ', lattice_constant io.write('slab.vasp', slab) print 'Warning, Z-component of poscar seems to be incorrect' io.write('slab.xyz', slab) x1 = 4 * (lattice_constant * (1. / 2)**.5) x2 = 4 * (lattice_constant * (1. / 2)**.5) * numpy.cos(60 * numpy.pi / 180) y2 = 4 * (lattice_constant * (1. / 2)**.5) * numpy.sin(60 * numpy.pi / 180) print 'Angstrom ' print str(round(x1, 6)), 0.00, 0.00 print str(round(x2, 6)), str(round(y2, 6)), 0.00
from jasp import * from ase.lattice.surface import fcc111 atoms = fcc111('Pt', size=(2, 2, 4), vacuum=10.0, a=3.986) atoms.append(Atom('C', [atoms[12].x, atoms[12].y, atoms[12].z + 1.851])) atoms.append(Atom('O', [atoms[-1].x, atoms[-1].y, atoms[-1].z + 1.157])) for field in [-0.5, 0.0, 0.5]: with jasp('surfaces/Pt-co-field-{0}'.format(field), xc='PBE', encut=350, kpts=(6,6,1), efield=field, # set the field ldipol=True, # turn dipole correction on idipol=3, # set field in z-direction atoms=atoms) as calc: try: print '{0}: {1:1.3f}'.format(field, atoms.get_potential_energy()) except (VaspSubmitted, VaspQueued): pass
from ase.constraints import FixAtoms def check_forces(): """Makes sure the unconstrained forces stay that way.""" forces = atoms.get_forces(apply_constraint=False) funconstrained = float(forces[0, 0]) forces = atoms.get_forces(apply_constraint=True) forces = atoms.get_forces(apply_constraint=False) funconstrained2 = float(forces[0, 0]) assert funconstrained2 == funconstrained atoms = fcc111('Cu', (2, 2, 1), vacuum=10.) atoms[0].x += 0.2 atoms.set_constraint(FixAtoms(indices=[atom.index for atom in atoms])) # First run the tes with EMT and save a force component. atoms.set_calculator(EMT()) check_forces() f = float(atoms.get_forces(apply_constraint=False)[0, 0]) # Save and reload with a SinglePointCalculator. atoms.write('singlepointtest.traj') atoms = read('singlepointtest.traj') check_forces() # Manually change a value. forces = atoms.get_forces(apply_constraint=False)
import numpy as np from ase import Atoms, Atom from ase.lattice.surface import fcc111, fcc211, add_adsorbate atoms = fcc211('Au', (3, 5, 8), vacuum=10.) assert len(atoms) == 120 atoms = atoms.repeat((2, 1, 1)) assert np.allclose(atoms.get_distance(0, 130), 2.88499566724) atoms = fcc111('Ni', (2, 2, 4), orthogonal=True) add_adsorbate(atoms, 'H', 1, 'bridge') add_adsorbate(atoms, Atom('O'), 1, 'fcc') add_adsorbate(atoms, Atoms('F'), 1, 'hcp') # The next test ensures that a simple string of multiple atoms cannot be used, # which should fail with a KeyError that reports the name of the molecule due # to the string failing to work with Atom(). failed = False try: add_adsorbate(atoms, 'CN', 1, 'ontop') except KeyError as e: failed = True assert e.args[0] == 'CN' assert failed
from ase.lattice.surface import fcc111 atoms = fcc111('Al', size=(2, 2, 4), vacuum=10.0) print([atom.z for atom in atoms]) print[atom.z <= 13 for atom in atoms]
from gpaw import GPAW from ase.lattice.surface import fcc111 from ase.lattice.surface import add_adsorbate atoms = fcc111('Pt', (2, 2, 6), a=4.00, vacuum=10.0) add_adsorbate(atoms, 'O', 2.0, 'fcc') calc = GPAW(mode='pw', kpts=(8, 8, 1), xc='RPBE') ncpus = 4
#!/usr/bin/env python from ase.calculators.aims import Aims from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms from ase import Atoms, Atom from ase.io import write adsorbate = Atoms('CO') adsorbate[1].z = 1.13 atoms = fcc111('Pt', size=(1, 1, 3), vacuum=10.0) # note this function only works when atoms are created by the surface module. add_adsorbate(atoms, adsorbate, height=1.2, position='fcc') constraint = FixAtoms(mask=[atom.symbol != 'O' and atom.symbol != 'C' for atom in atoms]) atoms.set_constraint(constraint) write('images/pt-fcc-site.png', atoms, show_unit_cell=2) calc = Aims(label='surfaces/pt-slab-co-fcc', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', kpts=(3, 3, 1), sc_accuracy_etot=1e-5, sc_accuracy_eev=1e-2, sc_accuracy_rho=1e-4, sc_accuracy_forces=1e-2, relax_geometry = 'bfgs 1.e-2') atoms.set_calculator(calc) print('energy = {0} eV'.format(atoms.get_potential_energy())) print(atoms.get_forces())
# This test verifies that energy and forces are (approximately) # parallelization independent # # Tests the LCAO energy and forces in non-orthogonal cell with # simultaneous parallelization over bands, domains and k-points (if # enough CPUs are available), both with and without scalapack # (if scalapack is available). # # Run with 1, 2, 4 or 8 (best) CPUs. # # This test covers many cases not caught by lcao_parallel or # lcao_parallel_kpt # # Written November 24, 2011, r8567 system = fcc111('Au', size=(1, 3, 1)) system.numbers[0] = 8 # It is important that the number of atoms is uneven; this # tests the case where the band parallelization does not match # the partitioning of orbitals between atoms (the middle atom has orbitals # on distinct band descriptor ranks) system.center(vacuum=3.5, axis=2) system.rattle(stdev=0.2, seed=17) #from ase.visualize import view #view(system) #system.set_pbc(0) #system.center(vacuum=3.5) from gpaw import FermiDirac
from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms from ase import Atoms, Atom from ase.io import write from ase.visualize import view def sortz(atoms): tags = atoms.positions[:,2] deco = sorted([(tag, i) for i, tag in enumerate(tags)]) indices = [i for tag, i in deco] return atoms[indices] adsorbate = molecule('CO') adsorbate2 = molecule('O2') atoms = fcc111('Pt', size=(4, 4, 2), vacuum=6.0) # note this function only works when atoms are created by the surface module. add_adsorbate(atoms, adsorbate, height=3.0, position='ontop') add_adsorbate(atoms, adsorbate2, height=3.0, position='fcc') atoms = sortz(atoms) atoms.translate([0, 0, -atoms[0].z]) mask=[atom.index for atom in atoms if atom.symbol == 'O' or atom.symbol == 'C'] mol = atoms[mask] del atoms[mask] mol.cell[0:2, ] = mol.cell[0:2, ]*1/3.0 mol.cell[2][2] = 3 mol[-1].z = mol[-3].z mol[-1].position = mol[-1].position + mol.cell[0]/6 + mol.cell[1]/6 mol.translate([0, 0, -mol[1].z]) mol = mol*[3, 3, 2]
# compute local potential of slab with no dipole from ase.lattice.surface import fcc111, add_adsorbate from jasp import * import matplotlib.pyplot as plt from ase.io import write slab = fcc111('Al', size=(2, 2, 2), vacuum=10.0) add_adsorbate(slab, 'Na', height=1.2, position='fcc') slab.center() write('images/Na-Al-slab.png', slab, rotation='-90x', show_unit_cell=2) with jasp('surfaces/Al-Na-nodip', xc='PBE', encut=340, kpts=(2, 2, 1), lvtot=True, # write out local potential lvhar=True, # write out only electrostatic potential, not xc pot atoms=slab) as calc: calc.calculate()
from ase import * from math import asin, pi, sqrt from gpaw import GPAW from ase.lattice.surface import fcc111 # Define geometry of slab + BF4: slab = fcc111('Au', size=(6, 4, 3),orthogonal=True) slab.center(axis=2, vacuum=12) d=0.8 tFB1 = Atoms([Atom('B', (0, 0, 0)), Atom('F', (d, d, d)), Atom('F', (-d, -d, d)), Atom('F', (-d, d, -d)), Atom('F', (d, -d, -d))]) tFB1.rotate('y',pi/4,center=(0, 0, 0)) tFB1.rotate('x',asin(1/sqrt(3))+pi,center=(0, 0, 0)) tFB1.rotate('z',pi/3,center=(0, 0, 0)) tFB1.translate(slab.positions[25]+(0.,0.,5.118)) slab += tFB1 # Fix second and third layers: mask = [atom.tag > 1 for atom in slab] #print mask slab.set_constraint(constraints.FixAtoms(mask=mask)) calc = GPAW(h=0.16, kpts=(2, 3, 1), txt='64.txt',parallel={'domain':64}, xc='RPBE') slab.set_calculator(calc) qn=optimize.QuasiNewton(slab,trajectory='64.traj',restart='64.pckl') qn.run(fmax=0.05) qn.attach(calc.write,1,'64.gpw')
from ase.ga.data import PrepareDB from ase.ga.startgenerator import StartGenerator from ase.ga.utilities import closest_distances_generator from ase.ga.utilities import get_all_atom_types from ase.constraints import FixAtoms import numpy as np from ase.lattice.surface import fcc111 db_file = 'gadb.db' # create the surface slab = fcc111('Au', size=(4, 4, 1), vacuum=10.0, orthogonal=True) slab.set_constraint(FixAtoms(mask=len(slab) * [True])) # define the volume in which the adsorbed cluster is optimized # the volume is defined by a corner position (p0) # and three spanning vectors (v1, v2, v3) pos = slab.get_positions() cell = slab.get_cell() p0 = np.array([0., 0., max(pos[:, 2]) + 2.]) v1 = cell[0, :] * 0.8 v2 = cell[1, :] * 0.8 v3 = cell[2, :] v3[2] = 3. # Define the composition of the atoms to optimize atom_numbers = 2 * [47] + 2 * [79] # define the closest distance two atoms of a given species can be to each other unique_atom_types = get_all_atom_types(slab, atom_numbers) cd = closest_distances_generator(atom_numbers=unique_atom_types,
from ase.lattice.surface import fcc111 from vasp import Vasp slab = fcc111('Al', size=(1, 1, 4), vacuum=10.0) calc = Vasp('surfaces/Al-bandstructure', xc='PBE', encut=300, kpts=[6, 6, 6], lcharg=True, # you need the charge density lwave=True, # and wavecar for the restart atoms=slab) n, bands, p = calc.get_bandstructure(kpts_path=[(r'$\Gamma$', [0, 0, 0]), ('$K1$', [0.5, 0.0, 0.0]), ('$K1$', [0.5, 0.0, 0.0]), ('$K2$', [0.5, 0.5, 0.0]), ('$K2$', [0.5, 0.5, 0.0]), (r'$\Gamma$', [0, 0, 0]), (r'$\Gamma$', [0, 0, 0]), ('$K3$', [0.0, 0.0, 1.0])], kpts_nintersections=10) p.savefig('images/Al-slab-bandstructure.png')
from vasp import Vasp from ase.lattice.surface import fcc111 import matplotlib.pyplot as plt Nlayers = [3, 4, 5, 6, 7, 8, 9, 10, 11] energies = [] sigmas = [] for n in Nlayers: slab = fcc111('Cu', size=(1, 1, n), vacuum=10.0) slab.center() calc = Vasp('bulk/Cu-layers/{0}'.format(n), xc='PBE', encut=350, kpts=[8, 8, 1], atoms=slab) calc.set_nbands(f=2) # the default nbands in VASP is too low for Cu energies.append(slab.get_potential_energy()) calc.stop_if(None in energies) for i in range(len(Nlayers) - 1): N = Nlayers[i] DeltaE_N = energies[i + 1] - energies[i] sigma = 0.5 * (-N * energies[i + 1] + (N + 1) * energies[i]) sigmas.append(sigma) print 'nlayers = {1:2d} sigma = {0:1.3f} eV/atom'.format(sigma, N) plt.plot(Nlayers[0:-1], sigmas, 'bo-') plt.xlabel('Number of layers') plt.ylabel('Surface energy (eV/atom)') plt.savefig('images/Cu-unrelaxed-surface-energy.png')
from ase.io import read from ase.lattice.surface import fcc111, add_adsorbate, fcc100, fcc110, hcp0001, bcc111 import os import sys import shutil nargs = len(sys.argv) argv1 = sys.argv[1] argv2 = sys.argv[2] fname = 'scratch/structure' + argv1 tmpDir = os.getenv('PBSTMPDIR') folder = 'scratch/vasp' + argv1 #lattice and initial atom setup for unit cell slab = fcc111('Pt', size=(3, 3, 3), vacuum=10) add_adsorbate(slab, 'Au', 2.5, 'fcc') #current position read in slabatoms = read(fname) slab.set_positions(slabatoms.get_positions()) mask = [atom.tag > 2 for atom in slab] slab.set_constraint(FixAtoms(mask=mask)) calc = Vasp(xc='PBE', lreal='Auto', kpts=[2, 2, 1], ismear=1, sigma=0.2, algo='fast', istart=0,
'bands': -2}, txt='CO_lumo.txt') calc = GPAW(nbands=60, h=0.2, xc='RPBE', kpts=(8,6,1), eigensolver='cg', spinpol=True, mixer=MixerSum(nmaxold=5, beta=0.1, weight=100), convergence={'energy': 100, 'density': 100, 'eigenstates': 1.0e-7, 'bands': -10}, txt=filename+'.txt') #---------------------------------------- # Import Slab with relaxed CO #slab = Calculator('gs.gpw').get_atoms() slab = fcc111('Pt', size=(1, 2, 3), orthogonal=True) add_adsorbate(slab, 'C', 2.0, 'ontop') add_adsorbate(slab, 'O', 3.15, 'ontop') slab.center(axis=2, vacuum=4.0) view(slab) molecule = slab.copy() del molecule [:-2] # Molecule #---------------- molecule.set_calculator(c_mol) molecule.get_potential_energy()
def build(): p = OptionParser(usage='%prog [options] [ads@]surf [output file]', version='%prog 0.1', description='Example ads/surf: fcc-CO@2x2Ru0001') p.add_option('-l', '--layers', type='int', default=4, help='Number of layers.') p.add_option('-v', '--vacuum', type='float', default=5.0, help='Vacuum.') p.add_option('-x', '--crystal-structure', help='Crystal structure.', choices=['sc', 'fcc', 'bcc', 'hcp']) p.add_option('-a', '--lattice-constant', type='float', help='Lattice constant in Angstrom.') p.add_option('--c-over-a', type='float', help='c/a ratio.') p.add_option('--height', type='float', help='Height of adsorbate over surface.') p.add_option('--distance', type='float', help='Distance between adsorbate and nearest surface atoms.') p.add_option('-M', '--magnetic-moment', type='float', default=0.0, help='Magnetic moment.') p.add_option('-G', '--gui', action='store_true', help="Pop up ASE's GUI.") p.add_option('-P', '--python', action='store_true', help="Write Python script.") opt, args = p.parse_args() if not 1 <= len(args) <= 2: p.error("incorrect number of arguments") if '@' in args[0]: ads, surf = args[0].split('@') else: ads = None surf = args[0] if surf[0].isdigit(): i1 = surf.index('x') n = int(surf[:i1]) i2 = i1 + 1 while surf[i2].isdigit(): i2 += 1 m = int(surf[i1 + 1:i2]) surf = surf[i2:] else: n = 1 m = 1 if surf[-1].isdigit(): if surf[1].isdigit(): face = surf[1:] surf = surf[0] else: face = surf[2:] surf = surf[:2] else: face = None Z = atomic_numbers[surf] state = reference_states[Z] if opt.crystal_structure: x = opt.crystal_structure else: x = state['symmetry'] if opt.lattice_constant: a = opt.lattice_constant else: a = estimate_lattice_constant(surf, x, opt.c_over_a) script = ['from ase.lattice.surface import ', 'vac = %r' % opt.vacuum, 'a = %r' % a] if x == 'fcc': if face is None: face = '111' slab = fcc111(surf, (n, m, opt.layers), a, opt.vacuum) script[0] += 'fcc111' script += ['slab = fcc111(%r, (%d, %d, %d), a, vac)' % (surf, n, m, opt.layers)] r = a / np.sqrt(2) / 2 elif x == 'bcc': if face is None: face = '110' if face == '110': slab = bcc110(surf, (n, m, opt.layers), a, opt.vacuum) elif face == '100': slab = bcc100(surf, (n, m, opt.layers), a, opt.vacuum) script[0] += 'bcc' + face script += ['slab = bcc%s(%r, (%d, %d, %d), a, vac)' % (face, surf, n, m, opt.layers)] r = a * np.sqrt(3) / 4 elif x == 'hcp': if face is None: face = '0001' if opt.c_over_a is None: c = np.sqrt(8 / 3.0) * a else: c = opt.c_over_a * a slab = hcp0001(surf, (n, m, opt.layers), a, c, opt.vacuum) script[0] += 'hcp0001' script += ['c = %r * a' % (c / a), 'slab = hcp0001(%r, (%d, %d, %d), a, c, vac)' % (surf, n, m, opt.layers)] r = a / 2 elif x == 'diamond': if face is None: face = '111' slab = diamond111(surf, (n, m, opt.layers), a, opt.vacuum) script[0] += 'diamond111' script += ['slab = diamond111(%r, (%d, %d, %d), a, vac)' % (surf, n, m, opt.layers)] r = a * np.sqrt(3) / 8 else: raise NotImplementedError magmom = opt.magnetic_moment if magmom is None: magmom = {'Ni': 0.6, 'Co': 1.2, 'Fe': 2.3}.get(surf, 0.0) slab.set_initial_magnetic_moments([magmom] * len(slab)) if magmom != 0: script += ['slab.set_initial_magnetic_moments([%r] * len(slab))' % magmom] slab.pbc = 1 script += ['slab.pbc = True'] name = '%dx%d%s%s' % (n, m, surf, face) if ads: site = 'ontop' if '-' in ads: site, ads = ads.split('-') name = site + '-' + ads + '@' + name symbols = string2symbols(ads) nads = len(symbols) if nads == 1: script[:0] = ['from ase import Atoms'] script += ['ads = Atoms(%r)' % ads] ads = Atoms(ads) else: script[:0] = ['from ase.structure import molecule'] script += ['ads = molecule(%r)' % ads] ads = molecule(ads) add_adsorbate(slab, ads, 0.0, site) d = opt.distance if d is None: d = r + covalent_radii[ads[0].number] / 2 h = opt.height if h is None: R = slab.positions y = ((R[:-nads] - R[-nads])**2).sum(1).min()**0.5 h = (d**2 - y**2)**0.5 else: assert opt.distance is None slab.positions[-nads:, 2] += h script[1] += ', add_adsorbate' script += ['add_adsorbate(slab, ads, %r, %r)' % (h, site)] if len(args) == 2: write(args[1], slab) script[1:1] = ['from ase.io import write'] script += ['write(%r, slab)' % args[1]] elif not opt.gui: write(name + '.traj', slab) script[1:1] = ['from ase.io import write'] script += ['write(%r, slab)' % (name + '.traj')] if opt.gui: view(slab) script[1:1] = ['from ase.visualize import view'] script += ['view(slab)'] if opt.python: print('\n'.join(script))
#!/usr/bin/env python from jasp import * from ase.lattice.surface import fcc111, add_adsorbate from ase.constraints import FixAtoms atoms = fcc111('Pt', size=(2, 2, 3), vacuum=10.0) # note this function only works when atoms are created by the surface module. add_adsorbate(atoms, 'O', height=1.2, position='hcp') constraint = FixAtoms(mask=[atom.symbol != 'O' for atom in atoms]) atoms.set_constraint(constraint) from ase.io import write write('images/Pt-hcp-o-site.png', atoms, show_unit_cell=2) with jasp('surfaces/Pt-slab-O-hcp', xc='PBE', kpts=(4, 4, 1), encut=350, ibrion=2, nsw=25, atoms=atoms) as calc: calc.calculate()
#!/usr/bin/env python from ase.lattice.surface import fcc111 import ase import kmcos import kmcos from kmcos.utils import get_ase_constructor from kmcos.types import * import numpy as np slab = fcc111('Pt', [1,1,4], vacuum=10) positions = slab.get_scaled_positions() model_name = str(__file__[+0:-3]).replace("__build", "") # This line automatically names the model based on the python file’s name. The brackets cut off zero characters from the beginning and three character from the end (".py"). The replace command removes the ‘__build’ part of the string. If you want to override this automatic naming, just set the variable ‘model_name’ equal to the string that you would like to use. kmc_model = kmcos.create_kmc_model(model_name) kmc_model.set_meta(model_name='pt111', model_dimension='2', author='Max J. Hoffmann', email='*****@*****.**', debug=0) layer = Layer(name='pt111') pos1 = np.array([positions[1, 0], positions[1, 1], 0.672]) layer.add_site(Site(name='hollow1', pos=pos1)) pos2 = np.array([positions[2, 0], positions[2, 1], 0.672])
import numpy as np from ase import Atoms, Atom from ase.lattice.surface import fcc111, fcc211, add_adsorbate atoms = fcc211("Au", (3, 5, 8), vacuum=10.0) assert len(atoms) == 120 atoms = atoms.repeat((2, 1, 1)) assert np.allclose(atoms.get_distance(0, 130), 2.88499566724) atoms = fcc111("Ni", (2, 2, 4), orthogonal=True) add_adsorbate(atoms, "H", 1, "bridge") add_adsorbate(atoms, Atom("O"), 1, "fcc") add_adsorbate(atoms, Atoms("F"), 1, "hcp") # The next test ensures that a simple string of multiple atoms cannot be used, # which should fail with a KeyError that reports the name of the molecule due # to the string failing to work with Atom(). failed = False try: add_adsorbate(atoms, "CN", 1, "ontop") except KeyError as e: failed = True assert e.args[0] == "CN" assert failed
from ase.ga.startgenerator import StartGenerator from ase.ga.utilities import closest_distances_generator, atoms_too_close from ase.ga.cutandsplicepairing import CutAndSplicePairing import numpy as np from ase.lattice.surface import fcc111 from ase.constraints import FixAtoms # first create two random starting candidates slab = fcc111("Au", size=(4, 4, 2), vacuum=10.0, orthogonal=True) slab.set_constraint(FixAtoms(mask=slab.positions[:, 2] <= 10.0)) pos = slab.get_positions() cell = slab.get_cell() p0 = np.array([0.0, 0.0, max(pos[:, 2]) + 2.0]) v1 = cell[0, :] * 0.8 v2 = cell[1, :] * 0.8 v3 = cell[2, :] v3[2] = 3.0 cd = closest_distances_generator(atom_numbers=[47, 79], ratio_of_covalent_radii=0.7) atom_numbers = 2 * [47] + 2 * [79] sg = StartGenerator( slab=slab, atom_numbers=atom_numbers, closest_allowed_distances=cd, box_to_place_in=[p0, [v1, v2, v3]] ) c1 = sg.get_new_candidate() c1.info["confid"] = 1 c2 = sg.get_new_candidate() c2.info["confid"] = 2
# Benzene on the slab from jasp import * from ase.lattice.surface import fcc111, add_adsorbate from ase.structure import molecule from ase.constraints import FixAtoms atoms = fcc111('Au', size=(3,3,3), vacuum=10) benzene = molecule('C6H6') benzene.translate(-benzene.get_center_of_mass()) # I want the benzene centered on the position in the middle of atoms # 20, 22, 23 and 25 p = (atoms.positions[20] + atoms.positions[22] + atoms.positions[23] + atoms.positions[25])/4.0 + [0.0, 0.0, 3.05] benzene.translate(p) atoms += benzene # now we constrain the slab c = FixAtoms(mask=[atom.symbol=='Au' for atom in atoms]) atoms.set_constraint(c) #from ase.visualize import view; view(atoms) with jasp('surfaces/Au-benzene-pbe', xc='PBE', encut=350, kpts=(4,4,1), ibrion=1, nsw=100, atoms=atoms) as calc: print atoms.get_potential_energy()
from ase import io from ase import Atoms from ase.visualize import view from ase.lattice.surface import fcc111 vasp_GW_project = 4.1839615096998237 # this is the lattice const I used for most MD vasp_Au_vdWDF = 4.25 vasp_Au_ariel = 4.16089 experiment = 4.08 lattice_const = vasp_GW_project slab = fcc111('Au', size=(5, 5, 6), a=lattice_const, vacuum=0.0, orthogonal=False) view(slab) print('used ', lattice_const) io.write('slab.cube', slab) io.write('slab.xyz', slab) x1 = 5 * (lattice_const * (1. / 2)**.5) x2 = 5 * (lattice_const * (1. / 2)**.5) * numpy.cos(60 * numpy.pi / 180) y2 = 5 * (lattice_const * (1. / 2)**.5) * numpy.sin(60 * numpy.pi / 180) print('Angstrom ') print(str(round(x1, 6)), 0.00, 0.00) print(str(round(x2, 6)), str(round(y2, 6)), 0.00)