core_refine_template
Backend functions related to correlating and refining particle stacks.
combine_euler_angles(angle_a, angle_b)
Helper function for composing rotations defined by two sets of Euler angles.
Source code in src/leopard_em/backend/core_refine_template.py
30 31 32 33 34 35 36 37 38 39 40 41 |
|
construct_multi_gpu_refine_template_kwargs(particle_stack_dft, template_dft, euler_angles, euler_angle_offsets, defocus_u, defocus_v, defocus_angle, defocus_offsets, pixel_size_offsets, corr_mean, corr_std, ctf_kwargs, projective_filters, batch_size, devices, num_cuda_streams)
Split particle stack between requested devices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particle_stack_dft
|
Tensor
|
Particle stack to split. |
required |
template_dft
|
Tensor
|
Template volume. |
required |
euler_angles
|
Tensor
|
Euler angles for each particle. |
required |
euler_angle_offsets
|
Tensor
|
Euler angle offsets to search over. |
required |
defocus_u
|
Tensor
|
Defocus U values for each particle. |
required |
defocus_v
|
Tensor
|
Defocus V values for each particle. |
required |
defocus_angle
|
Tensor
|
Defocus angle values for each particle. |
required |
defocus_offsets
|
Tensor
|
Defocus offsets to search over. |
required |
pixel_size_offsets
|
Tensor
|
Pixel size offsets to search over. |
required |
corr_mean
|
Tensor
|
Mean of the cross-correlation |
required |
corr_std
|
Tensor
|
Standard deviation of the cross-correlation |
required |
ctf_kwargs
|
dict
|
CTF calculation parameters. |
required |
projective_filters
|
Tensor
|
Projective filters for each particle. |
required |
batch_size
|
int
|
Batch size for orientation processing. |
required |
devices
|
list[device]
|
List of devices to split across. |
required |
num_cuda_streams
|
int
|
Number of CUDA streams to use per device. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
List of dictionaries containing the kwargs to call the single-GPU function. |
Source code in src/leopard_em/backend/core_refine_template.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
core_refine_template(particle_stack_dft, template_dft, euler_angles, euler_angle_offsets, defocus_offsets, defocus_u, defocus_v, defocus_angle, pixel_size_offsets, corr_mean, corr_std, ctf_kwargs, projective_filters, device, batch_size=32, num_cuda_streams=1)
Core function to refine orientations and defoci of a set of particles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particle_stack_dft
|
Tensor
|
The stack of particle real-Fourier transformed and un-fftshifted images. Shape of (N, H, W). |
required |
template_dft
|
Tensor
|
The template volume to extract central slices from. Real-Fourier transformed and fftshifted. |
required |
euler_angles
|
Tensor
|
The Euler angles for each particle in the stack. Shape of (N, 3). |
required |
euler_angle_offsets
|
Tensor
|
The Euler angle offsets to apply to each particle. Shape of (k, 3). |
required |
defocus_u
|
Tensor
|
The defocus along the major axis for each particle in the stack. Shape of (N,). |
required |
defocus_v
|
Tensor
|
The defocus along the minor for each particle in the stack. Shape of (N,). |
required |
defocus_angle
|
Tensor
|
The defocus astigmatism angle for each particle in the stack. Shape of (N,). Is the same as the defocus for the micrograph the particle came from. |
required |
defocus_offsets
|
Tensor
|
The defocus offsets to search over for each particle. Shape of (l,). |
required |
pixel_size_offsets
|
Tensor
|
The pixel size offsets to search over for each particle. Shape of (m,). |
required |
corr_mean
|
Tensor
|
The mean of the cross-correlation values from the full orientation search for the pixels around the center of the particle. Shape of (H - h + 1, W - w + 1). |
required |
corr_std
|
Tensor
|
The standard deviation of the cross-correlation values from the full orientation search for the pixels around the center of the particle. Shape of (H - h + 1, W - w + 1). |
required |
ctf_kwargs
|
dict
|
Keyword arguments to pass to the CTF calculation function. |
required |
projective_filters
|
Tensor
|
Projective filters to apply to each Fourier slice particle. Shape of (N, h, w). |
required |
device
|
device | list[device]
|
Device or list of devices to use for processing. |
required |
batch_size
|
int
|
The number of cross-correlations to process in one batch, defaults to 32. |
32
|
num_cuda_streams
|
int
|
Number of CUDA streams to use for parallel processing. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
dict[str, Tensor]
|
Dictionary containing the refined parameters for all particles. |
Source code in src/leopard_em/backend/core_refine_template.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
cross_correlate_particle_stack(particle_stack_dft, template_dft, rotation_matrices, projective_filters, mode='valid', batch_size=1024)
Cross-correlate a stack of particle images against a template.
Here, the argument 'particle_stack_dft' is a set of RFFT-ed particle images with necessary filtering already applied. The zeroth dimension corresponds to unique particles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particle_stack_dft
|
Tensor
|
The stack of particle real-Fourier transformed and un-fftshifted images. Shape of (N, H, W). |
required |
template_dft
|
Tensor
|
The template volume to extract central slices from. Real-Fourier transformed and fftshifted. |
required |
rotation_matrices
|
Tensor
|
The orientations of the particles to take the Fourier slices of, as a long list of rotation matrices. Shape of (N, 3, 3). |
required |
projective_filters
|
Tensor
|
Projective filters to apply to each Fourier slice particle. Shape of (N, h, w). |
required |
mode
|
Literal['valid', 'same']
|
Correlation mode to use, by default "valid". If "valid", the output will be the valid cross-correlation of the inputs. If "same", the output will be the same shape as the input particle stack. |
'valid'
|
batch_size
|
int
|
The number of particle images to cross-correlate at once. Default is 1024. Larger sizes will consume more memory. If -1, then the entire stack will be cross-correlated at once. |
1024
|
Returns:
Type | Description |
---|---|
Tensor
|
The cross-correlation of the particle stack with the template. Shape will depend on the mode used. If "valid", the output will be (N, H-h+1, W-w+1). If "same", the output will be (N, H, W). |
Raises:
Type | Description |
---|---|
ValueError
|
If the mode is not "valid" or "same". |
Source code in src/leopard_em/backend/core_refine_template.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
|