Coverage for gpaw/test/gllb/test_metallic.py: 96%
23 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
1import pytest
2import numpy as np
3from ase.build import bulk
4from gpaw import GPAW
7def run(xc, repeat=1):
8 atoms = bulk('Ag') * repeat
9 k = 4 // repeat
10 calc = GPAW(mode='lcao',
11 basis='sz(dzp)',
12 h=0.3,
13 setups={'Ag': '11'},
14 nbands=6 * repeat**3,
15 xc=xc,
16 parallel={'domain': 1},
17 kpts={'size': (k, k, k), 'gamma': False},
18 txt='-')
19 atoms.calc = calc
20 atoms.get_potential_energy()
21 x_i, y_i = calc.get_dos(npts=1001)
22 x_i -= calc.get_fermi_level()
23 y_i /= repeat**3
24 return x_i, y_i
27@pytest.mark.gllb
28@pytest.mark.libxc
29def test_metallic_GLLBSCM():
30 # GLLBSC should behave like GLLBSCM for metals and
31 # repeated cell should give exactly the same results
32 x1_i, y1_i = run(xc='GLLBSCM', repeat=1)
33 for x_i, y_i in [run(xc='GLLBSC', repeat=1),
34 run(xc='GLLBSCM', repeat=2)]:
35 # Test that the DOSes are the same
36 assert np.allclose(x1_i, x_i, rtol=0, atol=1e-8), \
37 "DOS energies don't match, " \
38 "error = {}".format(np.max(np.abs(x1_i - x_i)))
39 assert np.allclose(y1_i, y_i, rtol=0, atol=1e-6), \
40 "DOS values don't match, " \
41 "error = {}".format(np.max(np.abs(y1_i - y_i)))
44if __name__ == '__main__':
45 test_metallic_GLLBSCM()