feat(gui): rework the smart rotation dose strategy
CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / lint (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
Take the DAQ inputs at face value and solve the collection per beamline instead of applying stacked fudge factors. - Resolution is used as reported: the DAQ estimate is no longer biased, so the -0.2 A shift and the 1/(1/d + 0.1) reciprocal-space push are gone. d_tar now drives both the dose budget and the detector distance. - The crystal is assumed to fill the beam, so the sqrt(xtal_y * xtal_z) dilution of the dose rate is dropped. Under that assumption the beam dose rate is the diffraction-weighted rate, which is the damage-relevant one; averaging over unilluminated volume was under-reporting it. The redundant "Calculated Dose (xtal size)" row goes with it -- it was also being fed a rate under an MGy label. - Flux comes from DAQStatus at 100% transmission, replacing the hardcoded 2.5e11 that disagreed with the flux the panel displayed. - Beamline split: X10SA pins the detector at 100 Hz and solves for transmission; X06DA holds transmission at 100% and solves for exposure time, falling back to transmission at the exposure floor. When the budget cannot be spent at full beam we cap at 100% and flag the under-dose rather than stretching the frame. - Respect bl.dtz_min / bl.dtz_max (replacing the hardcoded 108 mm) and the per-beamline exposure floor, with 2 ms stated explicitly for X06DA. - Move the cryo/room-temperature switch from 250 K to the protein-solvent glass transition at 200 K. Warkentin & Thorne fit two Arrhenius regimes either side of ~200 K; applying the cryo budget in the 200-250 K band overdosed there by close to an order of magnitude. - Snap detector distance to 10 mm, transmission to two significant digits and exposure to 1 ms. Every snap rounds in the direction that under-spends the dose budget; dtz floors because calc_dtz_mm returns the largest distance that still puts d_tar on the detector edge. Dose constants are now named and carry their citations (Holton 2009 for kdose, Howells for the 10 MGy/A half-dose, Owen for the room-temperature limit) instead of appearing as bare literals. Fixed while in here: - "Total angle" was wired to the resolution field's newValue, so editing it never recalculated. - self.transmission was only assigned inside update_calculated_labels, which early-returns without a DAQ status, so "Run rotation" could raise AttributeError before the first status arrived. - "Total measurement time" reported the beam-on budget, not wall-clock; those differ whenever transmission is below 100%. - run_measurement re-read the widgets instead of sending the last calculated solution, so dtz, exposure and transmission could be mixed across edits. - Dropped a dead wavelength_angstrom None branch: it is a computed property on DiffractionGeometry and cannot be None. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018JVrLMLGNUXhfJjWxUcTBj
This commit is contained in:
1 parent
57f97d9e66
commit
c619d25c96
1 file changed
+241
-100
@@ -1,18 +1,92 @@
|
||||
import math
|
||||
|
||||
from aarecommon.config.beamline import mx_beamline
|
||||
from aarecommon.config.logger import setup_logger
|
||||
from aarecommon.models.beamline import MXBeamline
|
||||
from aarecommon.models.models import CrystalSize, DAQStatusModel, SimpleScanParameters
|
||||
from aarecommon.models.rotation_scan import RotationScanRequest
|
||||
from PySide6.QtCore import Qt, Signal, Slot
|
||||
from PySide6.QtWidgets import QGridLayout, QLabel, QPushButton, QSizePolicy, QSpacerItem, QWidget
|
||||
|
||||
from aare.gui.constants import LOGGER_NAME
|
||||
from aare.gui.panels.rotation_data_collection import add_data_to_path
|
||||
from aare.gui.panels.rotation_data_collection import (
|
||||
MAX_OMEGA_SPEED_DEG_S,
|
||||
MIN_EXP_TIME_S,
|
||||
add_data_to_path,
|
||||
)
|
||||
from aare.gui.styles import ABORT_TEXT, GO_TEXT, STATUS_ALERT
|
||||
from aare.gui.widgets.number_line_edit import NumberLineEdit
|
||||
|
||||
logger = setup_logger(LOGGER_NAME)
|
||||
|
||||
# --- Dose model -----------------------------------------------------------
|
||||
# kdose: photons um^-2 needed per Gy at lambda = 1 A, from Holton (2009)
|
||||
# J. Synchrotron Rad. 16, 133-142. The lambda^2 scaling below is the
|
||||
# photoelectric limit (mu_en/rho ~ lambda^3, photon energy ~ 1/lambda) and
|
||||
# assumes negligible heavy-metal content; Se-Met and metalloprotein crystals
|
||||
# absorb more than this, so use RADDOSE-3D for those.
|
||||
KDOSE_1A_PH_UM2_GY = 2000.0
|
||||
|
||||
# Howells et al. put the half-dose at 10 MGy per A of resolution; we budget
|
||||
# half of that, so the target resolution keeps roughly 70% of its intensity.
|
||||
CRYO_DOSE_PER_ANGSTROM_MGY = 10.0
|
||||
# Above the glass transition the crystal dies ~2 orders of magnitude faster.
|
||||
# Owen et al. measured D(1/2) ~ 0.38 MGy at room temperature and Holton's
|
||||
# lifetime calculator defaults to 0.2 MGy; 0.1 MGy/A with the same safety
|
||||
# factor sits just below both.
|
||||
RT_DOSE_PER_ANGSTROM_MGY = 0.1
|
||||
DOSE_SAFETY_FACTOR = 2.0
|
||||
|
||||
# Protein-solvent glass transition. Warkentin & Thorne fit two Arrhenius
|
||||
# regimes either side of ~200 K: below it damage is athermal (Ea ~ 1 kJ/mol),
|
||||
# above it diffusion-dominated (Ea ~ 18 kJ/mol) and the cryo budget no longer
|
||||
# applies. Switching at 250 K would apply the cryo budget in the 200-250 K
|
||||
# band and overdose there by close to an order of magnitude.
|
||||
GLASS_TRANSITION_K = 200.0
|
||||
|
||||
# --- Strategy quantisation ------------------------------------------------
|
||||
# Detector frame rate we pin on the flux-rich beamline (X10SA), where the
|
||||
# strategy solves for transmission instead of exposure time.
|
||||
FIXED_FRAME_RATE_HZ = 100.0
|
||||
DEFAULT_MIN_EXP_TIME_S = 0.0005
|
||||
# Shortest frame the strategy will ask a beamline for, where that is longer
|
||||
# than the detector's own floor in MIN_EXP_TIME_S. X06DA's detector reaches
|
||||
# 1/900 s, but 2 ms is the shortest usable frame for a strategy collection
|
||||
# there. Stated explicitly so it does not silently drop to 1.2 ms if
|
||||
# EXP_TIME_STEP_S is ever made finer.
|
||||
STRATEGY_MIN_EXP_TIME_S = {MXBeamline.X06DA: 0.002}
|
||||
DTZ_STEP_MM = 10.0
|
||||
EXP_TIME_STEP_S = 0.001
|
||||
TRANSMISSION_SIG_DIGITS = 2
|
||||
|
||||
|
||||
# Grid steps are not representable in binary (0.001, 0.1, ...), so an exact
|
||||
# multiple can land a hair either side of the integer. Without this tolerance
|
||||
# _floor_to(1.7, 0.1) returns 1.6 and _ceil_to(0.011, 0.001) returns 0.012.
|
||||
_QUANT_EPS = 1e-9
|
||||
|
||||
|
||||
def _floor_to(value: float, step: float) -> float:
|
||||
# Rounded back to 12 dp so the result is a clean grid value: 17 * 0.1 is
|
||||
# 1.7000000000000002, which would be displayed and emitted verbatim.
|
||||
return round(math.floor(value / step + _QUANT_EPS) * step, 12)
|
||||
|
||||
|
||||
def _ceil_to(value: float, step: float) -> float:
|
||||
return round(math.ceil(value / step - _QUANT_EPS) * step, 12)
|
||||
|
||||
|
||||
def _floor_significant(value: float, digits: int) -> float:
|
||||
"""Round down to `digits` significant digits.
|
||||
|
||||
Down, not nearest: every quantisation in the strategy is allowed to spend
|
||||
less than the dose budget but never more.
|
||||
"""
|
||||
if value <= 0.0:
|
||||
return 0.0
|
||||
step = 10.0 ** (math.floor(math.log10(value) + _QUANT_EPS) - (digits - 1))
|
||||
return _floor_to(value, step)
|
||||
|
||||
|
||||
class SimpleRotationSettingsPanel(QWidget):
|
||||
rotation_scan = Signal(RotationScanRequest)
|
||||
@@ -23,7 +97,10 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
|
||||
super().__init__(parent)
|
||||
|
||||
self._beamline = mx_beamline()
|
||||
self.n_images = 1
|
||||
self.transmission = 1.0
|
||||
self.delivered_dose_MGy = 0.0
|
||||
self.xtal_size_dose_rate_MGy_s = None
|
||||
self.xtal_size = CrystalSize(x=0, y=0, z=0)
|
||||
self.xtal_x = None
|
||||
@@ -69,6 +146,7 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
self.omega_button.setFixedWidth(30)
|
||||
self.omega_button.clicked.connect(self.update_omega_start)
|
||||
self._layout.addWidget(self.omega_button, 1, 5)
|
||||
self.start_angle_enter.newValue.connect(self.set_start_angle)
|
||||
|
||||
# Angular range (entry)
|
||||
self._layout.addWidget(QLabel("Total angle", parent=self), 2, 0)
|
||||
@@ -77,7 +155,7 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
)
|
||||
self._layout.addWidget(self.angular_range_enter, 2, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("°", parent=self), 2, 4)
|
||||
self.visible_res_enter.newValue.connect(self.set_total_angle)
|
||||
self.angular_range_enter.newValue.connect(self.set_total_angle)
|
||||
|
||||
self._layout.addWidget(QLabel("Image angle", parent=self), 3, 0)
|
||||
self.image_angle_enter = NumberLineEdit(
|
||||
@@ -179,52 +257,44 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
self._layout.addWidget(self.xtal_z_label, 16, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("um", parent=self), 16, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("Calculated Dose (xtal size)", parent=self), 17, 0)
|
||||
self.xtal_size_dose_label = QLabel("--", parent=self)
|
||||
self.xtal_size_dose_label.setAlignment(
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
|
||||
)
|
||||
self._layout.addWidget(self.xtal_size_dose_label, 17, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("MGy", parent=self), 17, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("X-ray Wavelength", parent=self), 18, 0)
|
||||
self._layout.addWidget(QLabel("X-ray Wavelength", parent=self), 17, 0)
|
||||
self.wavelength_label = QLabel("--", parent=self)
|
||||
self.wavelength_label.setAlignment(
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
|
||||
)
|
||||
self._layout.addWidget(self.wavelength_label, 18, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("Å", parent=self), 18, 4)
|
||||
self._layout.addWidget(self.wavelength_label, 17, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("Å", parent=self), 17, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("Flux", parent=self), 19, 0)
|
||||
self._layout.addWidget(QLabel("Flux", parent=self), 18, 0)
|
||||
self.flux_label = QLabel("--", parent=self)
|
||||
self.flux_label.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
|
||||
self._layout.addWidget(self.flux_label, 19, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("x 10<sup>9</sup> ph s<sup>-1</sup>", parent=self), 19, 4)
|
||||
self._layout.addWidget(self.flux_label, 18, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("x 10<sup>9</sup> ph s<sup>-1</sup>", parent=self), 18, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("Beam Size", parent=self), 20, 0)
|
||||
self._layout.addWidget(QLabel("Beam Size", parent=self), 19, 0)
|
||||
self.beam_size_label = QLabel("--", parent=self)
|
||||
self.beam_size_label.setAlignment(
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
|
||||
)
|
||||
self._layout.addWidget(self.beam_size_label, 20, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("um<sup>2</sup>", parent=self), 20, 4)
|
||||
self._layout.addWidget(self.beam_size_label, 19, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("um<sup>2</sup>", parent=self), 19, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("Calculated Dose", parent=self), 21, 0)
|
||||
self._layout.addWidget(QLabel("Calculated Dose", parent=self), 20, 0)
|
||||
self.calculated_dose_label = QLabel("--", parent=self)
|
||||
self.calculated_dose_label.setAlignment(
|
||||
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter
|
||||
)
|
||||
self._layout.addWidget(self.calculated_dose_label, 21, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("MGy", parent=self), 21, 4)
|
||||
self._layout.addWidget(self.calculated_dose_label, 20, 1, 1, 3)
|
||||
self._layout.addWidget(QLabel("MGy", parent=self), 20, 4)
|
||||
|
||||
self._layout.addWidget(QLabel("Total measurement time", parent=self), 22, 0)
|
||||
self._layout.addWidget(QLabel("Total measurement time", parent=self), 21, 0)
|
||||
self.total_time = QLabel(f"{self.total_time_s} min 0 s")
|
||||
self.total_time.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
|
||||
self._layout.addWidget(self.total_time, 22, 1, 1, 3)
|
||||
self._layout.addWidget(self.total_time, 21, 1, 1, 3)
|
||||
|
||||
# Vertical stretch below everything (surplus space sink).
|
||||
self._layout.addItem(
|
||||
QSpacerItem(0, 0, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding), 23, 0, 1, 6
|
||||
QSpacerItem(0, 0, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding), 22, 0, 1, 6
|
||||
)
|
||||
|
||||
@Slot(DAQStatusModel)
|
||||
@@ -264,10 +334,7 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
)
|
||||
self.flux_ph_s = s.bl.flux_ph_s
|
||||
self.flux_label.setText(f"<b>{(s.bl.flux_ph_s / 1e9):.2f}</b>")
|
||||
if s.diffraction.wavelength_angstrom is None:
|
||||
self.wavelength_label.setText("<b>N/A</b>")
|
||||
else:
|
||||
self.wavelength_label.setText(f"<b>{s.diffraction.wavelength_angstrom:.3f}</b>")
|
||||
self.wavelength_label.setText(f"<b>{s.diffraction.wavelength_angstrom:.3f}</b>")
|
||||
self.update_calculated_labels()
|
||||
|
||||
@Slot(float)
|
||||
@@ -286,6 +353,10 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
def set_temperature(self, v: float):
|
||||
self.update_calculated_labels()
|
||||
|
||||
@Slot(float)
|
||||
def set_start_angle(self, v: float):
|
||||
self.update_calculated_labels()
|
||||
|
||||
@Slot(str)
|
||||
def update_filename(self, filename: str):
|
||||
self._filename = filename
|
||||
@@ -302,85 +373,148 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
secs = 0
|
||||
self.total_time.setText(f"{mins} min {secs} s")
|
||||
|
||||
def _solve_transmission(self, budget_time_s: float, image_time_s: float) -> float:
|
||||
"""Transmission that spends the dose budget over ``n_images`` frames.
|
||||
|
||||
Snapped down to TRANSMISSION_SIG_DIGITS so quantisation can only
|
||||
under-spend the budget, and capped at 100%: when the crystal cannot
|
||||
absorb its budget at full beam we accept the under-dose rather than
|
||||
stretching the exposure.
|
||||
"""
|
||||
beam_on_s = self.n_images * image_time_s
|
||||
if beam_on_s <= 0.0 or budget_time_s <= 0.0:
|
||||
return 1.0
|
||||
# Only ever clamped down: clamping up to a floor would push the
|
||||
# delivered dose back above the budget.
|
||||
return min(1.0, _floor_significant(budget_time_s / beam_on_s, TRANSMISSION_SIG_DIGITS))
|
||||
|
||||
def _update_dtz(self, d_tar: float) -> None:
|
||||
"""Detector distance for ``d_tar``, snapped to DTZ_STEP_MM and clamped
|
||||
to the beamline travel limits.
|
||||
|
||||
The snap goes *down*: calc_dtz_mm returns the largest distance that
|
||||
still puts d_tar on the detector edge, so rounding up would drop the
|
||||
target resolution off the edge.
|
||||
"""
|
||||
requested = self._d.diffraction.calc_dtz_mm(d_tar)
|
||||
dtz_min = _ceil_to(self._d.bl.dtz_min, DTZ_STEP_MM)
|
||||
dtz_max = _floor_to(self._d.bl.dtz_max, DTZ_STEP_MM)
|
||||
|
||||
if requested <= 0.0:
|
||||
# d_tar is not reachable at this wavelength at any distance.
|
||||
self.dtz = dtz_min
|
||||
self.dtz_label.setText(f"""<span style="color: {STATUS_ALERT} ; ">-</span>""")
|
||||
return
|
||||
|
||||
snapped = _floor_to(requested, DTZ_STEP_MM)
|
||||
if snapped < dtz_min:
|
||||
self.dtz = dtz_min
|
||||
self.dtz_label.setText(
|
||||
f"""<span style="color: {STATUS_ALERT} ; ">{snapped:.0f}</span>"""
|
||||
)
|
||||
elif snapped > dtz_max:
|
||||
self.dtz = dtz_max
|
||||
self.dtz_label.setText(
|
||||
f"""<span style="color: {STATUS_ALERT} ; ">{snapped:.0f}</span>"""
|
||||
)
|
||||
else:
|
||||
self.dtz = snapped
|
||||
self.dtz_label.setText(f"{self.dtz:.0f}")
|
||||
|
||||
def update_calculated_labels(self):
|
||||
if self._d is None:
|
||||
return
|
||||
flux = 2.5e11 # TODO link flux
|
||||
# TODO add start angle
|
||||
# TODO link beam energy
|
||||
# TODO read resolution estiamtion from jfjoch
|
||||
total_angle = self.angular_range_enter.value
|
||||
d_vis = self.visible_res_enter.value
|
||||
image_angle = self.image_angle_enter.value
|
||||
d_vis = d_vis - 0.2 # additional fudge factor that weights more towards high_res
|
||||
if d_vis <= 0.0:
|
||||
d_vis = 1.3
|
||||
d_tar = 1 / (1 / d_vis + 0.1)
|
||||
|
||||
total_angle = self.angular_range_enter.value
|
||||
image_angle = max(self.image_angle_enter.value, 0.001)
|
||||
|
||||
# The DAQ resolution estimate is unbiased, so it is the target as-is:
|
||||
# no additive fudge and no reciprocal-space shift.
|
||||
d_tar = self.visible_res_enter.value
|
||||
self.target_res_label.setText(f"{d_tar:.2f}")
|
||||
|
||||
Kdose = 2000 / (self._d.diffraction.wavelength_angstrom**2)
|
||||
kdose = KDOSE_1A_PH_UM2_GY / self._d.diffraction.wavelength_angstrom**2
|
||||
|
||||
beam_size_um_y = self._d.geom.beam_size_mm.y * 1000
|
||||
beam_size_um_x = self._d.geom.beam_size_mm.x * 1000
|
||||
self.dose_rate_MGy_s = (flux / (beam_size_um_x * beam_size_um_y * Kdose)) / 1e6
|
||||
if (
|
||||
self.xtal_y is None
|
||||
or self.xtal_z is None
|
||||
or beam_size_um_x is None
|
||||
or beam_size_um_y is None
|
||||
):
|
||||
self.xtal_size_dose_rate_MGy_s = self.dose_rate_MGy_s
|
||||
|
||||
elif self.xtal_y > beam_size_um_y or self.xtal_z > beam_size_um_y:
|
||||
multiplier_1 = max(self.xtal_y, beam_size_um_y)
|
||||
multiplier_2 = max(self.xtal_z, beam_size_um_y)
|
||||
new_beam_um_y = math.sqrt(multiplier_1 * multiplier_2)
|
||||
self.xtal_size_dose_rate_MGy_s = (flux / (beam_size_um_x * new_beam_um_y * Kdose)) / 1e6
|
||||
beam_size_um_x = self._d.geom.beam_size_mm.x * 1000.0
|
||||
beam_size_um_y = self._d.geom.beam_size_mm.y * 1000.0
|
||||
beam_area_um2 = beam_size_um_x * beam_size_um_y
|
||||
|
||||
# Flux is reported by the DAQ at 100% transmission.
|
||||
flux_ph_s = self._d.bl.flux_ph_s
|
||||
if beam_area_um2 > 0.0 and flux_ph_s > 0.0:
|
||||
self.dose_rate_MGy_s = flux_ph_s / (beam_area_um2 * kdose) / 1e6
|
||||
else:
|
||||
self.xtal_size_dose_rate_MGy_s = self.dose_rate_MGy_s
|
||||
self.dose_rate_MGy_s = 0.0
|
||||
# The crystal is assumed to fill the beam, so no part of it sits
|
||||
# outside the illuminated volume and the two rates coincide. This is
|
||||
# also the diffraction-weighted rate under that assumption.
|
||||
self.xtal_size_dose_rate_MGy_s = self.dose_rate_MGy_s
|
||||
|
||||
if self.temp_enter.value > 250:
|
||||
self.target_dose_MGy = 0.1 * d_tar / 2.0 # TODO add user input
|
||||
if self.temp_enter.value > GLASS_TRANSITION_K:
|
||||
dose_per_angstrom = RT_DOSE_PER_ANGSTROM_MGY
|
||||
else:
|
||||
self.target_dose_MGy = 10 * d_tar / 2.0
|
||||
dose_per_angstrom = CRYO_DOSE_PER_ANGSTROM_MGY
|
||||
self.target_dose_MGy = dose_per_angstrom * d_tar / DOSE_SAFETY_FACTOR
|
||||
|
||||
self.target_dose_label.setText(f"{self.target_dose_MGy:.2f}")
|
||||
self.calculated_dose_rate_label.setText(f"{self.dose_rate_MGy_s:.2f}")
|
||||
self.xtal_size_dose_label.setText(f"{self.xtal_size_dose_rate_MGy_s:.2f}")
|
||||
self.n_images = max(1, round(total_angle / image_angle))
|
||||
|
||||
self.total_time_s = self.target_dose_MGy / self.dose_rate_MGy_s
|
||||
# Beam-on time at 100% transmission that spends exactly the budget.
|
||||
if self.dose_rate_MGy_s > 0.0:
|
||||
budget_time_s = self.target_dose_MGy / self.dose_rate_MGy_s
|
||||
else:
|
||||
budget_time_s = 0.0
|
||||
|
||||
# Floors on a single frame: the detector frame time raised to the
|
||||
# strategy floor where one is set, and the goniometer top speed at the
|
||||
# requested oscillation width.
|
||||
detector_min_s = MIN_EXP_TIME_S.get(self._beamline, DEFAULT_MIN_EXP_TIME_S)
|
||||
min_exp_time_s = max(
|
||||
STRATEGY_MIN_EXP_TIME_S.get(self._beamline, detector_min_s),
|
||||
image_angle / MAX_OMEGA_SPEED_DEG_S,
|
||||
)
|
||||
|
||||
if self._beamline is MXBeamline.X10SA:
|
||||
# Flux-rich: pin the detector at FIXED_FRAME_RATE_HZ and spend the
|
||||
# dose budget through transmission.
|
||||
frame_time_s = max(1.0 / FIXED_FRAME_RATE_HZ, min_exp_time_s)
|
||||
image_time_s = _ceil_to(frame_time_s, EXP_TIME_STEP_S)
|
||||
transmission = self._solve_transmission(budget_time_s, image_time_s)
|
||||
else:
|
||||
# Flux-limited: hold the beam at 100% and solve for exposure time.
|
||||
transmission = 1.0
|
||||
image_time_s = _floor_to(budget_time_s / self.n_images, EXP_TIME_STEP_S)
|
||||
if image_time_s < min_exp_time_s:
|
||||
# Cannot expose any shorter, so the balance comes out of
|
||||
# transmission instead.
|
||||
image_time_s = _ceil_to(min_exp_time_s, EXP_TIME_STEP_S)
|
||||
transmission = self._solve_transmission(budget_time_s, image_time_s)
|
||||
|
||||
self.image_time_s = image_time_s
|
||||
self.transmission = transmission
|
||||
|
||||
# Wall-clock, not the beam-on budget: this is what the operator waits
|
||||
# for, and the two differ whenever transmission is below 100%.
|
||||
self.total_time_s = self.n_images * self.image_time_s
|
||||
self.update_total_time_label()
|
||||
|
||||
self.calculated_dose_label.setText(
|
||||
f"<b>{self.xtal_size_dose_rate_MGy_s * self.total_time_s:.2f}</b>"
|
||||
)
|
||||
if image_angle == 0.0:
|
||||
image_angle = 0.001
|
||||
self.n_images = round(total_angle / image_angle)
|
||||
self.image_time_s = self.total_time_s / self.n_images
|
||||
if self.image_time_s < 0.0011:
|
||||
self.transmission = self.image_time_s / 0.0011
|
||||
self.image_time_s = 0.0011
|
||||
else:
|
||||
self.transmission = 1.0
|
||||
self.delivered_dose_MGy = self.dose_rate_MGy_s * self.transmission * self.total_time_s
|
||||
|
||||
self.dtz = self._d.diffraction.calc_dtz_mm(d_tar)
|
||||
self.dtz = max(self.dtz, 108)
|
||||
self._update_dtz(d_tar)
|
||||
|
||||
self.transmission_label.setText(f"{self.transmission * 100:.1f}")
|
||||
self.image_time_label.setText(f"{self.image_time_s:.4f}")
|
||||
self.target_dose_label.setText(f"{self.target_dose_MGy:.2f}")
|
||||
self.calculated_dose_rate_label.setText(f"{self.dose_rate_MGy_s:.3f}")
|
||||
self.transmission_label.setText(f"{self.transmission * 100:.3g}")
|
||||
self.image_time_label.setText(f"{self.image_time_s:.3f}")
|
||||
|
||||
if self.dtz <= 0.0:
|
||||
self.dtz_label.setText(f"""<span style="color: {STATUS_ALERT} ; ">-</span>""")
|
||||
elif self.dtz < self._d.bl.dtz_min:
|
||||
self.dtz_label.setText(
|
||||
f"""<span style="color: {STATUS_ALERT} ; ">{self.dtz:.2f}</span>"""
|
||||
if self.delivered_dose_MGy < 0.95 * self.target_dose_MGy:
|
||||
# Capped at 100% transmission: the crystal cannot absorb its
|
||||
# budget at this flux, so the data will be weaker than planned.
|
||||
self.calculated_dose_label.setText(
|
||||
f"""<span style="color: {STATUS_ALERT} ; ">"""
|
||||
f"""<b>{self.delivered_dose_MGy:.2f}</b></span>"""
|
||||
)
|
||||
self.dtz = self._d.bl.dtz_min
|
||||
else:
|
||||
self.dtz_label.setText(f"{self.dtz:.2f}")
|
||||
self.calculated_dose_label.setText(f"<b>{self.delivered_dose_MGy:.2f}</b>")
|
||||
|
||||
self.parameters = SimpleScanParameters(
|
||||
dtz=round(self.dtz),
|
||||
@@ -389,15 +523,18 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
incr_omega_deg=image_angle,
|
||||
steps=self.n_images,
|
||||
transmission=self.transmission,
|
||||
last_best_res=d_tar,
|
||||
last_best_b_factor=self._wilson_b,
|
||||
crystal_size=self.xtal_size,
|
||||
flux_ph_s=None,
|
||||
calculated_dose_rate_MGy_s=None,
|
||||
xtal_size_dose_rate_MGy_s=None,
|
||||
target_dose_MGy=None,
|
||||
crystal_size=self.xtal_size or CrystalSize(x=0, y=0, z=0),
|
||||
flux_ph_s=flux_ph_s,
|
||||
calculated_dose_Mgy=self.delivered_dose_MGy,
|
||||
calculated_dose_rate_MGy_s=self.dose_rate_MGy_s,
|
||||
xtal_size_dose_rate_MGy_s=self.xtal_size_dose_rate_MGy_s,
|
||||
target_dose_MGy=self.target_dose_MGy,
|
||||
dose_rate_MGy_s=self.dose_rate_MGy_s,
|
||||
beam_size_x_um=beam_size_um_x,
|
||||
beam_size_y_um=beam_size_um_y,
|
||||
d_vis=d_vis,
|
||||
d_vis=d_tar,
|
||||
d_tar=d_tar,
|
||||
)
|
||||
|
||||
@@ -407,15 +544,19 @@ class SimpleRotationSettingsPanel(QWidget):
|
||||
|
||||
@Slot()
|
||||
def run_measurement(self):
|
||||
# Send exactly what the panel last calculated and displayed, rather
|
||||
# than re-reading the widgets: dtz, exposure and transmission are a
|
||||
# single consistent solution and must not be mixed with a newer entry.
|
||||
p = self.parameters
|
||||
r = RotationScanRequest(
|
||||
file_prefix=str(add_data_to_path(self._filename)),
|
||||
start_omega_deg=self.start_angle_enter.value,
|
||||
steps=self.n_images,
|
||||
incr_omega_deg=self.image_angle_enter.value,
|
||||
dtz=self.dtz,
|
||||
transmission=self.transmission,
|
||||
start_omega_deg=p.start_omega_deg,
|
||||
steps=p.steps,
|
||||
incr_omega_deg=p.incr_omega_deg,
|
||||
dtz=p.dtz,
|
||||
transmission=p.transmission,
|
||||
screening=False,
|
||||
exp_time_s=self.image_time_s,
|
||||
exp_time_s=p.exp_time_s,
|
||||
)
|
||||
self.rotation_scan.emit(r)
|
||||
self.viewer_track_online.emit()
|
||||
Reference in new issue
Block a user