Coverage for gpaw/test/gllb/test_ne.py: 97%

31 statements  

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

1import pytest 

2from ase import Atoms, Atom 

3from gpaw import GPAW 

4from gpaw.atom.generator import Generator 

5from gpaw.atom.configurations import parameters 

6from gpaw.mpi import world 

7 

8 

9@pytest.mark.gllb 

10@pytest.mark.libxc 

11def test_gllb_ne(in_tmp_dir, add_cwd_to_setup_paths): 

12 atom = 'Ne' 

13 

14 for xcname in ['GLLBSC', 'GLLB']: 

15 if world.rank == 0: 

16 g = Generator(atom, xcname=xcname, scalarrel=False, nofiles=True) 

17 g.run(**parameters[atom]) 

18 eps = g.e_j[-1] 

19 else: 

20 eps = 0.0 

21 eps = world.sum_scalar(eps) 

22 world.barrier() 

23 

24 a = 5 

25 Ne = Atoms([Atom(atom, (0, 0, 0))], 

26 cell=(a, a, a), pbc=False) 

27 Ne.center() 

28 calc = GPAW(mode='fd', nbands=7, h=0.25, xc=xcname) 

29 Ne.calc = calc 

30 e = Ne.get_potential_energy() 

31 # Calculate the discontinuity 

32 homo, lumo = calc.get_homo_lumo() 

33 response = calc.hamiltonian.xc.response 

34 dxc_pot = response.calculate_discontinuity_potential(homo, lumo) 

35 response.calculate_discontinuity(dxc_pot) 

36 

37 eps3d = calc.wfs.kpt_u[0].eps_n[3] 

38 # if world.rank == 0: 

39 assert eps == pytest.approx(eps3d, abs=1e-3) 

40 # Correct for small cell +0.14eV (since the test needs to be fast 

41 # in test suite) 

42 assert e + 0.147106041 == pytest.approx(0, abs=5e-2)