Coverage for gpaw/test/response/test_gw_hBN_extrapolate.py: 100%
19 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
1""" Tests extrapolation to infinite energy cutoff + block parallelization.
2It takes ~10 s on one core"""
4import pytest
5from gpaw.response.g0w0 import G0W0
6import numpy as np
9@pytest.mark.response
10def test_response_gw_hBN_extrapolate(in_tmp_dir, scalapack, gpw_files):
11 ecuts = [20, 25, 30]
12 common = dict(truncation='2D',
13 q0_correction=True,
14 kpts=[0],
15 eta=0.2,
16 bands=(3, 5),
17 nblocksmax=True)
18 gw = G0W0(gpw_files['hbn_pw'],
19 'gw-hBN',
20 ecut=30,
21 frequencies={'type': 'nonlinear',
22 'domega0': 0.1},
23 ecut_extrapolation=ecuts,
24 **common)
26 results = gw.calculate()
27 e_qp = results['qp'][0, 0]
29 ev = -1.4528
30 ec = 3.69469
31 assert e_qp[0] == pytest.approx(ev, abs=0.01)
32 assert e_qp[1] == pytest.approx(ec, abs=0.01)
34 # The individual sigma matrix elements should be exactly the same
35 # when running with ecut-extrapolation, and when calculating
36 # with particular ecuts individually (given that nbands is not specified,
37 # and it is also chosen utilizing ecut).
38 for ie, ecut in enumerate(ecuts):
39 gw = G0W0(gpw_files['hbn_pw'],
40 f'gw-hBN-separate-ecut{ecut}',
41 ecut=ecut,
42 frequencies={'type': 'nonlinear',
43 'omegamax': 43.2, # We need same grid as above
44 'domega0': 0.1},
45 ecut_extrapolation=False,
46 **common)
47 res = gw.calculate()
48 assert np.allclose(res['dsigma_eskn'][0], results['dsigma_eskn'][ie])
49 assert np.allclose(res['sigma_eskn'][0], results['sigma_eskn'][ie])