示例#1
0
def check_df(name, ref_energy, ref_loss, ref_energy_lfe, ref_loss_lfe,
             **kwargs_override):
    kwargs = dict(calc=calc, q=q, w=w.copy(), eta=0.5, ecut=(30, 30, 30),
                  txt='df.%s.txt' % name)
    kwargs.update(kwargs_override)
    df = DF(**kwargs)
    fname = 'dfdump.%s.dat' % name
    df.get_EELS_spectrum(filename=fname)
    world.barrier()
    d = np.loadtxt(fname)

    loss = d[:, 1]
    loss_lfe = d[:, 2]
    energies = d[:, 0]

    #import pylab as pl
    #fig = pl.figure()
    #ax1 = fig.add_subplot(111)
    #ax1.plot(d[:, 0], d[:, 1]/np.max(d[:, 1]))
    #ax1.plot(d[:, 0], d[:, 2]/np.max(d[:, 2]))
    #ax1.axis(ymin=0, ymax=1)
    #fig.savefig('fig.%s.pdf' % name)

    energy, peakloss = getpeak(energies, loss)
    energy_lfe , peakloss_lfe = getpeak(energies, loss_lfe)

    check(name, energy, peakloss, ref_energy, ref_loss)
    check('%s-lfe' % name, energy_lfe, peakloss_lfe, ref_energy_lfe,
          ref_loss_lfe)

    line = template % (name, energy, peakloss, energy_lfe, peakloss_lfe,
                       repr(kwargs_override))
    scriptlines.append(line)
示例#2
0
if bse:
    
    bse = BSE('Al.gpw',w=np.linspace(0,24,241),
              q=np.array([0.25, 0, 0]),ecut=50., eta=0.2)

    bse.get_dielectric_function('Al_bse.dat')
    
if df:

    # Excited state calculation
    q = np.array([1/4.,0.,0.])
    w = np.linspace(0, 24, 241)
    
    df = DF(calc='Al.gpw', q=q, w=w, eta=0.2, ecut=50,hilbert_trans=False)
    df1, df2 = df.get_dielectric_function()
    df.get_EELS_spectrum(df1, df2,filename='Al_df.dat')
    df.write('Al.pckl')
    df.check_sum_rule()


if check_spectrum:

    d = np.loadtxt('Al_bse.dat')[:,2] 
    wpeak = 16.4 
    Nw = 164
    if d[Nw] > d[Nw-1] and d[Nw] > d[Nw+1]:
        pass
    else:
        raise ValueError('Plasmon peak not correct ! ')
    
    if np.abs(d[Nw] - 27.5317730322) > 1e-5:
示例#3
0
    eigensolver=
    'cg',  # It's preferable to use 'cg' to calculate unoccupied states.
    occupations=FermiDirac(0.05),
    txt='out_gs.txt')

atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('graphite.gpw', 'all')

# Part 2: Spectra calculations
f = paropen('graphite_q_list', 'w')  # Write down q.

for i in range(1, 8):  # Loop over different q.
    df = DF(
        calc='graphite.gpw',
        nbands=60,  # Use only bands that are converged in the gs calculation.
        q=np.array([i / 20., 0., 0.]),  # Gamma - M excitation
        #q=np.array([i/20., -i/20., 0.])  # Gamma - K excitation
        w=np.linspace(0, 40, 401),  # Spectra from 0-40 eV with 0.1 eV spacing.
        eta=0.2,  # Broadening parameter.
        ecut=40 + (i - 1) *
        10,  # In general, larger q requires larger planewave cutoff energy.       # 
        txt='out_df_%d.txt' % (i))  # Write differnt output for different q.

    df1, df2 = df.get_dielectric_function()
    df.get_EELS_spectrum(df1, df2, filename='graphite_EELS_%d' %
                         (i))  # Use different filenames for different q
    df.check_sum_rule(df1, df2)  # Check f-sum rule.

    print >> f, sqrt(np.inner(df.qq_v / Bohr, df.qq_v / Bohr))
示例#4
0
              ecut=50.,
              eta=0.2)
    bse.get_dielectric_function('Al_bse.dat')
    
if df:
    # Excited state calculation
    q = np.array([1/4.,0.,0.])
    w = np.linspace(0, 24, 241)
    
    df = DF(calc='Al.gpw',
            q=q,
            w=w,
            eta=0.2,
            ecut=50,
            hilbert_trans=False)
    df.get_EELS_spectrum(filename='Al_df.dat')
    df.write('Al.pckl')
    df.check_sum_rule()


if check_spectrum:
    d = np.loadtxt('Al_bse.dat')[:,2] 
    wpeak = 16.4 
    Nw = 164
    if d[Nw] > d[Nw-1] and d[Nw] > d[Nw+1]:
        pass
    else:
        raise ValueError('Plasmon peak not correct ! ')
    
    if np.abs(d[Nw] - 27.4958893542) > 1e-5:
        print d[Nw]
示例#5
0
    },
    idiotproof=False,  # allow uneven distribution of k-points
    xc='LDA')

atoms.set_calculator(calc)
atoms.get_potential_energy()
#calc.write('Al.gpw','all')
t2 = time.time()

# Excited state calculation
q = np.array([1 / 4., 0., 0.])
w = np.linspace(0, 24, 241)

df = DF(calc=calc, q=q, w=w, eta=0.2, ecut=50)
df1, df2 = df.get_dielectric_function()
df.get_EELS_spectrum(df1, df2, filename='EELS_Al')
df.check_sum_rule()

t3 = time.time()

print 'For ground  state calc, it took', (t2 - t1) / 60, 'minutes'
print 'For excited state calc, it took', (t3 - t2) / 60, 'minutes'

d = np.loadtxt('EELS_Al')
wpeak = 15.7  # eV
Nw = 157
if d[Nw, 1] > d[Nw - 1, 1] and d[Nw, 2] > d[Nw + 1, 2]:
    pass
else:
    raise ValueError('Plasmon peak not correct ! ')
示例#6
0
    atoms.get_potential_energy()
    calc.write('graphite.gpw','all')


if EELS:
                
    f = paropen('graphite_q_list', 'w')

    for i in range(1,8):
       
        w = np.linspace(0, 40, 401)
        q = np.array([i/20., 0., 0.]) # Gamma-M excitation
        #q = np.array([i/20., -i/20., 0.]) # Gamma-K excitation

        ecut = 40 + (i-1)*10
        df = DF(calc='graphite.gpw', nbands=nband, q=q, w=w,
                eta=0.2,ecut=ecut)

        df1, df2 = df.get_dielectric_function()

        df.get_EELS_spectrum(df1, df2,filename='graphite_EELS_' + str(i))
        df.check_sum_rule(df1, df2)

        print >> f, sqrt(np.inner(df.qq_v / Bohr, df.qq_v / Bohr)), ecut

    if rank == 0:
        os.remove('graphite.gpw')



示例#7
0
              w=np.linspace(0, 24, 241),
              q=np.array([0.25, 0, 0]),
              ecut=50.,
              eta=0.2)

    bse.get_dielectric_function('Al_bse.dat')

if df:

    # Excited state calculation
    q = np.array([1 / 4., 0., 0.])
    w = np.linspace(0, 24, 241)

    df = DF(calc='Al.gpw', q=q, w=w, eta=0.2, ecut=50, hilbert_trans=False)
    df1, df2 = df.get_dielectric_function()
    df.get_EELS_spectrum(df1, df2, filename='Al_df.dat')
    df.write('Al.pckl')
    df.check_sum_rule()

if check_spectrum:

    d = np.loadtxt('Al_bse.dat')[:, 2]
    wpeak = 16.4
    Nw = 164
    if d[Nw] > d[Nw - 1] and d[Nw] > d[Nw + 1]:
        pass
    else:
        raise ValueError('Plasmon peak not correct ! ')

    if np.abs(d[Nw] - 27.5317730322) > 1e-5:
        print d[Nw]
示例#8
0
            kpts=(4,4,4),
            parallel={'domain':1,
                      'band':1},
            idiotproof=False,  # allow uneven distribution of k-points
            xc='LDA')

atoms.set_calculator(calc)
atoms.get_potential_energy()
t2 = time.time()

# Excited state calculation
q = np.array([1/4.,0.,0.])
w = np.linspace(0, 24, 241)

df = DF(calc=calc, q=q, w=w, eta=0.2, ecut=(50,50,50))
df.get_EELS_spectrum(filename='EELS_Al')
df.check_sum_rule()
df.write('Al.pckl')

t3 = time.time()

print 'For ground  state calc, it took', (t2 - t1) / 60, 'minutes'
print 'For excited state calc, it took', (t3 - t2) / 60, 'minutes'

d = np.loadtxt('EELS_Al')
wpeak = 15.7 # eV
Nw = 157
if d[Nw, 1] > d[Nw-1, 1] and d[Nw, 2] > d[Nw+1, 2]:
    pass
else:
    raise ValueError('Plasmon peak not correct ! ')
示例#9
0
atoms.set_calculator(calc)
t1 = time.time()
atoms.get_potential_energy()
t2 = time.time()
calc.write('Al.gpw','all')

t3 = time.time()

# Excited state calculation
q = np.array([1/4.,0.,0.])
w = np.linspace(0, 24, 241)
    
df = DF(calc='Al.gpw', q=q, w=w, eta=0.2, ecut=50)
#df.write('Al.pckl')
df.get_EELS_spectrum(filename='EELS_Al_lcao')
df.check_sum_rule()
    
t4 = time.time()

print 'For ground  state calc, it took', (t2 - t1) / 60, 'minutes'
print 'For writing gpw, it took', (t3 - t2) / 60, 'minutes'
print 'For excited state calc, it took', (t4 - t3) / 60, 'minutes'

d = np.loadtxt('EELS_Al_lcao')
wpeak = 16.9 # eV
Nw = 169
if d[Nw, 1] > d[Nw-1, 1] and d[Nw, 2] > d[Nw+1, 2]:
    pass
else:
    raise ValueError('Plasmon peak not correct ! ')
示例#10
0
            eigensolver=RMM_DIIS(),
            mixer=Mixer(0.1,3),
            kpts=(4,4,4),
            xc='LDA')

atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('Al1.gpw','all')

# Excited state calculation
q = np.array([1./4.,0.,0.])
w = np.linspace(0, 24, 241)

df = DF(calc='Al1.gpw', q=q, w=w, eta=0.2, ecut=50)
#df.write('Al.pckl')
df.get_EELS_spectrum(filename='EELS_Al_1')

atoms = Atoms('Al8',scaled_positions=[(0,0,0),
                               (0.5,0,0),
                               (0,0.5,0),
                               (0,0,0.5),
                               (0.5,0.5,0),
                               (0.5,0,0.5),
                               (0.,0.5,0.5),
                               (0.5,0.5,0.5)],
              cell=[(0,a,a),(a,0,a),(a,a,0)],
              pbc=True)

calc = GPAW(gpts=(24,24,24),
            eigensolver=RMM_DIIS(),
            mixer=Mixer(0.1,3),
示例#11
0
        convergence={"bands": nband},
        eigensolver="cg",
        width=0.1,
    )
    atoms.set_calculator(calc)
    atoms.get_potential_energy()

if EELS:

    for i in range(1, 2):
        w = np.linspace(0, 15, 301)
        q = np.array([-i / 64.0, i / 64.0, 0.0])  # Gamma - K
        ecut = 40 + i * 10
        df = DF(calc=calc, q=q, w=w, eta=0.05, ecut=ecut, txt="df_" + str(i) + ".out")
        df.get_surface_response_function(z0=21.2 / 2, filename="be_EELS")
        df.get_EELS_spectrum()
        df.check_sum_rule()
        df.write("df_" + str(i) + ".pckl")

if check:
    d = np.loadtxt("be_EELS")

    wpeak1 = 2.50  # eV
    wpeak2 = 9.95
    Nw1 = 50
    Nw2 = 199

    if (
        d[Nw1, 1] > d[Nw1 - 1, 1]
        and d[Nw1, 1] > d[Nw1 + 1, 1]
        and d[Nw2, 1] > d[Nw2 - 1, 1]
示例#12
0
import numpy as np
from ase.structure import bulk
from gpaw import GPAW
from gpaw.response.df import DF

# Part 1: Ground state calculation
atoms = bulk('Al', 'fcc',
             a=4.043)  # Generate fcc crystal structure for aluminum
calc = GPAW(h=0.2, kpts=(4, 4, 4))  # GPAW calculator initialization

atoms.set_calculator(calc)
atoms.get_potential_energy()  # Ground state calculation is performed
calc.write('Al.gpw', 'all')  # Use 'all' option to write wavefunctions

# Part 2: Spectrum calculation      # DF: dielectric function object
df = DF(
    calc='Al.gpw',  # Ground state gpw file as input
    q=np.array([
        1. / 4., 0, 0
    ]),  # Momentum transfer, must be the difference between two kpoints !
    w=np.linspace(0, 24, 241)
)  # The Energies (eV) for spectrum: from 0-24 eV with 0.1 eV spacing

df.get_EELS_spectrum()  # By default, a file called 'EELS.dat' is generated
示例#13
0
            xc='LDA')

atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('Al.gpw','all')

t2 = time.time()

# Excited state calculation
q = np.array([1/4.,0.,0.])
w = np.linspace(0, 24, 241)
    
df = DF(calc='Al.gpw', q=q, w=w, eta=0.2, ecut=50)
df1, df2 = df.get_dielectric_function()
#df.write('Al.pckl')
df.get_EELS_spectrum(df1, df2,filename='EELS_Al_lcao')
df.check_sum_rule(df1, df2)
    
t3 = time.time()

print 'For ground  state calc, it took', (t2 - t1) / 60, 'minutes'
print 'For excited state calc, it took', (t3 - t2) / 60, 'minutes'

d = np.loadtxt('EELS_Al_lcao')
wpeak = 16.9 # eV
Nw = 169
if d[Nw, 1] > d[Nw-1, 1] and d[Nw, 2] > d[Nw+1, 2]:
    pass
else:
    raise ValueError('Plasmon peak not correct ! ')
示例#14
0
import numpy as np
from ase.lattice import bulk
from gpaw import GPAW
from gpaw.response.df import DF

# Part 1: Ground state calculation
atoms = bulk('Al', 'fcc', a=4.043)  # Generate fcc crystal structure for aluminum
calc = GPAW(h=0.2, kpts=(4,4,4))    # GPAW calculator initialization

atoms.set_calculator(calc)
atoms.get_potential_energy()        # Ground state calculation is performed
calc.write('Al.gpw','all')          # Use 'all' option to write wavefunctions

# Part 2: Spectrum calculation      # DF: dielectric function object
df = DF(calc='Al.gpw',              # Ground state gpw file as input
        q=np.array([1./4., 0, 0]),  # Momentum transfer, must be the difference between two kpoints !
        w=np.linspace(0, 24, 241))  # The Energies (eV) for spectrum: from 0-24 eV with 0.1 eV spacing

df.get_EELS_spectrum()              # By default, a file called 'EELS.dat' is generated
示例#15
0
calc = GPAW(gpts=(12,12,12),
            kpts=(4,4,4),
            xc='LDA')

atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('Al1.gpw','all')

# Excited state calculation
q = np.array([1./4.,0.,0.])
w = np.linspace(0, 24, 241)

df = DF(calc='Al1.gpw', q=q, w=w, eta=0.2, ecut=50)
df1, df2 = df.get_dielectric_function()
#df.write('Al.pckl')
df.get_EELS_spectrum(df1, df2,filename='EELS_Al_1')

atoms = Atoms('Al8',scaled_positions=[(0,0,0),
                               (0.5,0,0),
                               (0,0.5,0),
                               (0,0,0.5),
                               (0.5,0.5,0),
                               (0.5,0,0.5),
                               (0.,0.5,0.5),
                               (0.5,0.5,0.5)],
              cell=[(0,a,a),(a,0,a),(a,a,0)],
              pbc=True)

calc = GPAW(gpts=(24,24,24),
            kpts=(2,2,2),
            xc='LDA')
示例#16
0
            convergence={'bands':60}, # It's better NOT to converge all bands. 
            eigensolver='cg',         # It's preferable to use 'cg' to calculate unoccupied states.
            occupations=FermiDirac(0.05),
            txt='out_gs.txt')

atoms.set_calculator(calc)       
atoms.get_potential_energy()          
calc.write('graphite.gpw','all')

# Part 2: Spectra calculations            
f = paropen('graphite_q_list', 'w')     # Write down q.

for i in range(1,8):                    # Loop over different q.   
    df = DF(calc='graphite.gpw',       
            nbands=60,                  # Use only bands that are converged in the gs calculation.
            q=np.array([i/20., 0., 0.]),      # Gamma - M excitation
            #q=np.array([i/20., -i/20., 0.])  # Gamma - K excitation
            w=np.linspace(0, 40, 401),  # Spectra from 0-40 eV with 0.1 eV spacing.
            eta=0.2,                    # Broadening parameter.
            ecut=40+(i-1)*10,           # In general, larger q requires larger planewave cutoff energy.       # 
            txt='out_df_%d.txt' %(i))   # Write differnt output for different q.

    df1, df2 = df.get_dielectric_function()
    df.get_EELS_spectrum(df1, df2, filename='graphite_EELS_%d' %(i)) # Use different filenames for different q
    df.check_sum_rule(df1, df2)         # Check f-sum rule.

    print >> f, sqrt(np.inner(df.qq_v / Bohr, df.qq_v / Bohr))



示例#17
0
                convergence={'bands':nband},
                eigensolver = 'cg',
                width=0.1)
    atoms.set_calculator(calc)
    atoms.get_potential_energy()

if EELS:

    for i in range(1, 2):
        w = np.linspace(0, 15, 301)
        q = np.array([-i/64., i/64., 0.]) # Gamma - K
	ecut = 40 + i*10
        df = DF(calc=calc, q=q, w=w, eta=0.05, ecut = ecut,
                      txt='df_' + str(i) + '.out')  
        df.get_surface_response_function(z0=21.2/2, filename='be_EELS')  
        df.get_EELS_spectrum()    
        df.check_sum_rule()
        df.write('df_' + str(i) + '.pckl')

if check:
    d = np.loadtxt('be_EELS')

    wpeak1 = 2.50 # eV
    wpeak2 = 9.95
    Nw1 = 50
    Nw2 = 199

    if (d[Nw1, 1] > d[Nw1-1, 1] and d[Nw1, 1] > d[Nw1+1, 1] and  
       d[Nw2, 1] > d[Nw2-1, 1] and d[Nw2, 1] > d[Nw2+1, 1]):
        pass
    else: