Files
Jungfraujoch/tests/IceRingVerdictTest.cpp
leonarski_f aecd48b9d3
Build Packages / Build documentation (push) Successful in 48s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 15m47s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 23m19s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 18m47s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m27s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 26m59s
Build Packages / Unit tests (push) Successful in 1h50m25s
Build Packages / Validation Battery (push) Successful in 46m38s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 32m52s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 32m32s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 28m34s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 29m19s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 30m11s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 33m58s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 31m26s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 34m4s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 32m17s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Create release (push) Successful in 9s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 31m50s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 19m38s
v1.0.0-rc.186 (#97)
* jfjoch_broker (experimental): Live Rugnux covers serial collections from DECTRIS detectors; a rotation collection too large for the image buffer falls back to standard per-image processing with a warning, and a stream that ends without its end message finishes the collection instead of hanging it.
* jfjoch_broker (experimental): Live Rugnux settings to build the solvent during refinement and to process a rotation collection as stills, a Clear action for the last result, a `_report.txt` for live rotation runs, R-free reported for the refined model, and ice-ring detection on by default for rotation as in the command line.
* jfjoch_broker (experimental): More complete and reproducible live serial merges, analysed for twinning, pseudo-translation and anisotropy, with merging statistics by resolution shell in the live status.
* jfjoch_writer: Live results with large models are written reliably; update jfjoch_writer together with jfjoch_broker.
* Rugnux: Several masters can be processed together with `--force-still`, including grid scans; more robust and faster merging of several sweeps; improved twinning, pseudo-translation, anisotropy, anomalous-signal and space-group decisions.
* Rugnux: Molecular replacement places the copies of a multi-copy solution together; the pseudo-translation warning quotes the Patterson peak and is not raised once a model is placed; the report advises on extending the rotation or reorienting the crystal where the coverage would gain from it.
* Web frontend: Light and dark modes, a phone layout, a hideable page list, a redesigned Rugnux live page with step-through of the Fo-Fc peaks in the structure view.
* jfjoch_viewer: A broker URL given on the command line follows the running collection.

Reviewed-on: #97
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-13 20:13:43 +01:00

100 lines
4.4 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include <catch2/catch_all.hpp>
#include <random>
#include "../common/Definitions.h"
#include "../common/JFJochMath.h"
#include "../image_analysis/scale_merge/IceRingVerdict.h"
namespace {
// A Wilson crystal (B = 20 A^2) to 2 A, acentric intensities with 10% plus constant noise; the
// reflections within the flag width of an ice ring are flagged, and `ring` modifies the ones on
// the 2.667 A ring: dq is their offset from it in q.
template <class F>
std::vector<MergedReflection> Crystal(F ring, double d_min = 2.0, double noise = 1.0) {
std::mt19937 rng(1234);
std::exponential_distribution<double> wilson(1.0);
std::normal_distribution<double> gauss(0.0, 1.0);
std::uniform_real_distribution<double> s2(1.0 / (6.0 * 6.0), 1.0 / (d_min * d_min));
std::vector<MergedReflection> out;
for (int i = 0; i < 20000; ++i) {
MergedReflection r;
r.d = static_cast<float>(1.0 / std::sqrt(s2(rng)));
const double I_mean = 1000.0 * std::exp(-0.5 * 20.0 / (r.d * r.d));
const double I_true = I_mean * wilson(rng);
r.sigma = static_cast<float>(noise * std::sqrt(0.01 * I_true * I_true + 25.0));
r.I = static_cast<float>(I_true + r.sigma * gauss(rng));
r.on_ice_ring = IsOnIceRing(r.d, 0.03f);
const double dq = 2.0 * PI / r.d - 2.0 * PI / 2.667;
if (std::fabs(dq) < 0.03)
ring(r, dq, I_mean, rng);
out.push_back(r);
}
return out;
}
IceRingAction ActionOf(const IceRingDecision &d, float ring_d, int zone) {
for (const auto &z : d.zones)
if (z.ring_d == ring_d && z.zone == zone)
return z.action;
return IceRingAction::Merge;
}
}
TEST_CASE("IceRingVerdict_untouched_ring_is_merged") {
const auto merged = Crystal([](MergedReflection &, double, double, std::mt19937 &) {});
const auto d = DecideIceRings(merged);
REQUIRE(!d.zones.empty());
for (const auto &z : d.zones)
CHECK(z.action == IceRingAction::Merge);
for (double f : d.weight_factor)
CHECK(f == 1.0);
}
TEST_CASE("IceRingVerdict_biased_core_is_rejected") {
// The ring adds its own intensity on the core, and takes it out of the flanks' background.
const auto merged = Crystal([](MergedReflection &r, double dq, double I_mean, std::mt19937 &) {
r.I += static_cast<float>(std::fabs(dq) < ICE_VERDICT_CORE_Q ? 2.0 * I_mean : -0.5 * I_mean);
});
const auto d = DecideIceRings(merged);
CHECK(ActionOf(d, 2.667f, 0) == IceRingAction::Reject);
for (int zone : {-2, -1, 1, 2})
CHECK(ActionOf(d, 2.667f, zone) == IceRingAction::Reject);
CHECK(ActionOf(d, 2.249f, 0) == IceRingAction::Merge);
size_t rejected = 0;
for (double f : d.weight_factor)
rejected += f == 0.0;
CHECK(rejected > 0);
}
TEST_CASE("IceRingVerdict_noisy_unbiased_ring_is_down_weighted") {
// Zero-mean extra scatter of the size of the mean intensity: no bias, only noise.
const auto merged = Crystal([](MergedReflection &r, double, double I_mean, std::mt19937 &rng) {
std::normal_distribution<double> extra(0.0, 2.0 * I_mean);
r.I += static_cast<float>(extra(rng));
});
const auto d = DecideIceRings(merged);
CHECK(ActionOf(d, 2.667f, 0) == IceRingAction::DownWeight);
for (size_t i = 0; i < merged.size(); ++i)
if (std::fabs(2.0 * PI / merged[i].d - 2.0 * PI / 2.667) < ICE_VERDICT_CORE_Q) {
CHECK(d.weight_factor[i] < 1.0);
CHECK(d.weight_factor[i] > 0.0);
}
}
TEST_CASE("IceRingVerdict_rings_near_the_resolution_limit_get_a_verdict") {
// A weak 3.1 A dataset, every shell at I/sigma below 1: the 3.44 A ring sits just inside the limit
// and the 3.66 A one close to it. Each ring with flagged reflections must be judged, not merged
// silently for want of a Wilson fit.
const auto merged = Crystal([](MergedReflection &, double, double, std::mt19937 &) {}, 3.1, 4.0);
const auto d = DecideIceRings(merged);
for (float ring_d : {3.895f, 3.661f, 3.438f}) {
bool judged = false;
for (const auto &z : d.zones)
judged |= z.ring_d == ring_d && z.zone == 0 && z.n_neighbours >= ICE_VERDICT_MIN_NEIGHBOURS;
CHECK(judged);
}
}