torchref.model.model_collection module
Model collection for time-resolved kinetic refinement.
Provides ModelCollection — a named dictionary of MixedModel instances at different timepoints that share the same base structural models (ModelFT). Keys match DatasetCollection keys so targets can automatically pair them.
- class torchref.model.model_collection.ModelCollection(base_models, dark_key='dark', verbose=0)[source]
Bases:
DeviceMixin,ModuleNamed dictionary of MixedModel instances at different timepoints.
All timepoint models share the same base structural models (ModelFT objects stored once in an nn.ModuleList). Each timepoint gets its own independent fraction parameters via _SharedMixedModel.
Keys should match DatasetCollection keys so that collection-aware targets can automatically pair datasets with models.
- Parameters:
Examples
models = ModelCollection([model_dark, model_light]) models.add_dark() # fractions=[1, 0] models.add_timepoint("1ps", [0.9, 0.1]) models.add_timepoint("5ps", [0.7, 0.3]) # Access mixed = models["1ps"] fcalc = mixed(hkl) print(mixed.fractions)
- add_timepoint(name, fractions=None, frozen_fractions=False)[source]
Add a timepoint with given initial fractions.
- Parameters:
- Returns:
Self, for method chaining.
- Return type:
- add_dark(fractions=None)[source]
Add the dark / reference entry.
Default fractions: [1, 0, 0, …] (100 % ground state).
- Parameters:
fractions (List[float], optional) – Override dark fractions. Default is pure ground state.
- Returns:
Self, for method chaining.
- Return type:
- classmethod from_kinetics(base_models, occ_model, timepoint_names, dark_key='dark', verbose=0)[source]
Create a ModelCollection from a kinetics occupancy model.
- Parameters:
base_models (List[ModelFT]) – Shared structural models.
occ_model (occupancies_kinetics) – Kinetic occupancy model whose forward() returns shape [n_states, n_timepoints].
timepoint_names (List[str]) – Names for each timepoint column (excluding dark).
dark_key (str) – Key for the dark entry.
verbose (int) – Verbosity level.
- Return type:
- classmethod from_ihm(filepath, max_res=1.5, radius_angstrom=4.0, device=None, verbose=0)[source]
Load a ModelCollection from an IHM mmCIF file.
Requires the optional
python-ihmdependency.- Parameters:
filepath (str) – Path to IHM mmCIF file.
max_res (float) – Maximum resolution for FFT grid setup.
radius_angstrom (float) – Radius for electron density calculation.
device (torch.device, optional) – Device for model tensors.
verbose (int) – Verbosity level.
- Return type:
- write_ihm(filepath, mapping=None, datasets=None)[source]
Write this ModelCollection to IHM mmCIF format.
Requires the optional
python-ihmdependency.- Parameters:
filepath (str) – Output file path.
mapping (IHMEnsembleMapping, optional) – Mapping with metadata for round-tripping. If
None, a minimal mapping is created from the collection structure.datasets (dict of str -> ReflectionData, optional) – Per-timepoint reflection data to embed in the CIF. Each key should match a timepoint name.
- property dark_model: _SharedMixedModel
Shortcut for
self[dark_key].
- property base_models: ModuleList
The shared structural models (owned by this collection).
- property cell
- property spacegroup
- property device