// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #ifndef JFJOCH_INDEXANDREFINE_H #define JFJOCH_INDEXANDREFINE_H #include #include #include "../common/DiffractionSpot.h" #include "../common/DiffractionExperiment.h" #include "bragg_prediction/BraggPrediction.h" #include "indexing/IndexerThreadPool.h" #include "lattice_search/LatticeSearch.h" #include "scale_merge/ScaleAndMerge.h" #include "RotationIndexer.h" #include "RotationParameters.h" class IndexAndRefine { const bool index_ice_rings; const DiffractionExperiment& experiment; const DiffractionGeometry geom_; std::optional indexed_lattice; std::optional axis_; IndexerThreadPool *indexer_; std::unique_ptr rotation_indexer; RotationParameters rotation_parameters; struct IndexingOutcome { std::optional lattice_candidate; DiffractionExperiment experiment; LatticeMessage symmetry{ .centering = 'P', .niggli_class = 0, .crystal_system = gemmi::CrystalSystem::Triclinic }; bool beam_center_updated = false; explicit IndexingOutcome(const DiffractionExperiment& experiment_ref) : experiment(experiment_ref) {} }; mutable std::mutex reflections_mutex; std::vector> reflections; std::vector mosaicity; IndexingOutcome DetermineLatticeAndSymmetry(DataMessage &msg); void RefineGeometryIfNeeded(DataMessage &msg, IndexingOutcome &outcome); void QuickPredictAndIntegrate(DataMessage &msg, const SpotFindingSettings &spot_finding_settings, const CompressedImage &image, BraggPrediction &prediction, const IndexingOutcome &outcome); public: IndexAndRefine(const DiffractionExperiment &x, IndexerThreadPool *indexer); void ProcessImage(DataMessage &msg, const SpotFindingSettings &settings, const CompressedImage &image, BraggPrediction &prediction); /// Run scale-and-merge on accumulated reflections to refine per-image /// mosaicity (and optionally B-factors / scale factors). /// Returns std::nullopt if there are too few reflections to be meaningful. std::optional ScaleRotationData(const ScaleMergeOptions &opts = {}) const; std::optional Finalize(); }; #endif //JFJOCH_INDEXANDREFINE_H