Skip to content

Instantly share code, notes, and snippets.

@alisterburt
Last active February 11, 2023 14:16
Show Gist options
  • Select an option

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

Select an option

Save alisterburt/83496cae0cb852fcd149902b53a8eefc to your computer and use it in GitHub Desktop.
RELION 3.0 particle pose from STAR file
import starfile
from scipy.spatial.transform import Rotation as R
particle_star_file = 'hiv/01_10.00Apx_particles.star'
df = starfile.read(particle_star_file)
# get necessary info from dataframe
xyz = df[['rlnCoordinateX', 'rlnCoordinateY', 'rlnCoordinateZ']].to_numpy() # (n, 3)
shifts = df[['rlnOriginX', 'rlnOriginY', 'rlnOriginZ']].to_numpy() # (n, 3)
euler_angles = df[['rlnAngleRot', 'rlnAngleTilt', 'rlnAnglePsi']].to_numpy() # (n, 3)
# Get absolute position and orientation
particle_positions = xyz - shifts
rotation_matrices = R.from_euler(
seq='ZYZ', angles=euler_angles, degrees=True
).inv().as_matrix() # (n, 3, 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment