Build Packages / Build documentation (push) Successful in 46s
Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m25s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m46s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m25s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m41s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m46s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m37s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 24m31s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m9s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 20m47s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 26m21s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 27m36s
Build Packages / Generate python client (push) Successful in 31s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 29m27s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 31m46s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 25m22s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 30m36s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 31m49s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 23m57s
Build Packages / Unit tests (push) Successful in 1h47m52s
Build Packages / Validation Battery (push) Successful in 44m55s
* Rugnux: Rotation processing recovers most of the speed lost since 1.0.0-rc.180; live processing in jfjoch_broker finishes sooner. * Rugnux: More reliable rotation processing and indexing, including small molecules and supercells. * Rugnux: More robust serial data and model refinement; molecular replacement handles multi-chain models. * jfjoch_broker (experimental): Live serial processing keeps the detector geometry fixed for the whole run. * jfjoch_broker: Pixel sum without an FPGA, a mask bit for inactive pixels, and several stability fixes. * jfjoch_broker: Rotation indexing and quick integration moved to rugnux live mode; their API settings are deprecated and ignored. * jfjoch_broker, Rugnux: Azimuthal integration can use logarithmic (log10) Q bins or a given number of bins, set from the API, the web interface and the Rugnux command line. * jfjoch_viewer: Build and display fixes; the README is rewritten. Reviewed-on: #95 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
128 lines
4.6 KiB
C++
128 lines
4.6 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);
|
|
}
|
|
|
|
HKLKey HKLKey::unpack(uint64_t packed) {
|
|
constexpr int bits = 21;
|
|
constexpr int bias = 1 << (bits - 1);
|
|
constexpr std::uint64_t mask = (1ULL << bits) - 1ULL;
|
|
return HKLKey{static_cast<int>((packed >> 1) & mask) - bias,
|
|
static_cast<int>((packed >> (bits + 1)) & mask) - bias,
|
|
static_cast<int>((packed >> (2 * bits + 1)) & mask) - bias,
|
|
(packed & 1ULL) != 0};
|
|
}
|
|
|
|
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) || r.overloaded) // a saturated spot is not a measurement
|
|
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;
|
|
const float corr = r.prescaling_corr * r.qe_corr * r.flight_corr;
|
|
if (!std::isfinite(corr) || corr == 0.0f)
|
|
return false;
|
|
if (!std::isfinite(r.sigma) || r.sigma <= 0.0)
|
|
return false;
|
|
// A background variance below zero is no measurement either. It is what a background region reading
|
|
// below zero leaves - pixels that are not counting photons, such as a module whose pedestal is off on
|
|
// that frame - and the sigma of such a reflection falls to its floor of a photon while its net intensity
|
|
// reaches thousands: an observation a hundred times more trusted than any real one, which takes its
|
|
// reflection over in every merge and drags every frame that sees that reflection towards a scale of 0.
|
|
if (r.var_bkg < 0.0f)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
bool AcceptReflection(const Reflection &r, double d_min_limit, double d_max_limit) {
|
|
if (!std::isfinite(r.I) || r.overloaded) // a saturated spot is not a measurement
|
|
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;
|
|
const float corr = r.prescaling_corr * r.qe_corr * r.flight_corr;
|
|
if (!std::isfinite(corr) || corr == 0.0f)
|
|
return false;
|
|
if (!std::isfinite(r.sigma) || r.sigma <= 0.0)
|
|
return false;
|
|
if (r.var_bkg < 0.0f) // see above
|
|
return false;
|
|
return true;
|
|
}
|
|
|