Example #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)
Example #2
0
    def full_static_screened_interaction(self):
        """Calcuate W_GG(q)"""
        W_qGG = np.zeros((self.nibzq, self.npw, self.npw), dtype=complex)

        t0 = time()
        for iq in range(self.nibzq):
            q = self.ibzq_qc[iq]
            optical_limit = False
            if np.abs(q).sum() < 1e-8:
                q = self.q_c.copy()
                optical_limit = True
            df = DF(calc=self.calc,
                    q=q,
                    w=(0.,),
                    optical_limit=optical_limit,
                    nbands=self.nbands,
                    hilbert_trans=False,
                    eta=0.0001,
                    ecut=self.ecut*Hartree,
                    xc='RPA',
                    txt='df.out')
            df.initialize()
            df.calculate()

            if optical_limit:
                K_GG = self.V_qGG[iq].copy()
                q_v = np.dot(q, self.bcell_cv)
                K0 = calculate_Kc(q,
                                  self.Gvec_Gc,
                                  self.acell_cv,
                                  self.bcell_cv,
                                  self.pbc,
                                  vcut=self.vcut)[0,0]

                for iG in range(1,self.npw):
                    K_GG[0, iG] = self.V_qGG[iq, iG, iG]**0.5 * K0**0.5
                    K_GG[iG, 0] = self.V_qGG[iq, iG, iG]**0.5 * K0**0.5
                K_GG[0,0] = K0
                df_GG = np.eye(self.npw, self.npw) - K_GG*df.chi0_wGG[0]
            else:
                df_GG = np.eye(self.npw, self.npw) - self.V_qGG[iq]*df.chi0_wGG[0]
            dfinv_GG = np.linalg.inv(df_GG)
            
            if optical_limit:
                eps = 1/dfinv_GG[0,0]
                self.printtxt('    RPA macroscopic dielectric constant is: %3.3f' %  eps.real)
            W_qGG[iq] = dfinv_GG * self.V_qGG[iq]
            self.timing(iq, t0, self.nibzq, 'iq')
            
        if rank == 0:
            if self.kernel_file is not None:
                data = {'W_qGG': W_qGG}
                name = self.kernel_file+'.pckl'
                pickle.dump(data, open(name, 'w'), -1)
        
        return W_qGG
Example #3
0
    def initialize_calculation(self, w, ecut, nbands, kcommsize, extrapolate):
        
        dummy = DF(calc=self.calc,
                   eta=0.0,
                   w=w * 1j,
                   q=[0.,0.,0.],
                   ecut=ecut,
                   hilbert_trans=False,
                   kcommsize=kcommsize)
        dummy.txt = devnull
        dummy.spin = 0
        dummy.initialize()

        if nbands is None:
            nbands = dummy.npw
        self.nbands = nbands
        
        print >> self.txt, 'Planewave cut off            : %s eV' % ecut
        print >> self.txt, 'Number of Planewaves         : %s' % dummy.npw
        print >> self.txt, 'Response function bands      : %s' % nbands
        print >> self.txt, 'Frequency range              : %s - %s eV' % (w[0], w[-1])
        print >> self.txt, 'Number of frequency points   : %s' % len(w)
        if extrapolate:
            print >> self.txt, 'Extrapolation of frequencies : Squared Lorentzian'
        print >> self.txt
        print >> self.txt, 'Parallelization scheme'
        print >> self.txt, '     Total cpus         : %d' % dummy.comm.size
        if dummy.nkpt == 1:
            print >> self.txt, '     Band parsize       : %d' % dummy.kcomm.size
        else:
            print >> self.txt, '     Kpoint parsize     : %d' % dummy.kcomm.size
        print >> self.txt, '     Frequency parsize  : %d' % dummy.wScomm.size
        print >> self.txt, 'Memory usage estimate'
        print >> self.txt, '     chi0_wGG(Q)        : %f M / cpu' % (dummy.Nw_local *
                                                                     dummy.npw**2 * 16.
                                                                    / 1024**2)
        print >> self.txt
        del dummy
Example #4
0
    def initialize_calculation(self, w, ecut, nbands, kcommsize, extrapolate):

        dummy = DF(calc=self.calc,
                   eta=0.0,
                   w=w * 1j,
                   q=[0., 0., 0.],
                   ecut=ecut,
                   hilbert_trans=False,
                   kcommsize=kcommsize)
        dummy.txt = devnull
        dummy.spin = 0
        dummy.initialize()

        if nbands is None:
            nbands = dummy.npw
        self.nbands = nbands

        print >> self.txt, 'Planewave cut off            : %s eV' % ecut
        print >> self.txt, 'Number of Planewaves         : %s' % dummy.npw
        print >> self.txt, 'Response function bands      : %s' % nbands
        print >> self.txt, 'Frequency range              : %s - %s eV' % (
            w[0], w[-1])
        print >> self.txt, 'Number of frequency points   : %s' % len(w)
        if extrapolate:
            print >> self.txt, 'Extrapolation of frequencies : Squared Lorentzian'
        print >> self.txt
        print >> self.txt, 'Parallelization scheme'
        print >> self.txt, '     Total cpus         : %d' % dummy.comm.size
        if dummy.nkpt == 1:
            print >> self.txt, '     Band parsize       : %d' % dummy.kcomm.size
        else:
            print >> self.txt, '     Kpoint parsize     : %d' % dummy.kcomm.size
        print >> self.txt, '     Frequency parsize  : %d' % dummy.wScomm.size
        print >> self.txt, 'Memory usage estimate'
        print >> self.txt, '     chi0_wGG(Q)        : %f M / cpu' % (
            dummy.Nw_local * dummy.npw**2 * 16. / 1024**2)
        print >> self.txt
        del dummy
    def E_q(self,
            q,
            index=None,
            direction=0,
            integrated=True):

        if abs(np.dot(q, q))**0.5 < 1.e-5:
            q = [0.,0.,0.]
            q[direction] = 1.e-5
            optical_limit = True
        else:
            optical_limit = False

        dummy = DF(calc=self.calc,
                   eta=0.0,
                   w=self.w * 1j,
                   q=q,
                   ecut=self.ecut,
                   G_plus_q=True,
                   optical_limit=optical_limit,
                   hilbert_trans=False)
        dummy.txt = devnull
        dummy.initialize(simple_version=True)
        npw = dummy.npw
        del dummy

        if self.nbands is None:
            nbands = npw
        else:
            nbands = self.nbands

        if self.txt is sys.stdout:
            txt = 'response.txt'
        else:
            txt='response_'+self.txt.name
        df = DF(calc=self.calc,
                xc=None,
                nbands=nbands,
                eta=0.0,
                q=q,
                txt=txt,
                vcut=self.vcut,
                w=self.w * 1j,
                ecut=self.ecut,
                G_plus_q=True,
                kcommsize=self.kcommsize,
                comm=self.dfcomm,
                optical_limit=optical_limit,
                hilbert_trans=False)

        if index is None:
            print >> self.txt, 'Calculating KS response function at:'
        else:
            print >> self.txt, '#', index, \
                  '- Calculating KS response function at:'
        if optical_limit:
            print >> self.txt, 'q = [0 0 0] -', 'Polarization: ', direction
        else:
            print >> self.txt, 'q = [%1.6f %1.6f %1.6f] -' \
                  % (q[0],q[1],q[2]), '%s planewaves' % npw

        e_wGG = df.get_dielectric_matrix(xc='RPA', overwritechi0=True)
        df.chi0_wGG = None
        Nw_local = len(e_wGG)
        local_E_q_w = np.zeros(Nw_local, dtype=complex)
        E_q_w = np.empty(len(self.w), complex)
        for i in range(Nw_local):
            local_E_q_w[i] = (np.log(np.linalg.det(e_wGG[i]))
                              + len(e_wGG[0]) - np.trace(e_wGG[i]))
            #local_E_q_w[i] = (np.sum(np.log(np.linalg.eigvals(e_wGG[i])))
            #                  + len(e_wGG[0]) - np.trace(e_wGG[i]))
        df.wcomm.all_gather(local_E_q_w, E_q_w)
        del df
        
        if self.gauss_legendre is not None:
            E_q = np.sum(E_q_w * self.gauss_weights * self.transform) \
                  / (4*np.pi)
        else:   
            dws = self.w[1:] - self.w[:-1]
            E_q = np.dot((E_q_w[:-1] + E_q_w[1:])/2., dws) / (2.*np.pi)


        print >> self.txt, 'E_c(q) = %s eV' % E_q.real
        print >> self.txt

        if integrated:
            return E_q.real
        else:
            return E_q_w.real               
Example #6
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))
Example #7
0
              nc=[0,4],
              coupling=True,
              mode='RPA',
              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)
    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 ! ')
Example #8
0
# GS Calculation One
a = 6.75 * Bohr
atoms = bulk("C", "diamond", a=a)

calc = GPAW(h=0.2, eigensolver=RMM_DIIS(), mixer=Mixer(0.1, 3), kpts=(4, 4, 4), occupations=FermiDirac(0.001))

atoms.set_calculator(calc)
atoms.get_potential_energy()
calc.write("C.gpw", "all")

# Macroscopic dielectric constant calculation
q = np.array([0.0, 0.00001, 0.0])
w = np.linspace(0, 24.0, 241)

df = DF(calc="C.gpw", q=q, w=(0.0,), eta=0.001, ecut=50, hilbert_trans=False, optical_limit=True)
eM1, eM2 = df.get_macroscopic_dielectric_constant()

eM1_ = 6.15176021  # 6.15185095143 for dont use time reversal symmetry
eM2_ = 6.04805705  # 6.04815084635

if np.abs(eM1 - eM1_) > 1e-5 or np.abs(eM2 - eM2_) > 1e-5:
    print eM1, eM2
    raise ValueError("Macroscopic dielectric constant not correct ! ")


# Absorption spectrum calculation
del df
df = DF(calc="C.gpw", q=q, w=w, eta=0.25, ecut=50, optical_limit=True, txt="C_df.out")
df.get_absorption_spectrum()
df.check_sum_rule()
Example #9
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))



Example #10
0
                occupations=FermiDirac(0.001),
                convergence={'bands': 70})
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    calc.write('si.gpw', 'all')

if ABS:

    w = np.linspace(0, 24, 481)
    q = np.array([0.0, 0.00001, 0.])

    # getting macroscopic constant
    df = DF(calc='si.gpw',
            q=q,
            w=(0., ),
            eta=0.0001,
            hilbert_trans=False,
            txt='df_1.out',
            ecut=150,
            optical_limit=True)

    df1, df2 = df.get_dielectric_function()
    eM1, eM2 = df.get_macroscopic_dielectric_constant(df1, df2)

    df.write('df_1.pckl')

    if np.abs(eM1 - 13.992277) > 1e-4 or np.abs(eM2 - 12.589596) > 1e-4:
        print eM1, eM2
        raise ValueError('Pls check dielectric constant !')

    #getting absorption spectrum
    df = DF(calc='si.gpw',
Example #11
0
            kpts=(4,4,4),
            mode='lcao',
            basis='dzp',
            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
Example #12
0
            nbands=70,                # The result should also be converged with respect to bands.
            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.

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

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



Example #13
0
                nbands=nband+5,
                parallel={'domain':1,
                          'band':1},
                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]):
Example #14
0
atoms = bulk('C', 'diamond', a=a)

calc = GPAW(h=0.2, kpts=(4, 4, 4), occupations=FermiDirac(0.001))

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

# Macroscopic dielectric constant calculation
q = np.array([0.0, 0.00001, 0.])
w = np.linspace(0, 24., 241)

df = DF(calc='C.gpw',
        q=q,
        w=(0., ),
        eta=0.001,
        ecut=50,
        hilbert_trans=False,
        optical_limit=True)
df1, df2 = df.get_dielectric_function()
eM1, eM2 = df.get_macroscopic_dielectric_constant(df1, df2)

eM1_ = 6.15185095143
eM2_ = 6.04815084635

if (np.abs(eM1 - eM1_) > 1e-5 or np.abs(eM2 - eM2_) > 1e-5):
    print eM1, eM2
    raise ValueError('Macroscopic dielectric constant not correct ! ')

# Absorption spectrum calculation
df = DF(calc='C.gpw',
    def get_C6_coefficient(self,
                           ecut=100.,
                           nbands=None,
                           kcommsize=None,
                           gauss_legendre=None,
                           frequency_cut=None,
                           frequency_scale=None,
                           direction=2):

        self.initialize_calculation(None,
                                    ecut,
                                    nbands,
                                    kcommsize,
                                    gauss_legendre,
                                    frequency_cut,
                                    frequency_scale)

        d = direction
        d_pro = []
        for i in range(3):
            if i != d:
                d_pro.append(i)
        
        dummy = DF(calc=self.calc,
                   eta=0.0,
                   w=self.w * 1j,
                   ecut=self.ecut,
                   hilbert_trans=False)
        dummy.txt = devnull
        dummy.initialize(simple_version=True)
        npw = dummy.npw
        del dummy

        q = [0.,0.,0.]
        q[d] = 1.e-5

        if self.nbands is None:
            nbands = npw
        else:
            nbands = self.nbands

        if self.txt is sys.stdout:
            txt = 'response.txt'
        else:
            txt='response_'+self.txt.name
        df = DF(calc=self.calc,
                xc=None,
                nbands=nbands,
                eta=0.0,
                q=q,
                txt=txt,
                vcut=self.vcut,
                w=self.w * 1j,
                ecut=self.ecut,
                comm=world,
                optical_limit=True,
                G_plus_q=True,
                kcommsize=self.kcommsize,
                hilbert_trans=False)
        
        print >> self.txt, 'Calculating RPA response function'
        print >> self.txt, 'Polarization: %s' % d

        chi_wGG = df.get_chi(xc='RPA')
        chi0_wGG = df.chi0_wGG

        Nw_local = len(chi_wGG)
        local_a0_w = np.zeros(Nw_local, dtype=complex)
        a0_w = np.empty(len(self.w), complex)
        local_a_w = np.zeros(Nw_local, dtype=complex)
        a_w = np.empty(len(self.w), complex)

        Gvec_Gv = np.dot(df.Gvec_Gc + np.array(q), df.bcell_cv)
        gd = self.calc.density.gd
        n_d = gd.get_size_of_global_array()[d]
        d_d = gd.get_grid_spacings()[d]
        r_d = np.array([i*d_d for i in range(n_d)])

        print >> self.txt, 'Calculating real space integrals'

        int_G = np.zeros(npw, complex)
        for iG in range(npw):
            if df.Gvec_Gc[iG, d_pro[0]] == 0 and df.Gvec_Gc[iG, d_pro[1]] == 0:
                int_G[iG] = np.sum(r_d * np.exp(1j*Gvec_Gv[iG, d] * r_d))*d_d
        int2_GG = np.outer(int_G, int_G.conj())

        print >> self.txt, 'Calculating dynamic polarizability'

        for i in range(Nw_local):
            local_a0_w[i] = np.trace(np.dot(chi0_wGG[i], int2_GG))
            local_a_w[i] = np.trace(np.dot(chi_wGG[i], int2_GG))
        df.wcomm.all_gather(local_a0_w, a0_w)
        df.wcomm.all_gather(local_a_w, a_w)

        A = df.vol / gd.cell_cv[d,d]
        a0_w *= A**2 / df.vol
        a_w *= A**2 / df.vol

        del df
        
        C06 = np.sum(a0_w**2 * self.gauss_weights
                     * self.transform) * 3 / (2*np.pi)
        C6 = np.sum(a_w**2 * self.gauss_weights
                    * self.transform) * 3 / (2*np.pi)

        print >> self.txt, 'C06 = %s Ha*Bohr**6' % (C06.real / Ha)
        print >> self.txt, 'C6 = %s Ha*Bohr**6' % (C6.real / Ha)
        print >> self.txt

        return C6.real / Ha, C06.real / Ha
Example #16
0
              h=0.15,
              mode='lcao',
              basis='dzp',
              occupations=FermiDirac(0.01),
              stencils=(3,3))
    
    cluster.set_calculator(calc)
    cluster.get_potential_energy()
    calc.write('Au02.gpw','all')


if ABS:
    df = DF(calc='Au02.gpw', 
            q=np.array([0.0, 0.0, 0.00001]), 
            w=np.linspace(0,14,141),
            eta=0.1,
            ecut=10,
            optical_limit=True,
            kcommsize=4)              

    df.get_absorption_spectrum()             

    d = np.loadtxt('Absorption.dat')
    wpeak = 2.5 # eV
    Nw = 25
    if d[Nw, 4] > d[Nw-1, 4] and d[Nw, 4] > d[Nw+1, 4]:
        pass
    else:
        raise ValueError('Plasmon peak not correct ! ')
    
    if np.abs(d[Nw, 4] - 0.25788817927) > 5e-5:
Example #17
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
Example #18
0
import numpy as np
from gpaw import GPAW
from gpaw.response.df import DF

w = np.linspace(0, 24., 481)    # 0-24 eV with 0.05 eV spacing
q = np.array([0.0, 0.00001, 0.])

df = DF(calc='si.gpw',
        q=q,
        w=w,
        eta=0.1,           # Broadening parameter 
        ecut=150,          # Energy cutoff for planewaves
        optical_limit=True,
        txt='df_2.out')    # Output text

df1, df2 = df.get_dielectric_function()
df.get_absorption_spectrum(df1, df2, filename='si_abs.dat')
df.check_sum_rule(df1, df2)
df.write('df_2.pckl')      # Save important parameters and data 
Example #19
0
        nbands=nband + 5,
        parallel={"domain": 1, "band": 1},
        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]
Example #20
0
    def get_E_q(self,
                kcommsize=1,
                index=None,
                q=[0., 0., 0.],
                integrated=True,
                ecut=10,
                nbands=None,
                w=np.linspace(0, 200., 32),
                extrapolate=True):

        if index is None:
            self.initialize_calculation(w, ecut, nbands, kcommsize,
                                        extrapolate)

        if abs(q[0]) < 0.001 and abs(q[1]) < 0.001 and abs(q[2]) < 0.001:
            q = [1.e-5, 0., 0.]
            optical_limit = True
        else:
            optical_limit = False

        df = DF(calc=self.calc,
                nbands=self.nbands,
                eta=0.0,
                q=q,
                w=w * 1j,
                ecut=ecut,
                kcommsize=kcommsize,
                optical_limit=optical_limit,
                hilbert_trans=False)
        df.txt = devnull

        if index is None:
            print >> self.txt, 'Calculating RPA dielectric matrix at:'
        else:
            print >> self.txt, '#', index, '- Calculating RPA dielectric matrix at:'

        if optical_limit:
            print >> self.txt, 'Q = [0 0 0]'
        else:
            print >> self.txt, 'Q = %s' % q

        e_wGG = df.get_RPA_dielectric_matrix()

        Nw_local = len(e_wGG)
        local_E_q_w = np.zeros(Nw_local, dtype=complex)

        E_q_w = np.empty(len(w), complex)
        for i in range(Nw_local):
            local_E_q_w[i] = (np.log(np.linalg.det(e_wGG[i])) + len(e_wGG[0]) -
                              np.trace(e_wGG[i]))
            #local_E_q_w[i] = (np.sum(np.log(np.linalg.eigvals(e_wGG[i])))
            #                  + self.npw - np.trace(e_wGG[i]))
        df.wcomm.all_gather(local_E_q_w, E_q_w)
        del df
        del e_wGG
        dw = w[1] - w[0]
        E_q = dw * np.sum((E_q_w[:-1] + E_q_w[1:]) / 2.) / (2. * np.pi)
        if extrapolate:
            print
            '''Fit tail to: Eq(w) = A**2/((w-B)**2 + C)**2'''
            e1 = abs(E_q_w[-1])**0.5
            e2 = abs(E_q_w[-2])**0.5
            e3 = abs(E_q_w[-3])**0.5
            w1 = w[-1]
            w2 = w[-2]
            w3 = w[-3]
            B = (((e3 * w3**2 - e1 * w1**2) / (e1 - e3) -
                  (e2 * w2**2 - e1 * w1**2) / (e1 - e2)) /
                 ((2 * w3 * e3 - 2 * w1 * e1) / (e1 - e3) -
                  (2 * w2 * e2 - 2 * w1 * e1) / (e1 - e2)))
            C = ((w2 - B)**2 * e2 - (w1 - B)**2 * e1) / (e1 - e2)
            A = e1 * ((w1 - B)**2 + C)
            if C > 0:
                E_q -= A**2 * (np.pi / (4 * C**1.5) - (w1 - B) /
                               ((w1 - B)**2 + C) / (2 * C) - np.arctan(
                                   (w1 - B) / C**0.5) /
                               (2 * C**1.5)) / (2 * np.pi)
            else:
                E_q += A**2 * ((w1 - B) / ((w1 - B)**2 + C) / (2 * C) + np.log(
                    (w1 - B - abs(C)**0.5) / (w1 - B + abs(C)**0.5)) /
                               (4 * C * abs(C)**0.5)) / (2 * np.pi)

        print >> self.txt, 'E_c(Q) = %s eV' % E_q.real
        print >> self.txt
        if index is None:
            print >> self.txt, 'Calculation completed at:  ', ctime()
            print >> self.txt
            print >> self.txt, '------------------------------------------------------'
        if integrated:
            return E_q
        else:
            return E_q_w
Example #21
0
atoms.center()
calc = GPAW(gpts=(12,12,12),
            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),
Example #22
0
    def get_E_q(self,
                kcommsize=1,
                index=None,
                q=[0., 0., 0.],
                integrated=True,
                ecut=10,
                nbands=None,
                w=np.linspace(0, 200., 32),
                extrapolate=True):
        
        if index is None:
            self.initialize_calculation(w, ecut, nbands, kcommsize, extrapolate)

        if abs(q[0]) < 0.001 and abs(q[1]) < 0.001 and abs(q[2]) < 0.001:
            q = [1.e-5, 0., 0.]
            optical_limit = True
        else:
            optical_limit = False
            
        df = DF(calc=self.calc,
                nbands=self.nbands,
                eta=0.0,
                q=q,
                w=w * 1j,
                ecut=ecut,
                kcommsize=kcommsize,
                optical_limit=optical_limit,
                hilbert_trans=False)
        df.txt = devnull

        if index is None:
            print >> self.txt, 'Calculating RPA dielectric matrix at:'
        else:
            print >> self.txt, '#', index, '- Calculating RPA dielectric matrix at:'
        
        if optical_limit:
            print >> self.txt, 'Q = [0 0 0]'
        else:
            print >> self.txt, 'Q = %s' % q 
            
        e_wGG = df.get_RPA_dielectric_matrix()

        Nw_local = len(e_wGG)
        local_E_q_w = np.zeros(Nw_local, dtype=complex)

        E_q_w = np.empty(len(w), complex)
        for i in range(Nw_local):
            local_E_q_w[i] = (np.log(np.linalg.det(e_wGG[i]))
                              + len(e_wGG[0]) - np.trace(e_wGG[i]))
            #local_E_q_w[i] = (np.sum(np.log(np.linalg.eigvals(e_wGG[i])))
            #                  + self.npw - np.trace(e_wGG[i]))
        df.wcomm.all_gather(local_E_q_w, E_q_w)
        del df
        del e_wGG
        dw = w[1] - w[0]
        E_q = dw * np.sum((E_q_w[:-1] + E_q_w[1:])/2.) / (2.*np.pi)
        if extrapolate:
            print
            '''Fit tail to: Eq(w) = A**2/((w-B)**2 + C)**2'''
            e1 = abs(E_q_w[-1])**0.5
            e2 = abs(E_q_w[-2])**0.5
            e3 = abs(E_q_w[-3])**0.5
            w1 = w[-1]
            w2 = w[-2]
            w3 = w[-3]
            B = (((e3*w3**2-e1*w1**2)/(e1-e3) - (e2*w2**2-e1*w1**2)/(e1-e2))
                 / ((2*w3*e3-2*w1*e1)/(e1-e3) - (2*w2*e2-2*w1*e1)/(e1-e2)))
            C = ((w2-B)**2*e2 - (w1-B)**2*e1)/(e1-e2)
            A = e1*((w1-B)**2+C)
            if C > 0:
                E_q -= A**2*(np.pi/(4*C**1.5)
                             - (w1-B)/((w1-B)**2+C)/(2*C)
                             - np.arctan((w1-B)/C**0.5)/(2*C**1.5)) / (2*np.pi)
            else:
                E_q += A**2*((w1-B)/((w1-B)**2+C)/(2*C)
                             + np.log((w1-B-abs(C)**0.5)/(w1-B+abs(C)**0.5))
                             /(4*C*abs(C)**0.5)) / (2*np.pi)
                

        print >> self.txt, 'E_c(Q) = %s eV' % E_q.real
        print >> self.txt
        if index is None:
            print >> self.txt, 'Calculation completed at:  ', ctime()
            print >> self.txt
            print >> self.txt, '------------------------------------------------------'
        if integrated:
            return E_q
        else:
            return E_q_w
Example #23
0
            basis='dzp',
            xc='LDA')

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
Example #24
0
        'domain': 1,
        'band': 1
    },
    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:
Example #25
0
    def screened_interaction_kernel(self, iq):
        """Calcuate W_GG(w) for a given q.
        if static: return W_GG(w=0)
        is not static: return W_GG(q,w) - Vc_GG
        """

        q = self.ibzq_qc[iq]
        w = self.w_w.copy()*Hartree

        optical_limit = False
        if np.abs(q).sum() < 1e-8:
            q = np.array([1e-12, 0, 0]) # arbitrary q, not really need to be calculated
            optical_limit = True

        hilbert_trans = True
        if self.ppa or self.static:
            hilbert_trans = False

        df = DF(calc=self.calc, q=q.copy(), w=w, nbands=self.nbands, eshift=None,
                optical_limit=optical_limit, hilbert_trans=hilbert_trans, xc='RPA', time_ordered=True,
                rpad=self.rpad, vcut=self.vcut, G_plus_q=True,
                eta=self.eta*Hartree, ecut=self.ecut.copy()*Hartree,
                txt='df.out', comm=self.dfcomm, kcommsize=self.kcommsize)

        df.initialize()
        df.e_skn = self.e_skn.copy()
        df.calculate()

        dfinv_wGG = df.get_inverse_dielectric_matrix(xc='RPA')
        assert df.ecut[0] == self.ecut[0]
        if not self.static and not self.ppa:
            assert df.eta == self.eta
            assert df.Nw == self.Nw
            assert df.dw == self.dw

        # calculate Coulomb kernel and use truncation in 2D
        delta_GG = np.eye(df.npw)
        Vq_G = np.diag(calculate_Kc(q,
                                    df.Gvec_Gc,
                                    self.acell_cv,
                                    self.bcell_cv,
                                    self.pbc,
                                    integrate_gamma=True,
                                    N_k=self.kd.N_c,
                                    vcut=self.vcut))**0.5
        if (self.vcut == '2D' and df.optical_limit) or self.numint:
            for iG in range(len(df.Gvec_Gc)):
                if df.Gvec_Gc[iG, 0] == 0 and df.Gvec_Gc[iG, 1] == 0:
                    v_q, v0_q = calculate_Kc_q(self.acell_cv,
                                               self.bcell_cv,
                                               self.pbc,
                                               self.kd.N_c,
                                               vcut=self.vcut,
                                               q_qc=np.array([q]),
                                               Gvec_c=df.Gvec_Gc[iG])
                    Vq_G[iG] = v_q[0]**0.5
        self.Kc_GG = np.outer(Vq_G, Vq_G)

        if self.ppa:
            dfinv1_GG = dfinv_wGG[0] - delta_GG
            dfinv2_GG = dfinv_wGG[1] - delta_GG
            self.wt_GG = self.E0 * np.sqrt(dfinv2_GG / (dfinv1_GG - dfinv2_GG))
            self.R_GG = - self.wt_GG / 2 * dfinv1_GG
            del dfinv_wGG
            dfinv_wGG = np.array([1j*pi*self.R_GG + delta_GG])

        if self.static:
            assert len(dfinv_wGG) == 1
            W_GG = dfinv_wGG[0] * self.Kc_GG

            return df, W_GG
        else:
            Nw = np.shape(dfinv_wGG)[0]
            W_wGG = np.zeros_like(dfinv_wGG)
            for iw in range(Nw):
                dfinv_wGG[iw] -= delta_GG
                W_wGG[iw] = dfinv_wGG[iw] * self.Kc_GG

            return df, W_wGG
Example #26
0
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    calc.write('C_kpt8.gpw','all')

if bse:
    
    bse = BSE('C_kpt8.gpw',w=np.linspace(0,20,201),
              q=np.array([0,0,0.5]),optical_limit=True,ecut=50.,
              nbands=8)

    bse.get_dielectric_function('C_bse.dat')

if df:
    from gpaw.response.df import DF
    df = DF('C_kpt8.gpw',w=np.linspace(0,20,201),q=np.array([0,0,0.5]),
            optical_limit=True,ecut=50., hilbert_trans=False)
    df.get_absorption_spectrum(filename='C.dat')


if check_spectrum:

    d = np.loadtxt('C_bse.dat')[:,2]
    Nw1 = 97
    Nw2 = 109
    if d[Nw1] > d[Nw1-1] and d[Nw1] > d[Nw1+1] and \
       d[Nw2] > d[Nw2-1] and d[Nw2] > d[Nw2+1] :
        pass
    else:
        raise ValueError('Absorption peak not correct ! ')
    
    if np.abs(d[Nw1] - 68.8295454438) > 1e-5 or \
Example #27
0
import numpy as np
from gpaw import GPAW
from gpaw.response.df import DF

w = np.linspace(0, 24., 481)    # 0-24 eV with 0.05 eV spacing
q = np.array([0.0, 0.00001, 0.])

df = DF(calc='si.gpw',
        q=q,
        w=w,
        eta=0.1,           # Broadening parameter 
        ecut=150,          # Energy cutoff for planewaves
        optical_limit=True,
        txt='df_2.out')    # Output text

df.get_absorption_spectrum(filename='si_abs.dat')
df.check_sum_rule()
df.write('df_2.pckl')      # Save important parameters and data 
Example #28
0
    calc.write('Al.gpw','all')

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 ! ')
Example #29
0
a = 6.75 * Bohr
atoms = bulk('C', 'diamond', a=a)

calc = GPAW(h=0.2,
            kpts=(4,4,4),
            occupations=FermiDirac(0.001))

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

# Macroscopic dielectric constant calculation
q = np.array([0.0, 0.00001, 0.])
w = np.linspace(0, 24., 241)

df = DF(calc='C.gpw', q=q, w=(0.,), eta=0.001,
        ecut=50, hilbert_trans=False, optical_limit=True)
df1, df2 = df.get_dielectric_function()
eM1, eM2 = df.get_macroscopic_dielectric_constant(df1, df2)

eM1_ = 6.15185095143
eM2_ = 6.04815084635

if (np.abs(eM1 - eM1_) > 1e-5 or
    np.abs(eM2 - eM2_) > 1e-5):
    print eM1, eM2
    raise ValueError('Macroscopic dielectric constant not correct ! ')


# Absorption spectrum calculation
df = DF(calc='C.gpw', q=q, w=w, eta=0.25,
        ecut=50, optical_limit=True, txt='C_df.out')
    def initialize_calculation(self,
                               w,
                               ecut,
                               nbands,
                               kcommsize,
                               gauss_legendre,
                               frequency_cut,
                               frequency_scale):
        if kcommsize is None:
            if len(self.calc.wfs.bzk_kc) == 1:
                kcommsize = 1
            else:
                kcommsize = world.size
            
        if w is not None:
            assert (gauss_legendre is None and
                    frequency_cut is None and
                    frequency_scale is None)
        else:
            if gauss_legendre is None:
                gauss_legendre = 16
            self.gauss_points, self.gauss_weights = p_roots(gauss_legendre)
            if frequency_scale is None:
                frequency_scale = 2.0
            if frequency_cut is None:
                frequency_cut = 800.
            ys = 0.5 - 0.5 * self.gauss_points
            ys = ys[::-1]
            w = (-np.log(1-ys))**frequency_scale
            w *= frequency_cut/w[-1]
            alpha = (-np.log(1-ys[-1]))**frequency_scale/frequency_cut
            transform = (-np.log(1-ys))**(frequency_scale-1) \
                        / (1-ys)*frequency_scale/alpha
            self.transform = transform
            
        dummy = DF(calc=self.calc,
                   eta=0.0,
                   w=w * 1j,
                   q=[0.,0.,0.0001],
                   ecut=ecut,
                   optical_limit=True,
                   hilbert_trans=False,
                   kcommsize=kcommsize)
        dummy.txt = devnull
        dummy.initialize(simple_version=True)

        self.npw = dummy.npw
        self.ecut = ecut
        self.w = w
        self.gauss_legendre = gauss_legendre
        self.frequency_cut = frequency_cut
        self.frequency_scale = frequency_scale
        self.kcommsize = kcommsize
        self.nbands = nbands

        print >> self.txt
        print >> self.txt, 'Planewave cutoff              : %s eV' % ecut
        print >> self.txt, 'Number of Planewaves at Gamma : %s' % self.npw
        if self.nbands is None:
            print >> self.txt, 'Response function bands       :'\
                  + ' Equal to number of Planewaves'
        else:
            print >> self.txt, 'Response function bands       : %s' \
                  % self.nbands
        print >> self.txt, 'Frequencies'
        if self.gauss_legendre is not None:
            print >> self.txt, '    Gauss-Legendre integration '\
                  + 'with %s frequency points' % len(self.w)
            print >> self.txt, '    Frequency cutoff is '\
                  + '%s eV and scale (B) is %s' % (self.w[-1],
                                                  self.frequency_scale)
        else:
            print >> self.txt, '    %s specified frequency points' \
                  % len(self.w)
            print >> self.txt, '    Frequency cutoff is %s eV' \
                  % self.w[-1]
        print >> self.txt
        print >> self.txt, 'Parallelization scheme'
        print >> self.txt, '     Total CPUs        : %d' % dummy.comm.size
        if dummy.kd.nbzkpts == 1:
            print >> self.txt, '     Band parsize      : %d' % dummy.kcomm.size
        else:
            print >> self.txt, '     Kpoint parsize    : %d' % dummy.kcomm.size
        print >> self.txt, '     Frequency parsize : %d' % dummy.wScomm.size
        print >> self.txt, 'Memory usage estimate'
        print >> self.txt, '     chi0_wGG(Q)       : %f M / cpu' \
              % (dummy.Nw_local * self.npw**2 * 16. / 1024**2)
        print >> self.txt
        del dummy
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('Si', 'diamond', a=5.431)   # Generate diamond crystal structure for silicon
calc = GPAW(h=0.20, kpts=(4,4,4))        # GPAW calculator initialization
 
atoms.set_calculator(calc)               
atoms.get_potential_energy()             # Ground state calculation is performed
calc.write('si.gpw','all')               # Use 'all' option to write wavefunction

# Part 2 : Spectrum calculation          # DF: dielectric function object
df = DF(calc='si.gpw',                   # Ground state gpw file (with wavefunction) as input
        q=np.array([0.0, 0.00001, 0.0]), # Momentum transfer, here excites in y-direction
        w=np.linspace(0,14,141),         # The Energies (eV) for spectrum: from 0-14 eV with 0.1 eV spacing
        optical_limit=True)              # Indicates that its a optical spectrum calculation

df.get_absorption_spectrum()             # By default, a file called 'Absorption.dat' is generated
Example #32
0
                convergence={'bands':70})
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    calc.write('si.gpw','all')


if ABS:
            
    w = np.linspace(0, 24, 481)
    q = np.array([0.0, 0.00001, 0.])

    # getting macroscopic constant
    df = DF(calc='si.gpw',
            q=q,
            w=(0.,),
            eta=0.001, 
            hilbert_trans=False,
            ecut=150,
            optical_limit=True,
            txt='df_1.out')

    eM1, eM2 = df.get_macroscopic_dielectric_constant()

    df.write('df_1.pckl')

    if np.abs(eM1 - 13.991793) > 1e-3 or np.abs(eM2 - 12.589129) > 1e-3:
        print eM1, eM2
        raise ValueError('Please check dielectric constant !')

    #getting absorption spectrum
    df = DF(calc='si.gpw',
            q=q,
Example #33
0
a = 4.043
atoms = bulk('Al', 'fcc', a=a)
atoms.center()
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)
Example #34
0
from gpaw.response.df import DielectricFunction as DF

df = DF(
    'LiF_fulldiag.gpw',
    domega0=0.01,  # grid-spacing at 0 eV
    omega2=10.0,  # frequency where grid-spacing has doubled to 0.02 eV
    eta=0.1,  # broadening parameter
    nbands=60,  # number of bands to consider for building chi
    ecut=30,  # energy cutoff for planewaves
    txt='LiF_RPA_out2.txt')

# Calculate the dielectric function without and with local field effects:
df.get_dielectric_function()
Example #35
0
    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 ! ')
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('Si', 'diamond', a=5.431)   # Generate diamond crystal structure for silicon
calc = GPAW(h=0.20, kpts=(4,4,4))        # GPAW calculator initialization
 
atoms.set_calculator(calc)               
atoms.get_potential_energy()             # Ground state calculation is performed
calc.write('si.gpw','all')               # Use 'all' option to write wavefunction

# Part 2 : Spectrum calculation          # DF: dielectric function object
df = DF(calc='si.gpw',                   # Ground state gpw file (with wavefunction) as input
        q=np.array([0.0, 0.00001, 0.0]), # Momentum transfer, here excites in y-direction
        w=np.linspace(0,14,141),         # The Energies (eV) for spectrum: from 0-14 eV with 0.1 eV spacing
        optical_limit=True)              # Indicates that its a optical spectrum calculation

df.get_absorption_spectrum()             # By default, a file called 'Absorption.dat' is generated
Example #37
0
#    view(atoms)

    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)

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

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

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



Example #38
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
Example #39
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')



Example #40
0
            eigensolver='cg',
            occupations=FermiDirac(0.001),
            convergence={'bands':70})
    atoms.set_calculator(calc)
    atoms.get_potential_energy()
    calc.write('si.gpw','all')


if ABS:
            
    w = np.linspace(0, 24, 481)
    q = np.array([0.0, 0.00001, 0.])

    # getting macroscopic constant
    df = DF(calc='si.gpw', q=q, w=(0.,), eta=0.0001, 
        hilbert_trans=False, txt='df_1.out',
        ecut=150, optical_limit=True)

    df1, df2 = df.get_dielectric_function()
    eM1, eM2 = df.get_macroscopic_dielectric_constant(df1, df2)

    df.write('df_1.pckl')

    if np.abs(eM1 - 13.992277) > 1e-4 or np.abs(eM2 - 12.589596) > 1e-4:
        print eM1, eM2
        raise ValueError('Pls check dielectric constant !')

    #getting absorption spectrum
    df = DF(calc='si.gpw', q=q, w=w, eta=0.1,
        ecut=150, optical_limit=True, txt='df_2.out')
Example #41
0
            calc = GPAW(mode='pw', kpts=kpts, basis='dzp', dtype=complex,
                        maxiter=500,
                        usesymm=None, communicator=serial_comm)

        atoms.set_calculator(calc)
        atoms.get_potential_energy()

        gd = GridDescriptor(calc.wfs.gd.N_c, calc.atoms.cell / Bohr,
                            pbc_c=True, comm=serial_comm)
        kd = calc.wfs.kd
        setups = calc.wfs.setups
        bzk_kc = calc.wfs.kd.bzk_kc
        spos_ac = calc.atoms.get_scaled_positions()
        nbands = calc.get_number_of_bands()
        nspins = calc.wfs.nspins
        df = DF(calc)
        df.spos_ac = spos_ac
        
        if mode == 'fd':
            pt = LFC(gd, [setup.pt_j for setup in setups],
                              KPointDescriptor(bzk_kc),
                              dtype=calc.wfs.dtype)
            pt.set_positions(spos_ac)
        
            for spin in range(nspins):
                for k in range(len(bzk_kc)):
                    ibzk = k  # since no symmetry
                    u = kd.get_rank_and_index(spin, ibzk)[1]
                    kpt = calc.wfs.kpt_u[u]
                    for n in range(nbands):
                        P_ai = pt.dict()