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

43 statements  

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

1import pytest 

2import numpy as np 

3from ase import Atoms 

4from gpaw import GPAW, FermiDirac, PW 

5from gpaw.response.df import DielectricFunction 

6from gpaw.test import findpeak 

7 

8 

9@pytest.fixture 

10def gpwfile(in_tmp_dir): 

11 cluster = Atoms('Au2', [(0, 0, 0), (0, 0, 2.564)]) 

12 cluster.set_cell((6, 6, 6), scale_atoms=False) 

13 cluster.center() 

14 calc = GPAW(mode=PW(ecut=180, force_complex_dtype=True), 

15 xc={'name': 'RPBE', 'stencil': 1}, 

16 nbands=16, 

17 eigensolver='rmm-diis', 

18 parallel={'domain': 1}, 

19 occupations=FermiDirac(0.01)) 

20 

21 cluster.calc = calc 

22 cluster.get_potential_energy() 

23 calc.diagonalize_full_hamiltonian(nbands=24, scalapack=True) 

24 gpwname = 'Au2.gpw' 

25 calc.write(gpwname, 'all') 

26 return gpwname 

27 

28 

29@pytest.mark.dielectricfunction 

30@pytest.mark.response 

31@pytest.mark.slow 

32def test_response_au02_absorption(scalapack, in_tmp_dir, gpwfile): 

33 nw = 141 

34 frequencies = np.linspace(0, 14, nw) 

35 

36 df = DielectricFunction(gpwfile, 

37 frequencies=frequencies, 

38 hilbert=False, 

39 eta=0.1, 

40 ecut=10) 

41 

42 b0, b = df.get_dielectric_function(filename=None, 

43 direction='z') 

44 a0, a = df.get_polarizability(filename=None, 

45 direction='z') 

46 

47 w0_ = 5.60491055 

48 I0_ = 227.23392824591642 

49 w_ = 5.644900254787107 

50 I_ = 184.4086028397282 

51 

52 w, I = findpeak(frequencies, b0.imag) 

53 assert w == pytest.approx(w0_, abs=0.05) 

54 assert 6**3 * I / (4 * np.pi) == pytest.approx(I0_, abs=0.5) 

55 w, I = findpeak(frequencies, a0.imag) 

56 assert w == pytest.approx(w0_, abs=0.05) 

57 assert I == pytest.approx(I0_, abs=0.5) 

58 w, I = findpeak(frequencies, b.imag) 

59 assert w == pytest.approx(w_, abs=0.05) 

60 assert 6**3 * I / (4 * np.pi) == pytest.approx(I_, abs=0.5) 

61 w, I = findpeak(frequencies, a.imag) 

62 assert w == pytest.approx(w_, abs=0.05) 

63 assert I == pytest.approx(I_, abs=0.5)