From 3a4fcd2dd4c3579f9235c0f45132374211b768cf Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 27 Sep 2026 09:20:51 +0200 Subject: [PATCH] Rugnux: geometry-walk rounds run as probe passes, one full pass writes the kept round Every round of the rotation geometry walk was a full canonical pass - image loop, scale/merge, space-group search, model validation, P1 cross-check and every output file - while the walk reads only the round's post-refinement and validation-spot evidence, both in hand before the scaling engine is built. Rounds now stop there (postrefine_probe_only_, as the lattice arms already do), and the round the walk keeps is run once more to write the canonical files. Exact: a round's probe and its full pass are the same code up to the probe's return, and past that point a pass changes nothing on the run but the space group, which the next pass resets. A pass does change the run before that point (spot budget, axis sign, beam-centre search), so the kept LAST round is re-run from the experiment and beam_center_searched_ it started from, not from where its probe left them; a kept earlier round is gone back to exactly as before. The final pass runs without the post-refinement measurement the last round carried, which only reads the integrated reflections. p.hkl, p.mtz, p_P1.mtz, p_unmerged.mtz and p.cif byte-identical against the parent on the three open-arm sets whose walk takes rounds here (8pqd 1 round, 5m17 2, 7ph1 3; without --model, and 7ph1 also with it, where the report's model section matches too), and on myob and cytc (no rounds). The walk's log lines (distances, probe percentages, stop reason) are unchanged; the report's PASS count rises by one, the probe that now runs beside the full pass. Cost: a walk of n rounds runs n probes and one full pass instead of n full passes. Measured on a shared, loaded box (load 30-60): a round's full pass took 32-47 s on 7ph1 (56-88 s with --model) and 44-77 s on 5m17, its probe 6-11 s (16-18 s with --model); 7ph1 run back to back 182.7 -> 113.5 s. A one-round walk pays one probe more (8pqd: 24 s). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C --- rugnux/Rugnux.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index b79718c88..91dceda14 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -2704,6 +2704,11 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { ValidationSpotEvidence best_evidence = pass2.validation_evidence; std::optional probe_at_best; // the indexing probe at best_geometry, once run bool large_walk = false; // a round of this walk was started by a move of a step or more + // What the last round started from: a pass can leave the run changed behind it (a spot budget + // it shortened, an axis sign it flipped, a beam-centre search it ran), so a round is written + // from here, not from where its own probe left the run. + DiffractionExperiment last_round_start = experiment_; + bool last_round_searched = beam_center_searched_; while (!cancelled_ && prepass_detector_geometry_ && pass2.post_refine && pass2.post_refine->detector_refined) { if (geometry_rounds == MAX_GEOMETRY_ROUNDS) { @@ -2738,8 +2743,14 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { "asks for (round {} of at most {})", fit.distance_before_mm, fit.distance_after_mm, geometry_rounds + 1, MAX_GEOMETRY_ROUNDS); set_geometry(g); + last_round_start = experiment_; + last_round_searched = beam_center_searched_; + // A round is a probe pass: the walk reads only its fit and its validation evidence, both in + // hand before the merge, so the files are written once, below, at the round the walk keeps. speculate_geometry_probe_ = !large_walk; - pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false); + postrefine_probe_only_ = true; + pass2 = RunPipeline(observer, /*write_output=*/false, /*geometry_prepass=*/false); + postrefine_probe_only_ = false; speculate_geometry_probe_ = false; ++geometry_rounds; ++walk_passes; @@ -2776,12 +2787,18 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { last_pushback = pushback; } postrefine_probe_ = false; - // The canonical files were written by the last round; where that is not the best one, the best - // one is run again to write them. - if (!cancelled_ && geometry_rounds > best_round) { - logger.Info("Two-pass: going back to round {} of the geometry walk (distance {:.3f} mm), the " - "last one that lowered the realised residual", best_round, best_geometry[2]); - set_geometry(best_geometry); + // The rounds wrote nothing, so the round the walk kept is run again to write the canonical files. + if (!cancelled_ && geometry_rounds > 0) { + if (best_round == geometry_rounds) { + logger.Info("Two-pass: writing round {} of the geometry walk (distance {:.3f} mm)", + best_round, best_geometry[2]); + experiment_ = last_round_start; + beam_center_searched_ = last_round_searched; + } else { + logger.Info("Two-pass: going back to round {} of the geometry walk (distance {:.3f} mm), " + "the last one that lowered the realised residual", best_round, best_geometry[2]); + set_geometry(best_geometry); + } pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false); ++walk_passes; }