Debian Codegraph @

tests/algorithms/symmetry/absences/test_laue_group_info.py

raw
1 """Test components of the dials.space_group program."""
2
3 from __future__ import annotations
4
5 import pytest
6
7 from dials.algorithms.symmetry.absences.laue_groups_info import (
8 laue_groups,
9 score_screw_axes,
10 score_space_groups,
11 )
12 from dials.array_family import flex
13
14
15 def test_score_screw_axes_equivalent_axes():
16 """Test the score_screw_axes function (when equivalent axes present)."""
17 laue_group_info = laue_groups["P m -3"]
18
19 # unique axis 21a, but should pick up 21b, 21c
20 reflections = flex.reflection_table()
21 reflections["miller_index"] = flex.miller_index(
22 [(0, 1, 0), (0, 2, 0), (0, 0, 1), (0, 0, 2)]
23 )
24 reflections["intensity"] = flex.double([0.05, 100.0, 0.02, 100.0])
25 reflections["variance"] = flex.double([1.0, 1.0, 1.0, 1.0])
26
27 axes, scores = score_screw_axes(laue_group_info, reflections)
28 assert len(scores) == 1
29 assert len(axes) == 1
30 assert axes[0].name == "21a"
31 assert scores[0] > 0.99
32
33
34 def test_score_space_group():
35 """Test scoring of space groups by combining axis scores."""
36
37 # simple case, P 1 21 2, single score
38 laue_group = laue_groups["P 1 2/m 1"]
39 axis_scores = [0.98] # 21 > P41212
40 space_groups, scores = score_space_groups(axis_scores, laue_group)
41 for sg, score in zip(space_groups, scores):
42 if sg == "P 21":
43 assert score == pytest.approx(0.98)
44 elif sg == "P 2":
45 assert score == pytest.approx(0.02)
46
47 # More complex case - only use 42 score in space groups where not 41
48 laue_group = laue_groups["P 4/m m m"]
49 axis_scores = [0.95, 1.0, 0.95] # 41, 21 and 42 score high > P41212
50 space_groups, scores = score_space_groups(axis_scores, laue_group)
51 for sg, score in zip(space_groups, scores):
52 if sg == "P 41 21 2":
53 assert score == pytest.approx(0.95)
54 elif sg == "P 42 21 2":
55 assert score == pytest.approx(0.05 * 0.95)
56 elif sg == "P 4 21 2":
57 assert score == pytest.approx(0.05 * 0.05)
58 else:
59 assert score == pytest.approx(0.0)
60
61 # More complex case - only use 62, 63 score in space groups where not 61
62 laue_group = laue_groups["P 6/m"]
63 axis_scores = [0.95, 0.9, 0.85] # 61, 62, 63
64 space_groups, scores = score_space_groups(axis_scores, laue_group)
65 for sg, score in zip(space_groups, scores):
66 if sg == "P 61":
67 assert score == pytest.approx(0.95)
68 elif sg == "P 62":
69 assert score == pytest.approx(0.05 * 0.9)
70 elif sg == "P 63":
71 assert score == pytest.approx(0.05 * 0.85)
72 elif sg == "P 6":
73 assert score == pytest.approx(0.05 * 0.1 * 0.15)