Joint sweeps: sweeps within 1% of the finest d_min tie on resolution, the higher ISa decides

The reference was the finest per-sweep d_min, ties broken by ISa - but sweeps of one crystal mostly
stop at the same detector edge, with d_min apart in the third decimal by which reflections happen
to be measured there, so the tie-break almost never fired and the reference was picked on noise.
On a twinned small-molecule multi-sweep set this flipped when unrelated upstream changes moved the
long, best sweep's edge d_min by a few thousandths of an A: a short sweep with half its ISa and a
different beta became the reference, was joined, and SHELXL R1 went from 0.050 to 0.135. Within 1%
of the finest d_min the sweeps now count as reaching the same resolution and the ISa decides.

The per-sweep log line now also prints each sweep's d_min and ISa.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-14 18:00:37 +01:00
1 parent 595a94d4dc
commit 37e7ccb1a5
3 files changed
+34 -7

No files matched your search

+14 -5
View File
@@ -389,15 +389,24 @@ JointSweepRelation RelateJointSweeps(const std::vector<JointMemberSweep> &sweeps
if (sweeps.empty())
return out;
// The best sweep on its own: of the sweeps whose error model resolved an ISa, the one reaching the
// finest resolution, ties broken by the higher ISa (a sweep that merged nothing comes last).
// finest resolution, ties broken by the higher ISa (a sweep that merged nothing comes last). Sweeps of
// one crystal mostly stop at the same detector edge, their d_min apart in the third decimal by which
// reflections happen to be measured there: within 1% of the finest they reach the same resolution.
const auto accuracy_known = [&](size_t k) { return sweeps[k].isa > 0.0; }; // false on NaN
const auto d_min = [&](size_t k) { return std::isfinite(sweeps[k].d_min) ? sweeps[k].d_min : INFINITY; };
const bool any_known = std::any_of(sweeps.begin(), sweeps.end(), [](const JointMemberSweep &s) { return s.isa > 0.0; });
double finest = INFINITY;
for (size_t k = 0; k < sweeps.size(); ++k)
if (accuracy_known(k) == any_known)
finest = std::min(finest, d_min(k));
const auto reaches_finest = [&](size_t k) { return d_min(k) <= 1.01 * finest; };
const auto better = [&](size_t k, size_t than) {
if (accuracy_known(k) != accuracy_known(than))
return accuracy_known(k);
const double dk = std::isfinite(sweeps[k].d_min) ? sweeps[k].d_min : INFINITY;
const double dt = std::isfinite(sweeps[than].d_min) ? sweeps[than].d_min : INFINITY;
if (dk != dt)
return dk < dt;
if (reaches_finest(k) != reaches_finest(than))
return reaches_finest(k);
if (!reaches_finest(k) && d_min(k) != d_min(than))
return d_min(k) < d_min(than);
return (std::isfinite(sweeps[k].isa) ? sweeps[k].isa : 0.0) > (std::isfinite(sweeps[than].isa) ? sweeps[than].isa : 0.0);
};
out.reference = 0;
+3 -2
View File
@@ -4167,8 +4167,9 @@ int RugnuxCli::RunJointSweeps(const RugnuxSweepPlan &plan) {
m.distance_mm = sweep.member_result->used_distance_mm;
m.cell_esd = sweep.member_result->cell_esd;
logger.Info("Sweep {}: {} frames, {} in {:.3f} {:.3f} {:.3f} {:.2f} {:.2f} {:.2f} at {:.2f} mm, {} fulls, "
"{} merged", k + 1, m.n_frames, m.space_group.xhm(), m.cell.a, m.cell.b, m.cell.c,
m.cell.alpha, m.cell.beta, m.cell.gamma, m.distance_mm, m.fulls.size(), m.merged.size());
"{} merged to {:.3f} A, ISa {:.1f}", k + 1, m.n_frames, m.space_group.xhm(), m.cell.a, m.cell.b,
m.cell.c, m.cell.alpha, m.cell.beta, m.cell.gamma, m.distance_mm, m.fulls.size(), m.merged.size(),
m.d_min, m.isa);
} else
logger.Warning("Sweep {} ({}) gave no merge", k + 1, plan.sweeps[k].label);
return m;
+17
View File
@@ -182,6 +182,23 @@ TEST_CASE("RelateJointSweeps_ReferenceIsTheBestMeasuredSweepNotTheFinestResoluti
CHECK(relation.sweeps[1].decision == "no axes");
}
TEST_CASE("RelateJointSweeps_SweepsAtTheSameEdgeAreTiedOnResolution", "[Rugnux]") {
// Both sweeps stop at the same detector edge; the second's d_min is finer in the third decimal only, by
// the reflections it happened to measure there. That is a tie, and the higher ISa (the first) decides it.
const auto truth = Truth(1);
std::vector<JointMemberSweep> sweeps;
sweeps.push_back(MakeSweep(truth, gemmi::Op::identity(), 100, 2, 10.0));
sweeps.push_back(MakeSweep(truth, gemmi::Op::identity(), 100, 3, 10.0));
sweeps[0].isa = 40.0;
sweeps[1].isa = 20.0;
sweeps[1].d_min = sweeps[0].d_min * 0.995;
CHECK(RelateJointSweeps(sweeps).reference == 0);
// ... but a resolution finer beyond that is a better sweep.
sweeps[1].d_min = sweeps[0].d_min * 0.95;
CHECK(RelateJointSweeps(sweeps).reference == 1);
}
TEST_CASE("RelateJointSweeps_ASweepTheMergeCannotMeasureJoins", "[Rugnux]") {
// A cell of a few dozen unique reflections: too few for the isomorphism ratio, and the held-out
// residual of the merge moves by less than its own noise. Nothing measured refuses the sweep, so it