rugnux --refine: refine the placed model, list its difference-map blobs, report under REFINE_ keys

Opt-in. After the model's placement and everything it decides (setting, indexing, enantiomorph, MR, twin
choice), the placed model is refined against the merge it was placed on (RefineModel) and the blobs of the
refined mFo-DFc map are listed (FindDensityBlobs). Nothing reads the outcome: the reflection files, the
space group and R_WORK/R_FREE of the model as given are those of a run without --refine.

Writes <prefix>_refined_model.cif/.pdb, <prefix>_refined_maps.mtz (FP FC PHIC FWT PHWT DELFWT PHDELWT FOM
FREE) and <prefix>_blobs.json; the report's model section gains REFINE_* keys (start, placement and
restrained R-factors, rmsd bonds/angles, clashes, fixed residues, weights, blob counts by kind) and the five
strongest blobs. Documented in RUGNUX_MODEL_AND_REFERENCE.md and CPU_DATA_ANALYSIS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit aaee92711a205bf6a575a47c4db4555d34e7e8fe)
This commit is contained in:
leonarski_f committed 2026-10-25 07:20:32 +01:00
1 parent b4b68d368f
commit 7759643d4c
8 files changed
+180 -3

No files matched your search

+7
View File
@@ -18,6 +18,7 @@ This document describes the crystallographic algorithms implemented in Jungfrauj
12. auxiliary statistics (Wilson plot, ⟨I/σ(I)⟩, CC1/2, CCref),
13. amplitude estimation (French–Wilson) and R-free test-set flagging,
14. optional model-based validation: rigid-body placement of a supplied model (molecular replacement where the rigid body does not place it, or for a predicted model), R-free against it, sigma_A-weighted 2mFo−DFc / mFo−DFc electron-density maps, and an anomalous difference map with the strongest anomalous sites named.
15. optional restrained refinement of the placed model (`--refine`): rigid bodies and group B, then positions and B against a maximum-likelihood amplitude target with the dictionary's geometry, the X-ray weight chosen by R-free within geometry bounds, and the unexplained blobs of the refined difference map.
The reference is split into four parts, in pipeline order; the section numbers run continuously
@@ -59,6 +60,12 @@ The methods draw on, and in places reimplement, solutions from:
- P. H. C. Eilers, "A perfect smoother", *Anal. Chem.* **75** (2003), 3631-3636, after E. T. Whittaker, "On a new method of graduation", *Proc. Edinburgh Math. Soc.* **41** (1923), 63-75 (the penalised smoother of the fulls' per-frame scale, §10.6).
- H. F. Walker & P. Ni, "Anderson acceleration for fixed-point iterations", *SIAM J. Numer. Anal.* **49** (2011), 1715-1735, after D. G. Anderson, "Iterative procedures for nonlinear integral equations", *J. ACM* **12** (1965), 547-560 (the acceleration of the per-frame scaling loops, §10.6).
- R. A. Fisher, "Frequency distribution of the values of the correlation coefficient in samples from an indefinitely large population", *Biometrika* **10** (1915), 507-521 (the z-transformation on which the correction surfaces' held-out half-set CC1/2 is compared).
- R. C. Agarwal, "A new least-squares refinement technique based on the fast Fourier transform algorithm", *Acta Cryst.* **A34** (1978), 791-809 (the gradient of the refinement target, §15).
- N. S. Pannu & R. J. Read, "Improved structure refinement through maximum likelihood", *Acta Cryst.* **A52** (1996), 659-668, and G. N. Murshudov, A. A. Vagin & E. J. Dodson, *Acta Cryst.* **D53** (1997), 240-255 (the maximum-likelihood amplitude target and the B restraints, §15).
- V. Y. Lunin & T. P. Skovoroda, *Acta Cryst.* **A51** (1995), 880-887 (the likelihood parameters from the free set, §15).
- A. A. Vagin et al., "REFMAC5 dictionary: organization of prior chemical knowledge and guidelines for its use", *Acta Cryst.* **D60** (2004), 2184-2195 (the restraint dictionary, §15).
- P. V. Afonine et al., "Towards automated crystallographic structure refinement with phenix.refine", *Acta Cryst.* **D68** (2012), 352-367 (the weight chosen among refinements by R-free, §15).
- D. C. Liu & J. Nocedal, "On the limited memory BFGS method for large scale optimization", *Math. Program.* **45** (1989), 503-528 (the minimiser, §15).
- M. Wojdyr, "GEMMI: A library for structural biology", *J. Open Source Softw.* **7** (2022), 4200 (model / structure-factor / map machinery used in §14).
- J. P. Wright, "Experiences with GPU decompression for bitshuffle + LZ4 data", HDF5 User Group meeting (2021), and [github.com/jonwright/bslz4decoders](https://github.com/jonwright/bslz4decoders) (device-side decoding of bitshuffle+LZ4 images, §0).
- A. Thorn & G. M. Sheldrick, "ANODE: anomalous and heavy-atom density calculation", *J. Appl. Cryst.* **44** (2011), 1285-1287 (anomalous difference density read at the model's sites).
+17
View File
@@ -44,6 +44,7 @@ the rest walks through a run step by step.
| *(none)* | — | Everything from the data | — |
| `--model <file>` | An atomic model, PDB or mmCIF, gzipped or not, recognised by content: an experimental structure or a prediction | Validation after the merge (R-work/R-free, CC(model, data), maps, the placed model); a rigid-body placement checked against a null, with molecular replacement where the rigid body does not place it, and straight away for a prediction | Labels only (hand, indexing, axes), and only where the model fits. Other space groups → `<prefix>_mr.*` |
| `--mr <file>` | The same kinds of model | As `--model`, but molecular replacement straight away, without the rigid body. `--mode mx` only, not together with `--model` | Hand label only. Other space groups → `<prefix>_mr.*` |
| `--refine` | Nothing more (with `--model` or `--mr`) | Refines the placed model against the merge it was placed on - each chain as a rigid body and a B per residue, then every atom's position (and, where R-free says so, its B) restrained by the dictionary carried in rugnux, against a maximum-likelihood target - and lists the unexplained blobs of its difference map. Writes `<prefix>_refined_model.cif`, `<prefix>_refined_maps.mtz`, `<prefix>_blobs.json`; reported under `REFINE_` keys | No - it runs after everything is decided and decides nothing |
| PAE file beside a prediction | `AF-<id>-F1-predicted_aligned_error_v<n>.json` next to `AF-<id>-F1-model_v<n>.cif` (read automatically, no option) | Cuts the prediction into rigid domains for molecular replacement | No (a domain alone can only confirm the answer's group) |
| `-z, --reference <file>` (`--reference-mtz`) | Merged data of the same crystal form: an MTZ, or a PDB structure-factor mmCIF (`-sf.cif`) | Fixes the space group (in its own setting) and the cell (softly), puts the merge on its axes, resolves the indexing ambiguity, hands over its R-free set, reports CC<sub>ref</sub> on stills. Never a scale anchor | **Yes**: the space group, the axes, the indexing and the free set are the reference's |
| `--reference-column <label>` | An MTZ column label | Which column of the reference is read | Through `-z` only |
@@ -222,6 +223,22 @@ The safeguards behind 2 and 3:
replacement not placing the model and no model decision taken
("The wrong-model null" in `tools/battery/README.md`; see also [Tests](TESTS.md)).
## Refinement (`--refine`)
What the dictionary restrains is fixed at build time: the 20 standard amino acids and MSE, the DNA/RNA
nucleotides, ATP/ADP/AMP/GTP/GDP/GMP, DMSO, PEG fragments (PEG, PGE, PG4, 1PE), glycerol, ethylene glycol,
sulfate, phosphate, acetate, MPD, water and common ions (a subset of the CCP4 Monomer Library compiled into
rugnux; nothing is read from disk). Any other residue is held fixed: it stays in the structure factors and
the bulk-solvent mask, and the refined atoms are kept from clashing with it; `REFINE_RESIDUES_FIXED_NAMES`
lists them. The dictionary's hydrogens are added and ride on their parents. The X-ray weight is chosen from a
ladder of complete refinements by R-free, among those whose bond and angle rmsd stay within 0.02 A and 2
degrees; B-factor refinement is then tried at a few weights and kept only where it lowers R-free beyond
0.001. The free set is the merge's own, so R-free after `--refine` judges the refinement against reflections it
never fitted - but where the model was deposited, those reflections were most likely its depositor's working
reflections, and a refinement against new data then moves R-free up from the unrefined value rather than
down. `R_WORK`/`R_FREE` of the model as given are never replaced. On a GPU a refinement takes seconds; the CPU
engine computes the same and is several times slower.
## Free set and model bias
**How the free set is made.** Rugnux draws its own test set (5 %, raised towards about 500 reflections on small data but never above 10 %):
+64
View File
@@ -2739,6 +2739,70 @@ ReportDocument BuildReportDocument(const std::string &output_prefix,
mp.t_rotation, mp.t_translation, mp.t_rescore, mp.t_null, mp.t_domains, mp.hand_check.seconds), true));
}
}
// --refine: the placed model refined (Refinement.h). Keys of their own: R_WORK / R_FREE above stay the
// unrefined model's.
if (result.refinement.has_value()) {
const RefinementResult &rf = *result.refinement;
Add(s, Blank());
if (!rf.ok) {
Add(s, KeyEnum("REFINE", "NOT_PERFORMED", {"PERFORMED", "NOT_PERFORMED"}));
Add(s, KeyText("REFINE_REASON", rf.failure_reason));
} else {
Add(s, KeyEnum("REFINE", "PERFORMED", {"PERFORMED", "NOT_PERFORMED"}));
Add(s, KeyText("REFINE_DEVICE", rf.on_gpu ? "GPU" : "CPU", true));
Add(s, KeyReal("REFINE_SECONDS", rf.seconds, "{:.1f}", true));
Add(s, KeyReal("REFINE_D_MIN", rf.d_min, "{:.2f}"));
Add(s, KeyReal("REFINE_R_WORK_START", rf.r_work_start, "{:.4f}"));
Add(s, KeyReal("REFINE_R_FREE_START", rf.r_free_start, "{:.4f}"));
Add(s, KeyInt("REFINE_RIGID_BODIES", rf.rigid_bodies));
Add(s, KeyReal("REFINE_R_WORK_PLACEMENT", rf.r_work_placement, "{:.4f}"));
Add(s, KeyReal("REFINE_R_FREE_PLACEMENT", rf.r_free_placement, "{:.4f}"));
if (rf.restrained) {
Add(s, KeyReal("REFINE_R_WORK", rf.r_work, "{:.4f}"));
Add(s, KeyReal("REFINE_R_FREE", rf.r_free, "{:.4f}"));
Add(s, KeyReal("REFINE_RMSD_BONDS", rf.geometry.rmsd_bonds, "{:.4f}"));
Add(s, KeyReal("REFINE_RMSD_ANGLES", rf.geometry.rmsd_angles, "{:.2f}"));
Add(s, KeyReal("REFINE_RMSD_BONDS_START", rf.geometry_start.rmsd_bonds, "{:.4f}", true));
Add(s, KeyReal("REFINE_RMSD_ANGLES_START", rf.geometry_start.rmsd_angles, "{:.2f}", true));
Add(s, KeyInt("REFINE_CLASHES", rf.geometry.clashes));
Add(s, KeyReal("REFINE_XRAY_WEIGHT", rf.weight, "{:.4g}", true));
Add(s, KeyInt("REFINE_ATOMS", rf.atoms));
Add(s, KeyInt("REFINE_ATOMS_REFINED", rf.refined_atoms));
Add(s, KeyInt("REFINE_RESIDUES_FIXED", rf.fixed_residues));
if (!rf.fixed_names.empty()) {
std::string names;
for (const std::string &n : rf.fixed_names)
names += (names.empty() ? "" : " ") + n;
Add(s, KeyText("REFINE_RESIDUES_FIXED_NAMES", names));
}
}
Add(s, KeyReal("REFINE_BULK_SOLVENT_K_SOL", rf.k_sol, "{:.3f}", true));
Add(s, KeyReal("REFINE_BULK_SOLVENT_B_SOL", rf.b_sol, "{:.1f}", true));
int kinds[5] = {0, 0, 0, 0, 0};
for (const DensityBlob &b : rf.blobs)
kinds[static_cast<int>(b.kind)]++;
Add(s, KeyInt("REFINE_BLOBS", static_cast<int64_t>(rf.blobs.size())));
Add(s, KeyInt("REFINE_BLOBS_LIGAND", kinds[static_cast<int>(DensityBlob::Kind::Ligand)]));
Add(s, KeyInt("REFINE_BLOBS_WATER", kinds[static_cast<int>(DensityBlob::Kind::Water)]));
Add(s, KeyInt("REFINE_BLOBS_ION", kinds[static_cast<int>(DensityBlob::Kind::Ion)]));
Add(s, KeyInt("REFINE_BLOBS_MODEL_ERROR", kinds[static_cast<int>(DensityBlob::Kind::ModelError)]));
std::string top;
for (size_t i = 0; i < std::min<size_t>(rf.blobs.size(), 5); i++) {
const DensityBlob &b = rf.blobs[i];
top += fmt::format("\n {:<11} peak {:5.1f} sigma, {:6.1f} A^3, at {:7.2f} {:7.2f} {:7.2f}, {:.1f} A from {}",
DensityBlobKindName(b.kind), b.peak_sigma, b.volume, b.centroid.x, b.centroid.y,
b.centroid.z, b.nearest_atom_distance, b.nearest_atom);
}
Add(s, Prose(fmt::format(
" The placed model was refined against these data (--refine): each chain as a rigid body and\n"
" one B per residue, then every atom restrained by the dictionary carried in rugnux, the\n"
" X-ray weight chosen by R-free with the geometry held within bounds. REFINE_ keys describe\n"
" the refined model, which is written as {}_refined_model.cif with its maps; R_WORK and\n"
" R_FREE above remain the model as given. The refinement decided nothing about the\n"
" processing. The strongest unexplained blobs of its difference map ({}_blobs.json):{}",
output_prefix, output_prefix, top.empty() ? std::string(" none") : top)));
}
}
doc.sections.push_back(std::move(s));
}
+12
View File
@@ -34,6 +34,7 @@
#include "../image_analysis/indexing/HarmonicContamination.h" // HarmonicContaminationResult
#include "../image_analysis/structure_refinement/ModelValidation.h" // ModelValidationResult
#include "../image_analysis/structure_refinement/MolecularReplacement.h" // MolecularReplacementResult
#include "../image_analysis/structure_refinement/Refinement.h" // RefinementResult
#include "../image_analysis/indexing/LeftoverLattices.h" // LeftoverLatticeCensus
#include "ReportDocument.h" // ReportWarning, PathologyCode
#include "../image_analysis/scale_merge/SearchSpaceGroup.h" // SearchSpaceGroupResult
@@ -260,6 +261,12 @@ struct ProcessConfig {
// did not place, is searched for anyway.
bool force_mr = false;
// --refine: the placed model refined against the merge it was placed on - each chain as a rigid body and a B
// per residue, then every atom restrained (Refinement.h) - and what it leaves in the difference map listed
// (DensityBlobs.h). Reported in keys of its own; it decides nothing about the processing or the files the
// run writes otherwise.
bool refine = false;
// --finalist-ledger: report-only symmetry evidence table (and the twin-immune zones), folded from
// a merge of its own in P1 that only this flag makes.
bool finalist_ledger = false;
@@ -404,6 +411,9 @@ struct RugnuxOutputs {
std::shared_ptr<ModelMaps> model_prior_maps; // the same at <prefix>_mr
std::optional<PlacedModelOutput> placed_model; // <prefix>_model.cif/.pdb
std::optional<PlacedModelOutput> model_prior_placed_model; // <prefix>_mr_model.cif/.pdb
std::optional<PlacedModelOutput> refined_model; // <prefix>_refined_model.cif/.pdb (--refine)
std::shared_ptr<ModelMaps> refined_maps; // <prefix>_refined_maps.mtz
std::optional<std::vector<DensityBlob>> blobs; // <prefix>_blobs.json
std::optional<MtzTable> unmerged; // <prefix>_unmerged.mtz
std::optional<MtzTable> unmerged_partials; // <prefix>_unmerged_partials.mtz
std::string detector_jpeg; // <prefix>_detector.jpg; empty: none drawn
@@ -712,6 +722,8 @@ struct ProcessResult {
std::string model_placement;
// What molecular replacement found, where it ran; failure_reason says why where it could not.
std::optional<MolecularReplacementResult> model_prior;
// What --refine made of the placed model; unset where it was not asked for or there was nothing placed.
std::optional<RefinementResult> refinement;
// The file suffix the model's choice of another group or the twin hypothesis' subgroup is written under
// (_mr), and that group; empty where nothing was.
std::string model_prior_file_suffix;
+2
View File
@@ -86,6 +86,8 @@ std::string RugnuxCommandLine(const ProcessConfig &config,
}
if (config.model)
add(config.force_mr ? "--mr" : "--model", config.model->name);
if (config.model && config.refine)
args.emplace_back("--refine");
}
if (config.start_image != 0)
add("-s", std::to_string(config.start_image));
+32
View File
@@ -6,12 +6,37 @@
#include <filesystem>
#include <fstream>
#include <nlohmann/json.hpp>
#include "../writer/FileWriter.h"
#include "../writer/WriteModel.h"
#include "../writer/WriteRugnuxFiles.h"
namespace {
// The unexplained blobs of the refined model's difference map (DensityBlobs.h), strongest first.
void WriteDensityBlobs(const std::vector<DensityBlob> &blobs, const std::string &path, Logger &logger) {
nlohmann::json list = nlohmann::json::array();
for (const DensityBlob &b : blobs)
list.push_back({{"kind", DensityBlobKindName(b.kind)},
{"centroid", {b.centroid.x, b.centroid.y, b.centroid.z}},
{"peak_sigma", b.peak_sigma},
{"volume_A3", b.volume},
{"score_sigma_A3", b.score},
{"nearest_atom", b.nearest_atom},
{"nearest_atom_distance_A", b.nearest_atom_distance},
{"polar_contacts", b.polar_contacts},
{"metal_contacts", b.metal_contacts},
{"anomalous_sigma", b.anomalous_sigma}});
std::ofstream f(path, std::ofstream::out | std::ofstream::trunc);
if (!f) {
logger.Warning("Cannot open {} for writing", path);
return;
}
f << nlohmann::json{{"blobs", list}}.dump(1) << std::endl;
logger.Info("Difference-map blobs written to {}", path);
}
// The files of one output pass at `prefix`, all but its _process.h5.
void WriteOutputs(const RugnuxOutputs &o, const std::string &prefix, const OutputProvenance &provenance,
size_t nthreads, Logger &logger) {
@@ -30,6 +55,13 @@ void WriteOutputs(const RugnuxOutputs &o, const std::string &prefix, const Outpu
if (o.model_prior_placed_model)
WritePlacedModel(*o.model_prior_placed_model->model, o.model_prior_placed_model->cell,
o.model_prior_placed_model->space_group, prefix + "_mr", logger);
if (o.refined_model)
WritePlacedModel(*o.refined_model->model, o.refined_model->cell, o.refined_model->space_group,
prefix + "_refined", logger);
if (o.refined_maps)
WriteModelMaps(*o.refined_maps, prefix + "_refined", logger);
if (o.blobs)
WriteDensityBlobs(*o.blobs, prefix + "_blobs.json", logger);
if (o.unmerged) {
WriteMtz(*o.unmerged, prefix + "_unmerged.mtz");
logger.Info("Unmerged observations written to {}_unmerged.mtz", prefix);
+34 -3
View File
@@ -4361,6 +4361,8 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
std::optional<ModelPriorFile> model_prior_file;
// The coordinates that go with the maps beside the answer's files, kept once the model is done.
std::optional<PlacedModelOutput> placed_model_out;
// The merge that placement was made against, which --refine refines it against.
const std::vector<MergedReflection> *placed_merged = nullptr;
// The twin hypothesis the model is asked about: its own subgroup's merge where it has one, the data's
// otherwise - and whether that merge was made only for the model, so is written only where it chooses it.
std::optional<TwinFile> &model_twin = model_twin_merge ? model_twin_file : twin_file;
@@ -4540,8 +4542,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
twin_validation.r_free_twin, twin_validation.twin_fraction)
: std::string(),
maps_from_twin ? "the merge in " + mt.space_group.xhm() : "the answer's merge");
if (maps_from_twin && twin_validation.placed_model)
if (maps_from_twin && twin_validation.placed_model) {
placed_model_out = PlacedModelOutput{twin_validation.placed_model, mt.cell, mt.space_group};
placed_merged = &mt.merged;
}
// The model placed there and fitting better there chooses the subgroup: its files, <prefix>_mr. They
// carry the model's own group where it has the subgroup's rotations - the screws and the hand are the
// model's, as the coordinates beside them are, unless the anomalous map at its atoms is inverted - and
@@ -4567,9 +4571,11 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
mt_report.maps_from_this_merge = maps_from_twin;
mt_report.model_validation = std::move(twin_validation);
}
if (validation.placed_model && !maps_from_twin)
if (validation.placed_model && !maps_from_twin) {
placed_model_out = PlacedModelOutput{validation.placed_model, *result.consensus_cell,
experiment_.GetSpaceGroupOrP1()};
placed_merged = &sm.merged;
}
}
prepare_twin_file();
@@ -4673,8 +4679,10 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
}
if (own)
model_prior_file->placed = v.placed_model;
else
else {
placed_model_out = PlacedModelOutput{v.placed_model, cell, data_sg};
placed_merged = &sm.merged;
}
result.model_validation = std::move(v);
}
}
@@ -4700,6 +4708,29 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
if (model_prior_file)
result.model_prior_file_space_group = model_prior_file->space_group.xhm();
result.outputs->placed_model = placed_model_out;
// --refine: the placed model refined against the merge it was placed on, after everything above has been
// decided, so that nothing reads what it finds.
if (config_.refine && placed_model_out && placed_merged != nullptr && result.model_validation &&
result.model_validation->ok) {
phase("Refining the model");
Step("Refinement");
TimingMark mark(logger, "refinement");
RefinementSettings settings;
settings.nthreads = static_cast<size_t>(config_.nthreads);
settings.gpu_resident_bytes = rsm && rsm->OnGPU() ? rsm->DeviceBytes() : 0;
const PlacedModelOutput &p = *placed_model_out;
RefinementResult refined = RefineModel(*p.model, *placed_merged, gemmi::UnitCell(p.cell), p.space_group,
experiment_.GetWavelength_A(), logger, settings);
if (refined.ok) {
result.outputs->refined_model = PlacedModelOutput{refined.model, p.cell, p.space_group};
result.outputs->refined_maps = refined.maps;
result.outputs->blobs = refined.blobs;
Note(fmt::format("refined: R-work {:.3f}, R-free {:.3f}, rmsd bonds {:.3f} A, {} blobs", refined.r_work,
refined.r_free, refined.geometry.rmsd_bonds, refined.blobs.size()));
} else
logger.Warning("Refinement did not run: {}", refined.failure_reason);
result.refinement = std::move(refined);
}
// The outcome, as notes of the step that decided it
if (result.model_prior) {
const MolecularReplacementResult &mp = *result.model_prior;
+12
View File
@@ -242,6 +242,7 @@ void print_usage() {
std::cout << " --reference-column <label> Reference column to use, by MTZ label; an mmCIF is read under the labels gemmi cif2mtz gives it (IMEAN, FP, I(+), FC, F-model, ...) (default: auto - F-model, else IMEAN/I, else FP/FOBS/F)" << std::endl;
std::cout << " --model <file> After merging, validate vs this atomic model: R-free, sigma_A-weighted 2mFo-DFc/mFo-DFc maps, the model as placed (written beside them), and - where the merge kept the Bijvoet split - an anomalous difference map with the strongest anomalous scatterers named by the atom they sit on. PDB or mmCIF, gzipped or not, recognised by content rather than by extension. A prediction (AlphaFold or ModelCIF, pLDDT in the B column), or an experimental structure the rigid body does not place against its null, is placed by molecular replacement instead (see --mr)" << std::endl;
std::cout << " --mr <file> As --model, but placed by molecular replacement straight away, without the rigid-body placement first: as many copies as the cell holds, in every space group the merge cannot tell apart and in the twin hypothesis' subgroup. A prediction is trimmed to the residues of pLDDT 70 and above, and where the AlphaFold DB's predicted-aligned-error JSON sits beside it under its own name it is cut into rigid domains; any other PDB or mmCIF is taken as an experimental structure, its polymer only (no waters, ligands, hydrogens or alternative conformers). Which of the two it is is read from the file. It may relabel the enantiomorph of the answer, and a different space group it chooses is written beside the answer as <prefix>_mr.mtz/.cif with the placed model <prefix>_mr_model.pdb. --mode mx only" << std::endl;
std::cout << " --refine With --model or --mr: refine the placed model against the merge it was placed on - each chain as a rigid body and one B per residue, then every atom's position and B restrained by the dictionary carried in rugnux (standard amino acids and nucleotides, common ligands and additives, water and ions; anything else is held fixed) against a maximum-likelihood target, the X-ray weight chosen by R-free within geometry bounds - and list the unexplained blobs of its difference map. Writes <prefix>_refined_model.cif, <prefix>_refined_maps.mtz and <prefix>_blobs.json; reported under REFINE_ keys, never in place of the unrefined R-factors. Decides nothing about the processing" << std::endl;
std::cout << " --export-unmerged Write <prefix>_unmerged.mtz, an unmerged MTZ (POINTLESS column layout) of the integrated observations, for aimless / pointless / careless. On by default, whenever there is an output prefix. On a rotation run the partials of each reflection are summed into one full, written at the batch its rocking curve is centred on, with the summed rocking-curve fraction in FRACTIONCALC; an event that caught less of its rocking curve than --min-captured-fraction (or --min-partiality) is not written, exactly as in the merge, since a full is what the reading program is told these rows are. Intensities carry the deterministic per-reflection corrections and nothing else - Lorentz and polarization in the LP column, the sensor's angle-dependent efficiency in QE and the flight path's attenuation in FLIGHT, so raw counts are I / LP * QE * FLIGHT - while the partiality is not divided out and the per-image scale is not applied at all, since those programs scale the data themselves. Written in --mode mx and --mode scale, and with --no-merge" << std::endl;
std::cout << " --no-export-unmerged Do not write <prefix>_unmerged.mtz. It is the largest file a run produces, so a run whose observations are not going to another scaling program - a regression battery, say - can skip writing it" << std::endl;
std::cout << " --export-unmerged-partials Write <prefix>_unmerged_partials.mtz, the same observations with each partial as its own row (one batch per image) flagged for the reading program to sum, instead of summed here. Off by default and independent of --export-unmerged; both can be written in one run" << std::endl;
@@ -331,6 +332,7 @@ enum {
OPT_MODEL,
OPT_CRYSTFEL_GEOMETRY,
OPT_MR,
OPT_REFINE,
OPT_EXPORT_UNMERGED,
OPT_NO_EXPORT_UNMERGED,
OPT_EXPORT_UNMERGED_PARTIALS,
@@ -405,6 +407,7 @@ static option long_options[] = {
{"model", required_argument, nullptr, OPT_MODEL},
{"crystfel-geometry", required_argument, nullptr, OPT_CRYSTFEL_GEOMETRY},
{"mr", required_argument, nullptr, OPT_MR},
{"refine", no_argument, nullptr, OPT_REFINE},
{"export-unmerged", no_argument, nullptr, OPT_EXPORT_UNMERGED},
{"no-export-unmerged", no_argument, nullptr, OPT_NO_EXPORT_UNMERGED},
{"export-unmerged-partials", no_argument, nullptr, OPT_EXPORT_UNMERGED_PARTIALS},
@@ -1037,6 +1040,7 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) {
std::string crystfel_geometry; // --crystfel-geometry: read the input as CrystFEL would with this geometry
std::string model_pdb; // --model: PDB to validate merged intensities against (R-free + maps)
std::string mr_model; // --mr: --model, placed by molecular replacement straight away
bool refine_model = false; // --refine
bool export_unmerged = true; // on by default; --no-export-unmerged turns it off
bool export_unmerged_partials = false; // --export-unmerged-partials: the same, one row per image
std::string dump_observations; // diagnostic: dump unmerged -P rot3d fulls to this path
@@ -1279,6 +1283,9 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) {
case OPT_MR:
mr_model = optarg;
break;
case OPT_REFINE:
refine_model = true;
break;
case OPT_EXPORT_UNMERGED:
export_unmerged = true;
break;
@@ -1746,6 +1753,10 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) {
logger.Error("--model and --mr both name the model; give one");
exit(EXIT_FAILURE);
}
if (refine_model && mr_model.empty() && model_pdb.empty()) {
logger.Error("--refine refines a model: give it with --model or --mr");
exit(EXIT_FAILURE);
}
// Read before anything runs: a file that holds no model ends the run here rather than after it.
std::shared_ptr<const RugnuxModel> model;
if (const std::string path = mr_model.empty() ? model_pdb : mr_model; !path.empty()) {
@@ -3533,6 +3544,7 @@ static int RunRugnux(int argc, char **argv, bool no_gpu) {
config.export_unmerged_partials = export_unmerged_partials;
config.model = model;
config.force_mr = !mr_model.empty();
config.refine = refine_model;
// When merging, the merged reflections (.mtz/.cif) are the wanted output; skip the large
// _process.h5 unless explicitly requested. Without merging, the _process.h5 is the only output.
std::optional<ProcessFileSink> sink;