vib = Vibrations(atoms, indices=vibrateatoms, delta=0.03) vib.run() vib.summary(method='standard') # Make trajectory files to visualize the modes. for mode in range(len(vibrateatoms) * 3): vib.write_mode(mode) # Calculate free energy vib_energies = vib.get_energies() thermo = IdealGasThermo(vib_energies=vib_energies, electronicenergy=energy, atoms=atoms, geometry='linear', symmetrynumber=2, spin=0) # At 300K and 101325 Pa # change for your operating conditions freeenergy = thermo.get_gibbs_energy(temperature=300, pressure=101325) f = open(name + '.energy', 'w') f.write('Potential energy: ' + str(energy) + '\n' + 'Free energy: ' + str(freeenergy) + '\n') f.close ens = BEEF_Ensemble(calc) ens_e = ens.get_ensemble_energies() ens.write('ensemble.bee') pickle.dump(ens_e, open('ensemble.pkl', 'w'))
'removewf': True, 'wf_collect': False }, outdir='calcdir', dipole={'status': True}) #if qn.traj exists, restart from the last steps if os.path.exists('qn.traj') and os.path.getsize('qn.traj') != 0: Slab = read('qn.traj', index=-1) from math import sqrt Slab.set_calculator(calc) write('Initial_Slab_with_constraint.traj', Slab) dyn = QuasiNewton(Slab, logfile='out_scf.log', trajectory='qn.traj') dyn.run(fmax=fmaxout) energy = Slab.get_potential_energy() ens = BEEF_Ensemble(calc) d_energy = ens.get_ensemble_energies() calc.stop() print 'Final SCF energy: %18f [eV]' % (energy) print 'Deviation in energy: %18f [eV]' % (d_energy.std()) print '\n' Slab.write('final_' + Slab.get_chemical_formula() + '.traj') relaxed_atoms = calc.get_final_structure() psppath = '/home/users/vossj/suncat/psp/gbrv1.5pbe' pseudos = psppath.split('/')[-1] print 'Potential Energy:', energy, 'eV' print 'Maximum force:', fmaxout, 'eV/A' print 'Final Structure:', relaxed_atoms
# number of steps numsteps = 40 # for loop that changes the distance between the atoms, fixes it, and performs # a structural optimization. results writen out as i*.traj files for step, delta in enumerate(xrange(0,30,1)): if atoms.get_distance(atom1, atom2) < threshold: break if step < numsteps: atoms.set_distance(atom1, atom2, d, fix=0.5) qn = QuasiNewton(atoms, trajectory='i'+str(delta)+'.traj') qn.run(fmax=0.05) e = atoms.get_potential_energy() print d, e print >> f, d, e f.flush() d -= 0.1 f.close() # ensemble ens = BEEF_Ensemble(calc) ens.get_ensemble_energies() ens.write('fbl.bee') del sys, calc, ens
conv = {'eigenstates':1.e-6, 'density':1.e-6, 'energy':1.e-6} h = 0.18 tol1 = 1.e-3 tol2 = 1.e-1 # N2 molecule n2 = Cluster(Atoms('N2',[[0.,0.,0.],[0.,0.,1.09]])) n2.minimal_box(3.0, h=h) cell = n2.get_cell() calc = GPAW(h=h, xc='PBE', convergence=conv) n2.set_calculator(calc) n2.get_potential_energy() n2.calc.set(xc=xc) e_n2 = n2.get_potential_energy() f = n2.get_forces() ens = BEEF_Ensemble(n2) de_n2 = ens.get_ensemble_energies() del n2, calc, ens # N atom n = Atoms('N') n.set_cell(cell) n.center() calc = GPAW(h=h, xc='PBE', convergence=conv, hund=True) n.set_calculator(calc) n.get_potential_energy() n.calc.set(xc=xc) e_n = n.get_potential_energy() ens = BEEF_Ensemble(n) de_n = ens.get_ensemble_energies() del n, calc, ens
sigma=0.1, psppath='/home/vossj/suncat/psp/gbrv1.5pbe', #pseudopotential path convergence= {'energy':1e-5, #convergence parameters 'mixing':0.1, 'nmix':10, 'mix':4, 'maxsteps':500, 'diag':'david' }, dipole={'status':True}, #dipole correction to account for periodicity in z beefensemble = True, printensemble =True, outdir='calcdir') #output directory for Quantum Espresso files # attach the espresso calculator to the surface atoms.set_calculator(calc) # optimize the structure until the maximum force is # at most 0.05 eV/AA # output will be written to "qn.traj" with optimization log # written to "qn.log" qn = QuasiNewton(atoms, trajectory='qn.traj', logfile='qn.log') qn.run(fmax=0.05) #relevant commands for saving the BEEF error ensemble #useful if you choose to perform error analysis ens = BEEF_Ensemble(calc) ens_e = ens.get_ensemble_energies() ens.write('ensemble.bee') pickle.dump(ens_e,open('ensemble.pkl','w'))
# number of steps numsteps = 40 # for loop that changes the distance between the atoms, fixes it, and performs # a structural optimization. results writen out as i*.traj files for step, delta in enumerate(xrange(0, 30, 1)): if atoms.get_distance(atom1, atom2) < threshold: break if step < numsteps: atoms.set_distance(atom1, atom2, d, fix=0.5) qn = QuasiNewton(atoms, trajectory='i' + str(delta) + '.traj') qn.run(fmax=0.05) e = atoms.get_potential_energy() print d, e print >> f, d, e f.flush() d -= 0.1 f.close() # ensemble ens = BEEF_Ensemble(calc) ens.get_ensemble_energies() ens.write('fbl.bee') del sys, calc, ens
xc = 'BEEF-vdW' d = 0.75 tol1 = 1.e-10 tol2 = 1.e-2 tol3 = 1.e-1 # H2 molecule h2 = Atoms('H2',[[0.,0.,0.],[0.,0.,d]]) h2.center(vacuum=2.) cell = h2.get_cell() calc = GPAW(xc=xc) h2.set_calculator(calc) e_h2 = h2.get_potential_energy() f = h2.get_forces() ens = BEEF_Ensemble(calc) de_h2 = ens.get_ensemble_energies() del h2, calc, ens # H atom h = Atoms('H') h.set_cell(cell) h.center() calc = GPAW(xc=xc, spinpol=True) h.set_calculator(calc) e_h = h.get_potential_energy() ens = BEEF_Ensemble(calc) de_h = ens.get_ensemble_energies() # forces f0 = f[0].sum()
from ase.dft.bee import BEEF_Ensemble import numpy as np ens = BEEF_Ensemble() def read_beef(filename): energy, ensemble = ens.read(filename) return energy, ensemble # read out the energy and the ensemble of energies for each calculation E_N2, E_ens_N2 = read_beef('folder_name/N2.bee') E_cluster, E_ens_cluster = read_beef('folder_name/cluster.bee') E_2N_cluster, E_ens_2N_cluster = read_beef('folder_name/2N_cluster.bee') # compute the energy E_2N = E_2N_cluster - E_cluster - E_N2 # computer the standard deviation (the error) from the ensembles dE_2N = np.std(E_ens_2N_cluster - E_ens_cluster - E_ens_N2) print "Reaction energy:", E_2N print "Error:", dE_2N
def run_geo_opt(bulk_name, final_traj_name, site_coord): ''' This function runs the DFT calculations for the given trajectory name. It puts the adsorbate on the passed site coordinate. ''' time2= time.time() f.write('\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') f.write('Starting calculations: %30s\n' %(final_traj_name.split('.')[0])) f.write('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') db=connect('/home/mamunm/DATABASE/adsorbate-slab.db') ######Calculations parameters####### pw=500. dw=5000. xc='BEEF-vdW' kpts=(6,6,1) code='Qunatum-Espresso' facet=(1,1,1) layer=3 vacuum=10 a = final_traj_name.split('_') adsorbate = a[1] site = a[2] + '_' + a[3] + '_' + a[4] slab_name = a[5].split('.')[0] height = get_height(adsorbate, a[4]) f.write('\nComputed initial adsorption height: %4.2f Angstrom\n' %(height)) if '6' in slab_name: SBS_symbol = 'L10' #Strukterbericht symbol PS_symbol = 'tP2' #Pearson symbol else: SBS_symbol = 'L12' #Strukterbericht symbol PS_symbol = 'cP4' #Pearson symbol supercell='2x2' fmaxout=0.05 crystal='fcc' pol_metal = ['Fe', 'Ni', 'Co', 'Mn'] spinpol = False DB_dir = '/scratch/users/mamunm/DATABASE/Binary_Alloy_Project/Surface/' if '6' in slab_name: metal1 = slab_name.split('6')[0] metal2 = slab_name.split('6')[1] path_to_slab = DB_dir + '/AB/' if os.path.exists(path_to_slab + bulk_name): slab = read(path_to_slab + bulk_name + '/Initial_Slab_with_constraint.traj') if metal1 in pol_metal or metal2 in pol_metal: spinpol = True slab.set_initial_magnetic_moments([2.0 if atom.symbol in pol_metal else 0 for atom in slab]) else: metal1 = slab_name.split('9')[0] metal2 = slab_name.split('9')[1].split('3')[0] path_to_slab = DB_dir + '/A3B/' if os.path.exists(path_to_slab + bulk_name): slab = read(path_to_slab + bulk_name + '/Initial_Slab_with_constraint.traj') if metal1 in pol_metal or metal2 in pol_metal: spinpol = True slab.set_initial_magnetic_moments([2.0 if atom.symbol in pol_metal else 0 for atom in slab]) calc = espresso(pw = pw, dw = dw, xc = xc, kpts = kpts, spinpol = spinpol, nbands = -10, occupations = 'smearing', #'smeraing', 'fixed', 'tetrahedra' smearing = 'fd', #Fermi-Dirac sigma = 0.15, calcstress = True, mode = 'relax', nosym = True, beefensemble = True, convergence= {'energy' : 1e-5*13.6, 'mixing' : 0.3, 'nmix' : 10, 'mix' : 4, 'maxsteps' : 2000, 'diag' : 'david' }, psppath='/home/vossj/suncat/psp/gbrv1.5pbe', output = {'avoidio':False,'removewf':True,'wf_collect':False}, outdir='Calculations/'+ adsorbate + '_' + site + '/calcdir', dipole={'status':True}) #Add adsorbate on the surface add_adsorbate(slab, adsorbate, height, site_coord) slab.write('Initial_slab_with_adsorbate.traj') #if qn.traj exists, restart from the last steps if os.path.exists('qn.traj') and os.path.getsize('qn.traj') != 0: slab=read('qn.traj',index=-1) slab.set_calculator(calc) dyn = QuasiNewton(slab,logfile='out_scf.log',trajectory='qn.traj') dyn.run(fmax=fmaxout) energy = slab.get_potential_energy() ens=BEEF_Ensemble(calc) d_energy=ens.get_ensemble_energies() calc.stop() f.write('Final SCF energy: %18f [eV]\n'%(energy)) f.write('Deviation in energy: %18f [eV]\n'%(d_energy.std())) slab.write(final_traj_name) relaxed_atoms = calc.get_final_structure() psppath='/home/vossj/suncat/psp/gbrv1.5pbe' pseudos = psppath.split('/')[-1] f.write('Potential Energy: %2.10E eV\n' %(energy)) f.write('Maximum force: %2.6f eV/A\n' %(fmaxout)) f.write('Final Structure: %-300s\n' %(str(relaxed_atoms))) db.write(relaxed_atoms, crystal = crystal, epot = energy, supercell = supercell, layer = layer, SBS_symbol = SBS_symbol, vacuum = vacuum, facet = str(facet), PS_symbol = PS_symbol, slab_name = slab_name, adsorbate = adsorbate, site = site, name=str(slab.get_chemical_formula()), fmaxout = fmaxout, xc = xc, pw = pw, dw = dw, Ensemble_energy = d_energy.std(), code = code, psp = pseudos) f.write('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n') f.write("Elapsed time for %20s :: %s seconds\n" %(final_traj_name.split('.')[0], time.time()-time2)) f.write('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n')