diff --git a/docs/RUGNUX_CLI.md b/docs/RUGNUX_CLI.md index f195be852..3dc155f02 100644 --- a/docs/RUGNUX_CLI.md +++ b/docs/RUGNUX_CLI.md @@ -273,10 +273,10 @@ For very long axes the direction grid's angular resolution binds well below 500 | `--force-still` | Treat a rotation (goniometer) dataset as independent stills instead of rotation; several masters are then read as one stills run | | `-X, --indexing-algorithm ` | `Auto` (default) \| `FFT` \| `cuFFT` \| `FFTW` \| `FFBIDX` \| `None`, case-insensitive. `FFT` is the de-novo FFT search, on the GPU (cuFFT) where there is one and `--no-gpu` is not given, otherwise on the CPU (FFTW); `cuFFT` and `FFTW` name one implementation each; `cuFFT` needs a GPU and is refused without one. `FFBIDX` (known cell, `-C`) runs on the GPU where there is one and otherwise on the CPU. `Auto` takes `FFBIDX` on stills with a known cell, and `FFT` otherwise. `FFBIDX` without a cell (`-C`, or one from `-z`) resolves to `None` and indexes nothing, with no error. On rotation data `-X` is not consulted: the FFT search runs on the GPU where there is one and on the CPU otherwise, so `Auto`, `FFT`, `cuFFT` (with a GPU) and `FFTW` (without one, or under `--no-gpu`) are accepted and any other value stops the run at indexing; `FFBIDX` and `None` are for stills | | `-F` | Short for `-X FFT`, kept for old command lines | -| `-C, --unit-cell ` | Reference unit cell `"a,b,c,alpha,beta,gamma"` (required by `ffbidx`). On rotation data it also widens the FFT search to cover the cell given, at both ends: the longest axis looked for is raised to reach it, and `--fft-min-unit-cell` is lowered to admit it. A candidate that is an integer supercell of the cell given (a twin's coincidence lattice, a row taken at a multiple of its length) is stepped down to it. On stills the run always uses it: the geometry refinement takes it as a prior (1 % on the lengths, 1° on the angles the crystal system leaves free), and the log warns - with both numbers - where the frames refine its shape more than 3 % / 3° away, or where a sample of frames indexed de novo puts materially more spots on the lattice than the cell given ([§7.7](CPU_DATA_ANALYSIS_INDEXING.md#77-stills-a-given-cell-and-the-detector-modules)) | +| `-C, --unit-cell ` | Reference unit cell `"a,b,c,alpha,beta,gamma"` (required by `ffbidx`). On rotation data it also widens the FFT search to cover the cell given, at both ends: the longest axis looked for is raised to reach it, and `--fft-min-unit-cell` is lowered to admit it. A candidate that is an integer supercell of the cell given (a twin's coincidence lattice, a row taken at a multiple of its length) is stepped down to it. On stills the run always uses it: the geometry refinement takes it as a prior (1 % on the lengths, 1° on the angles the crystal system leaves free), and the log warns - with both numbers - where the frames refine its shape more than 3 % / 3° away, or where a sample of frames indexed de novo puts materially more spots on the lattice than the cell given ([§7.7](CPU_DATA_ANALYSIS_INDEXING.md#77-stills-a-given-cell-and-the-detector-modules)). Without `-S` the angles are read literally: an angle is 90° or 120° only where it is typed so (`90` or `90.00`, not `90.03`). A cell with no such angle, and not three equal angles, names a triclinic lattice, and the run behaves as with `-S P1` | | `--fft-min-unit-cell ` | Shortest cell axis the FFT search accepts, Å (default: 10; accepted 5-40). A candidate with a shorter axis is discarded — but on rotation data a row shorter than the floor, down to 3 Å, is recognised under the multiple of it the search reports past the floor, so a small-molecule cell is indexed without this flag. `-C` lowers the floor on its own to cover the cell given. On stills a crystal below the floor cannot be indexed unless this is lowered | | `--min-indexed-spots ` | Spots a frame must have on the lattice before it counts as indexed (default: 6, minimum 4). It sets the reported indexing rate and the count the rotation first pass ranks candidate lattices by; whether the run has a lattice at all is decided on the pooled spots instead ([§4.1](CPU_DATA_ANALYSIS_INDEXING.md#41-indexed-spot-decision-inlier-test)), and integration is not gated by it | -| `-S, --space-group ` | Space group number (`96`) or Hermann-Mauguin symbol (`P43212`) — for indexing and scaling. On serial stills whose group admits two indexings, it also lets the crystals be put on one from the data ([the indexing ambiguity](RUGNUX_ADVANCED.md#the-indexing-ambiguity)) | +| `-S, --space-group ` | Space group number (`96`) or Hermann-Mauguin symbol (`P43212`) — for indexing and scaling. On serial stills whose group admits two indexings, it also lets the crystals be put on one from the data ([the indexing ambiguity](RUGNUX_ADVANCED.md#the-indexing-ambiguity)). A fixed group fixes the lattice: indexing puts the crystal in the group's own Bravais class and nothing promotes, demotes, reduces or doubles it afterwards. A primitive group on a lattice with no primitive cell of its system (P2 on a C-centred monoclinic crystal, P3 on a rhombohedral one) is merged on the centred cell, and the positions the centring extinguishes are kept (they read about zero). With `-C` as well, the cell is written on the given cell's axes | | `-r, --geom-refine ` | Geometry refinement: `none` \| `orientation` \| `beam_and_lattice` (default; on rotation data restrained toward the sweep's geometry, [§7.4](CPU_DATA_ANALYSIS_INDEXING.md#74-multi-stage-tightening-of-inlier-tolerance)) \| `flex` (try all three per image, keep whichever indexes the most spots; alias `multi`) | | `-R, --two-pass-rotation[=num]` | Two-pass offline rotation indexing (default for goniometer data; optional first-pass image count, default 100) | | `--force-rotation-lattice ` | Force rotation lattice (9 floats, Å), skipping the first pass | diff --git a/image_analysis/IndexAndRefine.cpp b/image_analysis/IndexAndRefine.cpp index afdd25420..4c8ff1155 100644 --- a/image_analysis/IndexAndRefine.cpp +++ b/image_analysis/IndexAndRefine.cpp @@ -370,7 +370,9 @@ IndexAndRefine::IndexingOutcome IndexAndRefine::DetermineLatticeAndSymmetry(Data }; outcome.lattice_candidate = latt; } else { - auto sym_result = LatticeSearch(latt); + // A space group given without a cell still names the lattice's class (LatticeSearchForGroup). + const auto fixed = sg ? LatticeSearchForGroup(latt, *sg) : std::nullopt; + const auto sym_result = fixed ? *fixed : LatticeSearch(latt); outcome.symmetry = LatticeMessage{ .centering = sym_result.centering, .niggli_class = sym_result.niggli_class, diff --git a/image_analysis/lattice_search/LatticeSearch.cpp b/image_analysis/lattice_search/LatticeSearch.cpp index de3e127c3..505992cdd 100644 --- a/image_analysis/lattice_search/LatticeSearch.cpp +++ b/image_analysis/lattice_search/LatticeSearch.cpp @@ -547,6 +547,26 @@ std::optional LatticeSearchForClass(const CrystalLattice &L } +std::optional LatticeSearchForGroup(const CrystalLattice &L, const gemmi::SpaceGroup &sg) { + const char centring = sg.centring_type(); + const auto system = sg.crystal_system(); + const auto lattice_system = system == gemmi::CrystalSystem::Trigonal && centring == 'P' + ? gemmi::CrystalSystem::Hexagonal : system; + if (auto r = LatticeSearchForClass(L, lattice_system, centring)) + return r; + // A primitive group on a lattice with no primitive cell of the group's system - P 2 on a C-centred + // monoclinic lattice, P 3 on a rhombohedral one - is described on a centred cell of that system + // taken as primitive: the positions the centring extinguishes are then predicted and merged, as + // the group asks, and carry no intensity. + if (centring == 'P') + for (const char c : {'C', 'A', 'B', 'I', 'F', 'R'}) + if (auto r = LatticeSearchForClass(L, c == 'R' ? gemmi::CrystalSystem::Trigonal : system, c)) { + r->centering = 'P'; + return r; + } + return std::nullopt; +} + int LatticePointGroupOrder(gemmi::CrystalSystem system) { switch (system) { case gemmi::CrystalSystem::Monoclinic: return 2; diff --git a/image_analysis/lattice_search/LatticeSearch.h b/image_analysis/lattice_search/LatticeSearch.h index 5cf6588b6..da6ee8451 100644 --- a/image_analysis/lattice_search/LatticeSearch.h +++ b/image_analysis/lattice_search/LatticeSearch.h @@ -50,6 +50,13 @@ std::optional LatticeSearchForClass(const CrystalLattice& L // Order of the lattice point group, so "lower symmetry" is a well-defined comparison // (gemmi's enum orders Trigonal after Tetragonal, which have 6 and 8 rotations). +// The lattice of a space group the user fixed, searched for in L's metric: L is put in the setting of +// the group's own Bravais class and never promoted past it (a P 1 run stays triclinic on a metrically +// monoclinic cell). A trigonal-P group sits on a hexagonal-P lattice; a primitive group the lattice +// has no primitive cell for is put on a centred cell of its system, labelled 'P'. Empty where the +// metric cannot carry the group's system at all. +std::optional LatticeSearchForGroup(const CrystalLattice &L, const gemmi::SpaceGroup &sg); + int LatticePointGroupOrder(gemmi::CrystalSystem system); // Whether the conventional metric of this class asserts an equality between cell LENGTHS (a = b, and diff --git a/image_analysis/rotation_indexer/RotationIndexer.cpp b/image_analysis/rotation_indexer/RotationIndexer.cpp index fa6c7e111..a2d0a5ec3 100644 --- a/image_analysis/rotation_indexer/RotationIndexer.cpp +++ b/image_analysis/rotation_indexer/RotationIndexer.cpp @@ -313,17 +313,16 @@ void RotationIndexer::RunIndexingLocked() { // conventional hexagonal axes (LatticeSearch can land on the ortho-hexagonal C setting) so the // 3-fold is not hidden from scaling. // - // A user-fixed space group is deliberately NOT stamped on here. The group names the symmetry; - // it does not say which basis the FFT candidate came back in, and the conventional cell above - // was reduced for whatever class the METRIC matched. Relabelling that cell with the group's - // system and centring leaves the constrained refine snapping the wrong angles to the ideal - // ones: measured, a C-centred orthorhombic cell relabelled primitive monoclinic indexed 1 of - // 60 validation frames and an F-cubic one relabelled trigonal indexed 0 of 60, where the same - // frames index at 36/60 and 51/60 without a group. The group is applied where it belongs - to - // the scaling and the merge. + // A space group the user fixed decides the class: its own Bravais lattice is searched for in + // the candidate's metric (LatticeSearchForGroup), so the candidate is put in that class's + // setting rather than relabelled, and no promotion past it - a centring the group does not + // have, a metrically hexagonal cell - fires. Only where the metric cannot carry the group's + // class does the metric decide, and the scaling then reports the conflict. const bool demote_class = experiment.GetIndexingSettings().GetLatticeClassDemoted(); + const auto &fixed_sg = experiment.GetGemmiSpaceGroup(); auto build_sr = [&](const CrystalLattice &cand) -> LatticeSearchResult { - auto ls = LatticeSearch(cand); + const auto fixed = fixed_sg ? LatticeSearchForGroup(cand, *fixed_sg) : std::nullopt; + auto ls = fixed ? *fixed : LatticeSearch(cand); // The other hypothesis about a promotion that rests on a = b: walk the characters again // granting NO length equality at all, and take the class the metric carries on its angles // alone. Not the same as striking one class out - the tetragonal-P lattice also has a @@ -331,7 +330,7 @@ void RotationIndexer::RunIndexingLocked() { // very equality in question. The caller runs this as its own pass and keeps whichever pass // realises the lower held-out positional residual. The hexagonal re-expression below is a // promotion of the same kind, so it is not applied here. - if (demote_class && ClassImposesLengthEquality(ls.system)) + if (!fixed && demote_class && ClassImposesLengthEquality(ls.system)) return LatticeSearch(cand, /*dist_tolerance=*/0.0); // A primitive hexagonal lattice is written in ONE setting, the one derived from its reduced // cell, whichever route named the class. Its twelve equivalent settings are the same @@ -340,7 +339,7 @@ void RotationIndexer::RunIndexingLocked() { // under them, so a setting chosen afresh from each pass's strained cell lets the two // passes differ in setting and the guard compare rows that are not the same rows. if ((ls.system == gemmi::CrystalSystem::Hexagonal && ls.centering == 'P') - || (!IsHexagonalSystem(ls.system) && IsMetricallyHexagonal(ls.primitive_reduced))) { + || (!fixed && !IsHexagonalSystem(ls.system) && IsMetricallyHexagonal(ls.primitive_reduced))) { ls.conventional = HexagonalConventional(ls.primitive_reduced); ls.system = gemmi::CrystalSystem::Hexagonal; ls.centering = 'P'; @@ -416,12 +415,10 @@ void RotationIndexer::RunIndexingLocked() { const auto conv_uc = w.sr.conventional.GetUnitCell(); const float length_bound_A = 1.2f * static_cast(std::max({conv_uc.a, conv_uc.b, conv_uc.c})); w.constrained = make_data(w.sr.conventional, w.sr.system, length_bound_A); - // Pseudo-symmetry guard: also refine unconstrained (triclinic) on the primitive cell. Run it - // with a user-fixed space group too. The metric promotion the constrained refine acts on is - // decided by the geometry, not by the group, so it can be false whether or not a group was - // given - and without this cell there is nothing to catch it with, which is how a fixed - // group turned crystals the de-novo path indexes at 60/60 into runs that index none. - w.has_tri = (w.sr.system != gemmi::CrystalSystem::Triclinic); + // Pseudo-symmetry guard: also refine unconstrained (triclinic) on the primitive cell, which + // catches a false metric promotion. With a space group the user fixed there is no + // promotion to catch - the class is the group's - and no other lattice may be adopted. + w.has_tri = !fixed_sg && w.sr.system != gemmi::CrystalSystem::Triclinic; if (w.has_tri) w.tri = make_data(w.sr.primitive_reduced, gemmi::CrystalSystem::Triclinic, length_bound_A); w.viable = true; diff --git a/rugnux/RugnuxFirstPassRescues.cpp b/rugnux/RugnuxFirstPassRescues.cpp index 54eeacc0f..8b403339a 100644 --- a/rugnux/RugnuxFirstPassRescues.cpp +++ b/rugnux/RugnuxFirstPassRescues.cpp @@ -212,7 +212,7 @@ void Rugnux::FirstPassRun::StartLongAxisSearch(std::unique_ptr indexing_bound_A)) @@ -273,7 +273,7 @@ void Rugnux::FirstPassRun::JoinLongAxisSpeculation() { // Not when a cell was given: the standard pass was already sized for it (RaiseFFTBoundForKnownCell). auto Rugnux::FirstPassRun::LongAxisHypothesis(FirstPass standing) -> FirstPass { JoinLongAxisSpeculation(); - if (rx.cancelled_ || rx.experiment_.GetUnitCell().has_value()) + if (rx.cancelled_ || rx.experiment_.GetUnitCell().has_value() || rx.user_fixed_sg_) return standing; const auto start = std::chrono::steady_clock::now(); const LongAxisReach reach = LongAxisBound(); @@ -961,6 +961,9 @@ namespace { } auto Rugnux::FirstPassRun::SubLatticeHypothesis(FirstPass best) -> FirstPass { + // A space group the user fixed fixes the lattice, its volume included. + if (rx.user_fixed_sg_) + return best; // Asked again of each sub-lattice it adopts: a cell doubled along two or three axes is a sub-lattice // of index 4 or 8, reached one halving at a time. Each cell on the way is first asked whether it is // the coincidence lattice of two twin domains: two domains of a cell take fewer nodes than any diff --git a/rugnux/RugnuxScaleMerge.cpp b/rugnux/RugnuxScaleMerge.cpp index ea07e8a7c..4dcd8a49c 100644 --- a/rugnux/RugnuxScaleMerge.cpp +++ b/rugnux/RugnuxScaleMerge.cpp @@ -1197,14 +1197,24 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { axial.reserve(summed.size()); for (const auto &[hkl, sum] : summed) axial.push_back({hkl, sum.first / std::sqrt(sum.second)}); - const gemmi::Op cob = SeatGroupByAbsences(*result.consensus_cell, *user_fixed_sg_, axial); + // With the cell given too, the setting is the user's: the cell goes onto the given cell's axes. + 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(); + } else + cob = SeatGroupByAbsences(*result.consensus_cell, *user_fixed_sg_, axial); if (!(cob == gemmi::Op::identity())) { reseat_integrated(cob); const auto &uc = *result.consensus_cell; - logger.Info("The fixed space group {} names its symmetry elements by axis, and the absences " - "on the {} axial and zonal reflections put them on other axes of this cell than " - "the indexing did: reindexed by {} to a={:.3f} b={:.3f} c={:.3f} alpha={:.2f} " - "beta={:.2f} gamma={:.2f}", user_fixed_sg_->xhm(), axial.size(), + const std::string why = user_cell_ + ? std::string("the given cell puts them on other axes") + : fmt::format("the absences on the {} axial and zonal reflections put them on other axes", + axial.size()); + logger.Info("The fixed space group {} names its symmetry elements by axis, and {} of this cell " + "than the indexing did: reindexed by {} to a={:.3f} b={:.3f} c={:.3f} alpha={:.2f} " + "beta={:.2f} gamma={:.2f}", user_fixed_sg_->xhm(), why, IndexTriplet(HklOperator(cob)), uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma); } } @@ -3155,12 +3165,26 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { // search there. The enumeration is untouched, so no candidate that JUDGES another moves and // no chi2 reference changes; the doubled setting still wins its own table, and only the cell // its answer is expressed on is corrected. + // + // P 1 is the same case without the signal. The table has no centred setting of it, so on a + // centred lattice whose intensities carry no symmetry it wins on the centred cell itself and + // keeps the positions the centring adds as observations - measured, 0.28 on them + // against 7.0 on the lattice's own nodes, half the merge noise. The lattice's centring stands + // in for the group's there. + const char indexed_centring = end_msg.rotation_lattice_type.has_value() + ? end_msg.rotation_lattice_type->centering : 'P'; + const bool triclinic_on_centred = sg_search.best_space_group.has_value() + && sg_search.best_space_group->crystal_system() == gemmi::CrystalSystem::Triclinic + && indexed_centring != 'P'; if (!commit_reindex && sg_search.best_space_group.has_value() - && sg_search.best_space_group->number > 1 + && (sg_search.best_space_group->number > 1 || triclinic_on_centred) && end_msg.rotation_lattice.has_value() && end_msg.rotation_lattice_type.has_value()) { const gemmi::SpaceGroup won = *sg_search.best_space_group; constexpr double den3 = static_cast(gemmi::Op::DEN) * gemmi::Op::DEN * gemmi::Op::DEN; - const double det = won.basisop().det_rot() / den3; + const double det = triclinic_on_centred + ? 1.0 / (indexed_centring == 'F' ? 4 : indexed_centring == 'R' ? 3 : 2) + : won.basisop().det_rot() / den3; + const char centring = triclinic_on_centred ? indexed_centring : won.centring_type(); const int multiple = static_cast(std::lround(1.0 / det)); // 2 for C 1 1 2_1, 4 for F 1 if (det < 0.99 && multiple >= 2 && multiple <= 4) { // Reduce, then classify. The character table is reached through a Niggli reduction @@ -3171,7 +3195,7 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) { // too (that is how it got here), and an unrestricted search would hand it straight // back. const auto cand = LatticeSearchForClass( - end_msg.rotation_lattice->ToPrimitive(won.centring_type()), + end_msg.rotation_lattice->ToPrimitive(centring), won.crystal_system(), 'P'); // Change of basis from the doubled conventional setting straight to the reduced one, // P[i][j] = conv_real[i] . doubled_reciprocal[j], as everywhere else here - except diff --git a/rugnux/rugnux_cli.cpp b/rugnux/rugnux_cli.cpp index da59aa7c7..21cceb83c 100644 --- a/rugnux/rugnux_cli.cpp +++ b/rugnux/rugnux_cli.cpp @@ -1945,6 +1945,19 @@ int RugnuxInputRun::PrepareRugnuxInput() { : fmt::format("no GPU visible - {} CPU threads, which is much slower", nthreads)); console->Rule('-'); + // A cell given with -C and no -S is read literally: an angle is 90 or 120 deg only where it was + // typed so. A cell with no such angle, and not the three equal angles of a rhombohedral cell, names + // a triclinic lattice, so its group is P 1 - and the lattice and setting are then kept as for -S P1. + if (fixed_reference_unit_cell && space_group == nullptr) { + const auto &c = *fixed_reference_unit_cell; + const auto special = [](double x) { return x == 90.0 || x == 120.0; }; + if (!special(c.alpha) && !special(c.beta) && !special(c.gamma) + && !(c.alpha == c.beta && c.beta == c.gamma)) { + space_group = gemmi::find_spacegroup_by_number(1); + logger.Info("The cell given with -C has no angle of 90 or 120 deg, so it names a triclinic " + "lattice: space group P 1"); + } + } if (space_group != nullptr) logger.Info("Using space group {} (number {})", space_group->hm, space_group->number); diff --git a/tests/LatticeSearchTest.cpp b/tests/LatticeSearchTest.cpp index 72bafb701..f8f2217c5 100644 --- a/tests/LatticeSearchTest.cpp +++ b/tests/LatticeSearchTest.cpp @@ -756,3 +756,33 @@ TEST_CASE("AngleEqualityDeparture_deg measures what an orthorhombic promotion of tetra.system = gemmi::CrystalSystem::Tetragonal; CHECK(AngleEqualityDeparture_deg(tetra, sr.primitive_reduced) == 0.0); } + +TEST_CASE("LatticeSearch - a given triclinic cell that is metrically monoclinic C is honoured in P1") { + // A triclinic cell, Niggli-reduced, whose metric carries a two-fold: the same lattice is C-centred + // monoclinic, 21.0 6.3 9.8 90 106 90, and that is what the metric alone names it. + const CrystalLattice given(UnitCell(6.3, 9.8, 10.9623, 105.3083, 106.6992, 90.0)); + const auto by_metric = LatticeSearch(given); + CHECK(by_metric.system == gemmi::CrystalSystem::Monoclinic); + CHECK(by_metric.centering == 'C'); + + // Fixed in P 1 the lattice is not promoted: it stays triclinic, on the given cell. + const auto p1 = LatticeSearchForGroup(given, gemmi::SpaceGroup(*gemmi::find_spacegroup_by_name("P 1"))); + REQUIRE(p1.has_value()); + CHECK(p1->system == gemmi::CrystalSystem::Triclinic); + CHECK(p1->centering == 'P'); + check_uc(p1->conventional.GetUnitCell(), 6.3, 9.8, 10.9623, 105.3083, 106.6992, 90.0, 1e-3, 1e-2); + + // Fixed in C 2 it is put in the group's own class. + const auto c2 = LatticeSearchForGroup(given, gemmi::SpaceGroup(*gemmi::find_spacegroup_by_name("C 1 2 1"))); + REQUIRE(c2.has_value()); + CHECK(c2->system == gemmi::CrystalSystem::Monoclinic); + CHECK(c2->centering == 'C'); + + // Fixed in P 2, a group the lattice has no primitive monoclinic cell for: it is put on the C-centred + // cell taken as primitive, twice the volume, so the positions the centring extinguishes are kept. + const auto p2 = LatticeSearchForGroup(given, gemmi::SpaceGroup(*gemmi::find_spacegroup_by_name("P 1 2 1"))); + REQUIRE(p2.has_value()); + CHECK(p2->system == gemmi::CrystalSystem::Monoclinic); + CHECK(p2->centering == 'P'); + CHECK(std::abs(p2->conventional.CalcVolume()) == Catch::Approx(2.0 * std::abs(given.CalcVolume())).epsilon(1e-3)); +}