Files
Jungfraujoch/common/IndexingSettings.h
T
leonarski_fandClaude Opus 5 4e8db41785 indexing: refuse a coplanar candidate, and search the plane normal when the shortlist is flat
Three related changes to the FFT candidate path, batteried together because they touch the same
function.

A COPLANAR CANDIDATE REACHED REFINEMENT. ReduceResults filtered triples on lengths and angles only -
the 30-150 degree bound admits any flat combination - and there was no volume test. On one dataset 41
of 5535 candidates had |V|/abc below 0.05, with a clean decade gap to the next, and three of them
reached the optimizer. UnitCell is float, and for a cell that flat the metric determinant is around
1.5e-7, so float32 gets its sign wrong 19% of the time where float64 never does. The guard against a
negative argument to sqrt then CREATES the singularity it was meant to prevent: it puts c in the a-b
plane, the reciprocal volume is 1/0, and the residual is 0 times infinity. Ceres reported a
not-a-number Jacobian and wrote several hundred lines of solver output per failed solve.

VolumeFraction() is |V|/(|a||b||c|), rejected below 0.02 - about 1.1 degrees off flat, ten times below
the flattest real candidate observed and a thousand times above where float loses the sign. It is
enforced at the producer and at the two optimizer entry points. Note the existing sanity checks use
ABSOLUTE volume, which a 320 cubic-angstrom flat cell passes. The same reciprocal-volume division is
now guarded at the two remaining sites that share the pattern.

A SHORTLIST CONFINED TO ONE PLANE cannot close a cell, and the row it is missing is the plane normal.
That is detected from the scatter-matrix eigenvalue ratio - measured, degenerate clouds score 2e-5 to
3.3e-4 against 0.026 or more for every non-degenerate one, a factor of eighty - and one further
transform is spent with the same direction count inside a three-degree cap about the normal, so the
plan and buffers are untouched. More directions cannot substitute: at the exact true direction the
long axis ranks 1422 of 16384 by prominence while the shortlist cut is four times higher. Ranking, not
sampling, is the obstacle. A four-fold denser grid was measured and rejected - it reaches the same
answer to three decimal places and takes a run from 2.5 to 8 GB of device memory.

fft_min_unit_cell_A is reachable as --fft-min-unit-cell and is lowered automatically by -C, mirroring
how the maximum is already raised. The default of 10 is unchanged: a lower floor admits spurious
sub-cells on protein data, and over 73 protein runs the floor was never lowered while the sibling
maximum did fire twice, so the path is live and correctly inert.

Corpus of 93 datasets, both arms, one build: 72 bit-identical on report content and p.hkl checksum, 13
failing identically, and the count of working datasets rises by one. The volume guard fires on 58 of
93 and 47 of those stay bit-identical - it fires constantly and almost never changes an answer, which
is what it should do. Solver chatter falls from 919 lines across three datasets to none. The cap
fires on 4 of 93, none of them in the in-house or private arms.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lc5JG6kJqZoCWaoZ43JGTW
2026-08-29 20:31:20 +02:00

102 lines
5.0 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cstdint>
// Upper bound accepted by IndexingSettings::RefineThreads. Callers deriving a thread count from the
// machine must clamp to it - on a big host -N/2 exceeds it and the setter throws.
constexpr int MAX_REFINE_THREADS = 64;
enum class IndexingAlgorithmEnum {FFBIDX, FFT, FFTW, Auto, None};
// Flex = "let the pipeline decide": try several per-image refinements and keep whichever indexes the
// most spots (CLI -r flex; the legacy -r multi name is still accepted as an alias).
enum class GeomRefinementAlgorithmEnum {None, OrientationOnly, BeamCenter, Flex};
class IndexingSettings {
IndexingAlgorithmEnum algorithm;
int64_t fft_num_vectors = 16*1024;
float fft_max_unit_cell_A = 500.0;
float fft_min_unit_cell_A = 10.0;
float fft_max_angle_deg = 150.0;
float fft_min_angle_deg = 30.0;
float fft_high_resolution_A = 2.0;
float indexing_tolerance = 0.1;
float max_angle_from_ewald_deg = 2.0;
float unit_cell_dist_tolerance_vs_reference = 0.05; // relative
static constexpr float unit_cell_angle_tolerance_deg = 5.0; // degree
public:
// The longest cell the FFT search can be asked to reach, and so the longest it can ever find:
// FFTIndexer sizes its histogram from fft_max_unit_cell_A and the transform's last usable bin IS
// that length. Callers that widen the bound (a given cell, the long-axis rescue) must clamp to
// this rather than let the setter throw - a rescue that recovers an implausible axis must not
// take the whole run down with it.
static constexpr float fft_max_unit_cell_limit_A = 1200.0;
// The other end of the same search: any candidate whose reduced cell has an axis shorter than
// fft_min_unit_cell_A is discarded, and this is the lowest floor the setter accepts. A caller
// lowering the floor to reach a given cell clamps to it rather than let the setter throw.
static constexpr float fft_min_unit_cell_limit_A = 5.0;
private:
int64_t indexing_threads = 4;
// Threads splitting the candidate-cell refinement WITHIN one indexer call. 1 (the default) is the
// right answer whenever indexers already run one per image across all workers; it is raised only
// where few indexer threads exist and cores would otherwise sit idle.
int64_t refine_threads = 1;
int64_t viable_cell_min_spots = 9;
int64_t max_extra_lattices = 2;
bool blocking_behavior = true;
bool index_ice_rings = false;
bool enable_rotation_indexing = false;
float rotation_indexing_min_angular_range_deg = 20.0;
float rotation_indexing_angular_stride_deg = 0.5;
GeomRefinementAlgorithmEnum refinement = GeomRefinementAlgorithmEnum::BeamCenter;
public:
IndexingSettings();
IndexingSettings& ViableCellMinSpots(int64_t input);
IndexingSettings& Algorithm(IndexingAlgorithmEnum input);
IndexingSettings& FFT_MaxUnitCell_A(float input);
IndexingSettings& FFT_MinUnitCell_A(float input);
IndexingSettings& FFT_MaxAngle_deg(float input);
IndexingSettings& FFT_MinAngle_deg(float input);
IndexingSettings& FFT_NumVectors(int64_t input);
IndexingSettings& FFT_HighResolution_A(float input);
IndexingSettings& Tolerance(float input);
IndexingSettings& IndexingThreads(int64_t input);
IndexingSettings& RefineThreads(int64_t input);
IndexingSettings& UnitCellDistTolerance(float input);
IndexingSettings& GeomRefinementAlgorithm(GeomRefinementAlgorithmEnum input);
IndexingSettings& IndexIceRings(bool input);
IndexingSettings& RotationIndexing(bool input);
IndexingSettings& RotationIndexingMinAngularRange_deg(float input);
IndexingSettings& RotationIndexingAngularStride_deg(float input);
IndexingSettings& BlockingBehavior(bool input);
IndexingSettings& MaxExtraLattices(int64_t input);
[[nodiscard]] int64_t GetViableCellMinSpots() const;
[[nodiscard]] IndexingAlgorithmEnum GetAlgorithm() const;
[[nodiscard]] GeomRefinementAlgorithmEnum GetGeomRefinementAlgorithm() const;
[[nodiscard]] float GetFFT_MaxUnitCell_A() const;
[[nodiscard]] float GetFFT_MinUnitCell_A() const;
[[nodiscard]] int64_t GetFFT_NumVectors() const;
[[nodiscard]] float GetFFT_HighResolution_A() const;
[[nodiscard]] float GetTolerance() const;
[[nodiscard]] float GetFFT_MinAngle_deg() const;
[[nodiscard]] float GetFFT_MaxAngle_deg() const;
[[nodiscard]] int64_t GetIndexingThreads() const;
[[nodiscard]] int64_t GetRefineThreads() const;
[[nodiscard]] float GetUnitCellDistTolerance() const;
[[nodiscard]] float GetUnitCellAngleTolerance_deg() const;
[[nodiscard]] bool GetIndexIceRings() const;
[[nodiscard]] bool GetRotationIndexing() const;
[[nodiscard]] float GetRotationIndexingMinAngularRange_deg() const;
[[nodiscard]] float GetRotationIndexingAngularStride_deg() const;
[[nodiscard]] bool GetBlockingBehavior() const;
[[nodiscard]] int64_t GetMaxExtraLattices() const;
};