rugnux: write the twin hypothesis beside the answer as <prefix>_twin_<SG>.mtz/.cif
Near-perfect twins of a subgroup are undecidable from intensities, and a merge in the higher group cannot be twin-refined. Where the adopted group may have absorbed a twin law - a twin gate refused it and was overruled, or a group above P1 was adopted on a merge that read twin-like before the search - the same observations are also merged in a subgroup and written beside the answer, with the twin law and its fraction in _pdbx_reflns_twin. The subgroup is the one a decision named (the group a refused promotion was adopted over, the indexed lattice's group a metric re-ask promoted from), else the index-2 subgroup the search confirmed as a finalist whose lost two-fold agrees worst with the intensities. It is merged from the same engine, to the answer's resolution, without writing per-frame scales back; it carries the answer's free set (flags read off the answer's merge by the adopted group's asymmetric unit) and is written in the subgroup's reference and standard setting (a C 1 1 2_1 description is reduced to P 1 2_1 1). The fraction is Yeates' H on the pairs the law relates (1/2 - median H, a lower bound). At most one file; other qualifying subgroups are named in the report (TWIN_SUBGROUP_* keys). The answer's files are byte-identical. IndexTwoTwinSubgroups and EstimateTwinLawFraction are new and tested; the point-group ledger now carries each hypothesis's representative group. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
This commit is contained in:
1 parent
8f05793b67
commit
475df9e5cb
13 files changed
+557
-6
No files matched your search
@@ -172,6 +172,12 @@ axis preserves the class of a half-integer pseudo-translation, which is what a p
|
||||
That robustness does not extend to a pseudo-translation which is not half-integer, and the partner
|
||||
steps are restricted when one is detected - see the translational-pseudo-symmetry note below.
|
||||
|
||||
**The twin fraction of the twin hypothesis** follows Yeates: the intensity a twinned crystal records
|
||||
is (1−α) I(h) + α I(Th), and the disagreement
|
||||
H = |I(h) − I(Th)|/(I(h) + I(Th)) of the pairs a law relates is uniform on [0, 1−2α], so the median
|
||||
gives the fraction. T. O. Yeates, "Detecting and overcoming crystal twinning" (1997), Methods Enzymol.
|
||||
276, 344-358 [doi:10.1016/S0076-6879(97)76068-3](https://doi.org/10.1016/S0076-6879(97)76068-3).
|
||||
|
||||
**Translational pseudo-symmetry** is detected from the native Patterson computed from the merged
|
||||
intensities, and the interpretation of an off-origin peak as a pseudo-translation between copies of
|
||||
the contents of the asymmetric unit - together with the modulation it puts on the intensities, which
|
||||
|
||||
@@ -47,6 +47,7 @@ The methods draw on, and in places reimplement, solutions from:
|
||||
- P. Gasparotto, L. Barba, H.-C. Stadler et al., "TORO Indexer: a PyTorch-based indexing algorithm for kilohertz serial crystallography", *J. Appl. Cryst.* **57** (2024), 931-944 (the algorithm of the `ffbidx` fast-feedback indexer, §4).
|
||||
- I. Křivý & B. Gruber, "A unified algorithm for determining the reduced (Niggli) cell", *Acta Cryst.* **A32** (1976), 297-298, and International Tables for Crystallography Vol. A, Table 9.2.5.1 (the Niggli reduction and the lattice-character table of §5.3/§6).
|
||||
- J. E. Padilla & T. O. Yeates, "A statistic for local intensity differences: robustness to anisotropy and pseudo-centering and utility for detecting twinning", *Acta Cryst.* **D59** (2003), 1124-1130 (the L test, §13.2).
|
||||
- T. O. Yeates, "Detecting and overcoming crystal twinning", *Methods Enzymol.* **276** (1997), 344-358 (the $H$ statistic behind the twin fraction of the twin hypothesis, §13.2).
|
||||
- A. J. C. Wilson, "The probability distribution of X-ray intensities", *Acta Cryst.* **2** (1949), 318-321, and E. R. Howells, D. C. Phillips & D. Rogers, "The probability distribution of X-ray intensities. II. Experimental investigation and the X-ray detection of centres of symmetry", *Acta Cryst.* **3** (1950), 210-214 (the acentric and centric intensity distributions behind the centre-of-symmetry statistics of §13.1 and the Wilson outlier test of §13.3).
|
||||
- W. H. Baur & D. Kassner, "The perils of Cc: comparing the frequencies of falsely assigned space groups with their general population", *Acta Cryst.* **B48** (1992), 356-369 (writing the centrosymmetric group where the absences cannot decide the centre, §13.1).
|
||||
- R. J. Read, P. D. Adams & A. J. McCoy, "Intensity statistics in the presence of translational noncrystallographic symmetry", *Acta Cryst.* **D69** (2013), 176-183 (the native-Patterson detection of translational pseudo-symmetry, and the intensity modulation it produces, which the axial-zone screw-absence test scores against).
|
||||
|
||||
@@ -54,13 +54,17 @@ Both search merges also drop the **frames whose fitted per-frame scale came out
|
||||
|
||||
**A point group's own operators must agree with each other.** A point group is the claim that all of its operators are symmetries of one crystal, and a mixture of real and false operators has a specific shape: the real ones form a subgroup — the true group's intersection with the candidate — and everything outside it is false. The gate therefore reads the operators sorted by their $R$ against the merge, finds every prefix that closes into a subgroup, and takes the largest factor by which every operator outside such a subgroup reads worse than every operator inside it; above 3.2 the candidate is refused. A genuine group whose operators merely spread over a continuum — anisotropic systematic error spreads a cubic crystal's operators twofold — has no such gap. The earlier form, worst-agreeing over best-agreeing operator, divided by an extreme order statistic and refused a genuine $432$ as soon as one of its operators happened to agree unusually well.
|
||||
|
||||
**A group that holds every rotation of its lattice is refused when merging under it narrows the L-test like a twin.** Every gate above compares the added operators with a reference, and a pseudo-symmetric structure or a twin defeats them all. For a candidate that holds every rotation its lattice admits no twin law exists, so intensities merged under it that read like a twin's are not a twin. The Padilla–Yeates $L$-test is read twice on the same pairs of the $P1$ merge — as measured, and with every intensity replaced by the mean of its orbit under the candidate — and the candidate is refused where the merged $\langle|L|␍angle$ reads twin-like ($0.375 \le \langle|L|␍angle < 0.44$) and the averaging closed a third or more of the gap from the unmerged value to 0.375. Genuine lattice-holohedral groups close 0.01–0.25 of it. A merge reading below 0.375 is not read: nothing a twin or a false operator does reaches that, so something else compresses the intensities.
|
||||
**A group that holds every rotation of its lattice is refused when merging under it narrows the L-test like a twin.** Every gate above compares the added operators with a reference, and a pseudo-symmetric structure or a twin defeats them all. For a candidate that holds every rotation its lattice admits no twin law exists, so intensities merged under it that read like a twin's are not a twin. The Padilla–Yeates $L$-test is read twice on the same pairs of the $P1$ merge — as measured, and with every intensity replaced by the mean of its orbit under the candidate — and the candidate is refused where the merged $\langle|L|
|
||||
angle$ reads twin-like ($0.375 \le \langle|L|
|
||||
angle < 0.44$) and the averaging closed a third or more of the gap from the unmerged value to 0.375. Genuine lattice-holohedral groups close 0.01–0.25 of it. A merge reading below 0.375 is not read: nothing a twin or a false operator does reaches that, so something else compresses the intensities.
|
||||
|
||||
**The lattice class is re-asked where the metric knows more.** The Bravais class comes from Niggli reduction and a lattice-character lookup (§6), and that lookup can land short of the truth or beside it: near the Niggli type-I/type-II boundary it is decided by the last digits of the refined cell, and a lattice that is nearly but not exactly hexagonal matches the hexagonal character even when no point group that class can host carries the two-folds the data actually have. Two recoveries run, both settled by the intensities. Every rotation the cell metric can host beyond the named class — read off Le Page's two-fold search on the lattice itself, which measures each rotation's obliquity in a primitive basis and owes nothing to the character table — is put to the intensities as a single operator, scored exactly as the search scores its own operators, on the same reflection population and the same $E^2$ normalisation. And where the metric group is larger than the adopted class's holohedry, the merge is reindexed into the metric group's conventional cell and the space-group search is run again there, with every gate live; the reindex is committed only where the search in the new setting confirms a strictly higher point group *and* the centring the new cell describes, so a pseudo-symmetric metric leaves the answer already in hand standing.
|
||||
|
||||
### 13.2 Twinning check, and translational pseudo-symmetry
|
||||
|
||||
A Padilla–Yeates $L$-test ($\langle|L|\rangle$, $\langle L^2\rangle$ — 0.500 and 0.333 untwinned, 0.375 and 0.200 for a perfect twin) and the second moment $\langle I^2\rangle/\langle I\rangle^2$ (2.0 for untwinned acentric data, 1.5 for a perfect twin) are written to the merged mmCIF as a twinning diagnostic. Both are taken on intensities divided by their resolution-shell mean, over the shells whose $\langle I/\sigma\rangle$ reaches 1, with Wilson outliers rejected; the $L$-test pairs are therefore compared on one scale even where two index steps span a steep fall-off, as in phenix.xtriage and ctruncate, and the selection is by shell, never by the individual reflection's $I/\sigma$, which would cut the weak tail and bias $\langle|L|\rangle$ down. The twin fraction is quoted from the statistic that carries the verdict — the $L$-test unless the call rests on the second moment alone — and a second moment is not turned into a fraction under a detected pseudo-translation, which inflates it. A merohedral twin law exists only where the Laue class is a proper subgroup of the lattice holohedry, so in the high-symmetry holohedral classes ($4/mmm$, $6/mmm$, $m\bar{3}m$, and $\bar{3}m$ on a rhombohedral lattice) no twin is called. The $L$-test is still read there, for a different question: merging $I(h)$ with $I(Th)$ under a false operator $T$ gives $(I(h)+I(Th))/2$ whatever the twin fraction, which has the perfect-twin distribution, so $\langle|L|\rangle$ below 0.42 in a holohedral class is reported as **an adopted operator averaging unequal intensities** — the space group is too high, or a twin law was absorbed into the point group — a warning, never a change to the space group. A genuine operator leaves the untwinned 0.5. Reflections that overlap along a very long axis narrow the distribution the same way, which is one reason it stays a warning. The same numbers measured on the P1 merge the space-group search was given, before any point group was adopted, are reported beside them (`_BEFORE_SEARCH`), with that merge's own pseudo-translation declared and the reflections its lattice centring extinguishes left out. The low-symmetry holohedral classes ($\bar{1}$, $2/m$, $mmm$) also admit no strictly merohedral law, but they stay eligible for the twin call on purpose: *pseudo*-merohedral twinning through an accidentally special metric cannot be ruled out from the symmetry alone, and those are the classes it happens in.
|
||||
A Padilla–Yeates $L$-test ($\langle|L|\rangle$, $\langle L^2\rangle$ — 0.500 and 0.333 untwinned, 0.375 and 0.200 for a perfect twin) and the second moment $\langle I^2\rangle/\langle I\rangle^2$ (2.0 for untwinned acentric data, 1.5 for a perfect twin) are written to the merged mmCIF as a twinning diagnostic. Both are taken on intensities divided by their resolution-shell mean, over the shells whose $\langle I/\sigma\rangle$ reaches 1, with Wilson outliers rejected; the $L$-test pairs are therefore compared on one scale even where two index steps span a steep fall-off, as in phenix.xtriage and ctruncate, and the selection is by shell, never by the individual reflection's $I/\sigma$, which would cut the weak tail and bias $\langle|L|\rangle$ down. The twin fraction is quoted from the statistic that carries the verdict — the $L$-test unless the call rests on the second moment alone — and a second moment is not turned into a fraction under a detected pseudo-translation, which inflates it. A twin law exists only where the **lattice** has a rotation the group lacks, so whether one is possible is read off the cell, not off the name of the Laue class: the lattice's two-folds are found as for the free set (Le Page, within 3° obliquity — GEMMI's `find_twin_laws`), and where none lies outside the group no twin is called. That covers the holohedral classes ($4/mmm$ on a tetragonal lattice, $6/mmm$, $m\bar{3}m$, $\bar{3}m$ on a rhombohedral one) and equally $mmm$ or $2/m$ on a lattice with no special metric, while a pseudo-merohedral $2/m$ or $mmm$ lattice — a monoclinic $\beta$ near 90°, a C-centred cell with $b \approx a\sqrt{3}$ — admits a law and stays eligible. The $L$-test is still read where no law is possible, for a different question: merging $I(h)$ with $I(Th)$ under a false operator $T$ gives $(I(h)+I(Th))/2$ whatever the twin fraction, which has the perfect-twin distribution, so $\langle|L|\rangle$ below 0.42 there is reported as **an adopted operator averaging unequal intensities** — the space group is too high, or a twin law was absorbed into the point group — a warning, never a change to the space group. A genuine operator leaves the untwinned 0.5. Reflections that overlap along a very long axis narrow the distribution the same way, which is one reason it stays a warning. The same numbers measured on the P1 merge the space-group search was given, before any point group was adopted, are reported beside them (`_BEFORE_SEARCH`), with that merge's own pseudo-translation declared and the reflections its lattice centring extinguishes left out. Between that bar and the twin band's 0.44 the verdict is `NO_TWIN_LAW`: the intensities read twin-like, but the lattice admits no law for the group, so they are not a twin in it — the group may be too high (a subgroup's twin law absorbed, or non-crystallographic symmetry taken for real), or something other than twinning narrowed the distribution. It is reported as such rather than as a twin that "needs a twin law" no refinement program could be given.
|
||||
|
||||
**The twin hypothesis.** Where the adopted group may have absorbed a twin law — a twin gate of the search refused it and was overruled (§13.1), or a group above $P1$ was adopted on a merge that read twin-like before the search — the same observations are also merged in a subgroup and written beside the answer as `<prefix>_twin_<SG>.mtz` / `.cif`, in the subgroup's standard setting, to the answer's resolution and with the answer's free set (each reflection takes the flag of the reflection of the answer's merge its orbit falls in, so twin mates share it). The subgroup is the one a decision named — the group a refused promotion was adopted over, or the indexed lattice's group a metric re-ask promoted from — and otherwise, among the index-2 subgroups of the adopted group that the search confirmed as point-group finalists, the one whose lost two-fold agrees worst with the intensities (lowest operator CC): the most likely twin law. One file is written; the other subgroups that qualified are named in the report. The law is in the mmCIF's `_pdbx_reflns_twin` with its fraction, from Yeates' $H$ on the pairs it relates in the subgroup merge — $H = |I(h)-I(Th)|/(I(h)+I(Th))$ is uniform on $[0, 1-2\alpha]$, so $\alpha = 1/2 - \mathrm{median}\,H$, a lower bound since measurement error only adds to $H$. Nothing the answer is made of depends on it: it is a second merge from the same scaled observations, and the answer's files are byte for byte what they are without it. Refinement programs want twinned data merged in the true lower group, never detwinned, which is why the file is the merge and not a correction of the answer; a near-perfect twin of a subgroup and the higher group predict the same intensities, so which of the two is the crystal is a question for a model.
|
||||
|
||||
Beside them, on rotation data with `--finalist-ledger`, the run reports **twin-immune zone evidence** for the operators the adopted point group adds over each of its index-2 subgroups, read on a full-resolution merge of the observations in P1 that the option makes for the purpose. Under a twin law $T$, $I_\mathrm{obs}(h)=(1-\alpha)I(h)+\alpha I(Th)$; a reflection whose twin mate is itself up to the subgroup and Friedel is untouched at every $\alpha$, and those are exactly the reflections centric in the group but acentric in the subgroup. They read centric ($\langle|E^2-1|\rangle = 0.968$) if the added operators are real and acentric (0.736) if they are a twin law or a pseudo-symmetry — the one intensity statistic that still separates the two at $\alpha = 0.5$, where every operator statistic reads "real". Each zone is normalised against its own mean in resolution bins (and within the two phase classes of a detected pseudo-translation), read only in shells with $\langle I/\sigma\rangle \ge 5$ because noise inflates every class towards centric, and reported with $n$, a standard error and the centric-over-acentric Wilson log-likelihood ratio in nats (both densities convolved with each reflection's measurement error), beside the acentric control. It is read absolutely, never as the difference to the control: a perfect twin's control (0.541) plus noise inflation would otherwise look like true symmetry. An absolute reading is only as good as the normalisation, though, and the acentric control certifies it: an acentric population reads $-0.130$ nats per reflection when the normalisation is right, and whatever the control reads above that is the normalisation's — anisotropy, a pseudo-translation, a pseudo-centring, noise all inflate every class towards centric alike — so the zone, normalised the same way, carries the same per reflection and the **calibrated** evidence has it taken off (a twinned control reads *below* the expectation, so nothing is taken off a twin). The centric side is read **twinned at the fraction the lattice's other operations show** by their own correlation — the strongest CC of a lattice rotation outside the group, relative to the mean CC of the group's own operators, inverted through $\rho = 2\alpha(1-\alpha)/((1-\alpha)^2+\alpha^2)$ — because a twin by another law reaches a genuine zone exactly as it reaches the control: a genuine 321 crystal twinned by a 622 law read its 2-folds at −206 nats against the untwinned centric density and +209 at that law's fraction of 0.07. The operators' own twin law cannot reach their zone, so the acentric side stays untwinned, and the control's expectation is taken at the same fraction. Measured, a 6/m crystal with a 67 Ų anisotropy read its control at $+0.10$ nats per reflection and the zone of a refused 622 the same, so the zone's $+124$ nats were the normalisation's; calibrated it reads $-115$, and genuine promotions keep $+200$ and above. The calibrated zone is what a refused promotion is decided on (above). It is an in-house method: published practice (Yeates' $H$-test, xtriage) excludes these reflections as uninformative about the twin fraction, and no published test was found that uses them positively; the one precedent here is a trigonal crystal whose twin-immune zone read centric and whose higher group was then confirmed by refinement.
|
||||
|
||||
@@ -268,3 +272,4 @@ Where a CUDA GPU is present, the refinement's target is evaluated on it: the sam
|
||||
The rotation and translation actually taken are reported (`RIGID_BODY_ROTATION_DEG`, `RIGID_BODY_SHIFT_A`), together with the R-free before it (`R_FREE_BEFORE_RIGID_BODY`), so what the placement bought is visible.
|
||||
|
||||
The coordinates **as placed** are written as `<prefix>_model.cif`, and as `<prefix>_model.pdb` where the PDB format can hold the cell (the fragment-screening tools the file feeds — PanDDA, and the pair dimple produces — take a PDB beside the MTZ), so there is a coordinate file that describes the maps: the input's chains, residues, ligands, waters, B-factors, occupancies and anisotropic $U$s, moved, in the same cell and space group as `<prefix>.mtz`. Taking the frame from the written reflections rather than from the input model matters — §14.6 may have relabelled them to the model's enantiomorph, which is neither the data's original group nor, necessarily, the model's. It is written **whenever the maps are**, not only where the rigid-body step was committed: the model is re-fractionalized into the data cell and may be relabelled whatever the placement decided, so an unmoved model is still not the input file; and a model the null of §14.5 rejected is scored, placed and mapped like any other, which is precisely the case where the density is worth looking at.
|
||||
|
||||
+27
-3
@@ -738,14 +738,38 @@ dropped from the twin verdict **in both directions**: it can no longer indicate
|
||||
longer be read as proof that there is none. The second moment then decides alone.
|
||||
|
||||
**`TWINNING_VERDICT=`** is `NO_INDICATION`, `INDICATED` (⟨|L|⟩ below 0.44, the phenix.xtriage convention,
|
||||
or the second moment low, in a Laue class that admits a twin law), `SYMMETRY_SUSPECT` (the same low
|
||||
reading in a holohedral class, where no twin law exists and a false adopted operator gives the same
|
||||
distribution) or `NOT_READABLE`. ⟨|L|⟩ has a physical range: 0.5 untwinned, 0.375 a perfect twin,
|
||||
or the second moment low, where the lattice admits a twin law for the group), `SYMMETRY_SUSPECT`
|
||||
(⟨|L|⟩ below 0.42 where the lattice admits no twin law - a false adopted operator gives the same
|
||||
distribution), `NO_TWIN_LAW` (⟨|L|⟩ between 0.42 and 0.44 where the lattice admits no twin law: not a
|
||||
twin in this group, so the group may be too high, or something other than twinning narrowed the
|
||||
distribution) or `NOT_READABLE`. Whether a twin law is possible is read off the cell - a rotation of
|
||||
the lattice's metric, within 3° obliquity, that the group lacks - not off the Laue class, so a
|
||||
pseudo-merohedral monoclinic or orthorhombic lattice admits one and a general one does not. ⟨|L|⟩ has a physical range: 0.5 untwinned, 0.375 a perfect twin,
|
||||
whatever the law. Where it reads below 0.375, or above 0.55 (on this merge or on the one before the
|
||||
space-group search), no twin fraction explains it - the statistic is distorted, by tNCS, anisotropy,
|
||||
overlapping reflections of a very long cell, or too few reflections - and the verdict is
|
||||
`NOT_READABLE`, with no warning: it says nothing about twinning, nor about the space group.
|
||||
|
||||
### The twin hypothesis (`TWIN_SUBGROUP_*`)
|
||||
|
||||
Where the adopted space group may have absorbed a twin law - a twin gate of the space-group search
|
||||
refused it and was overruled, or a group above P1 was adopted on data that read twin-like before the
|
||||
search (`L_TEST_MEAN_ABS_L_BEFORE_SEARCH`) - the run also writes the same observations merged in a
|
||||
subgroup, as `<prefix>_twin_<SG>.mtz` and `.cif` in the subgroup's standard setting, to the same
|
||||
resolution and with the same free set as `<prefix>.mtz`, the twin law in the mmCIF's
|
||||
`_pdbx_reflns_twin`. A near-perfect twin of the subgroup predicts the same intensities as the higher
|
||||
group, and a refinement program can only twin-refine data merged in the lower group, so the file is
|
||||
there to refine against with the law where a model prefers it. The answer's files and keys do not
|
||||
depend on it. At most one is written.
|
||||
|
||||
| key | meaning |
|
||||
|---|---|
|
||||
| `TWIN_SUBGROUP_FILE` | The file written, `<prefix>_twin_<SG>.mtz` (and `.cif` beside it) |
|
||||
| `TWIN_SUBGROUP_SPACE_GROUP` | The subgroup, as written |
|
||||
| `TWIN_SUBGROUP_LAW` | The twin law on that file's axes, as an hkl triplet |
|
||||
| `TWIN_SUBGROUP_FRACTION` | The law's fraction from the disagreement of the pairs it relates (1/2 − median H, Yeates' H test): a lower bound |
|
||||
| `TWIN_SUBGROUP_ALTERNATIVES` | Other confirmed subgroups that qualified; `-S` merges in one |
|
||||
|
||||
## Diffraction anisotropy
|
||||
|
||||
Section 4 also reports how much the fall-off with resolution depends on **direction**, and whether that is
|
||||
|
||||
@@ -285,6 +285,10 @@ Absorption is corrected only by the empirical surface a rotation run fits and ke
|
||||
per-dataset input layout, and the pair dimple produces — and it is skipped, with a log line, for
|
||||
a cell the PDB format cannot hold. See
|
||||
[Validating against a model](RUGNUX_ADVANCED.md#validating-against-a-model-rugnux---model).
|
||||
- `<prefix>_twin_<SG>.mtz` / `.cif` — only where the chosen space group may have absorbed a twin law:
|
||||
the same data merged in a subgroup `<SG>`, with the twin law and its fraction, same resolution and
|
||||
free set as `<prefix>.mtz`, for refinement with that law. See
|
||||
[The twin hypothesis](RUGNUX_REPORT.md#the-twin-hypothesis-twin_subgroup_).
|
||||
- `<prefix>_report.txt` — the **results report**: what the run determined, in a form both a person and
|
||||
a beamline script can read. Always written, next to the files above. See
|
||||
[The results report](RUGNUX_REPORT.md#the-results-report).
|
||||
|
||||
@@ -2071,6 +2071,8 @@ SearchSpaceGroupResult SearchSpaceGroup(
|
||||
for (const auto& c : pg_cands) {
|
||||
PointGroupLedgerEntry e;
|
||||
e.point_group_hm = c.pg->representative ? c.pg->representative->point_group_hm() : "1";
|
||||
if (c.pg->representative)
|
||||
e.representative = *c.pg->representative;
|
||||
e.order = c.order;
|
||||
e.min_class_cc = c.min_class_cc;
|
||||
e.chi2 = c.chi2;
|
||||
|
||||
@@ -724,6 +724,9 @@ struct SearchSpaceGroupOptions {
|
||||
// REPORT-ONLY. Nothing in the search reads these back; the adoption is made exactly as before.
|
||||
struct PointGroupLedgerEntry {
|
||||
std::string point_group_hm;
|
||||
// The symmorphic group of the hypothesis, in the merge's basis: the name cannot say which axes a
|
||||
// "2" or a "222" is on, and a caller asking whether a given subgroup is a finalist needs to.
|
||||
std::optional<gemmi::SpaceGroup> representative;
|
||||
int order = 0;
|
||||
double min_class_cc = 0.0; // weakest operator CC among the group's own operators
|
||||
double chi2 = std::numeric_limits<double>::quiet_NaN(); // merge chi^2 folding under it
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "gemmi/twin.hpp"
|
||||
|
||||
#include "../../common/ParallelFor.h"
|
||||
#include "HKLKey.h"
|
||||
|
||||
namespace {
|
||||
int64_t PackHKL(int h, int k, int l) {
|
||||
@@ -62,6 +63,104 @@ bool TwinLawPossible(const gemmi::UnitCell& cell, const gemmi::SpaceGroup& space
|
||||
return !gemmi::find_twin_laws(cell, &space_group, max_obliquity_deg, /*all_ops=*/false).empty();
|
||||
}
|
||||
|
||||
std::vector<TwinSubgroup> IndexTwoTwinSubgroups(const gemmi::SpaceGroup& group) {
|
||||
const gemmi::GroupOps gops = group.operations();
|
||||
const size_t order = gops.sym_ops.size();
|
||||
std::vector<gemmi::Op::Rot> rots;
|
||||
for (const auto& op : gops.sym_ops)
|
||||
rots.push_back(op.rot);
|
||||
const auto index_of = [&](const gemmi::Op::Rot& r) {
|
||||
return static_cast<size_t>(std::find(rots.begin(), rots.end(), r) - rots.begin());
|
||||
};
|
||||
const auto product = [](const gemmi::Op::Rot& a, const gemmi::Op::Rot& b) {
|
||||
return gemmi::Op{a, {0, 0, 0}, 'x'}.combine(gemmi::Op{b, {0, 0, 0}, 'x'}).rot;
|
||||
};
|
||||
// Every index-2 subgroup of a crystallographic point group is generated by at most two of its
|
||||
// operations, so the closures of all pairs find them all.
|
||||
std::vector<std::vector<bool>> seen;
|
||||
std::vector<TwinSubgroup> out;
|
||||
for (size_t i = 0; i < order; ++i)
|
||||
for (size_t j = i; j < order; ++j) {
|
||||
std::vector<bool> in(order, false);
|
||||
in[0] = in[i] = in[j] = true; // sym_ops[0] is the identity
|
||||
for (bool grew = true; grew;) {
|
||||
grew = false;
|
||||
for (size_t a = 0; a < order; ++a)
|
||||
for (size_t b = 0; b < order; ++b)
|
||||
if (in[a] && in[b]) {
|
||||
const size_t c = index_of(product(rots[a], rots[b]));
|
||||
if (c < order && !in[c]) { in[c] = true; grew = true; }
|
||||
}
|
||||
}
|
||||
if (2 * static_cast<size_t>(std::count(in.begin(), in.end(), true)) != order
|
||||
|| std::find(seen.begin(), seen.end(), in) != seen.end())
|
||||
continue;
|
||||
seen.push_back(in);
|
||||
gemmi::GroupOps sub;
|
||||
sub.cen_ops = gops.cen_ops;
|
||||
std::vector<gemmi::Op> laws;
|
||||
for (size_t a = 0; a < order; ++a) {
|
||||
if (in[a]) {
|
||||
sub.sym_ops.push_back(gops.sym_ops[a]);
|
||||
continue;
|
||||
}
|
||||
const gemmi::Op r{rots[a], {0, 0, 0}, 'x'};
|
||||
if (r.det_rot() > 0 && r.combine(r).rot == gemmi::Op::identity().rot)
|
||||
laws.push_back(r);
|
||||
}
|
||||
if (laws.empty())
|
||||
continue;
|
||||
// The kept screws can sit off the origin GEMMI's table puts them at (the 2_1 axes of
|
||||
// P2_12_12_1 do not meet), so the subgroup is looked up at every origin shift; a shift moves
|
||||
// no reflection and no absence.
|
||||
const gemmi::SpaceGroup* found = nullptr;
|
||||
for (int n = 0; n < 12 * 12 * 12 && found == nullptr; ++n) {
|
||||
gemmi::GroupOps shifted = sub;
|
||||
gemmi::Op shift = gemmi::Op::identity();
|
||||
shift.tran = {n / 144 * gemmi::Op::DEN / 12, n / 12 % 12 * gemmi::Op::DEN / 12,
|
||||
n % 12 * gemmi::Op::DEN / 12};
|
||||
shifted.change_basis_forward(shift);
|
||||
found = gemmi::find_spacegroup_by_ops(shifted);
|
||||
}
|
||||
if (found != nullptr)
|
||||
out.push_back({*found, laws});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Following Yeates (1997) Methods Enzymol. 276, 344-358
|
||||
TwinLawFraction EstimateTwinLawFraction(const std::vector<MergedReflection>& merged,
|
||||
const gemmi::SpaceGroup& space_group, const gemmi::Op& law,
|
||||
bool merge_friedel) {
|
||||
TwinLawFraction result;
|
||||
const HKLKeyGenerator key_of(merge_friedel, space_group);
|
||||
const gemmi::GroupOps gops = space_group.operations();
|
||||
std::unordered_map<uint64_t, double> intensity;
|
||||
for (const auto& r : merged)
|
||||
if (UsableIntensity(r))
|
||||
intensity.emplace(key_of(r).pack(), r.I);
|
||||
std::vector<double> h;
|
||||
for (const auto& r : merged) {
|
||||
if (!UsableIntensity(r) || gops.is_reflection_centric({{r.h, r.k, r.l}}))
|
||||
continue;
|
||||
const auto mate = law.apply_to_hkl({{r.h, r.k, r.l}});
|
||||
const uint64_t k1 = key_of(r).pack(), k2 = key_of(mate[0], mate[1], mate[2]).pack();
|
||||
if (k2 <= k1)
|
||||
continue; // each pair once, and not a reflection with itself
|
||||
const auto it = intensity.find(k2);
|
||||
if (it == intensity.end() || r.I + it->second <= 0.0)
|
||||
continue;
|
||||
h.push_back(std::fabs(r.I - it->second) / (r.I + it->second));
|
||||
}
|
||||
result.pairs = static_cast<int>(h.size());
|
||||
if (h.empty())
|
||||
return result;
|
||||
const size_t mid = h.size() / 2;
|
||||
std::nth_element(h.begin(), h.begin() + mid, h.end());
|
||||
result.fraction = std::max(0.0, 0.5 - h[mid]);
|
||||
return result;
|
||||
}
|
||||
|
||||
TwinningAnalysisResult AnalyzeTwinning(const std::vector<MergedReflection>& merged,
|
||||
const gemmi::SpaceGroup* space_group, int resolution_shells,
|
||||
const std::array<double, 3>* tncs_vector, char lattice_centring,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -112,6 +113,31 @@ TwinningAnalysisResult AnalyzeTwinning(const std::vector<MergedReflection>& merg
|
||||
|
||||
std::string TwinningAnalysisToText(const TwinningAnalysisResult& result);
|
||||
|
||||
// An index-2 subgroup of `group` that keeps the translations of the operations it keeps (a
|
||||
// translationengleiche subgroup, in the group's own setting), with the proper two-folds of `group`
|
||||
// outside it: each is a twin law that merge in the subgroup would carry, were `group` a twin's
|
||||
// supergroup, and any one of them describes the twin (they differ by an operation of the subgroup).
|
||||
// Only subgroups whose coset holds a two-fold and that GEMMI's table names in this setting (at some origin) are listed.
|
||||
// The laws are rotations (zero translation), acting on Miller indices through apply_to_hkl.
|
||||
struct TwinSubgroup {
|
||||
gemmi::SpaceGroup subgroup;
|
||||
std::vector<gemmi::Op> laws;
|
||||
};
|
||||
std::vector<TwinSubgroup> IndexTwoTwinSubgroups(const gemmi::SpaceGroup& group);
|
||||
|
||||
// The twin fraction a twin law implies on a merge in a group the law is not part of, from the
|
||||
// disagreement of the reflection pairs it relates: H = |I(h) - I(Th)| / (I(h) + I(Th)) over the
|
||||
// acentric pairs, uniform on [0,1] for untwinned Wilson intensities and on [0, 1-2a] for a twin of
|
||||
// fraction a, so a = 1/2 - median H. A lower bound: measurement error only adds to H. NaN with no
|
||||
// pairs.
|
||||
struct TwinLawFraction {
|
||||
double fraction = std::numeric_limits<double>::quiet_NaN();
|
||||
int pairs = 0;
|
||||
};
|
||||
TwinLawFraction EstimateTwinLawFraction(const std::vector<MergedReflection>& merged,
|
||||
const gemmi::SpaceGroup& space_group, const gemmi::Op& law,
|
||||
bool merge_friedel = true);
|
||||
|
||||
// The verdict in one line - "INDICATED (...)", "SYMMETRY SUSPECT (...)" or "no indication (...)" -
|
||||
// so the report's summary row, its prose and the viewer all say the same thing.
|
||||
std::string TwinningVerdictLine(const TwinningAnalysisResult& result);
|
||||
|
||||
@@ -1906,6 +1906,34 @@ ReportDocument BuildReportDocument(const std::string &output_prefix,
|
||||
" against these data in this space group with that law.",
|
||||
result.twinning.twin_law_operator, result.twinning.twin_law_fraction)));
|
||||
}
|
||||
if (result.twin_subgroup_merge) {
|
||||
const auto &t = *result.twin_subgroup_merge;
|
||||
Add(s, KeyText("TWIN_SUBGROUP_FILE", t.file_prefix + ".mtz"));
|
||||
Add(s, KeyText("TWIN_SUBGROUP_SPACE_GROUP", t.space_group));
|
||||
Add(s, KeyText("TWIN_SUBGROUP_LAW", t.twin_law));
|
||||
Add(s, KeyReal("TWIN_SUBGROUP_FRACTION", t.twin_fraction, "{:.3f}"));
|
||||
Add(s, KeyInt("TWIN_SUBGROUP_FRACTION_PAIRS", t.twin_fraction_pairs, true));
|
||||
if (!t.other_subgroups.empty()) {
|
||||
std::string others;
|
||||
for (const auto &o : t.other_subgroups)
|
||||
others += (others.empty() ? "" : " | ") + o;
|
||||
Add(s, KeyText("TWIN_SUBGROUP_ALTERNATIVES", others));
|
||||
}
|
||||
Add(s, Prose(fmt::format(
|
||||
" Twin hypothesis: {} was adopted, but {}. A twin of {} whose law {} absorbs predicts\n"
|
||||
" these intensities too, and a merge in {} cannot be refined against that twin. So the\n"
|
||||
" same observations are also written merged in {} - same resolution, same free set -\n"
|
||||
" as {}.mtz / .cif, with the twin law {} at a fraction of at least {:.2f} (from the\n"
|
||||
" disagreement of the reflection pairs it relates, a lower bound; the mmCIF carries it\n"
|
||||
" as _pdbx_reflns_twin). Refine against it with that twin law where the model prefers it.\n"
|
||||
" Nothing in this report or in the answer's files depends on it.{}",
|
||||
t.adopted_space_group, t.reason, t.space_group, t.adopted_space_group, t.space_group,
|
||||
t.space_group, t.file_prefix, t.twin_law, t.twin_fraction,
|
||||
t.other_subgroups.empty() ? std::string()
|
||||
: "\n Other subgroups the search confirmed, each a twin hypothesis of\n"
|
||||
" its own (re-run with -S to merge in one): see\n"
|
||||
" TWIN_SUBGROUP_ALTERNATIVES.")));
|
||||
}
|
||||
for (size_t i = 0; i < result.twin_law_evidence.size(); ++i)
|
||||
Add(s, KeyText(fmt::format("TWIN_LAW_{}", i + 1).c_str(), result.twin_law_evidence[i]));
|
||||
if (result.twin_immune_zones && !result.twin_immune_zones->zones.empty()) {
|
||||
|
||||
@@ -477,6 +477,23 @@ struct ProcessResult {
|
||||
// merge (AnalyzeTwinImmuneZones). Report-only. Unset without --finalist-ledger.
|
||||
std::optional<TwinImmuneZoneResult> twin_immune_zones;
|
||||
|
||||
// The twin hypothesis written beside the answer: where the adopted group may have absorbed a twin
|
||||
// law (a twin gate overruled, or a group adopted on data that read twin-like before the search), the
|
||||
// same observations merged in a subgroup, to the same resolution and with the same free set, as
|
||||
// <prefix>_twin_<SG>.mtz / .cif in the subgroup's standard setting, carrying the law. The answer's
|
||||
// own files are not touched by it. Unset where none was written.
|
||||
struct TwinSubgroupMerge {
|
||||
std::string reason; // why the hypothesis was written
|
||||
std::string adopted_space_group; // the group of the answer, as written
|
||||
std::string space_group; // the subgroup, as written (standard setting)
|
||||
std::string file_prefix; // <prefix>_twin_<SG>
|
||||
std::string twin_law; // hkl triplet, on the subgroup file's axes
|
||||
double twin_fraction = NAN; // EstimateTwinLawFraction: a lower bound
|
||||
int twin_fraction_pairs = 0;
|
||||
std::vector<std::string> other_subgroups; // other confirmed subgroups that qualified
|
||||
};
|
||||
std::optional<TwinSubgroupMerge> twin_subgroup_merge;
|
||||
|
||||
// What --model found, when one was given. Set even when the validation could not run - its
|
||||
// failure_reason then says why - so the report can report the failure rather than leave a run
|
||||
// that was asked to validate looking like one that was not. Unset when no model was asked for.
|
||||
|
||||
@@ -214,6 +214,108 @@ namespace {
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// The subgroup a twin-law merge is made in (<prefix>_twin_<SG>), and the law it carries, where the
|
||||
// adopted group may have absorbed a twin law. Candidates are the index-2 subgroups of `group`
|
||||
// (IndexTwoTwinSubgroups); where a decision of the search named one - the group a refused promotion
|
||||
// was adopted over, or the indexed lattice's group a metric re-ask promoted from - only that one,
|
||||
// and otherwise those the search confirmed as point-group finalists (the ledger's eligible rows).
|
||||
// Among them, the one whose law agrees worst with the intensities (lowest Stage A CC): the
|
||||
// two-fold most likely to be the twin law. The rest are named for the report.
|
||||
struct TwinSubgroupChoice {
|
||||
gemmi::SpaceGroup subgroup;
|
||||
gemmi::Op law;
|
||||
std::vector<std::string> others;
|
||||
};
|
||||
|
||||
std::optional<TwinSubgroupChoice> ChooseTwinSubgroup(const gemmi::SpaceGroup &group,
|
||||
const SearchSpaceGroupResult &search,
|
||||
const std::optional<gemmi::SpaceGroup> &named) {
|
||||
const auto rotations = [](const gemmi::SpaceGroup &g) {
|
||||
std::vector<gemmi::Op::Rot> r;
|
||||
for (const auto &op : g.operations().sym_ops)
|
||||
r.push_back(op.rot);
|
||||
std::sort(r.begin(), r.end());
|
||||
return r;
|
||||
};
|
||||
const auto law_cc = [&](const gemmi::Op &law) {
|
||||
const std::string t = law.as_hkl().triplet('h');
|
||||
for (const auto &s : search.operator_scores)
|
||||
if (s.op_triplet_hkl == t)
|
||||
return s.cc;
|
||||
return std::numeric_limits<double>::infinity();
|
||||
};
|
||||
std::optional<TwinSubgroupChoice> best;
|
||||
double best_cc = 0.0;
|
||||
std::vector<std::string> names;
|
||||
for (const auto &t : IndexTwoTwinSubgroups(group)) {
|
||||
if (t.subgroup.operations().sym_ops.size() < 2)
|
||||
continue; // P1: a twin of it is not what a promotion absorbs
|
||||
const auto rots = rotations(t.subgroup);
|
||||
const bool qualifies = named
|
||||
? rotations(*named) == rots
|
||||
: std::any_of(search.point_group_ledger.begin(), search.point_group_ledger.end(),
|
||||
[&](const PointGroupLedgerEntry &e) {
|
||||
return e.eligible && e.representative
|
||||
&& rotations(*e.representative) == rots;
|
||||
});
|
||||
if (!qualifies)
|
||||
continue;
|
||||
names.push_back(t.subgroup.xhm());
|
||||
const gemmi::Op *law = &t.laws.front();
|
||||
for (const auto &l : t.laws)
|
||||
if (law_cc(l) < law_cc(*law))
|
||||
law = &l;
|
||||
if (!best || law_cc(*law) < best_cc) {
|
||||
best = TwinSubgroupChoice{t.subgroup, *law, {}};
|
||||
best_cc = law_cc(*law);
|
||||
}
|
||||
}
|
||||
if (best)
|
||||
for (const auto &n : names)
|
||||
if (n != best->subgroup.xhm())
|
||||
best->others.push_back(n);
|
||||
return best;
|
||||
}
|
||||
|
||||
// A twin-law choice on other axes: the group by SpaceGroupInBasis, the law conjugated by the
|
||||
// Miller-index operator the change of basis moves the reflections by. False where no setting in
|
||||
// GEMMI's table names the moved group.
|
||||
bool MoveTwinSubgroupChoice(TwinSubgroupChoice &c, const gemmi::Op &cob) {
|
||||
const gemmi::SpaceGroup *moved = SpaceGroupInBasis(c.subgroup, cob);
|
||||
if (moved == nullptr)
|
||||
return false;
|
||||
const gemmi::Op m = HklOperator(cob);
|
||||
c.subgroup = *moved;
|
||||
c.law = m.inverse().combine(c.law).combine(m); // h' = m h: back by m, the law, forward by m
|
||||
return true;
|
||||
}
|
||||
|
||||
// `group` carried into the setting a Miller-index reindex q (h' = q h) takes the merge to, with the
|
||||
// centring that setting describes - the move the metric re-ask makes with the lattice. Empty where
|
||||
// no setting in GEMMI's table names the result.
|
||||
std::optional<gemmi::SpaceGroup> GroupInReindexedSetting(const gemmi::SpaceGroup &group,
|
||||
const gemmi::Mat33 &q, char centring) {
|
||||
try {
|
||||
gemmi::Op hkl = gemmi::Op::identity();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = 0; j < 3; ++j)
|
||||
hkl.rot[i][j] = static_cast<int>(std::lround(q[j][i])) * gemmi::Op::DEN; // apply_to_hkl uses rot^T
|
||||
gemmi::Op cob = hkl.inverse();
|
||||
for (int i = 0; i < 12; ++i)
|
||||
for (int j = 0; j < 12; ++j)
|
||||
for (int k = 0; k < 12; ++k) {
|
||||
cob.tran = {i * gemmi::Op::DEN / 12, j * gemmi::Op::DEN / 12, k * gemmi::Op::DEN / 12};
|
||||
gemmi::GroupOps gops = group.operations();
|
||||
gops.change_basis_forward(cob);
|
||||
gops.cen_ops = gemmi::centring_vectors(centring);
|
||||
if (const gemmi::SpaceGroup *found = gemmi::find_spacegroup_by_ops(gops))
|
||||
return *found;
|
||||
}
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
// Proper rotations of a crystal system's holohedry - what a lattice of that class carries, and the
|
||||
@@ -1210,6 +1312,16 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
// above triclinic - i.e. a promotion was made, which is what makes a later "the Laue class is
|
||||
// holohedral so there is no twin law" conclusion circular.
|
||||
bool promoted_point_group = false;
|
||||
// The twin-law merge (<prefix>_twin_<SG>): where the adopted group may have absorbed a twin law,
|
||||
// the subgroup a second merge is made in and the law it carries, in the scaler's frame, and why.
|
||||
// The decisions below that name a subgroup leave it here: the group a refused promotion was
|
||||
// adopted over (a twin gate overruled), and the indexed lattice's group a metric re-ask promoted
|
||||
// from. Report and an extra file only - nothing the run writes as its answer reads any of it.
|
||||
std::optional<gemmi::SpaceGroup> twin_overruled_subgroup, twin_metric_subgroup;
|
||||
std::string twin_overruled_reason;
|
||||
std::optional<TwinSubgroupChoice> twin_choice;
|
||||
std::string twin_choice_reason;
|
||||
int twin_choice_group_number = 0; // the adopted group's, when the choice was made
|
||||
TimingMark search_mark(logger, "space-group search");
|
||||
if (search_space_group) {
|
||||
SearchSpaceGroupOptions sg_opts;
|
||||
@@ -1789,6 +1901,20 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
"group already found"
|
||||
: " - keeping the group already found; " + s2.refused_reason)));
|
||||
if (higher) {
|
||||
// The group of the lattice in hand, carried into the new setting: the subgroup of
|
||||
// the twin-law merge, should this promotion stand on twin-like data or over a
|
||||
// refusal by a twin gate (see twin_choice).
|
||||
if (sg_search.best_space_group) {
|
||||
gemmi::Mat33 q = reindex;
|
||||
if (commit_reindex)
|
||||
q = reindex.multiply(commit_reindex->inverse());
|
||||
twin_metric_subgroup = GroupInReindexedSetting(*sg_search.best_space_group, q,
|
||||
cand.centering);
|
||||
if (sg_search.refused_by_twin_gate) {
|
||||
twin_overruled_subgroup = twin_metric_subgroup;
|
||||
twin_overruled_reason = sg_search.refused_reason;
|
||||
}
|
||||
}
|
||||
sg_search = s2;
|
||||
// Leave the candidate it displaced among the alternatives, so the reported
|
||||
// "or ..." list stays the set of groups the data cannot separate.
|
||||
@@ -2476,6 +2602,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
sg_search.refused_point_group_hm, sg_search.refused_reason, hi_sg->xhm());
|
||||
logger.Info("{}", msg);
|
||||
stats_text << " " << msg << "\n\n";
|
||||
if (sg_search.refused_by_twin_gate) {
|
||||
twin_overruled_subgroup = sg;
|
||||
twin_overruled_reason = sg_search.refused_reason;
|
||||
}
|
||||
sg_search = hi_search;
|
||||
if (hi_search.best_space_group->number != hi_sg->number) {
|
||||
sg_search.alternatives.push_back(*hi_search.best_space_group);
|
||||
@@ -2537,6 +2667,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
measured, hi_sg->xhm());
|
||||
logger.Info("{}", msg);
|
||||
stats_text << " " << msg << "\n\n";
|
||||
if (sg_search.refused_by_twin_gate) {
|
||||
twin_overruled_subgroup = sg;
|
||||
twin_overruled_reason = sg_search.refused_reason;
|
||||
}
|
||||
sg_search = hi_search;
|
||||
// Leave the candidate it displaced among the alternatives, so the
|
||||
// reported "or ..." list stays the set of groups the data cannot
|
||||
@@ -2577,6 +2711,28 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
result.space_group.value_or(gemmi::get_spacegroup_p1()));
|
||||
}
|
||||
result.space_group_search = sg_search;
|
||||
|
||||
// Was a twin law possibly absorbed? Where a twin gate refused the adopted group and was
|
||||
// overruled, or where a group above P1 was adopted on data that read twin-like before the
|
||||
// search (the pre-promotion L-test), the merge in the subgroup is written beside the answer
|
||||
// too, with the law - so a refinement program can take the twin hypothesis without a re-run.
|
||||
// The answer itself is not touched by any of this.
|
||||
const bool pre_twin_like = result.pre_promotion_twinning && result.pre_promotion_twinning->twinning_suspected;
|
||||
if (!geometry_prepass && result.space_group && sg_search.point_group_order > 1
|
||||
&& (twin_overruled_subgroup || pre_twin_like)) {
|
||||
twin_choice = ChooseTwinSubgroup(*result.space_group, sg_search,
|
||||
twin_overruled_subgroup ? twin_overruled_subgroup
|
||||
: twin_metric_subgroup);
|
||||
twin_choice_group_number = result.space_group->number;
|
||||
twin_choice_reason = twin_overruled_subgroup
|
||||
? fmt::format("a twin gate refused it ({}) and was overruled", twin_overruled_reason)
|
||||
: fmt::format("the merge read twin-like before the space-group search ({})",
|
||||
TwinningVerdictLine(*result.pre_promotion_twinning));
|
||||
if (twin_choice)
|
||||
logger.Info("Twin hypothesis: {} was adopted, but {} - the merge in {} is written too, "
|
||||
"with twin law {}", result.space_group->xhm(), twin_choice_reason,
|
||||
twin_choice->subgroup.xhm(), twin_choice->law.as_hkl().triplet());
|
||||
}
|
||||
} else {
|
||||
// A space group was fixed by the user; surface it so the viewer/CLI can still show it.
|
||||
result.space_group = experiment_.GetGemmiSpaceGroup();
|
||||
@@ -2701,6 +2857,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
if (!(choice.cob == gemmi::Op::identity()))
|
||||
reseat_integrated(choice.cob);
|
||||
relabel_group(choice.cob, *moved);
|
||||
// The engine is about to be remade in the reference's frame, and the twin-law merge is
|
||||
// made from it: its subgroup moves with the data.
|
||||
if (twin_choice && !MoveTwinSubgroupChoice(*twin_choice, choice.cob))
|
||||
twin_choice.reset();
|
||||
determined_to_written = determined_to_written.combine(hkl);
|
||||
result.setting_operator = IndexTriplet(determined_to_written);
|
||||
rsm.emplace(experiment_, indexer->GetIntegrationOutcome(), result.consensus_cell,
|
||||
@@ -2776,6 +2936,24 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
// of its own rather than the experiment's, and writes no per-frame scale back onto the outcomes;
|
||||
// and nothing up to take_ledger_p1 calls the engine, changes the outcomes it was ingested from,
|
||||
// or changes the experiment. Its log lines are held and printed where it is taken.
|
||||
// The twin-law merge (see twin_choice), from the same engine as the answer's, to the resolution the
|
||||
// answer was cut at. Like the ledger's below, it merges the engine's own copy of the observations in
|
||||
// a group of its own and writes no per-frame scale back, so nothing the answer is made of sees it.
|
||||
std::optional<RotationScaleMerge::Result> twin_merge;
|
||||
if (twin_choice && rsm && result.consensus_cell && write_files && config_.write_merged
|
||||
&& !geometry_prepass && !superseded) {
|
||||
TimingMark mark(logger, "twin-law merge");
|
||||
phase("Merging in " + twin_choice->subgroup.short_name() + " (twin hypothesis)");
|
||||
rsm->SetWriteBackPerFrameScale(false);
|
||||
rsm->SetExportScaledFulls(false);
|
||||
rsm->SetFrenchWilson(false);
|
||||
const auto manual_d_min = experiment_.GetScalingSettings().GetHighResolutionLimit_A();
|
||||
rsm->SetDMinLimit(sm.statistics.overall.d_min);
|
||||
twin_merge = rsm->Run(/*for_search=*/false, /*full_stats=*/true,
|
||||
/*measure_cc_before_corrections=*/false, &twin_choice->subgroup);
|
||||
rsm->SetDMinLimit(manual_d_min);
|
||||
rsm->SetWriteBackPerFrameScale(true);
|
||||
}
|
||||
std::optional<RotationScaleMerge::Result> ledger_p1;
|
||||
Logger ledger_log = Logger::Buffered();
|
||||
std::future<RotationScaleMerge::Result> ledger_ahead;
|
||||
@@ -3271,6 +3449,109 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
// measurements, so the statistics computed above are unaffected; what changes is that the file,
|
||||
// the R-factors and the maps then all describe one indexing instead of two.
|
||||
std::future<void> placed_model_file;
|
||||
|
||||
// The twin-law merge made ready to be written: on the axes the answer is written on (every
|
||||
// relabelling since it was merged), with the answer's own free set - read off the answer's merge
|
||||
// by the adopted group's asymmetric unit, which both twin mates of a pair fall in - then in the
|
||||
// subgroup's standard setting, with its French-Wilson amplitudes and the law's fraction. Made once
|
||||
// the model, which can relabel the answer, is done with it; and before the model is asked about
|
||||
// the hypothesis itself (below).
|
||||
struct TwinFile {
|
||||
std::vector<MergedReflection> merged;
|
||||
UnitCell cell;
|
||||
gemmi::SpaceGroup space_group;
|
||||
gemmi::Op law;
|
||||
TwinLawFraction fraction;
|
||||
};
|
||||
std::optional<TwinFile> twin_file;
|
||||
const auto prepare_twin_file = [&] {
|
||||
if (twin_file || !twin_merge || !twin_choice)
|
||||
return;
|
||||
const bool friedel = experiment_.GetScalingSettings().GetMergeFriedel();
|
||||
const gemmi::SpaceGroup adopted = experiment_.GetSpaceGroupOrP1();
|
||||
TwinSubgroupChoice c = *twin_choice;
|
||||
std::vector<MergedReflection> merged = twin_merge->merged;
|
||||
if (!(merge_to_written == gemmi::Op::identity())) {
|
||||
if (!MoveTwinSubgroupChoice(c, merge_to_written.inverse())) {
|
||||
logger.Warning("Twin hypothesis: {} has no setting on the axes the answer is written on; "
|
||||
"its merge is not written", twin_choice->subgroup.xhm());
|
||||
return;
|
||||
}
|
||||
merged = ReindexMergedIntoAsu(merged, merge_to_written, c.subgroup, friedel);
|
||||
}
|
||||
// A subgroup of the group written - which the model can relabel to its enantiomorph, a change
|
||||
// of label only, so the subgroup's label follows it.
|
||||
const auto rotations_in = [](const gemmi::SpaceGroup &sub, const gemmi::SpaceGroup &group) {
|
||||
const gemmi::GroupOps g = group.operations();
|
||||
for (const auto &op : sub.operations().sym_ops)
|
||||
if (std::none_of(g.sym_ops.begin(), g.sym_ops.end(),
|
||||
[&](const gemmi::Op &o) { return o.rot == op.rot; }))
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
if (adopted.number != twin_choice_group_number && c.subgroup.is_enantiomorphic()) {
|
||||
gemmi::GroupOps e = c.subgroup.operations();
|
||||
e.change_basis_forward(c.subgroup.change_of_hand_op());
|
||||
if (const gemmi::SpaceGroup *other = gemmi::find_spacegroup_by_ops(e))
|
||||
c.subgroup = *other;
|
||||
}
|
||||
if (!rotations_in(c.subgroup, adopted)) {
|
||||
logger.Warning("Twin hypothesis: {} is not a subgroup of {} as written; its merge is not written",
|
||||
c.subgroup.xhm(), adopted.xhm());
|
||||
return;
|
||||
}
|
||||
AssignRfreeFlags(merged, c.subgroup, experiment_.GetScalingSettings().GetRfreeFraction(), 500,
|
||||
result.consensus_cell, config_.nthreads);
|
||||
ApplyReferenceFreeFlags(merged, adopted, sm.merged);
|
||||
const TwinLawFraction fraction = EstimateTwinLawFraction(merged, c.subgroup, c.law, friedel);
|
||||
UnitCell cell = *result.consensus_cell;
|
||||
// The subgroup's reference setting first: a subgroup of a centred group can be a primitive
|
||||
// group written on a multiple of its cell - C 1 1 2_1 is P 1 2_1 1 on twice the volume - which
|
||||
// no unimodular relabelling reaches. The reflections the centring extinguished have no index on
|
||||
// the primitive cell and are dropped; the rest move exactly.
|
||||
if (!(c.subgroup.basisop() == gemmi::Op::identity())) {
|
||||
const gemmi::Op to_reference = c.subgroup.basisop().inverse();
|
||||
const gemmi::Op m = HklOperator(to_reference);
|
||||
const gemmi::SpaceGroup before = c.subgroup;
|
||||
if (MoveTwinSubgroupChoice(c, to_reference)) {
|
||||
std::erase_if(merged, [&](const MergedReflection &r) {
|
||||
const auto h = m.apply_to_hkl_without_division({{r.h, r.k, r.l}});
|
||||
return h[0] % gemmi::Op::DEN != 0 || h[1] % gemmi::Op::DEN != 0 || h[2] % gemmi::Op::DEN != 0;
|
||||
});
|
||||
merged = ReindexMergedIntoAsu(merged, m, c.subgroup, friedel);
|
||||
cell = CellInBasis(cell, to_reference);
|
||||
} else {
|
||||
c.subgroup = before;
|
||||
}
|
||||
}
|
||||
const gemmi::Op standard = ChooseOutputSetting(cell, c.subgroup);
|
||||
if (!(standard == gemmi::Op::identity())) {
|
||||
const gemmi::SpaceGroup before = c.subgroup;
|
||||
if (MoveTwinSubgroupChoice(c, standard)) {
|
||||
merged = ReindexMergedIntoAsu(merged, HklOperator(standard), c.subgroup, friedel);
|
||||
cell = CellInBasis(cell, standard);
|
||||
} else {
|
||||
c.subgroup = before;
|
||||
}
|
||||
}
|
||||
FrenchWilsonOptions fw_opts;
|
||||
fw_opts.num_threads = config_.nthreads;
|
||||
ApplyFrenchWilson(merged, c.subgroup, fw_opts);
|
||||
twin_file = TwinFile{std::move(merged), cell, c.subgroup, c.law, fraction};
|
||||
|
||||
auto &t = result.twin_subgroup_merge.emplace();
|
||||
t.reason = twin_choice_reason;
|
||||
t.adopted_space_group = adopted.xhm();
|
||||
t.space_group = c.subgroup.xhm();
|
||||
t.file_prefix = config_.output_prefix + "_twin_" + c.subgroup.short_name();
|
||||
t.twin_law = c.law.as_hkl().triplet();
|
||||
t.twin_fraction = fraction.fraction;
|
||||
t.twin_fraction_pairs = fraction.pairs;
|
||||
t.other_subgroups = c.others;
|
||||
logger.Info("Twin hypothesis: {} in {}, twin law {} at a fraction of at least {:.2f} ({} pairs) -> {}.mtz/.cif",
|
||||
adopted.xhm(), c.subgroup.xhm(), t.twin_law, fraction.fraction, fraction.pairs,
|
||||
t.file_prefix);
|
||||
};
|
||||
if (result.consensus_cell && write_files && !config_.model_path.empty() && !geometry_prepass
|
||||
&& !superseded) {
|
||||
phase("Validating against model");
|
||||
@@ -3464,6 +3745,7 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
WritePlacedModel(*placed, cell, sg, prefix, logger);
|
||||
});
|
||||
}
|
||||
prepare_twin_file();
|
||||
|
||||
// The unmerged MTZ (written with the other output files, see there) is built from here on,
|
||||
// beside the reflection files: the indexing and the group it is written in are final once the
|
||||
@@ -3508,6 +3790,25 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
WriteReflections(sm.merged, *result.consensus_cell, experiment_, sm.statistics,
|
||||
em_report, result.twinning, config_.provenance, config_.output_prefix,
|
||||
static_cast<size_t>(std::max(1, config_.nthreads)), &sm.scaled_fulls);
|
||||
// The twin hypothesis beside it (see prepare_twin_file): the reflection files only, with the
|
||||
// law and its fraction in the mmCIF's _pdbx_reflns_twin.
|
||||
if (twin_file) {
|
||||
DiffractionExperiment twin_x = experiment_;
|
||||
twin_x.SetSpaceGroup(twin_file->space_group);
|
||||
TwinningAnalysisResult law;
|
||||
law.twin_law_operator = twin_file->law.as_hkl().triplet();
|
||||
law.twin_law_fraction = std::isfinite(twin_file->fraction.fraction) ? twin_file->fraction.fraction : 0.5;
|
||||
const ErrorModelReport twin_em{
|
||||
twin_merge->isa > 0 && twin_merge->isa_resolved ? fmt::format("{:.2f}", twin_merge->isa) : "?",
|
||||
std::string(), twin_merge->error_model_a > 0 ? fmt::format("{:.3f}", twin_merge->error_model_a)
|
||||
: std::string(),
|
||||
twin_merge->error_model_b > 0 ? fmt::format("{:.4e}", twin_merge->error_model_b)
|
||||
: std::string()};
|
||||
const std::string prefix = result.twin_subgroup_merge->file_prefix;
|
||||
WriteMtzReflections(twin_file->merged, twin_file->cell, twin_x, config_.provenance, prefix + ".mtz");
|
||||
WriteMmcifReflections(twin_file->merged, twin_file->cell, twin_x, twin_merge->statistics, twin_em,
|
||||
law, config_.provenance, prefix + ".cif", static_cast<size_t>(std::max(1, config_.nthreads)));
|
||||
}
|
||||
writing_mark.Stop();
|
||||
|
||||
// FINALIST LEDGER (--finalist-ledger), report-only and deliberately behind a flag: these
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
@@ -244,7 +246,7 @@ TEST_CASE("A twin law is possible exactly where the lattice has a rotation the g
|
||||
// reported as such, and not as "needs a twin law". Where the lattice does admit one, it is a twin.
|
||||
TEST_CASE("Twin-like statistics where no twin law is possible", "[twinning]") {
|
||||
const gemmi::SpaceGroup *sg = gemmi::find_spacegroup_by_name("P 2 2 2");
|
||||
const auto merged = MergedIn(Tetragonal("P 2 2 2", 0.12), "P 2 2 2");
|
||||
const auto merged = MergedIn(Tetragonal("P 2 2 2", 0.15), "P 2 2 2");
|
||||
const gemmi::UnitCell orthorhombic(47, 52, 63, 90, 90, 90);
|
||||
const gemmi::UnitCell tetragonal(47, 47, 63, 90, 90, 90);
|
||||
|
||||
@@ -448,3 +450,36 @@ TEST_CASE("L-test under a merge tells a false operator from a real one", "[twinn
|
||||
CHECK(perfect_twin.mean_abs_l == Catch::Approx(0.375).margin(0.02));
|
||||
CHECK(perfect_twin.mean_abs_l_merged == Catch::Approx(perfect_twin.mean_abs_l).margin(0.01));
|
||||
}
|
||||
|
||||
// The subgroups a twin-law merge can be made in: index 2, translations kept, and a two-fold of the
|
||||
// group outside them to be the law. A four-fold over its two-fold offers no two-fold, so no law.
|
||||
TEST_CASE("Index-2 subgroups with a two-fold twin law", "[twinning]") {
|
||||
const auto names = [](const char *group) {
|
||||
std::vector<std::string> out;
|
||||
for (const auto &t : IndexTwoTwinSubgroups(gemmi::get_spacegroup_by_name(group))) {
|
||||
CHECK_FALSE(t.laws.empty());
|
||||
out.push_back(t.subgroup.xhm());
|
||||
}
|
||||
std::sort(out.begin(), out.end());
|
||||
return out;
|
||||
};
|
||||
CHECK(names("P 2 2 2") == std::vector<std::string>{"P 1 1 2", "P 1 2 1", "P 2 1 1"});
|
||||
CHECK(names("P 21 21 21") == std::vector<std::string>{"P 1 1 21", "P 1 21 1", "P 21 1 1"});
|
||||
CHECK(names("P 4").empty());
|
||||
const auto p422 = names("P 4 2 2");
|
||||
CHECK(std::find(p422.begin(), p422.end(), "P 4") != p422.end());
|
||||
CHECK(std::find(p422.begin(), p422.end(), "P 2 2 2") != p422.end());
|
||||
CHECK(names("C 2 2 21").size() == 3);
|
||||
}
|
||||
|
||||
// Yeates' H on the pairs a law relates, in the group the law is not part of, reads the twin fraction.
|
||||
TEST_CASE("Twin fraction of a law from its pairs' disagreement", "[twinning]") {
|
||||
const gemmi::SpaceGroup &p4 = gemmi::get_spacegroup_by_name("P 4");
|
||||
const gemmi::Op law = jfjoch_test::TwinLaw(p4, gemmi::get_spacegroup_by_name("P 4 2 2"));
|
||||
for (double alpha : {0.0, 0.2, 0.4}) {
|
||||
CAPTURE(alpha);
|
||||
const auto f = EstimateTwinLawFraction(MergedIn(Tetragonal("P 4", alpha), "P 4"), p4, law);
|
||||
CHECK(f.pairs > 1000);
|
||||
CHECK(f.fraction == Catch::Approx(alpha).margin(0.03));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user