File: test_lattices.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (46 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download
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
# fmt: off
import numpy as np
import pytest

from ase.lattice import (
    all_variants,
    bravais_lattices,
    get_lattice_from_canonical_cell,
)


@pytest.mark.parametrize('name', list(bravais_lattices))
def test_bravais_lattices(name):
    latcls = bravais_lattices[name]
    assert latcls.name == name
    assert latcls.longname is not None
    for par in latcls.parameters:
        assert par in ['a', 'b', 'c', 'alpha', 'beta', 'gamma']


@pytest.mark.parametrize('lat', list(all_variants()),
                         ids=lambda lat: lat.variant)
def test_variants(lat):
    print(lat.variant)
    for par in lat.parameters:
        print(par, getattr(lat, par))

    print('cell', lat.tocell())
    cell = lat.tocell()
    if lat.name in ['TRI']:
        # Automatic check not implemented for these cell types, but we
        # can still recognize the canonical form:
        lat1 = get_lattice_from_canonical_cell(cell)
    else:
        lat1 = cell.get_bravais_lattice()
    assert lat1.name == lat.name, (lat1.name, lat.name)
    assert lat1.variant == lat.variant
    assert np.abs(cell - lat1.tocell()).max() < 1e-13
    print('cellpar', lat.cellpar())
    print('special path', lat.special_path)
    arr = lat.get_special_points_array()
    assert arr.shape == (len(lat.special_point_names), 3)

    dct = lat.get_special_points()
    assert len(dct) == len(lat.special_point_names)
    print(lat)