rugnux: the written cell obeys the written space group

A group adopted after integration sits on a cell refined in a lower Bravais
class (most often the triclinic primitive cell of a centred lattice). The
existing projection onto the group's metric fired only above a metric
violation of 1e-3, so a free fit's usual drift - a C 1 2/c 1 cell with
alpha 90.03 and gamma 89.97, a tetragonal or cubic cell with a != b - went
unchanged into the report, the mmCIF, the SHELX .ins, the MTZ and the
_process.h5, while the e.s.d.s beside it treated those angles as fixed.
In the latest full battery 20 of 258 rows reported such a cell, in every
crystal system and every input format.

The cell (and the rotation lattice recorded beside it) is now projected
onto the metric of the written group once, after the group and its setting
are final and before anything is written from it, wherever the violation
lies between float noise (1e-5) and MAX_METRIC_VIOLATION. That is an
info line; the re-refinement and the warning above 1e-3 are unchanged.
--mode scale does the same on the stored cell under the file's or -S's
group. The integrated reflections are not touched.

Measured on the 20 affected open-arm rows plus the 3 private and 1
multisweep rows with the defect (--no-refine, against an rc183 base on
the same sets): every cell now satisfies its group (violation <= 1e-16,
from up to 1.0e-3); nothing else changed beyond noise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdL4qBGYRiSXSGXfCLu
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-05 16:50:38 +01:00
1 parent 08594fe6c9
commit 62e77cdc48
5 files changed
+83 -4

No files matched your search

+13 -4
View File
@@ -1171,11 +1171,20 @@ bool MeasuredCentreClearlyLoses(const SearchMergeSignal &file_arm, const SearchM
// What a cell refined UNDER a group's own constraint leaves of that group's metric violation: float
// rounding on the lattice vectors, and nothing else (the constraint holds the angles at 90 exactly,
// so the residue is 1e-6 and below). A cell scoring above this was refined under something else -
// which is what has happened wherever the group was adopted AFTER integration, on a metric no
// constrained fit ever produced. Two orders below MAX_METRIC_VIOLATION, which bounds a cell that is
// WRONG for its group rather than merely unconstrained: the first says re-refine, the second refuse.
// so the residue is 1e-6 and below: CELL_FLOAT_NOISE). A cell scoring above that was refined under
// something else - which is what has happened wherever the group was adopted AFTER integration, on a
// metric no constrained fit ever produced. Up to this bound such a cell is the usual drift of a free
// fit (alpha 90.03 on a monoclinic cell) and is only projected onto the group's metric, without a
// word (CellConstrainedToGroup); above it the deviation is worth a re-refinement and a warning. Two
// orders below MAX_METRIC_VIOLATION, which bounds a cell that is WRONG for its group rather than
// merely unconstrained: the first says re-refine, the second refuse.
constexpr double MAX_CONSTRAINED_METRIC_NOISE = 1e-3;
constexpr double CELL_FLOAT_NOISE = 1e-5;
// The nearest cell the metric of `sg` fixes (SymmetrizeMetric), where `uc`'s violation of it lies
// between CELL_FLOAT_NOISE and MAX_METRIC_VIOLATION; empty where there is nothing to change. What is
// written - report, mmCIF, .ins, MTZ, _process.h5 - has to be a cell its group can describe.
std::optional<UnitCell> CellConstrainedToGroup(const UnitCell &uc, const gemmi::SpaceGroup &sg);
// Callbacks for progress and live results. Methods may be called from worker threads, so an
// implementation must be thread-safe. The default no-ops suit the CLIs.
+7
View File
@@ -328,6 +328,13 @@ SearchMergeSignal SearchSignal(const ProcessResult &r) {
r.search_merge_inner_cc_half, r.search_merge_inner_reflections};
}
std::optional<UnitCell> CellConstrainedToGroup(const UnitCell &uc, const gemmi::SpaceGroup &sg) {
const double violation = MetricViolation(uc, sg);
if (violation <= CELL_FLOAT_NOISE || violation > MAX_METRIC_VIOLATION)
return {};
return SymmetrizeMetric(CrystalLattice(uc), sg).GetUnitCell();
}
bool MeasuredCentreClearlyLoses(const SearchMergeSignal &file_arm, const SearchMergeSignal &measured_arm,
bool same_lattice, double sigmas) {
// A count is Poisson, as the first pass's near ties read counts of reflections; a CC1/2 over n
+21
View File
@@ -4081,6 +4081,27 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
: target != nullptr && !target->is_reference_setting() ? "SPACE_GROUP" : "STANDARD");
}
// The group and the axes are final here, and everything written from now on reads this cell. A
// group adopted after integration (a de-novo search on a lattice indexed in a lower class, -S, a
// reference) can leave the free fit's metric under it - a C 1 2/c 1 with alpha 90.03 - and below
// MAX_CONSTRAINED_METRIC_NOISE nothing above has touched it. The reflections stay as integrated.
if (result.consensus_cell && experiment_.GetGemmiSpaceGroup().has_value()) {
const gemmi::SpaceGroup &sg = *experiment_.GetGemmiSpaceGroup();
if (const auto constrained = CellConstrainedToGroup(*result.consensus_cell, sg)) {
const UnitCell &uc = *result.consensus_cell;
logger.Info("Cell constrained to {}: a={:.4f} b={:.4f} c={:.4f} alpha={:.3f} beta={:.3f} "
"gamma={:.3f}, from the freely refined a={:.4f} b={:.4f} c={:.4f} alpha={:.3f} "
"beta={:.3f} gamma={:.3f}", sg.xhm(), constrained->a, constrained->b,
constrained->c, constrained->alpha, constrained->beta, constrained->gamma,
uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma);
result.consensus_cell = constrained;
end_msg.unit_cell = result.consensus_cell;
}
if (end_msg.rotation_lattice.has_value()
&& CellConstrainedToGroup(end_msg.rotation_lattice->GetUnitCell(), sg).has_value())
end_msg.rotation_lattice = SymmetrizeMetric(*end_msg.rotation_lattice, sg);
}
// A pass RunAllPasses is about to throw away and run again. Its report is never printed and
// its files are overwritten seconds later, so everything below that only fills those in would
// be spent on an answer nobody reads. Every trigger of a re-run is settled by here - the
+11
View File
@@ -2373,6 +2373,17 @@ int RugnuxInputRun::PrepareRugnuxInput() {
experiment.SetSpaceGroup(*space_group);
if (fixed_reference_unit_cell.has_value())
experiment.SetUnitCell(fixed_reference_unit_cell);
// ...on the metric that group fixes, as the full pipeline writes it: a file from before it did,
// or a -S the stored cell was not refined under, can hold a cell the group cannot describe.
if (experiment.GetUnitCell() && experiment.GetGemmiSpaceGroup())
if (const auto constrained = CellConstrainedToGroup(*experiment.GetUnitCell(),
*experiment.GetGemmiSpaceGroup())) {
logger.Info("Cell constrained to {}: a={:.4f} b={:.4f} c={:.4f} alpha={:.3f} beta={:.3f} "
"gamma={:.3f}", experiment.GetGemmiSpaceGroup()->xhm(), constrained->a,
constrained->b, constrained->c, constrained->alpha, constrained->beta,
constrained->gamma);
experiment.SetUnitCell(constrained);
}
// A rotation (goniometer) dataset uses RotationScaleMerge unless --force-still asks for stills scaling.
IndexingSettings indexing_settings;
indexing_settings.RotationIndexing(experiment.GetGoniometer().has_value() && !force_still);
+31
View File
@@ -784,6 +784,37 @@ TEST_CASE("MeasuredCentreWins", "[process]") {
CHECK(MeasuredCentreWins(file, arm(monoclinic, mono, 0.88, 20000)).empty());
}
// A C 1 2/c 1 crystal indexed on its primitive (triclinic) cell and refined freely there: put back into
// the C-centred setting, its alpha and gamma come out a few hundredths of a degree off 90 - too
// little for the re-refinement above MAX_CONSTRAINED_METRIC_NOISE, and not a cell the group describes.
TEST_CASE("CellConstrainedToGroup puts a triclinic-refined C2/c cell onto the monoclinic metric", "[process]") {
const auto &c2c = *gemmi::find_spacegroup_by_name("C 1 2/c 1");
const CrystalLattice conv(UnitCell{.a = 18.0, .b = 9.0, .c = 10.0, .alpha = 90.0, .beta = 105.0, .gamma = 90.0});
// The primitive cell of the C lattice, with the drift a free fit leaves on one of its vectors.
const Coord p0 = (conv.Vec0() + conv.Vec1()) * 0.5f + Coord(0.0f, 0.004f, 0.003f);
const Coord p1 = (conv.Vec0() - conv.Vec1()) * 0.5f;
const CrystalLattice refined(p0 + p1, p0 - p1, conv.Vec2());
const UnitCell free_cell = refined.GetUnitCell();
REQUIRE(MetricViolation(free_cell, c2c) > CELL_FLOAT_NOISE);
REQUIRE(MetricViolation(free_cell, c2c) < MAX_CONSTRAINED_METRIC_NOISE);
REQUIRE(std::fabs(free_cell.alpha - 90.0) + std::fabs(free_cell.gamma - 90.0) > 0.01);
const auto fixed = CellConstrainedToGroup(free_cell, c2c);
REQUIRE(fixed.has_value());
CHECK(fixed->alpha == Catch::Approx(90.0).margin(1e-4));
CHECK(fixed->gamma == Catch::Approx(90.0).margin(1e-4));
CHECK(MetricViolation(*fixed, c2c) <= CELL_FLOAT_NOISE);
CHECK(fixed->beta == Catch::Approx(free_cell.beta).margin(0.05));
CHECK(fixed->a == Catch::Approx(free_cell.a).epsilon(1e-3));
CHECK(fixed->b == Catch::Approx(free_cell.b).epsilon(1e-3));
CHECK(fixed->c == Catch::Approx(free_cell.c).epsilon(1e-3));
// A cell already on the metric is left as it is, and so is one the group cannot describe at all.
CHECK_FALSE(CellConstrainedToGroup(*fixed, c2c).has_value());
CHECK_FALSE(CellConstrainedToGroup(UnitCell{.a = 18.0, .b = 9.0, .c = 10.0, .alpha = 60.0, .beta = 105.0,
.gamma = 90.0}, c2c).has_value());
}
TEST_CASE("MeasuredCentreClearlyLoses", "[process]") {
// Same lattice: the measured centre loses only where it is behind on the signal by more than the
// Poisson noise of the two counts AND its inner shell does not agree better by the margin.