Coverage for gpaw/test/parallel/test_diamond_gllb.py: 21%
34 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1"""Calculate diamond with various parallelizations with GLLBSC."""
2import pytest
3from gpaw.mpi import world
4from ase.build import bulk
5from gpaw import GPAW, Mixer
8@pytest.mark.gllb
9@pytest.mark.skipif(world.size < 4,
10 reason='world.size < 4')
11def test_parallel_diamond_gllb(in_tmp_dir):
12 xc = 'GLLBSC'
13 KS_gap_ref = 4.180237125868162
14 QP_gap_ref = 5.469387490357182
15 # M. Kuisma et. al, https://doi.org/10.1103/PhysRevB.82.115106
16 # C: KS gap 4.14 eV, QP gap 5.41eV, expt. 5.48 eV
17 KSb = []
18 dxcb = []
20 eigensolver = 'rmm-diis'
22 for band in [1, 2, 4]:
23 # Calculate ground state
24 atoms = bulk('C', 'diamond', a=3.567)
25 calc = GPAW(mode='fd',
26 h=0.15,
27 kpts=(4, 4, 4),
28 xc=xc,
29 nbands=8,
30 mixer=Mixer(0.5, 5, 50.0),
31 eigensolver=eigensolver,
32 parallel={'band': band})
33 atoms.calc = calc
34 atoms.get_potential_energy()
36 # Calculate accurate KS-band gap from band structure
37 bs_calc = calc.fixed_density(kpts={'path': 'GX', 'npoints': 12},
38 symmetry='off',
39 nbands=8,
40 convergence={'bands': 8},
41 eigensolver=eigensolver)
42 # Get the accurate KS-band gap
43 homo, lumo = bs_calc.get_homo_lumo()
45 # Calculate the discontinuity potential with accurate band gap
46 response = calc.hamiltonian.xc.response
47 dxc_pot = response.calculate_discontinuity_potential(homo, lumo)
49 # Calculate the discontinuity using the band structure calculator
50 bs_response = bs_calc.hamiltonian.xc.response
51 KS_gap, dxc = bs_response.calculate_discontinuity(dxc_pot)
52 assert KS_gap == pytest.approx(lumo - homo, abs=1e-10)
53 assert KS_gap == pytest.approx(KS_gap_ref, abs=1e-4)
55 QP_gap = KS_gap + dxc
56 assert QP_gap == pytest.approx(QP_gap_ref, abs=1e-4)
57 KSb.append(KS_gap)
58 dxcb.append(dxc)
60 assert abs(KSb[0] - KSb[1]) < 1e-6
61 assert abs(KSb[0] - KSb[2]) < 1e-6
62 assert abs(dxcb[0] - dxcb[1]) < 1e-6
63 assert abs(dxcb[0] - dxcb[2]) < 1e-6