ModMotl#

class cryocat.core.cryomotl.ModMotl(input_motl=None, mod_prefix='', mod_suffix='.mod')#

Bases: Motl

columns = ['object_id', 'contour_id', 'x', 'y', 'z', 'object_radius', 'mod_id']#
static convert_to_mod_motl(motl_df)#
convert_to_motl(mod_df)#

Converts a DataFrame containing model data into a format suitable for motl file generation.

Parameters:
mod_dfDataFrame

A DataFrame containing columns for ‘object_id’, ‘x’, ‘y’, ‘z’, ‘mod_id’, ‘contour_id’, and optionally ‘object_radius’. This DataFrame should represent objects and their contours with coordinates.

Raises:
ValueError

If any object does not have exactly correct number of points/contours.

Notes

The function processes the input DataFrame to calculate angles and coordinates for each object based on the provided contours and their points. It supports different scenarios based on the uniformity of contours per object and points per contour: 1. All objects have the same number of contours. 2. Each contour across objects has the same number of points.

Examples

>>> mod_df = pd.DataFrame({
...     'object_id': [1, 1, 2, 2],
...     'x': [1, 2, 1, 2],
...     'y': [1, 2, 1, 2],
...     'z': [1, 2, 1, 2],
...     'mod_id': [1, 1, 2, 2],
...     'contour_id': [1, 1, 2, 2],
...     'object_radius': [0.5, 0.5, 0.5, 0.5]
... })
>>> convert_instance = ConvertToMOTLClass()
>>> convert_instance.convert_to_motl(mod_df)
static read_in(input_path, mod_prefix='', mod_suffix='.mod')#

Reads in IMOD model file(s) from a file or specified directory. In case a path to the directory is specified, prefix and/or suffix can be passed as well to narrow down which files should be loaded. If none of them are passed all files with the extension .mod in that directory will be loaded.

Parameters:
input_pathstr

The path to a IMOD mod file or to the directory containing the model files.

mod_prefixstr, default=””

The prefix to add to each file name before reading. Defaults to an empty string.

mod_suffixstr, default=”.mod”

The suffix to add to each file name before reading. Defaults to ‘.mod’.

Returns:
DataFrame

A pandas DataFrame with read in coordinates, rotations (if possible), object idx and tomo idx.

Examples

>>> models = read_in('/path/to/models', mod_prefix='prefix_', mod_suffix='.txt')
write_out(output_path, motl_type='mod_motl')#

Write the mod_df (IMOD model format) to a .mod file using imod-compatible binary writer.

Parameters:
output_pathstr

The name of the output .mod file.

dfDataFrame

The pd DataFram