Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 28m46s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 32m5s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 39m44s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m30s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 31m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m29s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m51s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m7s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m6s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m44s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 33m22s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 34m6s
Build Packages / Unit tests (push) Successful in 1h2m47s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 35m59s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 34m8s
Build Packages / Validation Battery (push) Successful in 38m31s
* Rugnux: Refinement several times faster, one protocol on the CPU and the GPU, parts of it on the Apple GPU; its random draws are the same on every platform. * Rugnux: Refinement follows common practice: the free set decides only the restraint weights and the displacement model (isotropic, TLS or anisotropic, by Hamilton's test), everything else is decided on the working set; lower R-free for placed and predicted models. * Rugnux: Restraint dictionaries via `--restraints` (or among the inputs) and more built-in ligands; a model whose space group is a subgroup of the data's is refined in its own group; reflections plus a model select `--mode refine` on their own. * Rugnux: `-C` fixes the crystal system on the axes as typed; `-S` alone fixes the space group only, the cell is still found and reduced; a space group or cell stored in the input file is ignored, with a line in the log. * Rugnux: More reliable multi-sweep merging; `--mode scale` merges several stills runs as one; `_plot.txt` and the report name each input; a second crystal form is reported for stills given a cell. * jfjoch_broker (experimental): Live Rugnux on FPGA detectors (JUNGFRAU) takes the same path as a DECTRIS stream, rotation and serial alike, model step included, with analysis threads per GPU; frames waiting for the analysis can be viewed; no host stage drops a frame - a source faster than the analysis is held at the card. * jfjoch_broker: Summation of more than 256 frames per image is split between the card and the host (`summation_mode` is then `hybrid`), and live Rugnux runs on such collections; pedestal runs take a receiver of their own. * jfjoch_broker (experimental): `stills_downsample` analyses 1 of every N serial images (chosen by a hash; the first 2000 all; the others written without analysis; reset to 1 by `/initialize`); `max_spot_count` left out means 250 for per-image indexing and up to 1000 for live stills; the live status gives the merge before the model work, the fitted resolution and the anomalous peak height of each unexplained blob. * jfjoch_broker: Without a `pcie` entry the broker runs on a mock of the card instead of the HLS simulation; its spot, ROI and azimuthal results are zero then. * Web frontend: Redesigned Rugnux live page; Vite 8, TypeScript 6, Mol* 5.13 and dependency security updates. * Tools: `jfjoch_fpga_stills_test` measures live stills on the cards with a stored dataset; `jfjoch_fpga_test` loses the HLS-simulation option. * Other: FFTW no longer fetched or linked (the CPU FFT indexer keeps the name `FFTW`); PCIe driver now GPL-2.0-or-later and third-party notices complete; several crash fixes. Reviewed-on: #98 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
107 lines
5.1 KiB
C++
107 lines
5.1 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <cmath>
|
|
#include <random>
|
|
|
|
#include <spdlog/fmt/fmt.h>
|
|
#include <gemmi/blob.hpp>
|
|
#include <gemmi/pdb.hpp>
|
|
|
|
#include "../image_analysis/structure_refinement/DensityBlobs.h"
|
|
|
|
namespace {
|
|
|
|
// A P 32 2 1 map in sigma units with one Gaussian peak at `f` and its symmetry mates, the mates equal to within
|
|
// 0.1 sigma as in a map from a Fourier transform (the live cytochrome C difference map: up to 0.06 sigma)
|
|
gemmi::Grid<float> PeakMap(const gemmi::UnitCell &cell, const gemmi::SpaceGroup *sg, const gemmi::Fractional &f,
|
|
std::mt19937 &rng) {
|
|
gemmi::Grid<float> grid;
|
|
grid.unit_cell = cell;
|
|
grid.spacegroup = sg;
|
|
grid.set_size(72, 72, 84);
|
|
size_t idx = 0;
|
|
for (int w = 0; w < grid.nw; w++)
|
|
for (int v = 0; v < grid.nv; v++)
|
|
for (int u = 0; u < grid.nu; u++, idx++) {
|
|
gemmi::Fractional d(double(u) / grid.nu - f.x, double(v) / grid.nv - f.y, double(w) / grid.nw - f.z);
|
|
d = gemmi::Fractional(d.x - std::round(d.x), d.y - std::round(d.y), d.z - std::round(d.z));
|
|
const double r2 = cell.orthogonalize_difference(d).length_sq();
|
|
grid.data[idx] = static_cast<float>(10.0 * std::exp(-r2 / 2.0));
|
|
}
|
|
grid.symmetrize_max();
|
|
std::normal_distribution<float> noise(0.0f, 0.1f);
|
|
for (float &v : grid.data)
|
|
v += noise(rng);
|
|
return grid;
|
|
}
|
|
|
|
}
|
|
|
|
TEST_CASE("FindDensityBlobs_SymmetryMatesOnce", "[DensityBlobs]") {
|
|
const gemmi::UnitCell cell(60, 60, 70, 90, 90, 120);
|
|
const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name("P 32 2 1");
|
|
REQUIRE(sg != nullptr);
|
|
gemmi::BlobCriteria criteria;
|
|
criteria.cutoff = 3.0;
|
|
criteria.min_volume = 0.0;
|
|
criteria.min_score = 0.0;
|
|
criteria.min_peak = 4.0;
|
|
|
|
// Peaks over the whole cell, the asymmetric unit's faces among them: gemmi's flood fill finds some of those
|
|
// that cross a face twice - an edge point above the cutoff whose mate is just below it seeds the mate's copy.
|
|
std::mt19937 rng(1);
|
|
int found_twice = 0;
|
|
for (int i = 0; i < 8; i++)
|
|
for (int j = 0; j < 8; j++)
|
|
for (int k = 0; k < 8; k++) {
|
|
const gemmi::Fractional f(i / 8.0 + 0.01, j / 8.0 + 0.02, k / 8.0 + 0.005);
|
|
const gemmi::Grid<float> map = PeakMap(cell, sg, f, rng);
|
|
const gemmi::Position p = cell.orthogonalize(f);
|
|
const std::string pdb = fmt::format(
|
|
"CRYST1 60.000 60.000 70.000 90.00 90.00 120.00 P 32 2 1\n"
|
|
"HETATM 1 O HOH A 1 {:8.3f}{:8.3f}{:8.3f} 1.00 20.00 O\nEND\n",
|
|
p.x + 2.5, p.y, p.z);
|
|
const gemmi::Structure st = gemmi::read_pdb_string(pdb, "one water");
|
|
if (gemmi::find_blobs_by_flood_fill(map, criteria).size() > 1)
|
|
found_twice++;
|
|
const std::vector<DensityBlob> blobs = FindDensityBlobs(map, 1.0, st, 2.0);
|
|
INFO(fmt::format("peak at {:.3f} {:.3f} {:.3f}", f.x, f.y, f.z));
|
|
CHECK(blobs.size() == 1);
|
|
}
|
|
CHECK(found_twice > 0);
|
|
}
|
|
|
|
// The anomalous reading of a blob is the anomalous map's peak near the difference map's: an anomalous scatterer
|
|
// 0.7 A from the difference peak (the two maps on grids of their own, or the scatterer not the highest point of the
|
|
// blob) is read at its own height, not at the lower value its tail has at the difference peak. No map: no reading.
|
|
TEST_CASE("FindDensityBlobs_AnomalousPeakNearTheBlob", "[DensityBlobs]") {
|
|
const gemmi::UnitCell cell(60, 60, 70, 90, 90, 120);
|
|
const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name("P 32 2 1");
|
|
REQUIRE(sg != nullptr);
|
|
std::mt19937 rng(2);
|
|
const gemmi::Fractional f(0.31, 0.22, 0.13);
|
|
const gemmi::Position p = cell.orthogonalize(f);
|
|
const gemmi::Fractional g = cell.fractionalize(p + gemmi::Position(0.7, 0, 0));
|
|
const gemmi::Grid<float> difference = PeakMap(cell, sg, f, rng);
|
|
const gemmi::Grid<float> anomalous = PeakMap(cell, sg, g, rng);
|
|
const std::string pdb = fmt::format(
|
|
"CRYST1 60.000 60.000 70.000 90.00 90.00 120.00 P 32 2 1\n"
|
|
"HETATM 1 O HOH A 1 {:8.3f}{:8.3f}{:8.3f} 1.00 20.00 O\nEND\n",
|
|
p.x + 3.0, p.y, p.z);
|
|
const gemmi::Structure st = gemmi::read_pdb_string(pdb, "one water");
|
|
|
|
const std::vector<DensityBlob> without = FindDensityBlobs(difference, 1.0, st, 2.0);
|
|
REQUIRE(without.size() == 1);
|
|
CHECK(std::isnan(without[0].anomalous_sigma));
|
|
|
|
const std::vector<DensityBlob> with = FindDensityBlobs(difference, 1.0, st, 2.0, &anomalous, 1.0);
|
|
REQUIRE(with.size() == 1);
|
|
CHECK(anomalous.interpolate_value(p) < 8.5); // the Gaussian's tail at the difference peak: 10 exp(-0.245)
|
|
CHECK(with[0].anomalous_sigma > 9.0); // its own height, 10, sampled on the grid
|
|
CHECK(with[0].anomalous_sigma < 10.5);
|
|
CHECK(with[0].kind == DensityBlob::Kind::Ion);
|
|
}
|