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

32 statements  

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

1import pytest 

2import numpy as np 

3from gpaw.response.df import DielectricFunction 

4from gpaw.response.bse import BSE, read_spectrum 

5from gpaw.test import findpeak 

6 

7 

8@pytest.mark.dielectricfunction 

9@pytest.mark.response 

10def test_response_bse_aluminum(in_tmp_dir, gpw_files): 

11 df = 1 

12 bse = 1 

13 check_spectrum = 1 

14 

15 q_c = np.array([0.25, 0.0, 0.0]) 

16 w_w = np.linspace(0, 24, 241) 

17 eta = 0.2 

18 ecut = 50 

19 if bse: 

20 bse = BSE(gpw_files['bse_al'], 

21 valence_bands=range(4), 

22 conduction_bands=range(4), 

23 mode='RPA', 

24 nbands=4, 

25 q_c=q_c, 

26 ecut=ecut, 

27 ) 

28 bse.get_eels_spectrum(filename='bse_eels.csv', 

29 w_w=w_w, 

30 eta=eta) 

31 omega_w, bse_w = read_spectrum('bse_eels.csv') 

32 

33 if df: 

34 df = DielectricFunction(calc=gpw_files['bse_al'], 

35 frequencies=w_w, 

36 eta=eta, 

37 ecut=ecut, 

38 hilbert=False) 

39 df_w = df.get_eels_spectrum(q_c=q_c, filename=None)[1] 

40 

41 if check_spectrum: 

42 assert w_w == pytest.approx(omega_w) 

43 w_ = 15.1423 

44 I_ = 25.4359 

45 wbse, Ibse = findpeak(w_w, bse_w) 

46 wdf, Idf = findpeak(w_w, df_w) 

47 assert wbse == pytest.approx(w_, abs=0.01) 

48 assert wdf == pytest.approx(w_, abs=0.01) 

49 assert Ibse == pytest.approx(I_, abs=0.1) 

50 assert Idf == pytest.approx(I_, abs=0.1)