From c26d8c6ba4f46941ca4ca56591ef6c0ee657c472 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sat, 14 Nov 2026 11:54:02 +0100 Subject: [PATCH] rugnux: a PDB model is recognised whatever record it starts with The positional-input classifier knew a PDB file by its first record, from a short list (HEADER, TITLE, REMARK, CRYST1, ATOM, ...). A model written without a title section starts with whatever comes first in the format - rugnux's own refined model starts with its HELIX or LINK records - and was taken for an image file, so `rugnux --mode refine ` ended in "Several inputs are read together in --mode mx only" while the same file worked under --model. The list is now every record type the format puts before the coordinates. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK --- rugnux/RugnuxInputKind.cpp | 12 +++++++++--- tests/RugnuxInputKindTest.cpp | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/rugnux/RugnuxInputKind.cpp b/rugnux/RugnuxInputKind.cpp index 565ead494..547a38888 100644 --- a/rugnux/RugnuxInputKind.cpp +++ b/rugnux/RugnuxInputKind.cpp @@ -21,9 +21,15 @@ const char *RugnuxInputKindName(RugnuxInputKind kind) { } namespace { - // The record names a PDB file starts with (its first line that is not blank) - constexpr const char *PDB_RECORDS[] = {"HEADER", "TITLE ", "COMPND", "SOURCE", "KEYWDS", "EXPDTA", "AUTHOR", - "REVDAT", "REMARK", "SEQRES", "CRYST1", "MODEL ", "ATOM ", "HETATM"}; + // The records a PDB file can start with (its first line that is not blank): every record type of the format + // that precedes the coordinates. A file written by a program starts with whatever that program has to say - + // a refined model with no title section starts with its HELIX or LINK records. + constexpr const char *PDB_RECORDS[] = {"HEADER", "OBSLTE", "TITLE ", "SPLIT ", "CAVEAT", "COMPND", "SOURCE", + "KEYWDS", "EXPDTA", "NUMMDL", "MDLTYP", "AUTHOR", "REVDAT", "SPRSDE", + "JRNL ", "REMARK", "DBREF ", "DBREF1", "DBREF2", "SEQADV", "SEQRES", + "MODRES", "HET ", "HETNAM", "HETSYN", "FORMUL", "HELIX ", "SHEET ", + "SSBOND", "LINK ", "LINKR ", "CISPEP", "SITE ", "CRYST1", "ORIGX1", + "SCALE1", "MTRIX1", "MODEL ", "ATOM ", "HETATM"}; // The rule, fed one line at a time; done() once the answer cannot change. class Sniffer { diff --git a/tests/RugnuxInputKindTest.cpp b/tests/RugnuxInputKindTest.cpp index 7eb42fc4f..78779e4f2 100644 --- a/tests/RugnuxInputKindTest.cpp +++ b/tests/RugnuxInputKindTest.cpp @@ -45,13 +45,24 @@ TEST_CASE("RugnuxInputKind_Classify", "[rugnux_inputs]") { CHECK(ClassifyRugnuxInput(Write("ik_image2.cbf", "data_image\n_array_data.data\n_atom_site.x\n")) == K::Images); CHECK(ClassifyRugnuxInput(Write("ik_image.img", "{\nHEADER_BYTES= 512;\nDIM=2;\n}")) == K::Images); CHECK(ClassifyRugnuxInput(Write("ik_binary", std::string("\0\1\2\3\4\5\6\7\0\0\0\0\0\0\0\0x", 17))) == K::Images); + // A PDB file need not start with a title section: a refined model written without one starts with its + // HELIX or LINK records (the first line decides the format, the atom decides the model) + const std::string ATOM = "ATOM 1 CA ALA A 1 1.000 2.000 3.000 1.00 10.00 C\nEND\n"; + CHECK(ClassifyRugnuxInput(Write("ik_link_first.pdb", + "LINK SG CYS A 14 CAB HEC A 201 1555 1555 1.82\n" + ATOM)) == K::Model); + CHECK(ClassifyRugnuxInput(Write("ik_helix_first.pdb", + "HELIX 1 1 VAL A 4 LYS A 14 0\nCRYST1 50.000 50.000 50.000 90.00 90.00 90.00 P 1\n" + ATOM)) + == K::Model); + CHECK(ClassifyRugnuxInput(Write("ik_ssbond_first.pdb", + "SSBOND 1 CYS A 6 CYS A 127 1555 1555 2.03\n" + ATOM)) == K::Model); // A PDB file without an atom is not a model CHECK(ClassifyRugnuxInput(Write("ik_noatom.pdb", "HEADER TEST\nEND\n")) == K::Images); // Both coordinates and reflections: the user has to say CHECK(ClassifyRugnuxInput(Write("ik_both.cif", MODEL_CIF + "loop_\n_refln.index_h\n1\n")) == K::Ambiguous); for (const char *f: {"ik_model.cif", "ik_sf.cif", "ik_diffrn.cif", "ik_model.pdb", "ik_model.pdb.gz", "ik_sf.cif.gz", "ik_model_named.mtz", "ik_mtz_named.pdb", "ik_image.h5", "ik_image.cbf", "ik_image2.cbf", - "ik_image.img", "ik_binary", "ik_noatom.pdb", "ik_both.cif"}) + "ik_image.img", "ik_binary", "ik_noatom.pdb", "ik_both.cif", "ik_link_first.pdb", + "ik_helix_first.pdb", "ik_ssbond_first.pdb"}) std::filesystem::remove(f); }