// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include "HKLKey.h" #include "gemmi/symmetry.hpp" HKLKey CanonicalHKL(int32_t h, int32_t k, int32_t l, bool merge_friedel, const std::optional &in_sg) { HKLKey key{h, k, l, true}; if (!in_sg.has_value()) { if (!merge_friedel) { 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 = false; } } } else { gemmi::SpaceGroup sg = in_sg.value(); const auto ops = sg.operations(); const gemmi::ReciprocalAsu asu(&sg); 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; } HKLKey CanonicalHKL(const Reflection &r, bool merge_friedel, const std::optional &sg) { return CanonicalHKL(r.h, r.k, r.l, merge_friedel, sg); } HKLKey CanonicalHKL(const MergedReflection &r, bool merge_friedel, const std::optional &sg) { return CanonicalHKL(r.h, r.k, r.l, merge_friedel, sg); } bool AcceptReflection(const Reflection &r, double d_min_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 (!std::isfinite(r.rlp) || r.rlp == 0.0f) return false; return true; }