Coverage for gpaw/test/test_aeatom.py: 100%

41 statements  

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

1import pytest 

2from gpaw.atom.aeatom import AllElectronAtom, c 

3 

4 

5@pytest.mark.ci 

6@pytest.mark.serial 

7def test_aeatom(): 

8 Z = 79 # gold atom 

9 kwargs = dict(ngpts=5000, alpha2=1000 * Z**2, ngauss=200) 

10 

11 # Test Schroedinger equation: 

12 aea = AllElectronAtom(Z, log=None) 

13 aea.initialize(**kwargs) 

14 

15 errors = [] 

16 for channel in aea.channels: 

17 vr_g = channel.basis.rgd.empty() 

18 vr_g[:] = -Z 

19 # Basis set of Gaussians: 

20 channel.solve(vr_g) 

21 for n in range(7): 

22 e = channel.e_n[n] 

23 e0 = -0.5 * Z**2 / (n + channel.l + 1)**2 

24 errors.append(abs(e / e0 - 1)) 

25 

26 # Finite-difference: 

27 channel.solve2(vr_g, scalar_relativistic=False, Z=Z) 

28 for n in range(7): 

29 e = channel.e_n[n] 

30 e0 = -0.5 * Z**2 / (n + channel.l + 1)**2 

31 errors.append(abs(e / e0 - 1)) 

32 

33 print(max(errors)) 

34 assert max(errors) == pytest.approx(0, abs=2.0e-5) 

35 

36 # Test Dirac equation: 

37 aea = AllElectronAtom(Z, dirac=True, log=None) 

38 aea.initialize(**kwargs) 

39 

40 errors = [] 

41 for channel in aea.channels: 

42 vr_g = channel.basis.rgd.empty() 

43 vr_g[:] = -Z 

44 channel.solve(vr_g) 

45 for n in range(7): 

46 e = channel.e_n[n] 

47 if channel.k > 0: 

48 n += 1 

49 e0 = (1 + 

50 (Z / c)**2 / 

51 ((channel.k**2 - (Z / c)**2)**0.5 + n)**2)**-0.5 - 1 

52 e0 *= c**2 

53 errors.append(abs(e / e0 - 1)) 

54 

55 print(max(errors)) 

56 assert max(errors) == pytest.approx(0, abs=4.0e-5)