| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import copy |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from dxtbx.serialize import load |
| 8 |
|
| 9 |
from dials.algorithms.profile_model.ellipsoid.algorithm import run_ellipsoid_refinement |
| 10 |
from dials.algorithms.profile_model.ellipsoid.indexer import reindex |
| 11 |
from dials.array_family import flex |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.xdist_group(name="group1") |
| 15 |
def test_run_ellipsoid_refinement(dials_data): |
| 16 |
# Download data set and the internally referenced images |
| 17 |
ssx = dials_data("cunir_serial_processed") |
| 18 |
dials_data("cunir_serial") |
| 19 |
|
| 20 |
refls = flex.reflection_table.from_file(ssx / "indexed.refl") |
| 21 |
expts = load.experiment_list(ssx / "indexed.expt", check_format=False)[0:1] |
| 22 |
refls = refls.select_on_experiment_identifiers([expts[0].identifier]) |
| 23 |
refls = reindex(refls, expts[0]) |
| 24 |
|
| 25 |
e_simple1 = {"spherical": 0.00027709} |
| 26 |
e_simple6 = {"min": 5.93276e-5, "mid": 0.00019659, "max": 0.00043976} |
| 27 |
|
| 28 |
initial_crystal = copy.deepcopy(expts[0].crystal) |
| 29 |
for model, expected in zip( |
| 30 |
["simple1", "simple6"], |
| 31 |
[e_simple1, e_simple6], |
| 32 |
): |
| 33 |
elist = copy.deepcopy(expts[0:1]) |
| 34 |
out_expt, _, __ = run_ellipsoid_refinement( |
| 35 |
elist, refls, 0.00062, profile_model=model |
| 36 |
) |
| 37 |
for k, v in out_expt.profiles()[0].mosaicity().items(): |
| 38 |
assert expected[k] == pytest.approx(v, abs=1e-4) |
| 39 |
assert ( |
| 40 |
out_expt[0].crystal.get_unit_cell().parameters() |
| 41 |
!= initial_crystal.get_unit_cell().parameters() |
| 42 |
) |
| 43 |
assert list(out_expt[0].crystal.get_A()) != list(initial_crystal.get_A()) |
| 44 |
del elist[0].crystal.mosaicity |
| 45 |
|
| 46 |
# now try fix uc |
| 47 |
elist = copy.deepcopy(expts[0:1]) |
| 48 |
out_expt, _, __ = run_ellipsoid_refinement( |
| 49 |
elist, |
| 50 |
refls, |
| 51 |
0.00062, |
| 52 |
profile_model="simple6", |
| 53 |
fix_orientation=True, |
| 54 |
fix_unit_cell=True, |
| 55 |
) |
| 56 |
for k, v in out_expt.profiles()[0].mosaicity().items(): |
| 57 |
assert e_simple6[k] == pytest.approx(v, abs=1e-4) |
| 58 |
assert out_expt[0].crystal.get_unit_cell().parameters() == pytest.approx( |
| 59 |
initial_crystal.get_unit_cell().parameters(), abs=1e-12 |
| 60 |
) |
| 61 |
assert list(out_expt[0].crystal.get_A()) == pytest.approx( |
| 62 |
list(initial_crystal.get_A()), abs=1e-12 |
| 63 |
) |