The mask's shrink (0.8 A, Refmac radii) reaches no grid point on a grid whose step is not below it and is skipped, so the macromolecule keeps the whole 1.0 A probe. Model validation masked on the density's grid (d_min / 3), so every run merged to d_min above ~2.25 A lost its shrink; the refinement's capped grid did the same in cells above 2^26 points at 0.4 A once the cap passed 0.8 A. SolventMaskGrid (ModelGrid.h) now sizes the mask's grid for both: the step asked for, but never coarser than MASK_SPACING_SHRINK = 0.75 A nor than the density's grid (which it then is, as before). Validation asks for d_min / 3, so it keeps the density's grid up to 2.25 A and gets one of its own beyond; the refinement asks for d_min / 3 or 0.4 A or the cap's step as before. ModelStructureFactorsGPU masks on that grid with its own cuFFT plan where it is not the density's; GPU and CPU masks stay gemmi's to the radius-edge points, as before. Below the shrink radius the R-factors do not depend on the step (R-free the same at 0.78 / 0.70 / 0.60 / 0.40 A on a 2.1 A cell, 0.95 / 0.85 A 0.015 worse). Open arm, battery --only, before (f149f0a02) -> after, validation R-free (shell-scaled R_model): 4nwv (merged 2.94 A) 0.297 -> 0.281 (0.294 -> 0.278) 5lzl (2.88 A) 0.232 -> 0.210 (0.223 -> 0.200) 6oel (2.84 A) 0.259 -> 0.232 (0.249 -> 0.223) 8r5r (2.80 A) 0.294 -> 0.269 (0.265 -> 0.245) 6i3j (2.33 A) R_model 0.1924 -> 0.1916 5jvn (2.24 A), 7l6j, 5reo, 6cee: identical; space groups unchanged everywhere. Refinement in those runs: 4nwv (refinement mask 0.97 -> 0.75 A) as given 0.3073 -> 0.2865, placement 0.2994 -> 0.2780, refined 0.3061 -> 0.2800; 6oel (0.81 -> 0.75 A) 0.2711 -> 0.2725; others identical. 4nwv: refinement engine 3.55 -> 6.09 GB, validation structure factors 1.30 -> 3.26 GB and the null's 0.80 -> 3.25 GB (fewer rigid-body / scale engines side by side, all within the 13.29 GB budget); wall 121 -> 134 s (refinement +10 s, validation +0.8 s). 4ybb: unchanged fromf149f0a02. Tests: SolventMaskGrid_ShrinkActsAtLowResolution (new); ModelStructureFactorsGPU_MatchesCPU now against the CPU mask on SolventMaskGrid, which at 3.5 A exercises the GPU's own mask grid; [ModelValidation] (51 cases), Refinement*, ModelMaskGPU_* pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQqN9qRD57vnShzTC37
67 lines
3.4 KiB
C++
67 lines
3.4 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
// The device half of ModelStructureFactorsGPU (ModelStructureFactorsGPU.h). The host half works out with
|
|
// gemmi - which stays out of nvcc - everything that depends on the cell, the group and the resolution, and
|
|
// per evaluation the atoms' densities and positions; this half grids, transforms and composes. CUDA builds
|
|
// only.
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "ModelDensityGPU.h"
|
|
#include "ModelMaskGPU.h"
|
|
|
|
// Everything an engine needs that does not depend on the model's coordinates.
|
|
struct ModelStructureFactorsGPUSetup {
|
|
ModelDensityGrid grid; // the structure-factor grid, u fastest
|
|
ModelDensityGrid mask_grid; // the bulk-solvent mask's (SolventMaskGrid, ModelGrid.h): `grid`, or finer
|
|
double volume = 0;
|
|
// The group's operators as gemmi holds them: rot (row-major) and tran, in units of 1 / den.
|
|
std::vector<std::array<int, 12>> sym_ops;
|
|
int den = 24;
|
|
std::vector<ModelMaskOp> mask_ops; // every operator with every centring vector
|
|
std::vector<std::array<int, 3>> rows; // the reflections computed, in the order they come back
|
|
std::vector<double> row_scale; // n_cen * prepare_asu_data()'s unblur, per row
|
|
size_t max_atoms = 0, max_pairs = 0;
|
|
// The largest map MapFromFPhi() will be given: points of the real grid, and of its half-l transform.
|
|
size_t map_points = 0, map_complex_points = 0;
|
|
};
|
|
|
|
struct ModelStructureFactorsGPUEngineImpl;
|
|
|
|
class ModelStructureFactorsGPUEngine {
|
|
public:
|
|
// Every call names its device and leaves the calling thread's current device as it found it.
|
|
|
|
// The device's total memory.
|
|
static size_t TotalMemory(int device);
|
|
// The cuFFT work area the structure factors' and the mask's r2c, and a map of (nu, nv, nw)'s c2r, take on `device`.
|
|
static size_t FFTWorkBytes(int device, const ModelStructureFactorsGPUSetup &setup, int map_nu, int map_nv,
|
|
int map_nw);
|
|
// The bytes an engine for `setup` reserves on the device, given its cuFFT work area.
|
|
static size_t DeviceBytes(const ModelStructureFactorsGPUSetup &setup, size_t fft_work_bytes);
|
|
|
|
ModelStructureFactorsGPUEngine(int device, const ModelStructureFactorsGPUSetup &setup, size_t fft_work_bytes);
|
|
~ModelStructureFactorsGPUEngine();
|
|
|
|
// F_calc and F_mask at the rows for one set of atoms: each atom's density, its grid position
|
|
// (fractional times the grid size, wrapped into [0, n); the 4th number is not read) and the atoms of
|
|
// the bulk-solvent mask. Both come back as (re, im) per row.
|
|
void Compute(const std::vector<ModelDensityAtom> &atoms, const std::vector<std::array<float, 4>> &pos,
|
|
const std::vector<ModelMaskAtom> &mask_atoms, std::vector<std::array<float, 2>> &fcalc,
|
|
std::vector<std::array<float, 2>> &fmask);
|
|
|
|
// The real-space map rho(x) = 1/V sum F exp(-2 pi i h.x) of a half-l coefficient grid in gemmi's ZYX
|
|
// order - h slowest, l fastest and halved: nu * nv * (nw / 2 + 1) complex numbers, (re, im)
|
|
// interleaved, NaN read as zero - into `map`, nu * nv * nw floats with x fastest.
|
|
void Map(int nu, int nv, int nw, double volume, const float *coefficients, float *map);
|
|
|
|
private:
|
|
std::unique_ptr<ModelStructureFactorsGPUEngineImpl> impl_;
|
|
};
|