Coverage for gpaw/test/rsf_yukawa/test_rsf_general.py: 95%
37 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1"""Check for tunability of gamma for yukawa potential."""
2import pytest
3from ase import Atoms
4from gpaw import GPAW
5from gpaw.utilities.adjust_cell import adjust_cell
6from gpaw.eigensolvers import RMMDIIS
7from gpaw.xc.hybrid import HybridXC
8from gpaw.occupations import FermiDirac
9from gpaw.test import gen
10import gpaw.cgpaw as cgpaw
13@pytest.mark.hybrids
14def test_rsf_yukawa_rsf_general(in_tmp_dir, add_cwd_to_setup_paths):
15 libxc_version = getattr(cgpaw, 'libxc_version', '2.x.y')
16 if int(libxc_version.split('.')[0]) < 3:
17 from unittest import SkipTest
18 raise SkipTest
20 for atom in ['Be']:
21 gen(atom, xcname='PBE', scalarrel=True, exx=True,
22 yukawa_gamma=0.83, gpernode=149)
24 h = 0.35
25 be = Atoms('Be', positions=[[0, 0, 0]])
26 adjust_cell(be, 3.0, h=h)
28 c = {'energy': 0.05, 'eigenstates': 0.05, 'density': 0.05}
30 IP = 8.79
32 xc = HybridXC('LCY-PBE', omega=0.83)
33 fname = 'Be_rsf.gpw'
35 calc = GPAW(mode='fd', txt='Be.txt', xc=xc, convergence=c,
36 eigensolver=RMMDIIS(), h=h,
37 occupations=FermiDirac(width=0.0), spinpol=False)
38 be.calc = calc
39 energy_083 = be.get_potential_energy()
40 (eps_homo, eps_lumo) = calc.get_homo_lumo()
41 assert eps_homo == pytest.approx(-IP, abs=0.15)
42 xc2 = 'LCY-PBE'
43 energy_075 = calc.get_xc_difference(HybridXC(xc2))
44 assert energy_083 - energy_075 == pytest.approx(21.13, abs=0.2)
45 calc.write(fname)
46 calc2 = GPAW(fname)
47 xc = calc2.hamiltonian.xc
48 assert xc.name == 'LCY-PBE', 'wrong name for functional'
49 assert xc.omega == 0.83, 'wrong value for RSF omega'