Add a dataset-wide isotropic Wilson B-factor estimate, the analogue of XDS's "WILSON LINE ... B=" which we did not export. CalcGlobalWilsonB fits ln<I> vs 1/d^2 over the merged reflections (B = -2*slope), skipping the low-resolution non-linear region (d > 4 A) and shells past the signal limit (<I/sigma> < 1) so the estimate is insensitive to how far the merged data were carried. It is diagnostic only - not fed back into scaling - and is written to the mmCIF (_reflns.B_iso_Wilson_estimate), the printed merge statistics, and the log. Also harden the per-image Wilson B (CalcWilsonBFactor): accept the fit only when it is well-correlated and physically plausible (0 < B < 200 A^2), else leave b_factor unset. A bad frame (an indexing glitch, too few reflections) otherwise produced a wildly steep Wilson line and a B of several hundred A^2 that polluted the per-image plot; NaN is preferable to garbage. Diagnostic-only: the merged intensities and every merge statistic are byte-identical (verified baseline vs modified on the rotation battery). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29 lines
1.3 KiB
C++
29 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <limits>
|
|
#include <vector>
|
|
|
|
#include "../../common/JFJochMessages.h"
|
|
#include "../../common/Reflection.h"
|
|
|
|
void CalcISigma(DataMessage &msg);
|
|
void CalcWilsonBFactor(DataMessage &msg, bool replace_b = true);
|
|
|
|
void CalcISigma(DataMessage &msg, const std::vector<Reflection> &reflections);
|
|
void CalcWilsonBFactor(DataMessage &msg, const std::vector<Reflection> &reflections, bool replace_b = true);
|
|
|
|
// Dataset-wide isotropic Wilson B-factor estimate from a log-linear fit of the shell-averaged merged
|
|
// intensity against 1/d^2 (B = -2*slope). Robust because it averages over the whole dataset - the
|
|
// per-image CalcWilsonBFactor above is a per-frame estimate and much noisier. Diagnostic only (like
|
|
// XDS's "WILSON LINE ... B="), not used in scaling. Returns b = NaN when it cannot be determined.
|
|
struct GlobalWilsonB {
|
|
double b = std::numeric_limits<double>::quiet_NaN(); // Wilson B-factor estimate (A^2)
|
|
double correlation = std::numeric_limits<double>::quiet_NaN(); // |correlation| of the log-linear fit
|
|
int n_shells = 0; // resolution shells actually used
|
|
};
|
|
GlobalWilsonB CalcGlobalWilsonB(const std::vector<MergedReflection> &merged);
|
|
|