broker: serve the placed model and its maps of the last rugnux live run (/rugnux/model.cif, /rugnux/map.ccp4)
A rugnux live run that placed a model keeps it, with a copy of its map coefficients, beside the live status (RugnuxStructure), for as long as /rugnux/status keeps the run. Made in memory on the first request and cached, never written to disk: - GET /rugnux/model.cif: the placed model as mmCIF, labelled as WritePlacedModel labels _model.cif (PlacedModelMmcif, the labelling factored out of WritePlacedModel; the file output is unchanged). - GET /rugnux/map.ccp4?type=2fofc|fofc: the 2mFo-DFc / mFo-DFc map as a CCP4 map, FFT of the FWT/PHWT or DELFWT/PHDELWT coefficients (get_f_phi_on_grid + MapFromFPhi, sampled as ModelValidation samples), cut to the box around the model plus 5 A, with the whole cell's mean and RMS in the header. - 404 without a placed model or maps, 400 for an unknown map type; both routes protected by the dataset bearer token like /rugnux/status. rugnux_live_status gets placed_model. C++ model, python client docs, TypeScript client and redoc regenerated. Tests: a point's coefficients give a map peaking at the atom in a cropped box; the mmCIF; the structure is cleared at the next start; the auth test covers the new routes. End to end (myoglobin 2M replay with an AlphaFold model): the maps equal gemmi's FFT of the written _maps.mtz to 2.5e-6 rms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu (cherry picked from commit 33124c3288ba112def3f51c0d91f5206886f3495)
This commit is contained in:
1 parent
ae1169072a
commit
15ca4b329f
26 files changed
+835
-55
No files matched your search
+37
-17
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <gemmi/to_mmcif.hpp> // make_mmcif_document
|
||||
#include <gemmi/to_cif.hpp> // write_cif_to_stream
|
||||
@@ -27,20 +28,10 @@ bool coordinates_obey(const gemmi::SpaceGroup &coordinates_group, const gemmi::S
|
||||
label_ops.begin(), label_ops.end());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void WritePlacedModel(const gemmi::Structure &placed,
|
||||
const UnitCell &cell,
|
||||
const gemmi::SpaceGroup &space_group,
|
||||
const std::string &output_prefix,
|
||||
Logger &logger) {
|
||||
const std::string cif_path = output_prefix + "_model.cif";
|
||||
// PDB as well as mmCIF, because the fragment-screening tools this file exists for take a PDB:
|
||||
// PanDDA's per-dataset input is <name>.pdb beside <name>.mtz, and dimple produces the same pair.
|
||||
// Same coordinates, same frame, both formats - a PDB cannot hold every cell, so it is written
|
||||
// when it can be and skipped, with a line saying so, when it cannot.
|
||||
const std::string pdb_path = output_prefix + "_model.pdb";
|
||||
|
||||
// `placed` in `cell`, labelled with `space_group` wherever its coordinates obey it (see WritePlacedModel).
|
||||
// takes_model_group: the model's own group was kept instead.
|
||||
gemmi::Structure LabelledModel(const gemmi::Structure &placed, const UnitCell &cell,
|
||||
const gemmi::SpaceGroup &space_group, bool &takes_model_group) {
|
||||
gemmi::Structure st = placed;
|
||||
// The cell is the data's, taken from the same value the reflection files are written from: the
|
||||
// coordinates were re-fractionalized into it and genuinely sit there.
|
||||
@@ -55,11 +46,30 @@ void WritePlacedModel(const gemmi::Structure &placed,
|
||||
// structure it refines is not the model, and it says so nowhere. A pair whose two files disagree
|
||||
// is worth a warning; a coordinate file that is quietly wrong on its own is not worth writing.
|
||||
const gemmi::SpaceGroup *model_group = st.find_spacegroup();
|
||||
const bool takes_model_group = model_group != nullptr && !coordinates_obey(*model_group, space_group);
|
||||
const gemmi::SpaceGroup &label = takes_model_group ? *model_group : space_group;
|
||||
takes_model_group = model_group != nullptr && !coordinates_obey(*model_group, space_group);
|
||||
st.cell = cell;
|
||||
st.spacegroup_hm = label.xhm();
|
||||
st.spacegroup_hm = (takes_model_group ? *model_group : space_group).xhm();
|
||||
st.setup_cell_images();
|
||||
return st;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void WritePlacedModel(const gemmi::Structure &placed,
|
||||
const UnitCell &cell,
|
||||
const gemmi::SpaceGroup &space_group,
|
||||
const std::string &output_prefix,
|
||||
Logger &logger) {
|
||||
const std::string cif_path = output_prefix + "_model.cif";
|
||||
// PDB as well as mmCIF, because the fragment-screening tools this file exists for take a PDB:
|
||||
// PanDDA's per-dataset input is <name>.pdb beside <name>.mtz, and dimple produces the same pair.
|
||||
// Same coordinates, same frame, both formats - a PDB cannot hold every cell, so it is written
|
||||
// when it can be and skipped, with a line saying so, when it cannot.
|
||||
const std::string pdb_path = output_prefix + "_model.pdb";
|
||||
|
||||
bool takes_model_group = false;
|
||||
gemmi::Structure st = LabelledModel(placed, cell, space_group, takes_model_group);
|
||||
const gemmi::SpaceGroup &label = takes_model_group ? *st.find_spacegroup() : space_group;
|
||||
// Fills in entity types and label_asym_id for a model read from a PDB, which carries neither.
|
||||
// Both are no-ops where the input already had them, i.e. for an mmCIF input.
|
||||
// setup_entities and make_mmcif_document can both throw, and this runs BEFORE the reflection files
|
||||
@@ -100,3 +110,13 @@ void WritePlacedModel(const gemmi::Structure &placed,
|
||||
label.short_name(), space_group.short_name(), space_group.short_name());
|
||||
}
|
||||
}
|
||||
|
||||
std::string PlacedModelMmcif(const gemmi::Structure &placed, const UnitCell &cell,
|
||||
const gemmi::SpaceGroup &space_group) {
|
||||
bool takes_model_group = false;
|
||||
gemmi::Structure st = LabelledModel(placed, cell, space_group, takes_model_group);
|
||||
gemmi::setup_entities(st);
|
||||
std::ostringstream os;
|
||||
gemmi::cif::write_cif_to_stream(os, gemmi::make_mmcif_document(st));
|
||||
return os.str();
|
||||
}
|
||||
Reference in new issue
Block a user