From fe6660cecf07d8511d4aea9de68aad3e2368627b Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 11 Nov 2026 21:14:17 +0100 Subject: [PATCH] scale_merge: score a half-integer twin law as given, not rounded to integers OperatorScorer rounded each entry of the Miller-index matrix to an integer before building the gemmi operator, so a pseudo-merohedral law of a centred lattice - whose entries in the lattice's own basis are halves, such as the hexagonal two-folds of a C-centred cell with a = sqrt(3) b - was scored as a different operator altogether: on a crystal twinned by it at about 0.3 its pairs read unrelated (H 0.61, CC 0.02) where phenix.xtriage reads a Britton fraction of 0.33 for the same law, and the twin was missed. The entries are now kept in gemmi's 1/DEN units, and ScoreOperator skips an index whose image under the operator is not integral (the centring-absent class) instead of letting apply_to_hkl truncate it onto a reflection it does not relate. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK --- .../scale_merge/SearchSpaceGroup.cpp | 14 ++++++-- tests/SearchSpaceGroupTest.cpp | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/image_analysis/scale_merge/SearchSpaceGroup.cpp b/image_analysis/scale_merge/SearchSpaceGroup.cpp index 92b7a3bb1..89fb16241 100644 --- a/image_analysis/scale_merge/SearchSpaceGroup.cpp +++ b/image_analysis/scale_merge/SearchSpaceGroup.cpp @@ -949,7 +949,13 @@ RowModulation FindRowModulation(const gemmi::UnitCell& cell, const std::array OperatorScorer::operator()(const gemmi::M // gemmi applies an Op to Miller indices through the TRANSPOSE of its rot (Op::apply_to_hkl), and // writes an hkl triplet from the transpose as well, so the operator whose Miller-index matrix is M // is the Op holding M^T - and its triplet then reads as the rows of M, as everywhere else here. + // The entries are kept in gemmi's 1/DEN units, not rounded to integers first: a pseudo-merohedral + // law of a centred lattice (a C-centred cell with a = sqrt(3) b, say) has half-integer entries in + // that basis, and rounding them scored a different operator - its pairs read unrelated (H 0.61, CC + // 0.02) on a crystal twinned by it at 0.3. gemmi::Op op{}; op.notation = 'h'; op.tran = {0, 0, 0}; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3; ++j) - op.rot[i][j] = static_cast(std::lround(hkl_matrix[j][i])) * gemmi::Op::DEN; + op.rot[i][j] = static_cast(std::lround(hkl_matrix[j][i] * gemmi::Op::DEN)); const NormalisedMerge &nm = *impl->nm; std::vector visited(nm.n, 0); diff --git a/tests/SearchSpaceGroupTest.cpp b/tests/SearchSpaceGroupTest.cpp index 026ad2b77..9da5314ac 100644 --- a/tests/SearchSpaceGroupTest.cpp +++ b/tests/SearchSpaceGroupTest.cpp @@ -998,3 +998,38 @@ TEST_CASE("AnalyzeCentreOfSymmetry separates acentric from centric Wilson data") } } } + +// A pseudo-merohedral twin law of a centred lattice has half-integer entries in the lattice's own +// basis (a C-centred cell with a = sqrt(3) b is metrically hexagonal, and the hexagonal two-folds read +// as h/2 +- 3k/2 ...): it maps the centring-present indices onto integers and the absent ones onto +// halves. Scored as given it relates its own pairs; rounded to integers it is a different operator. +TEST_CASE("Operator correlation of a half-integer pseudo-merohedral law") { + const gemmi::Op law = gemmi::parse_triplet("h/2-k/2,-3/2*h-k/2,-l", 'h'); + gemmi::Mat33 m; // the Miller-index matrix of the law: h -> M h, rows as the triplet reads + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + m[i][j] = static_cast(law.rot[j][i]) / gemmi::Op::DEN; + // Friedel-merged C-centred reflections whose intensity is a function of the orbit under the law. + std::vector merged; + for (int h = -8; h <= 8; ++h) + for (int k = -8; k <= 8; ++k) + for (int l = -8; l <= 8; ++l) { + if ((h + k) % 2 != 0 || (h == 0 && k == 0 && l == 0)) + continue; + const gemmi::Op::Miller hkl{{h, k, l}}; + const gemmi::Op::Miller mate = law.apply_to_hkl(hkl); + const gemmi::Op::Miller neg{{-h, -k, -l}}, mate_neg{{-mate[0], -mate[1], -mate[2]}}; + if (hkl < neg) + continue; // one Friedel mate + const gemmi::Op::Miller rep = std::max({hkl, neg, mate, mate_neg}); + merged.push_back(MergedReflection{.h = h, .k = k, .l = l, + .I = static_cast(SyntheticIntensityFromAsu(rep)), + .sigma = 1.0, .d = static_cast(CalcSyntheticD(h, k, l))}); + } + const auto score = OperatorCorrelation(merged, m); + REQUIRE(score.has_value()); + CHECK(score->n_pairs > 300); + CHECK(score->cc > 0.99); // on shell-normalised E^2, and the synthetic d does not follow the law exactly + CHECK(score->h_stat == Catch::Approx(0.0).margin(1e-6)); + CHECK(score->op_triplet_hkl == "h/2-k/2,-3/2*h-k/2,-l"); +}