ComputationalCryoEM / ASPIRE-Python

Algorithms for Single Particle Reconstruction
http://spr.math.princeton.edu
GNU General Public License v3.0
47 stars 21 forks source link

Reconstruction with know angles and substraction of images from a volume #1184

Open Grigori200 opened 2 weeks ago

Grigori200 commented 2 weeks ago

Dear Aspire Team,

I am working on machine learning research project for CryoEM and I am searching right now for a tool or algorithms that would help me to create a lot of reconstructions of the same particle from slightly different sets of images as fast as it is possible. For every image I have already perform ed full reconstruction and estimated euler angles with Relion. To do that I think that I need to find 2 things in your library:

  1. A way to reconstruction a 3D volume from images with know euler angles without performing estimation process
  2. A way to remove information provided by a given image (some what substraction it) from the volume that was created with it.

I am not sure if you can help me, but thanks in advance.

garrettwrong commented 1 week ago

Hi there, I think we can help you with that.

Our Image class has a backproject method which takes in rotations and returns a Volume.

import numpy as np
from aspire.downloader import emdb_2660
from aspire.image import Image
from aspire.source import Simulation
from aspire.utils import Rotation

# You may bring your own images:
#    - numpy array with Image(array)
#    - mrc file with  Image.load('foo.mrc')
# I'll just generate some images with known angles for this example.
src = Simulation(
    vols=emdb_2660().astype(np.float64),
    n=100,  # number of images
    offsets=0,  # disable shifting images, ie projections centered
    amplitudes=1,  # uniform image amplitude
    seed=123,  # rng seed
    dtype=np.float64
)
images = src.images[:]  # ASPIRE `Image` object
# images.asnumpy()  # yields the underlying numpy array directly

# Get the image projection euler angles.
angles = src.angles
# Note we use ZYZ convention.
# If you are bringing a different convention you'll
# need to convert them to rotation matrices with SciPy etc.
rotation_matrices = Rotation.from_euler(angles).matrices

# Backproject using rotation matrices
volume = images.backproject(rotation_matrices)  # ASPIRE `Volume` object
volume.save('result.map',overwrite=True)  # save the volume
# volume.asnumpy()  # yields the underlying numpy array directly

# You should be able to open the resulting file in Chimera etc.

We can also read/write STAR files with RelionSource if that is preferable to you.

As far as removing information for a projection, that is sort of ambiguous. Taken directly, you can add another image to your image stack (and rotation to rotation stack) scaled by a (negative) value. You can also backproject a single image and subtract the resulting volumes, taking care of any normalizing.