Debian Codegraph @

tests/algorithms/symmetry/cosym/test_cosym_symmetry_analysis.py

raw
1 from __future__ import annotations
2
3 import numpy as np
4 import pytest
5
6 from cctbx import crystal, sgtbx, uctbx
7
8
9 def test_symmetry_analysis():
10 coords = np.array(
11 [
12 [0.835, 0.158],
13 [0.772, 0.104],
14 [0.108, 0.907],
15 [0.058, 0.76],
16 [0.926, 0.189],
17 [0.221, 0.888],
18 [0.957, 0.137],
19 [0.958, 0.143],
20 [-0.015, 0.726],
21 [-0.066, 0.29],
22 [0.135, 0.848],
23 [0.085, 0.788],
24 [0.897, 0.126],
25 [0.749, 0.073],
26 [0.166, 0.943],
27 [0.871, 0.248],
28 [0.116, 0.968],
29 [0.116, 0.973],
30 [0.706, 0.007],
31 [0.288, -0.055],
32 [0.137, 0.848],
33 [0.089, 0.78],
34 [0.893, 0.122],
35 [0.749, 0.077],
36 [0.165, 0.941],
37 [0.877, 0.242],
38 [0.114, 0.968],
39 [0.12, 0.971],
40 [0.716, 0.002],
41 [0.292, -0.062],
42 [0.841, 0.162],
43 [0.774, 0.104],
44 [0.1, 0.909],
45 [0.054, 0.761],
46 [0.927, 0.184],
47 [0.227, 0.88],
48 [0.957, 0.137],
49 [0.961, 0.143],
50 [-0.007, 0.716],
51 [-0.061, 0.287],
52 [0.13, 0.848],
53 [0.084, 0.783],
54 [0.898, 0.124],
55 [0.749, 0.075],
56 [0.169, 0.94],
57 [0.871, 0.247],
58 [0.114, 0.969],
59 [0.12, 0.969],
60 [0.717, 0.0],
61 [0.296, -0.066],
62 [0.84, 0.154],
63 [0.776, 0.103],
64 [0.104, 0.908],
65 [0.057, 0.755],
66 [0.925, 0.19],
67 [0.227, 0.883],
68 [0.958, 0.136],
69 [0.962, 0.143],
70 [-0.017, 0.724],
71 [-0.067, 0.295],
72 ]
73 )
74
75 sym_ops = [
76 sgtbx.rt_mx(s)
77 for s in ("-z,-y,-x", "y,z,x", "x,y,z", "-x,-z,-y", "z,x,y", "-y,-x,-z")
78 ]
79
80 crystal_symmetry = crystal.symmetry(
81 unit_cell=uctbx.unit_cell((98.33, 98.33, 135.99, 90, 90, 120)),
82 space_group_info=sgtbx.space_group_info("R3:H"),
83 ).minimum_cell()
84
85 from cctbx.sgtbx.lattice_symmetry import metric_subgroups
86
87 subgroups = metric_subgroups(
88 crystal_symmetry, max_delta=5, bravais_types_only=False
89 )
90
91 cb_op_inp_min = sgtbx.change_of_basis_op()
92
93 from dials.algorithms.symmetry.cosym import SymmetryAnalysis
94
95 analysis = SymmetryAnalysis(coords, sym_ops, subgroups, cb_op_inp_min)
96
97 assert analysis.best_solution.likelihood > 0.99
98 assert analysis.best_solution.confidence > 0.98
99 assert (
100 analysis.best_solution.subgroup["best_subsym"].space_group().type().number()
101 == 148
102 ) # R -3 :H
103 assert (
104 str(analysis)
105 == """\
106 Scoring individual symmetry elements
107 +--------------+--------+------+-----+-----------------+
108 | likelihood | Z-CC | CC | | Operator |
109 |--------------+--------+------+-----+-----------------|
110 | 0.087 | 1.96 | 0.2 | | 2 |(0, -1, 1) |
111 | 0.087 | 1.96 | 0.2 | | 2 |(-1, 0, 1) |
112 | 0.949 | 10 | 1 | *** | 3^-1 |(1, 1, 1) |
113 | 0.087 | 1.96 | 0.2 | | 2 |(-1, 1, 0) |
114 | 0.949 | 10 | 1 | *** | 3 |(1, 1, 1) |
115 +--------------+--------+------+-----+-----------------+
116 Scoring all possible sub-groups
117 +-------------------+-----+--------------+----------+--------+--------+---------+--------------------+
118 | Patterson group | | Likelihood | NetZcc | Zcc+ | Zcc- | delta | Reindex operator |
119 |-------------------+-----+--------------+----------+--------+--------+---------+--------------------|
120 | R -3 :H | *** | 0.995 | 8.04 | 10 | 1.96 | 0 | b-c,-a+c,a+b+c |
121 | P -1 | | 0.003 | -6.5 | 0 | 6.5 | 0 | a,b,c |
122 | R -3 m :H | | 0.001 | 6.5 | 6.5 | 0 | 0 | b-c,-a+c,a+b+c |
123 | C 1 2/m 1 | | 0 | -5.24 | 1.96 | 7.21 | 0 | -a-b,a-b,c |
124 | C 1 2/m 1 | | 0 | -5.24 | 1.96 | 7.21 | 0 | -b-c,b-c,a |
125 | C 1 2/m 1 | | 0 | -5.24 | 1.96 | 7.21 | 0 | -a-c,-a+c,b |
126 +-------------------+-----+--------------+----------+--------+--------+---------+--------------------+
127 Best solution: R -3 :H
128 Unit cell: 98.330, 98.330, 135.990, 90.000, 90.000, 120.000
129 Reindex operator: b-c,-a+c,a+b+c
130 Laue group probability: 0.995
131 Laue group confidence: 0.994"""
132 )
133
134 d = analysis.as_dict()
135 assert d["sym_op_scores"][0] == {
136 "cc": pytest.approx(0.19620531091685714),
137 "operator": "-x,-z,-y",
138 "likelihood": pytest.approx(0.08665625555575088),
139 "stars": "",
140 "z_cc": pytest.approx(1.9620531091685713),
141 }
142 assert d["subgroup_scores"][0] == {
143 "confidence": pytest.approx(0.9940687431995551),
144 "z_cc_for": pytest.approx(9.999725360190128),
145 "stars": "***",
146 "patterson_group": "-R 3",
147 "max_angular_difference": 0.0,
148 "likelihood": pytest.approx(0.995493024305035),
149 "cb_op": "-1/3*x+2/3*y-1/3*z,-2/3*x+1/3*y+1/3*z,1/3*x+1/3*y+1/3*z",
150 "z_cc_against": pytest.approx(1.9620621986200772),
151 "unit_cell": pytest.approx(
152 (
153 98.32999999999998,
154 98.32999999999998,
155 135.99,
156 90.0,
157 90.0,
158 119.99999999999999,
159 )
160 ),
161 "z_cc_net": pytest.approx(8.037663161570052),
162 }