RESULT-CHANGING: Solvent: waters and ions relabelled by their shell and their density, metal records decided once
The solvent audit gains the evidence the species need beyond the shell, and the build acts on it: - Electrons: the site's own density fitted to 2mFo-DFc with the neighbours' held (one amplitude at the environment's B, the other atoms' IT92 densities to the data's resolution subtracted out to 4.5 A), on the scale of the macromolecule's C/N/O nearby (not the waters', which read about half their model's height). Depositions read Mg 11, Na 10, Cl 19, K 21-23, Ca 22-26, Zn 33, waters 4-6. Term: log-normal against the species' expectation (an ion at full occupancy, a water at the model's waters' median) in the waters' spread. An ion is read where this fit puts it (within 0.6 A), not where its label's restraints hold it; a plain 2mFo-DFc maximum was tried first and pulled ions into their merged hydration density (1HR2 A5 1.7 A from a water). - Anomalous: f'' per species at the wavelength (gemmi fprime, vendored fprime.cpp, Larch-derived, notice added), on the scale of the model's S and P, Gaussian in the map's rms - replacing the fixed 4 sigma. - N7: a divalent ion on a purine N7 more than 1.0 A out of the base plane, or not 3.5-3.9 A from its O6/N6 (NAR 2017), costs Mg and Ca 2 per such ligand. - Halides: a missing donor costs Cl 0.5 (as a missing ligand does Mg/Na/Ca) and the positive-group requirement is gone - halides bind at hydrophobic surfaces too; the density decides. - The build relabels a water or single-atom ion (no altloc, once, with density of its own) whose best species is another, not ambiguously: residue, element, atom name, scattering charge; its metal records replaced by inner-sphere ones (rugnux_metalcN). REFINE_SOLVENT_RELABELLED, per-site reasons in the report and the JSON. - Metal LINK records left as contacts are decided once, on the model as given, and kept through the build's refinements (MetalRecordKey, BuildRefinementTopology outer_records) - the P2 ratchet. 1HR2 deposited-model audit vs Cat_Wiz / NAR 2017: the eight hexahydrated Mg A14-A27 MG; none of the ten speculative A51-A64 supported as Mg (6 water, 4 Cl?/water?); A5 ambiguous Na/Mg (NAR 2017: probably monovalent). Build with relabelling vs without (same binary, deposited SF): R-free 1hr2 -0.0019, 2r8s -0.0021, 7l6j -0.0016, 8agq -0.0006, 36gk 0, 8sa8 +0.0001, 193l +0.0003, 6hwj +0.0008. Relabelled: 1hr2 18 (14 speculative Mg -> water), 8agq 4 Na -> water, 8sa8 Mg -> Na at Glu-bidentate 2.3-2.5 A shells; waters -> Cl at donor sites. Tests: SolventSites_electrons_decide_halide_from_water, SolventSites_N7_out_of_plane, SolventBuild_relabel, the decided-once records in RefinementRestraints_metal_links_outer_sphere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQqN9qRD57vnShzTC37
This commit is contained in:
1 parent
ae500953e8
commit
47f4a603a6
22 files changed
+3920
-115
No files matched your search
@@ -62,6 +62,7 @@ These live in the source tree (see the path) rather than being fetched; traccc a
|
||||
| [fast-feedback-indexer](https://github.com/paulscherrerinstitute/fast-feedback-indexer) (commit a94fd4f) | `image_analysis/indexing/fast-feedback-indexer/` | PSI | BSD-3-Clause | [fast-feedback-indexer.txt](licenses/fast-feedback-indexer.txt) |
|
||||
| [GEMMI](https://github.com/project-gemmi/gemmi) | `gemmi_gph/` | Global Phasing Ltd. | MPL-2.0 | [gemmi.txt](licenses/gemmi.txt) |
|
||||
| [CCP4 Monomer Library](https://github.com/MonomerLibrary/monomers) (subset: restraint dictionary data) | `image_analysis/structure_refinement/monomers/` | CCP4 / the Monomer Library authors (Vagin et al.) | LGPL-3.0-only | [ccp4-monomer-library.txt](licenses/ccp4-monomer-library.txt) |
|
||||
| [Larch](https://github.com/xraypy/xraylarch) (its Cromer-Liberman routines, as GEMMI ports them) | `gemmi_gph/fprime.cpp` | Matthew Newville, The University of Chicago, et al. | MIT | [larch.txt](licenses/larch.txt) |
|
||||
| [PEGTL](https://github.com/taocpp/PEGTL) | `gemmi_gph/gemmi/third_party/tao/` | Dr. Colin Hirsch and Daniel Frey | MIT | [pegtl.txt](licenses/pegtl.txt) |
|
||||
| [sajson](https://github.com/chadaustin/sajson) | `gemmi_gph/gemmi/third_party/sajson.h` | Chad Austin | MIT | [sajson.txt](licenses/sajson.txt) |
|
||||
| [fast_float](https://github.com/fastfloat/fast_float) | `gemmi_gph/gemmi/third_party/fast_float.h` | The fast_float authors (Daniel Lemire et al.) | Apache-2.0 OR MIT OR BSL-1.0 | [fast-float.txt](licenses/fast-float.txt) |
|
||||
|
||||
+11
-1
@@ -651,7 +651,17 @@ able to identify metal atoms in protein structures?" (2003), Acta Cryst. D59, 32
|
||||
its outlier bound are CheckMyMetal's: H. Zheng, D. R. Cooper, P. J. Porebski, I. G. Shabalin, K. B. Handing
|
||||
and W. Minor, "CheckMyMetal: a macromolecular metal-binding validation tool" (2017), Acta Cryst. D73, 223-233
|
||||
[doi:10.1107/S2059798317001061](https://doi.org/10.1107/S2059798317001061). The score that combines them is
|
||||
our own.
|
||||
our own. The divalent ion's place on a purine N7 - in the base's plane, 3.5-3.9 Å from its O6 or N6 - is the test of
|
||||
Leonarski et al. (2017, above). A light ion is told from a water by a density above the waters', as Echols et al.
|
||||
(2014, above) flag one; a halide's few or no donors are allowed as Z. Dauter and M. Dauter describe halides binding
|
||||
also at hydrophobic surfaces, "Entering a new phase: using solvent halide ions in protein structure determination"
|
||||
(2001), Structure 9, R21-R26 [doi:10.1016/S0969-2126(01)00565-2](https://doi.org/10.1016/S0969-2126(01)00565-2).
|
||||
The anomalous scattering expected of each species is f″ at the data's wavelength by D. T. Cromer and D. A.
|
||||
Liberman, "Anomalous dispersion calculations near to and on the long-wavelength side of an absorption edge"
|
||||
(1981), Acta Cryst. A37, 267-268 [doi:10.1107/S0567739481000600](https://doi.org/10.1107/S0567739481000600),
|
||||
with the corrections of L. Kissel and R. H. Pratt, "Corrections to tabulated anomalous-scattering factors"
|
||||
(1990), Acta Cryst. A46, 170-175 [doi:10.1107/S0108767389010718](https://doi.org/10.1107/S0108767389010718), as
|
||||
GEMMI computes them (its port of the Larch routines).
|
||||
|
||||
## Software and computing methods
|
||||
|
||||
|
||||
@@ -191,7 +191,9 @@ would pull the ion onto that atom; it stays a contact instead. The coordination
|
||||
records the metal has within its inner sphere, plus the bonds its own residue's dictionary gives it (a heme iron's four pyrrole nitrogens) - interpolated linearly between two tabulated coordination numbers (rows resting on at least 20 sites
|
||||
count; σ is the row's standard deviation, at least 0.02 Å). Only the bond is restrained, not
|
||||
the angles at the metal. A contact without a record stays a repulsion, and a record to a symmetry mate is
|
||||
left out, as every bond to a symmetry mate is. The records are written out with the refined model as they were
|
||||
left out, as every bond to a symmetry mate is. Which records stay contacts is decided once, on the model as given:
|
||||
the solvent build's later refinements keep that decision rather than judge again distances the refinement has
|
||||
moved (a record at 2.50 Å refused, the ion slid to 2.39 Å, accepted the next round). The records are written out with the refined model as they were
|
||||
read, without the names of the links made here. The rmsd of these bonds - with the dictionary's own bonds of
|
||||
a metal within a ligand, a heme iron's to its porphyrin - is reported apart from the covalent bonds'
|
||||
(`REFINE_RMSD_METAL_BONDS`).
|
||||
@@ -301,8 +303,9 @@ person at the density; they do not identify a compound.
|
||||
### 15.10 The solvent audit
|
||||
|
||||
Every water and every single-atom ion of the refined model (and, with `--refine-score-only`, of the model as
|
||||
given) is measured in its surroundings and scored as each of water, Mg²⁺, Na⁺, K⁺, Ca²⁺ and Cl⁻ (NH₄⁺ is
|
||||
scored too, and only reported). It is an audit: the model is not changed, and nothing else reads it.
|
||||
given) is measured in its surroundings and its density and scored as each of water, Mg²⁺, Na⁺, K⁺, Ca²⁺ and Cl⁻
|
||||
(NH₄⁺ is scored too, and only reported). The audit changes nothing; the solvent build below reads it to relabel
|
||||
sites.
|
||||
|
||||
**What is measured.** The model's N and O atoms around the site, symmetry mates included, counted in the
|
||||
coordination bands of Cat_Wiz - 1.9-2.3 Å (Mg-like), 2.3-2.6 Å (Na, Ca), 2.6-3.2 Å (K, water) - and in the
|
||||
@@ -316,17 +319,36 @@ bond-valence sum $V = \sum_j q_j \exp((R_0 - d_j)/0.37)$ over the N and O within
|
||||
($R_0$ of Brese & O'Keeffe, $q_j$ the neighbour's occupancy) with its normalised vector sum (CheckMyMetal's
|
||||
nVECSUM), and the 2mFo-DFc, mFo-DFc and anomalous maps at the site, in their rms.
|
||||
|
||||
**The electrons a site shows.** The site's own density is fitted to 2mFo-DFc with its neighbours' held - a local
|
||||
real-space fit of one amplitude at a B tied to its surroundings: the map at points 0.3 Å apart within 1.0 Å of the
|
||||
site, put on the model's scale, less the density the model's other atoms put there (each atom's IT92 density to
|
||||
the data's resolution at its B, to 4.5 Å), against a water's density (O with its two H) at the environment's B
|
||||
(the mean B of the N and O within 3.5 Å, as CheckMyMetal compares a metal's with its ligands'), least squares.
|
||||
The amplitude, in waters, is the electrons it shows, and counted apart from the neighbours' that merge with it at
|
||||
moderate resolution. The map's scale per model unit is the median, over the macromolecule's C, N and O within
|
||||
6 Å (or all of them where fewer than three are), of each atom's height in the map over what the model puts there -
|
||||
not the waters', whose occupancy is the model's guess (the depositions' waters show half the density their model
|
||||
gives). An **ion** - whose label's restraints may hold it off its density - is read where that fit puts it,
|
||||
within 0.6 Å of its modelled position (its shell, bands and bond valences are measured from there); a water where
|
||||
it is modelled. On the refine and open arms the depositions' ions read Mg 11, Na 10, Cl 19, K 21-23, Ca 22-26 and
|
||||
Zn 33 (median), the waters 4-6.
|
||||
|
||||
**The anomalous signal a site would show.** For each species, f″ at the data's wavelength (Cromer-Liberman, with
|
||||
the corrections of Kissel & Pratt, as GEMMI computes it) at the environment's B, put on the scale of the anomalous
|
||||
map by least squares on the model's S and P (at least three); without an anomalous map, or nothing to scale it
|
||||
by, the term is left out.
|
||||
|
||||
**The score.** For each species, a plain sum of terms in log units:
|
||||
|
||||
| Term | What it is |
|
||||
|---|---|
|
||||
| first shell | the neighbours in the species' band against the coordination number it holds (Mg 6, Na 5-6, K 6-10, Ca 6-8, Cl 3-5, NH₄⁺ 4), quadratic; for water only more than four, or none at all, costs; for Mg, Na and Ca a missing ligand costs little (0.5), as the model may simply not have that water |
|
||||
| first shell | the neighbours in the species' band against the coordination number it holds (Mg 6, Na 5-6, K 6-10, Ca 6-8, Cl 3-5, NH₄⁺ 4), quadratic; for water only more than four, or none at all, costs; for Mg, Na, Ca and Cl a missing ligand costs little (0.5), as the model may simply not have that water - and a halide binds at hydrophobic surfaces too, with few donors or none (Dauter & Dauter 2001), where its electrons and its anomalous signal tell it from a water |
|
||||
| distances | for Mg, each neighbour in the band against Mg-O 2.07 ± 0.04 Å, Mg-N 2.19 ± 0.08 Å; for the others, whose distances are spread over their bands, the band is all there is |
|
||||
| contacts it does not make | 2 per N or O closer than the species' shell (closer than 2.9 Å for Cl), and for Mg per N or O in its exclusion zone 2.3-3.4 Å |
|
||||
| chemistry | a cation: 2 per donor-only neighbour in its shell and per positive group within 3.5 Å; Cl: 2 per acceptor-only neighbour, per negative group within 3.2 Å, and 2 where there is neither a positive group nor a donor N within 3.5 Å; water: 2 per hydrogen bond beyond two donated or two accepted (neighbours at 2.6-3.4 Å) |
|
||||
| contacts it does not make | 2 per N or O closer than the species' shell (closer than 2.9 Å for Cl), and for Mg per N or O in its exclusion zone 2.3-3.4 Å; for Mg and Ca 2 per first-shell purine N7 the site is more than 1.0 Å out of the plane of, or not 3.5-3.9 Å from the base's O6 or N6 (Leonarski et al. 2017) |
|
||||
| chemistry | a cation: 2 per donor-only neighbour in its shell and per positive group within 3.5 Å; Cl: 2 per acceptor-only neighbour and per negative group within 3.2 Å; water: 2 per hydrogen bond beyond two donated or two accepted (neighbours at 2.6-3.4 Å) |
|
||||
| bond valence | for a cation, $V$ against its charge $z$, Gaussian with a spread of $0.25z$ widened by the neighbours' distance errors, and the vector sum against CheckMyMetal's outlier bound 0.23 |
|
||||
| electrons | where the difference map at the site is above +3 σ, +1 for the species with more electrons than the label (18 against 10) and -1 for the others; below -3 σ the reverse; in between -0.5 for a species of another electron count, as B and occupancy can hide eight electrons |
|
||||
| anomalous | an anomalous peak of 4 σ or more: +2 for K, Ca and Cl, -2 for the others |
|
||||
| electrons | the electrons the site shows against those the species would (its density's height over a water's at the environment's B: Mg²⁺ and Na⁺ about 11, K⁺, Ca²⁺ and Cl⁻ about 20) - an ion at full occupancy, a water as the model's waters show (their median) - log-normal with the spread of the waters' (an ion's occupancy and order vary as much), at least that of the map's calibration. A site as dense as a full 10-electron scatterer is so more than a typical water, as Echols et al. flag a light ion by a 2mFo-DFc above the waters' mean; where the density is weak the term tells little, and the shell decides |
|
||||
| anomalous | the anomalous map at the site against what the species would show, Gaussian in the map's rms |
|
||||
|
||||
A site bound to another cation (closer than 2.6 Å) shares that cation's other ligands as neighbours - the
|
||||
cis waters of a Mg(H₂O)₆ are 2.9 Å apart - and those are left out of its score. **Coordinate error**: each
|
||||
@@ -339,17 +361,25 @@ the best species is another one, not ambiguously.
|
||||
|
||||
**Caveats.** The refined model's metal-site distances are restrained (§15.5) where its LINK records name
|
||||
the bonds, which pulls an ion's shell towards the label it carries - the first pitfall of every survey of
|
||||
ions in the PDB. `--mode refine --refine-score-only` audits the model as given instead. The electron count
|
||||
is read only from the residual difference density, which a B factor or an occupancy can absorb, and the map
|
||||
values are not yet compared with the neighbouring atoms'. Per site, everything above is in
|
||||
`<prefix>_solvent.json`; the counts are the `REFINE_SOLVENT_` keys of the report.
|
||||
ions in the PDB; the local fit reads the ion where its density puts it, but its ligands stay where the restraints
|
||||
held them. `--mode refine --refine-score-only` audits the model as given instead. The species are the six above:
|
||||
a site denser than any of them (a cacodylate's As, a heavier metal) is called the heaviest that fits worst least.
|
||||
Per site, everything above is in `<prefix>_solvent.json` (with `electrons`, `b_env`, `peak_shift_A`,
|
||||
`anomalous_expected`, `n7_ligands`, `n7_off_plane`); the counts are the `REFINE_SOLVENT_` keys of the report.
|
||||
|
||||
**The water build.** After the refinement, and to 2.8 Å (phenix.refine's ordered-solvent limit), waters are
|
||||
built and removed between refinements, as phenix.refine does in its macro-cycles: a round reads the refined
|
||||
model's maps, changes its waters, and refines the changed model again from the start; the round is kept where
|
||||
R-free is lower than before it, and the rounds stop when one changes nothing or after three. The atom
|
||||
list of a refinement is fixed, so each round is a refinement of its own. Waters only: no ion is placed or
|
||||
relabelled, and `--refine-score-only` builds nothing.
|
||||
**The solvent build.** After the refinement, and to 2.8 Å (phenix.refine's ordered-solvent limit), waters are
|
||||
built and removed and waters and ions relabelled between refinements, as phenix.refine builds waters in its
|
||||
macro-cycles: a round reads the refined model's maps and audit, changes its solvent, and refines the changed model
|
||||
again from the start; the round is kept where R-free is lower than before it, and the rounds stop when one changes
|
||||
nothing or after three. The atom list of a refinement is fixed, so each round is a refinement of its own.
|
||||
`--refine-score-only` builds nothing, and `--no-refine-solvent` turns the build off (the audit is still made).
|
||||
|
||||
- *Relabelled* is a water or a single-atom ion (no alternative conformer) whose best-supported species is another
|
||||
one, not ambiguously - a water becomes an ion, an ion water or another ion - once per site. It takes the
|
||||
species' residue name, element and atom name, and scatters as its ion (§15.2); its metal records go, and a metal
|
||||
gets a record for each N, O and S of its inner sphere in the model's own copy (within the library's distance plus
|
||||
0.33 Å, at the coordination of those within an octahedral site's), which the next refinement restrains as it
|
||||
restrains the model's own (§15.5).
|
||||
|
||||
- *Candidates* are the local maxima of mFo-DFc from 3 σ (phenix.refine's peak cutoff), each symmetry-equivalent
|
||||
set once, moved to the copy nearest the model. A peak closer than 1.2 Å to a model atom is that atom's own
|
||||
@@ -378,7 +408,8 @@ relabelled, and `--refine-score-only` builds nothing.
|
||||
carries its depositor's judgement.
|
||||
|
||||
`REFINE_SOLVENT_ADDED` and `REFINE_SOLVENT_REMOVED` count the waters added and still there and those of the model
|
||||
as given taken out; `REFINE_SOLVENT_NOT_SOLVENT` the not-solvent peaks of the final model's difference map;
|
||||
as given taken out, `REFINE_SOLVENT_RELABELLED` the sites relabelled (each, with its scores, in the report and the
|
||||
JSON); `REFINE_SOLVENT_NOT_SOLVENT` the not-solvent peaks of the final model's difference map;
|
||||
`REFINE_SOLVENT_BUILD_ROUNDS` the rounds kept. The model as given (`REFINE_R_FREE_START`, the `REFINE_SCORE_` terms) and the placement stage are the first refinement's; the refined model, its R-factors, geometry, maps and blobs are the last kept round's.
|
||||
|
||||
### 15.11 GPU and CPU
|
||||
@@ -404,8 +435,10 @@ What the refinement does not do yet - each a known gap, not a design choice:
|
||||
refined.
|
||||
- **NCS restraints**: copies are refined independently.
|
||||
- **Twin refinement**: the target is not a twinned one, also where the twin hypothesis' merge was written.
|
||||
- **Ion identification**: waters are built and removed (§15.10), but no ion is placed or relabelled; the solvent
|
||||
audit scores the waters and ions there are.
|
||||
- **Ion identification beyond the six species**: waters and ions are relabelled among water, Mg²⁺, Na⁺, K⁺, Ca²⁺
|
||||
and Cl⁻ (§15.10); NH₄⁺ is only reported, transition metals (Zn, Mn, ...) are measured but never relabelled, and no
|
||||
ion is placed at a peak that is not a water first. A site's hypotheses are compared by a local fit of its
|
||||
density, not by refining each in turn.
|
||||
- **Alternative conformations and occupancies**: existing conformers are refined in place; no occupancy is
|
||||
refined and no conformer is added.
|
||||
- **Rotamer and peptide-flip search**, and **Ramachandran restraints**.
|
||||
@@ -429,6 +462,9 @@ What the refinement does not do yet - each a known gap, not a design choice:
|
||||
- A. Blondel & M. Karplus, "New formulation for derivatives of torsion angles and improper torsion angles in molecular mechanics: elimination of singularities", *J. Comput. Chem.* **17** (1996), 1132-1141 (the torsion derivatives, §15.5).
|
||||
- M. M. Harding, "Geometry of metal-ligand interactions in proteins", *Acta Cryst.* **D57** (2001), 401-411, and "Small revisions to predicted distances around metal sites in proteins", *Acta Cryst.* **D62** (2006), 678-682; F. Leonarski, L. D'Ascenzo & P. Auffinger, "Mg2+ ions: do they bind to nucleobase nitrogens?", *Nucleic Acids Res.* **45** (2017), 987-1004 (the metal-site distances, §15.5).
|
||||
- R. W. Grosse-Kunstleve & P. D. Adams, "Algorithms for deriving crystallographic space-group information. II. Treatment of special positions", *Acta Cryst.* **A58** (2002), 60-65 (the site symmetry and the constraint of an atom on a special position, §15.5).
|
||||
- D. T. Cromer & D. A. Liberman, "Anomalous dispersion calculations near to and on the long-wavelength side of an absorption edge", *Acta Cryst.* **A37** (1981), 267-268, and L. Kissel & R. H. Pratt, "Corrections to tabulated anomalous-scattering factors", *Acta Cryst.* **A46** (1990), 170-175 (f″ at the data's wavelength, §15.10).
|
||||
- Z. Dauter & M. Dauter, "Entering a new phase: using solvent halide ions in protein structure determination", *Structure* **9** (2001), R21-R26 (halides at sites with few donors, §15.10).
|
||||
- N. Echols et al., "Automated identification of elemental ions in macromolecular crystal structures", *Acta Cryst.* **D70** (2014), 1104-1114 (a light ion flagged by its density above the waters', §15.10).
|
||||
- J. Nocedal, "Updating quasi-Newton matrices with limited storage", *Math. Comp.* **35** (1980), 773-782, and D. C. Liu & J. Nocedal, "On the limited memory BFGS method for large scale optimization", *Math. Program.* **45** (1989), 503-528 (the minimiser, §15.6).
|
||||
- A. T. Brünger, M. Karplus & G. A. Petsko, "Crystallographic refinement by simulated annealing: application to crambin", *Acta Cryst.* **A45** (1989), 50-61 (the starting weight from the ratio of the gradients, §15.7).
|
||||
- P. V. Afonine et al., "Towards automated crystallographic structure refinement with phenix.refine", *Acta Cryst.* **D68** (2012), 352-367 (weights chosen among refinements by R-free within geometry bounds, and the overall B moved into the atoms, §15.3, §15.7).
|
||||
|
||||
@@ -1206,8 +1206,9 @@ Where a model was placed and refined ([Refinement](RUGNUX_MODEL_AND_REFERENCE.md
|
||||
| `REFINE_SOLVENT_LABELS`, `REFINE_SOLVENT_BEST` | How many of them carry each label (`HOH 265 MG 42`), and how many each species is the best-supported one for |
|
||||
| `REFINE_SOLVENT_DISAGREE`, `REFINE_SOLVENT_AMBIGUOUS` | The sites whose best-supported species is not their label (water, Mg, Na, K, Ca or Cl), not ambiguously; the sites where the runner-up is within 2 of the best |
|
||||
| `REFINE_SOLVENT_IONS`, `REFINE_SOLVENT_IONS_DISAGREE` | The same for the sites not labelled water |
|
||||
| `REFINE_SOLVENT_ADDED` | Waters the water build added and still in the refined model (CPU_DATA_ANALYSIS_REFINEMENT §15.10). Present where the build ran: a restrained refinement to 2.8 A, not `--refine-score-only` |
|
||||
| `REFINE_SOLVENT_ADDED` | Waters the water build added and still in the refined model (CPU_DATA_ANALYSIS_REFINEMENT §15.10). Present where the build ran: a restrained refinement to 2.8 A, not `--refine-score-only` nor `--no-refine-solvent` |
|
||||
| `REFINE_SOLVENT_REMOVED` | Waters of the model as given that the build took out (mFo-DFc at -3 sigma or lower at the water) |
|
||||
| `REFINE_SOLVENT_RELABELLED` | Waters and single-atom ions the build relabelled as another species (water, Mg, Na, K, Ca or Cl) where their surroundings and density support it, not ambiguously; each, with the scores, in the report's prose and in `<prefix>_solvent.json`. Not with `--no-refine-solvent` |
|
||||
| `REFINE_SOLVENT_NOT_SOLVENT` | Difference-map peaks of the final model that cannot be a single solvent atom (bonded to the model, beside a displaced atom, a truncated side chain, a cluster or elongated density, denser than S and P): reported, not filled; each with its reason in `<prefix>_solvent.json` |
|
||||
| `REFINE_SOLVENT_BUILD_ROUNDS` | The build's rounds kept, each a refinement of its own kept where it lowered R-free |
|
||||
| `REFINE_SOLVENT_BUILD_SECONDS` | The build's time, its refinements included (REFINE_SECONDS includes it too) |
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#
|
||||
# assembly.cpp expands a deposited model's strict-NCS operators into the full asymmetric unit.
|
||||
#
|
||||
# fprime is GEMMI's Cromer-Liberman f'/f'' (its port of the Larch routines, credited in its header), for the
|
||||
# anomalous signal the refinement's solvent sites are expected to show at the data's wavelength.
|
||||
#
|
||||
# monlib/topo/riding_h are the restraint side: a monomer library read from memory (MonLib) and the
|
||||
# topology of a model built from it (prepare_topology), for rugnux's restrained refinement.
|
||||
ADD_LIBRARY(gemmi STATIC
|
||||
@@ -19,7 +22,7 @@ ADD_LIBRARY(gemmi STATIC
|
||||
pdb.cpp resinfo.cpp polyheur.cpp calculate.cpp eig3.cpp ccp4.cpp
|
||||
read_cif.cpp mmcif.cpp json.cpp mmread_gz.cpp
|
||||
to_mmcif.cpp to_pdb.cpp assembly.cpp
|
||||
monlib.cpp topo.cpp riding_h.cpp
|
||||
monlib.cpp topo.cpp riding_h.cpp fprime.cpp
|
||||
gemmi/cellred.hpp
|
||||
gemmi/symmetry.hpp
|
||||
gemmi/fail.hpp
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2010-2026 Matthew Newville, The University of Chicago
|
||||
Mauro Rovezzi, University Grenoble Alpes, CNRS
|
||||
Bruce Ravel, National Institute of Science and Technology
|
||||
Margaret Koker, Lawrence University
|
||||
Ryuichi Shimogawa, Stony Brook University
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXP80RESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE qUSE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1052,7 +1052,8 @@ struct OwnSlot {
|
||||
// A copy of the model as it was before the topology was made (the same topology comes out of it, hydrogens
|
||||
// included), with an engine of the main one's kind - a GPU's on `device`. Null where the card cannot make one.
|
||||
std::unique_ptr<OwnSlot> MakeOwnSlot(const gemmi::Structure &before_topology, const Context &main, int device,
|
||||
size_t nthreads, const RefinementSettings &settings) {
|
||||
size_t nthreads, const RefinementSettings &settings,
|
||||
const std::set<std::string> *outer_records) {
|
||||
auto slot = std::make_unique<OwnSlot>();
|
||||
Context &ctx = slot->ctx;
|
||||
ctx.st = before_topology;
|
||||
@@ -1065,7 +1066,7 @@ std::unique_ptr<OwnSlot> MakeOwnSlot(const gemmi::Structure &before_topology, co
|
||||
ctx.cancel = main.cancel;
|
||||
ctx.b_ceiling = main.b_ceiling;
|
||||
ctx.mask = std::make_unique<BulkSolventMask>(ctx.cell, *ctx.sg, ctx.d_min, nthreads);
|
||||
slot->topo = BuildRefinementTopology(ctx.st, settings.riding_hydrogens);
|
||||
slot->topo = BuildRefinementTopology(ctx.st, settings.riding_hydrogens, outer_records);
|
||||
ctx.atoms = AtomList(ctx.Model());
|
||||
ctx.SetRiderParents(slot->topo.rider_parent);
|
||||
#ifdef JFJOCH_USE_CUDA
|
||||
@@ -1262,9 +1263,11 @@ std::vector<TrialOutcome> RunTrials(const std::vector<TrialSlot> &trial_slots,
|
||||
namespace {
|
||||
|
||||
// One refinement of a model whose atoms stay as they are (RefineModel adds and removes waters between calls).
|
||||
// `outer_records`: the metal records to leave as contacts, decided by an earlier round (null: decide here).
|
||||
RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<MergedReflection> &merged,
|
||||
const gemmi::UnitCell &cell, const gemmi::SpaceGroup &sg, double wavelength_A,
|
||||
Logger &logger, const RefinementSettings &settings) {
|
||||
Logger &logger, const RefinementSettings &settings,
|
||||
const std::set<std::string> *outer_records = nullptr) {
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
RefinementResult result;
|
||||
Context ctx;
|
||||
@@ -1311,8 +1314,9 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<Me
|
||||
RefinementTopology topo;
|
||||
if (restrained) {
|
||||
std::optional<RefinementStage> topo_stage("topology");
|
||||
topo = BuildRefinementTopology(ctx.st, settings.riding_hydrogens);
|
||||
topo = BuildRefinementTopology(ctx.st, settings.riding_hydrogens, outer_records);
|
||||
topo_stage.reset();
|
||||
result.outer_records = topo.outer_records;
|
||||
ctx.atoms = AtomList(ctx.Model());
|
||||
ctx.SetRiderParents(topo.rider_parent);
|
||||
PlaceRiders(ctx, topo);
|
||||
@@ -1344,7 +1348,8 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<Me
|
||||
{
|
||||
const RefinementStage stage("solvent");
|
||||
const SolventMaps maps{result.map.get(), result.map_rms, result.difference_map.get(),
|
||||
result.difference_map_rms, result.anomalous_map.get(), result.anomalous_map_rms};
|
||||
result.difference_map_rms, result.anomalous_map.get(), result.anomalous_map_rms,
|
||||
wavelength_A};
|
||||
result.solvent = AnalyseSolventSites(ctx.st, result.d_min, maps);
|
||||
}
|
||||
result.b_ceiling = ctx.b_ceiling;
|
||||
@@ -1405,7 +1410,7 @@ RefinementResult RefineOnce(const gemmi::Structure &placed, const std::vector<Me
|
||||
#endif
|
||||
// a slot that cannot be made is left out, as where the card cannot take its engine
|
||||
try {
|
||||
own[k] = MakeOwnSlot(before_topology, ctx, devices[k], slot_threads, settings);
|
||||
own[k] = MakeOwnSlot(before_topology, ctx, devices[k], slot_threads, settings, outer_records);
|
||||
} catch (const std::exception &e) {
|
||||
logger.Warning("Refinement: a trial slot could not be made ({}), the trials share fewer", e.what());
|
||||
}
|
||||
@@ -1622,12 +1627,16 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
|
||||
const auto build_start = std::chrono::steady_clock::now();
|
||||
SolventBuildResult b;
|
||||
b.ran = true;
|
||||
// the metal records left as contacts on the model as given stay so in every round
|
||||
const std::set<std::string> outer_records = result.outer_records;
|
||||
std::set<std::string> added; // the waters added and still there
|
||||
std::set<std::string> relabelled; // the sites relabelled, by their new names
|
||||
std::vector<SolventEdit> not_solvent; // the not-solvent peaks of the model last picked on
|
||||
for (int round = 1;; round++) {
|
||||
const SolventMaps maps{result.map.get(), result.map_rms, result.difference_map.get(),
|
||||
result.difference_map_rms, nullptr, 0};
|
||||
SolventRound picked = PickSolvent(*result.model, maps, result.solvent, added, result.b_ceiling, round);
|
||||
SolventRound picked = PickSolvent(*result.model, maps, result.solvent, added, relabelled, result.b_ceiling,
|
||||
round);
|
||||
not_solvent.clear();
|
||||
for (const SolventEdit &e : picked.edits)
|
||||
if (e.kind == SolventEdit::Kind::NotSolvent)
|
||||
@@ -1635,11 +1644,11 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
|
||||
std::string refused;
|
||||
for (const auto &[why, n] : picked.refused)
|
||||
refused += fmt::format("{}{} {}", refused.empty() ? "" : ", ", n, why);
|
||||
logger.Info("Solvent build, round {}: {} waters to add, {} to remove, {} peaks not solvent{}", round,
|
||||
picked.added, picked.removed, picked.not_solvent,
|
||||
logger.Info("Solvent build, round {}: {} waters to add, {} to remove, {} sites to relabel, {} peaks not "
|
||||
"solvent{}", round, picked.added, picked.removed, picked.relabelled, picked.not_solvent,
|
||||
refused.empty() ? std::string() : "; peaks refused: " + refused);
|
||||
b.not_solvent = picked.not_solvent;
|
||||
if (picked.added + picked.removed == 0) {
|
||||
if (picked.added + picked.removed + picked.relabelled == 0) {
|
||||
b.stop = "nothing to change";
|
||||
break;
|
||||
}
|
||||
@@ -1649,7 +1658,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
|
||||
}
|
||||
gemmi::Structure changed = *result.model;
|
||||
ApplySolventEdits(changed, picked.edits);
|
||||
RefinementResult next = RefineOnce(changed, merged, cell, sg, wavelength_A, logger, settings);
|
||||
RefinementResult next = RefineOnce(changed, merged, cell, sg, wavelength_A, logger, settings, &outer_records);
|
||||
if (!next.ok || !next.restrained || next.cancelled || !(next.r_free < result.r_free)) {
|
||||
logger.Info("Solvent build, round {}: not kept (R-free {:.4f}, before {:.4f})", round, next.r_free,
|
||||
result.r_free);
|
||||
@@ -1664,6 +1673,13 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
|
||||
if (added.erase(e.site) == 0)
|
||||
b.removed++;
|
||||
b.edits.push_back(e);
|
||||
} else if (e.kind == SolventEdit::Kind::Relabelled) {
|
||||
const std::string now = e.species + e.site.substr(e.site.find(' '));
|
||||
if (added.erase(e.site) > 0)
|
||||
added.insert(now);
|
||||
relabelled.insert(now);
|
||||
b.relabelled++;
|
||||
b.edits.push_back(e);
|
||||
}
|
||||
}
|
||||
b.rounds = round;
|
||||
@@ -1682,9 +1698,9 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
|
||||
b.edits.insert(b.edits.end(), not_solvent.begin(), not_solvent.end());
|
||||
b.seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - build_start).count();
|
||||
result.seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
|
||||
logger.Info("Solvent build: {} waters added, {} removed in {} round{} kept ({}), {} peaks not solvent; "
|
||||
"R-free {:.4f}; {:.1f} s", b.added, b.removed, b.rounds, b.rounds == 1 ? "" : "s", b.stop,
|
||||
b.not_solvent, result.r_free, b.seconds);
|
||||
logger.Info("Solvent build: {} waters added, {} removed, {} sites relabelled in {} round{} kept ({}), {} peaks "
|
||||
"not solvent; R-free {:.4f}; {:.1f} s", b.added, b.removed, b.relabelled, b.rounds,
|
||||
b.rounds == 1 ? "" : "s", b.stop, b.not_solvent, result.r_free, b.seconds);
|
||||
result.solvent_build = std::move(b);
|
||||
}
|
||||
result.map.reset();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -165,6 +166,7 @@ struct RefinementResult {
|
||||
// audit, nothing in the model is changed by it.
|
||||
std::vector<SolventSite> solvent;
|
||||
double b_ceiling = 0; // the highest B the refinement allowed
|
||||
std::set<std::string> outer_records; // the metal records left as contacts (RefinementTopology)
|
||||
SolventBuildResult solvent_build; // the waters added and removed (settings.solvent)
|
||||
};
|
||||
|
||||
|
||||
@@ -27,9 +27,6 @@ constexpr float CHIRAL_SIGMA = 0.2f; // A^3
|
||||
constexpr float REPULSION_SIGMA = 0.2f; // A
|
||||
constexpr float HBOND_CONTACT = 2.6f; // A
|
||||
constexpr float METAL_CONTACT = 1.9f; // A, to N, O or S
|
||||
// A metal's inner sphere ends this far beyond the library's distance: Mg-O 2.07 A + 0.33 = 2.4 A, the inner-sphere
|
||||
// bound of Leonarski, D'Ascenzo & Auffinger (2017) Nucleic Acids Res. 45, 987-1004, taken for every metal.
|
||||
constexpr double INNER_SHELL_MARGIN = 0.33; // A
|
||||
const char *const OUTER_SPHERE_RECORD = "outer-sphere";
|
||||
// B similarity (BSimilarityTerm's kappa: sigma = kappa sqrt(B_i B_j)): main chain and the rest, for bonded pairs and
|
||||
// pairs bonded to a common atom - REFMAC's logs list sigma near 0.1 B for main-chain bonded pairs from B 11 to 140
|
||||
@@ -144,10 +141,13 @@ std::string MetalDonorModification(const std::string &resname, const std::string
|
||||
// 2.9 A) would otherwise pull the ion onto that O; it stays a contact (BuildRepulsions, METAL_CONTACT), and the
|
||||
// coordination counts only the records taken.
|
||||
// Records to a symmetry mate are left out, as every bond to a symmetry mate is (BuildRefinementTopology).
|
||||
// Returns the number of links made; `refused` the records left as contacts for their distance.
|
||||
// With `outer_given`, the records left as contacts are those it names instead, whatever the distances now (a
|
||||
// refinement's later rounds keep the first round's decision). Returns the number of links made; `outer` the
|
||||
// records left as contacts.
|
||||
// Distances as surveyed by Harding (2001) Acta Cryst. D57, 401-411 and (2006) Acta Cryst. D62, 678-682,
|
||||
// and for Mg, Na and K at nucleic acids by Leonarski, D'Ascenzo & Auffinger (2017) Nucleic Acids Res. 45, 987-1004
|
||||
int AddMetalLinks(gemmi::Structure &st, gemmi::MonLib &monlib, int &refused) {
|
||||
int AddMetalLinks(gemmi::Structure &st, gemmi::MonLib &monlib, const std::set<std::string> *outer_given,
|
||||
std::set<std::string> &outer) {
|
||||
gemmi::Model &model = st.models.at(0);
|
||||
struct Site {
|
||||
gemmi::Connection *conn;
|
||||
@@ -175,7 +175,7 @@ int AddMetalLinks(gemmi::Structure &st, gemmi::MonLib &monlib, int &refused) {
|
||||
// as they are): the site's coordination is then every record taken, a symmetry mate's or a described one too.
|
||||
std::vector<Site> sites;
|
||||
std::unordered_map<const gemmi::Atom *, int> coordination;
|
||||
refused = 0;
|
||||
outer.clear();
|
||||
for (const Site &rec : records) {
|
||||
const gemmi::Connection &conn = *rec.conn;
|
||||
const gemmi::CRA &a = rec.metal_first ? rec.metal : rec.donor, &b = rec.metal_first ? rec.donor : rec.metal;
|
||||
@@ -185,13 +185,17 @@ int AddMetalLinks(gemmi::Structure &st, gemmi::MonLib &monlib, int &refused) {
|
||||
b.atom->name, conn.partner2.altloc)) != nullptr;
|
||||
double distance = 0, sigma = 0;
|
||||
const int claimed_n = DictionaryMetalBonds(monlib, rec.metal) + claimed[rec.metal.atom];
|
||||
if (!described &&
|
||||
EmbeddedMetalDistance(rec.metal.atom->element.elem, rec.donor.atom->element.elem, claimed_n, distance, sigma) &&
|
||||
rec.d > distance + INNER_SHELL_MARGIN) {
|
||||
const std::string key = MetalRecordKey(conn);
|
||||
const bool beyond = outer_given != nullptr
|
||||
? outer_given->count(key) > 0
|
||||
: !described && EmbeddedMetalDistance(rec.metal.atom->element.elem,
|
||||
rec.donor.atom->element.elem, claimed_n, distance,
|
||||
sigma) && rec.d > distance + INNER_SHELL_MARGIN;
|
||||
if (beyond) {
|
||||
// named so that prepare_topology() matches it to no link, not even the one made for another site
|
||||
// of the same residues and atoms (BuildRefinementTopology restores the record's own name after it)
|
||||
rec.conn->link_id = OUTER_SPHERE_RECORD;
|
||||
refused++;
|
||||
outer.insert(key);
|
||||
continue;
|
||||
}
|
||||
if (coordination.count(rec.metal.atom) == 0)
|
||||
@@ -226,6 +230,10 @@ int AddMetalLinks(gemmi::Structure &st, gemmi::MonLib &monlib, int &refused) {
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string MetalRecordKey(const gemmi::Connection &conn) {
|
||||
return conn.partner1.str() + " - " + conn.partner2.str();
|
||||
}
|
||||
|
||||
void RestraintSet::Add(RestraintRecord r, int n_atoms_of_r) {
|
||||
r.slot = n_slots;
|
||||
n_slots += n_atoms_of_r;
|
||||
@@ -433,7 +441,8 @@ std::vector<SpecialPosition> FindSpecialPositions(const gemmi::Structure &st) {
|
||||
return out;
|
||||
}
|
||||
|
||||
RefinementTopology BuildRefinementTopology(gemmi::Structure &st, bool hydrogens) {
|
||||
RefinementTopology BuildRefinementTopology(gemmi::Structure &st, bool hydrogens,
|
||||
const std::set<std::string> *outer_records) {
|
||||
RefinementTopology out;
|
||||
gemmi::Model &model = st.models.at(0);
|
||||
out.monlib = std::make_shared<gemmi::MonLib>(EmbeddedMonomerLibrary());
|
||||
@@ -444,7 +453,8 @@ RefinementTopology BuildRefinementTopology(gemmi::Structure &st, bool hydrogens)
|
||||
std::vector<std::string> link_ids;
|
||||
for (const gemmi::Connection &conn : st.connections)
|
||||
link_ids.push_back(conn.link_id);
|
||||
out.metal_links = AddMetalLinks(st, monlib, out.metal_links_refused);
|
||||
out.metal_links = AddMetalLinks(st, monlib, outer_records, out.outer_records);
|
||||
out.metal_links_refused = static_cast<int>(out.outer_records.size());
|
||||
gemmi::Logger quiet; // missing atoms and unknown residues are what the fixed residues report
|
||||
quiet.threshold = 0;
|
||||
out.topo = gemmi::prepare_topology(st, monlib, 0,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include "gemmi/model.hpp"
|
||||
#include "gemmi/monlib.hpp"
|
||||
@@ -101,6 +102,7 @@ struct RefinementTopology {
|
||||
int bonds = 0, angles = 0, torsions = 0, chirals = 0, planes = 0;
|
||||
int metal_links = 0; // metal-donor bonds made from the model's LINK records (AddMetalLinks)
|
||||
int metal_links_refused = 0; // LINK records at an outer-sphere distance, left as contacts
|
||||
std::set<std::string> outer_records; // and which (MetalRecordKey)
|
||||
// The atoms on special positions (FindSpecialPositions), placed exactly on them; per atom its entry, -1 none.
|
||||
std::vector<SpecialPosition> special;
|
||||
std::vector<int> special_index;
|
||||
@@ -117,7 +119,17 @@ struct RefinementTopology {
|
||||
// With `hydrogens`, the dictionary's hydrogens are added to the residues it describes (waters excepted) and
|
||||
// placed; they ride on their parent atoms and take part in no restraint.
|
||||
// The atoms on special positions are moved onto them (SpecialPosition::OnSite).
|
||||
RefinementTopology BuildRefinementTopology(gemmi::Structure &st, bool hydrogens = false);
|
||||
// `outer_records`: where given, the metal records left as contacts are these (MetalRecordKey) whatever the model's
|
||||
// distances now - a decision taken once, on the model as given, and not again on distances its refinement moved.
|
||||
RefinementTopology BuildRefinementTopology(gemmi::Structure &st, bool hydrogens = false,
|
||||
const std::set<std::string> *outer_records = nullptr);
|
||||
|
||||
// A metal's inner sphere ends this far beyond the library's distance: Mg-O 2.07 A + 0.33 = 2.4 A, the inner-sphere
|
||||
// bound of Leonarski, D'Ascenzo & Auffinger (2017) Nucleic Acids Res. 45, 987-1004, taken for every metal.
|
||||
constexpr double INNER_SHELL_MARGIN = 0.33; // A
|
||||
|
||||
// The name a metal LINK / struct_conn record is known by: its two partners.
|
||||
std::string MetalRecordKey(const gemmi::Connection &conn);
|
||||
|
||||
// The riding hydrogens placed again on their parents as they are now (gemmi's place_hydrogens_on_all_atoms).
|
||||
void PlaceRidingHydrogens(RefinementTopology &topo);
|
||||
|
||||
@@ -196,12 +196,14 @@ const char *SolventEditKindName(SolventEdit::Kind kind) {
|
||||
case SolventEdit::Kind::Added: return "ADDED";
|
||||
case SolventEdit::Kind::Removed: return "REMOVED";
|
||||
case SolventEdit::Kind::NotSolvent: return "NOT_SOLVENT";
|
||||
case SolventEdit::Kind::Relabelled: return "RELABELLED";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
SolventRound PickSolvent(const gemmi::Structure &st, const SolventMaps &maps, const std::vector<SolventSite> &sites,
|
||||
const std::set<std::string> &built, double b_ceiling, int round) {
|
||||
const std::set<std::string> &built, const std::set<std::string> &relabelled, double b_ceiling,
|
||||
int round) {
|
||||
SolventRound out;
|
||||
if (st.models.empty() || maps.difference == nullptr || maps.map == nullptr || !(maps.difference_rms > 0) ||
|
||||
!(maps.map_rms > 0))
|
||||
@@ -259,10 +261,47 @@ SolventRound PickSolvent(const gemmi::Structure &st, const SolventMaps &maps, co
|
||||
out.edits.push_back(e);
|
||||
out.removed++;
|
||||
}
|
||||
// The sites whose surroundings and density support another species than their label, not ambiguously: each
|
||||
// relabelled once (an alternative conformer, a site relabelled before, or one with no density of its own to tell
|
||||
// the species by, stays as it is).
|
||||
std::set<std::string> taken_out;
|
||||
for (const SolventEdit &e : out.edits)
|
||||
taken_out.insert(e.site);
|
||||
for (const SolventSite &s : sites) {
|
||||
const std::string name = s.label + " " + s.chain + s.seqid;
|
||||
if (!SolventLabelScored(s) || s.ambiguous || SolventLabelAgrees(s) || s.altloc || taken_out.count(name) ||
|
||||
relabelled.count(name) || !(s.electrons > 0))
|
||||
continue;
|
||||
const int best = static_cast<int>(s.best);
|
||||
int label = 0;
|
||||
while (label < SOLVENT_SPECIES && s.label != SolventSpeciesName(static_cast<SolventSpecies>(label)))
|
||||
label++;
|
||||
if (SolventLabelIsWater(s))
|
||||
label = static_cast<int>(SolventSpecies::Water);
|
||||
SolventEdit e;
|
||||
e.kind = SolventEdit::Kind::Relabelled;
|
||||
e.round = round;
|
||||
e.site = name;
|
||||
e.chain = s.chain;
|
||||
e.seqid = gemmi::SeqId(s.seqid);
|
||||
e.pos = s.pos;
|
||||
e.difference_sigma = s.difference_sigma;
|
||||
e.map_sigma = s.map_sigma;
|
||||
e.b_iso = s.b_iso;
|
||||
e.species = SolventSpeciesName(s.best);
|
||||
e.reason = fmt::format("{} {:.1f} against {} {:.1f}; shell {}/{}/{}, electrons {:.1f}, anomalous {:.1f} sigma",
|
||||
e.species, s.score[best], s.label,
|
||||
label < SOLVENT_SPECIES ? s.score[label] : NAN, s.n_19_23, s.n_23_26, s.n_26_32,
|
||||
s.electrons, s.anomalous_sigma);
|
||||
out.edits.push_back(e);
|
||||
out.relabelled++;
|
||||
}
|
||||
|
||||
// A removed water is no partner of a new one, nor in its way.
|
||||
std::vector<gemmi::Position> removed;
|
||||
for (const SolventEdit &e : out.edits)
|
||||
removed.push_back(e.pos);
|
||||
if (e.kind == SolventEdit::Kind::Removed)
|
||||
removed.push_back(e.pos);
|
||||
auto is_removed = [&](const gemmi::Position &p) {
|
||||
return std::any_of(removed.begin(), removed.end(), [&](const gemmi::Position &q) { return q.dist(p) < 0.01; });
|
||||
};
|
||||
@@ -412,8 +451,103 @@ SolventRound PickSolvent(const gemmi::Structure &st, const SolventMaps &maps, co
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
gemmi::El SpeciesElement(const std::string &species) {
|
||||
return species == "HOH" ? gemmi::El::O : gemmi::Element(species).elem;
|
||||
}
|
||||
|
||||
// The site of `e` relabelled as e.species, its metal records replaced by its inner sphere's.
|
||||
void Relabel(gemmi::Structure &st, const SolventEdit &e, int &record) {
|
||||
gemmi::Model &model = st.models.at(0);
|
||||
const std::string from = e.site.substr(0, e.site.find(' '));
|
||||
gemmi::Residue *res = nullptr;
|
||||
gemmi::Chain *chain = nullptr;
|
||||
for (gemmi::Chain &ch : model.chains)
|
||||
for (gemmi::Residue &r : ch.residues)
|
||||
if (ch.name == e.chain && r.seqid == e.seqid && r.name == from && r.atoms.size() == 1) {
|
||||
res = &r;
|
||||
chain = &ch;
|
||||
}
|
||||
if (res == nullptr)
|
||||
return;
|
||||
const gemmi::AtomAddress old_address(chain->name, res->seqid, res->name, res->atoms[0].name);
|
||||
std::erase_if(st.connections, [&](const gemmi::Connection &c) {
|
||||
return c.partner1 == old_address || c.partner2 == old_address;
|
||||
});
|
||||
// the subchain and entity of a residue of the species already in the model, where there is one
|
||||
const gemmi::Residue *like = nullptr;
|
||||
for (const gemmi::Chain &ch : model.chains)
|
||||
for (const gemmi::Residue &r : ch.residues)
|
||||
if (r.name == e.species && like == nullptr)
|
||||
like = &r;
|
||||
const bool water = e.species == "HOH";
|
||||
res->name = e.species;
|
||||
res->entity_type = water ? gemmi::EntityType::Water : gemmi::EntityType::NonPolymer;
|
||||
res->het_flag = 'H';
|
||||
res->subchain = like != nullptr ? like->subchain : "";
|
||||
res->entity_id = like != nullptr ? like->entity_id : "";
|
||||
gemmi::Atom &a = res->atoms[0];
|
||||
a.element = gemmi::Element(SpeciesElement(e.species));
|
||||
a.name = water ? "O" : e.species;
|
||||
a.occ = std::max(a.occ, 0.0f);
|
||||
if (!a.element.is_metal())
|
||||
return;
|
||||
// the N, O and S of its inner sphere, within the model's own copy (a record to a symmetry mate is left out)
|
||||
struct Donor {
|
||||
const gemmi::Chain *ch;
|
||||
const gemmi::Residue *r;
|
||||
const gemmi::Atom *atom;
|
||||
double d;
|
||||
};
|
||||
std::vector<Donor> donors;
|
||||
double widest = 0, sigma = 0;
|
||||
for (gemmi::El el : {gemmi::El::O, gemmi::El::N, gemmi::El::S}) {
|
||||
double d0 = 0;
|
||||
if (EmbeddedMetalDistance(a.element.elem, el, 6, d0, sigma))
|
||||
widest = std::max(widest, d0 + INNER_SHELL_MARGIN + 0.2);
|
||||
}
|
||||
for (const gemmi::Chain &ch : model.chains)
|
||||
for (const gemmi::Residue &r : ch.residues)
|
||||
for (const gemmi::Atom &d : r.atoms)
|
||||
if (&r != res && (d.element == gemmi::El::O || d.element == gemmi::El::N || d.element == gemmi::El::S))
|
||||
if (const double dist = d.pos.dist(a.pos); dist < widest)
|
||||
donors.push_back({&ch, &r, &d, dist});
|
||||
// judged at the coordination of those within the inner sphere of an octahedral site, as AddMetalLinks judges
|
||||
// a model's records at the coordination they claim
|
||||
int cn = 0;
|
||||
for (const Donor &d : donors) {
|
||||
double ideal = 0;
|
||||
cn += EmbeddedMetalDistance(a.element.elem, d.atom->element.elem, 6, ideal, sigma) &&
|
||||
d.d <= ideal + INNER_SHELL_MARGIN;
|
||||
}
|
||||
for (const Donor &d : donors) {
|
||||
double ideal = 0;
|
||||
if (!EmbeddedMetalDistance(a.element.elem, d.atom->element.elem, std::max(cn, 1), ideal, sigma) ||
|
||||
d.d > ideal + INNER_SHELL_MARGIN)
|
||||
continue;
|
||||
gemmi::Connection c;
|
||||
c.name = "rugnux_metalc" + std::to_string(++record);
|
||||
c.type = gemmi::Connection::MetalC;
|
||||
c.asu = gemmi::Asu::Same;
|
||||
c.partner1 = gemmi::AtomAddress(d.ch->name, d.r->seqid, d.r->name, d.atom->name, d.atom->altloc);
|
||||
c.partner2 = gemmi::AtomAddress(chain->name, res->seqid, res->name, a.name);
|
||||
c.reported_distance = d.d;
|
||||
st.connections.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ApplySolventEdits(gemmi::Structure &st, std::vector<SolventEdit> &edits) {
|
||||
gemmi::Model &model = st.models.at(0);
|
||||
int record = 0;
|
||||
for (const gemmi::Connection &c : st.connections)
|
||||
if (c.name.rfind("rugnux_metalc", 0) == 0)
|
||||
record = std::max(record, std::atoi(c.name.c_str() + 13));
|
||||
for (const SolventEdit &e : edits)
|
||||
if (e.kind == SolventEdit::Kind::Relabelled)
|
||||
Relabel(st, e, record);
|
||||
// A chain name can stand for several chains of the model (a polymer and its waters read as two); each is meant.
|
||||
for (const SolventEdit &e : edits) {
|
||||
if (e.kind != SolventEdit::Kind::Removed)
|
||||
|
||||
@@ -12,17 +12,19 @@
|
||||
|
||||
#include "SolventSites.h" // SolventSite, SolventMaps
|
||||
|
||||
// One round of the water build that RefineModel runs between refinements (Refinement.h): waters placed at the
|
||||
// peaks of the difference map a refined model leaves, and the model's waters the maps no longer support taken
|
||||
// out. Waters only - no ion is placed or relabelled here.
|
||||
// One round of the solvent build that RefineModel runs between refinements (Refinement.h): waters placed at the
|
||||
// peaks of the difference map a refined model leaves, the model's waters the maps no longer support taken out, and
|
||||
// waters and ions relabelled.
|
||||
//
|
||||
// A peak of mFo-DFc becomes a water where it has a hydrogen-bond partner and nothing too close - on a special
|
||||
// position exactly on it, at the occupancy that makes its coinciding copies one water; a peak that
|
||||
// cannot be a single solvent atom - one bonded to the model, beside a negative peak on a model atom, where a
|
||||
// truncated side chain's missing atoms would be, one of a cluster of peaks at bonded distances, elongated, or
|
||||
// denser than the model's S and P - is reported as not solvent and left alone.
|
||||
// denser than the model's S and P - is reported as not solvent and left alone. A water or a single-atom ion whose
|
||||
// surroundings and density support another species, not ambiguously (SolventSites.h), is relabelled as it: a water
|
||||
// becomes an ion, an ion water or another ion.
|
||||
struct SolventEdit {
|
||||
enum class Kind { Added, Removed, NotSolvent };
|
||||
enum class Kind { Added, Removed, NotSolvent, Relabelled };
|
||||
Kind kind = Kind::NotSolvent;
|
||||
int round = 0;
|
||||
std::string site; // the water as modelled ("HOH A401"); empty for a peak not taken
|
||||
@@ -35,14 +37,16 @@ struct SolventEdit {
|
||||
double b_iso = 0; // an added water's starting B, a removed one's
|
||||
double occupancy = 1; // an added water's: 1 over its site's multiplicity on a special position
|
||||
double elongation = 0; // a peak's density: the longest axis over the shortest, rms
|
||||
std::string reason; // why: the partners an added water has, what a removed or refused one lacks
|
||||
std::string species; // a relabelled site's new residue name (HOH, MG, NA, K, CA, CL); its old one in `site`
|
||||
std::string reason; // why: the partners an added water has, what a removed or refused one lacks, the
|
||||
// scores a relabelled one has
|
||||
};
|
||||
|
||||
const char *SolventEditKindName(SolventEdit::Kind kind);
|
||||
|
||||
struct SolventRound {
|
||||
std::vector<SolventEdit> edits;
|
||||
int added = 0, removed = 0, not_solvent = 0;
|
||||
int added = 0, removed = 0, not_solvent = 0, relabelled = 0;
|
||||
std::map<std::string, int> refused; // the peaks neither taken nor reported, by what they lack
|
||||
};
|
||||
|
||||
@@ -59,6 +63,7 @@ struct SolventBuildResult {
|
||||
int rounds = 0; // the rounds kept
|
||||
int added = 0; // waters added and still in the model
|
||||
int removed = 0; // waters of the model as given taken out
|
||||
int relabelled = 0; // sites relabelled, in the rounds kept
|
||||
int not_solvent = 0; // peaks of the final model's difference map that are no solvent
|
||||
std::vector<SolventEdit> edits; // the kept rounds' additions and removals, then the final not-solvent peaks
|
||||
std::string stop; // why it stopped
|
||||
@@ -68,10 +73,13 @@ struct SolventBuildResult {
|
||||
// A round on `model` (the refined model the maps were made from, in their cell and space group): `maps` its
|
||||
// 2mFo-DFc and mFo-DFc (the anomalous one unused), `sites` its solvent audit (AnalyseSolventSites on the same
|
||||
// maps), `built` the waters added by earlier rounds (by name, "HOH A401"), `b_ceiling` the highest B its refinement
|
||||
// allowed.
|
||||
// allowed; `relabelled` the sites relabelled by earlier rounds (by their new name), which are not relabelled again.
|
||||
SolventRound PickSolvent(const gemmi::Structure &model, const SolventMaps &maps, const std::vector<SolventSite> &sites,
|
||||
const std::set<std::string> &built, double b_ceiling, int round);
|
||||
const std::set<std::string> &built, const std::set<std::string> &relabelled, double b_ceiling,
|
||||
int round);
|
||||
|
||||
// The round's waters taken out and put in: each added one to the chain of its nearest atom, numbered on from that
|
||||
// chain's last residue (its `site` is set to the name it gets).
|
||||
// chain's last residue (its `site` is set to the name it gets). A relabelled site gets its new residue name,
|
||||
// element and atom name; its metal records go, and a metal gets one for each N, O or S of its inner sphere (within
|
||||
// the library's distance plus 0.33 A, as the records of the model as given are taken).
|
||||
void ApplySolventEdits(gemmi::Structure &st, std::vector<SolventEdit> &edits);
|
||||
@@ -5,14 +5,20 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <tuple>
|
||||
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
|
||||
#include "gemmi/calculate.hpp" // find_best_plane
|
||||
#include "gemmi/fprime.hpp" // cromer_liberman
|
||||
#include "gemmi/neighbor.hpp"
|
||||
#include "gemmi/resinfo.hpp"
|
||||
|
||||
#include "ModelGrid.h" // IonFormFactor
|
||||
#include "MonomerLibrary.h"
|
||||
#include "RefinementRestraints.h" // AtomsNear
|
||||
#include "RefinementRestraints.h" // AtomsNear, SiteSymmetry
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -30,9 +36,21 @@ constexpr double BAND_EDGE = 0.05;
|
||||
// A contact the species does not make (closer than its shell, in its exclusion zone, a donor at a cation or an
|
||||
// acceptor at a halide, a like charge), in the score's log units, per contact.
|
||||
constexpr double BAD_CONTACT = 2.0;
|
||||
// A first-shell ligand fewer than a Mg, Na or Ca holds: a water the model may simply not have, so it costs little.
|
||||
// Incomplete shells are common; they are no evidence for the ion, and not much against it.
|
||||
// A first-shell ligand fewer than a Mg, Na, Ca or Cl holds: a water the model may simply not have, so it costs
|
||||
// little. Incomplete shells are common; they are no evidence for the ion, and not much against it - and a halide
|
||||
// binds at hydrophobic surfaces too, with few or no donors, where its electrons and its anomalous signal, not its
|
||||
// shell, tell it from a water.
|
||||
// Following Dauter & Dauter (2001) Structure 9, R21-R26
|
||||
constexpr double MISSING_LIGAND = 0.5;
|
||||
// The electron count's calibration on the waters: on those within SEARCH_RADIUS of the site where there are at
|
||||
// least this many, or on all of the model's; its spread (rms of the log of the waters' calibrations) at least this.
|
||||
// The density the model's other atoms put at a point is counted out to TAIL_RADIUS.
|
||||
constexpr int CALIBRATION_NEIGHBOURS = 3;
|
||||
constexpr double TAIL_RADIUS = 4.5; // A
|
||||
constexpr double ELECTRON_SPREAD_MIN = 0.15;
|
||||
// A divalent ion on a purine N7: within 1.0 A of the base's plane and 3.5-3.9 A from its O6 or N6, following
|
||||
// Leonarski, D'Ascenzo & Auffinger (2017) Nucleic Acids Res. 45, 987-1004
|
||||
constexpr double N7_PLANE_MAX = 1.0, N7_O6N6_MIN = 3.5, N7_O6N6_MAX = 3.9;
|
||||
|
||||
// R0 (A) of the bond-valence parameters for Mg, Na, K, Ca to O and to N, b = 0.37 A, as tabulated by Zheng et al.
|
||||
// (2017) Acta Cryst. D73, 316-325, Table 2.
|
||||
@@ -80,6 +98,167 @@ bool IsWater(const gemmi::Residue &r) {
|
||||
return r.is_water();
|
||||
}
|
||||
|
||||
// The element, charge and riding hydrogens each species scatters as: a water as O with its two H, NH4+ as N
|
||||
// with four.
|
||||
struct Scatterer {
|
||||
gemmi::El el;
|
||||
signed char charge;
|
||||
int hydrogens;
|
||||
};
|
||||
const Scatterer SCATTERERS[SOLVENT_SPECIES] = {{gemmi::El::O, 0, 2}, {gemmi::El::Mg, 2, 0}, {gemmi::El::Na, 1, 0},
|
||||
{gemmi::El::K, 1, 0}, {gemmi::El::Ca, 2, 0}, {gemmi::El::Cl, -1, 0},
|
||||
{gemmi::El::N, 0, 4}};
|
||||
|
||||
// The height at its centre of the density of an atom of form factor f(s) and B, as a map to d_min shows it:
|
||||
// 4 pi int_0^(1/d_min) f(s) exp(-B s^2 / 4) s^2 ds (s = 1/d), by Simpson's rule.
|
||||
// At distance r from the centre: 4 pi int f(s) exp(-B s^2 / 4) s^2 sin(2 pi s r) / (2 pi s r) ds.
|
||||
template <class F>
|
||||
double PeakHeight(F &&f, double b, double d_min, double r = 0) {
|
||||
constexpr int N = 64;
|
||||
const double s_max = 1.0 / d_min, h = s_max / N;
|
||||
double sum = 0;
|
||||
for (int k = 0; k <= N; k++) {
|
||||
const double s = k * h;
|
||||
const double w = (k == 0 || k == N) ? 1 : (k % 2 == 1 ? 4 : 2);
|
||||
const double x = 2 * PI * s * r;
|
||||
sum += w * f(s) * std::exp(-b * s * s / 4) * s * s * (x > 1e-9 ? std::sin(x) / x : 1.0);
|
||||
}
|
||||
return 4 * PI * sum * h / 3;
|
||||
}
|
||||
|
||||
double ScattererHeight(const Scatterer &sc, double b, double d_min, double r = 0) {
|
||||
const auto &f = IonFormFactor<double>(sc.el, sc.charge);
|
||||
const auto &fh = IonFormFactor<double>(gemmi::El::H, 0);
|
||||
return PeakHeight([&](double s) { return f.calculate_sf(s * s / 4) + sc.hydrogens * fh.calculate_sf(s * s / 4); },
|
||||
b, d_min, r);
|
||||
}
|
||||
|
||||
// How an atom of the model scatters for the density it puts at its neighbours: as modelled, a water with its
|
||||
// hydrogens.
|
||||
Scatterer ScattererOf(const gemmi::Residue &r, const gemmi::Atom &a) {
|
||||
return {a.element.elem, a.charge, IsWater(r) ? 2 : 0};
|
||||
}
|
||||
|
||||
// The density of an atom at distance r from it (ScattererHeight), tabulated per scatterer and B (to the nearest
|
||||
// A^2) at steps of 0.05 A out to TAIL_RADIUS, read by linear interpolation.
|
||||
class RadialDensity {
|
||||
public:
|
||||
explicit RadialDensity(double d_min) : d_min_(d_min) {}
|
||||
double operator()(const Scatterer &sc, double b, double r) { return At(Table(sc, b), r); }
|
||||
const std::vector<double> &Table(const Scatterer &sc, double b) {
|
||||
const int bi = static_cast<int>(std::lround(std::clamp(b, 0.0, 500.0)));
|
||||
const auto key = std::make_tuple(static_cast<int>(sc.el), static_cast<int>(sc.charge), sc.hydrogens, bi);
|
||||
auto it = tables_.find(key);
|
||||
if (it == tables_.end()) {
|
||||
std::vector<double> t(static_cast<size_t>(TAIL_RADIUS / STEP) + 2);
|
||||
for (size_t k = 0; k < t.size(); k++)
|
||||
t[k] = ScattererHeight(sc, bi, d_min_, k * STEP);
|
||||
it = tables_.emplace(key, std::move(t)).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
static double At(const std::vector<double> &t, double r) {
|
||||
if (!(r < TAIL_RADIUS))
|
||||
return 0;
|
||||
const double x = r / STEP;
|
||||
const size_t k = static_cast<size_t>(x);
|
||||
return t[k] + (x - k) * (t[k + 1] - t[k]);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr double STEP = 0.05;
|
||||
double d_min_;
|
||||
std::map<std::tuple<int, int, int, int>, std::vector<double>> tables_;
|
||||
};
|
||||
|
||||
// An atom near a site, as it scatters (for the density it puts there).
|
||||
struct Scattering {
|
||||
gemmi::Position pos;
|
||||
double occ;
|
||||
const std::vector<double> *density; // RadialDensity::Table() of its scatterer at its B
|
||||
};
|
||||
|
||||
// The site's own density fitted to the map near it, the model's other atoms (`others`) held: 2mFo-DFc, on the model's
|
||||
// scale (`k` per model unit), at points 0.3 A apart within FIT_RADIUS of `p0`, against `a` times a water (O and two
|
||||
// H) at B `b` centred at p plus the others' density there, least squares in a; p is p0, or with `search` the best of
|
||||
// the points 0.1 A apart within SOLVENT_PEAK_REACH of it. The site's height thus counted apart from its neighbours',
|
||||
// which merge with it at moderate resolution: a is the electrons it shows, in waters.
|
||||
struct LocalFit {
|
||||
gemmi::Position p;
|
||||
double a = NAN;
|
||||
};
|
||||
constexpr double FIT_RADIUS = 1.0; // A
|
||||
|
||||
LocalFit FitSite(const gemmi::Grid<float> &map, double k, const gemmi::Position &p0, double b,
|
||||
const std::vector<Scattering> &others, RadialDensity &radial, bool search) {
|
||||
std::vector<gemmi::Position> points;
|
||||
std::vector<double> obs;
|
||||
constexpr double STEP = 0.3;
|
||||
const double reach = FIT_RADIUS + (search ? SOLVENT_PEAK_REACH : 0.0);
|
||||
const int n = static_cast<int>(std::ceil(reach / STEP));
|
||||
for (int i = -n; i <= n; i++)
|
||||
for (int j = -n; j <= n; j++)
|
||||
for (int l = -n; l <= n; l++) {
|
||||
const gemmi::Position x(p0.x + i * STEP, p0.y + j * STEP, p0.z + l * STEP);
|
||||
if (x.dist(p0) > reach)
|
||||
continue;
|
||||
double tail = 0;
|
||||
for (const Scattering &o : others)
|
||||
tail += o.occ * RadialDensity::At(*o.density, x.dist(o.pos));
|
||||
points.push_back(x);
|
||||
obs.push_back(map.interpolate_value(x) / k - tail);
|
||||
}
|
||||
const std::vector<double> &water = radial.Table(SCATTERERS[0], b);
|
||||
auto fit = [&](const gemmi::Position &p, double &a) {
|
||||
double num = 0, den = 0, oo = 0;
|
||||
for (size_t m = 0; m < points.size(); m++)
|
||||
if (const double d = points[m].dist(p); d <= FIT_RADIUS) {
|
||||
const double shape = RadialDensity::At(water, d);
|
||||
num += obs[m] * shape;
|
||||
den += shape * shape;
|
||||
oo += obs[m] * obs[m];
|
||||
}
|
||||
a = den > 0 ? num / den : NAN;
|
||||
return den > 0 ? oo - num * num / den : INFINITY; // the residual at the best a
|
||||
};
|
||||
LocalFit out;
|
||||
out.p = p0;
|
||||
double best = fit(p0, out.a);
|
||||
// the points 0.2 A apart within reach, then 0.1 A apart around the best of them
|
||||
for (double step : {0.2, 0.1}) {
|
||||
if (!search)
|
||||
break;
|
||||
const gemmi::Position centre = out.p;
|
||||
const int m = step > 0.15 ? static_cast<int>(std::lround(SOLVENT_PEAK_REACH / step)) : 1;
|
||||
for (int i = -m; i <= m; i++)
|
||||
for (int j = -m; j <= m; j++)
|
||||
for (int l = -m; l <= m; l++) {
|
||||
const gemmi::Position p(centre.x + i * step, centre.y + j * step, centre.z + l * step);
|
||||
double a = 0;
|
||||
if (p.dist(p0) > SOLVENT_PEAK_REACH)
|
||||
continue;
|
||||
if (const double r = fit(p, a); r < best && a > 0) {
|
||||
best = r;
|
||||
out = {p, a};
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// The median and the rms spread (1.4826 times the median absolute deviation) of `v`.
|
||||
std::pair<double, double> MedianSpread(std::vector<double> v) {
|
||||
if (v.empty())
|
||||
return {NAN, NAN};
|
||||
std::sort(v.begin(), v.end());
|
||||
const double m = v[v.size() / 2];
|
||||
std::vector<double> dev;
|
||||
for (double x : v)
|
||||
dev.push_back(std::fabs(x - m));
|
||||
std::sort(dev.begin(), dev.end());
|
||||
return {m, 1.4826 * dev[dev.size() / 2]};
|
||||
}
|
||||
|
||||
bool IsHalogen(gemmi::El el) {
|
||||
return el == gemmi::El::F || el == gemmi::El::Cl || el == gemmi::El::Br || el == gemmi::El::I;
|
||||
}
|
||||
@@ -143,6 +322,7 @@ struct Ligand {
|
||||
double valence[BVS_CATIONS]; // its bond valence to each cation, occupancy weighted
|
||||
AtomChemistry chem;
|
||||
bool nitrogen;
|
||||
bool n7_off_plane; // a purine N7 the site is out of the plane of, or at the wrong distance from its O6/N6
|
||||
};
|
||||
|
||||
// The score of species `s` at `site`, with the N and O neighbours `ligands`. A plain sum of terms in log units:
|
||||
@@ -152,13 +332,22 @@ struct Ligand {
|
||||
// anomalous signal. A neighbour's coordinate error widens the bands it is counted in and the distance it is
|
||||
// compared with, so that where the coordinates are poor the species' shells overlap and the score cannot tell
|
||||
// them apart, rather than telling them apart wrongly. `label`: the label's species, -1 for one not scored here.
|
||||
double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &ligands, int label) {
|
||||
// What the model's waters show (SolventSite::electrons): the median and the rms spread of the log; NaN with too few.
|
||||
struct WaterElectrons {
|
||||
double median = NAN, spread = NAN;
|
||||
};
|
||||
constexpr int WATER_STATISTICS_MIN = 10;
|
||||
|
||||
// `expected_electrons`: per species, the electrons a site of it shows on the scale of SolventSite::electrons, an ion
|
||||
// at full occupancy; `waters`: what the model's waters show - many partly occupied or disordered - for the water.
|
||||
double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &ligands,
|
||||
const std::array<double, SOLVENT_SPECIES> &expected_electrons, const WaterElectrons &waters) {
|
||||
const SpeciesRule &rule = RULES[s];
|
||||
const auto species = static_cast<SolventSpecies>(s);
|
||||
double n = 0, distance = 0, too_close = 0, excluded = 0;
|
||||
double donors_in = 0, acceptors_in = 0; // donor-only and acceptor-only in the first shell
|
||||
double hbond_donors = 0, hbond_acceptors = 0; // the same at 2.6-3.4 A, a water's hydrogen bonds
|
||||
bool donor_nitrogen = false;
|
||||
double n7_off = 0; // first-shell N7 a divalent ion could not hold
|
||||
for (const Ligand &l : ligands) {
|
||||
const double e = l.sigma;
|
||||
const double p = InBand(l.distance, BAND_EDGE, rule.lo - e, rule.hi + e);
|
||||
@@ -178,7 +367,7 @@ double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &l
|
||||
const double hb = InBand(l.distance, BAND_EDGE, 2.6 - e, SHELL_RADIUS + e);
|
||||
hbond_donors += donor_only ? hb : 0;
|
||||
hbond_acceptors += acceptor_only ? hb : 0;
|
||||
donor_nitrogen = donor_nitrogen || (l.nitrogen && l.chem.donor && l.distance < LIKE_CHARGE_DISTANCE);
|
||||
n7_off += l.n7_off_plane ? p : 0;
|
||||
}
|
||||
|
||||
double score = 0;
|
||||
@@ -189,12 +378,14 @@ double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &l
|
||||
if (n < 1)
|
||||
score -= BAD_CONTACT * (1 - n);
|
||||
} else if (n < rule.cn && (species == SolventSpecies::Mg || species == SolventSpecies::Na ||
|
||||
species == SolventSpecies::Ca))
|
||||
species == SolventSpecies::Ca || species == SolventSpecies::Cl))
|
||||
score -= MISSING_LIGAND * (rule.cn - n);
|
||||
else
|
||||
score -= (n - rule.cn) * (n - rule.cn) / (2 * rule.cn_sigma * rule.cn_sigma);
|
||||
score += distance;
|
||||
score -= BAD_CONTACT * (too_close + excluded);
|
||||
if (rule.charge == 2)
|
||||
score -= BAD_CONTACT * n7_off;
|
||||
|
||||
// the chemistry
|
||||
if (rule.charge > 0) {
|
||||
@@ -203,9 +394,6 @@ double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &l
|
||||
} else if (rule.charge < 0) {
|
||||
score -= BAD_CONTACT * acceptors_in; // a halide is surrounded by donors
|
||||
score -= BAD_CONTACT * site.negative_contacts;
|
||||
// at least one positive group or one donor N, following Morshed et al. (2015) Acta Cryst. D71, 1147-1158
|
||||
if (!(site.nearest_positive < LIKE_CHARGE_DISTANCE) && !donor_nitrogen)
|
||||
score -= BAD_CONTACT;
|
||||
} else {
|
||||
// a water donates two hydrogen bonds and accepts two
|
||||
score -= BAD_CONTACT * (std::max(0.0, hbond_donors - 2) + std::max(0.0, hbond_acceptors - 2));
|
||||
@@ -222,19 +410,21 @@ double ScoreSpecies(int s, const SolventSite &site, const std::vector<Ligand> &l
|
||||
score -= 0.5 * std::pow(site.nvecsum[rule.bvs] / 0.23, 2);
|
||||
}
|
||||
|
||||
// the electrons: what the difference map says the label lacks (positive) or has too many of (negative)
|
||||
if (label >= 0 && std::isfinite(site.difference_sigma)) {
|
||||
const int delta = rule.electrons - RULES[label].electrons;
|
||||
if (site.difference_sigma >= 3)
|
||||
score += delta > 0 ? 1 : -1;
|
||||
else if (site.difference_sigma <= -3)
|
||||
score += delta < 0 ? 1 : -1;
|
||||
else if (delta != 0)
|
||||
score -= 0.5; // nothing missing, nothing extra - though B and occupancy can hide 8 electrons
|
||||
// the electrons: the density at the site against what the species gives at the environment's B, an ion at full
|
||||
// occupancy, a water as the model's waters show - many partly occupied or disordered; log-normal in the waters'
|
||||
// spread (an ion's occupancy and order vary as much), at least the neighbours' calibration's. An ion as dense as a
|
||||
// full 10-electron scatterer is so more than a typical water, as Echols et al. (2014) flag a light ion by a
|
||||
// 2mFo-DFc above the waters' mean; where the density is weak the electrons tell little, and the shell decides.
|
||||
if (std::isfinite(site.electrons) && expected_electrons[s] > 0) {
|
||||
const bool known = std::isfinite(waters.median);
|
||||
const double expected = known && species == SolventSpecies::Water ? waters.median : expected_electrons[s];
|
||||
const double spread = known ? std::max(site.electron_spread, waters.spread) : site.electron_spread;
|
||||
const double q = std::max(site.electrons / expected, 0.05);
|
||||
score -= std::log(q) * std::log(q) / (2 * spread * spread);
|
||||
}
|
||||
// the anomalous signal: K, Ca and Cl scatter anomalously, water, Mg and Na next to nothing
|
||||
if (std::isfinite(site.anomalous_sigma) && site.anomalous_sigma >= 4)
|
||||
score += rule.electrons == 18 ? 2 : -2;
|
||||
// the anomalous signal against the species' f'' at the wavelength, Gaussian in the map's rms
|
||||
if (std::isfinite(site.anomalous_sigma) && std::isfinite(site.anomalous_expected[s]))
|
||||
score -= 0.5 * std::pow(site.anomalous_sigma - site.anomalous_expected[s], 2);
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -308,6 +498,9 @@ std::vector<SolventSite> AnalyseSolventSites(const gemmi::Structure &st, double
|
||||
std::vector<SolventSite> out;
|
||||
if (st.models.empty())
|
||||
return out;
|
||||
// per site, scored once the waters' electrons are known: its N and O neighbours and each species' electrons
|
||||
std::vector<std::vector<Ligand>> site_ligands;
|
||||
std::vector<std::array<double, SOLVENT_SPECIES>> site_expected;
|
||||
gemmi::Model model = st.models[0]; // NeighborSearch takes it non-const
|
||||
gemmi::UnitCell cell = st.cell;
|
||||
cell.set_cell_images_from_spacegroup(st.find_spacegroup());
|
||||
@@ -328,13 +521,93 @@ std::vector<SolventSite> AnalyseSolventSites(const gemmi::Structure &st, double
|
||||
auto map_sigma = [](const gemmi::Grid<float> *g, double rms, const gemmi::Position &p) {
|
||||
return g != nullptr && rms > 0 ? g->interpolate_value(p) / rms : NAN;
|
||||
};
|
||||
const bool density = maps.map != nullptr && d_min > 0;
|
||||
RadialDensity radial(d_min);
|
||||
// The model's atoms near the one at (ci, ri, ai) at `own` - in `near`, AtomsNear's list - other than it and its
|
||||
// coinciding copies, as they scatter.
|
||||
auto others_of = [&](size_t ci, size_t ri, size_t ai, const gemmi::Position &own,
|
||||
const std::vector<ModelNeighbour> &near) {
|
||||
std::vector<Scattering> out;
|
||||
for (const ModelNeighbour &nb : near) {
|
||||
if (nb.chain == static_cast<int>(ci) && nb.residue == static_cast<int>(ri) && nb.atom == static_cast<int>(ai) &&
|
||||
nb.pos.dist(own) < 0.5)
|
||||
continue;
|
||||
const gemmi::Residue &r = model.chains[nb.chain].residues[nb.residue];
|
||||
const gemmi::Atom &a = r.atoms[nb.atom];
|
||||
out.push_back({nb.pos, a.occ, &radial.Table(ScattererOf(r, a), a.b_iso)});
|
||||
}
|
||||
return out;
|
||||
};
|
||||
auto tails = [&](const std::vector<Scattering> &others, const gemmi::Position &p) {
|
||||
double sum = 0;
|
||||
for (const Scattering &o : others)
|
||||
sum += o.occ * RadialDensity::At(*o.density, p.dist(o.pos));
|
||||
return sum;
|
||||
};
|
||||
// The map's scale, per electron (log), from the model's macromolecule: each C, N and O's height in 2mFo-DFc over
|
||||
// what the model puts there, the atom itself at its B and occupancy and the tails of its neighbours' - its
|
||||
// bonded neighbours and its riding hydrogens among them. Not from the waters: their occupancy is the model's
|
||||
// guess, and the depositions' waters show 0.3-0.5 of the height their model gives, the macromolecule's atoms
|
||||
// 0.8-1.
|
||||
std::map<const gemmi::Atom *, double> atom_calibration;
|
||||
std::pair<double, double> global_calibration{NAN, NAN};
|
||||
if (density) {
|
||||
std::vector<double> c;
|
||||
for (size_t ci = 0; ci < model.chains.size(); ci++)
|
||||
for (size_t ri = 0; ri < model.chains[ci].residues.size(); ri++) {
|
||||
const gemmi::Residue &r = model.chains[ci].residues[ri];
|
||||
if (IsWater(r) || IonAtom(r) != nullptr)
|
||||
continue;
|
||||
for (size_t ai = 0; ai < r.atoms.size(); ai++) {
|
||||
const gemmi::Atom &a = r.atoms[ai];
|
||||
if (!(a.element == gemmi::El::C || Polar(a.element.elem)) || a.occ != 1 || a.altloc)
|
||||
continue;
|
||||
const double model_height =
|
||||
radial(ScattererOf(r, a), a.b_iso, 0.0) +
|
||||
tails(others_of(ci, ri, ai, a.pos, AtomsNear(ns, model, a.pos, TAIL_RADIUS)), a.pos);
|
||||
const double v = maps.map->interpolate_value(a.pos) / model_height;
|
||||
if (v > 0) {
|
||||
atom_calibration[&a] = std::log(v);
|
||||
c.push_back(std::log(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
global_calibration = MedianSpread(c);
|
||||
}
|
||||
// f'' by Cromer & Liberman (1981) Acta Cryst. A37, 267-268, corrected as Kissel & Pratt (1990) Acta Cryst. A46,
|
||||
// 170-175 (GEMMI's fprime).
|
||||
// The anomalous map's height per unit of f'' at B (a point scatterer's), least squares through the origin on the
|
||||
// model's S and P - the scatterers there are that sit where the model puts them; NaN with fewer than three.
|
||||
double fpp[SOLVENT_SPECIES];
|
||||
double anomalous_scale = NAN;
|
||||
if (maps.anomalous != nullptr && maps.anomalous_rms > 0 && maps.wavelength_A > 0 && d_min > 0) {
|
||||
const double energy = 12398.4198 / maps.wavelength_A; // eV
|
||||
for (int k = 0; k < SOLVENT_SPECIES; k++)
|
||||
gemmi::cromer_liberman(static_cast<int>(SCATTERERS[k].el), energy, &fpp[k]);
|
||||
double fpp_s = 0, fpp_p = 0;
|
||||
gemmi::cromer_liberman(16, energy, &fpp_s);
|
||||
gemmi::cromer_liberman(15, energy, &fpp_p);
|
||||
double num = 0, den = 0;
|
||||
int n = 0;
|
||||
for (const gemmi::Chain &ch : model.chains)
|
||||
for (const gemmi::Residue &r : ch.residues)
|
||||
for (const gemmi::Atom &a : r.atoms)
|
||||
if (a.element == gemmi::El::S || a.element == gemmi::El::P) {
|
||||
const double unit = a.occ * (a.element == gemmi::El::S ? fpp_s : fpp_p) *
|
||||
PeakHeight([](double) { return 1.0; }, a.b_iso, d_min);
|
||||
num += maps.anomalous->interpolate_value(a.pos) * unit;
|
||||
den += unit * unit;
|
||||
n++;
|
||||
}
|
||||
if (n >= 3 && den > 0 && num > 0)
|
||||
anomalous_scale = num / den;
|
||||
}
|
||||
|
||||
for (size_t ci = 0; ci < model.chains.size(); ci++)
|
||||
for (size_t ri = 0; ri < model.chains[ci].residues.size(); ri++) {
|
||||
const gemmi::Residue &res = model.chains[ci].residues[ri];
|
||||
if (!IsWater(res) && IonAtom(res) == nullptr)
|
||||
continue;
|
||||
const int label = LabelSpecies(res.name);
|
||||
for (size_t ai = 0; ai < res.atoms.size(); ai++) {
|
||||
const gemmi::Atom &a = res.atoms[ai];
|
||||
if (a.is_hydrogen())
|
||||
@@ -353,15 +626,54 @@ std::vector<SolventSite> AnalyseSolventSites(const gemmi::Structure &st, double
|
||||
site.map_sigma = map_sigma(maps.map, maps.map_rms, a.pos);
|
||||
site.difference_sigma = map_sigma(maps.difference, maps.difference_rms, a.pos);
|
||||
site.anomalous_sigma = map_sigma(maps.anomalous, maps.anomalous_rms, a.pos);
|
||||
const std::vector<ModelNeighbour> near = AtomsNear(ns, model, a.pos, SEARCH_RADIUS + SOLVENT_PEAK_REACH);
|
||||
// The environment's B, and the map's scale from the macromolecule's atoms nearby where there are
|
||||
// enough of them.
|
||||
double b_sum = 0;
|
||||
int b_n = 0;
|
||||
std::vector<double> calibration;
|
||||
for (const ModelNeighbour &nb : near) {
|
||||
const gemmi::Atom &pa = model.chains[nb.chain].residues[nb.residue].atoms[nb.atom];
|
||||
if (nb.distance > SEARCH_RADIUS || (nb.chain == static_cast<int>(ci) && nb.residue == static_cast<int>(ri)))
|
||||
continue;
|
||||
if (const auto it = atom_calibration.find(&pa); it != atom_calibration.end())
|
||||
calibration.push_back(it->second);
|
||||
if (Polar(pa.element.elem) && nb.distance < BVS_RADIUS && (!a.altloc || !pa.altloc || a.altloc == pa.altloc)) {
|
||||
b_sum += pa.b_iso;
|
||||
b_n++;
|
||||
}
|
||||
}
|
||||
site.b_env = b_n > 0 ? b_sum / b_n : NAN;
|
||||
const double b_env = b_n > 0 ? site.b_env : a.b_iso;
|
||||
const double copies = a.occ * SiteSymmetry(cell, a.pos).multiplicity;
|
||||
const auto [log_k, spread] = static_cast<int>(calibration.size()) >= CALIBRATION_NEIGHBOURS
|
||||
? MedianSpread(calibration) : global_calibration;
|
||||
// The site's own density fitted with its neighbours' held, at the environment's B; an ion, whose
|
||||
// label's restraints may hold it off its density, where that fit puts it.
|
||||
const bool ion = !IsWater(res);
|
||||
gemmi::Position q = a.pos;
|
||||
site.electrons = site.electron_spread = NAN;
|
||||
if (density && std::isfinite(log_k) && copies > 0) {
|
||||
const LocalFit fit = FitSite(*maps.map, std::exp(log_k), a.pos, b_env, others_of(ci, ri, ai, a.pos, near),
|
||||
radial, ion);
|
||||
q = fit.p;
|
||||
site.electrons = 10.0 * fit.a / copies;
|
||||
site.electron_spread = std::max(ELECTRON_SPREAD_MIN, spread);
|
||||
}
|
||||
site.measured_at = q;
|
||||
site.peak_shift = q.dist(a.pos);
|
||||
|
||||
std::vector<Ligand> ligands;
|
||||
std::vector<gemmi::Position> bound_cations; // other cations closer than 2.6 A
|
||||
std::vector<gemmi::Position> inner; // the N and O closer than 2.6 A
|
||||
gemmi::Vec3 vec[BVS_CATIONS];
|
||||
for (const ModelNeighbour &nb : AtomsNear(ns, model, a.pos, SEARCH_RADIUS)) {
|
||||
for (ModelNeighbour nb : near) {
|
||||
// the site itself, its own hydrogens and its other conformers; its symmetry mates stay
|
||||
if (nb.chain == static_cast<int>(ci) && nb.residue == static_cast<int>(ri) &&
|
||||
(nb.atom != static_cast<int>(ai) || nb.distance < 0.5))
|
||||
(nb.atom != static_cast<int>(ai) || nb.pos.dist(a.pos) < 0.5))
|
||||
continue;
|
||||
nb.distance = q.dist(nb.pos);
|
||||
if (!(nb.distance < SEARCH_RADIUS))
|
||||
continue;
|
||||
const gemmi::Chain &pch = model.chains[nb.chain];
|
||||
const gemmi::Residue &pr = pch.residues[nb.residue];
|
||||
@@ -423,13 +735,39 @@ std::vector<SolventSite> AnalyseSolventSites(const gemmi::Structure &st, double
|
||||
l.sigma = std::sqrt(site.sigma_xyz * site.sigma_xyz + e * e);
|
||||
l.chem = chem;
|
||||
l.nitrogen = pa.element == gemmi::El::N;
|
||||
l.n7_off_plane = false;
|
||||
if (pa.name == "N7" && d < 2.6) {
|
||||
// the purine's ring, as the image the neighbour is, and its O6 or N6
|
||||
std::vector<gemmi::Atom> ring;
|
||||
const gemmi::Atom *o6n6 = nullptr;
|
||||
for (const gemmi::Atom &ra : pr.atoms) {
|
||||
static const std::set<std::string> RING = {"N9", "C8", "N7", "C5", "C6", "N1", "C2", "N3", "C4"};
|
||||
if (RING.count(ra.name) && (!a.altloc || !ra.altloc || ra.altloc == a.altloc)) {
|
||||
ring.push_back(ra);
|
||||
ring.back().pos = gemmi::Position(nb.image.apply(ra.pos));
|
||||
}
|
||||
if (ra.name == "O6" || ra.name == "N6")
|
||||
o6n6 = &ra;
|
||||
}
|
||||
if (ring.size() == 9 && o6n6 != nullptr) {
|
||||
site.n7_ligands++;
|
||||
std::vector<gemmi::Atom *> ptrs;
|
||||
for (gemmi::Atom &ra : ring)
|
||||
ptrs.push_back(&ra);
|
||||
const double plane = std::fabs(gemmi::get_distance_from_plane(q, gemmi::find_best_plane(ptrs)));
|
||||
const double side = q.dist(gemmi::Position(nb.image.apply(o6n6->pos)));
|
||||
l.n7_off_plane = plane > N7_PLANE_MAX + l.sigma || side < N7_O6N6_MIN - l.sigma ||
|
||||
side > N7_O6N6_MAX + l.sigma;
|
||||
site.n7_off_plane += l.n7_off_plane;
|
||||
}
|
||||
}
|
||||
if (d < BVS_RADIUS)
|
||||
for (int c = 0; c < BVS_CATIONS; c++) {
|
||||
// Following Brown & Altermatt (1985) Acta Cryst. B41, 244-247, occupancy weighted as
|
||||
// Muller et al. (2003) Acta Cryst. D59, 32-37
|
||||
l.valence[c] = pa.occ * std::exp(((l.nitrogen ? R0_N[c] : R0_O[c]) - d) / BV_B);
|
||||
site.bvs[c] += l.valence[c];
|
||||
vec[c] += (nb.pos - a.pos) * (l.valence[c] / d);
|
||||
vec[c] += (nb.pos - q) * (l.valence[c] / d);
|
||||
}
|
||||
ligands.push_back(l);
|
||||
}
|
||||
@@ -449,20 +787,51 @@ std::vector<SolventSite> AnalyseSolventSites(const gemmi::Structure &st, double
|
||||
? inner[i].dist(inner[j])
|
||||
: std::min(site.min_ligand_distance, inner[i].dist(inner[j]));
|
||||
|
||||
for (int s = 0; s < SOLVENT_SPECIES; s++)
|
||||
site.score[s] = ScoreSpecies(s, site, ligands, label);
|
||||
// NH4+ is reported, not decided: water, Mg, Na, K, Ca, Cl
|
||||
int best = 0, second = -1;
|
||||
for (int s = 1; s < static_cast<int>(SolventSpecies::NH4); s++)
|
||||
if (site.score[s] > site.score[best]) {
|
||||
second = best;
|
||||
best = s;
|
||||
} else if (second < 0 || site.score[s] > site.score[second])
|
||||
second = s;
|
||||
site.best = static_cast<SolventSpecies>(best);
|
||||
site.ambiguous = site.score[best] - site.score[second] < SOLVENT_AMBIGUOUS_MARGIN;
|
||||
// The electrons each species would show on the scale of the fit (its density's height over a water's at
|
||||
// the environment's B), and the anomalous signal each would give. A site on a special position counts
|
||||
// its coinciding copies.
|
||||
std::array<double, SOLVENT_SPECIES> expected_electrons{};
|
||||
if (std::isfinite(site.electrons))
|
||||
for (int k = 0; k < SOLVENT_SPECIES; k++)
|
||||
expected_electrons[k] = 10.0 * radial(SCATTERERS[k], b_env, 0.0) / radial(SCATTERERS[0], b_env, 0.0);
|
||||
for (int k = 0; k < SOLVENT_SPECIES; k++)
|
||||
site.anomalous_expected[k] =
|
||||
std::isfinite(anomalous_scale)
|
||||
? anomalous_scale * fpp[k] * copies * PeakHeight([](double) { return 1.0; }, b_env, d_min) /
|
||||
maps.anomalous_rms
|
||||
: NAN;
|
||||
if (std::isfinite(anomalous_scale))
|
||||
site.anomalous_sigma = map_sigma(maps.anomalous, maps.anomalous_rms, q);
|
||||
|
||||
site_ligands.push_back(std::move(ligands));
|
||||
site_expected.push_back(expected_electrons);
|
||||
out.push_back(site);
|
||||
}
|
||||
}
|
||||
|
||||
WaterElectrons waters;
|
||||
std::vector<double> w;
|
||||
for (const SolventSite &site : out)
|
||||
if (SolventLabelIsWater(site) && site.electrons > 0)
|
||||
w.push_back(std::log(site.electrons));
|
||||
if (static_cast<int>(w.size()) >= WATER_STATISTICS_MIN) {
|
||||
const auto [m, spread] = MedianSpread(w);
|
||||
waters = {std::exp(m), spread};
|
||||
}
|
||||
for (size_t i = 0; i < out.size(); i++) {
|
||||
SolventSite &site = out[i];
|
||||
for (int s = 0; s < SOLVENT_SPECIES; s++)
|
||||
site.score[s] = ScoreSpecies(s, site, site_ligands[i], site_expected[i], waters);
|
||||
// NH4+ is reported, not decided: water, Mg, Na, K, Ca, Cl
|
||||
int best = 0, second = -1;
|
||||
for (int s = 1; s < static_cast<int>(SolventSpecies::NH4); s++)
|
||||
if (site.score[s] > site.score[best]) {
|
||||
second = best;
|
||||
best = s;
|
||||
} else if (second < 0 || site.score[s] > site.score[second])
|
||||
second = s;
|
||||
site.best = static_cast<SolventSpecies>(best);
|
||||
site.ambiguous = site.score[best] - site.score[second] < SOLVENT_AMBIGUOUS_MARGIN;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -69,6 +69,25 @@ struct SolventSite {
|
||||
std::array<double, BVS_CATIONS> bvs{}, nvecsum{};
|
||||
// the maps at the site, in their rms; NaN where there is no such map
|
||||
double map_sigma = 0, difference_sigma = 0, anomalous_sigma = 0;
|
||||
// An ion is read where its own density puts it, not where the restraints of its label hold it: the highest point
|
||||
// of 2mFo-DFc within SOLVENT_PEAK_REACH of the modelled position (its shell, bands and bond valences are measured
|
||||
// from there), and how far that is from it (A). A water is read where it is modelled (shift 0).
|
||||
gemmi::Position measured_at;
|
||||
double peak_shift = 0;
|
||||
// The mean B of the N and O closer than 3.5 A (the environment's B, as CheckMyMetal compares a metal's with its
|
||||
// ligands'); NaN with none.
|
||||
double b_env = 0;
|
||||
// The electrons the 2mFo-DFc map shows at the site: its height there over the height of one electron of the
|
||||
// neighbours' (each neighbour's height over what its element at its B gives, the median of them), at the
|
||||
// environment's B and as a water's shape - 10 for a water as dense as its neighbours; NaN without the map or
|
||||
// neighbours. `electron_spread` is the spread of the neighbours' calibration (rms of the log), floored.
|
||||
double electrons = 0, electron_spread = 0;
|
||||
// The anomalous map's height expected at the site for each species (f'' at the wavelength, on the scale the
|
||||
// model's S and P show), in the map's rms; NaN where there is no anomalous map or nothing to put it on a scale.
|
||||
std::array<double, SOLVENT_SPECIES> anomalous_expected{};
|
||||
// Purine N7 among the first-shell ligands (closer than 2.6 A), and those of them a divalent ion could not hold:
|
||||
// the site more than 1.0 A out of the base's plane, or not 3.5-3.9 A from its O6 or N6 (NAR 2017).
|
||||
int n7_ligands = 0, n7_off_plane = 0;
|
||||
|
||||
std::array<double, SOLVENT_SPECIES> score{}; // log-score per species, SolventSpecies order
|
||||
SolventSpecies best = SolventSpecies::Water; // the best-scoring of water, Mg, Na, K, Ca and Cl
|
||||
@@ -79,7 +98,7 @@ struct SolventSite {
|
||||
constexpr double SOLVENT_AMBIGUOUS_MARGIN = 2.0;
|
||||
|
||||
// The maps a site is read in: 2mFo-DFc, mFo-DFc and the anomalous difference map, each with its rms; any of
|
||||
// them may be missing (null).
|
||||
// them may be missing (null). `wavelength_A`: the data's, for the anomalous scattering expected (0: unknown).
|
||||
struct SolventMaps {
|
||||
const gemmi::Grid<float> *map = nullptr;
|
||||
double map_rms = 0;
|
||||
@@ -87,8 +106,12 @@ struct SolventMaps {
|
||||
double difference_rms = 0;
|
||||
const gemmi::Grid<float> *anomalous = nullptr;
|
||||
double anomalous_rms = 0;
|
||||
double wavelength_A = 0;
|
||||
};
|
||||
|
||||
// How far from an ion's modelled position its density's highest point is looked for (A).
|
||||
constexpr double SOLVENT_PEAK_REACH = 0.6;
|
||||
|
||||
// Every water and single-atom ion of the first model of `st` (in its cell and space group; hydrogens are
|
||||
// ignored), in model order. `d_min`: the resolution the model was refined at, for the coordinate error
|
||||
// (0 for a model with no data).
|
||||
|
||||
@@ -74,6 +74,7 @@ copy_license bitshuffle-hperf.txt compression/bitshuffle_hperf/LICENSE-APACHE
|
||||
copy_license lz4.txt compression/lz4/LICENSE
|
||||
copy_license xilinx-hls-headers.txt fpga/include/LICENSE.HLS_Headers
|
||||
copy_license gemmi.txt gemmi_gph/LICENSE.txt
|
||||
copy_license larch.txt gemmi_gph/LICENSE-larch.txt
|
||||
copy_license fast-feedback-indexer.txt image_analysis/indexing/fast-feedback-indexer/LICENSE.md
|
||||
copy_license ccp4-monomer-library.txt image_analysis/structure_refinement/monomers/COPYING
|
||||
# GEMMI bundles six third-party headers under its own include tree, each under its own licence
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2010-2026 Matthew Newville, The University of Chicago
|
||||
Mauro Rovezzi, University Grenoble Alpes, CNRS
|
||||
Bruce Ravel, National Institute of Science and Technology
|
||||
Margaret Koker, Lawrence University
|
||||
Ryuichi Shimogawa, Stony Brook University
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXP80RESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE qUSE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+14
-6
@@ -502,19 +502,27 @@ namespace {
|
||||
" species, N/O in the bands 1.9-2.3/2.3-2.6/2.6-3.2 A, and their neighbours:{}",
|
||||
output_prefix, ion_rows.empty() ? std::string(" none") : ion_rows)));
|
||||
if (build.ran) {
|
||||
std::string relabelled;
|
||||
for (const SolventEdit &e : build.edits)
|
||||
if (e.kind == SolventEdit::Kind::Relabelled)
|
||||
relabelled += fmt::format("\n {} -> {}: {}", e.site, e.species, e.reason);
|
||||
Add(s, KeyInt("REFINE_SOLVENT_ADDED", build.added));
|
||||
Add(s, KeyInt("REFINE_SOLVENT_REMOVED", build.removed));
|
||||
Add(s, KeyInt("REFINE_SOLVENT_RELABELLED", build.relabelled));
|
||||
Add(s, KeyInt("REFINE_SOLVENT_NOT_SOLVENT", build.not_solvent));
|
||||
Add(s, KeyInt("REFINE_SOLVENT_BUILD_ROUNDS", build.rounds));
|
||||
Add(s, KeyReal("REFINE_SOLVENT_BUILD_SECONDS", build.seconds, "{:.1f}", true));
|
||||
Add(s, Prose(fmt::format(
|
||||
" Waters were added at difference-map peaks with a hydrogen-bond partner and removed where the\n"
|
||||
" maps no longer hold them, each round a refinement kept only where it lowered R-free: {}\n"
|
||||
" added, {} of the model's taken out, in {} round{} ({}). {} peaks are not solvent (bonded to\n"
|
||||
" the model, beside a displaced atom, a truncated side chain, a molecule's or elongated density,\n"
|
||||
" denser than S and P): reported, not filled. Each, with its reason, in {}_solvent.json.",
|
||||
build.added, build.removed, build.rounds, build.rounds == 1 ? "" : "s", build.stop,
|
||||
build.not_solvent, output_prefix)));
|
||||
" maps no longer hold them, and waters and ions relabelled where their surroundings and density\n"
|
||||
" support another species, each round a refinement kept only where it lowered R-free: {}\n"
|
||||
" added, {} of the model's taken out, {} relabelled, in {} round{} ({}). {} peaks are not solvent\n"
|
||||
" (bonded to the model, beside a displaced atom, a truncated side chain, a molecule's or elongated\n"
|
||||
" density, denser than S and P): reported, not filled. Each, with its reason, in\n"
|
||||
" {}_solvent.json.{}",
|
||||
build.added, build.removed, build.relabelled, build.rounds, build.rounds == 1 ? "" : "s",
|
||||
build.stop, build.not_solvent, output_prefix,
|
||||
relabelled.empty() ? std::string() : " The relabelled sites, new species and old, by score:" + relabelled)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,16 @@ void WriteSolventSites(const std::vector<SolventSite> &sites, const SolventBuild
|
||||
const char *cations[BVS_CATIONS] = {"MG", "NA", "K", "CA"};
|
||||
nlohmann::json list = nlohmann::json::array();
|
||||
for (const SolventSite &s : sites) {
|
||||
nlohmann::json bvs, nvecsum, score;
|
||||
nlohmann::json bvs, nvecsum, score, anomalous_expected;
|
||||
for (int c = 0; c < BVS_CATIONS; c++) {
|
||||
bvs[cations[c]] = s.bvs[c];
|
||||
nvecsum[cations[c]] = s.nvecsum[c];
|
||||
}
|
||||
for (int k = 0; k < SOLVENT_SPECIES; k++)
|
||||
{
|
||||
score[SolventSpeciesName(static_cast<SolventSpecies>(k))] = s.score[k];
|
||||
anomalous_expected[SolventSpeciesName(static_cast<SolventSpecies>(k))] = num(s.anomalous_expected[k]);
|
||||
}
|
||||
list.push_back({{"label", s.label}, {"chain", s.chain}, {"seqid", s.seqid},
|
||||
{"altloc", s.altloc ? std::string(1, s.altloc) : std::string()},
|
||||
{"xyz", {s.pos.x, s.pos.y, s.pos.z}}, {"occupancy", s.occupancy}, {"b_iso", s.b_iso},
|
||||
@@ -60,7 +63,11 @@ void WriteSolventSites(const std::vector<SolventSite> &sites, const SolventBuild
|
||||
{"nearest_ion_A", num(s.nearest_ion)}, {"ions_within_4.2", s.ions_within_42},
|
||||
{"ions_within_6", s.ions_within_6}, {"bvs", bvs}, {"nvecsum", nvecsum},
|
||||
{"map_sigma", num(s.map_sigma)}, {"difference_sigma", num(s.difference_sigma)},
|
||||
{"anomalous_sigma", num(s.anomalous_sigma)}, {"score", score},
|
||||
{"anomalous_sigma", num(s.anomalous_sigma)}, {"anomalous_expected", anomalous_expected},
|
||||
{"measured_at", {s.measured_at.x, s.measured_at.y, s.measured_at.z}},
|
||||
{"peak_shift_A", s.peak_shift}, {"b_env", num(s.b_env)}, {"electrons", num(s.electrons)},
|
||||
{"electron_spread", num(s.electron_spread)}, {"n7_ligands", s.n7_ligands},
|
||||
{"n7_off_plane", s.n7_off_plane}, {"score", score},
|
||||
{"best", SolventSpeciesName(s.best)}, {"ambiguous", s.ambiguous},
|
||||
{"agrees", SolventLabelAgrees(s)}, {"neighbours", s.neighbours}});
|
||||
}
|
||||
@@ -71,8 +78,9 @@ void WriteSolventSites(const std::vector<SolventSite> &sites, const SolventBuild
|
||||
edits.push_back({{"kind", SolventEditKindName(e.kind)}, {"round", e.round}, {"site", e.site},
|
||||
{"xyz", {e.pos.x, e.pos.y, e.pos.z}}, {"difference_sigma", num(e.difference_sigma)},
|
||||
{"map_sigma", num(e.map_sigma)}, {"b_iso", num(e.b_iso)},
|
||||
{"elongation", num(e.elongation)}, {"reason", e.reason}});
|
||||
{"elongation", num(e.elongation)}, {"species", e.species}, {"reason", e.reason}});
|
||||
out["build"] = {{"rounds", build->rounds}, {"added", build->added}, {"removed", build->removed},
|
||||
{"relabelled", build->relabelled},
|
||||
{"not_solvent", build->not_solvent}, {"stop", build->stop}, {"seconds", build->seconds},
|
||||
{"edits", edits}};
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <gemmi/mmread_gz.hpp>
|
||||
@@ -377,6 +378,16 @@ TEST_CASE("RefinementRestraints_metal_links_outer_sphere", "[Refinement]") {
|
||||
found += (r.atom[0] == mg && r.atom[1] == outer) || (r.atom[0] == outer && r.atom[1] == mg);
|
||||
CHECK(found == 1);
|
||||
}
|
||||
// decided once: the record left as a contact stays one where the refinement has moved the water into the inner
|
||||
// shell, and the six taken stay bonds where one has moved out of it
|
||||
const std::set<std::string> outer_records = BuildRefinementTopology(st).outer_records;
|
||||
REQUIRE(outer_records.size() == 1);
|
||||
res[6].atoms[0].pos = site + gemmi::Position(1, 1, 1) * (2.1 / std::sqrt(3.0));
|
||||
res[0].atoms[0].pos = site + gemmi::Position(1, 0, 0) * 2.9;
|
||||
const RefinementTopology moved = BuildRefinementTopology(st, false, &outer_records);
|
||||
CHECK(moved.metal_links == 6);
|
||||
CHECK(moved.outer_records == outer_records);
|
||||
CHECK(BuildRefinementTopology(st).metal_links == 6); // re-gated: the other record now refused instead
|
||||
}
|
||||
|
||||
// Deposited models cut down to a ligand and the residues within 4.2 A of it (test_data/ligands, from the PDB entries
|
||||
|
||||
@@ -80,7 +80,7 @@ TEST_CASE("SolventBuild_peak_with_and_without_partner", "[Solvent]") {
|
||||
const gemmi::Grid<float> map = map_with(st.cell, {}, 0.0f, 1.5f);
|
||||
const SolventMaps maps{&map, 1.0, &diff, 1.0, nullptr, 0};
|
||||
|
||||
SolventRound r = PickSolvent(st, maps, {}, {}, 300, 1);
|
||||
SolventRound r = PickSolvent(st, maps, {}, {}, {}, 300, 1);
|
||||
REQUIRE(r.added == 1);
|
||||
CHECK(r.not_solvent == 0);
|
||||
CHECK(r.refused["no hydrogen-bond partner"] == 1);
|
||||
@@ -112,7 +112,7 @@ TEST_CASE("SolventBuild_tetrahedral_cluster_refused", "[Solvent]") {
|
||||
const gemmi::Grid<float> map = map_with(st.cell, {}, 0.0f, 1.5f);
|
||||
const SolventMaps maps{&map, 1.0, &diff, 1.0, nullptr, 0};
|
||||
|
||||
const SolventRound r = PickSolvent(st, maps, {}, {}, 300, 1);
|
||||
const SolventRound r = PickSolvent(st, maps, {}, {}, {}, 300, 1);
|
||||
CHECK(r.added == 0);
|
||||
CHECK(count_kind(r, SolventEdit::Kind::NotSolvent) >= 1);
|
||||
bool tetrahedral = false;
|
||||
@@ -144,10 +144,45 @@ TEST_CASE("SolventBuild_removal", "[Solvent]") {
|
||||
}
|
||||
sites[1].difference_sigma = -4.0;
|
||||
|
||||
CHECK(PickSolvent(st, maps, sites, {}, 300, 1).removed == 1);
|
||||
SolventRound r = PickSolvent(st, maps, sites, {"HOH A3"}, 300, 1);
|
||||
CHECK(PickSolvent(st, maps, sites, {}, {}, 300, 1).removed == 1);
|
||||
SolventRound r = PickSolvent(st, maps, sites, {"HOH A3"}, {}, 300, 1);
|
||||
CHECK(r.removed == 2);
|
||||
ApplySolventEdits(st, r.edits);
|
||||
REQUIRE(st.models[0].chains[0].residues.size() == 1);
|
||||
CHECK(st.models[0].chains[0].residues[0].seqid.num == 1);
|
||||
}
|
||||
|
||||
// A water among six waters at 2.07 A relabelled Mg: the residue, element and atom name change and it gets a metal
|
||||
// record for each of its six ligands; relabelled water again, the records go.
|
||||
TEST_CASE("SolventBuild_relabel", "[Solvent]") {
|
||||
gemmi::Structure st = box();
|
||||
const gemmi::Position c(12, 12, 12);
|
||||
add_atom(st, "HOH", "O", gemmi::El::O, c);
|
||||
for (int axis = 0; axis < 3; axis++)
|
||||
for (double sign : {-1.0, 1.0}) {
|
||||
gemmi::Position p = c;
|
||||
(axis == 0 ? p.x : axis == 1 ? p.y : p.z) += sign * 2.07;
|
||||
add_atom(st, "HOH", "O", gemmi::El::O, p);
|
||||
}
|
||||
std::vector<SolventEdit> edits(1);
|
||||
edits[0].kind = SolventEdit::Kind::Relabelled;
|
||||
edits[0].site = "HOH A1";
|
||||
edits[0].chain = "A";
|
||||
edits[0].seqid = gemmi::SeqId(1, ' ');
|
||||
edits[0].species = "MG";
|
||||
ApplySolventEdits(st, edits);
|
||||
const gemmi::Residue &r = st.models[0].chains[0].residues[0];
|
||||
CHECK(r.name == "MG");
|
||||
CHECK(r.atoms[0].name == "MG");
|
||||
CHECK(r.atoms[0].element == gemmi::El::Mg);
|
||||
REQUIRE(st.connections.size() == 6);
|
||||
for (const gemmi::Connection &conn : st.connections)
|
||||
CHECK(conn.partner2.res_id.name == "MG");
|
||||
|
||||
edits[0].site = "MG A1";
|
||||
edits[0].species = "HOH";
|
||||
ApplySolventEdits(st, edits);
|
||||
CHECK(st.models[0].chains[0].residues[0].name == "HOH");
|
||||
CHECK(st.models[0].chains[0].residues[0].atoms[0].element == gemmi::El::O);
|
||||
CHECK(st.connections.empty());
|
||||
}
|
||||
@@ -8,6 +8,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <gemmi/dencalc.hpp>
|
||||
#include <gemmi/it92.hpp>
|
||||
|
||||
#include "../image_analysis/structure_refinement/MonomerLibrary.h"
|
||||
#include "../image_analysis/structure_refinement/RefinementRestraints.h"
|
||||
#include "../image_analysis/structure_refinement/SolventSites.h"
|
||||
@@ -230,3 +233,106 @@ TEST_CASE("SolventSites_coordinate_error_blurs_the_bands", "[Solvent]") {
|
||||
CHECK(blurred.score[mg] - blurred.score[na] < sharp.score[mg] - sharp.score[na]);
|
||||
CHECK(blurred.best != SolventSpecies::Water);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A residue of the embedded dictionary at its ideal coordinates (hydrogens left out), moved by `shift`.
|
||||
void add_residue(gemmi::Structure &st, const std::string &code, const gemmi::Position &shift) {
|
||||
gemmi::Chain &ch = st.models[0].chains[0];
|
||||
const gemmi::ChemComp &cc = EmbeddedMonomerLibrary().monomers.at(code);
|
||||
gemmi::Residue r;
|
||||
r.name = code;
|
||||
r.seqid = gemmi::SeqId(static_cast<int>(ch.residues.size()) + 1, ' ');
|
||||
for (const gemmi::ChemComp::Atom &ca : cc.atoms) {
|
||||
if (ca.is_hydrogen())
|
||||
continue;
|
||||
gemmi::Atom a;
|
||||
a.name = ca.id;
|
||||
a.element = ca.el;
|
||||
a.pos = gemmi::Position(ca.xyz) + shift;
|
||||
a.occ = 1.0f;
|
||||
a.b_iso = 30.0f;
|
||||
r.atoms.push_back(a);
|
||||
}
|
||||
ch.residues.push_back(r);
|
||||
}
|
||||
|
||||
// The model's density on a grid (no blur beyond the atoms' B), as a stand-in for the 2mFo-DFc map.
|
||||
gemmi::Grid<float> model_map(const gemmi::Structure &st, double d_min) {
|
||||
gemmi::DensityCalculator<gemmi::IT92<float>, float> dc;
|
||||
dc.d_min = d_min;
|
||||
dc.rate = 2.0;
|
||||
dc.set_grid_cell_and_spacegroup(st);
|
||||
dc.put_model_density_on_grid(st.models[0]);
|
||||
return dc.grid;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// The electrons a site shows, its own density fitted with its neighbours' held: a Cl- among four donors reads ~18
|
||||
// and is called Cl whichever label it carries; a water there reads as a 10-electron scatterer and is called water.
|
||||
TEST_CASE("SolventSites_electrons_decide_halide_from_water", "[Solvent]") {
|
||||
for (const bool chloride : {true, false}) {
|
||||
CAPTURE(chloride);
|
||||
gemmi::Structure st = empty_box();
|
||||
// the macromolecule the map's scale is read from
|
||||
for (int k = 0; k < 6; k++)
|
||||
add_residue(st, "TRP", gemmi::Position(5 + 5 * k, k % 2 == 0 ? 6 : 34, k % 3 == 0 ? 8 : 30));
|
||||
const double t = 3.2 / std::sqrt(3.0);
|
||||
for (const auto &[x, y, z] : std::vector<std::array<double, 3>>{{1, 1, 1}, {1, -1, -1}, {-1, 1, -1}, {-1, -1, 1}})
|
||||
add_atom(st, "GLY", "N", gemmi::El::N, gemmi::Position(CENTRE.x + t * x, CENTRE.y + t * y, CENTRE.z + t * z));
|
||||
if (chloride) {
|
||||
add_atom(st, "CL", "CL", gemmi::El::Cl, CENTRE);
|
||||
st.models[0].chains[0].residues.back().atoms[0].charge = -1;
|
||||
} else
|
||||
add_atom(st, "HOH", "O", gemmi::El::O, CENTRE);
|
||||
for (gemmi::Residue &r : st.models[0].chains[0].residues)
|
||||
for (gemmi::Atom &a : r.atoms)
|
||||
a.b_iso = 30.0f;
|
||||
const gemmi::Grid<float> map = model_map(st, 1.5);
|
||||
// labelled water either way
|
||||
gemmi::Residue &site = st.models[0].chains[0].residues.back();
|
||||
site.name = "HOH";
|
||||
site.atoms[0] = gemmi::Atom();
|
||||
site.atoms[0].name = "O";
|
||||
site.atoms[0].element = gemmi::El::O;
|
||||
site.atoms[0].pos = CENTRE;
|
||||
site.atoms[0].occ = 1.0f;
|
||||
site.atoms[0].b_iso = 30.0f;
|
||||
SolventMaps maps;
|
||||
maps.map = ↦
|
||||
maps.map_rms = 1.0;
|
||||
const SolventSite &s = site_labelled(AnalyseSolventSites(st, 1.5, maps), "HOH");
|
||||
CHECK(s.electrons == Catch::Approx(chloride ? 18.0 : 8.0).epsilon(0.25)); // the model's water: O only
|
||||
CHECK(s.best == (chloride ? SolventSpecies::Cl : SolventSpecies::Water));
|
||||
}
|
||||
}
|
||||
|
||||
// A divalent ion bound to a purine N7 lies in the base's plane, 3.5-3.9 A from its O6 (NAR 2017): one 1.5 A out of the
|
||||
// plane is flagged, and costs Mg - not Na - its score.
|
||||
TEST_CASE("SolventSites_N7_out_of_plane", "[Solvent]") {
|
||||
auto site_at = [](bool in_plane) {
|
||||
gemmi::Structure st = empty_box();
|
||||
add_residue(st, "G", CENTRE);
|
||||
const gemmi::Residue &g = st.models[0].chains[0].residues[0];
|
||||
const gemmi::Position n7 = g.find_atom("N7", '*')->pos, c5 = g.find_atom("C5", '*')->pos,
|
||||
c8 = g.find_atom("C8", '*')->pos;
|
||||
// outward from N7, 10 degrees off the bisector of C5-N7-C8 away from O6 (3.8 A from it), in the plane; or
|
||||
// tilted 46 degrees out of it; 2.2 A from N7 either way
|
||||
gemmi::Vec3 out = (n7 - c5).normalized() + (n7 - c8).normalized();
|
||||
out = out.normalized();
|
||||
const gemmi::Vec3 normal = (c5 - n7).cross(c8 - n7).normalized();
|
||||
const double turn = -10.0 * 3.14159265358979 / 180.0;
|
||||
const gemmi::Vec3 in_dir = out * std::cos(turn) + normal.cross(out) * std::sin(turn);
|
||||
const gemmi::Vec3 dir = in_plane ? in_dir : (in_dir * std::cos(0.8) + normal * std::sin(0.8));
|
||||
add_atom(st, "MG", "MG", gemmi::El::Mg, n7 + gemmi::Position(dir * 2.2));
|
||||
return site_labelled(AnalyseSolventSites(st, 0.0, SolventMaps{}), "MG");
|
||||
};
|
||||
const SolventSite in = site_at(true), off = site_at(false);
|
||||
CHECK(in.n7_ligands == 1);
|
||||
CHECK(in.n7_off_plane == 0);
|
||||
CHECK(off.n7_ligands == 1);
|
||||
CHECK(off.n7_off_plane == 1);
|
||||
const int mg = static_cast<int>(SolventSpecies::Mg), na = static_cast<int>(SolventSpecies::Na);
|
||||
CHECK(off.score[mg] - off.score[na] < in.score[mg] - in.score[na]);
|
||||
}
|
||||
Reference in new issue
Block a user