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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-14 01:51:57 +01:00
1 parent 344912139a
commit fabcb0e4d3
1 file changed
+55 -4
@@ -3332,6 +3332,57 @@ double FinalRWork(const RefinementResult &r) {
return r.restrained ? r.r_work : r.r_work_placement; 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<MergedReflection> &merged,
const gemmi::UnitCell &cell, const gemmi::SpaceGroup &sg, double wavelength_A,
Logger &logger, const RefinementSettings &settings,
const std::vector<gemmi::Op> &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 // 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 // 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 // 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<MergedReflecti
} }
} }
} }
RefinementResult twinned = RefineOnce(placed, merged, cell, sg, wavelength_A, logger, settings, {law}); RefinementResult twinned = RefineRounds(placed, merged, cell, sg, wavelength_A, logger, settings, {law});
if (!take_untwinned()) if (!take_untwinned())
return; return;
result.twin_split_pairs = 0; result.twin_split_pairs = 0;
@@ -3455,7 +3506,7 @@ void DecideTwin(const gemmi::Structure &placed, const std::vector<MergedReflecti
// has it; none left: the single law stands. // has it; none left: the single law stands.
RefinementResult multi; RefinementResult multi;
while (true) { while (true) {
multi = RefineOnce(placed, merged, cell, sg, wavelength_A, logger, settings, all, 1); multi = RefineRounds(placed, merged, cell, sg, wavelength_A, logger, settings, all, 1);
if (!multi.ok || multi.cancelled) if (!multi.ok || multi.cancelled)
return; return;
std::vector<gemmi::Op> kept{law}; std::vector<gemmi::Op> kept{law};
@@ -3590,7 +3641,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
// follows the untwinned one's, as when they ran one after the other. // follows the untwinned one's, as when they ran one after the other.
RefinementResult result; RefinementResult result;
if (!settings.twin) if (!settings.twin)
result = RefineOnce(placed, data, cell, sg, wavelength_A, logger, settings); result = RefineRounds(placed, data, cell, sg, wavelength_A, logger, settings);
else { else {
Logger twin_logger = Logger::Buffered(); Logger twin_logger = Logger::Buffered();
CardHeld held; CardHeld held;
@@ -3621,7 +3672,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
} }
}); });
try { try {
result = RefineOnce(placed, data, cell, sg, wavelength_A, logger, settings, {}, 0, &held); result = RefineRounds(placed, data, cell, sg, wavelength_A, logger, settings, {}, 0, &held);
} catch (...) { } catch (...) {
result = RefinementResult(); // not ok: the twinned arm decides nothing result = RefinementResult(); // not ok: the twinned arm decides nothing
held.Say(0); held.Say(0);