Files
leonarski_fandFilip Leonarski 19b135186d
Build Packages / Create release (push) Successful in 7s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m56s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m10s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m51s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m56s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 20m59s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 21m25s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 21m17s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 14m14s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m59s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 25m48s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 15m52s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m33s
Build Packages / Generate python client (push) Successful in 29s
Build Packages / Build documentation (push) Successful in 1m19s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m49s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 25m31s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 25m24s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 26m5s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 22m19s
Build Packages / Unit tests (push) Failing after 2h28m24s
Build Packages / Validation Battery (push) Successful in 40m33s
v1.0.0-rc.175 (#85)
* Rugnux: Processes a collection live while jfjoch_broker writes it (`rugnux <master.h5> <broker URL>`).
* Rugnux: Processing starts on the first images and confirms its choices once all are in, so analysis can begin during collection.
* Rugnux: Faster processing, especially on servers with several GPUs and CPU sockets and on computers without a GPU (`--no-gpu`, macOS).
* Rugnux: Uses much less GPU memory, so large data sets stay on the GPU of smaller cards, and a data set too large for the card is processed on the CPU instead.
* Rugnux: On macOS, Bragg integration runs on the Apple GPU.
* Rugnux: Better handling of twinning and pseudo-symmetry, with the twin hypothesis written as `<prefix>_twin_<SG>.mtz`, and a wrong `--model` no longer confirms the data or decides the hand.
* Rugnux: `--model` accepts predicted (AlphaFold) models and falls back to molecular replacement when the model is not placed as a rigid body (experimental `--mr` forces it), settling space group, hand and twinning and writing a different answer as `<prefix>_mr.mtz`.
* Rugnux: Molecular replacement is faster and settles the space group in more cases with several copies in the asymmetric unit.
* Rugnux: Deposition-ready mmCIF, a richer report, and numbered steps on the terminal with the full log in `<prefix>_log.txt`; `_P1.mtz`, `--estimate-beam-center` and `--beam-center-search` are removed.
* Rugnux: The beam-stop shadow is found correctly on tilted detectors.
* Rugnux: Stills files that record a stationary goniometer axis get the default stills geometry refinement.
* jfjoch_viewer: "Analyze dataset" uses the same defaults as a bare `rugnux <file>`, and shows the results of processed CBF, marCCD and SMV sweeps.
* jfjoch_viewer: The Files panel refreshes on F5 and every few seconds, and the plot type and other selections stay put during live collection.
* jfjoch_writer: Memory stays bounded and old data files are closed efficiently on long runs, any failure ends the run in an error state the broker is told about, and the master file appears only after its data files; the ZeroMQ pusher logs when a stalled writer makes it drop images.
* Fixes: The TCP image pusher no longer blocks the broker's receiver, GPU out-of-memory failures stop with a clear message, and the XDS plugin masks module and chip edges.

---------

Co-authored-by: Filip Leonarski <jungfrau@filips-mac-mini.home>
Reviewed-on: #85
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-16 15:34:43 +02:00

92 lines
4.0 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstddef>
#include <vector>
#include <cuda_runtime.h>
#include "../indexing/CUDAMemHelpers.h"
// The bulk-solvent mask of PutMaskOnGrid() (ModelGrid.h), i.e. gemmi's
// SolventMasker(AtomicRadiiSet::Refmac).put_mask_on_grid(), on the GPU. gemmi masks the atoms and then
// symmetrizes the grid with the minimum; the operators are isometries, so that is the same as masking
// every symmetry image of every atom, which is what is done here - no orbits, no symmetrize. The island
// removal is gemmi's (26-connected, periodic, the same size limit) as a union-find, and the shrink is
// gemmi's set_margin_around() as two passes over the grid.
//
// Every write of the masking is the same idempotent store and the union-find partition is unique, so
// the mask is bit-identical from run to run. It can differ from gemmi's at points lying exactly at an
// atom's radius, where float and double distances round differently.
struct ModelMaskGrid {
int nu = 0, nv = 0, nw = 0; // index = u + nu * (v + nv * w)
double orth[9]; // gemmi UnitCell::orth.mat, row-major (Cartesian = orth * fractional)
double volume = 0; // UnitCell::volume, A^3
};
// One atom to mask: fractional x, y, z wrapped into [0,1) and the mask radius in A. Double, because
// float fractional coordinates are off by up to 1e-5 A in a 200 A cell, enough to move points that lie at
// the radius; the distances themselves are float. (CUDA's double4 is deprecated from CUDA 13 and its
// replacement does not exist before, hence a struct of our own.)
struct ModelMaskAtom {
double x, y, z, radius;
};
// A fractional operator x' = rot * x + tran: every symmetry operator combined with every centring
// vector, identity included.
struct ModelMaskOp {
double rot[9]; // row-major
double tran[3];
};
class ModelMaskGPU {
public:
// Enough for Fm-3m, 48 operators times 4 centring vectors.
static constexpr int MAX_OPS = 192;
// Grid offsets within gemmi's r_shrink = 0.8 A: 26 at a 0.4 A spacing, 728 at 0.2 A.
static constexpr int MAX_STENCIL = 1024;
static size_t DeviceBytes(size_t max_points);
ModelMaskGPU(cudaStream_t stream, size_t max_points);
// Per zone. Throws if the grid has more than max_points points, if there are more than MAX_OPS
// operators, or if the shrink's stencil is over MAX_STENCIL offsets.
void SetGrid(const ModelMaskGrid &grid, const std::vector<ModelMaskOp> &ops);
// d_atoms: hydrogens and unoccupied atoms already left out. d_mask: the whole grid, 1 = solvent, 0 = macromolecule. Queued on the stream.
// The masking, then RemoveIslands(), then Shrink().
void Compute(const ModelMaskAtom *d_atoms, int n_atoms, float *d_mask);
// The island removal alone, on a mask of 0 and 1 already on the grid. Compute() runs it before Shrink().
void RemoveIslands(float *d_mask);
// The shrink alone, on a mask whose islands are already removed. A no-op on a grid too coarse for
// any grid offset to lie within r_shrink.
void Shrink(float *d_mask);
// What the masking kernel needs of the grid.
struct Geometry {
int nu, nv, nw;
float orth_n[9]; // orth * diag(1/nu, 1/nv, 1/nw): Cartesian of a grid-step offset
double spacing[3]; // gemmi Grid::spacing, the interplanar distance of the grid planes
};
private:
void SetShrinkStencil(const ModelMaskGrid &grid);
cudaStream_t stream;
size_t max_points;
Geometry geom{};
size_t npoints = 0;
int n_ops = 0;
int island_limit = 0;
int n_near = 0, n_stencil = 0; // the shrink's offsets: the first n_near are the near ones
CudaDevicePtr<ModelMaskOp> ops_d;
CudaDevicePtr<int> label; // union-find parent, then the component sizes
CudaDevicePtr<int> root; // each solvent point's component, -1 elsewhere
CudaDevicePtr<int3> stencil_d;
};