diff --git a/rugnux/RugnuxFirstPass.cpp b/rugnux/RugnuxFirstPass.cpp index 08285c70b..65b0d748e 100644 --- a/rugnux/RugnuxFirstPass.cpp +++ b/rugnux/RugnuxFirstPass.cpp @@ -2195,6 +2195,79 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) { } } + // Sub-lattice hypothesis: the standing cell's seven index-2 sub-lattices, in its own + // orientation and geometry, each scored on the validation frames. + // + // The FFT can only offer the cells its peaks build, and two lattices seen together - a twin + // domain or a second crystal whose reciprocal lattice shares an index-2 sub-lattice with + // this one's - build the lattice that contains them both: a cell twice the size of either, + // which indexes both crystals' spots and so wins every comparison of candidates the FFT + // returns. Where the true cell is then never offered, nothing downstream can choose it. + // Offering it costs seven frame counts. + // + // The frame count only nominates: a coarser lattice asks less accuracy of every spot, so a + // sub-lattice of the true cell can index as many frames as the cell itself, or a few more + // where the cell's own score is depressed. What decides is the comparison this pass already + // makes between a cell and its axis harmonic: the share of the validation frames' pooled + // spots each puts on itself over and above what a wrong spindle angle puts there, each + // against its own null (ValidationEvidencePrefers). A real superstructure keeps its cell on + // that count, because the class it adds holds reflections; a cell built out of two crystals + // loses it, because it has to place every spot of the one it describes twice as accurately + // with an orientation fitted to both. The nominee must also index a majority of the frames, + // the bar the false-promotion test above asks of a cell that "works", and no fewer frames + // than the standing cell: a standing cell that indexes almost nothing is not this crystal's + // lattice, its sub-lattices are not hypotheses about it, and the rescues below are what + // such a run needs. + if (!cancelled_ && best.result.has_value() && best.score > 0) { + const CrystalLattice prim = best.result->lattice + .ToPrimitive(best.result->search_result.centering); + const Coord A = prim.Vec0(), B = prim.Vec1(), C = prim.Vec2(); + std::optional sub_best; + std::string counts; + for (int u = 0; u < 2; u++) + for (int v = 0; v < 2; v++) + for (int w = 0; w < 2; w++) { + if (u + v + w == 0 || cancelled_) + continue; + const Coord t = (A * static_cast(u) + B * static_cast(v) + + C * static_cast(w)) / 2.0f; + const CrystalLattice sub = (w ? CrystalLattice(A, B, t) + : v ? CrystalLattice(A, t, C) + : CrystalLattice(t, B, C)).NiggliReduce(); + RotationIndexerResult cand = *best.result; + cand.lattice = sub; + cand.search_result = LatticeSearchResult{}; + cand.search_result.primitive_reduced = sub; + cand.search_result.conventional = sub; + cand.unconstrained.reset(); + cand.extra_lattices.clear(); + const int score = count_indexed(*indexer, cand); + counts += fmt::format(" ({},{},{}) {}", u, v, w, score); + if (!sub_best || score > sub_best->score) + sub_best = FirstPass{std::move(cand), score, + fmt::format("{} (sub-lattice {}{}{})", best.name, u, v, w), + std::abs(sub.CalcVolume())}; + } + bool adopt = false; + std::string verdict = " - none indexes a majority of the frames and as many as the standing cell"; + if (sub_best && sub_best->score >= best.score + && sub_best->score > static_cast(validation.size()) / 2) { + const PooledEvidence at_standing = pooled_evidence(*indexer, *best.result); + const PooledEvidence at_sub = pooled_evidence(*indexer, *sub_best->result); + adopt = ValidationEvidencePrefers(at_standing, at_sub); + verdict = fmt::format(" - the best puts {}/{} pooled spots on itself ({} by chance) against " + "the standing cell's {}/{} ({}), {}", + at_sub.on_lattice, at_sub.spots, at_sub.by_chance, + at_standing.on_lattice, at_standing.spots, at_standing.by_chance, + adopt ? "adopting it" : "keeping the standing cell"); + } + logger.Info("Sub-lattice hypothesis: the standing cell ({:.0f} A^3) indexes {}/{} validation " + "frames; its index-2 sub-lattices (half-translation u,v,w):{}{}", + best.vol, best.score, static_cast(validation.size()), counts, verdict); + if (adopt) + best = std::move(*sub_best); + } + // A lattice that indexes almost none of the validation frames is not this crystal's lattice. // Forcing it anyway integrates every image against it; the few partials that survive yield no // fulls in the 3D combine, and the run then dies inside the merge complaining about resolution -