Coverage for gpaw/test/solvation/test_lrtddft.py: 100%

26 statements  

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

1from ase.build import molecule 

2 

3import pytest 

4import gpaw.solvation as solv 

5from gpaw.utilities.adjust_cell import adjust_cell 

6from gpaw.lrtddft import LrTDDFT 

7from gpaw import PoissonSolver 

8 

9 

10@pytest.mark.old_gpaw_only 

11def test_solvation_lrtddft(): 

12 h = 0.3 

13 vac = 3.0 

14 

15 atoms = molecule('H2') 

16 adjust_cell(atoms, vac, h) 

17 

18 calc = solv.SolvationGPAW( 

19 mode='fd', xc='PBE', h=0.2, # non-solvent DFT parameters 

20 nbands=3, 

21 convergence={'energy': 0.1, 'eigenstates': 0.01, 'density': 0.1}, 

22 # convenient way to use HW14 water parameters: 

23 **solv.get_HW14_water_kwargs()) 

24 

25 # do the ground state calculation 

26 atoms.calc = calc 

27 atoms.get_potential_energy() 

28 print(id(calc.hamiltonian.poisson.dielectric)) 

29 print(id(calc.hamiltonian.dielectric)) 

30 

31 # linear response using ground state Poisson 

32 lrw = LrTDDFT(calc) 

33 lrw.diagonalize() 

34 

35 # We test the agreement of a pure RPA kernel 

36 # with setting eps to 1 

37 

38 lr = LrTDDFT(calc, 

39 poisson=PoissonSolver('fd', nn=calc.hamiltonian.poisson.nn)) 

40 lr.diagonalize() 

41 

42 calc.hamiltonian.poisson.dielectric.epsinf = 1. 

43 lr1 = LrTDDFT(calc) 

44 lr1.diagonalize() 

45 for ex, ex1 in zip(lr, lr1): 

46 assert ex.energy == pytest.approx(ex1.energy, abs=1e-14)