Coverage for gpaw/test/rsf_yukawa/test_lrtddft_short.py: 95%

39 statements  

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

1"""Check TDDFT ionizations with Yukawa potential.""" 

2import pytest 

3from ase import Atoms 

4from ase.units import Hartree 

5 

6import gpaw.cgpaw as cgpaw 

7from gpaw import GPAW 

8from gpaw.utilities.adjust_cell import adjust_cell 

9from gpaw.eigensolvers import RMMDIIS 

10from gpaw.lrtddft import LrTDDFT 

11from gpaw.mpi import world 

12from gpaw.occupations import FermiDirac 

13 

14 

15@pytest.mark.hybrids 

16def test_rsf_yukawa_lrtddft_short(in_tmp_dir): 

17 libxc_version = getattr(cgpaw, 'libxc_version', '2.x.y') 

18 if int(libxc_version.split('.')[0]) < 3: 

19 from unittest import SkipTest 

20 raise SkipTest 

21 

22 o_plus = Atoms('Be', positions=[[0, 0, 0]]) 

23 o_plus.set_initial_magnetic_moments([1.0]) 

24 adjust_cell(o_plus, 2.5, h=0.35) 

25 

26 def get_paw(**kwargs): 

27 """Return calculator object.""" 

28 c = {'energy': 0.05, 'eigenstates': 0.05, 'density': 0.05} 

29 return GPAW(mode='fd', convergence=c, eigensolver=RMMDIIS(), 

30 nbands=3, 

31 xc='PBE', 

32 parallel={'domain': world.size}, h=0.35, 

33 occupations=FermiDirac(width=0.0, fixmagmom=True), 

34 **kwargs) 

35 

36 calc_plus = get_paw(txt='Be_plus_PBE.log', charge=1) 

37 o_plus.calc = calc_plus 

38 o_plus.get_potential_energy() 

39 

40 calc_plus = calc_plus.new(xc='LCY-PBE:omega=0.83:unocc=True', 

41 txt='Be_plus_LCY_PBE_083.log') 

42 o_plus.calc = calc_plus 

43 o_plus.get_potential_energy() 

44 

45 lr = LrTDDFT(calc_plus, txt='LCY_TDDFT_Be.log', 

46 restrict={'istart': 0, 'jend': 1}) 

47 assert lr.xc.omega == pytest.approx(0.83, abs=0.0) 

48 lr.write('LCY_TDDFT_Be.ex.gz') 

49 e_ion = 9.3 

50 ip_i = 13.36 

51 # reading is problematic with EXX on more than one core 

52 if world.rank == 0: 

53 lr2 = LrTDDFT.read('LCY_TDDFT_Be.ex.gz') 

54 lr2.diagonalize() 

55 assert lr2.xc.omega == pytest.approx(0.83, abs=0.0) 

56 ion_i = lr2[0].get_energy() * Hartree + e_ion 

57 assert ion_i == pytest.approx(ip_i, abs=0.3)