Exemple #1
0
def check_df(name, ref_energy, ref_loss, ref_energy_lfe, ref_loss_lfe,
             **kwargs_override):
    kwargs = dict(calc=calc, frequencies=w.copy(), eta=0.5, ecut=30,
                  txt='df.%s.txt' % name)
    kwargs.update(kwargs_override)
    df = DielectricFunction(**kwargs)
    fname = 'dfdump.%s.dat' % name
    df.get_eels_spectrum('RPA',q_c=q,filename=fname)
    world.barrier()
    d = np.loadtxt(fname,delimiter=',')

    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)
def check_df(name, ref_energy, ref_loss, ref_energy_lfe, ref_loss_lfe, **kwargs_override):
    kwargs = dict(calc=calc, frequencies=w.copy(), eta=0.5, ecut=30, txt="df.%s.txt" % name)
    kwargs.update(kwargs_override)
    df = DielectricFunction(**kwargs)
    fname = "dfdump.%s.dat" % name
    df.get_eels_spectrum("RPA", q_c=q, filename=fname)
    world.barrier()
    d = np.loadtxt(fname, delimiter=",")

    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)
atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('Al', 'all')
t2 = time.time()

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

df = DielectricFunction(calc='Al',
                        frequencies=w,
                        eta=0.2,
                        ecut=50,
                        hilbert=False)
df.get_eels_spectrum(xc='ALDA', filename='EELS_Al_ALDA', q_c=q)
#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')

world.barrier()
d = np.loadtxt('EELS_Al_ALDA', delimiter=',')
# New results are compared with test values
wpeak1, Ipeak1 = findpeak(d[:, 0], d[:, 1])
wpeak2, Ipeak2 = findpeak(d[:, 0], d[:, 2])

test_wpeak1 = 15.4929666813  # eV
            mixer=Mixer(0.1,3),
            kpts=(4,4,4),
            parallel={'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 = DielectricFunction(calc=calc, frequencies=w, eta=0.2, ecut=50)
eels_NLFC_w, eels_LFC_w = df.get_eels_spectrum(filename='EELS_Al', q_c=q)
df_NLFC_w, df_LFC_w = df.get_dielectric_function(q_c=q)


df.check_sum_rule(spectrum=np.imag(df_NLFC_w))
df.check_sum_rule(spectrum=np.imag(df_LFC_w))

df.check_sum_rule(spectrum=eels_NLFC_w)
df.check_sum_rule(spectrum=eels_LFC_w)
#df.write('Al.pckl')

t3 = time.time()

print('')
print('For ground  state calc, it took', (t2 - t1) / 60, 'minutes')
print('For excited state calc, it took', (t3 - t2) / 60, 'minutes')
Exemple #5
0
calc.set(kpts=(20, 20, 7), fixdensity=True)
atoms.get_potential_energy()

# The result should also be converged with respect to bands:
calc.diagonalize_full_hamiltonian(nbands=60)
calc.write('graphite.gpw', 'all')

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

for i in range(1, 6):  # loop over different q
    df = DielectricFunction(
        calc='graphite.gpw',
        domega0=0.01,
        eta=0.2,  # Broadening parameter.
        ecut=100,
        # write different output for different q:
        txt='out_df_%d.txt' % i)

    q_c = [i / 20.0, 0.0, 0.0]  # Gamma - M excitation

    df.get_eels_spectrum(q_c=q_c, filename='graphite_EELS_%d' % i)

    # Calculate cartesian momentum vector:
    cell_cv = atoms.get_cell()
    bcell_cv = 2 * np.pi * np.linalg.inv(cell_cv).T
    q_v = np.dot(q_c, bcell_cv)
    print(sqrt(np.inner(q_v, q_v)), file=f)

f.close()
            parallel={'band':1},
            idiotproof=False,  # allow uneven distribution of k-points
            xc='LDA')

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

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

df = DielectricFunction(calc='Al', frequencies=w, eta=0.2, ecut=50,
                        hilbert=False)
df.get_eels_spectrum(xc='RPA', filename='EELS_Al', q_c=q)
#df.check_sum_rule()
#df.write('Al.pckl')

t3 = time.time()

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

world.barrier()
d = np.loadtxt('EELS_Al',delimiter=',')

# New results are compared with test values
wpeak1,Ipeak1 = findpeak(d[:,0],d[:,1])
wpeak2,Ipeak2 = findpeak(d[:,0],d[:,2])
from gpaw import GPAW
from gpaw.response.df import DielectricFunction

calc = GPAW("Ag_GLLBSC.gpw")
calc.diagonalize_full_hamiltonian(nbands=30)
calc.write("Ag_GLLBSC_full.gpw", "all")

# Set up dielectric function:
df = DielectricFunction(calc="Ag_GLLBSC_full.gpw", domega0=0.05)  # Ground state input  # energy grid spacing at omega=0

# Momentum transfer, must be the difference between two kpoints!
q_c = [1.0 / 10, 0, 0]
df.get_eels_spectrum(q_c=q_c)  # a file called 'eels.csv' is generated

# Plot spectrum
import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt("eels.csv", delimiter=",")
omega = data[:, 0]
eels = data[:, 2]
plt.plot(omega, eels)
plt.xlabel("Energy (eV)")
plt.ylabel("Loss spectrum")
plt.xlim(0, 20)
plt.show()
Exemple #8
0
# atoms.get_potential_energy()

# The result should also be converged with respect to bands:
calc.diagonalize_full_hamiltonian(nbands=60)
calc.write('caf2.gpw', 'all')

# Part 2: Spectra calculations
f = paropen(output_folder + '/caf2_q_list', 'w')  # write q

for i in range(1, 6):  # loop over different q
    df = DielectricFunction(
        calc='caf2.gpw',
        domega0=0.01,
        eta=0.2,  # Broadening parameter.
        ecut=100,
        # write different output for different q:
        txt='%s/out_df_%d.txt' % (output_folder, i))

    q_c = [i / 20.0, 0.0, 0.0]  # Gamma - M excitation

    df.get_eels_spectrum(q_c=q_c,
                         filename='%s/caf2_EELS_%d' % (output_folder, i))

    # Calculate cartesian momentum vector:
    cell_cv = atoms.get_cell()
    bcell_cv = 2 * np.pi * np.linalg.inv(cell_cv).T
    q_v = np.dot(q_c, bcell_cv)
    print(sqrt(np.inner(q_v, q_v)), file=f)

f.close()
calc.set(kpts=(20, 20, 7), fixdensity=True)
atoms.get_potential_energy()

# The result should also be converged with respect to bands:
calc.diagonalize_full_hamiltonian(nbands=60)
calc.write('graphite.gpw', 'all')

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

for i in range(1, 6):  # loop over different q
    df = DielectricFunction(calc='graphite.gpw',
                            domega0=0.01,
                            eta=0.2,  # Broadening parameter.
                            ecut=100,
                            # write different output for different q:
                            txt='out_df_%d.txt' % i)

    q_c = [i / 20.0, 0.0, 0.0]  # Gamma - M excitation
    
    df.get_eels_spectrum(q_c=q_c, filename='graphite_EELS_%d' % i)

    # Calculate cartesian momentum vector:
    cell_cv = atoms.get_cell()
    bcell_cv = 2 * np.pi * np.linalg.inv(cell_cv).T
    q_v = np.dot(q_c, bcell_cv)
    print(sqrt(np.inner(q_v, q_v)), file=f)

f.close()
Exemple #10
0
atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write('Al', 'all')
t2 = time.time()

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

df = DielectricFunction(calc='Al',
                        frequencies=w,
                        eta=0.2,
                        ecut=50,
                        hilbert=False)
df.get_eels_spectrum(xc='RPA', filename='EELS_Al', q_c=q)

t3 = time.time()

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

world.barrier()
d = np.loadtxt('EELS_Al', delimiter=',')

# New results are compared with test values
wpeak1, Ipeak1 = findpeak(d[:, 0], d[:, 1])
wpeak2, Ipeak2 = findpeak(d[:, 0], d[:, 2])

test_wpeak1 = 15.7064968875  # eV
Exemple #11
0
from ase.build import bulk
from gpaw import GPAW
from gpaw.response.df import DielectricFunction

# Part 1: Ground state calculation
atoms = bulk('Al', 'fcc', a=4.043)  # generate fcc crystal structure
# GPAW calculator initialization:
k = 13
calc = GPAW(mode='pw', kpts=(k, k, k))

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 = DielectricFunction(calc='Al.gpw')  # ground state gpw file as input

# Momentum transfer, must be the difference between two kpoints:
q_c = [1.0 / k, 0, 0]
df.get_eels_spectrum(q_c=q_c)  # by default, an 'eels.csv' file is generated
import numpy as np
from ase.lattice import bulk
from gpaw import GPAW
from gpaw.response.df import DielectricFunction

# Part 1: Ground state calculation
atoms = bulk('Al', 'fcc', a=4.043)      # Generate fcc crystal structure for aluminum
calc = GPAW(mode='pw',                  # GPAW calculator initialization
            kpts={'density': 5.0, 'gamma': True})

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 = DielectricFunction(calc='Al.gpw')  # Ground state gpw file as input

q_c = [1.0 / 13, 0, 0]          # Momentum transfer, must be the difference between two kpoints !
df.get_eels_spectrum(q_c=q_c)           # By default, a file called 'eels.csv' is generated
Exemple #13
0
              valence_bands=range(4),
              conduction_bands=range(4),
              mode='RPA',
              nbands=4,
              ecut=ecut,
              write_h=False,
              write_v=False,
              )
    bse_w = bse.get_eels_spectrum(filename=None,
                                  q_c=q_c,
                                  w_w=w_w,
                                  eta=eta)[1]
    
if df:
    df = DielectricFunction(calc='Al.gpw',
                            frequencies=w_w,
                            eta=eta,
                            ecut=ecut,
                            hilbert=False)
    df_w = df.get_eels_spectrum(q_c=q_c, filename=None)[1]

if check_spectrum:
    w_ = 15.1423
    I_ = 25.4359
    wbse, Ibse = findpeak(w_w, bse_w)
    wdf, Idf = findpeak(w_w, df_w)
    equal(wbse, w_, 0.01)
    equal(wdf, w_, 0.01)
    equal(Ibse, I_, 0.1)
    equal(Idf, I_, 0.1)
            parallel={'band':1},
            idiotproof=False,  # allow uneven distribution of k-points
            xc='LDA')

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

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

df = DielectricFunction(calc='Al', frequencies=w, eta=0.2, ecut=50,
                        hilbert=False)
df.get_eels_spectrum(xc='ALDA', filename='EELS_Al_ALDA',q_c=q)
#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'

world.barrier()
d = np.loadtxt('EELS_Al_ALDA',delimiter=',')
# New results are compared with test values
wpeak1,Ipeak1 = findpeak(d[:,0],d[:,1])
wpeak2,Ipeak2 = findpeak(d[:,0],d[:,2])

test_wpeak1 = 15.4929666813 # eV