From 82029ebc0e82f6d2c26b6a9ebeb4147c4e691a04 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 11 Nov 2026 12:41:38 +0100 Subject: [PATCH] RESULT-CHANGING: a harmonic pair of beam centres is decided on the point-symmetry capture first Where the file's centre and the background-walk centre index lattices whose primitive volumes differ by an integer factor (2-4), the decision was made on the pooled excess of spots over chance - a comparison of two working indexings, which on a harmonic pair can favour the wrong centre: on the battery it chose the centre holding the larger, false cell in 3 of 9 such runs, and on an F-centred cubic small-molecule crystal the file centre (4 px out across the spindle) was kept, the first pass fell to triclinic and the cell ended 1.6 % long. The pre-scan already measures the centre a second way, as the image's strongest point-symmetry centre, and only stills used it. Against each run's own final refined beam over the rotation runs of the battery its median error is 0.26 px (walk 1.17, file 2.89), and "the centre nearer the capture" picks the better of file and walk in 167 of 180 runs where they differ. It is now asked first on a harmonic pair: where its margin is at least 1.5 % (below ~1 % its surface is flat and it is uninformative) the centre nearer it is taken with its cell; the long- axis and sub-lattice hypotheses then test that cell on its own spots as before. Without an informative capture the pooled spots decide, and where they keep the file's centre the measured one is still carried to the merge (previous commit). Forced-centre runs of the ten harmonic-pair sets: the measured centre is the one that merges in five (four collapse at the file's centre: ISa 0.6-2.6 against 13-31), the file's in two - one where the capture is uninformative, unchanged, and one unscored P1 set that merges poorly at either centre, where the capture now takes the measured one - and the centre makes no difference in the rest. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK --- docs/CPU_DATA_ANALYSIS_IMAGE.md | 16 +++++++++---- docs/RUGNUX_CLI.md | 2 +- rugnux/Rugnux.cpp | 1 + rugnux/Rugnux.h | 4 +++- rugnux/RugnuxFirstPassRescues.cpp | 40 ++++++++++++++++++++++++++++--- rugnux/RugnuxPreScan.cpp | 4 +++- 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/docs/CPU_DATA_ANALYSIS_IMAGE.md b/docs/CPU_DATA_ANALYSIS_IMAGE.md index eb91d0157..ca528af07 100644 --- a/docs/CPU_DATA_ANALYSIS_IMAGE.md +++ b/docs/CPU_DATA_ANALYSIS_IMAGE.md @@ -232,10 +232,16 @@ within 2 %. The outcomes: the file's centre and its class are kept. 4. **Both index, on different lattices.** Both cells are reported in a warning. Where the primitive volumes differ by an integer factor of 2 to 4 — an axis harmonic, which a centre error along the - spindle produces — the choice is made on the **pooled validation spots**: the measured centre is - adopted where its lattice, larger or smaller, beats chance and puts a share of the spots on itself - over its own wrong-spindle null that exceeds the file's by more than the binomial noise of the two - (z = 3.29). Otherwise the file's centre is kept, with a warning. + spindle produces — the choice is made first on the pre-scan's **point-symmetry capture**, a second + reading of the same background by an estimator that sees neither lattice: where its margin is at + least 1.5 % (below ~1 % its surface is flat and its peak can be anywhere), the centre nearer the + capture is taken with its cell. Otherwise it is made on the **pooled validation spots**: the + measured centre is adopted where its lattice, larger or smaller, beats chance and puts a share of + the spots on itself over its own wrong-spindle null that exceeds the file's by more than the + binomial noise of the two (z = 3.29). Where that does not adopt it, the file's centre is kept for + the first pass and, on a two-pass run, both centres are carried to the merge (next paragraph). + Whichever cell a centre brings, the long-axis and sub-lattice hypotheses then test it on its own + spots, so a centre is not refused for the harmonic it first indexed. 5. **The file's centre does not index.** Nothing defends it, so: - where the measured centre indexes, it is **adopted**; - where it does not, the rotation-axis sign is flipped **at the measured centre**, since each of the @@ -249,7 +255,7 @@ within 2 %. The outcomes: file's centre is put back, so a run that fails for some other reason fails at the geometry it was given. -**Both centres judged on the merge (rotation, two-pass).** Where case 3 or 5 carried both centres, the +**Both centres judged on the merge (rotation, two-pass).** Where case 3, 4 or 5 carried both centres, the whole first pass is run again at the measured centre — with its own post-refinement — and the two arms are compared on their search merges ($P1$, whole range, before the correction surfaces). Where case 2 held a hypothesis, this is done only if the file's arm merges diff --git a/docs/RUGNUX_CLI.md b/docs/RUGNUX_CLI.md index 1e502d430..6718cd50d 100644 --- a/docs/RUGNUX_CLI.md +++ b/docs/RUGNUX_CLI.md @@ -207,7 +207,7 @@ The model is taken as placed in the data's cell, and refined in the data's space | Option | Description | | --- | --- | -| `--beam-center-check[=off]` | Measure the beam centre from the isotropy of the scattered background on **every** run, report how far the file's value is from it (against how right this geometry needs it to be), and on rotation data index a **second first pass** at the measured centre. The fit reads the projection `--detect-beam-stop` already builds, so it costs no extra frames. **On by default**; `=off` disables it, and with it the measured centre's part in the post-refinement bound. The measured centre is adopted where the file's centre indexes nothing and the measured one indexes a majority; where the two return cells related by an integer volume factor (2 to 4) and the measured centre's cell, larger or smaller, carries materially more of the pooled validation spots against its own chance level; and, on a two-pass run, where the first pass is run at both centres and the measured one merges better — done where the two give the same cell in different metric symmetries, where they agree only once less of each frame is read, and where they agree but lie further apart than the geometry absorbs and the file's centre merges inconsistently in the lowest-resolution shell. Otherwise the file's centre is kept. On stills, where there is no first pass, the file's centre, the measured one and the point-symmetry capture's are each indexed on a sample of frames and the one putting materially more spots on the lattice is taken; with `-C`, or after the geometry refinement has fitted a cell de novo, the detector distance is searched too (30-3000 mm, the file's value one hypothesis). Still runs when `--beam-x`/`--beam-y` are given. See [§1.4](CPU_DATA_ANALYSIS_IMAGE.md) | +| `--beam-center-check[=off]` | Measure the beam centre from the isotropy of the scattered background on **every** run, report how far the file's value is from it (against how right this geometry needs it to be), and on rotation data index a **second first pass** at the measured centre. The fit reads the projection `--detect-beam-stop` already builds, so it costs no extra frames. **On by default**; `=off` disables it, and with it the measured centre's part in the post-refinement bound. The measured centre is adopted where the file's centre indexes nothing and the measured one indexes a majority; where the two return cells related by an integer volume factor (2 to 4) and the pre-scan's point-symmetry capture (where its margin is at least 1.5 %) lies nearer the measured centre - without an informative capture, where the measured centre's cell, larger or smaller, carries materially more of the pooled validation spots against its own chance level, and otherwise the two centres are judged on the merge; and, on a two-pass run, where the first pass is run at both centres and the measured one merges better — done where the two give the same cell in different metric symmetries, where they agree only once less of each frame is read, and where they agree but lie further apart than the geometry absorbs and the file's centre merges inconsistently in the lowest-resolution shell. Otherwise the file's centre is kept. On stills, where there is no first pass, the file's centre, the measured one and the point-symmetry capture's are each indexed on a sample of frames and the one putting materially more spots on the lattice is taken; with `-C`, or after the geometry refinement has fitted a cell de novo, the detector distance is searched too (30-3000 mm, the file's value one hypothesis). Still runs when `--beam-x`/`--beam-y` are given. See [§1.4](CPU_DATA_ANALYSIS_IMAGE.md) | ### Spot finding diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index 1bd222a86..48fb8ed89 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -750,6 +750,7 @@ void Rugnux::JoinBeamCenterCapture() { const BackgroundCentres c = background_center_capture_.get(); background_center_ = c.measured; point_symmetry_center_ = c.point_symmetry; + point_symmetry_margin_ = c.point_symmetry_margin; measured_beam_center_ = background_center_; background_center_capture_ = {}; } diff --git a/rugnux/Rugnux.h b/rugnux/Rugnux.h index c1f18ef09..720dba98f 100644 --- a/rugnux/Rugnux.h +++ b/rugnux/Rugnux.h @@ -1337,9 +1337,11 @@ class Rugnux { struct BackgroundCentres { std::optional measured; std::optional> point_symmetry; + float point_symmetry_margin = 0.0f; // (best - runner-up) / best of the capture's peaks }; std::shared_future background_center_capture_; - std::optional> point_symmetry_center_; + std::optional> point_symmetry_center_; // a direct beam, not a PONI + float point_symmetry_margin_ = 0.0f; void JoinBeamCenterCapture(); // The centre the background measured, kept when the two centres index the SAME cell but a // different metric symmetry off it and the disagreement is by itself large enough to have decided diff --git a/rugnux/RugnuxFirstPassRescues.cpp b/rugnux/RugnuxFirstPassRescues.cpp index 0c7b4b0c7..54eeacc0f 100644 --- a/rugnux/RugnuxFirstPassRescues.cpp +++ b/rugnux/RugnuxFirstPassRescues.cpp @@ -827,8 +827,42 @@ auto Rugnux::FirstPassRun::CentresDisagree(FirstPass best, const FirstPass &alt, const double nearest_n = std::round(ratio); const bool integer_harmonic = nearest_n >= 2.0 && nearest_n <= 4.0 && std::abs(ratio - nearest_n) < 0.15; + // First asked of the THIRD reading of the centre, the pre-scan's point-symmetry capture: the + // image's centrosymmetry about the point the beam lands on, read off the same background by a + // different estimator than the isotropy walk that gave the measured centre, and touching neither + // lattice. Both statistics below compare two working indexings, and on a harmonic pair both + // can point at the wrong centre - which is why the capture is asked first. The two centres are + // judged by which one the capture lies nearer. Measured on the rotation runs of the battery + // against each run's own final refined beam: median error 0.26 px for the capture, 1.17 for the + // walk, 2.89 for the file; "the one nearer the capture" picked the better of file and walk in + // 167 of 180 runs where they differed, and on the harmonic pairs every case where the centre + // decided the result (four adoptions of the measured centre, and the small-molecule crystal of + // the merge-arm comment below, where the pooled spots chose wrong). The capture's margin is its + // own confidence: a margin under ~1 % is a flat surface and its peak can be anywhere (median + // 6.9 px off there, against 0.2-0.3 px from 1.5 % up), and then the pooled spots decide as before. + constexpr float MIN_CAPTURE_MARGIN = 0.015f; bool adopted_measured = false; - if (integer_harmonic) { + bool decided_by_capture = false; + if (integer_harmonic && rx.point_symmetry_center_ && rx.point_symmetry_margin_ >= MIN_CAPTURE_MARGIN) { + // The capture is a direct beam, the two centres are PONIs: put it in their frame. + const auto [direct_x, direct_y] = rx.experiment_.GetDiffractionGeometry().GetDirectBeam_pxl(); + const float capture_x = rx.point_symmetry_center_->first - (direct_x - header_x); + const float capture_y = rx.point_symmetry_center_->second - (direct_y - header_y); + const float to_file = std::hypot(capture_x - header_x, capture_y - header_y); + const float to_measured = std::hypot(capture_x - measured_x, capture_y - measured_y); + decided_by_capture = true; + adopted_measured = to_measured < to_file; + logger.Warning("Beam centre check: the point-symmetry capture puts the beam at ({:.2f},{:.2f}), " + "margin {:.1f}%, {:.2f} px from the measured centre and {:.2f} px from the file's - " + "the run takes the {} centre and its {} cell", + capture_x, capture_y, 100.0f * rx.point_symmetry_margin_, to_measured, to_file, + adopted_measured ? "measured" : "file's", + (adopted_measured ? alt.vol > best.vol : best.vol > alt.vol) ? "larger" : "smaller"); + if (adopted_measured) { + TryBeamCenter(measured_x, measured_y); + best = alt; + } + } else if (integer_harmonic) { const PooledEvidence at_header = MeasurePooled(*indexer, *best.result); TryBeamCenter(measured_x, measured_y); const PooledEvidence at_measured = MeasurePooled(*indexer, *alt.result); @@ -862,12 +896,12 @@ auto Rugnux::FirstPassRun::CentresDisagree(FirstPass best, const FirstPass &alt, // file's centre was kept and the run ended on a cell 1.6 % long. Rather than decide on that, carry // the measured centre forward and judge the two arms on their merges (RunAllPasses), as the // same-cell case above does. - if (!adopted_measured && integer_harmonic && geometry_prepass) { + if (!adopted_measured && !decided_by_capture && integer_harmonic && geometry_prepass) { rx.beam_center_alternative_ = std::array{measured_x, measured_y}; logger.Warning("Beam centre check: the pooled spots do not settle which of the two " "cells is the centre error, so the run keeps the file's centre for now " "and carries the measured one forward, adopting whichever merges better"); - } else if (!adopted_measured) + } else if (!adopted_measured && !decided_by_capture) logger.Warning("Beam centre check: the run keeps the file's centre. The " "frame counts cannot arbitrate this - a cell twice as long " "must place every spot twice as accurately to score the " diff --git a/rugnux/RugnuxPreScan.cpp b/rugnux/RugnuxPreScan.cpp index 248a018ff..00ce896dd 100644 --- a/rugnux/RugnuxPreScan.cpp +++ b/rugnux/RugnuxPreScan.cpp @@ -1291,8 +1291,10 @@ void Rugnux::PreScan(int start_image, int images_to_process, int frame_count, Ru : "this is not a rotation sweep, so there is no spindle to resolve it on"); } BackgroundCentres centres{background_center, std::nullopt}; - if (!capture.point.empty()) + if (!capture.point.empty()) { centres.point_symmetry = std::make_pair(capture.point[0].beam_x_pxl, capture.point[0].beam_y_pxl); + centres.point_symmetry_margin = capture.margin_point; + } return centres; }).share();