Build Packages / Build documentation (push) Successful in 48s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 15m47s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 23m19s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 18m47s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m27s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 26m59s
Build Packages / Unit tests (push) Successful in 1h50m25s
Build Packages / Validation Battery (push) Successful in 46m38s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 32m52s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 32m32s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 28m34s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 29m19s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 30m11s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 33m58s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 31m26s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 34m4s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 32m17s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Create release (push) Successful in 9s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 31m50s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 19m38s
* jfjoch_broker (experimental): Live Rugnux covers serial collections from DECTRIS detectors; a rotation collection too large for the image buffer falls back to standard per-image processing with a warning, and a stream that ends without its end message finishes the collection instead of hanging it. * jfjoch_broker (experimental): Live Rugnux settings to build the solvent during refinement and to process a rotation collection as stills, a Clear action for the last result, a `_report.txt` for live rotation runs, R-free reported for the refined model, and ice-ring detection on by default for rotation as in the command line. * jfjoch_broker (experimental): More complete and reproducible live serial merges, analysed for twinning, pseudo-translation and anisotropy, with merging statistics by resolution shell in the live status. * jfjoch_writer: Live results with large models are written reliably; update jfjoch_writer together with jfjoch_broker. * Rugnux: Several masters can be processed together with `--force-still`, including grid scans; more robust and faster merging of several sweeps; improved twinning, pseudo-translation, anisotropy, anomalous-signal and space-group decisions. * Rugnux: Molecular replacement places the copies of a multi-copy solution together; the pseudo-translation warning quotes the Patterson peak and is not raised once a model is placed; the report advises on extending the rotation or reorienting the crystal where the coverage would gain from it. * Web frontend: Light and dark modes, a phone layout, a hideable page list, a redesigned Rugnux live page with step-through of the Fo-Fc peaks in the structure view. * jfjoch_viewer: A broker URL given on the command line follows the running collection. Reviewed-on: #97 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
159 lines
7.6 KiB
C++
159 lines
7.6 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <array>
|
|
#include <cmath>
|
|
|
|
#include "SweepCoverage.h"
|
|
#include "../../common/JFJochMath.h"
|
|
|
|
namespace {
|
|
// The proper rotations of the point group, identity included, as gemmi row-convention matrices
|
|
// on Miller indices (h' = h W). Friedel is added at the orbit, not here.
|
|
std::vector<std::array<std::array<double, 3>, 3>> ProperRotations(const gemmi::SpaceGroup &sg) {
|
|
std::vector<std::array<std::array<double, 3>, 3>> rot;
|
|
for (const auto &op : sg.operations().derive_symmorphic().sym_ops) {
|
|
const auto &w = op.rot;
|
|
const double det =
|
|
static_cast<double>(w[0][0]) * (w[1][1] * w[2][2] - w[1][2] * w[2][1])
|
|
- static_cast<double>(w[0][1]) * (w[1][0] * w[2][2] - w[1][2] * w[2][0])
|
|
+ static_cast<double>(w[0][2]) * (w[1][0] * w[2][1] - w[1][1] * w[2][0]);
|
|
if (det <= 0)
|
|
continue;
|
|
std::array<std::array<double, 3>, 3> m{};
|
|
for (int i = 0; i < 3; i++)
|
|
for (int j = 0; j < 3; j++)
|
|
m[i][j] = static_cast<double>(w[i][j]) / gemmi::Op::DEN;
|
|
rot.push_back(m);
|
|
}
|
|
return rot;
|
|
}
|
|
|
|
double Mod360(double a) {
|
|
a = std::fmod(a, 360.0);
|
|
return a < 0 ? a + 360.0 : a;
|
|
}
|
|
}
|
|
|
|
std::vector<double> EwaldCrossingAngles_deg(const Coord &s, const Coord &u, const Coord &s0) {
|
|
// The crystal turned by -phi: s(phi) = s_par + s_perp cos phi - (u x s_perp) sin phi, in reflecting
|
|
// position when 2 s(phi).s0 + |s|^2 = 0, i.e. A cos phi - B sin phi = C = rho cos(phi + delta).
|
|
const Coord s_par = u * (u * s), s_perp = s - s_par;
|
|
const double A = 2.0 * (s_perp * s0), B = 2.0 * ((u % s_perp) * s0);
|
|
const double C = -static_cast<double>(s * s) - 2.0 * (s_par * s0);
|
|
const double rho = std::sqrt(A * A + B * B);
|
|
if (rho < 1e-12 || std::fabs(C) > rho)
|
|
return {};
|
|
const double delta = std::atan2(B, A) * 180.0 / PI;
|
|
const double half = std::acos(C / rho) * 180.0 / PI;
|
|
return {Mod360(-delta + half), Mod360(-delta - half)};
|
|
}
|
|
|
|
std::optional<double> SweepCoverageForecast::DegreesTo(double target_fraction) const {
|
|
for (size_t k = 0; k < fraction_at.size(); k++)
|
|
if (fraction_at[k] >= target_fraction)
|
|
return static_cast<double>(k);
|
|
return {};
|
|
}
|
|
|
|
std::optional<SweepCoverageForecast> ForecastSweepCoverage(const gemmi::SpaceGroup &sg,
|
|
const CrystalLattice &lattice,
|
|
const GoniometerAxis &gonio,
|
|
const Coord &s0,
|
|
double d_min_A,
|
|
double start_deg, double end_deg) {
|
|
const Coord spindle = gonio.GetAxis();
|
|
if (spindle.Length() < 1e-9f || d_min_A <= 0 || !(end_deg > start_deg) || s0.Length() < 1e-9f)
|
|
return {};
|
|
const Coord u = spindle.Normalize();
|
|
const double sweep = end_deg - start_deg;
|
|
|
|
const auto rot = ProperRotations(sg);
|
|
const Coord a = lattice.Vec0(), b = lattice.Vec1(), c = lattice.Vec2();
|
|
const Coord as = lattice.Astar(), bs = lattice.Bstar(), cs = lattice.Cstar();
|
|
|
|
// Uniform over reciprocal space to d_min: a spiral of directions, radii at the volume quantiles.
|
|
constexpr int N_DIRECTIONS = 1536, N_RADII = 8;
|
|
const double golden_angle = PI * (3.0 - std::sqrt(5.0));
|
|
const double q_max = 1.0 / d_min_A;
|
|
|
|
std::vector<int64_t> reached(361, 0); // reached[k]: measured by [start, end + k]
|
|
int64_t measurable = 0, total = 0;
|
|
for (int i = 0; i < N_DIRECTIONS; i++) {
|
|
const double z = 1.0 - 2.0 * (static_cast<double>(i) + 0.5) / N_DIRECTIONS;
|
|
const double r = std::sqrt(std::max(0.0, 1.0 - z * z));
|
|
const double phi = golden_angle * i;
|
|
const Coord p(static_cast<float>(r * std::cos(phi)), static_cast<float>(r * std::sin(phi)),
|
|
static_cast<float>(z));
|
|
const double h0 = a * p, h1 = b * p, h2 = c * p;
|
|
for (int k = 0; k < N_RADII; k++) {
|
|
const double q = q_max * std::cbrt((static_cast<double>(k) + 0.5) / N_RADII);
|
|
++total;
|
|
bool measured = false, crosses = false;
|
|
double extension = 360.0;
|
|
for (const auto &m : rot) {
|
|
const double g0 = h0 * m[0][0] + h1 * m[1][0] + h2 * m[2][0];
|
|
const double g1 = h0 * m[0][1] + h1 * m[1][1] + h2 * m[2][1];
|
|
const double g2 = h0 * m[0][2] + h1 * m[1][2] + h2 * m[2][2];
|
|
const Coord dir = as * static_cast<float>(g0) + bs * static_cast<float>(g1)
|
|
+ cs * static_cast<float>(g2);
|
|
for (const float sign : {1.0f, -1.0f}) { // Friedel
|
|
const Coord s = dir.Normalize() * static_cast<float>(sign * q);
|
|
for (const double root : EwaldCrossingAngles_deg(s, u, s0)) {
|
|
crosses = true;
|
|
const double from_start = Mod360(root - start_deg);
|
|
if (from_start <= sweep)
|
|
measured = true;
|
|
else
|
|
extension = std::min(extension, Mod360(root - end_deg));
|
|
}
|
|
}
|
|
}
|
|
if (!crosses)
|
|
continue;
|
|
++measurable;
|
|
const int first = measured ? 0 : static_cast<int>(std::ceil(extension));
|
|
for (int e = std::min(first, 360); e <= 360; e++)
|
|
++reached[e];
|
|
}
|
|
}
|
|
if (total == 0)
|
|
return {};
|
|
SweepCoverageForecast out;
|
|
out.fraction_at.resize(361);
|
|
for (int e = 0; e <= 360; e++)
|
|
out.fraction_at[e] = static_cast<double>(reached[e]) / static_cast<double>(total);
|
|
out.measured_fraction = out.fraction_at[0];
|
|
out.asymptote_fraction = static_cast<double>(measurable) / static_cast<double>(total);
|
|
return out;
|
|
}
|
|
|
|
double SecondSweepTilt_deg(double wavelength_A, double d_min_A, double max_lost_fraction) {
|
|
// A reciprocal point at angle a from a spindle is blind to a sweep about it past q = 2 sin(a) / lambda.
|
|
// Count, uniformly over reciprocal space to d_min, the points blind to the spindle u and to u tilted
|
|
// by `tilt` alike; by the cones' symmetry about their axes only the angle between the two matters.
|
|
constexpr int N_DIRECTIONS = 4096, N_RADII = 16;
|
|
const double golden_angle = PI * (3.0 - std::sqrt(5.0));
|
|
for (int tilt = 1; tilt <= 90; tilt++) {
|
|
const double t = tilt * PI / 180.0;
|
|
int64_t lost = 0;
|
|
for (int i = 0; i < N_DIRECTIONS; i++) {
|
|
const double z = 1.0 - 2.0 * (static_cast<double>(i) + 0.5) / N_DIRECTIONS;
|
|
const double r = std::sqrt(std::max(0.0, 1.0 - z * z));
|
|
const double x = r * std::cos(golden_angle * i);
|
|
const double sin_a1 = r; // from u = (0, 0, 1)
|
|
const double c2 = x * std::sin(t) + z * std::cos(t); // from u tilted towards x
|
|
const double sin_a2 = std::sqrt(std::max(0.0, 1.0 - c2 * c2));
|
|
for (int k = 0; k < N_RADII; k++) {
|
|
const double q = std::cbrt((static_cast<double>(k) + 0.5) / N_RADII) / d_min_A;
|
|
const double half = q * wavelength_A / 2.0;
|
|
if (sin_a1 < half && sin_a2 < half)
|
|
++lost;
|
|
}
|
|
}
|
|
if (static_cast<double>(lost) / (static_cast<double>(N_DIRECTIONS) * N_RADII) <= max_lost_fraction)
|
|
return tilt;
|
|
}
|
|
return 90.0;
|
|
}
|