cryolike.metadata

cryolike.metadata.lens_descriptor

class cryolike.metadata.lens_descriptor.LensDescriptor(*, defocusU: float | ndarray = array([10200.]), defocusV: float | ndarray = array([9800.]), defocusAngle: float | ndarray = array([90.]), phaseShift: float | ndarray = array([0.]), sphericalAberration: float | ndarray[tuple[int, ...], dtype[floating]] = 2.7, voltage: float | ndarray[tuple[int, ...], dtype[floating]] = 300.0, amplitudeContrast: float | ndarray[tuple[int, ...], dtype[floating]] = 0.1, angleRotation: ndarray[tuple[int, ...], dtype[floating]] | None = None, angleTilt: ndarray[tuple[int, ...], dtype[floating]] | None = None, anglePsi: ndarray[tuple[int, ...], dtype[floating]] | None = None, ref_pixel_size: float | ndarray[tuple[int, ...], dtype[floating]] | None = None, defocusAngle_degree: bool = True, phaseShift_degree: bool = True, files: ndarray | None = None, idxs: ndarray[tuple[int, ...], dtype[integer]] | None = None, ctfBfactor: float | ndarray[tuple[int, ...], dtype[floating]] | None = None, ctfScalefactor: float | ndarray[tuple[int, ...], dtype[floating]] | None = None)

Bases: object

Class describing the properties of a device, to be used to compute the relevant contrast transfer function (CTF).

defocusU

Defocus in U-dimension, in Angstrom

Type:

FloatArrayType

defocusV

Defocus in V-dimension, in Angstrom

Type:

FloatArrayType

defocusAngle

Defocus angle, in radians

Type:

FloatArrayType

phaseShift

phase shift, in radians

Type:

FloatArrayType

sphericalAberration

Spherical aberration, in mm

Type:

float

voltage

Voltage, in kV

Type:

float

amplitudeContrast

Amplitude contrast

Type:

float

angleRotation

Optional rotational angle

Type:

FloatArrayType | None

angleTilt

Optional rotational angle

Type:

FloatArrayType | None

anglePsi

Optional rotational angle

Type:

FloatArrayType | None

ref_pixel_size

Recorded pixel size from a descriptor file

Type:

FloatArrayType | None

files

List of image files referenced in a combined Cryosparc descriptor file

Type:

np.ndarray | None

idxs

Lookup table for interpreting the images described by a combined Cryosparc descriptor file

Type:

IntArrayType | None

ctfBfactor

B-factor of CTF, typically from a Starfile. For accounting/reference only.

Type:

float | FloatArrayType | None

ctfScalefactor

Scale factor of CTF, typically from a Starfile. For accounting/reference only.

Type:

float | FloatArrayType | None

batch_whole() BatchableLensFields

Returns a tuple of all the per-image descriptors available.

Returns:

This LensDescriptor’s defocusU, defocusV,

defocus angle, and phase shift parameters.

Return type:

BatchableLensFields

classmethod from_cryosparc_file(file: str, get_fs_data: bool = False)

Create a LensDescriptor from a Cryosparc file, which may optionally have internal filesystem data indexing images in MRC files.

Parameters:
  • file (str) – The path to the Cryosparc file

  • get_fs_data (bool, optional) – If set, assume we are operating on a Cryosparc file with MRC indexing. In this case, we will look for a “blob/path” member identifying the MRC file paths and a “blob/idx” member mapping the records in the Cryosparc file to the image records. We will only attempt to read pixel size data from the Cryosparc file when get_fs_data is True. Defaults to False.

Returns:

A LensDescriptor read from the specified Cryosparc file.

Return type:

LensDescriptor

classmethod from_starfile(star_file: str, defocus_is_degree: bool = True, phase_shift_is_degree: bool = True)

Read a Starfile and generate a LensDescriptor object

Parameters:
  • star_file (str) – Path to the Starfile

  • defocus_is_degree (bool, optional) – Whether the Starfile stores the DefocusAngle property in degrees. Defaults to True.

  • phase_shift_is_degree (bool, optional) – Whether the Starfile stores the PhaseShift property in degrees. Defaults to True.

Returns:

A LensDescriptor representation of the apparatus data

from the given Starfile.

Return type:

LensDescriptor

get_selections(selections) BatchableLensFields

Returns a tuple of per-image descriptors for selected records, identified by index.

Parameters:

selections (IntArrayType) – Indices to return

Returns:

Defocus and phase shift data for

the specifically requested indices.

Return type:

BatchableLensFields

get_slice(start: int, end: int) BatchableLensFields

Returns a tuple of per-image descriptors for a particular range, without removing it from the descriptor.

Parameters:
  • start (int) – Beginning index (inclusive)

  • end (int) – Ending index (exclusive)

Returns:

Defocus and phase shfit data for the

indicated range of images.

Return type:

BatchableLensFields

cryolike.metadata.image_descriptor

class cryolike.metadata.image_descriptor.ImageDescriptor(precision: Precision, cartesian_grid: CartesianGrid2D, polar_grid: PolarGrid, viewing_angles: ViewingAngles | None, viewing_distance: float | None, atom_radii: float | ndarray[tuple[int, ...], dtype[floating]] | None = None, atom_selection: str | ndarray | None = 'name CA', use_protein_residue_model: bool = True, atom_shape: AtomShape = AtomShape.GAUSSIAN)

Bases: object

Class recording the information necessary to interpret an image, whether experimentally captured (Images) or constructed from a model (Templates).

precision

The precision (single or double) of the image representation

Type:

cryolike.util.enums.Precision

cartesian_grid

The two-dimensional Cartesian grid that describes the images

Type:

cryolike.grids.cartesian_grid.CartesianGrid2D

polar_grid

The PolarGrid object that can be used to interpret the Fourier representation of the image

Type:

cryolike.grids.polar_grid.PolarGrid

viewing_angles

A ViewingAngles object describing the different orientations that make up the generated template stack

Type:

cryolike.metadata.viewing_angles.ViewingAngles

viewing_distance

A viewing distance (separation on the surface of a sphere) that allows regenerating the viewing angles. Only relevant for templates with regularly spaced viewing angles.

Type:

float | None

atom_radii

Only relevant for template creation from PDB files. If set, describes the radius of the atoms (as a single value for all atoms) in the model.

Type:

float | None

atom_selection

Only relevant for template creation from PDB files. If set, describes which atoms should be taken from the model.

Type:

str | None

use_protein_residue_model

Only relevant for template creation from PDB files. Indicates whether to use standard sizes for molecules mentioned in the PDB file.

Type:

bool

atom_shape

An enumeration value describing how to interpret atoms in a model. Typical values are AtomShape.HARD_SPHERE and AtomShape.GAUSSIAN. Only relevant for templates constructed from atomic models.

Type:

cryolike.util.enums.AtomShape

classmethod from_individual_values(n_pixels: int, pixel_size: float, precision: Literal['single'] | Literal['double'] | Precision = Precision.SINGLE, resolution_factor: float = 1.0, viewing_distance: float | None = None, n_inplanes: int | None = None, atom_radii: float | None = None, atom_selection: str | None = 'name CA', use_protein_residue_model: bool = True, atom_shape: AtomShape | str = AtomShape.GAUSSIAN)

Create an ImageDescriptor from a small set of values. This will produce a square Cartesian grid and uniform polar grid. Only the Cartesian-grid dimensions are required: other values will be set to defaults if not provided. As a reminder, values other than the grids have no effect on Images, and only impact Templates during the template-creation process.

Parameters:
  • n_pixels (int) – Number of pixels per side of the grid

  • pixel_size (float) – Size of each pixel in Angstrom

  • precision ('single' | 'double' | Precision, optional) – Precision at which to carry out computations. Defaults to Precision.SINGLE.

  • resolution_factor (float, optional) – The resolution factor for template generation. Defaults to 1.0.

  • viewing_distance (float | None, optional) – Viewing distance of the image capture device. Used to compute viewing angles. Defaults to None.

  • n_inplanes (int | None, optional) – Number of points per ring of the polar quadrature grid. Defaults to None.

  • atom_radii (float | None, optional) – Radius of atoms in the model being interpreted. Defaults to None.

  • atom_selection (str | None, optional) – Which atoms from the PDB file to read. Ignored for non-PDB files. Defaults to “name CA”.

  • use_protein_residue_model (bool, optional) – Whether to use the default sizes for proteins in PDB. Defaults to True.

  • atom_shape (AtomShape | str, optional) – Whether to treat atoms as hard spheres or Gaussian clouds. Defaults to AtomShape.GAUSSIAN.

Returns:

A fully-populated ImageDescriptor object.

Return type:

ImageDescriptor

print()

Prints a set of parameters to the command line.

save(filename: str, overwrite: bool = False)

Create NPZ file named filename from the to_dict() representations of the data in self.

Parameters:

filename (str) – NPZ file to use as output. Operation will be canceled if this named file already exists unless overwrite is True

Kwargs:

overwrite (bool): whether to allow overwriting existing files. Default False

Raises:

ValueError – If the requested output filename already exists unless overwrite is True

cryolike.metadata.viewing_angles

class cryolike.metadata.viewing_angles.ViewingAngles(azimus: ndarray[tuple[int, ...], dtype[floating]] | Tensor, polars: ndarray[tuple[int, ...], dtype[floating]] | Tensor, gammas: ndarray[tuple[int, ...], dtype[floating]] | Tensor | None)

Bases: object

Class storing the viewing angles, with weights, for a particular template/image stack.

Viewing angles define the orientation of the particle relative to the imaging device. Thus, a ViewingAngles object is usually tied to a particular stack of observed images (Images) or reference images (Templates), with one value for each member for each image in the stack. However, if the ViewingAngles members are unit length in the highest dimension (i.e. len(azimus[0] == 1) then the angles can be broadcast to a whole image stack.

azimus

Azimuthal angle for each image

Type:

Tensor

polars

Polar angle for each image

Type:

Tensor

gammas

Gamma angle (grayscale correction factor) for each image

Type:

Tensor

weights_viewing

Weights to apply to each angle, per-image

Type:

Tensor

n_angles

Number of angles in the stack. For the ViewingAngles object to be paired with a Templates or Images object, the number of angles must match the number of images in that object, or be 1 (indicating that the angles will be broadcast over each image). The outermost length of each of the four tensors in the class must match the number of angles.

Type:

int

classmethod from_viewing_distance(viewing_distance: float) ViewingAngles

Constructs a set of viewing angles from a regular viewing distance.

Parameters:

viewing_distance (float) – The desired difference between two angles

Returns:

The set of viewing angles computed from this viewing distance

Return type:

ViewingAngles