Validation
validation
Validation and comparison utilities for chemical shift predictions.
Functions:
compare_chemical_shifts(predicted, reference, atom_types=None)
Compare two sets of chemical shifts and calculate validation metrics.
This function aligns predicted and reference chemical shifts by chain and residue ID, then calculates the Root Mean Square Error (RMSE) and Pearson correlation coefficient (R) for each specified atom type.
Educational Note: - RMSE provides a measure of the absolute accuracy of the predictions in ppm. - Pearson R measures the linear correlation, sensitive to how well the relative shifts (the "spread") are captured, even if there is a global offset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicted
|
Dict[str, Dict[int, Dict[str, float]]]
|
Predicted shifts {chain_id: {res_id: {atom: val}}} |
required |
reference
|
Dict[str, Dict[int, Dict[str, float]]]
|
Reference shifts (e.g., experimental or ShiftX2) |
required |
atom_types
|
Optional[List[str]]
|
List of atoms to compare. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, float]]
|
A dictionary of metrics per atom type: {atom: {"rmse": float, "pearson": float}} |
Source code in synth_nmr/validation.py
calculate_rpf_scores(predicted_noes, experimental_restraints, distance_cutoff=5.0)
Calculate Recall, Precision, and F-measure (RPF) scores for NOE validation.
EDUCATIONAL BACKGROUND — The RPF Validation Framework ─────────────────────────────────────────────────────────────────── The RPF framework (Montelione et al., 2005) is the gold standard for measuring the consistency between a structural model and experimental NOE data.
-
Recall (R): What fraction of the EXPERIMENTAL restraints are satisfied by the model? If R is low, the model is failing to explain the data. Formula: R = satisfied_restraints / total_experimental_restraints
-
Precision (P): What fraction of the PREDICTED NOEs (based on the structure's coordinates) are actually observed in the experimental data? If P is low, the model contains short-range contacts that the data says shouldn't be there. Formula: P = supported_predictions / total_predicted_noes
-
F-measure (F): The harmonic mean of R and P. This provides a single, balanced metric of structural quality. High F (> 0.7) indicates a model that is both accurate and complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicted_noes
|
List[Dict]
|
NOE list from nmr.calculate_synthetic_noes. |
required |
experimental_restraints
|
List[Dict]
|
Parsed experimental upper bounds. |
required |
distance_cutoff
|
float
|
Distance (Å) to consider a pair "close". |
5.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict[str, float]
|
{"recall": float, "precision": float, "f_measure": float} |
Source code in synth_nmr/validation.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
calculate_dp_score(rpf_scores)
Calculate the Discriminating Power (DP) score.
EDUCATIONAL BACKGROUND — The DP-Score ─────────────────────────────────────────────────────────────────── The DP-score (Huang et al., 2012) normalizes the F-measure to provide a standardized metric of structural quality.
It compares the F-measure of the model against the F-measure expected for a "random coil" or poorly folded structure.
- DP > 0.7: High-quality, native-like fold.
- DP < 0.5: Likely an incorrect fold or highly disordered.
Formula: DP = (F_model - F_random) / (1 - F_random) (Note: For this project, we use a simplified baseline of F_random = 0.1)
Source code in synth_nmr/validation.py
calculate_cs_r_factor(predicted, reference, atom='CA', res_name_map=None)
Calculate the Chemical Shift R-factor (Rcs).
EDUCATIONAL BACKGROUND — Chemical Shift R-factors ─────────────────────────────────────────────────────────────────── Inspired by X-ray Crystallography, the Rcs factor measures the normalised agreement between predicted and experimental shifts.
Unlike RMSE (which is in absolute ppm), the R-factor is dimensionless, making it comparable across different atom types (CA vs. N vs. H).
Correct formula (Wishart 1995 / SPARTA+ convention): Rcs = Σ |δ_calc − δ_exp| / Σ |δ_exp − δ_rc|
where δ_rc is the per-residue random-coil baseline. The denominator is the total secondary shift amplitude in the reference data — normalising by this quantity ensures Rcs ~ 1 for a random model and Rcs ~ 0 for a perfect model.
NOTE: Correct normalisation requires knowing each residue's amino acid
type. Supply res_name_map ({res_id: three_letter_code}) for full
accuracy. When omitted the function falls back to using the mean
random-coil value across all 20 standard amino acids for the requested
atom type, which is a reasonable approximation for CA (mean ~ 56 ppm).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicted
|
Dict[str, Dict[int, Dict[str, float]]]
|
{chain_id: {res_id: {atom_name: value}}} |
required |
reference
|
Dict[str, Dict[int, Dict[str, float]]]
|
{chain_id: {res_id: {atom_name: value}}} |
required |
atom
|
str
|
Atom type to compare (default "CA"). |
'CA'
|
res_name_map
|
Optional[Dict[int, str]]
|
Optional {res_id: three_letter_code} for exact RC lookup. |
None
|
Returns:
| Type | Description |
|---|---|
float
|
Dimensionless R-factor. Returns 0.0 if there is no overlapping data. |
Source code in synth_nmr/validation.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
calculate_rdc_q_factor(predicted, experimental)
Calculate the RDC Q-factor (Cornilescu Q).
EDUCATIONAL BACKGROUND — The RDC Q-factor ─────────────────────────────────────────────────────────────────── The Q-factor is the standard metric for Residual Dipolar Coupling (RDC) validation. It measures the agreement between calculated and observed couplings, normalized by the magnitude of the observed data.
Formula: Q = sqrt( sum( (D_calc - D_exp)^2 ) / sum( D_exp^2 ) )
Interpretation: - Q < 0.2: Excellent agreement (high-resolution structure). - 0.2 < Q < 0.5: Reasonable agreement. - Q > 0.5: Poor agreement or incorrect alignment tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicted
|
Dict[int, float]
|
Map of {residue_id: RDC_value} |
required |
experimental
|
Dict[int, float]
|
Map of {residue_id: RDC_value} |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The Q-factor. |
Source code in synth_nmr/validation.py
validate_against_bmrb(bmrb_id, structure, predictor=None)
Automated validation of a structure against a BMRB entry.
This high-level function: 1. Downloads experimental data from BMRB. 2. Predicts observables for the provided structure. 3. Calculates accuracy metrics (RMSE, R-factor, RPF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bmrb_id
|
int
|
BMRB accession ID. |
required |
structure
|
AtomArray
|
biotite.structure.AtomArray. |
required |
predictor
|
Any
|
Optional custom shift predictor. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict[str, Dict[str, float]]
|
Validation metrics. |
Source code in synth_nmr/validation.py
print_validation_report(stats)
Print a formatted validation report.