Coverage for gpaw/test/pw/test_fe_stress_mgga.py: 95%

19 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-20 00:19 +0000

1import numpy as np 

2import pytest 

3from ase.io.ulm import ulmopen 

4from ase.parallel import parprint 

5 

6from gpaw import GPAW 

7 

8 

9@pytest.mark.mgga 

10def test_pw_fe_stress_mgga(gpw_files, gpaw_new): 

11 if gpaw_new and ulmopen(gpw_files['fe_pw_distorted']).version < 4: 

12 pytest.skip('Unsupported new-GPAW + old gpw-file combo') 

13 

14 fe = GPAW(gpw_files['fe_pw_distorted']).get_atoms() 

15 

16 # Trigger nasty bug (fixed in !486): 

17 if not gpaw_new: 

18 fe.calc.wfs.pt.blocksize = fe.calc.wfs.pd.maxmyng - 1 

19 

20 s_analytical = fe.get_stress() 

21 # Calculated numerical stress once, store here to speed up test 

22 # numerical stresses: 

23 # revTPSS stress: [0.03113369 -0.05080607 -0.03739338 

24 # -0.03096389 0.21181234 0.0114693] 

25 s_numerical = np.array([0.03113369, -0.05080607, -0.03739338, 

26 -0.03096389, 0.21181234, 0.0114693]) 

27 # s_numerical = fe.calc.calculate_numerical_stress(fe, 1e-5) 

28 s_err = s_numerical - s_analytical 

29 

30 parprint('Analytical stress:\n', s_analytical) 

31 parprint('Numerical stress:\n', s_numerical) 

32 parprint('Error in stress:\n', s_err) 

33 assert np.all(abs(s_err) < 1e-4)