From d3f537aac69e232ed10397c08bb6753be8b1fdb4 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 16 Nov 2026 07:48:55 +0100 Subject: [PATCH] -S with -C: the cell goes onto the given axes by the nearest relabelling CellMappingOperators admits every relabelling within 5% / 3 deg of the given cell, so on a cell with two lengths that close more than one maps; ops.front() took the first in enumeration order (the identity where it qualifies) even where another put the cell on the typed axes better, e.g. a pure 2-fold given on the shorter of two near-equal axes. The nearest one is now taken (the OnGivenAxes distance), the identity on a tie. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK --- rugnux/RugnuxScaleMerge.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rugnux/RugnuxScaleMerge.cpp b/rugnux/RugnuxScaleMerge.cpp index a48b88e5f..d703e1579 100644 --- a/rugnux/RugnuxScaleMerge.cpp +++ b/rugnux/RugnuxScaleMerge.cpp @@ -1200,11 +1200,24 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { for (const auto &[hkl, sum] : summed) axial.push_back({hkl, sum.first / std::sqrt(sum.second)}); // With the cell given too, the setting is the user's: the cell goes onto the given cell's axes. + // Where two lengths are within the 5% CellsCorrespond allows, more than one relabelling maps the + // cell onto the given one, and the given axes are those of the nearest (the identity on a tie). gemmi::Op cob = gemmi::Op::identity(); if (user_cell_) { - const auto ops = CellMappingOperators(gemmi::UnitCell(*result.consensus_cell), gemmi::UnitCell(*user_cell_)); - if (!ops.empty()) - cob = ops.front(); + const UnitCell &given = *user_cell_; + double best = std::numeric_limits::infinity(); + for (const gemmi::Op &op : CellMappingOperators(gemmi::UnitCell(*result.consensus_cell), + gemmi::UnitCell(given))) { + const UnitCell m = CellInBasis(*result.consensus_cell, op); + const double d = std::fabs(m.alpha - given.alpha) + std::fabs(m.beta - given.beta) + + std::fabs(m.gamma - given.gamma) + + 100.0 * (std::fabs(m.a - given.a) / given.a + std::fabs(m.b - given.b) / given.b + + std::fabs(m.c - given.c) / given.c); + if (d < best) { + best = d; + cob = op; + } + } } else cob = SeatGroupByAbsences(*result.consensus_cell, *user_fixed_sg_, axial); if (!(cob == gemmi::Op::identity())) {