Coverage for gpaw/test/pseudopotential/test_atompaw.py: 100%

28 statements  

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

1from gpaw.atom.atompaw import AtomPAW 

2from gpaw.upf import UPFSetupData 

3import gpaw.test.pseudopotential.H_pz_hgh as H_hgh 

4import gpaw.test.pseudopotential.O_pz_hgh as O_hgh 

5from gpaw.mpi import world 

6 

7 

8def test_pseudopotential_atompaw(in_tmp_dir): 

9 def check(title, calc, epsref_n, threshold): 

10 eps_n = calc.wfs.kpt_u[0].eps_n 

11 print(title) 

12 for i, epsref in enumerate(epsref_n): 

13 err = abs(epsref - eps_n[i]) 

14 ok = (err <= threshold) 

15 status = 'ok' if ok else 'FAILED' 

16 print('state %d | eps=%f | ref=%f | err=%f | tol=%s | %s' % 

17 (i, 

18 eps_n[i], 

19 epsref, 

20 err, 

21 threshold, 

22 status)) 

23 assert ok 

24 

25 # Load pseudopotential from Python module as string, then 

26 # write the string to a file, then load the file. 

27 def upf(upf_module, fname): 

28 with open(fname, 'w') as fd: 

29 fd.write(upf_module.ps_txt) 

30 return UPFSetupData(fname) 

31 

32 if world.rank == 0: # This test is not really parallel 

33 for setup in ['paw', 'hgh', upf(H_hgh, 'H.pz-hgh.UPF')]: 

34 calc = AtomPAW('H', [[[1]]], 

35 rcut=12.0, h=0.05, 

36 setups={'H': setup}, txt=None) 

37 # horrible UPF right now: 

38 tol = 5e-4 if setup in ['paw', 'hgh'] else 1e-3 

39 check('H %s' % setup, calc, [-0.233471], tol) 

40 

41 for setup in ['paw', 'hgh', upf(O_hgh, 'O.pz-hgh.UPF')]: 

42 calc = AtomPAW('O', [[[2], [4]]], 

43 rcut=10.0, h=0.035, 

44 setups={'O': setup}, txt=None) 

45 # horrible UPF right now: 

46 tol = 1e-3 if setup in ['paw', 'hgh'] else 5e-3 

47 check('O %s' % setup, calc, [-0.871362, -0.338381], tol)