Space-group search (image_analysis/scale_merge/SearchSpaceGroup): - Two-stage POINTLESS-style determination. Stage A scores each distinct rotation operator once (was once per candidate space group, ~34x faster on lysozyme: ~26s -> <1s) and picks the largest point group all of whose operators confirm. Stage B picks the maximal space group whose predicted absences are confirmed weak, fixing the prototype's default to the symmorphic group (it returned P422 instead of P4(3)2(1)2). Enantiomorphic / origin-ambiguous pairs (P4(1) vs P4(3), I222 vs I2(1)2(1)2(1)) are reported as indistinguishable. - Constrain candidates to subgroups of the lattice (metric) holohedry and weigh centering only P-vs-metric, fed from rotation indexing's LatticeSearch result. Integration / pipeline: - With no user-fixed space group, predict in P (IndexAndRefine) so the centering-absent reflections are integrated and the search can confirm/deny centering (catching pseudo-centering / a missed superstructure) instead of trusting the metric; a user-fixed group still rejects absences in integration. - JFJochProcess: scale+merge in P1 -> determine the space group -> set it and re-scale+merge in it (statistics then come out in the right symmetry) -> write it to /entry/sample/space_group_number (new EndMessage.space_group_number, preferred by NXmx::Sample). jfjoch_scale no longer searches; it consumes the file's space group (and no longer clobbers it with an empty -S). Twinning (new image_analysis/scale_merge/TwinningAnalysis): Padilla-Yeates L-test (<|L|>, <L^2>; acentric-only, positive intensities so L is bounded) plus a shell-normalised <I^2>/<I>^2 second moment and a twin-fraction estimate. Reported after the final merge in jfjoch_process and jfjoch_scale, and surfaced in the jfjoch_viewer merge-statistics window with a red outline when twinning is suspected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
120 lines
4.8 KiB
C++
120 lines
4.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "../common/DiffractionExperiment.h"
|
|
#include "../common/PixelMask.h"
|
|
#include "../common/CrystalLattice.h"
|
|
#include "../common/Reflection.h" // MergedReflection
|
|
#include "../common/JFJochMessages.h" // DataMessage
|
|
#include "../common/JFJochReceiverPlots.h" // MeanProcessingTime
|
|
#include "../image_analysis/spot_finding/SpotFindingSettings.h"
|
|
#include "../image_analysis/scale_merge/Merge.h" // MergeStatistics
|
|
#include "../image_analysis/scale_merge/TwinningAnalysis.h" // TwinningAnalysisResult
|
|
|
|
class JFJochHDF5Reader;
|
|
|
|
// Offline reprocessing of a stored Jungfraujoch HDF5 dataset, shared by jfjoch_process,
|
|
// jfjoch_azint and (later) the viewer. The full processing workflow lives here, not in the CLIs:
|
|
// setup, an optional two-pass rotation-indexing pre-pass, a parallel per-image loop (std::thread),
|
|
// an optional scaling/merging post-pass, and the _process.h5 output. The detector geometry and all
|
|
// algorithm settings are configured on the DiffractionExperiment by the caller; ProcessConfig only
|
|
// carries run control. Cancellable from any thread (e.g. SIGINT or a GUI button) via Cancel().
|
|
enum class ProcessMode {
|
|
AzimuthalIntegration, // preprocess + azimuthal integration only (jfjoch_azint)
|
|
FullAnalysis // spot finding + indexing + refinement + integration (jfjoch_process)
|
|
};
|
|
|
|
struct ProcessConfig {
|
|
ProcessMode mode = ProcessMode::FullAnalysis;
|
|
|
|
int start_image = 0;
|
|
int end_image = -1; // -1 => to the end of the dataset
|
|
int stride = 1;
|
|
int nthreads = 1;
|
|
|
|
// Output prefix for the _process.h5 (and scaled reflections). Empty => process without writing.
|
|
std::string output_prefix;
|
|
|
|
SpotFindingSettings spot_finding; // FullAnalysis spot finding
|
|
|
|
// Rotation indexing (FullAnalysis)
|
|
bool rotation_indexing = false;
|
|
bool two_pass_rotation = true;
|
|
bool reuse_rotation_spots = true;
|
|
int rotation_indexing_image_count = 100;
|
|
std::optional<CrystalLattice> forced_rotation_lattice;
|
|
|
|
// Scaling / merging (FullAnalysis). reference_data (from a reference MTZ) also drives the
|
|
// per-image live scaling path when present.
|
|
bool run_scaling = false;
|
|
int64_t scaling_iter = 3;
|
|
std::vector<MergedReflection> reference_data;
|
|
|
|
// Diagnostic: if set, the -P rot3d combine writes the unmerged fulls here (for comparison vs XDS).
|
|
std::string observation_dump_path;
|
|
};
|
|
|
|
struct ProcessResult {
|
|
bool cancelled = false;
|
|
uint64_t images_processed = 0;
|
|
double processing_time_s = 0.0;
|
|
double frame_rate_hz = 0.0;
|
|
double throughput_MBs = 0.0;
|
|
std::optional<float> indexing_rate;
|
|
std::optional<UnitCell> consensus_cell;
|
|
bool rotation_lattice_found = false;
|
|
MeanProcessingTime mean_processing_time{};
|
|
std::optional<std::string> written_master_path;
|
|
std::string merge_statistics_text; // populated when scaling/merging ran
|
|
|
|
// Structured merge statistics (per-shell + overall), populated when scaling/merging ran. ISa is
|
|
// the error-model asymptotic I/sigma (1/b); has_reference is true when a reference MTZ drove CCref.
|
|
bool has_merge_statistics = false;
|
|
MergeStatistics merge_statistics;
|
|
double error_model_isa = 0.0;
|
|
bool has_reference = false;
|
|
|
|
// Twinning analysis of the final merged intensities (l_test_pairs == 0 when not computed).
|
|
TwinningAnalysisResult twinning;
|
|
|
|
// Space group determined by the search (when the user did not fix one), used for the final
|
|
// re-scale/merge and written to the master file.
|
|
std::optional<int64_t> space_group_number;
|
|
};
|
|
|
|
// Callbacks for progress and live results. Methods may be called from worker threads, so an
|
|
// implementation must be thread-safe. The default no-ops suit the CLIs.
|
|
class JFJochProcessObserver {
|
|
public:
|
|
virtual ~JFJochProcessObserver() = default;
|
|
virtual void OnPhase(const std::string &phase) {}
|
|
virtual void OnProgress(uint64_t done, uint64_t total) {}
|
|
virtual void OnImageProcessed(const DataMessage &msg) {}
|
|
};
|
|
|
|
class JFJochProcess {
|
|
JFJochHDF5Reader &reader_;
|
|
DiffractionExperiment experiment_;
|
|
PixelMask pixel_mask_;
|
|
ProcessConfig config_;
|
|
std::atomic<bool> cancelled_{false};
|
|
|
|
public:
|
|
JFJochProcess(JFJochHDF5Reader &reader, DiffractionExperiment experiment,
|
|
PixelMask pixel_mask, ProcessConfig config);
|
|
|
|
// Runs the configured workflow to completion or until Cancel(). Throws on setup failure.
|
|
ProcessResult Run(JFJochProcessObserver *observer = nullptr);
|
|
|
|
// Request cancellation; safe to call from any thread (the worker loop checks between images).
|
|
void Cancel() { cancelled_ = true; }
|
|
bool IsCancelled() const { return cancelled_; }
|
|
};
|