Files
leonarski_f 63f5f96132
Build Packages / Create release (push) Successful in 9s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m19s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 10m26s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 19m33s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m17s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 23m28s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 24m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 27m30s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m4s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 29m19s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 29m31s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 23m19s
Build Packages / Generate python client (push) Successful in 28s
Build Packages / Build documentation (push) Successful in 1m22s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 24m39s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 29m40s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 28m31s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 24m33s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 27m45s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 29m25s
Build Packages / Unit tests (push) Successful in 1h35m24s
Build Packages / Validation Battery (push) Successful in 35m45s
v1.0.0-rc.180 (#91)
* Rugnux: A placed model is refined by default - restrained maximum-likelihood refinement on the GPU (CPU without one), writing `<prefix>_refined_model.cif`, `<prefix>_refined_maps.mtz` and the difference-map blobs in `<prefix>_blobs.json`; `--no-refine` skips it.
* Rugnux: `--mode refine` refines a model against merged structure factors from an MTZ or mmCIF file.
* Rugnux: The embedded restraint dictionary covers amino acids, nucleotides including common modified RNA nucleotides, common cofactors, crystallisation additives, waters and ions, with metal sites restrained from the model's LINK records.
* Rugnux: A model or reference file can be given among the inputs in any order, recognised by its contents.
* Rugnux: The geometry refinement algorithm option is now `-r, --geom-refine` (was `--refine`).
* Rugnux: Serial stills resolve the indexing ambiguity from the data when no model or reference is given, reject merge outliers by default, follow the run's measured rocking curve in prediction and partiality (also in `--mode scale`), and index reproducibly on the GPU.
* Rugnux: Reflections touching the beam-stop shadow are not integrated, reflections coarser than the low-resolution limit are merged and written (but kept out of the scale fit), and the polarisation plane is measured more reliably.
* Rugnux: Small-molecule runs report unit-cell e.s.d.s, in a SHELX `.ins` beside the `.hkl` and in the mmCIF.
* jfjoch_broker: Live Rugnux refines the uploaded model after placement; the web frontend's Rugnux live page has a hero panel with resolution, ISa, space group, placement and refined R-work/R-free, and its Mol* viewer shows the refined model and maps.
* Documentation: A new front page with download pages for Rugnux and the viewer, and the technical reference reorganised below it.
* Build: The fast-feedback indexer is part of the source tree instead of being downloaded at build time.

Reviewed-on: #91
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-27 13:18:42 +01:00

134 lines
6.3 KiB
Python

#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
# SPDX-License-Identifier: GPL-3.0-only
"""Copy the subset of the CCP4 Monomer Library (https://github.com/MonomerLibrary/monomers, LGPL-3.0)
that rugnux's restrained refinement carries in its binary into this directory.
update_monomers.py /path/to/monomers
COMPOUNDS below is THE list: a compound named there is restrained by the refinement, everything else
is held fixed. To add one, add its code and run this again; CMake embeds every .cif of this directory
(MonomerLibrary.cpp), so nothing else needs to change.
The compound files are copied verbatim. links_and_mods.cif is cut down to the links and modifications
that can apply to these compounds (the polymer links, the termini, the disulfide, ...), and ener_lib.cif
to its atom-type table (_lib_atom: the van der Waals and ion radii and the hydrogen-bond types).
metals.json, the library's statistics of metal-ligand distances, becomes metals.cif: for each metal ion of
COMPOUNDS and each donor element of METAL_LIGANDS, the distance per coordination number (the restraints of
metal sites the links of links_and_mods.cif do not describe).
Requires the gemmi Python module."""
import json
import os
import shutil
import sys
import gemmi
AMINO_ACIDS = ["ALA", "ARG", "ASN", "ASP", "CYS", "GLN", "GLU", "GLY", "HIS", "ILE",
"LEU", "LYS", "MET", "PHE", "PRO", "SER", "THR", "TRP", "TYR", "VAL", "MSE"]
NUCLEOTIDES = ["DA", "DC", "DG", "DT", "A", "C", "G", "U"]
# The modified nucleotides of tRNA and rRNA most often met, polymer residues joined by the same backbone link.
MODIFIED_NUCLEOTIDES = ["PSU", "5MC", "1MA", "OMG", "OMC", "OMU", "H2U", "M2G", "7MG", "2MG", "5MU"]
NUCLEOTIDE_LIGANDS = ["ATP", "ADP", "AMP", "GTP", "GDP", "GMP"]
# The cofactors most often met, and the oxygen a heme iron binds. (Not carbon monoxide: CMO.cif has C-O at 1.25 A,
# where bound CO is near 1.15 A.)
COFACTORS = ["NAD", "NAI", "NAP", "NDP", "FAD", "FMN", "HEM", "HEC", "SAM", "SAH", "OXY"]
ADDITIVES = ["DMS", "PEG", "PGE", "PG4", "1PE", "GOL", "EDO", "SO4", "PO4", "ACT", "MPD"]
WATER_AND_IONS = ["HOH", "NA", "K", "MG", "CA", "ZN", "MN", "FE", "FE2", "NI", "CU", "CO", "CD",
"CL", "BR", "IOD"]
COMPOUNDS = (AMINO_ACIDS + NUCLEOTIDES + MODIFIED_NUCLEOTIDES + NUCLEOTIDE_LIGANDS + COFACTORS + ADDITIVES +
WATER_AND_IONS)
# The donor elements of metal sites whose distances metals.cif carries.
METAL_LIGANDS = ["O", "N", "S"]
# Groups of the polymers above; links and modifications of other groups (sugars) are left out.
GROUPS = {".", "peptide", "P-peptide", "M-peptide", "DNA/RNA", "NON-POLYMER"}
def compound_path(lib, code):
return os.path.join(lib, code[0].lower(), code + ".cif")
def applies(comp, group):
return (comp == "." or comp in COMPOUNDS) and group in GROUPS
def trim_links_and_mods(lib, out):
doc = gemmi.cif.read(os.path.join(lib, "links_and_mods.cif"))
links = doc.find_block("link_list").find("_chem_link.", ["id", "comp_id_1", "mod_id_1", "group_comp_1",
"comp_id_2", "mod_id_2", "group_comp_2", "name"])
mods = doc.find_block("mod_list").find("_chem_mod.", ["id", "name", "comp_id", "group_id"])
keep_links = [list(r) for r in links if applies(r[1], r[3]) and applies(r[4], r[6])]
keep_mods = [list(r) for r in mods if applies(r[2], r[3])]
keep = {"link_" + r[0] for r in keep_links} | {"mod_" + r[0] for r in keep_mods}
new = gemmi.cif.Document()
for name, tag, rows in (("link_list", "_chem_link.", keep_links), ("mod_list", "_chem_mod.", keep_mods)):
block = new.add_new_block(name)
old = doc.find_block(name).find_loop_item(tag + "id").loop
loop = block.init_loop(tag, [t[len(tag):] for t in old.tags])
for r in rows:
loop.add_row(r)
for block in doc:
if block.name in keep:
new.add_copied_block(block)
new.write_file(out)
return len(keep_links), len(keep_mods)
def trim_ener_lib(lib, out):
doc = gemmi.cif.read(os.path.join(lib, "ener_lib.cif"))
atoms = doc[0].find_loop_item("_lib_atom.type").loop
new = gemmi.cif.Document()
block = new.add_new_block(doc[0].name)
loop = block.init_loop("_lib_atom.", [t[len("_lib_atom."):] for t in atoms.tags])
for i in range(atoms.length()):
loop.add_row([atoms[i, j] for j in range(atoms.width())])
new.write_file(out)
def trim_metals(lib, out):
"""metals.json -> metals.cif: one row per metal ion of COMPOUNDS, ligand element and coordination number,
with the mean distance, its standard deviation and the number of sites behind it."""
with open(os.path.join(lib, "metals.json")) as f:
table = json.load(f)["metal_coordination"]
metals = set()
for code in WATER_AND_IONS:
for atom in gemmi.make_chemcomp_from_block(gemmi.cif.read(compound_path(lib, code))[-1]).atoms:
if atom.el.is_metal:
metals.add(atom.el.name)
new = gemmi.cif.Document()
block = new.add_new_block("metal_coordination")
loop = block.init_loop("_metal_coordination.", ["metal", "ligand", "coordination", "distance", "std", "count"])
n = 0
for metal in sorted(metals):
for ligand in METAL_LIGANDS:
for row in table.get(metal, {}).get(ligand, []):
loop.add_row([metal, ligand, str(row["coord"]), "%.4f" % row["mean"], "%.4f" % row["std"],
str(row["count"])])
n += 1
new.write_file(out)
return n
def main():
if len(sys.argv) != 2:
sys.exit(__doc__)
lib = sys.argv[1]
here = os.path.dirname(os.path.abspath(__file__))
for f in os.listdir(here):
if f.endswith(".cif"):
os.remove(os.path.join(here, f))
for code in COMPOUNDS:
shutil.copyfile(compound_path(lib, code), os.path.join(here, code + ".cif"))
n_links, n_mods = trim_links_and_mods(lib, os.path.join(here, "links_and_mods.cif"))
trim_ener_lib(lib, os.path.join(here, "ener_lib.cif"))
n_metal_rows = trim_metals(lib, os.path.join(here, "metals.cif"))
shutil.copyfile(os.path.join(lib, "COPYING"), os.path.join(here, "COPYING"))
print(f"{len(COMPOUNDS)} compounds, {n_links} links, {n_mods} modifications, {n_metal_rows} metal distances")
if __name__ == "__main__":
main()