eM1, eM2 = df.get_macroscopic_dielectric_constant() equal(eM1, eM1_, 0.01) equal(eM2, eM2_, 0.01) # Absorption spectrum calculation RPA df = DielectricFunction('C.gpw', eta=0.25, ecut=50, frequencies=np.linspace(0, 24., 241), hilbert=False) a0, a = df.get_dielectric_function(filename=None) df.check_sum_rule(a.imag) equal(a0[0].real, eM1_, 0.01) equal(a[0].real, eM2_, 0.01) w, I = findpeak(np.linspace(0, 24., 241), a0.imag) equal(w, w0_, 0.01) equal(I / (4 * np.pi), I0_, 0.05) w, I = findpeak(np.linspace(0, 24., 241), a.imag) equal(w, w_, 0.01) equal(I / (4 * np.pi), I_, 0.05) a0, a = df.get_polarizability(filename=None) w, I = findpeak(np.linspace(0, 24., 241), a0.imag) equal(w, w0_, 0.01) equal(I, I0_, 0.01) w, I = findpeak(np.linspace(0, 24., 241), a.imag) equal(w, w_, 0.01) equal(I, I_, 0.01)
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 test_Ipeak1 = 29.644489594 test_wpeak2 = 15.5196459206 # eV test_Ipeak2 = 26.5680624522 if abs(test_wpeak1 - wpeak1) > 0.02 or abs(test_wpeak2 - wpeak2) > 0.02: print((test_wpeak1 - wpeak1, test_wpeak2 - wpeak2)) raise ValueError('Plasmon peak not correct ! ') if abs(test_Ipeak1 - Ipeak1) > 1 or abs(test_Ipeak2 - Ipeak2) > 1: print((Ipeak1 - test_Ipeak1, Ipeak2 - test_Ipeak2)) raise ValueError('Please check spectrum strength ! ')
df_ws = DielectricFunction('Au2.gpw', frequencies=np.linspace(0, 14, 141), hilbert=not True, eta=0.1, ecut=10, truncation='wigner-seitz') a0_ws, a_ws = df_ws.get_polarizability(filename=None, direction='z') w0_ = 5.60491055 I0_ = 244.693028 w_ = 5.696528390 I_ = 207.8 w, I = findpeak(np.linspace(0, 14., 141), b0.imag) equal(w, w0_, 0.05) equal(6**3 * I / (4 * np.pi), I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a0.imag) equal(w, w0_, 0.05) equal(I, I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a0_ws.imag) equal(w, w0_, 0.05) equal(I, I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), b.imag) equal(w, w_, 0.05) equal(6**3 * I / (4 * np.pi), I_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a.imag) equal(w, w_, 0.05) equal(I, I_, 0.5) # The Wigner-Seitz truncation does not give exactly the same for small cell
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') 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.70 # eV test_Ipeak1 = 29.05 # eV test_wpeak2 = 15.725 # eV test_Ipeak2 = 26.41 # eV if np.abs(test_wpeak1-wpeak1)<1e-2 and np.abs(test_wpeak2-wpeak2)<1e-2: pass else: print(test_wpeak1-wpeak1,test_wpeak2-wpeak2) raise ValueError('Plasmon peak not correct ! ') if np.abs(test_Ipeak1-Ipeak1)>1e-2 or np.abs(test_Ipeak2-Ipeak2)>1e-2:
df1NLFCx, df1LFCx = df1.get_dielectric_function(direction='x') df1NLFCy, df1LFCy = df1.get_dielectric_function(direction='y') df1NLFCz, df1LFCz = df1.get_dielectric_function(direction='z') df2 = DielectricFunction('gs_Na_large.gpw', omegamax=15, domega0=0.05, hilbert=True, ecut=150) df2NLFCx, df2LFCx = df2.get_dielectric_function(direction='x') df2NLFCy, df2LFCy = df2.get_dielectric_function(direction='y') df2NLFCz, df2LFCz = df2.get_dielectric_function(direction='z') # Compare plasmon frequencies and intensities w_w = df1.chi0.omega_w w1, I1 = findpeak(w_w, -(1. / df1LFCx).imag) w2, I2 = findpeak(w_w, -(1. / df2LFCx).imag) equal(w1, w2, 1e-2) equal(I1, I2, 1e-3) w1, I1 = findpeak(w_w, -(1. / df1LFCy).imag) w2, I2 = findpeak(w_w, -(1. / df2LFCy).imag) equal(w1, w2, 1e-2) equal(I1, I2, 1e-3) w1, I1 = findpeak(w_w, -(1. / df1LFCz).imag) w2, I2 = findpeak(w_w, -(1. / df2LFCz).imag) equal(w1, w2, 1e-2) equal(I1, I2, 1e-3)
RSrep='grid', filename='iron_dsus' + '_%d.csv' % (q + 1)) t3 = time.time() parprint('Ground state calculation took', (t2 - t1) / 60, 'minutes') parprint('Excited state calculation took', (t3 - t2) / 60, 'minutes') world.barrier() # Part 3: identify peaks in scattering function and compare to test values d1 = np.loadtxt('iron_dsus_1.csv', delimiter=', ') d2 = np.loadtxt('iron_dsus_2.csv', delimiter=', ') wpeak1, Ipeak1 = findpeak(d1[:, 0], -d1[:, 4]) wpeak2, Ipeak2 = findpeak(d2[:, 0], -d2[:, 4]) mw1 = (wpeak1 + d1[0, 0]) * 1000 mw2 = (wpeak2 + d2[0, 0]) * 1000 test_mw1 = 81.0 # meV test_mw2 = 242.866784926 # meV test_Ipeak1 = 71.0518550563 # a.u. test_Ipeak2 = 60.5 # a.u. # Magnon peak: equal(test_mw1, mw1, eta * 200) equal(test_mw2, mw2, eta * 900) # Scattering function intensity:
kpts={'size': (1, 1, NK), 'gamma': True}, parallel={'band': 1}, gpts=(10, 10, 10 * NH)) a.get_potential_energy() a.calc.diagonalize_full_hamiltonian(nbands=2 * NH) a.calc.write('H_chain.gpw', 'all') DF = DielectricFunction('H_chain.gpw', ecut=1e-3, hilbert=False, omega2=np.inf, intraband=False) eps_NLF, eps_LF = DF.get_dielectric_function(direction='z') omega_w = DF.get_frequencies() return omega_w, eps_LF NH_i = [2**n for n in [0, 4]] NK_i = [2**n for n in [6, 2]] opeak_old = np.nan peak_old = np.nan for NH, NK in zip(NH_i, NK_i): omega_w, eps_w = get_hydrogen_chain_dielectric_function(NH, NK) eels_w = -(1. / eps_w).imag opeak, peak = findpeak(omega_w, eels_w) # Test for consistency if not np.isnan(opeak_old): equal(opeak, opeak_old, tolerance=1e-3) equal(peak, peak_old, tolerance=1e-3) opeak_old = opeak peak_old = peak
layer.set_calculator(calc) layer.get_potential_energy() response = calc.hamiltonian.xc.xcs['RESPONSE'] response.calculate_delta_xc() E_ks, dis = response.calculate_delta_xc_perturbation() calc.write('MoS2.gpw', mode='all') else: dis = 0.5345 bse = BSE('MoS2.gpw', ecut=10, valence_bands=[8], conduction_bands=[9], eshift=dis, nbands=15, write_h=False, write_v=False, wfile=None, mode='BSE', truncation='2D') w_w, alpha_w = bse.get_polarizability(filename='bse.csv', pbc=[True, True, False], eta=0.02, w_w=np.linspace(0., 5., 5001)) w_ = 0.833 I_ = 26.51 w, I = findpeak(w_w[:1000], alpha_w.imag[:1000]) equal(w, w_, 0.01) equal(I, I_, 0.1)
a = a.repeat((1, 1, NH)) a.calc = GPAW(mode=PW(200), kpts={'size': (1, 1, NK), 'gamma': True}, parallel={'band': 1}, dtype=complex, gpts=(10, 10, 10 * NH)) a.get_potential_energy() a.calc.diagonalize_full_hamiltonian(nbands=2 * NH) a.calc.write('H_chain.gpw', 'all') DF = DielectricFunction('H_chain.gpw', ecut=1e-3, hilbert=False, omega2=np.inf, intraband=False) eps_NLF, eps_LF = DF.get_dielectric_function(direction='z') omega_w = DF.get_frequencies() return omega_w, eps_LF NH_i = [2**n for n in [0, 4]] NK_i = [2**n for n in [6, 2]] opeak_old = np.nan peak_old = np.nan for NH, NK in zip(NH_i, NK_i): omega_w, eps_w = get_hydrogen_chain_dielectric_function(NH, NK) eels_w = -(1. / eps_w).imag opeak, peak = findpeak(omega_w, eels_w) # Test for consistency if not np.isnan(opeak_old): equal(opeak, opeak_old, tolerance=1e-3) equal(peak, peak_old, tolerance=1e-3) opeak_old = opeak peak_old = peak
a0, a = df.get_polarizability(filename=None, direction='z') df_ws = DielectricFunction('Au2.gpw', frequencies=np.linspace(0, 14, 141), hilbert=not True, eta=0.1, ecut=10, truncation='wigner-seitz') a0_ws, a_ws = df_ws.get_polarizability(filename=None, direction='z') w0_ = 5.60491055 I0_ = 244.693028 w_ = 5.696528390 I_ = 207.8 w, I = findpeak(np.linspace(0, 14., 141), b0.imag) equal(w, w0_, 0.05) equal(6**3 * I / (4 * np.pi), I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a0.imag) equal(w, w0_, 0.05) equal(I, I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a0_ws.imag) equal(w, w0_, 0.05) equal(I, I0_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), b.imag) equal(w, w_, 0.05) equal(6**3 * I / (4 * np.pi), I_, 0.5) w, I = findpeak(np.linspace(0, 14., 141), a.imag) equal(w, w_, 0.05) equal(I, I_, 0.5) # The Wigner-Seitz truncation does not give exactly the same for small cell
eshift = 0.8 bse = BSE('Si.gpw', ecut=50., valence_bands=range(4), conduction_bands=range(4, 8), eshift=eshift, nbands=8, write_h=False, write_v=False) w_w, eps_w = bse.get_dielectric_function(filename=None, eta=0.2, w_w=np.linspace(0, 10, 2001)) if check: w_ = 2.552 I_ = 421.15 w, I = findpeak(w_w, eps_w.imag) equal(w, w_, 0.01) equal(I, I_, 0.1) if GS and nosym: atoms = bulk('Si', 'diamond', a=a) calc = GPAW(mode='pw', kpts={ 'size': (2, 2, 2), 'gamma': True }, occupations=FermiDirac(0.001), nbands=12, symmetry='off', convergence={'bands': -4}) atoms.set_calculator(calc)
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)
df3 = DielectricFunction('gs_Na.gpw', nblocks=4, ecut=400, txt='4block.txt') df3NLFCx, df3LFCx = df3.get_dielectric_function(direction='x') df3NLFCy, df3LFCy = df3.get_dielectric_function(direction='y') df3NLFCz, df3LFCz = df3.get_dielectric_function(direction='z') df4 = DielectricFunction('gs_Na.gpw', nblocks=8, ecut=400, txt='8block.txt') df4NLFCx, df4LFCx = df4.get_dielectric_function(direction='x') df4NLFCy, df4LFCy = df4.get_dielectric_function(direction='y') df4NLFCz, df4LFCz = df4.get_dielectric_function(direction='z') # Compare plasmon frequencies and intensities w_w = df1.chi0.omega_w w1, I1 = findpeak(w_w, -(1. / df1LFCx).imag) w2, I2 = findpeak(w_w, -(1. / df2LFCx).imag) w3, I3 = findpeak(w_w, -(1. / df3LFCy).imag) w4, I4 = findpeak(w_w, -(1. / df4LFCy).imag) equal(w1, w2, 1e-2) equal(I1, I2, 1e-3) equal(w1, w3, 1e-2) equal(I1, I3, 1e-3) equal(w1, w4, 1e-2) equal(I1, I4, 1e-3)