From fabcb0e4d3a1a284213791ba07e6ad713bbaee14 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 13 Nov 2026 23:51:02 +0100 Subject: [PATCH] Refinement: run again from the refined model while R-free falls (3 rounds at most) One refinement chooses its X-ray weight and NCS on the B factors as given and its displacement model (TLS / U) only after them. Where the displacements change much - a placed prediction, whose B factors are its pLDDT - the weights stand on B factors the model no longer has. Running the refinement again from its own result (as REFMAC users do by hand) lets the weight ladder and the NCS choice see the refined displacements. Cytochrome C, three copies placed by MR from the AlphaFold model, 1.73 A, live merge: round 2 chose an eight times lower X-ray weight without NCS, R-work 0.367 -> 0.361 at bonds 0.002 -> 0.001 A, R-free 0.418 -> 0.405; with --refine-solvent 0.427 -> 0.409 -> 0.401. REFMAC5 from the same model reaches 0.41-0.43. On 22 battery merges with their placed models no R-free rose; lyso_x06da_ref -0.003, cytc_x10sa -0.005, 9khr -0.003, 6hv2 -0.002, the rest unchanged. End to end from the AlphaFold DB models of the timing benchmark (MR, rugnux mx): myob_x10sa 0.341 -> 0.312, cytc_x10sa 0.419 -> 0.410, 9zlo 0.289 -> 0.283, 9s02 and 9gjx unchanged. Cost: refinement time x1.3-4 (cytochrome C 6 -> 12 s on the GPU; 9s02 22 -> 30 s), the second round being run to be judged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK --- .../structure_refinement/Refinement.cpp | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/image_analysis/structure_refinement/Refinement.cpp b/image_analysis/structure_refinement/Refinement.cpp index cb1e3406e..7e8c81502 100644 --- a/image_analysis/structure_refinement/Refinement.cpp +++ b/image_analysis/structure_refinement/Refinement.cpp @@ -3332,6 +3332,57 @@ double FinalRWork(const RefinementResult &r) { return r.restrained ? r.r_work : r.r_work_placement; } +// The refinement run again from the model it ended with, while that lowers R-free by more than the tie, up to +// REFINEMENT_ROUNDS in all. One refinement chooses its weights on the B factors as given and its displacement model +// only after them, so where the displacements change much - a placed prediction, whose B factors are its pLDDT - the +// weights were chosen for B factors it no longer has: on a placed prediction of three copies the second round chose +// an eight times lower X-ray weight, R-work and R-free both fell and R-free went 0.418 -> 0.405 (with the solvent +// build 0.427 -> 0.409 -> 0.401), where REFMAC5 reached 0.41-0.43 from the same model. The first round's view of +// the model as given is kept; the solvent build is the first round's. +constexpr int REFINEMENT_ROUNDS = 3; + +RefinementResult RefineRounds(const gemmi::Structure &placed, const std::vector &merged, + const gemmi::UnitCell &cell, const gemmi::SpaceGroup &sg, double wavelength_A, + Logger &logger, const RefinementSettings &settings, + const std::vector &twin_laws = {}, size_t null_first = 0, + CardHeld *held = nullptr) { + RefinementResult result = RefineOnce(placed, merged, cell, sg, wavelength_A, logger, settings, twin_laws, + null_first, held); + RefinementSettings again = settings; + again.solvent = false; + for (int round = 2; round <= REFINEMENT_ROUNDS; round++) { + if (!result.ok || !result.restrained || result.as_given || result.cancelled || settings.score_only || + result.model == nullptr) + break; + logger.Info("Refinement, round {}: from the model the round before ended with (R-free {:.4f})", round, + result.r_free); + RefinementResult next = RefineOnce(*result.model, merged, cell, sg, wavelength_A, logger, again, twin_laws, + null_first); + if (!next.ok || !next.restrained || next.as_given || !(next.r_free < result.r_free - R_FREE_TIE)) { + logger.Info("Refinement, round {}: not kept (R-free {:.4f})", round, FinalRFree(next)); + result.seconds += next.seconds; + break; + } + next.seconds += result.seconds; + next.r_work_start = result.r_work_start; + next.r_free_start = result.r_free_start; + next.score_start = result.score_start; + next.adp_input = result.adp_input; + next.adp_input_aniso_atoms = result.adp_input_aniso_atoms; + next.rigid_bodies = result.rigid_bodies; + next.group_b = result.group_b; + next.r_work_placement = result.r_work_placement; + next.r_free_placement = result.r_free_placement; + next.geometry_start = result.geometry_start; + next.ncs_rmsd_start = result.ncs_rmsd_start; + next.solvent_build = result.solvent_build; + if (next.adp_model == "the model's U held") // the round before's displacement model, refined on + next.adp_model = result.adp_model; + result = std::move(next); + } + return result; +} + // The twin hypotheses beside the untwinned refinement `result`, as a ladder. First one law: the placed model refined // again, solvent build and displacement model included, against the data as twinned by a law of the lattice, and the // twinned refinement taken (into `result`) where the law beats its own null (TwinNull) on the free reflections by @@ -3407,7 +3458,7 @@ void DecideTwin(const gemmi::Structure &placed, const std::vector kept{law}; @@ -3590,7 +3641,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector