torchref.kinetic.targets module
Collection-aware targets for kinetic refinement.
All targets extend torchref.refinement.targets.base.Target and operate
on paired DatasetCollection + ModelCollection instances. Keys are matched
automatically so that each timepoint dataset is paired with its
corresponding mixed model.
Targets
- CollectionDifferenceTarget
Multi-timepoint difference target (primary optimization driver).
- CollectionMLTarget
Multi-timepoint maximum-likelihood amplitude target.
- MultiModelGeometryTarget
Geometry restraints applied to the shared base models.
- MultiModelADPTarget
ADP restraints applied to the shared base models.
- KineticPriorTarget
Regularizes per-timepoint fractions towards a kinetic model.
- class torchref.kinetic.targets.CollectionDifferenceTarget(dataset_collection, model_collection, scaler=None, normalize=True, use_work_set=True, verbose=0)[source]
Bases:
TargetMean-based difference target using DatasetCollection + ModelCollection.
Computes differences relative to the mean across all N datasets (dark + timepoints), with proper error propagation accounting for the covariance between each dataset and the mean:
F_mean(h) = (1/N) Σ_i F_obs_i(h) ΔF_obs_i = F_obs_i - F_mean ΔF_calc_i = |F_calc_i| - F_calc_mean Var(F_i - F_mean) = σ_i²·(1 - 2/N) + (Σ_j σ_j²)/N²
For N=2 (dark + one timepoint) this gives identical gradients to the direct dark-reference subtraction. For N>2 the mean reference has lower noise.
All computation is vectorized on stacked (N, n_hkl) tensors — no Python loops over datasets.
- Parameters:
dataset_collection (DatasetCollection)
model_collection (ModelCollection)
scaler (ScalerBase) – Single scaler applied to all F_calc (uses
forward_mixedwith per-model fractions when available).normalize (bool) – If True, divide total NLL by number of datasets.
use_work_set (bool) – If True, compute loss only on the work set (rfree_flags=True).
verbose (int) – Verbosity level.
- class torchref.kinetic.targets.CollectionMLTarget(dataset_collection, model_collection, scaler=None, normalize=True, use_work_set=True, verbose=0)[source]
Bases:
TargetMulti-timepoint maximum-likelihood amplitude target.
Computes Rice-distribution NLL (acentric) and the corresponding centric NLL for each timepoint, with proper validity masking and NaN/Inf protection. Vectorized on stacked (N_tp, n_hkl) tensors.
- Parameters:
dataset_collection (DatasetCollection)
model_collection (ModelCollection)
scaler (ScalerBase, optional) – Single scaler applied to each timepoint’s F_calc.
normalize (bool) – Divide total NLL by number of matched timepoints.
use_work_set (bool) – Compute loss only on work set.
verbose (int) – Verbosity level.
- class torchref.kinetic.targets.MultiModelGeometryTarget(model_collection, verbose=0)[source]
Bases:
TargetGeometry restraints for the shared base models in a ModelCollection.
Creates a
TotalGeometryTargetfor each base model and sums them. Since models are shared across timepoints, restraints only need to be computed once per base model (not per timepoint).- Parameters:
model_collection (ModelCollection)
verbose (int) – Verbosity level.
- __init__(model_collection, verbose=0)[source]
Initialize target.
- Parameters:
verbose (int, optional) – Verbosity level. Default is 0.
- class torchref.kinetic.targets.MultiModelADPTarget(model_collection, verbose=0)[source]
Bases:
TargetADP restraints for the shared base models in a ModelCollection.
Same pattern as MultiModelGeometryTarget but using TotalADPTarget.
- Parameters:
model_collection (ModelCollection)
verbose (int) – Verbosity level.
- class torchref.kinetic.targets.KineticPriorTarget(model_collection, kinetic_model, timepoints_map, verbose=0)[source]
Bases:
TargetRegularize per-timepoint fractions towards a kinetic model.
The kinetic model provides a smooth prior over how population fractions should evolve over time. The fractions in ModelCollection are free parameters; this target penalizes deviation from the kinetic prediction.
Periodically call
refit_prior()to update the kinetic model to match the current free fractions (EM-style alternation).- Parameters:
model_collection (ModelCollection)
kinetic_model (occupancies_kinetics) – The kinetic occupancy model whose
forward()returns shape[n_states, n_timepoints].timepoints_map (Dict[str, int]) – Maps timepoint names to indices into the kinetic model’s time axis. E.g.
{"1ps": 0, "5ps": 1, "10ps": 2}.verbose (int) – Verbosity level.
- __init__(model_collection, kinetic_model, timepoints_map, verbose=0)[source]
Initialize target.
- Parameters:
verbose (int, optional) – Verbosity level. Default is 0.