diff --git a/image_analysis/RotationIndexer.cpp b/image_analysis/RotationIndexer.cpp index 8e1264c7..2e7bbc84 100644 --- a/image_analysis/RotationIndexer.cpp +++ b/image_analysis/RotationIndexer.cpp @@ -12,8 +12,8 @@ RotationIndexer::RotationIndexer(const DiffractionExperiment &x, IndexerThreadPo index_ice_rings(x.GetIndexingSettings().GetIndexIceRings()), axis_(x.GetGoniometer()), geom_(x.GetDiffractionGeometry()), + updated_geom_(geom_), indexer_(indexer) { - if (axis_) { float angle_norm_deg = std::fabs(axis_->GetIncrement_deg()); if (angle_norm_deg < 1e-6) { @@ -40,8 +40,6 @@ void RotationIndexer::SetLattice(const CrystalLattice &lattice) { indexed_lattice = lattice; } -#include - void RotationIndexer::TryIndex() { // Index std::vector v_sel; @@ -80,14 +78,14 @@ void RotationIndexer::TryIndex() { auto indexer_result = indexer_.Run(experiment, coords_sel).get(); if (!indexer_result.lattice.empty()) { // Find lattice type - auto sym_result = LatticeSearch(indexer_result.lattice[0]); + search_result_ = LatticeSearch(indexer_result.lattice[0]); // Run refinement DiffractionExperiment experiment_copy(experiment); XtalOptimizerData data{ .geom = experiment_copy.GetDiffractionGeometry(), - .latt = sym_result.conventional, - .crystal_system = sym_result.system, + .latt = search_result_.conventional, + .crystal_system = search_result_.system, .min_spots = experiment.GetIndexingSettings().GetViableCellMinSpots(), .refine_beam_center = true, .refine_distance_mm = true, @@ -97,12 +95,14 @@ void RotationIndexer::TryIndex() { if (data.crystal_system == gemmi::CrystalSystem::Trigonal) data.crystal_system = gemmi::CrystalSystem::Hexagonal; - if (XtalOptimizer(data, v_sel)) + if (XtalOptimizer(data, v_sel)) { indexed_lattice = data.latt; + updated_geom_ = data.geom; + } } } -std::optional RotationIndexer::ProcessImage(int64_t image, const std::vector &spots) { +std::optional RotationIndexer::ProcessImage(int64_t image, const std::vector &spots) { std::unique_lock ul(m); // For non-rotation just ignore the whole procedure @@ -130,7 +130,11 @@ std::optional RotationIndexer::ProcessImage(int64_t image, const } if (indexed_lattice) - return indexed_lattice->Multiply(rot.transpose()); + return RotatinIndexerImageResult{ + .lattice = indexed_lattice->Multiply(rot.transpose()), + .search_result = search_result_, + .geom = updated_geom_ + }; return {}; } diff --git a/image_analysis/RotationIndexer.h b/image_analysis/RotationIndexer.h index 9f8a8b62..9e28803c 100644 --- a/image_analysis/RotationIndexer.h +++ b/image_analysis/RotationIndexer.h @@ -10,6 +10,7 @@ #include "../common/DiffractionSpot.h" #include "../common/DiffractionExperiment.h" #include "indexing/IndexerThreadPool.h" +#include "lattice_search/LatticeSearch.h" // RotationIndexer works as following: // 1. First accumulates spot results from rotation images (only images within a certain stride are included) @@ -17,12 +18,18 @@ // 3. If indexing is successful - lattice is provided that is used by subsequent images // 4. If indexing is not-successful - accumulation procedure is continued +struct RotatinIndexerImageResult { + CrystalLattice lattice; + LatticeSearchResult search_result; + DiffractionGeometry geom; +}; + class RotationIndexer { mutable std::mutex m; const DiffractionExperiment& experiment; constexpr static int64_t max_spots = 32768; - constexpr static float min_accum_angle_deg = 20.0; + constexpr static float min_accum_angle_deg = 10.0; constexpr static float stride_angle_deg = 0.5; constexpr static int64_t min_images_for_indexing = 10; @@ -32,6 +39,8 @@ class RotationIndexer { std::vector coords_; std::optional axis_; const DiffractionGeometry geom_; + DiffractionGeometry updated_geom_; + LatticeSearchResult search_result_; IndexerThreadPool &indexer_; @@ -42,11 +51,13 @@ class RotationIndexer { int64_t first_image_to_try_indexing; std::optional indexed_lattice; + + void TryIndex(); public: RotationIndexer(const DiffractionExperiment& x, IndexerThreadPool& indexer); void SetLattice(const CrystalLattice &lattice); - std::optional ProcessImage(int64_t image, const std::vector& spots); + std::optional ProcessImage(int64_t image, const std::vector& spots); std::optional Finalize(bool retry); };