Coverage for gpaw/test/response/test_graphene_EELS.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-12 00:18 +0000

1import numpy as np 

2import pytest 

3 

4from gpaw.response.df import DielectricFunction 

5from gpaw.test import findpeak 

6 

7 

8@pytest.mark.dielectricfunction 

9@pytest.mark.response 

10def test_graphene_EELS(in_tmp_dir, gpw_files): 

11 # Test values 

12 q_qc = [ 

13 [0, 0, 0], 

14 [1 / 3, 0, 0], 

15 ] 

16 refs_q = [ 

17 # peak frequency and intensity (rows), w.o./w. local-field corr. (cols) 

18 np.array([[7.57, 7.66], [3.78, 4.01]]), 

19 np.array([[5.86, 6.29], [0.99, 0.48]]), 

20 ] 

21 # Calculation 

22 dfcalc = DielectricFunction(gpw_files['graphene_pw'], truncation='2D', 

23 frequencies=np.linspace(0., 9., 141), 

24 eta=0.3, ecut=150, rate='eta', hilbert=False) 

25 for q_c, refs in zip(q_qc, refs_q): 

26 epsinv = dfcalc.get_inverse_dielectric_function(q_c=q_c) 

27 omega_w, eels0_w, eels_w = epsinv.eels_spectrum().arrays 

28 

29 # import matplotlib.pyplot as plt 

30 # plt.plot(omega_w, eels0_w) 

31 # plt.plot(omega_w, eels_w) 

32 # plt.show() 

33 

34 # Test against reference 

35 e0, I0 = findpeak(omega_w, eels0_w) 

36 e, I = findpeak(omega_w, eels_w) 

37 assert np.array([e0, e]) == pytest.approx(refs[0, :], abs=0.05) 

38 assert np.array([I0, I]) == pytest.approx(refs[1, :], abs=0.02)