Coverage for gpaw/test/pipekmezey/test_pm_spin.py: 100%

19 statements  

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

1import pytest 

2from ase import Atoms 

3from gpaw import GPAW 

4from gpaw.pipekmezey.pipek_mezey_wannier import PipekMezey 

5 

6 

7@pytest.mark.pipekmezey 

8def test_pipekmezey_spin(in_tmp_dir): 

9 

10 atoms = Atoms('O2', 

11 positions=[[0, 0, 0], 

12 [0, 0, 1.207]]) 

13 atoms.center(vacuum=5) 

14 

15 calc = GPAW(mode='fd', 

16 h=0.24, 

17 convergence={'density': 1e-4, 

18 'eigenstates': 1e-4}, 

19 hund=True) 

20 

21 calc.atoms = atoms 

22 calc.calculate() 

23 

24 # Spin 0 

25 PM = PipekMezey(calc=calc, 

26 spin=0, 

27 seed=42) 

28 PM.localize() 

29 

30 P = PM.get_function_value() 

31 

32 assert P == pytest.approx(5.973, abs=0.001) 

33 

34 # Spin 1 

35 PM = PipekMezey(calc=calc, 

36 spin=1, 

37 seed=42) 

38 PM.localize() 

39 

40 P = PM.get_function_value() 

41 

42 assert P == pytest.approx(3.315, abs=0.001)