Distance check: a distance that holds its own but still asks onward is not the fixed point
A pre-pass whose own paired test held its distance ended the walk as the fixed point (bb24b36eb), even where the move it asked for still pointed the way every distance before it had. Along the direction the data do not determine - the distance and the cell scale trading against each other - the ask stays the same size from wherever it is integrated and only its significance wanders: a crystal asking for 0.8-1.0 mm more at four distances had its fourth held by its own test, the run adopted it, and the two-pass walk ran on 4 % past the header (cell 4 % off, ISa 15 -> 5). A held distance now ends the walk as the fixed point only where its ask has changed sign; otherwise it is one more distance tried, and the bracket test decides as before (there: the header stands). The lattice-identity test of the pre-passes takes out the scale the distance puts on the cell (the ratio of the two distances) before it asks for whole-number indices: a pre-pass at another distance integrates the same crystal on a cell scaled with the distance, and 0.1 of an index is 3 % of a cell on a combination of index 3. The known ratio, not the ratio of the volumes, so that a supercell twice the cell along all three axes is not taken for the same lattice. A rejected pre-pass is logged with its distance from whole indices, with the scale taken out and without. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQpv3w9JdZswRqKUW2H
This commit is contained in:
1 parent
1824c721fb
commit
0c72dc2ebf
1 file changed
+29
-16
+29
-16
@@ -138,24 +138,31 @@ namespace {
|
||||
// are whole-number combinations of the other's, to the 0.1 ScaleMergeAndSymmetry reindexes to. The
|
||||
// cell edges alone do not say it: a pre-pass at a beam 15 px off was measured settling on a cell of
|
||||
// edges within 2 % of the right one's, in another orientation, with 8 of 60 validation frames.
|
||||
bool IndexesSameLattice(const ProcessResult &a, const ProcessResult &b) {
|
||||
// Returned is the largest distance from a whole number. A pre-pass at another distance indexes the
|
||||
// same crystal on a cell scaled with the distance, so that scale - `scale`, a's cell over b's: the
|
||||
// ratio of the distances they were integrated at - is taken out first. Not the ratio of their
|
||||
// volumes: a supercell twice the cell along all three axes would then read as the same lattice.
|
||||
double LatticeMismatch(const ProcessResult &a, const ProcessResult &b, double scale) {
|
||||
if (!a.end_message.rotation_lattice || !b.end_message.rotation_lattice)
|
||||
return std::numeric_limits<double>::infinity();
|
||||
const auto primitive = [](const ProcessResult &r) {
|
||||
const auto &type = r.end_message.rotation_lattice_type;
|
||||
return r.end_message.rotation_lattice->ToPrimitive(type ? type->centering : 'P');
|
||||
};
|
||||
const auto integral = [](const CrystalLattice &x, const CrystalLattice &y) {
|
||||
const auto mismatch = [](const CrystalLattice &x, const CrystalLattice &y, double scale) {
|
||||
const Coord v[3] = {x.Vec0(), x.Vec1(), x.Vec2()};
|
||||
const Coord rs[3] = {y.Astar(), y.Bstar(), y.Cstar()};
|
||||
double worst = 0.0;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
if (!(std::fabs(v[i] * rs[j] - std::round(v[i] * rs[j])) < 0.1))
|
||||
return false;
|
||||
return true;
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
const double n = v[i] * rs[j] / scale;
|
||||
worst = std::max(worst, std::fabs(n - std::round(n)));
|
||||
}
|
||||
return worst;
|
||||
};
|
||||
if (!a.end_message.rotation_lattice || !b.end_message.rotation_lattice)
|
||||
return false;
|
||||
const CrystalLattice pa = primitive(a), pb = primitive(b);
|
||||
return integral(pa, pb) && integral(pb, pa);
|
||||
const double m = std::max(mismatch(pa, pb, scale), mismatch(pb, pa, 1.0 / scale));
|
||||
return std::isfinite(m) ? m : std::numeric_limits<double>::infinity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -893,6 +900,11 @@ std::optional<std::array<float, 5>> Rugnux::FixedPointDistance(RugnuxObserver *o
|
||||
// changes sign. The first is the fixed point found and realised in one pass: on most crystals the
|
||||
// data integrated at the free fit's distance ask for that distance again, and the passes that walked
|
||||
// past it to bracket it only confirmed the sign change and realised the same residual again. A
|
||||
// distance that holds its own while the move it asks for still points on, the way every distance
|
||||
// before it asked, is not that: along the direction the data do not determine the ask stays the same
|
||||
// size from wherever it is integrated, and only its significance wanders (measured: four distances
|
||||
// each asking for 0.8-1.0 mm more, the fourth held by its own test). It is one more distance tried,
|
||||
// and the walk goes on to the bracket test below. A
|
||||
// pre-pass that did not index pass 1's lattice is not used, and ends the search: its ask and its
|
||||
// residual are another lattice's, and no residual of it can be compared with pass 1's.
|
||||
std::vector<std::pair<double, double>> points{{d0, held.distance_free_mm}};
|
||||
@@ -902,7 +914,8 @@ std::optional<std::array<float, 5>> Rugnux::FixedPointDistance(RugnuxObserver *o
|
||||
const double d = d0 + k * move;
|
||||
const ProcessResult r = prepass_at(d);
|
||||
const double a = asked(r);
|
||||
const bool same_lattice = IndexesSameLattice(pass1, r);
|
||||
const double mismatch = LatticeMismatch(pass1, r, d0 / d);
|
||||
const bool same_lattice = mismatch < 0.1;
|
||||
text += fmt::format(", {:.2f} -> {:.2f}{}", d, a, same_lattice ? "" : " (another lattice)");
|
||||
if (!same_lattice) {
|
||||
const auto cell = [](const ProcessResult &x) {
|
||||
@@ -912,18 +925,18 @@ std::optional<std::array<float, 5>> Rugnux::FixedPointDistance(RugnuxObserver *o
|
||||
return fmt::format("{:.3f} {:.3f} {:.3f} {:.2f} {:.2f} {:.2f}", c.a, c.b, c.c, c.alpha, c.beta, c.gamma);
|
||||
};
|
||||
logger.Info("Distance check: the pre-pass at {:.3f} mm indexed another lattice than pass 1's - not used "
|
||||
"(primitive {} against pass 1's {})", d, cell(r), cell(pass1));
|
||||
"(primitive {} against pass 1's {}, indices {:.3f} from whole, {:.3f} before the cell scale "
|
||||
"is taken out)", d, cell(r), cell(pass1), mismatch, LatticeMismatch(pass1, r, 1.0));
|
||||
}
|
||||
if (!std::isfinite(a) || !same_lattice)
|
||||
break;
|
||||
realised.push_back({d, r.post_refine});
|
||||
points.emplace_back(d, a);
|
||||
if (r.post_refine->rocking_holds_distance) {
|
||||
fixed = d;
|
||||
if ((a - d) * move <= 0.0) {
|
||||
if (r.post_refine->rocking_holds_distance)
|
||||
fixed = d;
|
||||
break;
|
||||
}
|
||||
if ((a - d) * move <= 0.0)
|
||||
break;
|
||||
}
|
||||
if (cancelled_)
|
||||
return std::nullopt;
|
||||
@@ -958,7 +971,7 @@ std::optional<std::array<float, 5>> Rugnux::FixedPointDistance(RugnuxObserver *o
|
||||
std::optional<Realised> star;
|
||||
if (tried != realised.end()) {
|
||||
star = *tried;
|
||||
} else if (const ProcessResult r = prepass_at(d_star); IndexesSameLattice(pass1, r)) {
|
||||
} else if (const ProcessResult r = prepass_at(d_star); LatticeMismatch(pass1, r, d0 / d_star) < 0.1) {
|
||||
star = Realised{d_star, r.post_refine};
|
||||
} else {
|
||||
logger.Info("Distance check: the pre-pass at {:.3f} mm indexed another lattice than pass 1's - not used",
|
||||
|
||||
Reference in new issue
Block a user