Files
leonarski_fandClaude Opus 5.5 676979560f Unexplained blobs: the anomalous difference map's peak height at each, in the report and live
Each blob of the refined mFo-DFc map now carries the anomalous difference map's peak height
(|F+| - |F-| on the model's phases less 90 degrees, in its rms): its highest point within 1 A of
the blob's peak, not the value at the peak. The two maps are on grids of their own (up to ~0.7 A
apart at 2 A) and the anomalous scatterer need not be the difference density's highest point;
1 A, half the shortest metal-ligand bond, keeps a neighbouring modelled S or metal from being read
as the blob's own. NaN (null in _blobs.json) where the merge kept no Bijvoet pairs, instead of 0.
The ION rule reads the same value.

The report's blob list shows it only where the SUMMARY's Anomalous row says "signal present"
(AnomalousRow, factored out of the summary so both read one decision); without the signal it is
noise and is left out. --mode refine has no merge to judge on and leaves it out.

Live: rugnux_live_blob.anomalous_sigma in /rugnux/status (C++ model, python docs, frontend client
and Redoc regenerated); the Rugnux page's Details get a blob table with an "anom σ" column and the
structure viewer's peak label an "anom" reading, both only where anomalous_signal is set.

Tests: FindDensityBlobs_AnomalousPeakNearTheBlob (a scatterer 0.7 A off the difference peak read
at its own height; no map, no reading), Refinement_blob_anomalous_peak (a model missing a zinc and
a water, data with the zinc's f'': zinc blob 32 sigma, water -0.1), report and live checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
2026-11-15 12:56:22 +01:00

49 lines
2.6 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <cmath>
#include <string>
#include <vector>
#include "gemmi/grid.hpp"
#include "gemmi/model.hpp"
#include "../../common/JFJochMessages.h"
// What a model leaves unexplained: the connected regions of positive mFo-DFc density above a cutoff ("blobs"),
// each placed beside the model, measured and given a likely reading - a water, an ion, something ligand-sized,
// or an error of the model itself (a misplaced or missing atom, an alternative conformation).
//
// The readings are rules on what is measured, meant to point a person at the density, not to identify a
// compound: a blob called LIGAND is density of ligand size and shape where the model has nothing, which a
// buffer molecule or an unmodelled side chain can be as well as the compound that was soaked.
struct DensityBlob {
enum class Kind { Water, Ion, Ligand, ModelError, Unassigned };
Kind kind = Kind::Unassigned;
gemmi::Position centroid; // the copy nearest the model
double peak_sigma = 0; // the highest point, in the map's rms
double volume = 0; // A^3 above the cutoff
double score = 0; // the density above the cutoff integrated, sigma A^3
double nearest_atom_distance = 0;
std::string nearest_atom; // e.g. "OG1 THR A42"
int polar_contacts = 0; // N or O of the model at 2.4-3.4 A
int metal_contacts = 0; // N, O or S of the model at 1.8-2.6 A
// The anomalous difference map's peak height within 1 A of the blob's peak, in its rms; NaN where there is none
double anomalous_sigma = NAN;
};
const char *DensityBlobKindName(DensityBlob::Kind kind);
// The blobs as the end message carries them to the writer, for <prefix>_blobs.json.
DensityBlobsMessage DensityBlobsToMessage(const std::vector<DensityBlob> &blobs);
// The blobs of `difference` (an mFo-DFc map of the whole cell, rms `rms`) above 3 sigma that peak above 4 sigma,
// strongest (by score) first. `model`: what the map was made from, in the map's cell. `anomalous`: the anomalous
// difference map on any grid of the same cell, or null. Following the flood fill of Coot's unmodelled blobs as
// gemmi implements it (find_blobs_by_flood_fill).
std::vector<DensityBlob> FindDensityBlobs(const gemmi::Grid<float> &difference, double rms, const gemmi::Structure &model,
double d_min, const gemmi::Grid<float> *anomalous = nullptr,
double anomalous_rms = 0);