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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-15 09:37:15 +01:00
1 parent 387b31eae0
commit 64d964d3d9
2 files changed
+8 -5

No files matched your search

@@ -569,13 +569,14 @@ std::optional<LatticeSearchResult> LatticeSearchForGroup(const CrystalLattice &L
std::optional<LatticeSearchResult> LatticeSearchForSystem(const CrystalLattice &L, gemmi::CrystalSystem system) {
const bool hexagonal_family = system == gemmi::CrystalSystem::Hexagonal || system == gemmi::CrystalSystem::Trigonal;
std::optional<LatticeSearchResult> 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) {
@@ -57,8 +57,10 @@ std::optional<LatticeSearchResult> LatticeSearchForClass(const CrystalLattice& L
// metric cannot carry the group's system at all.
std::optional<LatticeSearchResult> 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<LatticeSearchResult> LatticeSearchForSystem(const CrystalLattice &L, gemmi::CrystalSystem system);