Coverage for gpaw/test/lrtddft/test_select.py: 100%

36 statements  

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

1import pytest 

2from ase import Atoms 

3from gpaw import GPAW, FermiDirac 

4from gpaw.lrtddft import LrTDDFT 

5 

6 

7@pytest.fixture 

8def oxygen(): 

9 atoms = Atoms('O') 

10 atoms.cell = [3, 4, 5] 

11 atoms.center() 

12 

13 atoms.calc = GPAW(mode='fd', 

14 occupations=FermiDirac(width=0.1), 

15 nbands=5) 

16 atoms.get_potential_energy() 

17 return atoms 

18 

19 

20@pytest.mark.lrtddft 

21def test_digonalize(oxygen): 

22 """Test selection at diagonalization stage""" 

23 lr = LrTDDFT(oxygen.calc) 

24 

25 # all 

26 lr.diagonalize() 

27 assert len(lr) == 10 

28 

29 lr.diagonalize(restrict={'istart': 3}) 

30 assert len(lr) == 1 

31 

32 lr.diagonalize(restrict={'jend': 1}) 

33 assert len(lr) == 1 

34 

35 lr.diagonalize(restrict={'eps': 0.75}) 

36 assert len(lr) == 2 

37 

38 lr.diagonalize(restrict={'energy_range': 1}) 

39 assert len(lr) == 3 

40 

41 lr.diagonalize(restrict={'from': [0], 'to': [3, 4]}) 

42 assert len(lr) == 2 

43 

44 

45@pytest.mark.lrtddft 

46def test_window(oxygen): 

47 """Test window selection at calculation step""" 

48 froml = [0, 1] 

49 tol = [4] 

50 lr = LrTDDFT(oxygen.calc, restrict={'from': froml, 'to': tol}) 

51 assert len(lr) == len(froml) * len(tol) 

52 for ks in lr.kss: 

53 assert ks.i in froml 

54 assert ks.j in tol