Files
Jungfraujoch/rugnux/RugnuxDefaults.cpp
T
leonarski_fandFilip Leonarski 19b135186d
Build Packages / Create release (push) Successful in 7s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m56s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m10s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m51s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m56s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 20m59s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 21m25s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 21m17s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 14m14s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m59s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 25m48s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 15m52s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m33s
Build Packages / Generate python client (push) Successful in 29s
Build Packages / Build documentation (push) Successful in 1m19s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m49s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 25m31s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 25m24s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 26m5s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 22m19s
Build Packages / Unit tests (push) Failing after 2h28m24s
Build Packages / Validation Battery (push) Successful in 40m33s
v1.0.0-rc.175 (#85)
* Rugnux: Processes a collection live while jfjoch_broker writes it (`rugnux <master.h5> <broker URL>`).
* Rugnux: Processing starts on the first images and confirms its choices once all are in, so analysis can begin during collection.
* Rugnux: Faster processing, especially on servers with several GPUs and CPU sockets and on computers without a GPU (`--no-gpu`, macOS).
* Rugnux: Uses much less GPU memory, so large data sets stay on the GPU of smaller cards, and a data set too large for the card is processed on the CPU instead.
* Rugnux: On macOS, Bragg integration runs on the Apple GPU.
* Rugnux: Better handling of twinning and pseudo-symmetry, with the twin hypothesis written as `<prefix>_twin_<SG>.mtz`, and a wrong `--model` no longer confirms the data or decides the hand.
* Rugnux: `--model` accepts predicted (AlphaFold) models and falls back to molecular replacement when the model is not placed as a rigid body (experimental `--mr` forces it), settling space group, hand and twinning and writing a different answer as `<prefix>_mr.mtz`.
* Rugnux: Molecular replacement is faster and settles the space group in more cases with several copies in the asymmetric unit.
* Rugnux: Deposition-ready mmCIF, a richer report, and numbered steps on the terminal with the full log in `<prefix>_log.txt`; `_P1.mtz`, `--estimate-beam-center` and `--beam-center-search` are removed.
* Rugnux: The beam-stop shadow is found correctly on tilted detectors.
* Rugnux: Stills files that record a stationary goniometer axis get the default stills geometry refinement.
* jfjoch_viewer: "Analyze dataset" uses the same defaults as a bare `rugnux <file>`, and shows the results of processed CBF, marCCD and SMV sweeps.
* jfjoch_viewer: The Files panel refreshes on F5 and every few seconds, and the plot type and other selections stay put during live collection.
* jfjoch_writer: Memory stays bounded and old data files are closed efficiently on long runs, any failure ends the run in an error state the broker is told about, and the master file appears only after its data files; the ZeroMQ pusher logs when a stalled writer makes it drop images.
* Fixes: The TCP image pusher no longer blocks the broker's receiver, GPU out-of-memory failures stop with a clear message, and the XDS plugin masks module and chip edges.

---------

Co-authored-by: Filip Leonarski <jungfrau@filips-mac-mini.home>
Reviewed-on: #85
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-16 15:34:43 +02:00

109 lines
5.6 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "RugnuxDefaults.h"
namespace {
// Smoothing range for the per-frame scale G on rotation data (XDS DELPHI-like), in degrees.
constexpr double SMOOTH_G_DEG = 5.0;
// Per-observation outlier rejection for the rotation combine, in sigma.
constexpr double REJECT_OUTLIERS_NSIGMA = 6.0;
}
void ApplyRugnuxExperimentDefaults(DiffractionExperiment &experiment) {
// The Lp correction the integrator applies to every reflection. Without it the intensities carry an
// azimuthal, intensity-proportional modulation (~1.3x at 2 A for a 1 A beam) that symmetry mates do
// NOT share, because they sit at the same 2-theta but a different azimuth - which is exactly the
// "unequal intensities forced together" signature the space-group search vetoes as pseudo-symmetry.
experiment.PolarizationFactor(0.99);
// The background ring's radial curvature correction: auto, applied per image where the ice score
// sees a smooth ring. The library default stays off (the broker keeps it off); offline, over ice
// sets and clean controls, auto was a clear gain where it fired (smooth ice: CC to the model +0.015,
// R shell-scaled -0.019 on one set) and bit-identical where it did not, while forcing it on
// everywhere cost a clean set 0.008 in CC to the model.
BraggIntegrationSettings bis = experiment.GetBraggIntegrationSettings();
bis.BackgroundRadialCorrection(std::nullopt);
experiment.ImportBraggIntegrationSettings(bis);
}
void ClearStoredCrystal(DiffractionExperiment &experiment) {
experiment.SpaceGroupNumber(std::nullopt);
experiment.SetUnitCell(std::nullopt);
}
ScalingSettings RugnuxDefaultScalingSettings(bool rotation) {
ScalingSettings s;
// Refit the per-frame scale on the combined fulls. Rotation only - it is what lifts ISa there, and
// there is no combine on the stills path.
s.ScaleFulls(rotation);
s.SmoothGDegrees(rotation ? SMOOTH_G_DEG : 0.0);
// Drop edge-of-sweep fulls whose rocking curve was captured less than this. 0.7 rather than 0.5 also
// strips the partiality-extrapolated fulls that dominate the intensity second moment on weakly
// diffracting crystals, without which the de-novo space-group search is starved by the error-model
// I/sigma floor and falls back to P1.
s.MinCapturedFraction(rotation ? 0.7 : 0.0);
// Capture-aware systematic sigma: down-weights the over-extrapolated under-captured fulls.
s.CaptureUncertaintyCoeff(rotation ? 1.0 : 0.0);
// A single un-rejected artifact wrecks the intensity-correlation and second-moment statistics the
// space-group and twinning tests are built on.
s.OutlierRejectNsigma(rotation ? REJECT_OUTLIERS_NSIGMA : 0.0);
// Run the de-novo space-group search a second time on a merge of only the well-measured
// observations and keep whichever found more symmetry. It cannot lose symmetry, so an imperfect cut
// only means the second opinion contributes nothing.
s.SearchMinZeta(rotation ? 0.85 : 0.0);
return s;
}
bool RugnuxRotationData(const DiffractionExperiment &experiment) {
const auto gonio = experiment.GetGoniometer();
return gonio.has_value() && gonio->IsScanning();
}
SpotFindingSettings RugnuxDefaultSpotFinding(bool rotation) {
SpotFindingSettings s;
s.enable = true;
s.indexing = true;
s.adaptive_threshold = true;
// The high-resolution limit stays unset - as far as the detector reaches - for rotation as well as
// stills. Rotation used to keep 1.5 A on the strength of an indexing-rate measurement, but over the
// 33-crystal battery that limit changes nothing on 29 crystals, changes no space-group decision at
// all, and on the crystals where it does bite it is the LIMIT that is worse: the one crystal that
// loses appreciable indexing rate without it (99.5 -> 94.2%) comes back with better R_meas, better
// high-resolution CC1/2 and better ISa. Fewer frames, better data.
s.high_resolution_limit = std::nullopt;
s.min_pix_per_spot = rotation ? std::optional<int64_t>(2) : std::nullopt;
return s;
}
void ApplyRugnuxIntegrationRadii(DiffractionExperiment &experiment, bool rotation) {
if (rotation)
return;
// Stills spots span a range of crystal orientations captured in a single shot, so they land
// wider on the detector than the r1=4 monochromatic-rotation default assumes. A larger signal
// box lets the profile-fit integrator capture the whole spot while its profile weighting keeps
// the extra background from adding noise (a plain box-sum degrades with it). Measured R-free
// gains on serial stills.
//
// r3 = 14 rather than 12: the reported sigma carries the ring mean's own error as
// (dI/dbkg)^2 * bkg/n_ring, and the ring only holds 244 pixels at r3 = 12 against the
// rotation default's 408, so that term is a larger share of the variance here than
// anywhere else. 14 takes the ring to about 410 pixels. What normally stops a ring being
// widened is crowding - a neighbour inside the annulus is excluded from it - and stills
// barely crowd: under a percent of stills reflections have any neighbour within 13 px,
// against most of them on rotation.
BraggIntegrationSettings bis = experiment.GetBraggIntegrationSettings();
bis.R1(6.0f).R2(8.0f).R3(14.0f);
experiment.ImportBraggIntegrationSettings(bis);
}
bool RugnuxDetectIceRings(std::optional<bool> file_detect_ice_rings, bool rotation) {
return file_detect_ice_rings.value_or(rotation);
}