rugnux finds the beam stop and its holder in a projection of 60 images and marks them in the pixel mask as bit 9 (--detect-beam-stop[=N|off], on by default). Reflections behind the stop are attenuated but not flagged, so they integrate low with a plausible sigma and nothing downstream catches them: the signal-box gate requires 100% valid pixels and shadow pixels are valid, the background clip is high-side only, and the |zeta| cut applies only to the space-group search merge. The detection compares each pixel's background against the typical background at the same radius on two channels. An azimuthal one (the ring median) finds the holder arm, which is a minority of its ring; a radial one (the background just outside) finds the disk, which the ring median cannot see because inside a fully blocked ring the median is the shadow itself. Pixels are pooled over a 5x5 box and tested only where the background has actually been counted, so low-background data no longer masks the whole detector. Recorded reflections are carved back out - a beam stop cannot block a reflection that was measured. Bit 9 belongs to the run that found it, not to the dataset: it is cleared when a run starts, so a mask read back from a file that carries one starts clear. The user mask (bit 8) is left alone. Scaling and merging gain a low-resolution limit, default 50 A (--scaling-low-resolution <num>, 0 removes it), applied per observation before scaling so it also protects the per-frame scale fit and the space-group search. 50 A is the value XDS configurations use; rugnux_vs_xds.py now matches both of XDS's resolution limits instead of only the high one, so the lowest shell is the same shell in the two programs. The viewer draws the detected shadow in coral with a "Show beam stop" switch in the side panel, exposes the low-resolution limit in the settings dock, and offers detection in its processing jobs. Adding an image marker meant giving the reader a MIN_REAL_PXL_VALUE, because several places classify a pixel by range rather than by equality and would otherwise read the new marker as a very negative intensity. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
111 lines
3.4 KiB
C++
111 lines
3.4 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <cmath>
|
|
|
|
#include "HKLKey.h"
|
|
#include "gemmi/symmetry.hpp"
|
|
|
|
uint64_t HKLKey::pack() const {
|
|
constexpr int bits = 21;
|
|
constexpr int bias = 1 << (bits - 1); // 1,048,576
|
|
constexpr int max_value = bias - 1;
|
|
constexpr int min_value = -bias;
|
|
constexpr std::uint64_t mask = (1ULL << bits) - 1ULL;
|
|
|
|
if (h < min_value || h > max_value ||
|
|
k < min_value || k > max_value ||
|
|
l < min_value || l > max_value) {
|
|
throw std::out_of_range("HKL index outside packable range");
|
|
}
|
|
|
|
const std::uint64_t hh = static_cast<std::uint64_t>(h + bias) & mask;
|
|
const std::uint64_t kk = static_cast<std::uint64_t>(k + bias) & mask;
|
|
const std::uint64_t ll = static_cast<std::uint64_t>(l + bias) & mask;
|
|
|
|
return (hh << 1) | (kk << (bits + 1)) | (ll << (2 * bits + 1)) | (plus ? 1ULL : 0ULL);
|
|
}
|
|
|
|
HKLKeyGenerator::HKLKeyGenerator(bool merge_friedel, int32_t space_group_number)
|
|
: HKLKeyGenerator(merge_friedel, *gemmi::find_spacegroup_by_number(space_group_number)) {
|
|
}
|
|
|
|
HKLKeyGenerator::HKLKeyGenerator(bool merge_friedel, const gemmi::SpaceGroup &sg)
|
|
: merge_friedel(merge_friedel),
|
|
sg(sg),
|
|
ops(sg.operations()),
|
|
asu(&sg) {
|
|
}
|
|
|
|
HKLKey HKLKeyGenerator::operator()(const MergedReflection &r) const {
|
|
return operator()(r.h, r.k, r.l);
|
|
}
|
|
|
|
HKLKey HKLKeyGenerator::operator()(const Reflection &r) const {
|
|
return operator()(r.h, r.k, r.l);
|
|
}
|
|
|
|
HKLKey HKLKeyGenerator::operator()(int32_t h, int32_t k, int32_t l) const {
|
|
HKLKey key{h, k, l, true};
|
|
|
|
if (sg.number == 1) {
|
|
const HKLKey neg{-h, -k, -l, true};
|
|
if (std::tie(key.h, key.k, key.l) < std::tie(neg.h, neg.k, neg.l)) {
|
|
key.h = -key.h;
|
|
key.k = -key.k;
|
|
key.l = -key.l;
|
|
key.plus = merge_friedel;
|
|
}
|
|
} else {
|
|
const gemmi::Op::Miller in{h, k, l};
|
|
const auto [hkl, sign_plus] = asu.to_asu_sign(in, ops);
|
|
|
|
key.h = hkl[0];
|
|
key.k = hkl[1];
|
|
key.l = hkl[2];
|
|
key.plus = merge_friedel ? true : sign_plus;
|
|
}
|
|
return key;
|
|
}
|
|
|
|
bool HKLKeyGenerator::IsSystematicallyAbsent(int32_t h, int32_t k, int32_t l) const {
|
|
return ops.is_systematically_absent(gemmi::Op::Miller{h, k, l});
|
|
}
|
|
|
|
bool HKLKeyGenerator::IsSystematicallyAbsent(const Reflection &r) const {
|
|
return IsSystematicallyAbsent(r.h, r.k, r.l);
|
|
}
|
|
|
|
bool AcceptReflection(const Reflection &r, std::optional<double> d_min_limit, std::optional<double> d_max_limit) {
|
|
if (!std::isfinite(r.I))
|
|
return false;
|
|
if (!std::isfinite(r.d) || r.d <= 0.0f)
|
|
return false;
|
|
if (d_min_limit && r.d < d_min_limit)
|
|
return false;
|
|
if (d_max_limit && r.d > d_max_limit)
|
|
return false;
|
|
if (!std::isfinite(r.rlp) || r.rlp == 0.0f)
|
|
return false;
|
|
if (!std::isfinite(r.sigma) || r.sigma <= 0.0)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
bool AcceptReflection(const Reflection &r, double d_min_limit, double d_max_limit) {
|
|
if (!std::isfinite(r.I))
|
|
return false;
|
|
if (!std::isfinite(r.d) || r.d <= 0.0f)
|
|
return false;
|
|
if (d_min_limit > 0.0 && r.d < d_min_limit)
|
|
return false;
|
|
if (d_max_limit > 0.0 && r.d > d_max_limit)
|
|
return false;
|
|
if (!std::isfinite(r.rlp) || r.rlp == 0.0f)
|
|
return false;
|
|
if (!std::isfinite(r.sigma) || r.sigma <= 0.0)
|
|
return false;
|
|
return true;
|
|
}
|
|
|