Coverage for gpaw/test/corehole/test_h2o.py: 96%

26 statements  

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

1import numpy as np 

2import pytest 

3 

4import gpaw.mpi as mpi 

5from gpaw import GPAW 

6from gpaw.xas import XAS 

7 

8 

9@pytest.mark.old_gpaw_only 

10def test_corehole_h2o(in_tmp_dir, add_cwd_to_setup_paths, gpw_files): 

11 if mpi.size != 1: # 1 core only for now 

12 return 

13 

14 # Generate setup for oxygen with half a core-hole: 

15 calc = GPAW(gpw_files['h2o_xas']) 

16 

17 xas = XAS(calc) 

18 x, y = xas.get_spectra() 

19 e1_kn = xas.eps_kn 

20 de1 = e1_kn[0, 1] - e1_kn[0, 0] 

21 

22 if mpi.size == 1: 

23 # calc = GPAW('h2o-xas.gpw') 

24 # poissonsolver=FDPoissonSolver(use_charge_center=True)) 

25 # calc.initialize() 

26 xas = XAS(calc) 

27 x, y = xas.get_spectra() 

28 e2_kn = xas.eps_kn 

29 w_n = np.sum(xas.sigma_cmkn[:, 0, 0, :].real**2, axis=0) 

30 de2 = e2_kn[0, 1] - e2_kn[0, 0] 

31 

32 assert de2 == pytest.approx(2.0733, abs=0.005) 

33 assert w_n[1] / w_n[0] == pytest.approx(2.22, abs=0.01) 

34 

35 assert de1 == de2 

36 

37 xnl, ynl = xas.get_spectra(linbroad=[0.5, 540, 550]) 

38 assert len(xnl) == len(x) 

39 

40 if 0: 

41 import matplotlib.pyplot as plt 

42 plt.plot(x, y[0]) 

43 plt.plot(x, sum(y)) 

44 plt.show()