Files
Jungfraujoch/gemmi_gph/read_cif.cpp
T
leonarski_fandClaude Opus 5 18d3f55325 rugnux: read mmCIF models with --model, and say when a model could not be used
--model called gemmi::read_pdb unconditionally, so a coordinate file in mmCIF -
which is how the PDB serves coordinates by default - was refused outright:

  Model validation: cannot read model 6G8A.cif:
  Incorrect file format (perhaps it is cif not pdb?)

Worse than the refusal was what followed it. ValidateAgainstModel logged,
returned an empty result, and the run went on to finish with exit code 0, no
R-free, no maps and nothing in the report - indistinguishable from a run that was
never given --model at all. A script that passed a .cif, checked the exit code
and grepped for R-free simply got nothing back.

Both read sites now go through read_structure_gz with CoorFormat::Detect, so PDB,
mmCIF and mmJSON are all read, gzipped or not, and the format comes from the
file's content rather than from its name. Detect is passed explicitly: GEMMI
otherwise takes the extension and only falls back to the content when it does not
recognise one, and a model arrives named however whoever produced it named it.

That needed a part of GEMMI the vendored subset had trimmed away. mmread.hpp was
already here but its CIF parser was not, so this restores what upstream GEMMI
ships: read_cif/mmcif/json/mmread_gz, plus GEMMI's own copies of PEGTL (MIT,
Colin Hirsch and Daniel Frey; 155 headers, 672 kB) and sajson (MIT, Chad Austin;
one header). Both are listed in THIRD_PARTY_NOTICES.md with their own licence
texts, PEGTL's collected by COLLECT.sh and sajson's kept by hand, its terms being
a comment block rather than a file. json.cpp carries a one-line change: upstream
keeps sajson at the root of its repository, outside the include tree this subset
copies, so the include points at where the other bundled headers live.

ModelValidationResult gains failure_reason, and a model that was asked for and
could not be used now reaches the results report as

  WARNING: Model validation did not run: model bogus.pdb has no atoms or no unit cell

in --mode mx and --mode scale alike. The run still succeeds - a merge that is good
is not made bad by a model that was not - but it no longer does so quietly.

One log line was making a claim it could not support: the indexing-ambiguity
message said the ambiguity was "resolved against the supplied model" while being
printed before the model is read, so it announced a resolution that a failed model
never performed. It now says the model will be used; the reference branch, where
the work really has already happened, keeps the past tense.

Verified on the rotation test dataset with a deposited mmCIF, the same file
gzipped, an mmCIF under a .pdb name, a PDB, and an unreadable file.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WmryXe8ASbNi632sUMfsa
2026-08-27 22:09:51 +02:00

39 lines
1.1 KiB
C++

// Copyright 2021 Global Phasing Ltd.
#include <gemmi/read_cif.hpp>
#include <gemmi/cif.hpp> // for cif::read
#include <gemmi/json.hpp> // for cif::read_mmjson
#include <gemmi/gz.hpp> // for MaybeGzipped
namespace gemmi {
cif::Document read_cif_gz(const std::string& path, int check_level) {
return cif::read(MaybeGzipped(path), check_level);
}
bool check_cif_syntax_gz(const std::string& path, std::string* msg) {
return cif::check_syntax(MaybeGzipped(path), msg);
}
cif::Document read_mmjson_gz(const std::string& path) {
return cif::read_mmjson(MaybeGzipped(path));
}
CharArray read_into_buffer_gz(const std::string& path) {
return read_into_buffer(MaybeGzipped(path));
}
cif::Document read_cif_from_memory(const char* data, size_t size, const char* name,
int check_level) {
return cif::read_memory(data, size, name, check_level);
}
cif::Document read_first_block_gz(const std::string& path, size_t limit) {
cif::Document doc;
doc.source = path;
cif::read_one_block(doc, MaybeGzipped(path), limit);
return doc;
}
} // namespace gemmi