A restraint mmCIF (monomer library, AceDRG, grade, eLBOW: data_comp_<CODE>, data_link_*, data_mod_*) is read by the caller (ReadRestraintDictionary, no file I/O in the library) into a RestraintDictionary that RefinementSettings carries; BuildRefinementTopology takes its entries over the embedded library's of the same name. A PDB CCD entry (bonds without lengths) is restrained to its ideal coordinates' bonds, angles and sp2 planes (no torsions, no chiral volumes); without ideal coordinates it is refused. Positional inputs: an mmCIF with _chem_comp_atom/_chem_link/_chem_mod and no atoms or reflections is a restraint file; a model and reflections with no images and no --mode run --mode refine. Embedded: RET (LYS-RET), HC4, CRO, GYS, CR2, NRQ (their pept links), BLA, LBV, CYC (CYS-CYC). CMO stays out (library C-O 1.25 A). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
102 lines
6.7 KiB
C++
102 lines
6.7 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <zlib.h>
|
|
|
|
#include "../rugnux/RugnuxInputKind.h"
|
|
|
|
namespace {
|
|
const std::string MODEL_CIF = "data_test\n#\n_cell.length_a 50.0\nloop_\n_atom_site.group_PDB\n_atom_site.id\n"
|
|
"ATOM 1\n";
|
|
const std::string SF_CIF = "data_r1abcsf\n_cell.length_a 50.0\nloop_\n_refln.index_h\n_refln.index_k\n"
|
|
"_refln.index_l\n_refln.intensity_meas\n1 0 0 10.0\n";
|
|
const std::string RESTRAINT_CIF = "data_comp_list\nloop_\n_chem_comp.id\n_chem_comp.group\nXYZ non-polymer\n"
|
|
"data_comp_XYZ\nloop_\n_chem_comp_atom.comp_id\n_chem_comp_atom.atom_id\nXYZ C1\n";
|
|
const std::string PDB = "HEADER TEST\nREMARK 1 SYNTHETIC\nCRYST1 50.000 50.000 50.000 90.00 90.00 90.00 P 1\n"
|
|
"ATOM 1 CA ALA A 1 1.000 2.000 3.000 1.00 10.00 C\nEND\n";
|
|
|
|
std::string Write(const std::string &name, const std::string &content) {
|
|
std::ofstream(name, std::ios::binary) << content;
|
|
return name;
|
|
}
|
|
|
|
std::string WriteGz(const std::string &name, const std::string &content) {
|
|
gzFile f = gzopen(name.c_str(), "wb");
|
|
gzwrite(f, content.data(), static_cast<unsigned>(content.size()));
|
|
gzclose(f);
|
|
return name;
|
|
}
|
|
}
|
|
|
|
TEST_CASE("RugnuxInputKind_Classify", "[rugnux_inputs]") {
|
|
using K = RugnuxInputKind;
|
|
CHECK(ClassifyRugnuxInput(Write("ik_model.cif", MODEL_CIF)) == K::Model);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_sf.cif", SF_CIF)) == K::Reflections);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_diffrn.cif", "data_x\nloop_\n_diffrn_refln.index_h\n1\n")) == K::Reflections);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_model.pdb", PDB)) == K::Model);
|
|
CHECK(ClassifyRugnuxInput(WriteGz("ik_model.pdb.gz", PDB)) == K::Model);
|
|
CHECK(ClassifyRugnuxInput(WriteGz("ik_sf.cif.gz", SF_CIF)) == K::Reflections);
|
|
// the name says nothing: a model in a file called .mtz, reflections in one called .pdb
|
|
CHECK(ClassifyRugnuxInput(Write("ik_model_named.mtz", MODEL_CIF)) == K::Model);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_mtz_named.pdb", std::string("MTZ \0\0\0\0", 8) + "binary")) == K::Reflections);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_image.h5", std::string("\x89HDF\r\n\x1a\n\0\0\0\0", 12))) == K::Images);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_image.cbf", "###CBF: VERSION 1.5\ndata_image\n_array_data.data\n")) == K::Images);
|
|
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);
|
|
// A restraint dictionary, a CCD entry and a file of links only
|
|
CHECK(ClassifyRugnuxInput(Write("ik_restraints.cif", RESTRAINT_CIF)) == K::Restraints);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_ccd.cif", "data_XYZ\n_chem_comp.id XYZ\nloop_\n_chem_comp_atom.comp_id\n"
|
|
"_chem_comp_atom.atom_id\nXYZ C1\n")) == K::Restraints);
|
|
CHECK(ClassifyRugnuxInput(Write("ik_links.cif", "data_link_list\nloop_\n_chem_link.id\nAB\n")) == K::Restraints);
|
|
// 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_link_first.pdb",
|
|
"ik_helix_first.pdb", "ik_ssbond_first.pdb", "ik_restraints.cif", "ik_ccd.cif", "ik_links.cif"})
|
|
std::filesystem::remove(f);
|
|
}
|
|
|
|
TEST_CASE("RugnuxInputKind_SplitAnyOrder", "[rugnux_inputs]") {
|
|
const std::string img = Write("ik_s_image.h5", std::string("\x89HDF\r\n\x1a\n\0\0\0\0", 12));
|
|
const std::string model = Write("ik_s_model.pdb", PDB);
|
|
const std::string sf = Write("ik_s_sf.cif", SF_CIF);
|
|
const std::string dict1 = Write("ik_s_dict1.cif", RESTRAINT_CIF), dict2 = Write("ik_s_dict2.cif", RESTRAINT_CIF);
|
|
for (const auto &order: std::vector<std::vector<std::string>>{{img, model, sf, dict1, dict2},
|
|
{dict1, model, sf, img, dict2},
|
|
{sf, dict1, img, model, dict2}}) {
|
|
const RugnuxPositionalInputs s = SplitRugnuxInputs(order);
|
|
CHECK(s.images == std::vector<std::string>{img});
|
|
CHECK(s.model == model);
|
|
CHECK(s.reflections == sf);
|
|
CHECK(s.restraints == std::vector<std::string>{dict1, dict2}); // several, in the order given
|
|
}
|
|
// image files keep their order; a path that is no file (yet) is left to the image readers
|
|
const RugnuxPositionalInputs s = SplitRugnuxInputs({"later_master.h5", model, img});
|
|
CHECK(s.images == std::vector<std::string>{"later_master.h5", img});
|
|
|
|
const std::string model2 = Write("ik_s_model2.cif", MODEL_CIF);
|
|
CHECK_THROWS(SplitRugnuxInputs({img, model, model2}));
|
|
CHECK_THROWS(SplitRugnuxInputs({sf, img, sf}));
|
|
const std::string both = Write("ik_s_both.cif", MODEL_CIF + "loop_\n_refln.index_h\n1\n");
|
|
CHECK_THROWS(SplitRugnuxInputs({img, both}));
|
|
for (const auto &f: {img, model, sf, model2, both, dict1, dict2})
|
|
std::filesystem::remove(f);
|
|
}
|