Three defects found by code review

The twin-law report block dereferenced the adopted space group without the
guard every other use of it carries; a de-novo run whose search refused a
point group but left no adopted group would crash there, after the merge.

The joint post-refinement's distance-correlation array was read on every run
that holds the header distance, but only written when the solve is usable, so
an unusable first solve printed four indeterminate values as correlations.

The merge-degradation gate ran neither of its two branches when the data
confirm more than one operator and the best of them is itself close to the
random-pairing end: the contrast has no scale to read on such a merge, but the
candidate was then promoted on no merge-degradation evidence at all. It now
falls back to the noise-floor ratio, as it does when only one operator is
confirmed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nW6FNRP1bBJJ8pfHiByAT
This commit is contained in:
leonarski_fandClaude Opus 5 committed 2026-09-20 18:45:19 +02:00
1 parent 0e67a7b055
commit e61454a27b
3 files changed
+10 -7

No files matched your search

@@ -666,7 +666,8 @@ PostRefineResult PostRefineRotationGeometry(PostRefineObservations observations,
for (int j = 0; j < 3; ++j) {
rv_f[j] = ax0[j]; q0_f[j] = p0_0[j]; q1_f[j] = p1_0[j]; q2_f[j] = p2_0[j];
}
double distance_corr[4];
// Only written when the joint solve is usable, and read unconditionally below.
double distance_corr[4] = {NAN, NAN, NAN, NAN};
bool convJ = solve_joint(FIT, /*wide=*/true, /*fix_distance=*/false, bm_f, ds_f, rv_f,
q0_f, q1_f, q2_f, distance_corr);
double exc_ref_se = NAN;
@@ -1645,9 +1645,11 @@ SearchSpaceGroupResult SearchSpaceGroup(
// the crystal itself defines: the best-agreeing operator anywhere at one end, unrelated
// reflections (random_pairing_r) at the other. A genuine operator sits at the clean end,
// a false one at the random end (see min_operator_r_contrast).
// - The first step out of P1, where only one operator is confirmed at all, has no other
// operator to be the clean end - fall back to the merge's own random-noise R floor
// (max_operator_r_over_floor).
// - Where there is no clean end to measure from - the first step out of P1, where only one
// operator is confirmed at all, and the merge whose best operator is itself close to the
// random end - fall back to the merge's own random-noise R floor
// (max_operator_r_over_floor). The contrast has no scale to read on those, but leaving
// the candidate ungated would promote it on no merge-degradation evidence at all.
bool r_refused = false;
double r_gate_value = std::numeric_limits<double>::quiet_NaN();
if (std::isfinite(c.r_added)) {
@@ -1657,8 +1659,7 @@ SearchSpaceGroupResult SearchSpaceGroup(
r_gate_value = (result.random_pairing_r - c.r_added)
/ (result.random_pairing_r - global_best_r);
r_refused = r_gate_value < opt.min_operator_r_contrast;
} else if (n_confirmed_ops < 2
&& std::isfinite(result.merge_r_floor) && result.merge_r_floor > 0.0) {
} else if (std::isfinite(result.merge_r_floor) && result.merge_r_floor > 0.0) {
r_gate_value = c.r_added / result.merge_r_floor;
r_refused = r_gate_value > opt.max_operator_r_over_floor;
}
+2 -1
View File
@@ -6922,7 +6922,8 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
result.twinning.laue_class_was_chosen_by_promotion = promoted_point_group;
// A refusal that stood on the twin-immune zone names the law: the first operator the
// refused group adds, at the fraction its own disagreement implies (a lower bound).
if (result.space_group_search && result.space_group_search->refused_point_group_representative
if (twin_sg && result.space_group_search
&& result.space_group_search->refused_point_group_representative
&& result.twin_zone_decision.find("acentric, the added") != std::string::npos) {
const auto &sgs = *result.space_group_search;
const gemmi::GroupOps hi = sgs.refused_point_group_representative->operations();