From d585be7b68e4a4b5f472bc66b4026c38bc5e2dc1 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Tue, 17 Nov 2026 12:15:36 +0100 Subject: [PATCH] Refinement: the twinned arm stops after its ladder where its law is far from being taken Where the lattice admits a twin law a second, twinned refinement runs beside the untwinned one and is decided at its end by how far the law is ahead of its null (TwinNull, taken at 3 standard errors, 2 where the data read twinned). That lead is now also measured after the twinned arm's first ladder; under 0.5 standard errors the arm stops there, its threads go to the untwinned arm, and the law is decided (not taken) where it stopped. On 19 refinements with a law the lead rose by at most 1.35 from the ladder's end to the end; the 3 twinned crystals were 8.6-17.7 ahead at the ladder's end. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UqXYdHHZ4cogS1mrGUtfN7 --- .../structure_refinement/Refinement.cpp | 42 +++++++++++++++---- .../structure_refinement/Refinement.h | 3 ++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/image_analysis/structure_refinement/Refinement.cpp b/image_analysis/structure_refinement/Refinement.cpp index 0786337cc..423f451df 100644 --- a/image_analysis/structure_refinement/Refinement.cpp +++ b/image_analysis/structure_refinement/Refinement.cpp @@ -1848,6 +1848,11 @@ constexpr size_t TWIN_NULL_SHIFT = 2; // evidence (AdoptTwinLaw). constexpr double TWIN_NULL_Z = 3.0; constexpr double TWIN_NULL_Z_DATA = 2.0; +// A twinned refinement stops after its first ladder where the law is ahead of its null by less than this many +// standard errors there (RefineOnce, 1a.): 1.5 under the lowest bar a law is taken at (TWIN_NULL_Z_DATA). From the +// ladder's end to the refinement's, the law's lead rose by 1.35 at most (on 19 refinements with a law, 3 twinned: those +// 8.6-17.7 at the ladder's end, the others under 2.4). +constexpr double TWIN_STOP_Z = 0.5; // `first`: the first law whose mates are replaced - the laws before it keep theirs (the null of the domains added to // them). With several laws a twin group holds up to Laws() + 1 reflections, kept next to each other, and law first + k // is paired (Laws() + 1) (k + 1) apart: past the reflection's own group, and no two laws drawing the same partner. @@ -3440,6 +3445,22 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector= 0 ? std::move(outcomes[k]) : TrialOutcome(); }; TrialOutcome state = ladder_choice(pos0, b0, aniso0, nullptr); + // 1a. A twinned refinement (DecideTwin) stops where the ladder leaves its law far from being taken, hardly + // ahead of its null (TwinNull, TWIN_STOP_Z) - its threads go to the untwinned refinement beside it, and + // the law is decided where it stopped. + bool stopped = false; + if (settings.twin_arm_stops && state.ran && !ctx.Cancelled()) { + ctx.SetPositions(state.pos); + ctx.SetB(state.b); + ctx.SetAniso(state.aniso); + ctx.Restore(state.fit); + ctx.FModel(); + RefinementResult null; + TwinNull(ctx, null, null_first); + stopped = null.twin_null_z < TWIN_STOP_Z; + logger.Info("Refinement, twin law: after the ladder fraction {:.3f}, ahead of its null by {:.1f} standard " + "errors{}", FractionSum(ctx.rows), null.twin_null_z, stopped ? " - not taken further" : ""); + } // 2. The trajectory: steps of a few macro-cycles from where the last one ended, each trying the weights as they // are and, in turn, the positions' X-ray weight halved and doubled (halved only in the first step, from the @@ -3505,7 +3526,8 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector(std::max(settings.population, 0), trial_slots.size()); - if (population > 1 && state.ran && !ctx.Cancelled()) { + if (population > 1 && !stopped && state.ran && !ctx.Cancelled()) { const RefinementStage pop_stage("population"); const double w = state.trial.weight, adp = state.trial.adp_weight, ncs_s = state.trial.ncs_sigma; // the members, the most different first: the positions as they are and kicked, on the data as they are @@ -3600,7 +3622,7 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector trials; for (double f : settings.final_ladder) @@ -4214,7 +4236,7 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector own_tls = state.tls; @@ -4451,7 +4473,9 @@ void DecideTwin(const gemmi::Structure &placed, const std::vector *spare_arm_threads = nullptr; + // A twinned refinement beside the untwinned one (DecideTwin): it stops after its first ladder where that leaves + // the law far from being taken. + bool twin_arm_stops = false; // The user's restraint dictionary, over the embedded one (BuildRefinementTopology) RestraintDictionary dictionary; };