File: test_elk.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (49 lines) | stat: -rw-r--r-- 1,707 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pytest

from ase.build import bulk


def systems():
    yield bulk('Si')
    atoms = bulk('Fe')
    atoms.set_initial_magnetic_moments([1.0])
    yield atoms


@pytest.mark.calculator_lite
@pytest.mark.parametrize('atoms', systems(),
                         ids=lambda atoms: str(atoms.symbols))
@pytest.mark.calculator('elk', tasks=0, ngridk=(3, 3, 3))
def test_elk_bulk(factory, atoms):
    calc = factory.calc()
    atoms.calc = calc
    spinpol = atoms.get_initial_magnetic_moments().any()
    props = atoms.get_properties(['energy', 'forces'])
    energy = props['energy']

    # Need more thorough tests.
    if str(atoms.symbols) == 'Si2':
        assert energy == pytest.approx(-15729.719246, abs=0.1)
        assert atoms.get_potential_energy() == pytest.approx(energy)

    # Since this is FileIO we tend to just load everything there is:
    expected_props = {
        'energy', 'free_energy', 'forces', 'ibz_kpoints',
        'eigenvalues', 'occupations'
    }

    assert expected_props < set(props)

    # TODO move to unittest based on random numbers
    # This really belongs in a test of the calculator method mixin
    assert calc.get_fermi_level() == props['fermi_level']
    assert calc.get_ibz_k_points() == pytest.approx(props['ibz_kpoints'])
    assert calc.get_k_point_weights() == pytest.approx(props['kpoint_weights'])

    I = slice(None)
    assert calc.get_eigenvalues(I, I) == pytest.approx(props['eigenvalues'])
    assert calc.get_occupation_numbers(I, I) == pytest.approx(
        props['occupations'])
    assert calc.get_spin_polarized() == spinpol
    assert calc.get_number_of_spins() == 1 + int(spinpol)
    assert calc.get_number_of_bands() == props['nbands']