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
Example #2
0
        '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
Example #3
0
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')