em_map_utils.map_covariance

map_covariance.py

Author:

Ardan Patwardhan

Affiliation:

EMBL-EBI, Wellcome Genome Campus, CB10 1SD, UK

Date:

31/07/2025

Description:

Class for handling the covariance matrix of the map value distribution and related eigenvectors and eigenvalues.

Attributes

Classes

Classes

MapCovariance

-

Module Contents

em_map_utils.map_covariance.logger
class em_map_utils.map_covariance.MapCovariance(map_grid)
RHAS_XYZ
RHAS_ZYX
RHAS_BASE
RHAS_ALL
static sign_align_eigenvectors(evecs1, evecs2)

Two eigenvector systems may be very similar but look very different due to the signs. Here we change the signs of evec2 to make it as similar to evec1 while keeping to a right-handed system. In order to maintain a right handed system, two vectors need to change sign.

Note: Eigenvectors are specified in different columns, e.g evecs[:,0], evecs[:,1], evecs[:,2].

Parameters:
  • evecs1 – First set of eigenvectors

  • evecs2 – Second set of eigenvectors

Returns:

Second set of eigenvectors where the signs of the eigenvectors have been adjusted

classmethod find_closest_rhas(vecs)

Given a triplet of basis vectors, find the closest match right handed coordinate system.

Parameters:

vecs – Triplet of vectors, one in each column.

Returns:

Closest matching right-handed system with each column representing a basis vector.

classmethod align_map_principal_axes(map_grid, axes=None, cubify_if_needed=False, dtype=np.float32)

Determine the principal axes that corresponds to a map grid and rotate the map so that the principal axes are aligned with the axes specified. Notes: 1) The axis vectors in axes are in columns, e.g., axis 0 = axes[:,0], axis 1 = axes[:,1]. 2) The principal axis will be ordered by eigenvalue in descending order and the first axis

will be aligned to axes[:,0]

Parameters:
  • map_grid – Map grid to be aligned.

  • axes – Axis vectors to use as a reference when aligning principal axes. If None, the closest right-handed system to the eigenvectors will be used.

  • cubify_if_needed – If the map is non-cubic, pad it to the max dimension prior to any rotation.

  • dtype – Data type of the output arrays.

Returns:

Aligned map grid, applied rotation, eigenvalues, and eigenvectors.

classmethod map_rotate_forward_backward(map_grid, rotation, cubify_if_needed=False)

Rotate map by the given rotation, estimate the rotation using the map’s principal axes. Rotate the map back so that the map is once again aligned to the input map and then find the diff between the rotation matrices of the input and back-rotated map. This method is useful for testing purposes.

Parameters:
  • map_grid – Input map.

  • rotation – SciPy rotation to apply to input map.

  • cubify_if_needed – If map is cubic, pad it to the max dimension prior to any rotation.

Returns:

Tuple with rotated map, back-rotated map and back rotation.

phys_scale_eigenvectors(mrc, scaling)

Using the voxel sizes from an MRC file to scale the eigen- vectors to Ångstroms. Note although the voxel size in the three dimensions is almost always the same in cryoEM, this routine takes into account that they may not be. However this feature has not been tested.

Parameters:
  • mrc – MRC file with voxel sizes.

  • scaling – Scaling factor to apply to vectors.

Returns:

Vector with scalings for each of the eigenvectors.

lengths_from_eigenvalues(mrc, scaling)

The eigenvalues are related to the extent of the map value distribution along the principal axes. This routine attempts to estimate the physical extents of the map value distribution using different estimates.

Parameters:
  • mrc – MRC file contain voxel sizes.

  • scaling – Scaling factor to apply to vectors.

Returns:

Tuple with FWHM, two sigma and sphere diameter lengths.

centre_coos
cov_matrix
eigenvalues
eigenvectors
em_map_utils.map_covariance.parser