Coverage for gpaw/test/lcao/test_scissors.py: 96%
26 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-08 00:17 +0000
1import pytest
2from ase import Atoms
3from gpaw.new.ase_interface import GPAW
4from gpaw.lcao.scissors import non_self_consistent_scissors_shift as nsc_shift
5from gpaw.spinorbit import soc_eigenstates
6from gpaw.mpi import world
9def test_scissors():
10 """Opens gap in one of two isolated H2 moleculs."""
11 h2 = Atoms('2H2', [[0, 0, 0], [0, 0, 0.74],
12 [4, 0, 0], [4, 0, 0.74]])
13 h2.center(vacuum=3.0)
14 d = 1.0
15 h2.calc = GPAW(mode='lcao',
16 basis='sz(dzp)',
17 eigensolver={'name': 'scissors',
18 'shifts': [(-d, d, 2)]},
19 symmetry='off',
20 parallel={'domain': 1,
21 'band': world.size,
22 'sl_auto': True},
23 txt=None)
24 h2.get_potential_energy()
25 eigs1 = h2.calc.get_eigenvalues()
27 i, ii, iii, iv = eigs1
28 assert ii - i == pytest.approx(d, abs=0.01)
29 assert iv - iii == pytest.approx(d, abs=0.01)
31 # Non self-consistent:
32 eigs2 = nsc_shift([(-d, d, 2)], h2.calc.dft)[0, 0]
33 assert eigs2 == pytest.approx(eigs1)
35 # Check also fixed-density calculations:
36 calc = h2.calc.fixed_density(kpts=[[0, 0, 0]])
37 eigs3 = calc.get_eigenvalues()
38 assert eigs3 == pytest.approx(eigs1)
40 # SOC corrections:
41 eigs4 = soc_eigenstates(calc).eigenvalues()[0]
42 assert eigs4[::2] == pytest.approx(eigs1)
43 assert eigs4[1::2] == pytest.approx(eigs1)
46if __name__ == '__main__':
47 test_scissors()