File: test_space_group_data.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 (52 lines) | stat: -rw-r--r-- 1,669 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
50
51
52
import pytest
import numpy as np
from numpy.testing import assert_allclose
from ase.spacegroup import (get_bravais_class,
                            get_point_group,
                            polar_space_group,
                            Spacegroup)
from ase.spacegroup.spacegroup import SpacegroupNotFoundError
import ase.lattice


TOL = 1E-10

functions = [get_bravais_class, get_point_group, polar_space_group]


@pytest.mark.parametrize("sg,lattice,point_group,polar",
                         [[100, ase.lattice.TET, '4mm', True],
                          [225, ase.lattice.FCC, '4/m -3 2/m', False]])
def test_valid_spacegroup(sg, lattice, point_group, polar):
    assert get_bravais_class(sg) == lattice
    assert get_point_group(sg) == point_group
    assert polar_space_group(sg) == polar


@pytest.mark.parametrize("func", functions)
def test_nonpositive_spacegroup(func):
    with pytest.raises(ValueError, match="positive"):
        func(0)


@pytest.mark.parametrize("func", functions)
def test_bad_spacegroup(func):
    with pytest.raises(ValueError, match="Bad"):
        func(400)


def _spacegroup_reciprocal_cell(no, setting):
    try:
        sg = Spacegroup(no, setting)
    except SpacegroupNotFoundError:
        return
    reciprocal_check = np.linalg.inv(sg.scaled_primitive_cell).T
    assert_allclose(sg.reciprocal_cell, reciprocal_check, atol=TOL)


def test_spacegroup_reciprocal_cell():
    # Would be better to use pytest.mark.parametrize if we can figure out
    # how to not list hundreds of test cases in the output.
    for setting in [1, 2]:
        for no in range(1, 231):
            _spacegroup_reciprocal_cell(setting, no)