Coverage for gpaw/test/elph/test_resonant_term.py: 100%

38 statements  

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

1import numpy as np 

2import pytest 

3 

4from gpaw.elph import ResonantRamanCalculator 

5 

6 

7def make_hermitian(mat): 

8 n = mat.shape[0] 

9 for i in range(n): 

10 for j in range(i + 1, n): 

11 mat[j, i] = mat[i, j].conj() 

12 

13 

14@pytest.mark.serial 

15def test_resonant_term(): 

16 rt = ResonantRamanCalculator.resonant_term 

17 

18 f_n = np.array([1.0, 0.0, 0.0]) 

19 f_vc = np.outer(f_n, 1.0 - f_n) 

20 assert f_vc[0] == pytest.approx([0.0, 1.0, 1.0]) 

21 print(f_vc) 

22 

23 E_n = np.array([-1.0, 0.0, 1.0]) 

24 E_vc = np.zeros((3, 3), dtype=complex) + 1j * 0.1 

25 for n in range(3): 

26 E_vc[n] += (E_n - E_n[n]) 

27 assert E_vc[0] == pytest.approx([0.0 + 1j * 0.1, 

28 1.0 + 1j * 0.1, 

29 2.0 + 1j * 0.1]) 

30 

31 nn = np.zeros((3, 3), dtype=complex) 

32 nn[0, 0] = 1.0 

33 nn[1, 1] = 2.0 

34 nn[2, 2] = 3.0 

35 nn[0, 1] = 0.5 + 0.1j 

36 nn[0, 2] = 0.25 + 0.1j 

37 nn[1, 2] = 0.125 + 0.1j 

38 make_hermitian(nn) 

39 # print(nn) 

40 mom_dnn = np.zeros((2, 3, 3), dtype=complex) 

41 mom_dnn[0] = nn 

42 mom_dnn[1] = 2. * nn 

43 

44 elph_lnn = np.zeros((2, 3, 3), dtype=complex) 

45 elph_lnn[1] = 3. * nn 

46 

47 wph_w = np.array([0.0, 0.2]) 

48 

49 term = rt(f_vc, E_vc, mom_dnn, elph_lnn, 0, 3, 1.0, wph_w) 

50 # we'll want to check whether this is the expect number 

51 assert term[1] == pytest.approx(-29.768613861386154 - 64.0461386138614j) 

52 

53 # complement polarisations need to yield the same result 

54 term2 = rt(f_vc, E_vc, mom_dnn[[1, 0], :, :], elph_lnn, 0, 3, 1.0, wph_w) 

55 assert term[1] == pytest.approx(term2[1])