acryo package
Subpackages
- acryo.alignment package
- Module contents
AlignmentResult
BaseAlignmentModel
BaseAlignmentModel.align()
BaseAlignmentModel.fit()
BaseAlignmentModel.has_hetero_templates
BaseAlignmentModel.has_rotation
BaseAlignmentModel.input_shape
BaseAlignmentModel.is_multi_templates
BaseAlignmentModel.landscape()
BaseAlignmentModel.mask
BaseAlignmentModel.niter
BaseAlignmentModel.pre_transform()
BaseAlignmentModel.score()
BaseAlignmentModel.template
BaseAlignmentModel.with_params()
FSCAlignment
NCCAlignment
PCCAlignment
RotationImplemented
TomographyInput
ZNCCAlignment
- Module contents
- acryo.backend package
- Module contents
AnyArray
Backend
Backend.affine_transform()
Backend.arange()
Backend.argmax()
Backend.argmin()
Backend.array()
Backend.asarray()
Backend.asnumpy()
Backend.cumsum()
Backend.exp()
Backend.fftfreq()
Backend.fftn()
Backend.fftshift()
Backend.fix()
Backend.full()
Backend.ifftn()
Backend.ifftshift()
Backend.indices()
Backend.irfftn()
Backend.linspace()
Backend.lowpass_filter()
Backend.lowpass_filter_ft()
Backend.map_coordinates()
Backend.max()
Backend.maycopy()
Backend.mean()
Backend.meshgrid()
Backend.min()
Backend.missing_wedge_mask()
Backend.name
Backend.pad()
Backend.percentile()
Backend.rfftn()
Backend.rotated_crop()
Backend.spline_filter()
Backend.sqrt()
Backend.stack()
Backend.sum()
Backend.sum_labels()
Backend.tensordot()
Backend.unravel_index()
Backend.zeros()
build_mesh()
set_backend()
using_backend()
- Module contents
- acryo.classification package
- acryo.loader package
- acryo.molecules package
- Submodules
- acryo.molecules.core module
Molecules
Molecules.affine_matrix()
Molecules.append()
Molecules.concat()
Molecules.concat_with()
Molecules.copy()
Molecules.count()
Molecules.cutby()
Molecules.drop_features()
Molecules.empty()
Molecules.euler_angle()
Molecules.features
Molecules.filter()
Molecules.from_axes()
Molecules.from_csv()
Molecules.from_dataframe()
Molecules.from_euler()
Molecules.from_file()
Molecules.from_matrix()
Molecules.from_parquet()
Molecules.from_quat()
Molecules.from_random()
Molecules.from_rotvec()
Molecules.group_by()
Molecules.groupby()
Molecules.head()
Molecules.linear_transform()
Molecules.local_coordinates()
Molecules.matrix()
Molecules.pos
Molecules.quaternion()
Molecules.rotate_by()
Molecules.rotate_by_euler_angle()
Molecules.rotate_by_matrix()
Molecules.rotate_by_quaternion()
Molecules.rotate_by_rotvec()
Molecules.rotate_by_rotvec_internal()
Molecules.rotate_random()
Molecules.rotator
Molecules.rotvec()
Molecules.sample()
Molecules.sort()
Molecules.subset()
Molecules.tail()
Molecules.to_csv()
Molecules.to_dataframe()
Molecules.to_file()
Molecules.to_parquet()
Molecules.translate()
Molecules.translate_internal()
Molecules.translate_random()
Molecules.with_features()
Molecules.x
Molecules.y
Molecules.z
cross()
- Module contents
Molecules
Molecules.affine_matrix()
Molecules.append()
Molecules.concat()
Molecules.concat_with()
Molecules.copy()
Molecules.count()
Molecules.cutby()
Molecules.drop_features()
Molecules.empty()
Molecules.euler_angle()
Molecules.features
Molecules.filter()
Molecules.from_axes()
Molecules.from_csv()
Molecules.from_dataframe()
Molecules.from_euler()
Molecules.from_file()
Molecules.from_matrix()
Molecules.from_parquet()
Molecules.from_quat()
Molecules.from_random()
Molecules.from_rotvec()
Molecules.group_by()
Molecules.groupby()
Molecules.head()
Molecules.linear_transform()
Molecules.local_coordinates()
Molecules.matrix()
Molecules.pos
Molecules.quaternion()
Molecules.rotate_by()
Molecules.rotate_by_euler_angle()
Molecules.rotate_by_matrix()
Molecules.rotate_by_quaternion()
Molecules.rotate_by_rotvec()
Molecules.rotate_by_rotvec_internal()
Molecules.rotate_random()
Molecules.rotator
Molecules.rotvec()
Molecules.sample()
Molecules.sort()
Molecules.subset()
Molecules.tail()
Molecules.to_csv()
Molecules.to_dataframe()
Molecules.to_file()
Molecules.to_parquet()
Molecules.translate()
Molecules.translate_internal()
Molecules.translate_random()
Molecules.with_features()
Molecules.x
Molecules.y
Molecules.z
axes_to_rotator()
from_euler_xyz_coords()
- acryo.pick package
- acryo.pipe package
- Module contents
ImageConverter
ImageProvider
center_by_mass()
closing()
converter_function()
dilation()
from_array()
from_arrays()
from_atoms()
from_file()
from_files()
from_gaussian()
from_pdb()
gaussian_filter()
gaussian_smooth()
highpass_filter()
lowpass_filter()
provider_function()
shift()
soft_otsu()
threshold_otsu()
- Module contents
- acryo.testing package
- acryo.tilt package
Submodules
acryo.simulator module
- class acryo.simulator.Component(molecules: Molecules, image: NDArray[np.float32] | ImageProvider)[source]
Bases:
NamedTuple
A component of tomogram.
- image: ndarray[tuple[int, ...], dtype[float32]] | ImageProvider
Alias for field number 1
- class acryo.simulator.TomogramSimulator(order: Literal[0, 1, 3] = 3, scale: nm = 1.0, corner_safe: bool = False)[source]
Bases:
object
An object for tomogram simulation
A TomogramSimulator contains set(s) of molecules and their corresponding density and additional information for tomogram generation. For instance, to simulate a tomogram with two sets of molecules, you can do
>>> sim = TomogramSimulator() >>> sim.add_molecules(molecules_a, image_a, name="Molecule-A") >>> sim.add_molecules(molecules_b, image_b, name="Molecule-B") >>> img = sim.simulate(shape=(128, 128, 128))
- Parameters:
order (int, default is 3) – Interpolation order for density image. - 0 = Nearest neighbor - 1 = Linear interpolation - 3 = Cubic interpolation
scale (float, default is 1.0) – Scale of the pixel. This value is used to determine the position of the molecules.
corner_safe (bool, default is False) – Not implemented yet.
- add_molecules(molecules: Molecules, image: NDArray[np.float32] | ImageProvider, *, name: str | None = None, overwrite: bool = False) Self [source]
Add molecules to the tomogram.
- Parameters:
molecules (Molecules) – Molecules object that defines the coordinates and orientations of the input molecules.
image (np.ndarray or ImageProvider) – Density image of the input molecules, or an image provider.
name (str, optional) – Name of the molecules., by default None
overwrite (bool, default is False) – If true, allow overwriting existing component.
- Returns:
Same object.
- Return type:
- property corner_safe: bool
- property order: Literal[0, 1, 3]
Return the interpolation order.
- replace(order: Literal[0, 1, 3] | None = None, scale: float | None = None, corner_safe: bool | None = None) Self [source]
Return a new instance with different parameter(s).
- property scale: float
The physical scale of the tomogram.
- simulate(shape: tuple[pixel, pixel, pixel], colormap: Callable[[pl.DataFrame], ColorType] | NDArray[np.float32] | None = None) NDArray[np.float32] [source]
Simulate a tomogram.
- Parameters:
shape (tuple of int) – Shape of the tomogram.
colormap (callable, optional) – Colormap used to generate the colored tomogram. The input is a polars row vector of features of each molecule.
- Returns:
Simulated tomogram image.
- Return type:
np.ndarray
- simulate_2d(shape: tuple[int, int]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a grayscale tomogram.
- simulate_projection(shape: tuple[int, int], center: tuple[float, float, float], xaxis: tuple[float, float, float], yaxis: tuple[float, float, float]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a projection of the tomogram in any direction.
Projection plane and the projection range are defined by the given parameters.
shape
andcenter
define the range of the projection plane. Technically,center
will be the scale-considered center of the assumed 3D tomogram image.xaxis
andyaxis
define the coordinate system of the projection plane.- Parameters:
shape ((int, int)) – Output shape of the projection.
center ((float, float, float)) – Center of the projection plane in world coordinate system.
xaxis ((float, float, float)) – X-axis of the projection plane in world coordinate system.
yaxis ((float, float, float)) – Y-axis of the projection plane in world coordinate system.
- Returns:
Simulated projection image.
- Return type:
2D array
- simulate_tilt_series(degrees: Iterable[float], shape: tuple[int, int, int]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a tilt series of the tomogram.
This method is a simplified version of
simulate_projection()
. Projection angles are restricted to the rotation around the y-axis of the world coordinate and the tomogram will be projected parallel to the z-axis.- Parameters:
degrees (iterable of float) – Rotation angles.
shape ((int, int, int)) – Tomogram shape.
- Returns:
Tilting series image.
- Return type:
(N, Y, X) array
Module contents
- class acryo.BatchLoader(order: int = 3, scale: float = 1.0, output_shape: int | tuple[int, int, int] | Unset = Unset, corner_safe: bool = False)[source]
Bases:
LoaderBase
Collection of tomograms and their molecules.
A BatchLoader is similar to a list of SubtomogramLoader objects, but with better consistency in loader parameters and more convenient access to the molecules. This class is useful for processing many tomograms at once, especially when you want to get the average of all the molecules available.
- add_loader(loader: SubtomogramLoader | BatchLoader) Self [source]
Add a subtomogram loader or a batch loader to the collection.
- add_tomogram(image: np.ndarray | da.Array, molecules: Molecules, image_id: Hashable | None = None) Self [source]
Add a tomogram and its molecules to the collection.
- Parameters:
image (np.ndarray or da.Array) – Tomogram image. This argument is passed directly to the SubtomogramLoader constructor.
molecules (Molecules) – Molecules in the tomogram (corresponding to the
image
argument). This argument is passed directly to the SubtomogramLoader constructor.image_id (Hashable, optional) – Identifier for the tomogram. If not provided, a unique identifier will be generated. This identifier is used to tag molecules with the tomogram they reside in.
- binning(binsize: int, *, compute: bool = False) Self [source]
Return a new instance with binned images.
- construct_loading_tasks(output_shape: _ShapeType = None, backend: Backend | None = None) DaskArrayList [source]
Construct batch loading tasks.
- classmethod from_loaders(loaders: Iterable[SubtomogramLoader], order: int = 3, scale: nm = 1.0, output_shape: pixel | tuple[pixel, pixel, pixel] | Unset = Unset, corner_safe: bool = False) Self [source]
Construct a loader from a list of loaders.
- property images: MappingProxyType
All the images in the collection.
- property loaders: LoaderAccessor
Interface to access the subtomogram loaders.
- class acryo.MockLoader(template: ndarray[tuple[int, ...], dtype[float32]] | ImageProvider, molecules: Molecules, noise: float = 0.0, degrees: Sequence[float] | ndarray[tuple[int, ...], dtype[float32]] | None = None, central_axis: tuple[float, float, float] = (0.0, 1.0, 0.0), order: int = 3, scale: float = 1.0, corner_safe: bool = False)[source]
Bases:
LoaderBase
A subtomogram loader from a virtual tomogram.
This loader is for testing purpose only. The tomogram does not actually exist but subtomograms are generated on the fly based on the template image. The true center of the molecules is always at (0, 0, 0) and the true rotation is always the identity rotation. Thus, given molecule positions/rotations will directly be the values to be tested.
- Parameters:
template (3D array, ImageProvider) – The template image.
molecules (Molecules) – The molecules to be loaded. Note that the true center/rotation is always (0, 0, 0) and the identity rotation, respectively.
noise (float, optional) – Standard deviation of the Gaussian noise to be added to the subtomograms projection slices.
degrees (array-like, optional) – The rotation angles in degrees. If not provided, projection/back-projection will not be simulated.
central_axis (tuple, default is (0.0, 1.0, 0.0)) – The central axis of the rotation during tomogram acquisition.
- class acryo.Molecules(pos: _Array1D | _Array2D, rot: Rotation | None = None, features: FrameInitTypes | None = None)[source]
Bases:
object
Object that represents position- and orientation-defined molecules.
Positions are represented by a (N, 3)
np.ndarray
and orientations are represented by ascipy.spatial.transform.Rotation
object. Features of each molecule can also be recorded by thefeatures
property.- Parameters:
pos (ArrayLike) – Moleculs positions.
rot (scipy.spatial.transform.Rotation object) – Molecule orientations.
features (dataframe, optional) – Molecule features.
- affine_matrix(src: ndarray, dst: ndarray | None = None, inverse: bool = False) ndarray[tuple[int, ...], dtype[float32]] [source]
Construct affine matrices using positions and angles of molecules.
- Parameters:
src (np.ndarray) – Source coordinates.
dst (np.ndarray, optional) – Destination coordinates. By default the coordinates of molecules will be used.
inverse (bool, default is False) – Return inverse mapping if true.
- Returns:
Array of concatenated affine matrices.
- Return type:
(N, 4, 4) array
- classmethod concat(moles: Iterable[Molecules], concat_features: bool = True, nullable: bool = True) Self [source]
Concatenate Molecules objects.
- concat_with(other: Molecules, /, nullable: bool = True) Self [source]
Concatenate the molecules with the others.
- Parameters:
other (Molecules) – Molecules to be concatenated.
nullable (bool, default is True) – If true, missing features in either of the molecules will be filled with
null
. Raise error otherwise.
- cutby(by: str, bins: list[float]) MoleculeCutGroup [source]
Cut molecules into sub-groups by binning.
- drop_features(columns: str | Sequence[str], *more_columns: str) Self [source]
Return a new instance with updated features.
- euler_angle(seq: str = 'ZXZ', degrees: bool = False) ndarray[tuple[int, ...], dtype[float64]] [source]
Calculate Euler angles that transforms a source vector to vectors that belong to the object.
- Parameters:
seq (str, default is "ZXZ") – Copy of
scipy.spatial.transform.Rotation.as_euler
. 3 characters belonging to the set {“X”, “Y”, “Z”} for intrinsic rotations, or {“x”, “y”, “z”} for extrinsic rotations. Adjacent axes cannot be the same. Extrinsic and intrinsic rotations cannot be mixed in one function call.degrees (bool, default is False) – Copy of
scipy.spatial.transform.Rotation.as_euler
. Returned angles are in degrees if this flag is True, else they are in radians.
- Returns:
Euler angles.
- Return type:
(N, 3) ndarray
- property features: DataFrame
Molecules features.
- filter(predicate: pl.Expr | str | pl.Series | list[bool] | np.ndarray) Self [source]
Filter molecules by its features.
- classmethod from_axes(pos: _Array2D, z: _Array2D | None = None, y: _Array2D | None = None, x: _Array2D | None = None) Self [source]
Construct molecule cloud with orientation from two of their local axes.
- classmethod from_csv(path: PathLike, pos_cols: list[str] = ['z', 'y', 'x'], rot_cols: list[str] = ['zvec', 'yvec', 'xvec'], **pl_kwargs) Self [source]
Load csv as a Molecules object.
- classmethod from_dataframe(df: pl.DataFrame, pos_cols: list[str] = ['z', 'y', 'x'], rot_cols: list[str] = ['zvec', 'yvec', 'xvec']) Self [source]
Construct Molecules object from a DataFrame.
- classmethod from_euler(pos: _Array2D, angles: _Array2D, seq: str = 'ZXZ', degrees: bool = False, order: Literal['xyz', 'zyx'] = 'xyz', features: pl.DataFrame | None = None) Self [source]
Create molecules from Euler angles.
- classmethod from_file(path: PathLike, pos_cols: list[str] = ['z', 'y', 'x'], rot_cols: list[str] = ['zvec', 'yvec', 'xvec']) Self [source]
Load a file as a Molecules object using proper reader.
- classmethod from_matrix(pos: _Array2D, matrix: np.ndarray, features: pl.DataFrame | None = None) Self [source]
Create molecules from rotation matrices.
- classmethod from_parquet(path: PathLike, pos_cols: list[str] = ['z', 'y', 'x'], rot_cols: list[str] = ['zvec', 'yvec', 'xvec']) Self [source]
Load parquet as a Molecules object.
- classmethod from_quat(pos: _Array2D, quat: _Array2D, features: pl.DataFrame | None = None) Self [source]
Create molecules from quaternions.
- classmethod from_random(pos: _Array2D, seed: int | None = None, features: pl.DataFrame | None = None) Self [source]
Create randomly oriented molecules from given positions.
- classmethod from_rotvec(pos: _Array2D, vec: _Array2D, features: pl.DataFrame | None = None) Self [source]
Create molecules from rotation vectors.
- group_by(by: str | Expr) MoleculeGroup[str] [source]
- group_by(by: Sequence[str | Expr] | tuple[str | Expr, ...]) MoleculeGroup[tuple[str, ...]]
- group_by(by: str | Expr, *more_by: str | Expr) MoleculeGroup[tuple[str, ...]]
Group molecules into sub-groups.
- groupby(by, *more_by)
Group molecules into sub-groups.
- linear_transform(shift: _Array2D, rotator: Rotation, inv: bool = False) Self [source]
Shift and rotate molecules around their own coordinate.
- local_coordinates(shape: tuple[int, int, int], scale: float = 1.0, *, squeeze: bool = True) ndarray[tuple[int, ...], dtype[float32]] [source]
Generate local coordinates at the neighborhood of each molecule.
- Parameters:
shape ((int, int, int)) – Shape of the local coordinates.
scale (float, default is 1.0) – Scale of the local coordinates.
squeeze (bool, default is True) – If ture and the number of molecules is 1, the first axis will be removed.
- Returns:
World coordinates.
array[i]
can be directly used as the coordinates forndi.map_coordinates
.- Return type:
(N, D, Z, Y, X) array
- matrix() ndarray[tuple[int, ...], dtype[float64]] [source]
Calculate rotation matrices that align molecules in such orientations that
vec
belong to the object.- Returns:
Rotation matrices. Rotations represented by these matrices transform molecules to the same orientations, i.e., align all the molecules.
- Return type:
(N, 3, 3) ndarray
- property pos: ndarray[tuple[int, ...], dtype[float32]]
Positions of molecules.
- quaternion(canonical: bool = False) ndarray[tuple[int, ...], dtype[float64]] [source]
Calculate quaternions that transforms a source vector to vectors that belong to the object.
- Returns:
Quaternions.
- Return type:
(N, 4) ndarray
- rotate_by(rotator: Rotation, *, copy: bool = True) Self [source]
Rotate molecule with a
Rotation
object.Note that
Rotation
object satisfies following equation.>>> rot1.apply(rot2.apply(v)) == (rot1*rot2).apply(v)
- Parameters:
rotator (Rotation) – Molecules will be rotated by this object.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated orientation.
- Return type:
- rotate_by_euler_angle(angles: _Array2D, seq: str = 'ZXZ', degrees: bool = False, order: Literal['xyz', 'zyx'] = 'xyz', copy: bool = True) Self [source]
Rotate molecules using Euler angles, with their position unchanged.
- Parameters:
angles (array-like) – Euler angles of rotation.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated orientation.
- Return type:
- rotate_by_matrix(matrix: ArrayLike, *, copy: bool = True) Self [source]
Rotate molecules using rotation matrices, with their position unchanged.
- Parameters:
matrix (ArrayLike) – Rotation matrices, whose length must be same as the number of molecules.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated orientation.
- Return type:
- rotate_by_quaternion(quat: _Array1D | _Array2D, *, copy: bool = True) Self [source]
Rotate molecules using quaternions, with their position unchanged.
- Parameters:
quat (ArrayLike) – Rotation quaternion.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated orientation.
- Return type:
- rotate_by_rotvec(vector: _Array2D, *, copy: bool = True) Self [source]
Rotate molecules using rotation vectors, with their position unchanged.
- Parameters:
vector (array-like) – Rotation vectors.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated orientation.
- Return type:
- rotate_by_rotvec_internal(vector: _Array1D | _Array2D, *, copy: bool = True) Self [source]
Rotate molecules using internal rotation vector.
Vector components are calculated in the molecule-coordinate.
- Parameters:
vector (ArrayLike) – Rotation vector(s).
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated angles.
- Return type:
- rotate_random(copy: bool = True, seed: int | None = None) Self [source]
Rotate molecules randomly.
- Parameters:
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
seed (int, default is None) – Random seed to generate randomized rotators.
- Returns:
Instance with updated orientation.
- Return type:
- property rotator: Rotation
Return
scipy.spatial.transform.Rotation
object
- rotvec() ndarray[tuple[int, ...], dtype[float64]] [source]
Calculate rotation vectors that transforms a source vector to vectors that belong to the object.
- Returns:
Rotation vectors.
- Return type:
(N, 3) ndarray
- sort(by: IntoExpr | Iterable[IntoExpr], *more_by: IntoExpr, descending: bool = False) Self [source]
Return a new instance with sorted molecules and features.
- Parameters:
by (str or Expr or sequence of them) – Column name or expression to sort by.
descending (bool, default is False) – If true, sort in descending order.
- subset(spec: int | slice | list[int] | NDArray[np.bool_] | NDArray[np.integer]) Self [source]
Create a subset of molecules by slicing.
Any slicing supported in
numpy.ndarray
, except for integer, can be used here. Molecule positions and angles are sliced at the same time.- Parameters:
spec (int, slice, list of int, or ndarray) – Specifier that defines which molecule will be used. Any objects that numpy slicing are defined are supported. For instance,
[2, 3, 5]
means the 2nd, 3rd and 5th molecules will be used (zero-indexed), andslice(10, 20)
means the 10th to 19th molecules will be used.- Returns:
Molecule subset.
- Return type:
- to_csv(save_path: str | Path, float_precision: int | None = 4) None [source]
Save molecules as a csv file.
- Parameters:
save_path (PathLike) – Save path.
float_precision (int, default is 4) – Float precision.
- to_dataframe() DataFrame [source]
Convert coordinates, rotation and features into a single data frame.
- to_parquet(save_path: PathLike, *, compression: ParquetCompression = 'zstd', compression_level: int | None = 10) None [source]
Save molecules as a parquet file.
- Parameters:
save_path (PathLike) – Save path.
compression (str, default is "zstd") – Compression method, by default “zstd”.
- translate(shifts: _Array1D | _Array2D, copy: bool = True) Self [source]
Translate molecule positions by
shifts
.Shifts are applied in world coordinates, not internal coordinates of every molecules. If molecules should be translated in their own coordinates, such as translating toward y-direction of each molecules by 1.0 nm, use
translate_internal
instead. Translation operation does not convert molecule orientations.- Parameters:
shifts ((3,) or (N, 3) array) – Spatial shift of molecules.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated positional coordinates.
- Return type:
- translate_internal(shifts: _Array1D | _Array2D, *, copy: bool = True) Self [source]
Translate molecule positions internally by
shifts
.Shifts are applied in the coordinates of each molecule. If molecules should be translated in world coordinates use
translate
instead.- Parameters:
shifts ((3,) or (N, 3) array) – Spatial shift of molecules.
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Instance with updated positional coordinates.
- Return type:
- translate_random(max_distance: nm, *, seed: int | None = None, copy: bool = True) Self [source]
Apply random translation to each molecule.
Translation range is restricted by a maximum distance and translation values are uniformly distributed in this region. Different translations will be applied to different molecules.
- Parameters:
max_distance (nm) – Maximum distance of translation.
seed (int, optional) – Random seed, by default None
copy (bool, default is True) – If true, create a new instance, otherwise overwrite the existing instance.
- Returns:
Translated molecules.
- Return type:
- with_features(exprs: IntoExpr | Iterable[IntoExpr], *more_exprs: IntoExpr, **named_exprs: IntoExpr) Self [source]
Return a new instance with updated features.
- property x: ndarray[tuple[int, ...], dtype[float64]]
Vectors of x-axis.
- property y: ndarray[tuple[int, ...], dtype[float64]]
Vectors of y-axis.
- property z: ndarray[tuple[int, ...], dtype[float64]]
Vectors of z-axis.
- class acryo.SubtomogramLoader(image: ndarray | Array, molecules: Molecules, order: int = 3, scale: float = 1.0, output_shape: int | tuple[int, int, int] | Unset = Unset, corner_safe: bool = False)[source]
Bases:
LoaderBase
A class for efficient loading of subtomograms.
A
SubtomogramLoader
instance is basically composed of two elements, an image and a Molecules object. A subtomogram is loaded by creating a local rotated Cartesian coordinate at a molecule and calculating mapping from the image to the subtomogram.- Parameters:
image (np.ndarray or da.Array) – Tomogram image. Must be 3-D.
molecules (Molecules) – Molecules object that represents positions and orientations of subtomograms.
order (int, default is 3) – Interpolation order of subtomogram sampling. - 0 = Nearest neighbor - 1 = Linear interpolation - 3 = Cubic interpolation
scale (float, default is 1.0) – Physical scale of pixel, such as nm. This value does not affect averaging/alignment results but molecule coordinates are multiplied by this value. This parameter is useful when another loader with binned image is created.
output_shape (int or tuple of int, optional) – Shape of output subtomogram in pixel. This parameter is not required if template (or mask) image is available immediately.
corner_safe (bool, default is False) – If true, regions around molecules will be cropped at a volume larger than
output_shape
so that densities at the corners will not be lost due to rotation. If target density is globular, this parameter should be set false to save computation time.
- binning(binsize: pixel = 2, *, compute: bool = True) Self [source]
Return a new instance with binned image.
This method also properly translates the molecule coordinates.
- Parameters:
binsize (int, default is 2) – Bin size.
compute (bool, default is True) – If true, the image is computed immediately to a numpy array.
- Returns:
A new instance with binned image.
- Return type:
- construct_loading_tasks(output_shape: int | tuple[int, ...] | None = None, backend: Backend | None = None) DaskArrayList [source]
Construct a list of subtomogram lazy loader.
- Returns:
Each object returns a subtomogram on execution by
da.compute
.- Return type:
list of Delayed object
- property image: NDArray[np.float32] | da.Array
Return tomogram image.
- class acryo.TomogramSimulator(order: Literal[0, 1, 3] = 3, scale: nm = 1.0, corner_safe: bool = False)[source]
Bases:
object
An object for tomogram simulation
A TomogramSimulator contains set(s) of molecules and their corresponding density and additional information for tomogram generation. For instance, to simulate a tomogram with two sets of molecules, you can do
>>> sim = TomogramSimulator() >>> sim.add_molecules(molecules_a, image_a, name="Molecule-A") >>> sim.add_molecules(molecules_b, image_b, name="Molecule-B") >>> img = sim.simulate(shape=(128, 128, 128))
- Parameters:
order (int, default is 3) – Interpolation order for density image. - 0 = Nearest neighbor - 1 = Linear interpolation - 3 = Cubic interpolation
scale (float, default is 1.0) – Scale of the pixel. This value is used to determine the position of the molecules.
corner_safe (bool, default is False) – Not implemented yet.
- add_molecules(molecules: Molecules, image: NDArray[np.float32] | ImageProvider, *, name: str | None = None, overwrite: bool = False) Self [source]
Add molecules to the tomogram.
- Parameters:
molecules (Molecules) – Molecules object that defines the coordinates and orientations of the input molecules.
image (np.ndarray or ImageProvider) – Density image of the input molecules, or an image provider.
name (str, optional) – Name of the molecules., by default None
overwrite (bool, default is False) – If true, allow overwriting existing component.
- Returns:
Same object.
- Return type:
- property corner_safe: bool
- property order: Literal[0, 1, 3]
Return the interpolation order.
- replace(order: Literal[0, 1, 3] | None = None, scale: float | None = None, corner_safe: bool | None = None) Self [source]
Return a new instance with different parameter(s).
- property scale: float
The physical scale of the tomogram.
- simulate(shape: tuple[pixel, pixel, pixel], colormap: Callable[[pl.DataFrame], ColorType] | NDArray[np.float32] | None = None) NDArray[np.float32] [source]
Simulate a tomogram.
- Parameters:
shape (tuple of int) – Shape of the tomogram.
colormap (callable, optional) – Colormap used to generate the colored tomogram. The input is a polars row vector of features of each molecule.
- Returns:
Simulated tomogram image.
- Return type:
np.ndarray
- simulate_2d(shape: tuple[int, int]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a grayscale tomogram.
- simulate_projection(shape: tuple[int, int], center: tuple[float, float, float], xaxis: tuple[float, float, float], yaxis: tuple[float, float, float]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a projection of the tomogram in any direction.
Projection plane and the projection range are defined by the given parameters.
shape
andcenter
define the range of the projection plane. Technically,center
will be the scale-considered center of the assumed 3D tomogram image.xaxis
andyaxis
define the coordinate system of the projection plane.- Parameters:
shape ((int, int)) – Output shape of the projection.
center ((float, float, float)) – Center of the projection plane in world coordinate system.
xaxis ((float, float, float)) – X-axis of the projection plane in world coordinate system.
yaxis ((float, float, float)) – Y-axis of the projection plane in world coordinate system.
- Returns:
Simulated projection image.
- Return type:
2D array
- simulate_tilt_series(degrees: Iterable[float], shape: tuple[int, int, int]) ndarray[tuple[int, ...], dtype[float32]] [source]
Simulate a tilt series of the tomogram.
This method is a simplified version of
simulate_projection()
. Projection angles are restricted to the rotation around the y-axis of the world coordinate and the tomogram will be projected parallel to the z-axis.- Parameters:
degrees (iterable of float) – Rotation angles.
shape ((int, int, int)) – Tomogram shape.
- Returns:
Tilting series image.
- Return type:
(N, Y, X) array