Files
Jungfraujoch/image_analysis/scale_merge/ScaleAndMerge.h
T

75 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <vector>
#include <cstdint>
#include <optional>
#include "../../common/Reflection.h"
#include "gemmi/symmetry.hpp"
struct ScaleMergeOptions {
bool refine_b_factor = true;
int max_num_iterations = 100;
double max_solver_time_s = 1.0;
double image_number_rounding = 1.0;
double min_sigma = 1e-3;
bool fix_first_image_scale = true;
std::optional<double> b_min = 0.0;
std::optional<double> b_max = 200.0;
// Symmetry canonicalization of HKL prior to merging/scaling.
// If not set, the routine uses raw HKL as-is.
std::optional<gemmi::SpaceGroup> space_group;
// If true, treat Friedel mates as equivalent (merge anomalous pairs).
// If false, keep them separate by including a sign flag in the HKL key.
bool merge_friedel = true;
// --- Kabsch(XDS)-style partiality model ---
// Rotation range (wedge) used in partiality calculation.
// Set to 0 to disable partiality correction.
double wedge_deg = 1.0;
// --- Mosaicity (user input in degrees; internally converted to radians) ---
bool refine_mosaicity = true;
double mosaicity_init_deg = 0.17; // ~0.003 rad
std::optional<double> mosaicity_min_deg = 1e-3;
std::optional<double> mosaicity_max_deg = 2.0;
// --- Optional: regularize per-image scale k towards 1 (Kabsch-like) ---
bool regularize_scale_to_one = false;
double scale_regularization_sigma = 0.05;
};
struct MergedReflection {
int h;
int k;
int l;
double I;
double sigma;
double d = 0.0;
};
struct ScaleMergeResult {
std::vector<MergedReflection> merged;
std::vector<double> image_scale_k;
std::vector<double> image_b_factor;
std::vector<int> image_ids;
// One mosaicity value per image (degrees).
std::vector<double> mosaicity_deg;
// Goodness-of-fit squared (reduced chi-squared).
double gof2 = 1.0;
};
ScaleMergeResult ScaleAndMergeReflectionsCeres(const std::vector<Reflection>& observations,
const ScaleMergeOptions& opt = {});