Skip to content

Instantly share code, notes, and snippets.

@alisterburt
Created February 11, 2023 14:24
Show Gist options
  • Select an option

  • Save alisterburt/fe8eb89c4bee793c7a1cda63bdc623e7 to your computer and use it in GitHub Desktop.

Select an option

Save alisterburt/fe8eb89c4bee793c7a1cda63bdc623e7 to your computer and use it in GitHub Desktop.
Extract particles poses from a RELION 3.1 STAR file
import starfile
from scipy.spatial.transform import Rotation as R
particle_star_file = 'hiv/01_10.00Apx_particles.star'
star = starfile.read(particle_star_file)
df = df = star['particles'].merge(star['optics'], on='rlnOpticsGroup')
# get necessary info from dataframes
xyz = df[['rlnCoordinateX', 'rlnCoordinateY', 'rlnCoordinateZ']].to_numpy()
shifts_ang = df[['rlnOriginXAngst', 'rlnOriginYAngst', 'rlnOriginZAngst']].to_numpy()
pixel_size = df['rlnImagePixelSize'].to_numpy()
euler_angles = df[['rlnAngleRot', 'rlnAngleTilt', 'rlnAnglePsi']].to_numpy()
# Get absolute position and orientations
particle_positions = xyz - (shifts_ang / pixel_size)
rotation_matrices = R.from_euler(
seq='ZYZ', angles=euler_angles, degrees=True
).inv().as_matrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment