A miniCBF header states three things about how the instrument is put together that the reader was assuming instead: which laboratory direction the image's columns run along, which its rows run along, and which the spindle turns about. Some beamlines append a CBF template block holding the full imgCIF axis table, which says all three outright. Two instruments in the corpus are not what was assumed, in two different ways. One mounts its detector a quarter turn round, so the image's columns run vertically. Another turns its spindle about the VERTICAL, with the image mounted the usual way; its table says so, and its "# Oscillation_axis" line says so a second way, by naming the image direction the spindle runs along rather than a vector. Either error leaves the spindle 90 degrees from the image. That is not a sign, so the run's axis-sign rescue cannot reach it, and no refinement recovers it: all three affected sweeps indexed nothing usable. So the table is read. The element axes give the image orientation, matched against the eight discrete mountings exactly as the NXmx module directions already are - the match itself moves to DetectorOrientation, so both readers share one definition rather than two copies. The goniometer axis with no parent gives the spindle DIRECTION; its sign stays the rescue's business, which is the part a convention can legitimately differ on. The detector axis with no parent gives the 2theta arm, replacing the assumption that the arm shares the spindle's axis - the one header stating both states them with the same vector, so this changes no answer, only what it rests on. imgCIF's frame differs from the internal one by a half turn about x, a rotation and not a mirror, as writer/HDF5NXmx.cpp already records from the other side. Where a header carries no table, a "+SLOW" on the Oscillation_axis line still says the spindle runs along the image's slow direction. That is the only thing one of the three affected sets says about it. The axis NAME on that line stays unusable - the header that carries both says "X.CW" where its own table says Y - but the direction token is not: where both are present they agree, which is what makes reading it evidence rather than a guess. Also: naming a frame with no directory at all now finds its sweep. parent_path() of a bare filename is empty and iterating an empty path finds nothing, so running from inside the data directory reported that no images were found. Measured, with nothing on the command line. The vertical-spindle protein set goes from no usable lattice to 100% indexed, P 6(3) 2 2 with a cell 0.43% from deposited, 87846 reflections at 86.3% completeness and CC(1/2) 0.995. Its companion from the same detector, which has no table and only the +SLOW token, goes from a spurious monoclinic cell at 2.3% completeness and I/sigma 0.21 to the right orthorhombic lattice, 97.7% indexed, 59.7% complete, CC(1/2) 0.996. The quarter-turned set's three sweeps, at three arm positions, now all index without the hand-passed quarter turn they needed and agree on one cell to 0.03 A. Six miniCBF sets that state no table and no +SLOW - including one whose Oscillation_axis line names an axis in a third dialect - are byte-identical in .hkl, .mtz, .cif and the image statistics, as are two NXmx sets, which is the shared orientation matcher moving nothing on that path either. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T3yNBXk4wKdMZy1ak2NY7f
64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "DetectorOrientation.h"
|
|
#include "JFJochException.h"
|
|
|
|
DetectorOrientation::DetectorOrientation(bool mirror_y, int64_t quarter_turns) {
|
|
MirrorY(mirror_y);
|
|
QuarterTurns(quarter_turns);
|
|
}
|
|
|
|
DetectorOrientation &DetectorOrientation::MirrorY(bool input) {
|
|
mirror_y = input;
|
|
return *this;
|
|
}
|
|
|
|
DetectorOrientation &DetectorOrientation::QuarterTurns(int64_t input) {
|
|
if ((input < 0) || (input > 3))
|
|
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
|
"Quarter turns must be 0, 1, 2 or 3");
|
|
quarter_turns = input;
|
|
return *this;
|
|
}
|
|
|
|
bool DetectorOrientation::IsMirrorY() const {
|
|
return mirror_y;
|
|
}
|
|
|
|
int64_t DetectorOrientation::GetQuarterTurns() const {
|
|
return quarter_turns;
|
|
}
|
|
|
|
bool DetectorOrientation::IsIdentity() const {
|
|
return !mirror_y && (quarter_turns == 0);
|
|
}
|
|
|
|
RotMatrix DetectorOrientation::Matrix() const {
|
|
// Columns of Rz(k*90 deg), in the internal frame (x = column, y = row downward, z = beam). y
|
|
// points down, so a positive right-handed turn about +z takes +x to +y - clockwise on screen.
|
|
const float c[4] = {1, 0, -1, 0};
|
|
const float s[4] = {0, 1, 0, -1};
|
|
const Coord rz_x = {c[quarter_turns], s[quarter_turns], 0};
|
|
const Coord rz_y = {-s[quarter_turns], c[quarter_turns], 0};
|
|
|
|
// Rz * diag(1,-1,1): the mirror negates the second column.
|
|
return {rz_x, mirror_y ? -rz_y : rz_y, {0, 0, 1}};
|
|
}
|
|
|
|
std::optional<DetectorOrientation> DetectorOrientation::Match(const Coord &fast, const Coord &slow) {
|
|
for (int64_t quarter_turns = 0; quarter_turns < 4; quarter_turns++) {
|
|
for (const bool mirror_y: {false, true}) {
|
|
const DetectorOrientation orientation(mirror_y, quarter_turns);
|
|
const RotMatrix m = orientation.Matrix();
|
|
if (((m.Column(0) - fast).Length() < 1e-3f) && ((m.Column(1) - slow).Length() < 1e-3f))
|
|
return orientation;
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
|
|
bool DetectorOrientation::operator==(const DetectorOrientation &other) const {
|
|
return (mirror_y == other.mirror_y) && (quarter_turns == other.quarter_turns);
|
|
}
|