diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c4d63c58e..1b4614050 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -18,6 +18,7 @@ * The rugnux reindexing resolver refuses a reference correlation measured on too few reflections instead of scoring it zero, so a run is no longer reindexed on an operator that mapped almost everything outside the reference's coverage. * `SPACE_GROUP_ALTERNATIVES=` lists every candidate the absences support equally well, keyed on the absence evidence rather than on a raw count, so a group predicting one more absence on a zone the sweep never measured is no longer dropped from the list. * A screw axis whose absences the merged data show to be extinct is no longer refused because a handful of reflections in its class read as present, so a crystal whose strongest axial row carries rocking-curve tails from its neighbours is assigned the screw its absences support. +* `-C` accepts a known cell in any equivalent description - conventional or primitive, centred or not - instead of only the reduced primitive form, so a centred cell given the way it is published no longer makes the run report that it found no lattice. * The rugnux space-group search determines glide planes from zonal systematic absences, so a non-Sohncke space group such as P 2_1/c or Pbca is named where the run previously stopped at its Sohncke subgroup; the results report carries the best Sohncke group for the same data as `SOHNCKE_SPACE_GROUP=` on every run, and `REPORT_VERSION` is 12. A centre of symmetry is not determinable from intensities and is never claimed. * `rugnux` corrects each reflection for the sensor's quantum efficiency at the angle the diffracted beam meets the detector. diff --git a/image_analysis/indexing/PostIndexingRefinement.cpp b/image_analysis/indexing/PostIndexingRefinement.cpp index 7875accf1..e3f20dc3c 100644 --- a/image_analysis/indexing/PostIndexingRefinement.cpp +++ b/image_analysis/indexing/PostIndexingRefinement.cpp @@ -172,36 +172,37 @@ std::vector Refine(const std::vector &in_spots, const float cos_min_angle = std::cos(p.min_angle_deg * PI / 180.0f); const float cos_max_angle = std::cos(p.max_angle_deg * PI / 180.0f); + // A reference cell is typed the way a deposit or a paper states it, which for a centred lattice + // is the CONVENTIONAL cell - and the candidates it is compared against are Niggli-reduced + // PRIMITIVE cells, whose edges a C, I, F or R description does not have. Compared as typed, a + // centred reference therefore rejects the true candidate: it survives only where the transform + // happened to build the centred cell itself as well - a cell of a sublattice, on which the run + // then proceeds - and otherwise no lattice is returned at all, so the user who quotes the deposit + // is exactly the one the option fails. The reference is therefore expanded into the primitive + // lattices its six numbers could stand for, one per centring, each reduced the way a candidate + // is; a candidate matching any of them is kept. The cell as typed stays in the set because + // ffbidx hands back the basis it was given, unreduced. + std::vector reference_cells; + if (p.reference_unit_cell) { + reference_cells.push_back(*p.reference_unit_cell); + const CrystalLattice reference(*p.reference_unit_cell); + for (const char centering: {'A', 'B', 'C', 'I', 'F', 'R'}) + reference_cells.push_back(reference.ToPrimitive(centering).NiggliReduce().GetUnitCell()); + reference_cells.push_back(reference.NiggliReduce().GetUnitCell()); + } + for (int i = 0; i < scores.size(); i++) { Eigen::Matrix3f cell_rows = oCell.block(3u * i, 0u, 3u, 3u); Eigen::Matrix3f cell_cols = cell_rows.transpose(); Eigen::Vector3f row_norms = cell_rows.rowwise().norm(); - if (p.reference_unit_cell) { + if (!reference_cells.empty()) { std::array obs = {row_norms(0), row_norms(1), row_norms(2)}; - std::array ref = { - static_cast(p.reference_unit_cell->a), - static_cast(p.reference_unit_cell->b), - static_cast(p.reference_unit_cell->c) - }; std::sort(obs.begin(), obs.end()); - std::sort(ref.begin(), ref.end()); - bool lengths_ok = true; - for (int k = 0; k < 3; ++k) { - const float denom = std::max(ref[k], REFINE_MIN_REFERENCE_LENGTH_EPSILON); - const float rel_dev = std::abs(obs[k] - ref[k]) / denom; - if (rel_dev > p.dist_tolerance_vs_reference) { - lengths_ok = false; - break; - } - } - if (!lengths_ok) - continue; - - // Also require the angles to match the reference. Fold each to its acute complement - // (min(x,180-x)) so the obtuse/acute setting choice is irrelevant, then compare the - // sorted triples. Guards against a right-edges/wrong-angle cell (a pseudo-symmetric + // The angles are compared as well as the lengths. Each is folded to its acute complement + // (min(x,180-x)) so the obtuse/acute setting choice is irrelevant, then the sorted + // triples are compared. Guards against a right-edges/wrong-angle cell (a pseudo-symmetric // near-metric, e.g. a monoclinic beta refined to the wrong value) passing on lengths. auto fold = [](float deg) { return std::min(deg, 180.0f - deg); }; auto row_angle = [&](int i, int j) { @@ -209,22 +210,27 @@ std::vector Refine(const std::vector &in_spots, -1.0f, 1.0f)) * 180.0f / PI; }; std::array obs_ang = {fold(row_angle(1, 2)), fold(row_angle(0, 2)), fold(row_angle(0, 1))}; - std::array ref_ang = { - fold(static_cast(p.reference_unit_cell->alpha)), - fold(static_cast(p.reference_unit_cell->beta)), - fold(static_cast(p.reference_unit_cell->gamma)) - }; std::sort(obs_ang.begin(), obs_ang.end()); - std::sort(ref_ang.begin(), ref_ang.end()); - bool angles_ok = true; - for (int k = 0; k < 3; ++k) { - if (std::abs(obs_ang[k] - ref_ang[k]) > REFINE_ANGLE_TOLERANCE_VS_REFERENCE_DEG) { - angles_ok = false; - break; + auto matches = [&](const UnitCell &reference) { + std::array ref = {reference.a, reference.b, reference.c}; + std::sort(ref.begin(), ref.end()); + for (int k = 0; k < 3; ++k) { + const float denom = std::max(ref[k], REFINE_MIN_REFERENCE_LENGTH_EPSILON); + if (std::abs(obs[k] - ref[k]) / denom > p.dist_tolerance_vs_reference) + return false; } - } - if (!angles_ok) + + std::array ref_ang = {fold(reference.alpha), fold(reference.beta), fold(reference.gamma)}; + std::sort(ref_ang.begin(), ref_ang.end()); + for (int k = 0; k < 3; ++k) { + if (std::abs(obs_ang[k] - ref_ang[k]) > REFINE_ANGLE_TOLERANCE_VS_REFERENCE_DEG) + return false; + } + return true; + }; + + if (std::none_of(reference_cells.begin(), reference_cells.end(), matches)) continue; } else { if (row_norms.minCoeff() < p.min_length_A || row_norms.maxCoeff() > p.max_length_A) diff --git a/tests/IndexingUnitTest.cpp b/tests/IndexingUnitTest.cpp index 49c0365d4..0d299f331 100644 --- a/tests/IndexingUnitTest.cpp +++ b/tests/IndexingUnitTest.cpp @@ -246,6 +246,50 @@ TEST_CASE("FFTIndexer","[Indexing]") { logger.Info("Time: {} ms", std::chrono::duration_cast(end - start).count()); } +TEST_CASE("FFTIndexer_CentredReferenceCell","[Indexing]") { + // A reference cell is quoted the way a deposit states it, which for a centred lattice is the + // conventional cell - and the indexer's candidates are Niggli-reduced primitive cells, whose + // edges that description does not have. The two descriptions of one lattice must therefore + // select the same candidate, or the user who quotes the deposit gets no lattice at all. + const UnitCell conventional{70.0f, 70.0f, 70.0f, 90.0f, 90.0f, 90.0f}; + const CrystalLattice primitive = CrystalLattice(conventional).ToPrimitive('F'); + const UnitCell primitive_uc = primitive.GetUnitCell(); + + std::vector vec; + for (int h = -3; h < 8; h++) + for (int k = -3; k < 8; k++) + for (int l = -3; l < 8; l++) + vec.push_back(h * primitive.Astar() + k * primitive.Bstar() + l * primitive.Cstar()); + + auto index_with = [&](const UnitCell &reference) { + DiffractionExperiment experiment; + IndexingSettings settings; + settings.Algorithm(IndexingAlgorithmEnum::FFT) + .FFT_MaxUnitCell_A(250.0).FFT_HighResolution_A(2 * M_PI / 3.0); + experiment.ImportIndexingSettings(settings).SetUnitCell(reference); + std::unique_ptr indexer = CreateIndexer(experiment); + REQUIRE(indexer); + return indexer->Run(vec).lattice; + }; + + const auto from_primitive = index_with(primitive_uc); + const auto from_conventional = index_with(conventional); + + REQUIRE(from_primitive.size() == 1); + REQUIRE(from_conventional.size() == 1); + + for (const auto &found : {from_primitive[0], from_conventional[0]}) { + const auto uc_out = found.GetUnitCell(); + CHECK(uc_out.a == Catch::Approx(primitive_uc.a).epsilon(0.01)); + CHECK(uc_out.b == Catch::Approx(primitive_uc.b).epsilon(0.01)); + CHECK(uc_out.c == Catch::Approx(primitive_uc.c).epsilon(0.01)); + CHECK(uc_out.alpha == Catch::Approx(primitive_uc.alpha).epsilon(0.01)); + CHECK(uc_out.beta == Catch::Approx(primitive_uc.beta).epsilon(0.01)); + CHECK(uc_out.gamma == Catch::Approx(primitive_uc.gamma).epsilon(0.01)); + } + +} + TEST_CASE("FFTIndexer_SpindleSeverity", "[Indexing][Spindle]") { // End to end through the real indexer: a crystal whose shortest row lies on the spindle must // come back with a severity of 1 from a normal run, from a severity-only run - which must not