Model Module

The model module manages 3D/2D volume models for reconstruction.

Model Types

  • MODEL_3D - Full 3D volume reconstruction

  • MODEL_2D - 2D slice reconstruction

  • MODEL_RZ - Cylindrical (R-Z) reconstruction

Usage Example

from dragonfly.model import Model

model = Model(size=64, num_modes=2, model_type='3d')
model.allocate('starting_model.h5', model_mean=100.0)

view = model.slice_gen(quaternion, detector, mode=0)
class dragonfly.model.Model(long size=0, int num_modes=1, model_type='3d')

Bases: object

Model class for 3D/2D volume reconstruction.

Parameters:
  • size (int) – Size of the model grid. Default 0.

  • num_modes (int) – Number of modes. Default 1.

  • model_type (str) – Model type (‘3d’, ‘2d’, or ‘rz’). Default ‘3d’.

allocate(self, fname, double model_mean=1., int rank=0, bool fixed_seed=False)

Allocate and optionally load model from file.

Parameters:
  • fname (str) – Path to model file or empty string for random initialization.

  • model_mean (float) – Mean value for random initialization. Default 1.0.

  • rank (int) – MPI rank for parallel loading. Default 0.

  • fixed_seed (bool) – Use fixed seed for random initialization. Default False.

center

Center coordinate of the model.

free(self)

Free allocated model memory.

inter_weight

Interpolation weights, shape (num_modes, size, …).

static make_rot_quat(double[:] quaternion)

Convert quaternion to rotation matrix.

Parameters:

quaternion (numpy.ndarray) – 4-component quaternion.

Returns:

3x3 rotation matrix.

Return type:

numpy.ndarray

model1

Current model intensities, shape (num_modes, size, …).

model2

Accumulated model from current iteration, shape (num_modes, size, …).

mtype

Returns the model type (MODEL_3D, MODEL_2D, or MODEL_RZ).

ndim

Number of dimensions (3 for 3D, 2 for 2D/RZ).

num_modes

Number of modes.

static rotate_model(double[:, :, :] model, double[:, :] rot, int max_r=0, rotmodel=None)

Apply rotation matrix to model.

Parameters:
  • model (numpy.ndarray) – Model array to rotate.

  • rot (numpy.ndarray) – 3x3 rotation matrix.

  • max_r (int) – Maximum radius for masking. Default 0.

  • rotmodel (numpy.ndarray) – Pre-allocated output array. Default None.

Returns:

Rotated model.

Return type:

numpy.ndarray

size

Size of the model grid.

slice_gen(self, double[:] quat, CDetector det, int mode=0, view=None)

Generate a 2D slice from the model.

Parameters:
  • quat (numpy.ndarray) – Quaternion defining the orientation.

  • det (CDetector) – Detector to project onto.

  • mode (int) – Mode index. Default 0.

  • view (numpy.ndarray) – Pre-allocated output array. Default None.

Returns:

2D slice values.

Return type:

numpy.ndarray

slice_merge(self, double[:] quat, double[:] view, CDetector det, int mode=0)

Merge a 2D slice back into the model.

Parameters:
  • quat (numpy.ndarray) – Quaternion defining the orientation.

  • view (numpy.ndarray) – 2D slice values to merge.

  • det (CDetector) – Detector for projection.

  • mode (int) – Mode index. Default 0.

static symmetrize_axial(double[:, :, :] model, double[:, :, :] weights, int order)

Apply N-fold axial symmetry.

Parameters:
static symmetrize_friedel(double[:, :, :] model, double[:, :, :] weights)

Apply Friedel (point inversion) symmetry.

Parameters:
static symmetrize_friedel2d(double[:, :, :] model2d, double[:, :, :] weights2d)

Apply Friedel symmetry to 2D slices.

Parameters:
static symmetrize_icosahedral(double[:, :, :] model, double[:, :, :] weights)

Apply icosahedral point group symmetry.

Parameters:
static symmetrize_octahedral(double[:, :, :] model, double[:, :, :] weights)

Apply octahedral point group symmetry.

Parameters:
vol

Total volume (number of voxels).