-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
64 lines (52 loc) · 2.45 KB
/
helpers.py
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
53
54
55
56
57
58
59
60
61
62
63
64
def compare_with_ground_truth(a, b, c, dxcryst_models, symbol="C121", verbose=False):
"""
:param a: ground truth a (real space)
:param b: ground truth b (real space)
:param c: gournd truth c (real space)
:param dxcryst_models: P1 models or whatever
:param symbol: target space group
:return: list of angles, one for each model
"""
from cctbx import sgtbx
from dxtbx.model import MosaicCrystalSauter2014
from cctbx import crystal_orientation
from libtbx.test_utils import approx_equal
from scitbx.array_family import flex
from scitbx.matrix import sqr
sgi = sgtbx.space_group_info(symbol=symbol)
CB_OP_C_P = sgi.change_of_basis_op_to_primitive_setting()
icount = 0
angles = []
icount += 1
for crystal_model in dxcryst_models:
if crystal_model.get_space_group().info().type().lookup_symbol() == "P 1":
crystal_model = crystal_model.change_basis(CB_OP_C_P.inverse())
mosaic_model = MosaicCrystalSauter2014(crystal_model)
direct_A = mosaic_model.get_A_inverse_as_sqr()
sim_compatible = direct_A
integrated_Ori = crystal_orientation.crystal_orientation(
sim_compatible,
crystal_orientation.basis_type.direct)
header_Ori = crystal_orientation.crystal_orientation(
tuple(a)+tuple(b)+tuple(c),
crystal_orientation.basis_type.direct)
C2_ground_truth = header_Ori.change_basis(CB_OP_C_P.inverse())
if verbose:
C2_ground_truth.show(legend="C2_ground_truth")
# align integrated model with ground truth
cb_op_align = integrated_Ori.best_similarity_transformation(C2_ground_truth, 50, 1)
aligned_Ori = integrated_Ori.change_basis(sqr(cb_op_align))
if verbose:
aligned_Ori.show(legend="integrated, aligned")
print("alignment matrix", cb_op_align)
U_integrated = aligned_Ori.get_U_as_sqr()
U_ground_truth = C2_ground_truth.get_U_as_sqr()
missetting_rot = U_integrated * U_ground_truth.inverse()
assert approx_equal(missetting_rot.determinant(), 1.0)
# now calculate the angle as mean a_to_a,b_to_b,c_to_c
aoff = aligned_Ori.a.angle(C2_ground_truth.a, deg=True)
boff = aligned_Ori.b.angle(C2_ground_truth.b, deg=True)
coff = aligned_Ori.c.angle(C2_ground_truth.c, deg=True)
hyp = flex.mean(flex.double((aoff, boff, coff)))
angles.append(hyp)
return angles