Merge rc187-ms-refsweep
This commit is contained in:
commit
6a053df2dd
3 files changed
+69
-23
No files matched your search
@@ -388,29 +388,55 @@ JointSweepRelation RelateJointSweeps(const std::vector<JointMemberSweep> &sweeps
|
||||
out.sweeps.resize(sweeps.size());
|
||||
if (sweeps.empty())
|
||||
return out;
|
||||
// The best sweep on its own: of the sweeps whose error model resolved an ISa, the one reaching the
|
||||
// finest resolution, ties broken by the higher ISa (a sweep that merged nothing comes last). Sweeps of
|
||||
// one crystal mostly stop at the same detector edge, their d_min apart in the third decimal by which
|
||||
// reflections happen to be measured there: within 1% of the finest they reach the same resolution.
|
||||
// Every sweep put on the axes of every other (ChooseReferenceSetting): on[k][j] puts sweep k on sweep j's.
|
||||
Logger logger("Rugnux");
|
||||
TimingMark axes_mark(logger, "joint sweeps: axes");
|
||||
const size_t n = sweeps.size();
|
||||
std::vector<std::vector<ReferenceSettingChoice>> on(n, std::vector<ReferenceSettingChoice>(n));
|
||||
std::vector<std::future<void>> rows;
|
||||
for (size_t k = 0; k < n; ++k)
|
||||
rows.push_back(std::async(std::launch::async, [&sweeps, &on, n, k] {
|
||||
for (size_t j = 0; j < n; ++j)
|
||||
if (j != k && !sweeps[k].merged.empty() && !sweeps[j].merged.empty())
|
||||
on[k][j] = ChooseReferenceSetting(sweeps[k].merged, sweeps[k].cell, sweeps[k].space_group,
|
||||
sweeps[j].merged, sweeps[j].cell, sweeps[j].space_group);
|
||||
}));
|
||||
for (auto &row : rows)
|
||||
row.get();
|
||||
|
||||
// The reference (RelateJointSweeps in the header): of the sweeps with a resolved ISa, those that the most
|
||||
// others correlate with on their axes; of these the finest, within 1%, then the higher ISa.
|
||||
std::vector<int> partners(n, 0);
|
||||
for (size_t k = 0; k < n; ++k)
|
||||
for (size_t j = 0; j < n; ++j)
|
||||
if (on[k][j].cc >= MIN_REFERENCE_CC) // false on NaN
|
||||
partners[j]++;
|
||||
for (size_t k = 0; k < n; ++k)
|
||||
logger.Info("Sweep {}: {} of the other sweeps can be put on its axes", k + 1, partners[k]);
|
||||
const auto accuracy_known = [&](size_t k) { return sweeps[k].isa > 0.0; }; // false on NaN
|
||||
const auto d_min = [&](size_t k) { return std::isfinite(sweeps[k].d_min) ? sweeps[k].d_min : INFINITY; };
|
||||
const auto isa = [&](size_t k) { return std::isfinite(sweeps[k].isa) ? sweeps[k].isa : 0.0; };
|
||||
const bool any_known = std::any_of(sweeps.begin(), sweeps.end(), [](const JointMemberSweep &s) { return s.isa > 0.0; });
|
||||
double finest = INFINITY;
|
||||
for (size_t k = 0; k < sweeps.size(); ++k)
|
||||
std::vector<size_t> candidates;
|
||||
for (size_t k = 0; k < n; ++k)
|
||||
if (accuracy_known(k) == any_known)
|
||||
finest = std::min(finest, d_min(k));
|
||||
candidates.push_back(k);
|
||||
const int most = partners[*std::max_element(candidates.begin(), candidates.end(),
|
||||
[&](size_t a, size_t b) { return partners[a] < partners[b]; })];
|
||||
std::erase_if(candidates, [&](size_t k) { return partners[k] < most; });
|
||||
double finest = INFINITY;
|
||||
for (const size_t k : candidates)
|
||||
finest = std::min(finest, d_min(k));
|
||||
const auto reaches_finest = [&](size_t k) { return d_min(k) <= 1.01 * finest; };
|
||||
const auto better = [&](size_t k, size_t than) {
|
||||
if (accuracy_known(k) != accuracy_known(than))
|
||||
return accuracy_known(k);
|
||||
if (reaches_finest(k) != reaches_finest(than))
|
||||
return reaches_finest(k);
|
||||
if (!reaches_finest(k) && d_min(k) != d_min(than))
|
||||
return d_min(k) < d_min(than);
|
||||
return (std::isfinite(sweeps[k].isa) ? sweeps[k].isa : 0.0) > (std::isfinite(sweeps[than].isa) ? sweeps[than].isa : 0.0);
|
||||
return isa(k) > isa(than);
|
||||
};
|
||||
out.reference = 0;
|
||||
for (size_t k = 1; k < sweeps.size(); ++k)
|
||||
out.reference = static_cast<int>(candidates.front());
|
||||
for (const size_t k : candidates)
|
||||
if (better(k, out.reference))
|
||||
out.reference = static_cast<int>(k);
|
||||
const JointMemberSweep &ref = sweeps[out.reference];
|
||||
@@ -418,11 +444,9 @@ JointSweepRelation RelateJointSweeps(const std::vector<JointMemberSweep> &sweeps
|
||||
out.sweeps[out.reference].cc = out.sweeps[out.reference].identity_cc = 1.0;
|
||||
out.sweeps[out.reference].decision = "reference";
|
||||
|
||||
// First the axes: each sweep on the reference's (ChooseReferenceSetting), then the twin laws of the
|
||||
// lattice settled over all the pairs at once (ConsensusTwinLaws).
|
||||
Logger logger("Rugnux");
|
||||
TimingMark axes_mark(logger, "joint sweeps: axes");
|
||||
for (size_t k = 0; k < sweeps.size(); ++k) {
|
||||
// First the axes: each sweep on the reference's, then the twin laws of the lattice settled over all
|
||||
// the pairs at once (ConsensusTwinLaws).
|
||||
for (size_t k = 0; k < n; ++k) {
|
||||
if (static_cast<int>(k) == out.reference)
|
||||
continue;
|
||||
JointSweepRelation::Sweep &s = out.sweeps[k];
|
||||
@@ -431,9 +455,7 @@ JointSweepRelation RelateJointSweeps(const std::vector<JointMemberSweep> &sweeps
|
||||
s.why_left_out = "it merged nothing";
|
||||
continue;
|
||||
}
|
||||
const ReferenceSettingChoice choice = ChooseReferenceSetting(sweeps[k].merged, sweeps[k].cell,
|
||||
sweeps[k].space_group, ref.merged, ref.cell,
|
||||
ref.space_group);
|
||||
const ReferenceSettingChoice &choice = on[k][out.reference];
|
||||
s.cob = choice.cob;
|
||||
s.cc = choice.cc;
|
||||
s.identity_cc = choice.identity_cc;
|
||||
|
||||
@@ -84,14 +84,21 @@ std::vector<HeldOutGain> MeasureHeldOutGains(const std::vector<const std::vector
|
||||
const gemmi::SpaceGroup &space_group);
|
||||
|
||||
// How each sweep is put on the axes of the reference and whether it joins it. The reference is the
|
||||
// best-diffracting sweep whose intensities have a measured accuracy: of the sweeps whose error model
|
||||
// resolved an ISa, the one whose own merge reaches the finest resolution (ties: the higher ISa) - the
|
||||
// best-diffracting sweep whose intensities have a measured accuracy and that the other sweeps agree with:
|
||||
// of the sweeps whose error model resolved an ISa, those on whose axes the most other sweeps can be put
|
||||
// (their merged intensities correlate with its at MIN_REFERENCE_CC, as a sweep's must with the reference's
|
||||
// to join), and of these the one whose own merge reaches the finest resolution (within 1% of it the sweeps
|
||||
// tie - sweeps of one crystal stop at the same detector edge - and the higher ISa decides) - the
|
||||
// least damaged one, as KAMO (Yamashita et al. (2018) Acta Cryst. D74, 441-449) picks the data set of the
|
||||
// smallest Wilson B - not the largest: a long but poor sweep is a poor yardstick for the others, and one
|
||||
// that stays at low resolution shares too few reflections with the rest. The resolution alone is not
|
||||
// enough: a lattice that integrated a few hundred reflections of noise out to the edge of the detector
|
||||
// reaches the finest resolution of all, with 2% of the data merged and no ISa its error model could
|
||||
// resolve, and the merge made on its axes held nothing. Nor is a sweep's own CC1/2 or its unique count
|
||||
// resolve, and the merge made on its axes held nothing. Nor is an ISa enough: the crystal integrated in a
|
||||
// wrong setting resolves one, reaches the edge as well, and correlates with no other sweep - as the
|
||||
// reference, every other sweep had no axes on it and was processed again given its cell. Only the other
|
||||
// sweeps can show which merge measured the crystal, so the pairs are counted first, as Brehm & Diederichs
|
||||
// (2014) Acta Cryst. D70, 101-109 and KAMO relate data sets over all pairs. Nor is a sweep's own CC1/2 or its unique count
|
||||
// a better merit (both were tried): CC1/2 saturates on a small cell and reads precision, which a long
|
||||
// sweep of a poor crystal has, and a count rewards a sweep merged in too high a symmetry; both moved the
|
||||
// reference off the sweep the others agree with. Each other sweep is put on the reference's axes (the
|
||||
|
||||
@@ -199,6 +199,23 @@ TEST_CASE("RelateJointSweeps_SweepsAtTheSameEdgeAreTiedOnResolution", "[Rugnux]"
|
||||
CHECK(RelateJointSweeps(sweeps).reference == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("RelateJointSweeps_ReferenceIsASweepTheOthersAgreeWith", "[Rugnux]") {
|
||||
// Two sweeps of the crystal to 3 A, and a third with a resolved ISa reaching the finest resolution of
|
||||
// all whose intensities are another crystal's - what the crystal integrated in a wrong setting merges.
|
||||
// On its own it is the best sweep, but no other correlates with it: the reference is one of the two.
|
||||
const auto truth = Truth(1);
|
||||
std::vector<JointMemberSweep> sweeps;
|
||||
sweeps.push_back(MakeSweep(Truth(99), gemmi::Op::identity(), 100, 2, 10.0));
|
||||
sweeps.push_back(MakeSweep(CoarserThan(truth, 3.0), gemmi::Op::identity(), 100, 3, 10.0));
|
||||
sweeps.push_back(MakeSweep(CoarserThan(truth, 3.0), gemmi::Op::identity(), 100, 4, 20.0));
|
||||
REQUIRE(sweeps[0].d_min < 0.99 * sweeps[1].d_min);
|
||||
|
||||
const auto relation = RelateJointSweeps(sweeps);
|
||||
CHECK(relation.reference == 1);
|
||||
CHECK(relation.sweeps[2].included);
|
||||
CHECK_FALSE(relation.sweeps[0].included);
|
||||
}
|
||||
|
||||
TEST_CASE("RelateJointSweeps_ASweepThatKeptTheTwinOverlapIsLeftOut", "[Rugnux]") {
|
||||
// The reference's integration left out the reflections the other twin domain overlaps (index 2); the
|
||||
// third sweep's kept them. Its intensities agree elsewhere, so only the integration tells them apart.
|
||||
|
||||
Reference in new issue
Block a user