model validation: write the placed model as PDB as well as mmCIF
The file exists for fragment screening, and the tools it is meant to feed take a PDB: PanDDA's per-dataset input is <name>.pdb beside <name>.mtz, and dimple produces that same pair. Writing only mmCIF left the one consumer the file was for unable to read it. Same coordinates, same frame, both formats. gemmi::write_pdb was already linked - to_mmcif.cpp needs use_hetatm out of to_pdb.cpp - so this costs a call and no dependency. A PDB cannot express every cell, so it is written where it can be and skipped with a line saying so where it cannot; the mmCIF is unconditional. Measured on one rotation run: <prefix>_model.pdb and <prefix>_model.cif carry the same 1156 atoms, and both read back with the space group and cell of the .mtz beside them. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
847e44d718
commit
232fd649ae
1 file changed
+23
-6
+23
-6
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <gemmi/to_mmcif.hpp> // make_mmcif_document
|
||||
#include <gemmi/to_cif.hpp> // write_cif_to_stream
|
||||
#include <gemmi/to_pdb.hpp> // write_pdb
|
||||
#include <gemmi/polyheur.hpp> // setup_entities
|
||||
|
||||
#include "../common/Logger.h"
|
||||
@@ -16,7 +17,12 @@ void WritePlacedModel(const gemmi::Structure &placed,
|
||||
const gemmi::SpaceGroup &space_group,
|
||||
const std::string &output_prefix,
|
||||
Logger &logger) {
|
||||
const std::string path = output_prefix + "_model.cif";
|
||||
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";
|
||||
|
||||
gemmi::Structure st = placed;
|
||||
// Not the model's own cell and group but the data's, taken from the same two values the reflection
|
||||
@@ -34,16 +40,27 @@ void WritePlacedModel(const gemmi::Structure &placed,
|
||||
// The map writer does the same.
|
||||
try {
|
||||
gemmi::setup_entities(st);
|
||||
std::ofstream os(path);
|
||||
std::ofstream os(cif_path);
|
||||
gemmi::cif::write_cif_to_stream(os, gemmi::make_mmcif_document(st));
|
||||
if (!os) {
|
||||
logger.Error("Model validation: cannot write the placed model to {}", path);
|
||||
logger.Error("Model validation: cannot write the placed model to {}", cif_path);
|
||||
return;
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
logger.Warning("Model validation: could not write the placed model to {} ({})", path, e.what());
|
||||
logger.Warning("Model validation: could not write the placed model to {} ({})",
|
||||
cif_path, e.what());
|
||||
return;
|
||||
}
|
||||
logger.Info("Model validation: the model as placed against these data written to {} "
|
||||
"(cell and space group {} as in the reflection files)", path, space_group.short_name());
|
||||
bool pdb_written = false;
|
||||
try {
|
||||
std::ofstream os(pdb_path);
|
||||
gemmi::write_pdb(st, os);
|
||||
pdb_written = static_cast<bool>(os);
|
||||
} catch (const std::exception &e) {
|
||||
logger.Warning("Model validation: the placed model could not also be written as PDB ({}); "
|
||||
"{} has it", e.what(), cif_path);
|
||||
}
|
||||
logger.Info("Model validation: the model as placed against these data written to {}{} "
|
||||
"(cell and space group {} as in the reflection files)",
|
||||
cif_path, pdb_written ? " and " + pdb_path : "", space_group.short_name());
|
||||
}
|
||||
Reference in new issue
Block a user