Files
Jungfraujoch/viewer/widgets/PowderCalibrationWidget.h
leonarski_fandClaude Opus 5 2456bbe7f6 viewer: calibrate a sample cell against its own space group, as the CLI does
The powder-calibration widget built its ring list with CalculateXtalRings(cell),
which assumes a primitive lattice. The overload taking a space group exists
precisely because the fit pairs the innermost OBSERVED ring with the innermost
LISTED one, so a list opening with a reflection the symmetry forbids scales the
whole calibration by the ratio between that ring and the first real one.

rugnux_cli was moved to the new overload when it landed; the viewer was not. So
on any centred sample cell the viewer's calibration was scaled wrong - the exact
failure the overload was added to prevent.

The widget already takes the cell from the loaded dataset; it now takes the group
with it and uses both. Where the dataset has no group the old call stands, which
is the same P-lattice assumption as before and no worse.

Found by a whole-branch review, which saw the two call sites side by side where a
per-commit read of either could not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 17:38:40 +02:00

53 lines
2.2 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <QWidget>
#include <gemmi/symmetry.hpp>
#include <QCheckBox>
#include <QComboBox>
#include <QVector>
#include "../../common/UnitCell.h"
#include "../../reader/JFJochReaderImage.h"
#include "../../image_analysis/geom_refinement/PowderCalibration.h" // CalibrationMethod
// What a whole-dataset calibration run is set to. The analysis library takes the calibrant as a ring
// list rather than a name (ice has no cell to enumerate rings from), so the name is resolved here.
struct CalibrationSelection {
QString name;
std::vector<float> ring_q; // q = 2*pi/d [1/A], ascending
CalibrationMethod method = CalibrationMethod::Rings;
bool refine_tilt = true; // false pins rot1/rot2 where they are (a calibration meant for XDS)
};
// Detector geometry from a powder standard: the calibrant, and how its rings are measured. The two
// buttons fit the image currently on screen; "Analyze dataset" reads Selection() and fits the whole
// dataset the same way rugnux --mode calibration does.
class PowderCalibrationWidget : public QWidget {
Q_OBJECT
std::optional<UnitCell> sample_cell;
// Taken with the cell, and used with it: the ring list a user-supplied cell produces has to carry
// the group's absences, or the fit pairs the innermost OBSERVED ring with a forbidden one.
std::optional<gemmi::SpaceGroup> sample_sg;
QComboBox* calibrantCombo{nullptr}; // stores current calibrant selection
QComboBox* methodCombo{nullptr}; // rings / spots, for the whole-dataset run
QCheckBox* refineTiltCheck{nullptr};// fit the detector tilt, or hold it where it is
std::vector<float> GetCalibrantRings() const;
void updateCalibrantList();
signals:
void ringsFromCalibration(QVector<float> v);
void findBeamCenter(QVector<float> ring_q, bool guess, bool refine_tilt);
public:
PowderCalibrationWidget(QWidget* parent);
CalibrationSelection Selection() const;
public slots:
void loadImage(std::shared_ptr<const JFJochReaderImage> image);
private slots:
void findBeamCenterClicked();
void optimizeBeamCenterClicked();
};