From e4d64e67c9e5712096aad6b59b07d65f9a003bdb Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 26 Oct 2026 18:18:28 +0100 Subject: [PATCH] rugnux: French-Wilson takes the anisotropy tensor from the merge alone, the rest of the analysis is joined after molecular replacement AnisotropyPriorHKL is the same tensor, bit for bit, as AnisotropyTensorHKL(AnalyzeAnisotropy(...)), so the amplitudes no longer wait for the unmerged-observation part of the analysis (ScaledObservations): the model work starts at once and the analysis, its text and the merge statistics are taken before the rigid-body validation or after molecular replacement. The analysis takes its own copy of the space group, which the enantiomorph relabelling changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu --- rugnux/RugnuxScaleMerge.cpp | 50 +++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/rugnux/RugnuxScaleMerge.cpp b/rugnux/RugnuxScaleMerge.cpp index e22aef7a9..48b94dd89 100644 --- a/rugnux/RugnuxScaleMerge.cpp +++ b/rugnux/RugnuxScaleMerge.cpp @@ -3668,7 +3668,9 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { // Diffraction anisotropy (see where it is reported, below), made beside the analyses that come // before it: it reads the merge, the integrated observations and the per-frame scales the merge - // wrote back, none of which they change, and most of it is gathering the observations. + // wrote back, none of which they change, and most of it is gathering the observations. It runs on + // beside the molecular replacement too (finish_analyses), so it takes its own copy of the group: the + // enantiomorph relabelling there changes the experiment's. std::future anisotropy; if (!geometry_prepass && !superseded && result.consensus_cell) { AnisotropyRunInfo aniso_run; @@ -3679,12 +3681,13 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { aniso_run.nthreads = config_.nthreads; const float wedge_deg = experiment_.GetGoniometer() ? experiment_.GetGoniometer()->GetWedge_deg() : 0.0f; anisotropy = std::async(std::launch::async, - [&, aniso_run, wedge_deg, cell = *result.consensus_cell, + [&, aniso_run, wedge_deg, cell = *result.consensus_cell, sg = twin_sg_opt, rotation = experiment_.IsRotationIndexing()] { + const gemmi::SpaceGroup *g = sg ? &*sg : nullptr; return AnalyzeAnisotropy(sm.merged, - ScaledObservations(indexer->GetIntegrationOutcome(), rotation, twin_sg, + ScaledObservations(indexer->GetIntegrationOutcome(), rotation, g, wedge_deg, 0.5, config_.nthreads), - cell, twin_sg, aniso_run); + cell, g, aniso_run); }); } // fast_live, cut (the broker's deadline or a cancel): the model is left out, and the files are written @@ -4071,17 +4074,16 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { // tensor directions the symmetry forbids - the only place a dataset measures its own // systematic error - are identically zero in it. if (anisotropy.valid()) { - TimingMark anisotropy_mark(logger, "analyses/anisotropy wait"); - sm.statistics.anisotropy = anisotropy.get(); - anisotropy_mark.Stop(); - stats_text << AnisotropyToText(sm.statistics.anisotropy) << "\n"; // The amplitudes are the one place the tensor is used: French-Wilson with the Wilson // prior of each reflection taken along its own direction. The intensities and - // everything measured on them above are left as they are. + // everything measured on them above are left as they are. The tensor is the analysis' + // own, fitted to the merge alone (AnisotropyPriorHKL), so the model work does not wait for + // the rest of the analysis, which is taken once that is done (finish_analyses). The analysis + // reads the intensities only; French-Wilson writes the amplitudes only. FrenchWilsonOptions fw_opts; fw_opts.num_threads = config_.nthreads; - fw_opts.anisotropy_hkl = AnisotropyTensorHKL(sm.statistics.anisotropy, - gemmi::UnitCell(*result.consensus_cell)); + fw_opts.anisotropy_hkl = AnisotropyPriorHKL(sm.merged, gemmi::UnitCell(*result.consensus_cell), + twin_sg); ApplyFrenchWilson(sm.merged, experiment_.GetSpaceGroupOrP1(), fw_opts); } else if (rsm) { // No tensor: the isotropic prior. The rotation merge leaves its amplitudes to here. @@ -4091,10 +4093,21 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { } } - stats_text << sm.statistics; - result.merge_statistics_text = stats_text.str(); - result.has_merge_statistics = true; - result.merge_statistics = sm.statistics; + // The anisotropy and the statistics text it ends, once the model work has gone ahead: before the + // validation below, which edits the text and moves the merge to the model's frame, or after the + // molecular replacement. + const auto finish_analyses = [&] { + if (anisotropy.valid()) { + TimingMark anisotropy_mark(logger, "analyses/anisotropy wait"); + sm.statistics.anisotropy = anisotropy.get(); + anisotropy_mark.Stop(); + stats_text << AnisotropyToText(sm.statistics.anisotropy) << "\n"; + } + stats_text << sm.statistics; + result.merge_statistics_text = stats_text.str(); + result.has_merge_statistics = true; + result.merge_statistics = sm.statistics; + }; result.reference_merge_statistics = sm.reference_statistics; result.reference_isa = sm.reference_isa; @@ -4441,7 +4454,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { // for by molecular replacement below. bool placed_by_rigid_body = false; bool twin_chosen_by_model = false; - if (model_run && !model_predicted && !config_.force_mr) { + const bool validated_first = model_run && !model_predicted && !config_.force_mr; + if (validated_first) + finish_analyses(); + if (validated_first) { phase("Validating against model"); Step("Model validation"); TimingMark mark(logger, "model validation"); @@ -4755,6 +4771,8 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { } result.model_prior = std::move(mr); } + if (!validated_first) + finish_analyses(); // The cell's e.s.d.s (CellEsd.h), from the same integrated observations and at the same point as the // unmerged MTZ below: the indexing and the group are final here, once the model has been read. Rotation