torchref.refinement.targets.adp package
- class torchref.refinement.targets.adp.ADPTarget(model=None, verbose=0, **kwargs)[source]
Bases:
ModelTargetBase class for ADP restraint targets.
ADP targets access the model’s ADP values and restraints for similarity, rigid bond, and other ADP-related restraints.
- Parameters:
- class torchref.refinement.targets.adp.ADPSimilarityTarget(model=None, simu_sigma=2.0, verbose=0)[source]
Bases:
ADPTargetADP Similarity restraint (SIMU in Phenix/SHELX).
Restrains B-factors of bonded atoms to be similar. NLL = 0.5 * ((B_i - B_j) / σ)² + log(σ) + 0.5 * log(2π)
Tunable parameters (as buffers): - _simu_sigma: float, sigma for B-factor differences (default 2.0 Ų)
- class torchref.refinement.targets.adp.RigidBondTarget(model=None, sigma=0.004, use_aniso=True, verbose=0)[source]
Bases:
ADPTargetRigid Bond restraint (DELU in SHELX, Hirshfeld test).
Based on Hirshfeld’s rigid bond test (Acta Cryst. A32, 239, 1976).
For a truly rigid bond, the mean-square displacement amplitudes (MSDA) of the two bonded atoms along the bond direction should be equal. This is because in a rigid bond, the atoms move together.
For anisotropic ADPs (U tensors):
z_12 = l_12^T U_1 l_12 / |l_12|² (MSDA of atom 1 along bond) z_21 = l_21^T U_2 l_21 / |l_21|² (MSDA of atom 2 along bond) Δz = z_12 - z_21 should be ~0
For isotropic B-factors, the difference in B_iso is used as a proxy:
ΔB = B_1 - B_2
This differs from SIMU (ADPSimilarityTarget) which restrains the full ADP tensors to be similar. Rigid bond only restrains the component along the bond direction.
Energy: E = w * Δz² NLL: NLL = 0.5 * (Δz / σ)² + log(σ) + 0.5 * log(2π)
References
Hirshfeld, F.L. (1976). Acta Cryst. A32, 239.
cctbx/adp_restraints/rigid_bond.h
- Parameters:
model (Model) – Reference to Model object.
sigma (float, optional) – Target standard deviation for Δz. Default is 0.004 Ų. Hirshfeld found typical values of 0.001 Ų for good structures.
use_aniso (bool, optional) – If True and model has anisotropic ADPs, use proper tensor calculation. Default is True.
verbose (int, optional) – Verbosity level. Default is 0.
- forward()[source]
Compute rigid bond restraint.
For isotropic refinement, uses B-factor differences along bonds. For anisotropic refinement, computes proper MSDA differences.
- class torchref.refinement.targets.adp.ADPEntropyTarget(model=None, verbose=0)[source]
Bases:
ADPTargetADP Entropy regularization target.
Uses the model’s existing adp_kl_divergence_loss or similar.
- class torchref.refinement.targets.adp.ADPLocalityTarget(model=None, k_neighbors=50, correlation_length=5.0, scale=5.0, exclude_bonded=True, verbose=0)[source]
Bases:
ADPTargetProximity-based ADP restraint using K nearest neighbors.
Uses a spatial cell-list (O(N) memory, O(N·k) time) instead of a full N×N distance matrix, so it scales to arbitrarily large structures without memory issues.
- Parameters:
model (Model) – Reference to Model object.
k_neighbors (int, optional) – Number of nearest neighbors to consider. Default is 50.
correlation_length (float, optional) – Distance scale for weight decay in Angstrom. Default is 5.0.
scale (float, optional) – Scaling factor for loss magnitude. Default is 5.0.
exclude_bonded (bool, optional) – Exclude directly bonded atoms. Default is True.
verbose (int, optional) – Verbosity level. Default is 0.
- __init__(model=None, k_neighbors=50, correlation_length=5.0, scale=5.0, exclude_bonded=True, verbose=0)[source]
Initialize model target.
- class torchref.refinement.targets.adp.ScalerURegularizationTarget(scaler, n_reflections, verbose=0)[source]
Bases:
TargetPin the isotropic component of the scaler’s anisotropic U to zero.
F_scaled = scale · exp(-2π²·sᵀUs) · F_calccouplesUinto the same Debye-Waller slot as the atomic B-factors. The anisotropic deviatoric part of U encodes real directional attenuation in the data and should stay free. The isotropic part — the traceU11 + U22 + U33— is a straight trade with a uniform atomic B shift and must be anchored so the atoms absorb the B-factor roll-off, not the scaler.Penalty
(tr U)² · N_ref / 6— squared trace, scaled by the order of magnitude of the xray gradient on U. The/ 6matches the per-component gradient scaling the user originally requested.
- class torchref.refinement.targets.adp.ScalerLogScaleTrendTarget(scaler, n_reflections, verbose=0)[source]
Bases:
TargetPin out the Debye-Waller-like trend in the per-bin
log_scale.Per-bin scales exist to absorb localized data-quality issues — an outlier bin, a slightly mis-merged shell. They are not supposed to absorb the global resolution-dependent attenuation envelope; that is what atomic B-factors are for. A
log_scale[i] ≈ a + b·s²[i]structure with nonzerobis exactly a B-factor masquerading as a per-bin scale: it shiftsB_eff = B_atom − 4·b, letting atoms drift broader or sharper while the overallF_scaledamplitudes stay unchanged.The target fits the least-squares slope of
log_scaleagainst the bin-mean|s|²and penalizesslope². The intercepta(the overall scale) is free. Residuals off the fit line are also free — those encode the outlier absorption the scales are supposed to do.Penalty
slope² · N_ref / nbins— the/ nbinsmatches how xray gradient on a singlelog_scale[i]scales; theN_reffactor brings the total into xray’s order of magnitude.
Submodules
- torchref.refinement.targets.adp.base module
- torchref.refinement.targets.adp.entropy module
- torchref.refinement.targets.adp.locality module
- torchref.refinement.targets.adp.rigid_bond module
- torchref.refinement.targets.adp.scaler_log_scale module
- torchref.refinement.targets.adp.scaler_u module
- torchref.refinement.targets.adp.similarity module