Merged MTZ: multiplicity columns N, N(+) and N(-)
The merged MTZ carries the number of observations merged into each value: N (type I) after SIGIMEAN, N(+)/N(-) after SIGI(-) where the anomalous columns are written - the labels and the integer type dials.merge gives them. The merged reflection carries the counts from the half-set accumulators (rotation and on-the-fly merges) and per hand from the anomalous table; the two places that swap the Bijvoet hands on a reindexing swap the counts with them. Centrics, which have no anomalous split, carry N(+) = N(-) = 0. Every existing column keeps its label, type and value. The synthetic merged generator carries the multiplicity it simulates and the writer tests check the new columns; the MTZ column lists in the docs are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQrPqZ52Tp6rzzZGxf3 (cherry picked from commit 01a24d7b7b37f6263a950cc56af069448922df48)
This commit is contained in:
1 parent
84e1ed78b4
commit
441f020a2b
12 files changed
+49
-23
No files matched your search
@@ -112,6 +112,10 @@ struct MergedReflection {
|
||||
// written - the ring contaminates it, it does not make it absent - and this only marks it so
|
||||
// a consumer that must not read the ring as crystal signal can leave it out.
|
||||
bool on_ice_ring = false;
|
||||
// Observations merged into I, and into each Bijvoet hand of it (the MTZ N, N(+), N(-) columns).
|
||||
int32_t n_obs = 0;
|
||||
int32_t n_plus = 0;
|
||||
int32_t n_minus = 0;
|
||||
bool rfree_flag = false;
|
||||
float F = NAN; // French-Wilson amplitude |F| (filled by ApplyFrenchWilson at end of merge)
|
||||
float sigmaF = NAN; // its sigma
|
||||
|
||||
@@ -124,7 +124,7 @@ Everything lands in `<prefix>_report.txt` section 4 (`ANISOTROPY_*` keys), in th
|
||||
- **Space-group symmetry** beyond centering absences is not enforced during prediction/integration unless the space group is supplied and used downstream.
|
||||
- **Resolution masking** is controllable, and so is every stage of ice-ring handling (§3.3, §10.10). None of it runs unless the crystal is measured to have ice, because the fixed bands are a fixed cost in unique reflections whether it does or not.
|
||||
- **Rotation vs still modes** differ substantially in prediction and scaling: partiality is angle-driven in rotation data, while stills are predicted within an excitation-error window that follows the run's rocking curve (§8.2) and get their partiality from the default-on per-crystal tilt post-refinement (§10.2) — or unit partiality with `--simple-stills`.
|
||||
- **Amplitudes and intensities.** The merged output carries both intensities (mmCIF `intensity_meas`, MTZ `IMEAN`/`SIGIMEAN`) and French–Wilson amplitudes (mmCIF `F_meas_au`, MTZ `F`/`SIGF`; §10.8), so a downstream program can refine against either.
|
||||
- **Amplitudes and intensities.** The merged output carries both intensities (mmCIF `intensity_meas`, MTZ `IMEAN`/`SIGIMEAN`, with the multiplicity in `N`) and French–Wilson amplitudes (mmCIF `F_meas_au`, MTZ `F`/`SIGF`; §10.8), so a downstream program can refine against either.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -65,11 +65,12 @@ the `.hkl` worth knowing before using it:
|
||||
column types CCP4 programs dispatch on:
|
||||
|
||||
```
|
||||
H K L IMEAN SIGIMEAN I(+) SIGI(+) I(-) SIGI(-) F SIGF F(+) SIGF(+) F(-) SIGF(-) FreeR_flag
|
||||
H H H J Q K M K M F Q G L G L I
|
||||
H K L IMEAN SIGIMEAN N I(+) SIGI(+) I(-) SIGI(-) N(+) N(-) F SIGF F(+) SIGF(+) F(-) SIGF(-) FreeR_flag
|
||||
H H H J Q I K M K M I I F Q G L G L I
|
||||
```
|
||||
|
||||
`F` is the French–Wilson amplitude. The header carries the determined space group, the refined cell
|
||||
`F` is the French–Wilson amplitude; `N` is the number of observations merged into `IMEAN`, and
|
||||
`N(+)`/`N(-)` into each Bijvoet hand (the multiplicity columns `dials.merge` writes). The header carries the determined space group, the refined cell
|
||||
and the wavelength, on a dataset of its own behind the reserved `HKL_base`, which is where the MTZ
|
||||
format puts them. `<prefix>_unmerged.mtz` reads 1.54187 Å (CCP4's Cu Kα default) under `mtzinfo`
|
||||
and is not wrong: its columns sit on `HKL_base` deliberately, as POINTLESS expects, and the
|
||||
|
||||
@@ -304,8 +304,8 @@ Absorption is corrected only by the empirical surface a rotation run fits and ke
|
||||
- Merging is **on by default** (`--no-merge` disables it). The merged reflections are written in
|
||||
**three** formats — each has its uses downstream:
|
||||
- `<prefix>.mtz` — CCP4 MTZ for the CCP4 / phenix reflection tools. The columns are
|
||||
`H K L IMEAN SIGIMEAN I(+) SIGI(+) I(-) SIGI(-) F SIGF F(+) SIGF(+) F(-) SIGF(-) FreeR_flag`
|
||||
(`F` is the French–Wilson amplitude); the anomalous columns are present whenever any reflection
|
||||
`H K L IMEAN SIGIMEAN N I(+) SIGI(+) I(-) SIGI(-) N(+) N(-) F SIGF F(+) SIGF(+) F(-) SIGF(-) FreeR_flag`
|
||||
(`F` is the French–Wilson amplitude, `N` the number of observations merged into each value); the anomalous columns are present whenever any reflection
|
||||
carries a Bijvoet split — a rotation run always does, a stills run only with `-A`.
|
||||
- `<prefix>.cif` — mmCIF, for deposition and as the self-describing native format (also carries the
|
||||
merging statistics, ISa, twinning and radiation-damage indicators).
|
||||
|
||||
@@ -205,6 +205,7 @@ struct MergedOutRow {
|
||||
int h = 0, k = 0, l = 0;
|
||||
float Imean = NAN, sImean = NAN, Ip = NAN, sIp = NAN, Im = NAN, sIm = NAN;
|
||||
float Fmean = NAN, sFmean = NAN, Fp = NAN, sFp = NAN, Fm = NAN, sFm = NAN;
|
||||
int n = 0, np = 0, nm = 0; // observations merged into Imean, Ip and Im
|
||||
// The value written into FreeR_flag: 0 for the TEST set, 1 for the working set. That is the CCP4
|
||||
// convention the column NAME belongs to - CCP4's own freerflag writes 0..19 with 0 as the ~5%
|
||||
// test bin, and REFMAC's default FREE 0 reads it that way, so the opposite (phenix/CNS) numbering
|
||||
@@ -233,7 +234,7 @@ std::vector<MergedOutRow> BuildMergedRows(const std::vector<MergedReflection> &r
|
||||
for (const auto& r : reflections)
|
||||
out_rows.push_back({r.h, r.k, r.l, r.I, r.sigma, r.I_plus, r.sigma_plus, r.I_minus,
|
||||
r.sigma_minus, r.F, r.sigmaF, r.F_plus, r.sigmaF_plus, r.F_minus,
|
||||
r.sigmaF_minus, r.rfree_flag ? 0 : 1});
|
||||
r.sigmaF_minus, r.n_obs, r.n_plus, r.n_minus, r.rfree_flag ? 0 : 1});
|
||||
} else {
|
||||
// Anomalous: group the two mates by their (shared) Friedel-merged ASU representative, then form
|
||||
// IMEAN / F as their inverse-variance Friedel mean. A single generator gives both the group key
|
||||
@@ -243,6 +244,7 @@ std::vector<MergedOutRow> BuildMergedRows(const std::vector<MergedReflection> &r
|
||||
int h = 0, k = 0, l = 0;
|
||||
float Ip = NAN, sIp = NAN, Im = NAN, sIm = NAN;
|
||||
float Fp = NAN, sFp = NAN, Fm = NAN, sFm = NAN;
|
||||
int np = 0, nm = 0;
|
||||
int rfree = 1;
|
||||
};
|
||||
std::map<std::tuple<int, int, int>, AnomRow> rows;
|
||||
@@ -251,8 +253,8 @@ std::vector<MergedOutRow> BuildMergedRows(const std::vector<MergedReflection> &r
|
||||
AnomRow& row = rows[{key.h, key.k, key.l}];
|
||||
row.h = key.h; row.k = key.k; row.l = key.l;
|
||||
row.rfree = r.rfree_flag ? 0 : 1;
|
||||
if (key.plus) { row.Ip = r.I; row.sIp = r.sigma; row.Fp = r.F; row.sFp = r.sigmaF; }
|
||||
else { row.Im = r.I; row.sIm = r.sigma; row.Fm = r.F; row.sFm = r.sigmaF; }
|
||||
if (key.plus) { row.Ip = r.I; row.sIp = r.sigma; row.Fp = r.F; row.sFp = r.sigmaF; row.np = r.n_obs; }
|
||||
else { row.Im = r.I; row.sIm = r.sigma; row.Fm = r.F; row.sFm = r.sigmaF; row.nm = r.n_obs; }
|
||||
}
|
||||
|
||||
// Friedel-mean of the two mates by inverse variance (the single mate, if only one was measured).
|
||||
@@ -275,7 +277,8 @@ std::vector<MergedOutRow> BuildMergedRows(const std::vector<MergedReflection> &r
|
||||
combine(row.Ip, row.sIp, row.Im, row.sIm, i_mean, sig_i_mean);
|
||||
combine(row.Fp, row.sFp, row.Fm, row.sFm, f_mean, sig_f_mean);
|
||||
out_rows.push_back({row.h, row.k, row.l, i_mean, sig_i_mean, row.Ip, row.sIp, row.Im,
|
||||
row.sIm, f_mean, sig_f_mean, row.Fp, row.sFp, row.Fm, row.sFm, row.rfree});
|
||||
row.sIm, f_mean, sig_f_mean, row.Fp, row.sFp, row.Fm, row.sFm,
|
||||
row.np + row.nm, row.np, row.nm, row.rfree});
|
||||
}
|
||||
}
|
||||
return out_rows;
|
||||
@@ -665,13 +668,16 @@ MtzTable MergedMtzTable(const std::vector<MergedReflection> &reflections,
|
||||
{"native", experiment.GetSampleName(), "native", experiment.GetWavelength_A()}};
|
||||
|
||||
// One row per reflection in the CCP4 anomalous layout (IMEAN + I(+)/I(-), and the same split for
|
||||
// the French-Wilson amplitude), which aimless / ctruncate / mtz2sca / ANODE read directly.
|
||||
// the French-Wilson amplitude), which aimless / ctruncate / mtz2sca / ANODE read directly. N is the
|
||||
// number of observations merged into IMEAN and N(+)/N(-) into each hand, the labels and the integer
|
||||
// type dials.merge gives them.
|
||||
bool has_anom = true;
|
||||
const std::vector<MergedOutRow> out_rows = BuildMergedRows(reflections, experiment, has_anom);
|
||||
std::vector<std::pair<const char *, char>> columns{{"H", 'H'}, {"K", 'H'}, {"L", 'H'},
|
||||
{"IMEAN", 'J'}, {"SIGIMEAN", 'Q'}};
|
||||
{"IMEAN", 'J'}, {"SIGIMEAN", 'Q'}, {"N", 'I'}};
|
||||
if (has_anom)
|
||||
columns.insert(columns.end(), {{"I(+)", 'K'}, {"SIGI(+)", 'M'}, {"I(-)", 'K'}, {"SIGI(-)", 'M'}});
|
||||
columns.insert(columns.end(), {{"I(+)", 'K'}, {"SIGI(+)", 'M'}, {"I(-)", 'K'}, {"SIGI(-)", 'M'},
|
||||
{"N(+)", 'I'}, {"N(-)", 'I'}});
|
||||
columns.insert(columns.end(), {{"F", 'F'}, {"SIGF", 'Q'}}); // F: the French-Wilson amplitude
|
||||
if (has_anom)
|
||||
columns.insert(columns.end(), {{"F(+)", 'G'}, {"SIGF(+)", 'L'}, {"F(-)", 'G'}, {"SIGF(-)", 'L'}});
|
||||
@@ -680,9 +686,9 @@ MtzTable MergedMtzTable(const std::vector<MergedReflection> &reflections,
|
||||
m.columns.push_back({label, type, type == 'H' ? 0 : 1, {}});
|
||||
for (const auto &row : out_rows) {
|
||||
std::vector<float> v{static_cast<float>(row.h), static_cast<float>(row.k), static_cast<float>(row.l),
|
||||
row.Imean, row.sImean};
|
||||
row.Imean, row.sImean, static_cast<float>(row.n)};
|
||||
if (has_anom)
|
||||
v.insert(v.end(), {row.Ip, row.sIp, row.Im, row.sIm});
|
||||
v.insert(v.end(), {row.Ip, row.sIp, row.Im, row.sIm, static_cast<float>(row.np), static_cast<float>(row.nm)});
|
||||
v.insert(v.end(), {row.Fmean, row.sFmean});
|
||||
if (has_anom)
|
||||
v.insert(v.end(), {row.Fp, row.sFp, row.Fm, row.sFm});
|
||||
|
||||
@@ -568,7 +568,8 @@ std::vector<MergedReflection> MergeOnTheFly::ExportIntensities() {
|
||||
.I_half = {NAN, NAN},
|
||||
.sigma_half = {NAN, NAN},
|
||||
.d = accum.d,
|
||||
.on_ice_ring = accum.on_ice_ring
|
||||
.on_ice_ring = accum.on_ice_ring,
|
||||
.n_obs = static_cast<int32_t>(accum.n_half[0] + accum.n_half[1])
|
||||
};
|
||||
|
||||
if (accum.exists_half[0] && accum.exists_half[1]) {
|
||||
|
||||
@@ -101,6 +101,7 @@ std::vector<MergedReflection> ReindexMergedIntoAsu(const std::vector<MergedRefle
|
||||
std::swap(r.sigma_plus, r.sigma_minus);
|
||||
std::swap(r.F_plus, r.F_minus);
|
||||
std::swap(r.sigmaF_plus, r.sigmaF_minus);
|
||||
std::swap(r.n_plus, r.n_minus);
|
||||
}
|
||||
const bool at_asu_index = merge_friedel || key.plus;
|
||||
r.h = at_asu_index ? key.h : -key.h;
|
||||
|
||||
@@ -6349,6 +6349,7 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
mr.sigma_half[0] = mr.sigma_half[1] = NAN;
|
||||
mr.d = a.d;
|
||||
mr.on_ice_ring = a.on_ice;
|
||||
mr.n_obs = static_cast<int32_t>(a.nh[0] + a.nh[1]);
|
||||
if (a.nh[0] + a.nh[1] > 0 && a.swh[0] > 0.0 && a.swh[1] > 0.0) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
mr.I_half[i] = static_cast<float>(a.swIh[i] / a.swh[i]);
|
||||
@@ -6662,7 +6663,7 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
// N_uniq. ----
|
||||
sub("statistics");
|
||||
const int n_shells = report_shell_count;
|
||||
struct AnomExport { float Ip = NAN, sIp = NAN, Im = NAN, sIm = NAN; };
|
||||
struct AnomExport { float Ip = NAN, sIp = NAN, Im = NAN, sIm = NAN; int32_t np = 0, nm = 0; };
|
||||
std::unordered_map<uint64_t, AnomExport> anom_export; // filled by the run's own table only
|
||||
auto statistics_over = [&](const std::vector<MergedReflection> &merged, float grid_d_min,
|
||||
float grid_d_max, float d_max_label, double d_floor,
|
||||
@@ -7031,6 +7032,8 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
const double swp = a.sw[0][0] + a.sw[0][1], swm = a.sw[1][0] + a.sw[1][1];
|
||||
const double swIp = a.swI[0][0] + a.swI[0][1], swIm = a.swI[1][0] + a.swI[1][1];
|
||||
AnomExport ex;
|
||||
ex.np = a.nh[0][0] + a.nh[0][1];
|
||||
ex.nm = a.nh[1][0] + a.nh[1][1];
|
||||
if (swp > 0.0) { ex.Ip = static_cast<float>(swIp / swp); ex.sIp = static_cast<float>(1.0 / std::sqrt(swp)); }
|
||||
if (swm > 0.0) { ex.Im = static_cast<float>(swIm / swm); ex.sIm = static_cast<float>(1.0 / std::sqrt(swm)); }
|
||||
if (own_table && (std::isfinite(ex.Ip) || std::isfinite(ex.Im))) anom_export[fkey] = ex;
|
||||
@@ -7275,6 +7278,7 @@ RotationScaleMerge::Result RotationScaleMerge::MergeAndStats(int n_groups, bool
|
||||
if (it == anom_export.end()) continue;
|
||||
r.I_plus = it->second.Ip; r.sigma_plus = it->second.sIp;
|
||||
r.I_minus = it->second.Im; r.sigma_minus = it->second.sIm;
|
||||
r.n_plus = it->second.np; r.n_minus = it->second.nm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4938,6 +4938,7 @@ std::vector<MergedReflection> ExpandToSubgroup(const std::vector<MergedReflectio
|
||||
std::swap(e.sigma_plus, e.sigma_minus);
|
||||
std::swap(e.F_plus, e.F_minus);
|
||||
std::swap(e.sigmaF_plus, e.sigmaF_minus);
|
||||
std::swap(e.n_plus, e.n_minus);
|
||||
}
|
||||
out.push_back(e);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ TEST_CASE("RugnuxResultFiles: rugnux's outputs -> END blocks -> CBOR -> writer,
|
||||
WritePlacedModel(WithJungfraujoch(TestModel(), gemmi::SoftwareItem::Phasing), TEST_CELL,
|
||||
experiment.GetSpaceGroupOrP1(), original, logger);
|
||||
end.placed_model = PlacedModelFromStructure(TestModel(), TEST_CELL, experiment.GetSpaceGroupOrP1().xhm());
|
||||
REQUIRE(end.merged->columns.size() == 16); // with the anomalous columns
|
||||
REQUIRE(end.merged->columns.size() == 19); // with the anomalous columns and the three N
|
||||
CHECK(end.merged->columns[0].values.size() == reflections.size());
|
||||
CHECK(end.placed_model->atom_name.size() == 2 * 3 * 6 + 2);
|
||||
|
||||
@@ -195,9 +195,9 @@ TEST_CASE("RugnuxResultFiles: rugnux's outputs -> END blocks -> CBOR -> writer,
|
||||
CHECK(ReadFile(written + "_model.pdb") == ReadFile(original + "_model.pdb"));
|
||||
|
||||
const gemmi::Mtz mtz = gemmi::read_mtz_file(written + ".mtz");
|
||||
CHECK(Labels(mtz) == std::vector<std::string>{"H", "K", "L", "IMEAN", "SIGIMEAN", "I(+)", "SIGI(+)", "I(-)",
|
||||
"SIGI(-)", "F", "SIGF", "F(+)", "SIGF(+)", "F(-)", "SIGF(-)",
|
||||
"FreeR_flag"});
|
||||
CHECK(Labels(mtz) == std::vector<std::string>{"H", "K", "L", "IMEAN", "SIGIMEAN", "N", "I(+)", "SIGI(+)", "I(-)",
|
||||
"SIGI(-)", "N(+)", "N(-)", "F", "SIGF", "F(+)", "SIGF(+)", "F(-)",
|
||||
"SIGF(-)", "FreeR_flag"});
|
||||
CHECK(mtz.nreflections == static_cast<int>(reflections.size()));
|
||||
CHECK(mtz.datasets.back().wavelength == Catch::Approx(experiment.GetWavelength_A()).epsilon(1e-5));
|
||||
const gemmi::Mtz maps_mtz = gemmi::read_mtz_file(written + "_maps.mtz");
|
||||
@@ -236,7 +236,7 @@ TEST_CASE("RugnuxResultFiles: an existing file is kept when overwrite is off", "
|
||||
WriteRugnuxResultFiles(end, prefix, true, logger);
|
||||
const gemmi::Mtz mtz = gemmi::read_mtz_file(prefix + ".mtz");
|
||||
CHECK(mtz.nreflections == 1);
|
||||
CHECK(Labels(mtz) == std::vector<std::string>{"H", "K", "L", "IMEAN", "SIGIMEAN", "F", "SIGF", "FreeR_flag"});
|
||||
CHECK(Labels(mtz) == std::vector<std::string>{"H", "K", "L", "IMEAN", "SIGIMEAN", "N", "F", "SIGF", "FreeR_flag"});
|
||||
|
||||
std::filesystem::remove_all(dir);
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@ namespace jfjoch_test {
|
||||
|
||||
const double i_merged = sum_n_i / n_obs;
|
||||
r.I = static_cast<float>(i_merged);
|
||||
r.n_obs = n_obs;
|
||||
// The error model on one observation, averaged down by the merge, then thrown off
|
||||
// by the error-model miscalibration.
|
||||
r.sigma = static_cast<float>(std::hypot(sigma_one, p.error_model_b * i_merged) /
|
||||
|
||||
@@ -63,12 +63,19 @@ TEST_CASE("Merged MTZ: the data dataset is id 1 and carries the wavelength", "[w
|
||||
|
||||
// The wavelength is read off the dataset the data columns belong to, so they have to be on the
|
||||
// data dataset and not on the base.
|
||||
for (const char *label : {"IMEAN", "SIGIMEAN", "F", "SIGF", "FreeR_flag"}) {
|
||||
for (const char *label : {"IMEAN", "SIGIMEAN", "N", "F", "SIGF", "FreeR_flag"}) {
|
||||
const gemmi::Mtz::Column *col = mtz.column_with_label(label);
|
||||
REQUIRE(col != nullptr);
|
||||
CHECK(col->dataset_id == 1);
|
||||
}
|
||||
|
||||
// N is the number of observations merged into IMEAN, an integer column as dials.merge writes it.
|
||||
const gemmi::Mtz::Column *n_col = mtz.column_with_label("N");
|
||||
CHECK(n_col->type == 'I');
|
||||
for (size_t i = 0; i < reflections.size(); i++)
|
||||
CHECK(mtz.data[i * mtz.columns.size() + n_col->idx] == static_cast<float>(reflections[i].n_obs));
|
||||
CHECK(reflections.front().n_obs == std::max(2, params.multiplicity));
|
||||
|
||||
// Cell and space group travel in the same header.
|
||||
CHECK(mtz.spacegroup != nullptr);
|
||||
CHECK(mtz.spacegroup->number == 96);
|
||||
|
||||
Reference in new issue
Block a user