Files
leonarski_f 4809c1622c
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 28m46s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 32m5s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 39m44s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m30s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 31m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m29s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m51s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m7s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m6s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m44s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 33m22s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 34m6s
Build Packages / Unit tests (push) Successful in 1h2m47s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 35m59s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 34m8s
Build Packages / Validation Battery (push) Successful in 38m31s
v1.0.0-rc.187 (#98)
* Rugnux: Refinement several times faster, one protocol on the CPU and the GPU, parts of it on the Apple GPU; its random draws are the same on every platform.
* Rugnux: Refinement follows common practice: the free set decides only the restraint weights and the displacement model (isotropic, TLS or anisotropic, by Hamilton's test), everything else is decided on the working set; lower R-free for placed and predicted models.
* Rugnux: Restraint dictionaries via `--restraints` (or among the inputs) and more built-in ligands; a model whose space group is a subgroup of the data's is refined in its own group; reflections plus a model select `--mode refine` on their own.
* Rugnux: `-C` fixes the crystal system on the axes as typed; `-S` alone fixes the space group only, the cell is still found and reduced; a space group or cell stored in the input file is ignored, with a line in the log.
* Rugnux: More reliable multi-sweep merging; `--mode scale` merges several stills runs as one; `_plot.txt` and the report name each input; a second crystal form is reported for stills given a cell.
* jfjoch_broker (experimental): Live Rugnux on FPGA detectors (JUNGFRAU) takes the same path as a DECTRIS stream, rotation and serial alike, model step included, with analysis threads per GPU; frames waiting for the analysis can be viewed; no host stage drops a frame - a source faster than the analysis is held at the card.
* jfjoch_broker: Summation of more than 256 frames per image is split between the card and the host (`summation_mode` is then `hybrid`), and live Rugnux runs on such collections; pedestal runs take a receiver of their own.
* jfjoch_broker (experimental): `stills_downsample` analyses 1 of every N serial images (chosen by a hash; the first 2000 all; the others written without analysis; reset to 1 by `/initialize`); `max_spot_count` left out means 250 for per-image indexing and up to 1000 for live stills; the live status gives the merge before the model work, the fitted resolution and the anomalous peak height of each unexplained blob.
* jfjoch_broker: Without a `pcie` entry the broker runs on a mock of the card instead of the HLS simulation; its spot, ROI and azimuthal results are zero then.
* Web frontend: Redesigned Rugnux live page; Vite 8, TypeScript 6, Mol* 5.13 and dependency security updates.
* Tools: `jfjoch_fpga_stills_test` measures live stills on the cards with a stored dataset; `jfjoch_fpga_test` loses the HLS-simulation option.
* Other: FFTW no longer fetched or linked (the CPU FFT indexer keeps the name `FFTW`); PCIe driver now GPL-2.0-or-later and third-party notices complete; several crash fixes.

Reviewed-on: #98
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-19 20:49:28 +01:00

167 lines
8.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).
These three are modified versions of library files, so each is written with a comment at its top that says
so, from what and when (the notice the library's LGPL-3.0 asks of a modified copy).
Requires the gemmi Python module."""
import datetime
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"]
# The chromophores of the photoreceptors time-resolved crystallography studies, with the library's links to the
# protein where it has them: retinal (its Schiff base to a lysine, LYS-RET), the p-coumaric acid of the
# photoactive yellow protein (its thioester to a cysteine is not in the library), the GFP-type chromophores
# (CRO-pept), and the bilins of the phytochromes (phycocyanobilin's thioether to a cysteine, CYS-CYC). The flavins of
# the LOV domains and photolyases are among the COFACTORS.
CHROMOPHORES = ["RET", "HC4", "CRO", "GYS", "CR2", "NRQ", "BLA", "LBV", "CYC"]
# N-acetyl-D-glucosamine, beta (NAG) and alpha (NDG): the lysozyme ligand, alone or as chitobiose/chitotriose.
SUGARS = ["NAG", "NDG"]
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 + CHROMOPHORES +
SUGARS + ADDITIVES + WATER_AND_IONS)
# The donor elements of metal sites whose distances metals.cif carries.
METAL_LIGANDS = ["O", "N", "S"]
# Groups of the compounds above: the polymers, and the pyranoses for the glycosidic links (and that of a sugar to
# Asn, Ser or Thr); links and modifications of other groups are left out.
GROUPS = {".", "peptide", "P-peptide", "M-peptide", "DNA/RNA", "NON-POLYMER", "pyranose"}
MODIFIED = {
"links_and_mods.cif": "links_and_mods.cif, cut down to the links and modifications that can apply to the "
"compounds of update_monomers.py",
"ener_lib.cif": "ener_lib.cif, cut down to its atom-type table (_lib_atom)",
"metals.cif": "metals.json, converted to CIF and cut down to the metal ions of update_monomers.py and their "
"donor elements",
}
def write_modified(doc, out):
"""Write a cut-down library file with the notice of the modification at its top."""
doc.write_file(out)
with open(out) as f:
text = f.read()
notice = ("# Modified from the CCP4 Monomer Library (https://github.com/MonomerLibrary/monomers),\n"
"# LGPL-3.0-only, see COPYING: " + MODIFIED[os.path.basename(out)] + ".\n"
"# Generated by update_monomers.py on " + datetime.date.today().isoformat() + ".\n")
with open(out, "w") as f:
f.write(notice + text)
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)
write_modified(new, 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())])
write_modified(new, 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
write_modified(new, 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()