From ae444437f49230f8cce74e3b8e89d8e3415ece8f Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Fri, 25 Sep 2026 15:40:25 +0200 Subject: [PATCH] rugnux: accept a PDB structure-factor mmCIF as the -z reference -z (now also --reference; --reference-mtz still works) takes an SF-mmCIF (e.g. a deposited -sf.cif, gzipped or not) as well as an MTZ. The format is recognised by content: a file starting with "MTZ " is an MTZ, anything else is parsed as CIF. The first merged reflection block with the requested column (or, by default, one the auto choice accepts) is converted to a gemmi::Mtz in memory with GEMMI's CifToMtz and then read by the unchanged MTZ loader, so the in-memory reference is exactly what the MTZ path yields. Unmerged (_diffrn_refln) and anomalous-only blocks are passed over; the log names the block used. The R-free set comes from _refln.status (f -> FreeR_flag 0, o -> 1: the CCP4 convention the loader already reads) and is preferred to _refln.pdbx_r_free_flag, whose convention varies by program; a status column with no 'f' is ignored and pdbx_r_free_flag is used instead. Checked on two open-arm sets in the deposited setting (one with F_meas_au only, one with intensity_meas): reference loaded with the deposited cell and group, the inherited free set agrees with the deposited status 'f' on every common reflection, and the merge correlates at CC 0.99 with the deposition. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C --- docs/CHANGELOG.md | 1 + docs/CPU_DATA_ANALYSIS_INTEGRATION.md | 4 +- docs/RUGNUX_ADVANCED.md | 14 ++- image_analysis/LoadFCalcFromMtz.cpp | 76 ++++++++++++- image_analysis/LoadFCalcFromMtz.h | 6 +- rugnux/rugnux_cli.cpp | 11 +- tests/CMakeLists.txt | 3 +- tests/LoadReferenceSfCifTest.cpp | 153 ++++++++++++++++++++++++++ 8 files changed, 251 insertions(+), 17 deletions(-) create mode 100644 tests/LoadReferenceSfCifTest.cpp diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8bbdb045c..ac267c892 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -22,6 +22,7 @@ * Rugnux writes its files in the standard setting, as XDS and POINTLESS do (e.g. P 21 21 2 with the pure two-fold on c rather than P 2 21 21), or in the setting of a reference MTZ, of a model that fits, of the cell given with `-C` or of a non-standard `-S` symbol; `SETTING_OPERATOR=` and `SETTING_SOURCE=` report it. * Rugnux puts the merge onto a reference MTZ's axes before inheriting its free-R flags, and does not inherit them where the merge does not match the reference (`REFERENCE_MISMATCH`); `REFERENCE_OPERATOR=`, `REFERENCE_CC=` and `REFERENCE_MATCHED_FRACTION=` report the match. * Rugnux places a space group given with `-S` on the axes its systematic absences name, so `-S 18` on a cell whose pure two-fold is not its longest axis no longer merges with the screw absences on the wrong rows. +* `rugnux -z` also takes a PDB structure-factor mmCIF (`-sf.cif`, gzipped or not) as the reference, with its R-free set; `--reference` is a new name for `--reference-mtz`. * `rugnux --polarization` is documented as the polarization degree (XDS `FRACTION_OF_POLARIZATION` = (1 + p)/2); the default 0.99 suits undulators. ### 1.0.0-rc.172 diff --git a/docs/CPU_DATA_ANALYSIS_INTEGRATION.md b/docs/CPU_DATA_ANALYSIS_INTEGRATION.md index fd6d4508e..a51501b97 100644 --- a/docs/CPU_DATA_ANALYSIS_INTEGRATION.md +++ b/docs/CPU_DATA_ANALYSIS_INTEGRATION.md @@ -409,7 +409,7 @@ A fraction of the unique reflections (`rfree_fraction`, default 0.05) is flagged On small data, where `rfree_fraction` (default 0.05) would give too few test reflections for a statistically stable R-free (Brünger's ~500–2000 rule), the fraction is **floored** so at least ~500 distinct reflections are free — capped at 10 % so a large test set never steals working data. For ordinary data this floor is inactive and the fraction stays flat at `rfree_fraction`, preserving the cross-dataset-identical property above; it only lifts the fraction on genuinely small datasets, where per-dataset R-free stability outweighs cross-dataset identity (and a shared reference set is the way to keep exact identity there). -When a reference MTZ (`--reference-mtz`) carries a `FreeR_flag` column, its test set is **imported** instead: every merged reflection whose Laue-ASU index matches the reference takes the reference's flag (reflections absent from the reference keep the hash flag). The match is made in the reference's frame — on rotation data the merge is first put onto the reference's axes, choosing among every description of the lattice on them (and every alternative indexing) by the intensity correlation with the reference — and only where the merge then matches it: an intensity CC of at least 0.5 over at least half of the merged reflections in the reference's resolution range. Below that the reference is not the same crystal form on the same axes, its flags would land on unrelated reflections, and they are not imported (`REFERENCE_MISMATCH`). This lets a whole fragment-screening campaign inherit one shared free set from the apo/reference dataset. The CCP4/refmac convention (test set = flag 0, including the historical 0–19 form) is assumed, with the complement taken automatically if flag 0 would be the majority (a phenix-style file where 1 marks free). +When a reference (`--reference`: an MTZ, or a PDB structure-factor mmCIF, which is converted to one with `_refln.status` `f`/`o` becoming flag 0/1) carries a `FreeR_flag` column, its test set is **imported** instead: every merged reflection whose Laue-ASU index matches the reference takes the reference's flag (reflections absent from the reference keep the hash flag). The match is made in the reference's frame — on rotation data the merge is first put onto the reference's axes, choosing among every description of the lattice on them (and every alternative indexing) by the intensity correlation with the reference — and only where the merge then matches it: an intensity CC of at least 0.5 over at least half of the merged reflections in the reference's resolution range. Below that the reference is not the same crystal form on the same axes, its flags would land on unrelated reflections, and they are not imported (`REFERENCE_MISMATCH`). This lets a whole fragment-screening campaign inherit one shared free set from the apo/reference dataset. The CCP4/refmac convention (test set = flag 0, including the historical 0–19 form) is assumed, with the complement taken automatically if flag 0 would be the majority (a phenix-style file where 1 marks free). ### 10.8 French–Wilson amplitudes @@ -433,7 +433,7 @@ Amplitudes are written as MTZ `F`/`SIGF`, mmCIF `_refln.F_meas_au`/`F_meas_sigma ### 10.9 Reference data: fixing the space group and resolving the indexing ambiguity -A reference dataset (`--reference-mtz`) supplies known intensities for the same crystal form, and is used in two ways. +A reference dataset (`--reference`, MTZ or SF-mmCIF) supplies known intensities for the same crystal form, and is used in two ways. **Fix the space group and cell.** Unless overridden on the command line (`-S` for the space group, `-C` for the cell), the reference's space group is adopted and its cell is used as the soft reference cell — indexing may still drift the cell within tolerance, so a small mismatch between reference and data is absorbed rather than rejected. This applies to both stills and rotation data. diff --git a/docs/RUGNUX_ADVANCED.md b/docs/RUGNUX_ADVANCED.md index 5cc0db053..2283b2b54 100644 --- a/docs/RUGNUX_ADVANCED.md +++ b/docs/RUGNUX_ADVANCED.md @@ -10,11 +10,15 @@ validation, re-merging without re-integration, and the full option tables. ## Reference data and the indexing ambiguity -### What a reference MTZ does (`-z`) +### What a reference does (`-z`) `-z reference.mtz` supplies **known intensities of the same crystal form** — a previously merged -dataset, or `F-model` amplitudes computed from a structure. It is read once, before processing -starts, and used for four things: +dataset, or `F-model` amplitudes computed from a structure. The reference can equally be a PDB +structure-factor file (`-z 1abc-sf.cif`, SF-mmCIF), gzipped or not; the format is taken from the +file's content. From an mmCIF the first merged reflection block with a usable column is read (the log +names it), its columns under the MTZ labels `gemmi cif2mtz` gives them (`IMEAN`, `FP`, `FC`, …), and +its R-free set from `_refln.status` (`f` free, `o` working), or from `_refln.pdbx_r_free_flag` where +the status marks no test set. It is read once, before processing starts, and used for four things: - **It fixes the space group and the unit cell** the run works in, unless `-S` / `-C` override them. The cell is a *soft* reference: indexing may still drift within tolerance, so a small mismatch @@ -373,8 +377,8 @@ Scaling and merging: | `--search-min-zeta ` | De-novo space-group search only: also search a merge of just the observations whose Lorentz geometry \|ζ\| reaches this, and report both answers (default: 0.85 for rotation, 0 = single search). Reflections crossing the Ewald sphere near-tangentially are measured worst and can make a real symmetry operator look like a twin law. Where the two searches disagree, the merge of all the observations decides — as it always has for the systematic absences | | `--mosaicity ` | Diagnostic: fix the scaling mosaicity (°) instead of using the per-image seed | | `--scaling-iterations ` | Cap on the per-frame scaling iterations; the loop stops earlier once the scales settle, and a merge that hits the cap is flagged `SCALING_NOT_CONVERGED` (default: 100) | -| `-z, --reference-mtz ` | Reference MTZ of the same crystal form: fixes the space group, its setting and the cell, resolves the [indexing ambiguity](#the-indexing-ambiguity), hands over the R-free set and reports CCref. Not a scale anchor | -| `--reference-column