Coverage for gpaw/test/mom/test_mom_lcao_smearing.py: 100%

25 statements  

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

1import pytest 

2from gpaw import GPAW, restart 

3from gpaw.mom import prepare_mom_calculation 

4 

5 

6@pytest.mark.mom 

7def test_mom_lcao_smearing(in_tmp_dir, gpw_files): 

8 calc = GPAW(gpw_files['co_mom']) 

9 E_gs = calc.get_potential_energy() 

10 

11 f_sn = [] 

12 for spin in range(calc.get_number_of_spins()): 

13 f_n = calc.get_occupation_numbers(spin=spin) 

14 f_sn.append(f_n) 

15 

16 ne0_gs = f_sn[0].sum() 

17 f_sn[0][3] -= 1. 

18 f_sn[0][5] += 1. 

19 

20 # Test both MOM and fixed occupations with Gaussian smearing 

21 for i in [True, False]: 

22 atoms, calc = restart(gpw_files['co_mom']) 

23 

24 # Excited-state calculation with Gaussian 

25 # smearing of the occupation numbers 

26 prepare_mom_calculation(calc, atoms, 

27 numbers=f_sn, 

28 width=0.01, 

29 use_fixed_occupations=i) 

30 E_es = atoms.get_potential_energy() 

31 

32 f_n0 = calc.get_occupation_numbers(spin=0) 

33 ne0_es = f_n0.sum() 

34 

35 dE = E_es - E_gs 

36 dne0 = ne0_es - ne0_gs 

37 print(dE) 

38 assert dE == pytest.approx(9.8445603513, abs=0.01) 

39 assert dne0 == pytest.approx(0.0, abs=1e-16)