torchref.io.mtz module
MTZ file format reading and writing.
This module provides functions for reading and writing MTZ files containing crystallographic reflection data (structure factor amplitudes, intensities, R-free flags, etc.).
Space groups are returned as gemmi.SpaceGroup objects for consistency throughout torchref.
Functions
- read
Read an MTZ file and return a reader object.
- write
Write reflection data to an MTZ file.
Classes
- MTZReader
Reader class for MTZ files.
Examples
from torchref.io import mtz
# Reading
reader = mtz.read('data.mtz', verbose=1)
data_dict, cell, spacegroup = reader()
print(spacegroup.short_name()) # gemmi.SpaceGroup object
# Writing
mtz.write(df, cell, spacegroup, 'output.mtz')
- class torchref.io.mtz.MTZReader(verbose=0, column_names=None)[source]
Bases:
objectReader for MTZ files containing crystallographic structure factor data.
This class reads MTZ files using reciprocalspaceship and extracts: - Miller indices (h, k, l) - Structure factor amplitudes or intensities - Associated uncertainties (sigma values) - R-free test set flags
- cell
Unit cell parameters [a, b, c, alpha, beta, gamma].
- Type:
np.ndarray
- spacegroup
Space group object.
- Type:
gemmi.SpaceGroup
Examples
reader = mtz.read('data.mtz', verbose=1) data_dict, cell, spacegroup = reader() print(f"Found {len(data_dict['HKL'])} reflections in {spacegroup.short_name()}")
- AMPLITUDE_PRIORITY = ['F-obs', 'FOBS', 'FP', 'F', 'F-obs-filtered', 'FOBS-filtered', 'F(+)', 'FPLUS', 'FMEAN', 'F-pk', 'F_pk', 'FO', 'FODD', 'F-model', 'FC', 'FCALC']
- INTENSITY_PRIORITY = ['I-obs', 'IOBS', 'I', 'IMEAN', 'I-obs-filtered', 'IOBS-filtered', 'I(+)', 'IPLUS', 'IP', 'I-pk', 'I_pk', 'IHLI', 'I_full', 'IOBS_full', 'IO']
- RFREE_FLAG_NAMES = ['R-free-flags', 'RFREE', 'FreeR_flag', 'FREE', 'R-free', 'Rfree', 'FREER', 'FREE_FLAG', 'test', 'TEST', 'free', 'Free']
- torchref.io.mtz.write(df, cell, spacegroup, filepath)[source]
Write a DataFrame to an MTZ file.
- Parameters:
df (pandas.DataFrame) – DataFrame containing reflection data. Expected columns include H, K, L (Miller indices) and data columns like F_obs, I_obs, etc.
cell (list, numpy.ndarray, or torch.Tensor) – Unit cell parameters [a, b, c, alpha, beta, gamma] in A and degrees.
spacegroup (str or gemmi.SpaceGroup) – Space group symbol or gemmi SpaceGroup object.
filepath (str) – Output MTZ filename.
- Returns:
Returns 1 on success.
- Return type: