Coverage for gpaw/test/corehole/test_si.py: 98%

42 statements  

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

1import pytest 

2import numpy as np 

3 

4from gpaw import GPAW 

5from gpaw.test import gen 

6from gpaw.xas import XAS, RecursionMethod 

7import gpaw.mpi as mpi 

8 

9 

10@pytest.mark.old_gpaw_only 

11def test_corehole_si(in_tmp_dir, add_cwd_to_setup_paths, gpw_files): 

12 # restart from file 

13 calc = GPAW(gpw_files['si_corehole_pw']) 

14 si = calc.atoms 

15 

16 if mpi.size == 1: 

17 xas = XAS(calc) 

18 x, y = xas.get_spectra() 

19 else: 

20 x = np.linspace(0, 10, 50) 

21 

22 k = 2 

23 calc = calc.new(kpts=(k, k, k)) 

24 calc.initialize(si) 

25 calc.set_positions(si) 

26 assert calc.wfs.dtype == complex 

27 

28 r = RecursionMethod(calc) 

29 r.run(40) 

30 if mpi.size == 1: 

31 z = r.get_spectra(x) 

32 

33 if 0: 

34 import matplotlib.pyplot as plt 

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

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

37 plt.plot(x, z[0]) 

38 plt.show() 

39 

40 # 2p corehole 

41 s = gen('Si', name='hch2p', corehole=(2, 1, 0.5), gpernode=30) 

42 calc = GPAW(gpw_files['si_corehole_pw'], 

43 setups={0: s}) 

44 si.calc = calc 

45 

46 def stopcalc(): 

47 calc.scf.converged = True 

48 

49 calc.attach(stopcalc, 1) 

50 _ = si.get_potential_energy() 

51 

52 

53def test_si_nonortho(in_tmp_dir, add_cwd_to_setup_paths, gpw_files): 

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

55 # restart from file 

56 # code moved to fixtures: si_corehole_sym, 

57 # si_corehole_nosym_pw, si_corehole_sym_pw 

58 calc1 = GPAW(gpw_files['si_corehole_sym_pw']) 

59 calc2 = GPAW(gpw_files['si_corehole_nosym_pw']) 

60 if mpi.size == 1: 

61 xas1 = XAS(calc1) 

62 x, y1 = xas1.get_spectra() 

63 xas2 = XAS(calc2) 

64 x2, y2 = xas2.get_spectra(E_in=x) 

65 

66 assert (np.sum(abs(y1 - y2)[0, :500]**2) < 5e-9) 

67 assert (np.sum(abs(y1 - y2)[1, :500]**2) < 5e-9) 

68 assert (np.sum(abs(y1 - y2)[2, :500]**2) < 5e-9)