From 8880e953826e94b00517828e572b43c871412e10 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 9 Oct 2026 20:13:33 +0200 Subject: [PATCH] SearchSpaceGroup: offer every monoclinic setting the holohedry holds; break sibling ties on axial screw evidence Stage A offered the b-unique two-fold (reference setting) on the lattice's holohedry alone, but held its a- and c-unique siblings (pass-1 settings) to CellHostsRotations at 2e-3. On a cell refined free ~0.2 deg off orthogonal only the b-unique rung existed, so when the holohedral 222 was refused the setting, not the data, chose the two-fold axis. Stage B already offers non-reference settings without asking the cell, for the same reason; Stage A now does likewise where a holohedry is given. With siblings of one order eligible together, ties were broken on the class CC alone, which a twin law at fraction ~0.4 can win. A twin law cannot extinguish an axial row (every principal row maps to itself or its Friedel mate), so ties now go first to the group whose pure two-fold axes carry the more screw evidence on their own odd axial row - judged exactly as Stage B judges that zone - and only then to the CC. Rows on 3-, 4- or 6-fold axes are not read. Open arm: 6p8j (deposited P2_1, b = 152 A) was P 1 1 2 on the 88 A axis, now P 1 21 1 on the 152 A axis (152 A odd row 158 nats, 46 A row 36, 88 A row refused; R-free 0.214). 9hnc and 5cc8 p.mtz md5-identical (siblings offered but refused by added-operator R). On five passing P2_1 sets in an orthorhombic metric the true axis carries all the evidence (offline replay), so no change there. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi --- .../scale_merge/SearchSpaceGroup.cpp | 82 ++++++++++++++++++- tests/SearchSpaceGroupTest.cpp | 19 +++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/image_analysis/scale_merge/SearchSpaceGroup.cpp b/image_analysis/scale_merge/SearchSpaceGroup.cpp index 2a9be66fc..da2765a2a 100644 --- a/image_analysis/scale_merge/SearchSpaceGroup.cpp +++ b/image_analysis/scale_merge/SearchSpaceGroup.cpp @@ -726,8 +726,15 @@ RowModulation FindRowModulation(const gemmi::UnitCell& cell, const std::arraybegin(), holohedry->end(), rs.begin(), rs.end())) continue; + // Where the lattice's holohedry is known, it already says the metric hosts every + // rotation inside it - the reference-setting rung (pass 0) is offered on that alone - + // so its sibling settings are offered on the same terms. Asking the cell instead held + // them to a tighter tolerance than their reference sibling: on a cell refined free + // a fifth of a degree off orthogonal, the b-unique two-fold was the only one offered, + // and the setting rather than the data chose the axis. if (pass == 1 && - (index.count(rs) > 0 || !CellHostsRotations(*cell, sg.operations()))) + (index.count(rs) > 0 + || (!holohedry.has_value() && !CellHostsRotations(*cell, sg.operations())))) continue; auto it = index.find(rs); @@ -1638,6 +1645,70 @@ SearchSpaceGroupResult SearchSpaceGroup( } return *twinned; }; + // Whether the odd class of one principal axial row reads extinct - a 2(1) on that axis - judged + // exactly as Stage B judges that zone: the odd reflections, de-modulated for a pseudo-translation, + // in units of the even ones' mean E^2, through TrimmedZoneSum and ScrewZoneEvidence, with the same + // violation count and the same deferral to the evidence. + const auto row_screw_evidence = [&](const AxialRow& row) { + std::vector control; + std::vector odd; + for (size_t i = 0; i < n; ++i) { + if (!pass_absence[i] || (H[i] == 0) + (K[i] == 0) + (L[i] == 0) != 2 + || RowOf(H[i], K[i], L[i]) != row) + continue; + if ((H[i] + K[i] + L[i]) % 2) + odd.push_back(i); + else + control.push_back(Esq[i]); + } + if (odd.empty() || control.empty()) + return 0.0; + const double mean = std::accumulate(control.begin(), control.end(), 0.0) / control.size(); + if (!(mean > 0.0)) + return 0.0; + const double scale = control.size() >= 3 ? std::max(1.0, MedianOf(control)) : 1.0; + double sum_u = 0.0, max_u = 0.0; + int violations = 0; + for (size_t i : odd) { + const double e = Esq[i] / tncs_expected[i]; + const bool violation = IoverSigma[i] > present_cut + && (opt.present_e_squared <= 0.0 || e > opt.present_e_squared * scale); + const double u = std::max(0.0, e) / mean; + violations += violation; + sum_u += u; + if (!(violation && u >= 1.0)) + max_u = std::max(max_u, u); + } + const int a = static_cast(odd.size()); + const double ev = ScrewZoneEvidence(TrimmedZoneSum(sum_u, max_u, a), a); + const bool screwed = ev >= opt.min_screw_absence_evidence + && (violations <= opt.max_absent_violation_fraction * a || violations == 0 || ev >= a); + return screwed ? ev : 0.0; + }; + // The screw evidence a point group's own two-folds carry: summed over its two-folds that run along + // a principal axis whose odd axial row reads extinct (row_screw_evidence), in nats. A twin law + // cannot extinguish an axial row - a two-fold maps every principal row onto itself or its Friedel + // mate - so between two sibling groups of one order, the one whose own two-fold carries the dead + // row is the crystal's and the other is the twin law that out-correlated it. + // Only a row whose axis is a two-fold and nothing more: on a 3-, 4- or 6-fold axis the odd class + // is not what the screw extinguishes (a 3_1 keeps l = 3, 9, ... strong), so it says nothing here. + const auto screwed_two_folds = [&](const PointGroupInfo& pg) { + const auto is_two_fold = [](const gemmi::Op& op) { + return op.rot != gemmi::Op::identity().rot && op.combine(op).rot == gemmi::Op::identity().rot; + }; + double total = 0.0; + for (const AxialRow& row : {RowOf(1, 0, 0), RowOf(0, 1, 0), RowOf(0, 0, 1)}) { + const gemmi::Op::Miller hkl{{row[0], row[1], row[2]}}; + bool two_fold = false, higher = false; + for (const auto& rot : pg.rotations) + if (rot.rot != gemmi::Op::identity().rot && rot.apply_to_hkl(hkl) == hkl) + (is_two_fold(rot) ? two_fold : higher) = true; + if (two_fold && !higher) + total += row_screw_evidence(row); + } + return total; + }; + double best_pg_screwed = 0.0; for (auto& c : pg_cands) { // A genuine symmetry operator merges equivalent reflections, so it barely changes the reduced // chi^2 relative to the best subgroup - across the whole rotation-test battery every correct @@ -2001,10 +2072,17 @@ SearchSpaceGroupResult SearchSpaceGroup( continue; } c.eligible = true; - if (c.order > best_pg_order || (c.order == best_pg_order && c.min_class_cc > best_pg_min_cc)) { + // Ties in order go to the group whose own two-folds carry the more screw evidence (see + // screwed_two_folds), and only then to the higher class CC. + const double screwed = screwed_two_folds(*c.pg); + if (c.order > best_pg_order + || (c.order == best_pg_order + && (screwed > best_pg_screwed + || (screwed == best_pg_screwed && c.min_class_cc > best_pg_min_cc)))) { best_pg = c.pg; best_pg_order = c.order; best_pg_min_cc = c.min_class_cc; + best_pg_screwed = screwed; } } diff --git a/tests/SearchSpaceGroupTest.cpp b/tests/SearchSpaceGroupTest.cpp index 40a96990e..27544da52 100644 --- a/tests/SearchSpaceGroupTest.cpp +++ b/tests/SearchSpaceGroupTest.cpp @@ -444,6 +444,25 @@ TEST_CASE("SearchSpaceGroup names a non-reference setting only on a cell that ho } } +// A cell refined free a fifth of a degree off orthogonal hosts none of the three monoclinic settings +// to CELL_SETTING_TOLERANCE, yet the reference (b-unique) rung is offered on the lattice's holohedry +// alone. Its a- and c-unique siblings are offered on the same terms, or the setting picks the axis. +TEST_CASE("SearchSpaceGroup offers every monoclinic setting the lattice's holohedry holds") { + const gemmi::SpaceGroup& sg = gemmi::get_spacegroup_by_name("P 1 1 21"); + const auto merged = GenerateMergedReflectionsForSpaceGroup(sg, 12); + + SearchSpaceGroupOptions opt; + opt.merge_friedel = true; + opt.lattice_system = gemmi::CrystalSystem::Orthorhombic; + opt.cell = gemmi::UnitCell(40.0, 50.0, 60.0, 89.8, 90.0, 89.8); + opt.enumerate_all_settings = true; + opt.enumerate_all_rotation_sets = true; + const auto result = SearchSpaceGroup(merged, opt); + INFO(SearchSpaceGroupResultToText(result)); + REQUIRE(result.best_space_group.has_value()); + CHECK(result.best_space_group->xhm() == "P 1 1 21"); +} + // The screw axes of an orthorhombic crystal can lie on any pair of axes, and only one of the three // namings of #18 is a reference setting. With the narrow enumeration the group that predicts a // SUBSET of the real absences and nothing else wins on no evidence at all, so the reported group is