Coverage for gpaw/test/corehole/test_li2.py: 100%

26 statements  

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

1"""Test all electron density for right interpretation of coreholes""" 

2import pytest 

3from ase.build import molecule 

4from ase.units import Bohr 

5from gpaw import GPAW, PoissonSolver 

6from gpaw.mixer import Mixer 

7from gpaw.test import gen 

8 

9 

10@pytest.mark.old_gpaw_only 

11def test_aed_with_corehole_li(): 

12 """Compare number of electrons for different channels with corehole""" 

13 li_setup = gen('Li', name='fch1s', corehole=(1, 0, 1), xcname='PBE') 

14 grf = 1 

15 atoms = molecule('Li2') 

16 atoms.center(vacuum=2.5) 

17 

18 calc = GPAW(mode='fd', 

19 xc='PBE', 

20 mixer=Mixer(), 

21 setups={0: li_setup}, 

22 charge=-1, 

23 poissonsolver=PoissonSolver('fd')) 

24 atoms.calc = calc 

25 atoms.get_potential_energy() 

26 

27 n_sg = calc.get_all_electron_density(gridrefinement=grf) 

28 

29 ne_sz = calc.density.gd.integrate( 

30 n_sg, global_integral=False) * (Bohr / grf)**3 

31 assert ne_sz == pytest.approx(6.0, abs=1e-5) 

32 

33 atoms.set_initial_magnetic_moments([0.66, .34]) 

34 calc = calc.new(spinpol=True) 

35 atoms.calc = calc 

36 atoms.get_potential_energy() 

37 

38 for sz in range(2): 

39 n_sg = calc.get_all_electron_density(spin=sz, gridrefinement=grf) 

40 ne_sz = calc.density.gd.integrate( 

41 n_sg, global_integral=False) * (Bohr / grf)**3 

42 assert ne_sz == pytest.approx(3.0, abs=1e-5)