Coverage for gpaw/test/response/test_na_plasmons.py: 42%

26 statements  

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

1import pytest 

2from gpaw.mpi import world 

3from ase import Atoms 

4from gpaw import GPAW, PW 

5from gpaw.response.df import DielectricFunction 

6from gpaw.test import findpeak 

7 

8# Comparing the EELS spectrum of sodium for different block 

9# parallelizations. Intended to be run with 8 cores. 

10# Reasons that this can fail: 

11# - Bug in block parallelization 

12 

13pytestmark = pytest.mark.skipif(world.size < 4, reason='world.size < 4') 

14 

15 

16@pytest.mark.dielectricfunction 

17@pytest.mark.response 

18@pytest.mark.slow 

19def test_response_na_plasmons(in_tmp_dir, scalapack): 

20 a = 4.23 / 2.0 

21 a1 = Atoms('Na', 

22 scaled_positions=[[0, 0, 0]], 

23 cell=(a, a, a), 

24 pbc=True) 

25 

26 a1.calc = GPAW(mode=PW(300), 

27 kpts={'size': (10, 10, 10), 'gamma': True}, 

28 parallel={'band': 1}, 

29 txt='small.txt') 

30 

31 a1.get_potential_energy() 

32 a1.calc.diagonalize_full_hamiltonian(nbands=20) 

33 a1.calc.write('gs_Na.gpw', 'all') 

34 

35 # Calculate the dielectric functions 

36 df1 = DielectricFunction('gs_Na.gpw', 

37 nblocks=1, 

38 ecut=40, 

39 rate=0.001, 

40 txt='1block.txt') 

41 

42 df1NLFCx, df1LFCx = df1.get_dielectric_function(direction='x') 

43 

44 df2 = DielectricFunction('gs_Na.gpw', 

45 nblocks=4, 

46 ecut=40, 

47 rate=0.001, 

48 txt='4block.txt') 

49 

50 df2NLFCx, df2LFCx = df2.get_dielectric_function(direction='x') 

51 

52 # Compare plasmon frequencies and intensities 

53 w_w = df1.chi0calc.wd.omega_w 

54 w1, I1 = findpeak(w_w, -(1. / df1LFCx).imag) 

55 w2, I2 = findpeak(w_w, -(1. / df2LFCx).imag) 

56 assert w1 == pytest.approx(w2, abs=1e-2) 

57 assert I1 == pytest.approx(I2, abs=1e-3)