Coverage for gpaw/test/ralda/test_ralda_He.py: 100%
29 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
1import pytest
2from ase import Atoms
4from gpaw import GPAW, FermiDirac
5from gpaw.mpi import serial_comm
6from gpaw.xc.fxc import FXCCorrelation
7from gpaw.xc.rpa import RPACorrelation
9pytestmark = pytest.mark.usefixtures('module_tmp_path')
12@pytest.fixture(scope='module')
13def calc():
14 a = 3.0
15 atoms = Atoms('He', cell=[a, a, a], pbc=True)
16 calc = GPAW(mode=dict(name='pw', ecut=200),
17 kpts=dict(size=(2, 2, 2), gamma=True),
18 nbands=2,
19 txt='gpaw.txt',
20 occupations=FermiDirac(0.001),
21 # FXCCorrelation needs a serial-comm GPAW object:
22 communicator=serial_comm)
23 atoms.calc = calc
24 atoms.get_potential_energy()
25 calc.diagonalize_full_hamiltonian(nbands=20)
26 return calc
29whyskip_rapbe = 'https://gitlab.com/gpaw/gpaw/-/issues/723'
32@pytest.mark.rpa
33@pytest.mark.response
34@pytest.mark.parametrize('xc, kwargs, ref_energy', [
35 ('RPA', dict(nlambda=16), -0.1054),
36 ('rALDA', dict(unit_cells=[1, 1, 2]), -0.0560),
37 pytest.param('rAPBE', dict(unit_cells=[1, 1, 2]), -0.0523,
38 marks=pytest.mark.skip(reason=whyskip_rapbe)),
39 ('rALDA', dict(avg_scheme='wavevector'), -0.0241),
40 ('rAPBE', dict(avg_scheme='wavevector'), -0.0288),
41])
42def test_ralda_ralda_energy_He(in_tmp_dir, scalapack, calc, xc, kwargs,
43 ref_energy):
44 ecuts = [20, 30]
45 fxc = FXCCorrelation(calc, xc=xc, ecut=ecuts, **kwargs)
46 energy = fxc.calculate()[-1]
48 assert energy == pytest.approx(ref_energy, abs=0.001)
50 if xc == 'RPA':
51 rpa = RPACorrelation(calc, nfrequencies=8, ecut=ecuts)
52 E_rpa1 = rpa.calculate()[-1]
53 assert E_rpa1 == pytest.approx(ref_energy, abs=0.001)