Utilities API
Checkpoint Management
CheckpointReader
Helper class to read from either a directory or a ZIP archive checkpoint. Provides unified interface for file access.
- class cryoPARES.utils.checkpointReader.CheckpointReader(checkpoint_path)[source]
Bases:
objectHelper class to read from either a directory or a ZIP archive checkpoint. Provides unified interface for file access.
- Parameters:
checkpoint_path (str)
- __init__(checkpoint_path)[source]
Initialize checkpoint reader.
- Parameters:
checkpoint_path (
str) – Path to checkpoint directory or ZIP file
- load_torch(relative_path, **kwargs)[source]
Load PyTorch model/tensor from checkpoint.
- Parameters:
relative_path (str)
- load_jit(relative_path)[source]
Load TorchScript model from checkpoint.
- Parameters:
relative_path (str)
Checkpoint Utils
- cryoPARES.utils.checkpointUtils.get_best_checkpoint(checkpoint_dir, best_is_less=True)[source]
Get the best checkpoint from a directory.
Parameters: checkpoint_dir (str): Path to the directory containing the checkp Returns: str: The path to the best checkpoint.
- cryoPARES.utils.checkpointUtils.increment_generic(generic_string, pattern, count_group_idx)[source]
- cryoPARES.utils.checkpointUtils.increment_version(fname_string, path_basename='(.*version_)(\\d+)$', extension=None)[source]
- cryoPARES.utils.checkpointUtils.find_last_version(rootdir, count_group_idx=1, path_pattern='(.*version_)(\\d+)$', dir_only=False)[source]
Path Utilities
- cryoPARES.utils.paths.find_configs_root()[source]
Find the project configs root by looking for constants.py
- Return type:
- cryoPARES.utils.paths.find_project_root()[source]
Find the project root by looking for pyproject.toml
- Return type:
- cryoPARES.utils.paths.get_most_recent_file(folder_path, template)[source]
Finds the most recent file in a directory that matches a given template.
- cryoPARES.utils.paths.convert_config_args_to_absolute_paths(config_args)[source]
Convert any relative YAML file paths in config_args to absolute paths.
This is important for subprocess propagation, where relative paths may be resolved relative to a different working directory.
- Parameters:
config_args – List of config strings (e.g., [‘config.yaml’, ‘train.n_epochs=100’])
- Returns:
List of config strings with YAML file paths converted to absolute paths, or None if config_args is None
PyTorch Utilities
Reconstruction Utilities
- cryoPARES.utils.reconstructionUtils.get_mrc_metadata(mrc_fname)[source]
Read MRC file metadata without loading the full volume data.
- Parameters:
mrc_fname (
str) – Path to the MRC file- Return type:
- Returns:
Tuple of (shape, sampling_rate) where shape is (nx, ny, nz) and sampling_rate is in Angstroms/pixel
- Raises:
FileNotFoundError – If the file does not exist
ValueError – If the file is not a valid MRC file
Geometry Utilities
Angle Conversions
- cryoPARES.geometry.convert_angles.euler_angles_to_matrix(euler_angles, convention)[source]
Convert rotations given as Euler angles in radians to rotation matrices.
Angle Metrics
- cryoPARES.geometry.metrics_angles.rotation_magnitude(rot)[source]
Compute rotation magnitude in radians.
- Parameters:
rot – tensor of shape (…,3,3)
- Returns:
The rotation magnitude in radians
- cryoPARES.geometry.metrics_angles.nearest_rotmat_idx(src, targets)[source]
Return index of target that is nearest to each element in src.
Uses negative trace of the dot product to avoid arccos operation.
- Parameters:
src – tensor of shape (B, 3, 3)
targets – tensor of shape (…, 3, 3)
- Returns:
dot_trace: The value of the trace of the selected nearest rotmat idxs
idxs: The idxs of the nearest rotation matrices
- cryoPARES.geometry.metrics_angles.rotation_error_rads(rotA, rotB)[source]
Compute rotation error in radians between two rotation matrices.
- Parameters:
rotA – tensor of shape (…,3,3). Rotation matrix
rotB – tensor of shape (…,3,3). Rotation matrix
- Returns:
rotation error in radians, tensor of shape (…)
- cryoPARES.geometry.metrics_angles.rotation_error_with_sym(rotA, rotB, symmetry=None)[source]
Compute rotation error in radians between two rotation matrices with symmetry.
- Parameters:
rotA – tensor of shape (…,3,3). Rotation matrix
rotB – tensor of shape (…,3,3). Rotation matrix
symmetry – string or None. Symmetry group (e.g., ‘I’, ‘O’, ‘T’, ‘D7’, etc.) If None, computes standard rotation error without symmetry
- Returns:
rotation error in radians, tensor of shape (…)