Coverage for gpaw/test/exx/test_double_cell.py: 79%
33 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import pytest
2from ase import Atoms
3from gpaw import GPAW, PW
6@pytest.mark.libxc
7@pytest.mark.hybrids
8def test_exx_double_cell(in_tmp_dir):
9 L = 2.6
10 a = Atoms('H2',
11 [[0, 0, 0], [0.5, 0.5, 0]],
12 cell=[L, L, 1],
13 pbc=1)
14 a.center()
16 a.calc = GPAW(
17 mode=PW(400),
18 symmetry='off',
19 kpts={'size': (1, 1, 4), 'gamma': True},
20 convergence={'density': 1e-6},
21 spinpol=True,
22 txt='H2.txt',
23 xc='HSE06')
24 e1 = a.get_potential_energy()
25 eps1 = a.calc.get_eigenvalues(1)[0]
26 f1 = a.get_forces()
27 assert abs(f1[1, 0] - 9.60644) < 0.0005
28 if 0:
29 # To check against numeric calculation of the forces, but it takes
30 # more time
31 from gpaw.test import calculate_numerical_forces
32 f1n = calculate_numerical_forces(a, 0.001, [1], [0])[0, 0]
33 assert abs(f1[1, 0] - f1n) < 0.0005
35 a *= (1, 1, 2)
36 a.calc = GPAW(
37 mode=PW(400),
38 kpts={'size': (1, 1, 2), 'gamma': True},
39 symmetry='off',
40 convergence={'density': 1e-6},
41 txt='H4.txt',
42 xc='HSE06')
43 e2 = a.get_potential_energy()
44 eps2 = a.calc.get_eigenvalues(0)[0]
45 f2 = a.get_forces()
47 f2[:2] -= f1
48 f2[2:] -= f1
50 assert abs(e2 - 2 * e1) < 0.002
51 assert abs(eps1 - eps2) < 0.001
52 assert abs(f2).max() < 0.00085
55if __name__ == '__main__':
56 from cProfile import Profile
57 prof = Profile()
58 prof.enable()
59 test_exx_double_cell(1)
60 prof.disable()
61 from gpaw.mpi import rank, size
62 prof.dump_stats(f'prof-{size}.{rank}')