Coverage for gpaw/test/response/test_na_plasmons_tetrahedron.py: 32%
38 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1import pytest
2from ase import Atoms
3from gpaw.mpi import world
4from gpaw import GPAW, PW
5from gpaw.response.df import DielectricFunction
6from gpaw.test import findpeak
8# Comparing the EELS spectrum of sodium for different block
9# parallelizations. Intended to be run with 8 cores.
11pytestmark = pytest.mark.skipif(world.size < 4, reason='world.size < 4')
14@pytest.mark.dielectricfunction
15@pytest.mark.response
16@pytest.mark.slow
17@pytest.mark.xfail(reason='https://gitlab.com/gpaw/gpaw/-/jobs/5215834173')
18def test_response_na_plasmons_tetrahedron(in_tmp_dir, scalapack):
19 a = 4.23 / 2.0
20 a1 = Atoms('Na',
21 scaled_positions=[[0, 0, 0]],
22 cell=(a, a, a),
23 pbc=True)
25 a1.calc = GPAW(mode=PW(250),
26 kpts={'size': (10, 10, 10), 'gamma': True},
27 parallel={'band': 1},
28 txt='small.txt')
30 a1.get_potential_energy()
31 a1.calc.diagonalize_full_hamiltonian(nbands=20)
32 a1.calc.write('gs_Na.gpw', 'all')
34 kwargs = {'integrationmode': 'tetrahedron integration',
35 'ecut': 40}
37 # Calculate the dielectric functions: tetrahedral 1 block
38 df1 = DielectricFunction('gs_Na.gpw',
39 rate=0.001,
40 nblocks=1,
41 txt='1block.txt',
42 **kwargs)
43 df1NLFCx, df1LFCx = df1.get_dielectric_function(direction='x')
45 # tetrahedral 4 blocks
46 df2 = DielectricFunction('gs_Na.gpw',
47 rate=0.001,
48 nblocks=4,
49 txt='4block.txt',
50 **kwargs)
51 df2NLFCx, df2LFCx = df2.get_dielectric_function(direction='x')
53 # tetrahedron integration 4 blocks with large eta
54 kwargs.update({'eta': 4.25})
55 df3 = DielectricFunction('gs_Na.gpw',
56 rate=0.001,
57 nblocks=4,
58 txt='4block.txt',
59 **kwargs)
60 df3NLFCx, df3LFCx = df3.get_dielectric_function(direction='x')
62 # point integration 4 blocks with large eta (smearing)
63 kwargs.update({'integrationmode': 'point integration', 'eta': 4.25})
64 df4 = DielectricFunction('gs_Na.gpw',
65 rate=0.001,
66 nblocks=4,
67 txt='4block.txt',
68 **kwargs)
69 df4NLFCx, df4LFCx = df4.get_dielectric_function(direction='x')
71 # Compare plasmon frequencies and intensities
72 w_w = df1.chi0calc.wd.omega_w
74 w1, I1 = findpeak(w_w, -(1. / df1LFCx).imag)
75 w2, I2 = findpeak(w_w, -(1. / df2LFCx).imag)
76 w3, I3 = findpeak(w_w, -(1. / df3LFCx).imag)
77 w4, I4 = findpeak(w_w, -(1. / df4LFCx).imag)
79 # omegas don't change
80 assert [w3, w4] == pytest.approx([0.283057, 0.300520], abs=1e-2)
81 assert w1 == pytest.approx(w2, 1e-2) # omega: serial vs parallel
82 # omega: PI & TI w/ large eta are aprx equal
83 assert w4 == pytest.approx(w3, 2e-2, abs=True)
84 assert I1 == pytest.approx(I2, 1e-3) # intensity: serial vs parallel