Files
Jungfraujoch/image_analysis/scale_merge/HKLKey.cpp
T
leonarski_f 680c36c20d
Build Packages / Unit tests (push) Successful in 1h22m15s
Build Packages / build:windows:nocuda (push) Successful in 18m0s
Build Packages / build:windows:cuda (push) Successful in 20m30s
Build Packages / build:viewer-tgz:cpu (push) Successful in 10m32s
Build Packages / build:viewer-tgz:cuda (push) Successful in 11m39s
Build Packages / build:rugnux-tgz (x86_64) (push) Successful in 8m55s
Build Packages / build:rugnux:windows (push) Successful in 11m25s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 20m6s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 16m27s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 20m19s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 15m34s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 20m25s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 19m36s
Build Packages / build:rpm (rocky8) (push) Successful in 17m43s
Build Packages / build:rpm (rocky9) (push) Successful in 13m34s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 21m28s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 18m19s
Build Packages / DIALS test (push) Successful in 12m36s
Build Packages / XDS test (durin plugin) (push) Successful in 6m56s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 6m48s
Build Packages / XDS test (neggia plugin) (push) Successful in 6m7s
Build Packages / Generate python client (push) Successful in 11s
Build Packages / Build documentation (push) Successful in 36s
Build Packages / Create release (push) Skipped
Build Packages / build:rugnux:aarch64 (cross) (push) Successful in 5m11s
v1.0.0-rc.166 (#76)
* `rugnux --mode calibration` writes `<prefix>.json` beside the `.poni`, whose `dataset_settings` member is a `jfjoch_broker` `dataset_settings` body as it stands.
* `rugnux` and `jfjoch_viewer` read PILATUS miniCBF sweeps natively, without conversion.
* Masters written by other facilities open, including Eiger 1.x and third-party NXmx variants.
* `rugnux` measures the beam centre on every run, and indexes with it when the file's value indexes nothing.
* A detector swung out on a 2theta arm is placed where the file says it stands, and the calibration can hold the tilt fixed.
* `rugnux` writes the unmerged MTZ by default, and a P1 merge beside it, so a wrong space group can be re-merged without reprocessing.
* Significant improvements to symmetry handling in `rugnux`: the lattice, the point group, the setting and the systematic absences.
* The `rugnux` report gives the resolution the CC1/2 fit reached, beside the range the reflections were written to.
* The `rugnux` report gives the twinning statistics measured before the space group was decided, beside the ones measured after.
* The `rugnux` report gives the strong-direction diffraction limit, and warns when CC1/2 is not monotone with resolution.
* `rugnux` ranks screw axes on the evidence their absences carry, rather than on how many control reflections a candidate happens to have.
* Twinning is no longer reported when the L-test contradicts it.
* The `rugnux` report gives the detector tilt, the measured tilt and the direct beam beside the beam centre, and a post-refined beam centre is judged against the run's own measurement rather than the file's.
* `--no-refine-tilt` holds the detector tilt at the value in the file, instead of zeroing it, when the calibration starts from the spots.
* The `jfjoch_viewer` grid scan view draws the cells in the proportion of the scan steps, so the map has the shape of the scanned area.

Reviewed-on: #76
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-09-02 21:17:31 +02:00

107 lines
3.3 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, 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;
}