Hello,
We would like to analyze the Viewing Direction Distribution in more detail. Is there a way to extract this information from one of the .cs files generated by Cryosparc?
Hello,
We would like to analyze the Viewing Direction Distribution in more detail. Is there a way to extract this information from one of the .cs files generated by Cryosparc?
Hi @Pielhaas,
CryoSPARC will soon support automatic generation of BILD files that help display the viewing direction distribution, see this thread for more discussion on how BILD files display the viewing direction distribution.
The raw 3D pose data in CryoSPARC that are used to generate these files (along with the viewing direction plot) are contained within the alignments3D/pose
variables, which store poses in an axis-angle representation in radians. This could certainly be extracted and worked with in a scripting environment via CryoSPARC Tools. The viewing direction specifically is a function of the pose, and extracting it would require converting the axis-angle vector to a rotation matrix and taking it’s last column. I could provide a quick code snippet to use built-in CryoSPARC functions to do this if desired – please let me know!
Hope this helps,
Michael
Yes if you have pyem installed you have star2bild.py which creates the BILD output for any star file. You could also use it to get out the distribution itself to do your own analysis.
Dear Michael,
Thank you for your reply and offer to help. Instead of converting the cs files to star files to bild files and then extract the numerical values, I think it would be more efficient if one could calculate the angular viewing directions directly from the cs files. Given that there are several ways to convert an axis-angle vector to a rotation matrix, I would very much appreciate if you could provide a code snippet that allows to determine the viewing directions.
Best regards, Marcel
Hi @Pielhaas,
Please see this thread for a similar script which you could use as a template for how to load particles into a python script using CryoSPARC Tools. For the code snippet:
# [...]
from cryosparc_compute import geometry
import numpy as n
particles_dset = job.load_output('particles') # particles from desired job
poses = particles_dset['alignments3D/pose']
def get_viewdir(poses):
""" Get the viewing direction from 3D particle poses """
Rs = geometry.expmaps(poses)
viewdirs = Rs[...,2]
return viewdirs
def get_azimuth_elevation(viewdirs):
""" Get the azimuth and elevation angles from a viewing direction vector """
viewdirs_azimuth = n.arctan2( viewdirs[:, 1], viewdirs[:, 0])
viewdirs_elevation = n.arcsin( viewdirs[:, 2])
return viewdirs_azimuth, viewdirs_elevation
viewdirs = get_viewdir(poses)
az, el = get_azimuth_elevation(viewdirs)
viewdirs
is a 3D vector pointing along the projection direction.
Best,
Michael
Thank you @mmclean for the snippet.
I have cryosparc tools 4.2.0 installed but am not able to get it to work. The line :
from cryosparc_compute import geometry
causes an error: No module named ‘cryosparc_compute’
Analogous the line in the linked script,
from cryosparc_tools.cryosparc.tools import CryoSPARC
yields a similar error.
Any ideas of what might be wrong?
Dear @Pielhaas,
Apologies for the delayed response. I believe this is because internal CryoSPARC modules (e.g. cryosparc_compute
) are not accessible in the CryoSPARC Tools environment.
First, you can locate the path to the desired particles cs file, from the output of a refinement job. This can be obtained from the following button in the outputs tab:
You could modify the snippet below to such that particles_dset
refers to the desired particle cs file:
from cryosparc_compute import geometry
import numpy as n
# Replace me below!
particles_dset = dataset.Dataset.load('/path/to/cs/file/of/desired/particles.cs') # particles from desired job
poses = particles_dset['alignments3D/pose']
def get_viewdir(poses):
""" Get the viewing direction from 3D particle poses """
Rs = geometry.expmaps(poses)
viewdirs = Rs[...,2]
return viewdirs
def get_azimuth_elevation(viewdirs):
""" Get the azimuth and elevation angles from a viewing direction vector """
viewdirs_azimuth = n.arctan2( viewdirs[:, 1], viewdirs[:, 0])
viewdirs_elevation = n.arcsin( viewdirs[:, 2])
return viewdirs_azimuth, viewdirs_elevation
viewdirs = get_viewdir(poses)
az, el = get_azimuth_elevation(viewdirs)
You could then try running this in the cryosparcm interactive client via running the terminal command:
cryosparcm icli
and finally copy and pasting the contents of the modified script above.
Now, the az
and el
variables would hold the azimuth and elevation viewing directions for each particle, in the order they exist in the dataset.
Best,
Michael
Thank you for the clarification.
Is there any chance the compute module will implemented in cryosparc-tools? It would significantly simplify some of our procedures.