Coverage for gpaw/test/pw/test_si_stress.py: 100%
19 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import numpy as np
2import pytest
3from ase.build import bulk
5from gpaw import GPAW, PW, Mixer
6from gpaw.mpi import world
9@pytest.mark.stress
10def test_pw_si_stress(in_tmp_dir, gpaw_new):
11 xc = 'PBE'
12 si = bulk('Si')
13 si.calc = GPAW(mode=PW(200),
14 mixer=Mixer(0.7, 5, 50.0),
15 xc=xc,
16 kpts=(1, 1, 2), # Run (1, 1, 2) to avoid gamma pt code
17 convergence={'energy': 1e-8},
18 parallel={'domain': min(2, world.size)},
19 txt='si_stress.txt')
21 si.set_cell(np.dot(si.cell,
22 [[1.02, 0, 0.03],
23 [0, 0.99, -0.02],
24 [0.2, -0.01, 1.03]]),
25 scale_atoms=True)
27 si.get_potential_energy()
29 if not gpaw_new:
30 # Trigger nasty bug (fixed in !486):
31 si.calc.wfs.pt.blocksize = si.calc.wfs.pd.maxmyng - 1
33 s_analytical = si.get_stress()
34 s_ref = [-0.16569446, -0.07630128, -0.1266625,
35 -0.06144752, -0.02055657, 0.04574812]
36 # si.calc.calculate_numerical_stress(si, 1e-5)
37 print(s_analytical)
38 s_err = s_analytical - s_ref
39 assert np.all(abs(s_err) < 1e-4)