File: test_standard_form.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 (41 lines) | stat: -rw-r--r-- 1,211 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
"""Bravais lattice type check.

1) For each Bravais variant, check that we recognize the
standard cell correctly.

2) For those Bravais lattices that we can recognize in non-standard form,
   Niggli-reduce them and recognize them as well."""

import pytest
import numpy as np

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


variants = [lat for lat in all_variants() if lat.ndim == 3]


@pytest.mark.parametrize('lat', variants)
def test_lattice(lat):
    cell = lat.tocell()

    def check(lat1):
        print('check', repr(lat), '-->', repr(lat1))
        err = np.abs(cell.cellpar() - lat1.cellpar()).max()
        assert err < 1e-5, err

    check(get_lattice_from_canonical_cell(cell))

    if lat.name == 'TRI':
        # The TRI lattices generally permute (the ones we produce as
        # all_variants() are reduced to a form with smaller
        # orthogonality defect) which might be desirable but would
        # trigger an error in this test.
        return

    stdcell, op = identify_lattice(cell, 1e-4)
    check(stdcell)
    rcell, op = cell.niggli_reduce()
    stdcell, op = identify_lattice(rcell, 1e-4)
    check(stdcell)