From 64d964d3d9f02c4d3772bfd6de667611345f448d Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 15 Nov 2026 09:09:40 +0100 Subject: [PATCH] LatticeSearchForSystem: take the centring the metric fits best, not the first that passes A C-centred monoclinic lattice with beta 1.75 deg off 90 also passes as a primitive monoclinic one at the character table's tolerance; taken first, that cell is not the crystal's and the run lost 0.2 A. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK --- image_analysis/lattice_search/LatticeSearch.cpp | 7 ++++--- image_analysis/lattice_search/LatticeSearch.h | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/image_analysis/lattice_search/LatticeSearch.cpp b/image_analysis/lattice_search/LatticeSearch.cpp index ff58afb1e..dd22b9fc8 100644 --- a/image_analysis/lattice_search/LatticeSearch.cpp +++ b/image_analysis/lattice_search/LatticeSearch.cpp @@ -569,13 +569,14 @@ std::optional LatticeSearchForGroup(const CrystalLattice &L std::optional LatticeSearchForSystem(const CrystalLattice &L, gemmi::CrystalSystem system) { const bool hexagonal_family = system == gemmi::CrystalSystem::Hexagonal || system == gemmi::CrystalSystem::Trigonal; + std::optional best; for (const char c : {'P', 'C', 'A', 'B', 'I', 'F', 'R'}) { const auto s = !hexagonal_family ? system : c == 'R' ? gemmi::CrystalSystem::Trigonal : gemmi::CrystalSystem::Hexagonal; - if (auto r = LatticeSearchForClass(L, s, c)) - return r; + if (auto r = LatticeSearchForClass(L, s, c); r && (!best || MetricDeviation(*r) < MetricDeviation(*best))) + best = r; } - return std::nullopt; + return best; } int LatticePointGroupOrder(gemmi::CrystalSystem system) { diff --git a/image_analysis/lattice_search/LatticeSearch.h b/image_analysis/lattice_search/LatticeSearch.h index 2c7b85910..28419d6fe 100644 --- a/image_analysis/lattice_search/LatticeSearch.h +++ b/image_analysis/lattice_search/LatticeSearch.h @@ -57,8 +57,10 @@ std::optional LatticeSearchForClass(const CrystalLattice& L // metric cannot carry the group's system at all. std::optional LatticeSearchForGroup(const CrystalLattice &L, const gemmi::SpaceGroup &sg); -// The lattice of a crystal system the user fixed (the cell given with -C): the system's centrings are -// tried in turn, primitive first, as the cell typed cannot say which the crystal has and the data can. +// The lattice of a crystal system the user fixed (the cell given with -C): of the system's centrings +// the metric carries - the cell typed cannot say which the crystal has, the data can - the one it fits +// best. Primitive first on a tie: a C-centred monoclinic lattice with beta near 90 also passes, 2 deg +// off, as a primitive one, and that cell is not the crystal's. // The hexagonal family takes a rhombohedral lattice as well. Empty where the metric carries none. std::optional LatticeSearchForSystem(const CrystalLattice &L, gemmi::CrystalSystem system);