torchref.io.ihm_mapping module
Intermediate representation for IHM mmCIF ensemble data.
Provides dataclasses that map between IHM categories and torchref’s ModelCollection / DatasetCollection structures. This mapping can be:
Populated by IHMReader from an IHM mmCIF file
Constructed programmatically (e.g., from a kinetic model)
Passed to IHMWriter for round-trip output
Concept Mapping
IHM state -> base model (ModelFT) in ModelCollection IHM model group -> timepoint entry (_SharedMixedModel) in ModelCollection IHM population fraction -> fraction_params in _SharedMixedModel
- class torchref.io.ihm_mapping.IHMStateInfo(state_id, name, details='', model_num=1)[source]
Bases:
objectMetadata for a single structural state (e.g., ground state, intermediate).
- Parameters:
state_id (int) – Unique identifier matching
_ihm_multi_state_modeling.state_id.name (str) – Human-readable name (e.g.,
"ground_state","intermediate_1").details (str) – Free-text description of this state.
model_num (int) –
pdbx_PDB_model_numin the_atom_siteloop that corresponds to this state’s coordinates.
- __init__(state_id, name, details='', model_num=1)
- class torchref.io.ihm_mapping.IHMModelGroupInfo(group_id, name, state_fractions=<factory>, time_delay=None, time_delay_units='s')[source]
Bases:
objectMetadata for a model group (experimental condition / timepoint).
- Parameters:
group_id (int) – Unique identifier matching
_ihm_model_group.id.name (str) – Human-readable name (e.g.,
"dark","1ps","5ps").state_fractions (Dict[int, float]) – Mapping of
state_id-> population fraction for this group. Fractions should sum to 1.0.time_delay (float, optional) – Time delay in
time_delay_units(for time-resolved experiments).time_delay_units (str) – Units for
time_delay. Default"s"(seconds).
- __init__(group_id, name, state_fractions=<factory>, time_delay=None, time_delay_units='s')
- class torchref.io.ihm_mapping.IHMEnsembleMapping(states=<factory>, model_groups=<factory>, cell=None, spacegroup=None, atom_data_per_state=None)[source]
Bases:
objectComplete mapping between IHM mmCIF categories and torchref structures.
This is the central interchange object: both
IHMReaderandIHMWriteroperate through it. It can also be constructed manually for programmatic workflows (e.g., building an IHM file from aKineticRefinementresult without reading one first).- Parameters:
states (List[IHMStateInfo]) – Structural states (one per base model in ModelCollection).
model_groups (List[IHMModelGroupInfo]) – Model groups / timepoints (one per timepoint in ModelCollection).
cell (list of float, optional) – Unit cell parameters
[a, b, c, alpha, beta, gamma].spacegroup (str, optional) – Space group name (Hermann-Mauguin notation).
atom_data_per_state (dict, optional) – Mapping of
state_id-> pandas DataFrame with atom data. Populated byIHMReader.read_atom_data().
- states: List[IHMStateInfo]
- model_groups: List[IHMModelGroupInfo]
- get_fractions_for_group(group_name)[source]
Return population fractions for a model group, ordered by state_id.
- identify_dark_group()[source]
Heuristic: identify the reference / dark group.
Returns the name of the first model group where a single state has population fraction >= 0.95, or
Noneif no such group exists.
- get_state_by_id(state_id)[source]
Look up a state by its ID.
- Raises:
KeyError – If no state with the given ID exists.
- get_group_by_name(name)[source]
Look up a model group by name.
- Raises:
KeyError – If no group with the given name exists.
- validate()[source]
Check internal consistency.
- Raises:
ValueError – If states are empty, fractions don’t reference valid states, or fractions don’t sum to ~1.0 for any group.
- __init__(states=<factory>, model_groups=<factory>, cell=None, spacegroup=None, atom_data_per_state=None)