File: test_predict.py

package info (click to toggle)
dials 3.25.0%2Bdfsg3-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,112 kB
  • sloc: python: 134,740; cpp: 34,526; makefile: 160; sh: 142
file content (93 lines) | stat: -rw-r--r-- 2,521 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from __future__ import annotations

import shutil
import subprocess
from pathlib import Path

from dials.array_family import flex


def plausible(table):
    # Check the reflection IDs
    assert "id" in table
    assert "miller_index" in table
    assert "s1" in table
    assert "xyzcal.px" in table
    assert "xyzcal.mm" in table
    for row in table.rows():
        assert row["id"] == 0
    return True


def test_static_prediction(dials_data, tmp_path):
    result = subprocess.run(
        [
            shutil.which("dials.predict"),
            str(
                dials_data("misc_regression", pathlib=True)
                / "prediction-static-crystal.expt"
            ),
        ],
        cwd=tmp_path,
        capture_output=True,
    )
    assert not result.returncode and not result.stderr

    table = flex.reflection_table.from_file(tmp_path / "predicted.refl")
    assert len(table) == 1996
    assert plausible(table)


def test_scan_varying_prediction(dials_data, tmp_path):
    result = subprocess.run(
        [
            shutil.which("dials.predict"),
            str(
                dials_data("misc_regression", pathlib=True)
                / "prediction-varying-crystal.expt"
            ),
        ],
        cwd=tmp_path,
        capture_output=True,
    )
    assert not result.returncode and not result.stderr

    table = flex.reflection_table.from_file(tmp_path / "predicted.refl")
    assert len(table) == 1934
    assert plausible(table)


def test_force_static_prediction(dials_data, tmp_path):
    result = subprocess.run(
        [
            shutil.which("dials.predict"),
            str(
                dials_data("misc_regression", pathlib=True)
                / "prediction-varying-crystal.expt"
            ),
            "force_static=True",
        ],
        cwd=tmp_path,
    )
    assert not result.returncode and not result.stderr

    table = flex.reflection_table.from_file(tmp_path / "predicted.refl")
    assert len(table) == 1996
    assert plausible(table)


def test_experiment_parameters(dials_data: Path, tmp_path):
    result = subprocess.run(
        [
            shutil.which("dials.predict"),
            str(
                dials_data("misc_regression", pathlib=True)
                / "prediction-varying-crystal.expt"
            ),
        ],
        cwd=tmp_path,
    )
    assert not result.returncode and not result.stderr

    table = flex.reflection_table.from_file(tmp_path / "predicted.refl")
    assert table.experiment_identifiers()