ml-struct-bio / cryodrgn

Neural networks for cryo-EM reconstruction
http://cryodrgn.cs.princeton.edu
GNU General Public License v3.0
311 stars 75 forks source link

backproject_voxel FSC plot should automatically detect the pixel size #385

Closed zhonge closed 3 weeks ago

zhonge commented 3 months ago

I ran cryodrgn backproject_voxel on a cryo-ET dataset, and this was the output plot:

Command:

$ cryodrgn backproject_voxel particles.star --tilt -d 2.93 --poses pose.pkl --ctf ctf.pkl --datadir subtilts/ -o backproject_voxel.mrc

iTerm2 O0cIO9 backproject_voxel_fsc-plot

The units are incorrect since the pixel size is 3.401 A. We should try to automatically detect the pixel size from the input ctf.pkl. Also let's update the x axis label to "Spatial frequency".

michal-g commented 3 months ago

In backproject_voxel.py, the pixel size was already being detected from the input ctf.pkl:

Apix = float(ctf_params[0, 0]) if ctf_params is not None else 1.0

and passed along to relevant downstream functions, such as when saving the volume:

MRCFile.write(args.o, np.array(volume_full).astype("float32"), Apix=Apix)

but not when creating the half-map FSC plot:

create_fsc_plot(fsc_vals=fsc_vals, outfile="_".join([out_path, "fsc-plot.png"]))

which has now been updated to:

create_fsc_plot(fsc_vals=fsc_vals, outfile="_".join([out_path, "fsc-plot.png"]), Apix=Apix)

compare this to the similar usage of create_fsc_plot() in commands_utils/fsc.py:

create_fsc_plot(fsc_vals=fsc_vals, outfile=plot_file, Apix=args.Apix)

Thus as of v3.4.0-a1 these plots should be updated to look more like:

backproject_tilt2_fsc-plot

This plot was created using the command

cryodrgn backproject_voxel tests/data/sta_testing_bin8.star --poses tests/data/sta_pose.pkl --ctf tests/data/sta_ctf.pkl --datadir tests/data/ -o backproject_tilt2.mrc -d 2.93 -a 3 --tilt

ran from within this cryodrgn/ repository, i.e. using the testing files located here!

michal-g commented 3 weeks ago

For the v3.4.0 release we ended up doing a deeper update of both backprojection and FSC calculation including incorporating the phase-randomization method used by cryoSPARC to correct for mask overfitting.

backproject_voxel now uses a given directory to store output, so the above example can now be replicated using:

$ cryodrgn backproject_voxel tests/data/sta_testing_bin8.star --poses tests/data/sta_pose.pkl --ctf tests/data/sta_ctf.pkl --datadir tests/data/ -o backproject_tilt/ -d 2.93 -a 3 --tilt
$ cryodrgn_utils fsc backproject_tilt/half_map_a.mrc backproject_tilt/half_map_b.mrc -p test-plot.png

whereas the default plot now produced by backproject_voxel for this reconstruction can be found under backproject_tilt/fsc-plot.png: fsc-plot