From 88e2f7b96aa1871577ccad780f9787001f79878e Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 15 Nov 2026 13:03:22 +0100 Subject: [PATCH] Sugar links never join two conformers; warn on ignored restraint files AddSugarLinks paired atoms by distance regardless of altloc, so a pyranose and its partner both in conformers A and B also got the A-B bonds. A pair whose altlocs are both set and differ is now skipped; a blank altloc still pairs with any, as gemmi does. New test: a GlcNAc on an Asn in two conformers links A-A and B-B only. rugnux logs one warning when restraint files are given but the run refines no model (no model, --no-refine, or a mode without refinement). RUGNUX_CLI.md: the automatic --mode refine also applies when the model comes from --model and the reflections are among the inputs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK --- docs/RUGNUX_CLI.md | 7 ++-- .../RefinementRestraints.cpp | 2 ++ rugnux/rugnux_cli.cpp | 4 +++ tests/RefinementTest.cpp | 34 +++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/RUGNUX_CLI.md b/docs/RUGNUX_CLI.md index c07e2e434..de73be06f 100644 --- a/docs/RUGNUX_CLI.md +++ b/docs/RUGNUX_CLI.md @@ -58,9 +58,10 @@ rugnux --mode refine -o refined data.mtz model.cif ``` Refines a model against merged data that already exist - an MTZ or a structure-factor mmCIF - and -reads no images. The model is required, given among the inputs or with `--model`. Given a model and -reflections among the inputs and no images, without `--mode`, rugnux takes `--mode refine` -(`rugnux -o refined data.mtz model.cif`). A restraint dictionary for a ligand can be given among the +reads no images. The model is required, given among the inputs or with `--model`. Without `--mode`, +rugnux takes `--mode refine` when the inputs hold reflections and no images and a model is given - +among the inputs or with `--model` (`rugnux -o refined data.mtz model.cif`, +`rugnux -o refined --model model.cif data.mtz`). A restraint dictionary for a ligand can be given among the inputs as well (`--restraints`) ([Refining a model against structure factors](RUGNUX_MODEL_AND_REFERENCE.md#refining-a-model-against-structure-factors-rugnux---mode-refine)). diff --git a/image_analysis/structure_refinement/RefinementRestraints.cpp b/image_analysis/structure_refinement/RefinementRestraints.cpp index 613c1b39a..d35c89910 100644 --- a/image_analysis/structure_refinement/RefinementRestraints.cpp +++ b/image_analysis/structure_refinement/RefinementRestraints.cpp @@ -244,7 +244,9 @@ int AddSugarLinks(gemmi::Structure &st, const gemmi::MonLib &monlib) { for (gemmi::Chain &ch2 : model.chains) for (gemmi::Residue &r2 : ch2.residues) for (gemmi::Atom &a2 : r2.atoms) { + // two conformers (A with B) are never bonded; a blank altloc pairs with any if (&r1 == &r2 || a1.is_hydrogen() || a2.is_hydrogen() || recorded.count({&a1, &a2}) || + (a1.altloc && a2.altloc && a1.altloc != a2.altloc) || a1.pos.dist(a2.pos) > SUGAR_BOND_MAX || std::get<0>(monlib.match_link(r1, a1.name, a1.altloc, r2, a2.name, a2.altloc)) == nullptr) continue; diff --git a/rugnux/rugnux_cli.cpp b/rugnux/rugnux_cli.cpp index f5fc3c92e..bba857edf 100644 --- a/rugnux/rugnux_cli.cpp +++ b/rugnux/rugnux_cli.cpp @@ -1858,6 +1858,10 @@ int RugnuxCli::Parse(int argc, char **argv) { } } + if (!restraint_files.empty() + && (!model || !(mode == RugnuxMode::Refine || (mode == RugnuxMode::MX && refine_model)))) + logger.Warning("The restraint files are ignored: this run refines no model (no model given, --no-refine, " + "or a --mode without refinement)"); for (const std::string &path : restraint_files) { try { std::ifstream f(path, std::ios::binary); diff --git a/tests/RefinementTest.cpp b/tests/RefinementTest.cpp index a83a09607..b485828cd 100644 --- a/tests/RefinementTest.cpp +++ b/tests/RefinementTest.cpp @@ -527,6 +527,40 @@ TEST_CASE("RefinementRestraints_glcnac", "[Refinement]") { CHECK(glycosidic == 1); } +// A GlcNAc on an Asn, both in two conformers A and B with no LINK record: the sugar links join A to A and B to B, +// never the C1 of one conformer to the ND2 of the other, though that pair is within bonding distance too. +TEST_CASE("RefinementRestraints_sugar_links_altloc", "[Refinement]") { + const gemmi::UnitCell cell(50, 55, 60, 90, 90, 90); + gemmi::Structure st = residue_crystal({"ASN", "NAG"}, cell, "P 1", 5); + std::vector &res = st.models[0].chains[0].residues; + // the ring moved for its C1 to be 1.43 A from ND2, and its O1 removed + const gemmi::Position shift = res[0].find_atom("ND2", '*')->pos + gemmi::Position(1.43, 0, 0) + - res[1].find_atom("C1", '*')->pos; + for (gemmi::Atom &a : res[1].atoms) + a.pos += shift; + std::erase_if(res[1].atoms, [](const gemmi::Atom &a) { return a.name == "O1"; }); + // conformer B of both residues 0.6 A off A: C1(A)-ND2(B) is 1.55 A + for (gemmi::Residue &r : res) { + std::vector atoms; + for (gemmi::Atom a : r.atoms) { + a.occ = 0.5f; + a.altloc = 'A'; + atoms.push_back(a); + a.altloc = 'B'; + a.pos += gemmi::Position(0, 0.6, 0); + atoms.push_back(a); + } + r.atoms = atoms; + } + const RefinementTopology topo = BuildRefinementTopology(st); + CHECK(topo.sugar_links == 2); + int same = 0, mixed = 0; + for (const gemmi::Connection &c : st.connections) + (c.partner1.altloc == c.partner2.altloc ? same : mixed)++; + CHECK(same == 2); + CHECK(mixed == 0); +} + // A zinc bound by four cysteines (the dictionary's own ZN-CYS link) and a magnesium by six waters (links made from // the library's metal-site statistics), both from LINK records: the bonds come out at the expected distances, // and a metal set off its site returns there under them alone.