48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "LoadFCalcFromMtz.h"
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <gemmi/mtz.hpp>
|
|
|
|
#include "../common/Reflection.h"
|
|
|
|
std::vector<MergedReflection> LoadFCalcFromMtz(const std::string& path) {
|
|
gemmi::Mtz mtz;
|
|
mtz.read_file_gz(path, true);
|
|
|
|
const gemmi::Mtz::Column* fc = mtz.column_with_label("F-model", nullptr, 'F');
|
|
if (fc == nullptr)
|
|
throw std::runtime_error("MTZ does not contain F-model column");
|
|
|
|
std::vector<MergedReflection> result;
|
|
result.reserve(static_cast<std::size_t>(mtz.nreflections));
|
|
|
|
const std::size_t stride = mtz.columns.size();
|
|
|
|
for (int i = 0; i < mtz.nreflections; ++i) {
|
|
const std::size_t row = static_cast<std::size_t>(i) * stride;
|
|
const float f = (*fc)[static_cast<std::size_t>(i)];
|
|
|
|
if (std::isnan(f))
|
|
continue;
|
|
|
|
MergedReflection r;
|
|
r.h = static_cast<int32_t>(mtz.data[row + 0]);
|
|
r.k = static_cast<int32_t>(mtz.data[row + 1]);
|
|
r.l = static_cast<int32_t>(mtz.data[row + 2]);
|
|
r.I = f * f;
|
|
r.sigma = NAN;
|
|
r.d = 0.0f;
|
|
|
|
result.emplace_back(r);
|
|
}
|
|
|
|
return result;
|
|
}
|