| Bsoft 2.0.5 Bernard's software package

mg_refine.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_refine.h"
11 #include "rwmg.h"
12 #include "mg_ctf.h"
13 #include "rwimg.h"
14 #include "Complex.h"
15 #include "Matrix3.h"
16 #include "linked_list.h"
17 #include "random_numbers.h"
18 #include "utilities.h"
19
20 #include <sys/stat.h>
21 #include <fcntl.h>
22
23 // Declaration of global variables
24 extern int verbose; // Level of output to the screen
25
26 // Local function prototypes
27 long part_refine_orientation(Bparticle* part, Bstring& partfile, double pixel_size,
28 Bimage* pref, Bimage* pmask, Bsymmetry* sym, int max_iter, double alpha_step, double accuracy,
29 double shift_step, double shift_accuracy, double hi_res, double lo_res,
30 int fom_type, vector<double> weight, double edge_radius,
31 CTFparam* em_ctf, double def_std, double shift_std,
32 double view_std, double max_angle, double max_mag, int flags,
33 FSI_Kernel* kernel, fft_plan planf);
34 double img_refine_monte(Bimage* p, Bimage* pref, double hi_res, double lo_res,
35 int max_iter, int fom_type, vector<double>& weight, CTFparam* em_ctf,
36 double def_std, double shift_std, double view_std,
37 double max_angle, double max_mag, FSI_Kernel* kernel, long &number);
38 double img_refine_grid(Bimage* p, Bimage* pref, double hi_res, double lo_res,
39 double alpha_step, double accuracy, double shift_step,
40 double shift_accuracy, double max_mag,
41 int fom_type, vector<double>& weight, CTFparam* em_ctf, double def_std, FSI_Kernel* kernel, long &number);
42
77 long mg_refine_orientations(Bproject* project, Bstring& reffile, Bstring& maskfile,
78 Bstring& sym_string, int part_select, int max_iter,
79 double alpha_step, double accuracy, double shift_step,
80 double shift_accuracy, int fom_type, vector<double> weight,
81 double hi_res, double lo_res, int kernel_width, int kernel_power,
82 double edge_radius, double def_std, double shift_std,
83 double view_std, double max_angle, double max_mag, int flags)
84 {
85 if ( reffile.length() < 1 ) {
86 cerr << "Error: A reference map must be provided!" << endl << endl;
87 return -1;
88 }
89
90 if ( max_iter < 1 ) {
91 if ( alpha_step < SMALLFLOAT || accuracy < SMALLFLOAT ) {
92 if ( alpha_step < SMALLFLOAT )
93 cerr << "Error: The angular step size is too small! (" << alpha_step*180.0/M_PI << ")" << endl;
94 if ( accuracy < SMALLFLOAT )
95 cerr << "Error: The accuracy is too small! (" << accuracy*180.0/M_PI << ")" << endl;
96 return -1;
97 }
98 if ( alpha_step < accuracy ) {
99 cerr << "Error: The angular step size is smaller than the accuracy! (" << alpha_step*180.0/M_PI << " < " << accuracy*180.0/M_PI << ")" << endl;
100 return -1;
101 }
102 }
103
104 random_seed();
105
106 if ( sym_string.length() < 1 ) sym_string = "C1";
107
108 Bsymmetry* sym = init_point_group_symmetry(sym_string);
109
110 long npart(0), npix, number(0);
111 Bfield* field = project->field;
112 Bmicrograph* mg;
113 Bparticle* part;
114
115 Bimage* pref = read_img(reffile, 1, -1);
116
117 if ( !pref ) {
118 cerr << "Error: The reference was not read!" << endl << endl;
119 return -1;
120 }
121
122 if ( hi_res < 2*pref->sampling()[0] ) hi_res = 2*pref->sampling()[0];
123
124 if ( !weight.size() )
125 weight = C_curve(pref->sizeX(), 1/pref->real_size()[0]);
126
127 // Fourier transform size for the original map size
128 long ft_size = pref->sizeX();
129
130 if ( pref->compound_type() == TSimple ) {
131 if ( verbose )
132 cout << "Fourier transforming reference map " << pref->file_name() << endl;
133 pref->fft();
134 }
135
136 // Reduce the reference map's transform size to save memory
137 int diam = (int) (2.2*pref->real_size()[0]/hi_res + 0.5);
138 if ( diam%2 ) diam += 1;
139 Vector3<long> size(diam, diam, diam);
140 Vector3<double> scale(1,1,1);
141 if ( diam < pref->sizeX() )
142 scale = pref->change_transform_size(size);
143
144 pref->set(0, 0);
145 pref->set(1, 0);
146
147 npix = pref->sizeX()*pref->sizeY();
148
149 // Mask to apply to particles
150 Bimage* pmask = NULL;
151 if ( maskfile.length() ) pmask = read_img(maskfile, 1, 0);
152
153 if ( hi_res < 2*pref->sampling()[0] ) hi_res = 2*pref->sampling()[0];
154
155 // Interpolation kernel
156 FSI_Kernel* kernel = new FSI_Kernel(kernel_width, kernel_power);
157
158 // FFT plan for the particle images
159 fft_plan planf = fft_setup_plan(ft_size, ft_size, 1, FFTW_FORWARD, 1);
160
161 if ( verbose ) {
162 cout << "Refining orientations:" << endl;
163 if ( max_iter ) {
164 cout << "Maximum iterations: " << max_iter << endl;
165 cout << "Defocus standard deviation: " << def_std << " A" << endl;
166 cout << "Shift standard deviation: " << shift_std << " pixels" << endl;
167 cout << "View standard deviation: " << view_std << endl;
168 cout << "Maximum angle variation: " << max_angle*180.0/M_PI << " degrees" << endl;
169 cout << "Maximum magnification variation: " << max_mag << endl;
170 } else {
171 cout << "Grid angular step and accuracy: " << alpha_step*180.0/M_PI
172 << " " << accuracy*180.0/M_PI << " degrees" << endl;
173 cout << "Grid shift step and accuracy: " << shift_step
174 << " " << shift_accuracy << " pixels" << endl;
175 cout << "Maximum magnification change: " << max_mag << endl;
176 }
177 cout << "Reference: " << pref->file_name() << endl;
178 // cout << "Reference origin: " << pref->image->origin()/scale << endl;
179 cout << "Reference origin: " << pref->image->origin()/scale << endl;
180 if ( maskfile.length() ) cout << "Real space mask file: " << maskfile << endl;
181 cout << "Symmetry: " << sym_string << endl;
182 cout << "Resolution measurement type: ";
183 if ( fom_type < 1 ) cout << "FRC" << endl;
184 else cout << "DPR" << endl;
185 cout << "Resolution limits: " << hi_res << " - ";
186 if ( lo_res > 0 ) cout << lo_res << " A" << endl;
187 else cout << " inf A" << endl;
188 cout << "Micrograph\tPID\tMag\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
189 }
190
191 pref->phase_shift_to_origin();
192
193 if ( verbose & VERB_DEBUG )
194 cout << "DEBUG mg_refine_orientations: origin after phase shift: " << pref->image->origin() << endl;
195
196 // Directory for individual particle parameter files
197 if ( flags & WRITE_PPX ) {
198 mkdir("ppx", O_CREAT );
199 chmod("ppx", 0755);
200 }
201
202 time_t t = time(NULL);
203
204 for ( field = project->field; field; field = field->next ) {
205 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->part ) {
206 for ( part = mg->part; part; part = part->next ) {
207 if ( ( part_select<0 && part->sel ) || ( part->sel==part_select ) ) {
208 number += part_refine_orientation(part, mg->fpart, mg->pixel_size, pref, pmask, sym,
209 max_iter, alpha_step, accuracy, shift_step, shift_accuracy,
210 hi_res, lo_res, fom_type, weight, edge_radius,
211 mg->ctf, def_std, shift_std, view_std, max_angle, max_mag,
212 flags, kernel, planf);
213 npart++;
214 if ( verbose & VERB_RESULT )
215 cout << setw(15) << mg->id << tab << part->id << tab << part->mag << tab <<
216 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
217 setprecision(4) << part->view[0] << tab <<
218 part->view[1] << tab << part->view[2] << tab <<
219 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
220 setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
221 (long)(time(NULL) - t) << endl;
222 } else {
223 part->fom[0] = part->fom[1] = part->sel = 0;
224 }
225 }
226 }
227 }
228
229 t = (time(NULL) - t);
230
231 long ts = (long) t;
232 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
233
234 if ( verbose & VERB_RESULT ) {
235 cout << "Number of comparisons: " << number << endl;
236 cout << "Comparisons per particle: " << number*1.0/npart << endl;
237 cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
238 cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
239 cout << "Algorithm time: " << ts*1.0e6/(number*npix) << " us/pixel" << endl << endl;
240 }
241
242 kill_symmetry(sym);
243
244 delete kernel;
245
246 fft_destroy_plan(planf);
247
248 return number;
249 }
250
251 long project_refine_orientations(Bproject* project, Bstring& reffile, Bstring& maskfile,
252 Bstring& sym_string, int part_select, int max_iter,
253 double alpha_step, double accuracy, double shift_step,
254 double shift_accuracy, int fom_type, vector<double> weight,
255 double hi_res, double lo_res, int kernel_width, int kernel_power,
256 double edge_radius, double def_std, double shift_std,
257 double view_std, double max_angle, double max_mag, int flags)
258 {
259 if ( reffile.length() < 1 ) {
260 cerr << "Error: A reference map must be provided!" << endl << endl;
261 return -1;
262 }
263
264 if ( max_iter < 1 ) {
265 if ( alpha_step < SMALLFLOAT || accuracy < SMALLFLOAT ) {
266 if ( alpha_step < SMALLFLOAT )
267 cerr << "Error: The angular step size is too small! (" << alpha_step*180.0/M_PI << ")" << endl;
268 if ( accuracy < SMALLFLOAT )
269 cerr << "Error: The accuracy is too small! (" << accuracy*180.0/M_PI << ")" << endl;
270 return -1;
271 }
272 if ( alpha_step < accuracy ) {
273 cerr << "Error: The angular step size is smaller than the accuracy! (" << alpha_step*180.0/M_PI << " < " << accuracy*180.0/M_PI << ")" << endl;
274 return -1;
275 }
276 }
277
278 random_seed();
279
280 if ( sym_string.length() < 1 ) sym_string = "C1";
281
282 Bsymmetry* sym = init_point_group_symmetry(sym_string);
283
284 long npix;
285 Bimage* pref = read_img(reffile, 1, -1);
286
287 if ( !pref ) {
288 cerr << "Error: The reference was not read!" << endl << endl;
289 return -1;
290 }
291
292 if ( hi_res < 2*pref->sampling()[0] ) hi_res = 2*pref->sampling()[0];
293
294 // Fourier transform size for the original map size
295 long ft_size = pref->sizeX();
296
297 if ( pref->compound_type() == TSimple ) {
298 if ( verbose )
299 cout << "Fourier transforming reference map " << pref->file_name() << endl;
300 pref->fft();
301 }
302
303 // Reduce the reference map's transform size to save memory
304 int diam = (int) (2.2*pref->real_size()[0]/hi_res + 0.5);
305 if ( diam%2 ) diam += 1;
306 Vector3<long> size(diam, diam, diam);
307 Vector3<double> scale(1,1,1);
308 if ( diam < pref->sizeX() )
309 scale = pref->change_transform_size(size);
310
311 pref->set(0, 0);
312 pref->set(1, 0);
313
314 npix = pref->sizeX()*pref->sizeY();
315
316 // Mask to apply to particles
317 Bimage* pmask = NULL;
318 if ( maskfile.length() ) {
319 pmask = read_img(maskfile, 1, 0);
320 pmask->origin(pmask->size()/2);
321 }
322
323 if ( hi_res < 2*pref->sampling()[0] ) hi_res = 2*pref->sampling()[0];
324
325 // Interpolation kernel
326 FSI_Kernel* kernel = new FSI_Kernel(kernel_width, kernel_power);
327
328 // FFT plan for the particle images
329 fft_plan planf = fft_setup_plan(ft_size, ft_size, 1, FFTW_FORWARD, 1);
330
331 long npart(0);
332 Bparticle** partarr = project_mg_particle_array(project, part_select, npart);
333
334 if ( verbose ) {
335 cout << "Refining orientations:" << endl;
336 if ( max_iter ) {
337 cout << "Maximum iterations: " << max_iter << endl;
338 cout << "Shift standard deviation: " << shift_std << " pixels" << endl;
339 cout << "View standard deviation: " << view_std << endl;
340 cout << "Maximum angle variation: " << max_angle*180.0/M_PI << " degrees" << endl;
341 cout << "Maximum magnification variation: " << max_mag << endl;
342 } else {
343 cout << "Grid step and accuracy: " << alpha_step*180.0/M_PI
344 << " " << accuracy*180.0/M_PI << " degrees" << endl;
345 cout << "Maximum magnification change: " << max_mag << endl;
346 }
347 cout << "Defocus standard deviation: " << def_std << " A" << endl;
348 cout << "Reference: " << pref->file_name() << endl;
349 // cout << "Reference origin: " << pref->image->origin()/scale << endl;
350 cout << "Reference origin: " << pref->image->origin()/scale << endl;
351 if ( maskfile.length() ) cout << "Real space mask file: " << maskfile << endl;
352 cout << "Symmetry: " << sym_string << endl;
353 cout << "Resolution measurement type: ";
354 if ( fom_type < 1 ) cout << "FRC" << endl;
355 else cout << "DPR" << endl;
356 cout << "Resolution limits: " << hi_res << " - ";
357 if ( lo_res > 0 ) cout << lo_res << " A" << endl;
358 else cout << " inf A" << endl;
359 cout << "Weighting scheme: ";
360 if ( !weight.size() )
361 cout << "C curve" << endl;
362 else
363 cout << "Input curve" << endl;
364 cout << "Micrograph\tPID\tMag\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
365 }
366
367 pref->phase_shift_to_origin();
368
369 if ( !weight.size() )
370 weight = C_curve(pref->sizeX(), 1/pref->real_size()[0]);
371
372 if ( verbose & VERB_DEBUG )
373 cout << "DEBUG project_refine_orientations: origin after phase shift: " << pref->image->origin() << endl;
374
375 // Directory for individual particle parameter files
376 if ( flags & WRITE_PPX ) {
377 mkdir("ppx", O_CREAT );
378 chmod("ppx", 0755);
379 }
380
381 time_t t = time(NULL);
382 long number(0);
383 int* nar = new int[npart];
384
385 #ifdef HAVE_GCD
386 dispatch_queue_t myq = dispatch_queue_create(NULL, NULL);
387 dispatch_apply(npart, dispatch_get_global_queue(0, 0), ^(size_t i){
388 Bparticle* part = partarr[i];
389 Bmicrograph* mg = part->mg;
390 nar[i] = part_refine_orientation(part,
391 mg->fpart, mg->pixel_size, pref, pmask, sym,
392 max_iter, alpha_step, accuracy, shift_step, shift_accuracy,
393 hi_res, lo_res, fom_type, weight, edge_radius,
394 mg->ctf, def_std, shift_std, view_std, max_angle, max_mag,
395 flags, kernel, planf);
396 dispatch_sync(myq, ^{
397 if ( verbose & VERB_RESULT )
398 cout << setw(15) << mg->id << tab << part->id << tab << part->mag << tab <<
399 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
400 setprecision(4) << part->view[0] << tab <<
401 part->view[1] << tab << part->view[2] << tab <<
402 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
403 setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
404 (long)(time(NULL) - t) << endl;
405 });
406 });
407 #else
408 #pragma omp parallel for
409 for ( long i=0; i<npart; i++ ) {
410 Bparticle* part = partarr[i];
411 Bmicrograph* mg = part->mg;
412 nar[i] = part_refine_orientation(part,
413 mg->fpart, mg->pixel_size, pref, pmask, sym,
414 max_iter, alpha_step, accuracy, shift_step, shift_accuracy,
415 hi_res, lo_res, fom_type, weight, edge_radius,
416 mg->ctf, def_std, shift_std, view_std, max_angle, max_mag,
417 flags, kernel, planf);
418 #pragma omp critical
419 {
420 if ( verbose & VERB_RESULT )
421 cout << setw(15) << mg->id << tab << part->id << tab << part->mag << tab <<
422 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
423 setprecision(4) << part->view[0] << tab <<
424 part->view[1] << tab << part->view[2] << tab <<
425 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
426 setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
427 (long)(time(NULL) - t) << endl;
428 }
429 }
430 #endif
431
432 for ( long i=0; i<npart; i++ ) number += nar[i];
433
434 t = (time(NULL) - t);
435
436 long ts = (long) t;
437 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
438
439 if ( verbose & VERB_RESULT ) {
440 cout << "Number of comparisons: " << number << endl;
441 cout << "Comparisons per particle: " << number*1.0/npart << endl;
442 cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
443 cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
444 cout << "Algorithm time: " << ts*1.0e6/(number*npix) << " us/pixel" << endl << endl;
445 }
446
447 delete[] partarr;
448 delete[] nar;
449
450 kill_symmetry(sym);
451
452 delete kernel;
453
454 fft_destroy_plan(planf);
455
456 return number;
457 }
458
492 long part_refine_orientation(Bparticle* part, Bstring& partfile, double pixel_size,
493 Bimage* pref, Bimage* pmask, Bsymmetry* sym, int max_iter, double alpha_step, double accuracy,
494 double shift_step, double shift_accuracy, double hi_res, double lo_res,
495 int fom_type, vector<double> weight, double edge_radius,
496 CTFparam* em_ctf, double def_std, double shift_std,
497 double view_std, double max_angle, double max_mag, int flags,
498 FSI_Kernel* kernel, fft_plan planf)
499 {
500 FOMType fom_tag[NFOM] = {FOM, FOM_CV};
501
502 if ( flags & CHECK_PPX )
503 if ( ppx_check(part, fom_tag) ) return 0;
504
505 if ( verbose & VERB_DEBUG )
506 cout << "DEBUG part_refine_orientation: file=" << partfile << " image=" << part->id << endl;
507
508 Bimage* p = read_img(partfile, 1, part->id - 1);
509 if ( !p )
510 return error_show("Error in part_refine_orientation", __FILE__, __LINE__);
511
512 if ( pixel_size > 0 ) p->sampling(pixel_size, pixel_size, 1);
513
514 if ( part->ori[0] <= 0 ) {
515 if ( p->image->origin()[0] > 0 ) part->ori[0] = p->image->origin()[0];
516 else part->ori[0] = p->sizeX()/2;
517 }
518 if ( part->ori[1] <= 0 ) {
519 if ( p->image->origin()[1] > 0 ) part->ori[1] = p->image->origin()[1];
520 else part->ori[1] = p->sizeY()/2;
521 }
522 part->ori[2] = 0;
523 p->origin(part->ori);
524
525 if ( part->mag < 0.5 ) {
526 if ( p->image->magnification() > 0.5 )
527 part->mag = p->image->magnification();
528 else part->mag = 1;
529 }
530
531 part->fom[0] = part->fom[1] = 0;
532
533 p->change_type(Float);
534 p->rescale_to_avg_std(0, 1);
535 p->calculate_background();
536
537 int edge_size = (int) (2*edge_radius);
538 Vector3<long> size(edge_size, edge_size, 1);
539 Vector3<double> start(part->ori[0]-edge_radius, part->ori[1]-edge_radius, 0);
540 if ( edge_size )
541 p->edge(1, size, start, 1, FILL_BACKGROUND, 0);
542
543 Vector3<double> shift;
544 Bimage* pm;
545
546 if ( pmask ) {
547 pm = pmask->copy();
548 shift = p->image->origin() - pm->image->origin();
549 pm->shift(shift);
550 p->multiply(pm);
551 delete pm;
552 }
553
554 p->fft(planf, 0);
555
556 p->set(0, 0);
557 p->set(1, 0);
558
559 // Reduce the particle transform size to match that of the reference
560 Vector3<double> scale(1,1,1);
561 if ( pref->sizeX() < p->sizeX() ) {
562 size[0] = pref->sizeX();
563 size[1] = pref->sizeY();
564 scale = p->change_transform_size(size);
565 }
566
567 int apply_ctf(0);
568 double bestdef(0);
569 if ( em_ctf ) {
570 bestdef = em_ctf->defocus_average();
571 if ( def_std ) {
572 if ( part->def < 1 ) part->def = em_ctf->defocus_average();
573 bestdef = part->def;
574 apply_ctf = 1;
575 }
576 }
577
578 long i, number(0);
579 double fom, bestmag = part->mag;
580 Vector3<double> bestorigin(scale[0]*part->ori[0], scale[1]*part->ori[1], scale[2]*part->ori[2]);
581 View bestview = part->view;
582 View* view = symmetry_get_all_views(sym, part->view);
583 View* v;
584 CTFparam* ctf_copy = new CTFparam;
585
586 for ( i=1, v = view; v; v = v->next, i++ ) {
587 p->origin(scale[0]*part->ori[0], scale[1]*part->ori[1], scale[2]*part->ori[2]);
588 p->view(*v);
589 p->image->magnification(part->mag);
590 if ( verbose & VERB_DEBUG )
591 cout << "DEBUG part_refine_orientation: view=" << *v << endl;
592
593 if ( em_ctf ) {
594 ctf_copy->update(em_ctf);
595 if ( apply_ctf && part->def > 1 ) ctf_copy->defocus_average(part->def);
596 }
597
598 if ( max_iter )
599 fom = img_refine_monte(p, pref, hi_res, lo_res, max_iter, fom_type,
600 weight, ctf_copy, def_std,
601 shift_std, view_std, max_angle, max_mag, kernel, number);
602 else
603 fom = img_refine_grid(p, pref, hi_res, lo_res, alpha_step, accuracy,
604 shift_step, shift_accuracy, max_mag,
605 fom_type, weight, ctf_copy, def_std, kernel, number);
606
607 if ( part->fom[0] < fom ) {
608 part->fom[0] = fom;
609 part->fom[1] = p->image->FOM();
610 part->sel = i;
611 if ( ctf_copy && apply_ctf ) bestdef = ctf_copy->defocus_average();
612 bestorigin = p->image->origin();
613 bestview = p->image->view();
614 bestmag = p->image->magnification();
615 }
616
617 }
618
619 if ( ctf_copy ) delete ctf_copy;
620
621 if ( apply_ctf ) {
622 if ( bestdef > 1 ) part->def = bestdef;
623 part->dev = em_ctf->defocus_deviation();
624 part->ast = em_ctf->astigmatism_angle();
625 }
626 part->ori[0] = bestorigin[0]/scale[0];
627 part->ori[1] = bestorigin[1]/scale[1];
628 part->ori[2] = bestorigin[2]/scale[2];
629 part->view = bestview;
630 part->mag = bestmag;
631
632 kill_list((char *) view, sizeof(View));
633 delete p;
634
635 if ( flags & WRITE_PPX ) {
636 Bstring ppx_name = ppx_filename(part->mg->id, part->id);
637 write_particle(ppx_name, part, 0, 0, fom_tag);
638 ppx_name = 0;
639 }
640
641 return number;
642 }
643
644 /*
645 FRC:
646 sum((FoFc*)re)
647 -------------------------
648 sqrt(sum(Fc^2)*sum(Fo^2))
649 DPR:
650 (sum((|Fo|+|Fc|)*dPhi^2))
651 sqrt|-----------------------|
652 ( sum(|Fo|+|Fc|) )
653 */
654 double img_recip_space_fom(Bimage* p, Bimage* pref, double hi_res, double lo_res,
655 int fom_type, vector<double>& weight, int apply_ctf, CTFparam* em_ctf)
656 {
657 if ( pref->sampling()[0] < 0.01 ) pref->sampling(1,1,1);
658 if ( lo_res > 0 && hi_res > lo_res ) swap(hi_res, lo_res);
659 if ( hi_res < 2*pref->sampling()[0] ) hi_res = 2*pref->sampling()[0];
660
661 double max_rad = pref->real_size()[0]/hi_res;
662 double max_rad_cv = 1.1*max_rad;
663 if ( max_rad_cv <= max_rad ) max_rad_cv = max_rad + 1;
664
665 double max_rad_sq = max_rad*max_rad;
666 double max_rad_cv_sq = max_rad_cv*max_rad_cv;
667 double min_rad_sq(0);
668 if ( lo_res > 0 ) {
669 min_rad_sq = pref->real_size()[0]/lo_res;
670 min_rad_sq *= min_rad_sq;
671 }
672
673 if ( verbose & VERB_DEBUG )
674 cout << "DEBUG img_recip_space_fom: max_rad=" << max_rad << " (" << max_rad_sq << ")" << endl;
675
676 double dphi, ctf_fac;
677 if ( !em_ctf ) apply_ctf = 0;
678 else if ( em_ctf->defocus_average() < 1 ) apply_ctf = 0;
679
680 long i, j, xx, yy;
681 long hx = (p->sizeX() - 1)/2, hy = (p->sizeY() - 1)/2;
682 double sx2, sy2, s2, d2, amp, denom, f, cv, wsum;
683 Vector3<double> m, d, iv;
684 Vector3<double> freq_scale(1.0/p->real_size()[0], 1.0/p->real_size()[1], 1.0);
685
686 double* w = new double[p->sizeX()];
687 for ( j=0; j<p->sizeX(); j++ ) w[j] = 1;
688 if ( weight.size() )
689 for ( size_t j=0; j<weight.size(); j++ ) if ( weight[j] ) w[j] = weight[j];
690
691 double* fom = new double[p->sizeX()];
692 double* dsum = new double[p->sizeX()];
693 double* msum = new double[p->sizeX()];
694 for ( i=0; i<p->sizeX(); i++ ) fom[i] = dsum[i] = msum[i] = 0;
695
696 Complex<float>* data = (Complex<float> *) p->data_pointer();
697 Complex<float>* refdata = (Complex<float> *) pref->data_pointer();
698 Complex<float> dtemp;
699
700 for ( yy=i=0; yy<p->sizeY(); yy++ ) {
701 iv[1] = yy;
702 if ( iv[1] > hy ) iv[1] -= p->sizeY();
703 sy2 = freq_scale[1]*iv[1];
704 sy2 *= sy2;
705 for ( xx=0; xx<p->sizeX(); xx++, i++ ) {
706 iv[0] = xx;
707 if ( iv[0] > hx ) iv[0] -= p->sizeX();
708 sx2 = freq_scale[0]*iv[0];
709 sx2 *= sx2;
710 d2 = iv.length2();
711 if ( d2 >= min_rad_sq && d2 <= max_rad_cv_sq ) {
712 s2 = sx2 + sy2;
713 j = (long) sqrt(d2);
714 dtemp = refdata[i];
715 if ( apply_ctf ) {
716 ctf_fac = em_ctf->calculate(s2, atan2(iv[1],iv[0]));
717 dtemp *= -ctf_fac;
718 }
719 if ( fom_type < 1 ) {
720 fom[j] += data[i].real()*dtemp.real() + data[i].imag()*dtemp.imag();
721 msum[j] += dtemp.power();
722 dsum[j] += data[i].power();
723 } else {
724 amp = data[i].amp() + dtemp.amp();
725 dphi = angle_set_negPI_to_PI(data[i].phi() - dtemp.phi());
726 fom[j] += amp*dphi*dphi;
727 msum[j] += amp;
728 }
729 }
730 }
731 }
732
733 if ( fom_type < 1 ) {
734 for ( f=wsum=0, j=0; j<max_rad; j++ ) {
735 wsum += w[j];
736 denom = dsum[j]*msum[j];
737 if ( denom > 0 ) f += w[j]*fom[j]/sqrt(denom);
738 }
739 f /= wsum;
740 for ( cv=wsum=0, j=(long)max_rad; j<max_rad_cv; j++ ) {
741 wsum += w[j];
742 denom = dsum[j]*msum[j];
743 if ( denom > 0 ) cv += w[j]*fom[j]/sqrt(denom);
744 }
745 cv /= wsum;
746 } else {
747 for ( f=wsum=0, j=0; j<max_rad; j++ ) {
748 wsum += w[j];
749 if ( msum[j] ) f += w[j]*cos(sqrt(fom[j]/msum[j]));
750 }
751 f /= wsum;
752 for ( cv=wsum=0, j=(long)max_rad; j<max_rad_cv; j++ ) {
753 wsum += w[j];
754 if ( msum[j] ) cv += w[j]*cos(sqrt(fom[j]/msum[j]));
755 }
756 cv /= wsum;
757 }
758
759 delete[] fom;
760 delete[] dsum;
761 delete[] msum;
762 delete[] w;
763
764 p->image->FOM(cv);
765
766 return f;
767 }
768
769 double img_fit_in_recip_space_monte(Bimage* p, Bimage* pref, double hi_res, double lo_res,
770 int max_iter, int fom_type, vector<double>& weight, CTFparam* em_ctf, double def_std, double shift_std,
771 FSI_Kernel* kernel, long &number)
772 {
773 // Defocus may be changed in this function
774 int apply_ctf(0);
775 double predef(0), bestdef(0);
776 if ( def_std && em_ctf && em_ctf->defocus_average() ) {
777 predef = bestdef = em_ctf->defocus_average();
778 apply_ctf = 1;
779 }
780
781 // double scale = pref->sampling()[0]/p->sampling()[0];
782 // Vector3<double> vscale(pref->sizeX()/(scale*p->sizeX()), pref->sizeY()/(scale*p->sizeX()), pref->sizeZ()/(scale*p->sizeX()));
783
784 View view(p->image->view());
785 Matrix3 mat = view.matrix();
786 // mat = vscale * mat;
787 mat = mat * p->image->magnification();
788 // cout << mat << endl;
789
790 if ( verbose & VERB_DEBUG )
791 cout << "DEBUG img_fit_in_recip_space_monte: view=" << view << endl;
792
793 Bimage* pcs = pref->central_section(mat, hi_res/1.11, kernel);
794
795 long iter;
796 double fom, prefom(-1), bestfom(-1), bestcv(0);
797 double irm = 1.0/get_rand_max();
798 Vector3<double> origin(p->image->origin());
799 Vector3<double> r, preorigin = origin, bestorigin = origin;
800
801 Bimage* pcopy;
802
803 for ( iter = 0; iter<max_iter; iter++ ) {
804 if ( verbose & VERB_DEBUG )
805 cout << "DEBUG img_fit_in_recip_space_monte: iter=" << iter << endl;
806 if ( iter > 0 ) {
807 if ( apply_ctf ) em_ctf->defocus_average(em_ctf->defocus_average() + random_gaussian(0, def_std));
808 r = vector3_xy_random_gaussian(0, shift_std);
809 origin += r;
810 }
811
812 pcopy = p->copy();
813 pcopy->origin(origin);
814 pcopy->phase_shift_to_origin();
815
816 fom = img_recip_space_fom(pcopy, pcs, hi_res, lo_res, fom_type, weight, apply_ctf, em_ctf);
817 number++;
818
819 if ( bestfom < fom ) {
820 bestfom = fom;
821 if ( apply_ctf ) bestdef = em_ctf->defocus_average();
822 bestorigin = origin;
823 bestcv = pcopy->image->FOM();
824 if ( verbose & VERB_FULL )
825 cout << iter << tab << fom << tab << bestcv << endl;
826 }
827
828 if ( fom/prefom > random()*irm ) {
829 if ( apply_ctf ) predef = em_ctf->defocus_average();
830 preorigin = origin;
831 prefom = fom;
832 } else {
833 if ( apply_ctf ) em_ctf->defocus_average(predef);
834 origin = preorigin;
835 fom = prefom;
836 }
837 delete pcopy;
838 }
839
840 p->origin(bestorigin);
841 p->image->FOM(bestcv);
842 if ( apply_ctf ) em_ctf->defocus_average(bestdef);
843
844 delete pcs;
845
846 return bestfom;
847 }
848
849 double img_fit_in_recip_space_grid(Bimage* p, Bimage* pref, double hi_res, double lo_res,
850 double step, double accuracy, int fom_type, vector<double>& weight, CTFparam* em_ctf, double def_std, FSI_Kernel* kernel, long &number)
851 {
852 // Defocus may be changed in this function
853 int apply_ctf(0);
854 double bestdef(0);
855 if ( def_std && em_ctf && em_ctf->defocus_average() ) {
856 bestdef = em_ctf->defocus_average();
857 apply_ctf = 1;
858 }
859
860 // double scale = pref->sampling()[0]/p->sampling()[0];
861 // Vector3<double> vscale(pref->sizeX()/(scale*p->sizeX()), pref->sizeY()/(scale*p->sizeX()), pref->sizeZ()/(scale*p->sizeX()));
862
863 View view(p->image->view());
864 Matrix3 mat = view.matrix();
865 // mat = vscale * mat;
866 mat = mat * p->image->magnification();
867 // cout << mat << endl;
868
869 if ( verbose & VERB_DEBUG )
870 cout << "DEBUG img_fit_in_recip_space_grid: view=" << view << endl;
871
872 Bimage* pcs = pref->central_section(mat, hi_res/1.11, kernel);
873
874 int i, ibest;
875 double x, y, fom, prevfom, bestfom(-1);
876 double def, def_start, def_end, bestcv(0);
877 Vector3<double> bestorigin(p->image->origin());
878 Bimage* pcopy;
879
880 if ( apply_ctf ) {
881 pcopy = p->copy();
882 pcopy->phase_shift_to_origin();
883 def_start = bestdef - 5*def_std;
884 def_end = bestdef + 5*def_std;
885 for ( def = def_start; def <= def_end; def += def_std ) {
886 em_ctf->defocus_average(def);
887 fom = img_recip_space_fom(pcopy, pcs, hi_res, lo_res, fom_type, weight, apply_ctf, em_ctf);
888 number++;
889 if ( bestfom < fom ) {
890 bestfom = fom;
891 bestdef = def;
892 bestcv = pcopy->image->FOM();
893 if ( verbose & VERB_FULL )
894 cout << def << tab << fom << tab << bestcv << endl;
895 }
896 }
897 delete pcopy;
898 em_ctf->defocus_average(bestdef);
899 }
900
901 while ( step >= accuracy ) {
902 prevfom = bestfom;
903 bestfom = -1;
904 for ( i=ibest=0, y = p->image->origin()[1] - step; y <= p->image->origin()[1] + step; y += step ) {
905 for ( x = p->image->origin()[0] - step; x <= p->image->origin()[0] + step; x += step, i++ ) {
906 pcopy = p->copy();
907 pcopy->image->origin(x, y, 0);
908 pcopy->phase_shift_to_origin();
909
910 fom = img_recip_space_fom(pcopy, pcs, hi_res, lo_res, fom_type, weight, apply_ctf, em_ctf);
911
912 number++;
913
914 if ( bestfom < fom ) {
915 bestfom = fom;
916 ibest = i;
917 bestorigin = Vector3<double>(x, y, 0);
918 bestcv = pcopy->image->FOM();
919 if ( verbose & VERB_FULL )
920 cout << x << tab << y << tab << fom << tab << bestcv << endl;
921 }
922
923 delete pcopy;
924 }
925 }
926 if ( ibest == i/2 || fabs(prevfom - bestfom) < 1e-6 ) step /= 2; // Contract around best case
927 }
928
929 p->origin(bestorigin);
930 p->image->FOM(bestcv);
931
932 delete pcs;
933
934 return bestfom;
935 }
936
963 double img_refine_monte(Bimage* p, Bimage* pref, double hi_res, double lo_res,
964 int max_iter, int fom_type, vector<double>& weight, CTFparam* em_ctf,
965 double def_std, double shift_std, double view_std,
966 double max_angle, double max_mag, FSI_Kernel* kernel, long &number)
967 {
968 int apply_ctf(0);
969 double def, predef(0), bestdef(0);
970 if ( def_std && em_ctf && em_ctf->defocus_average() ) {
971 def = predef = bestdef = em_ctf->defocus_average();
972 apply_ctf = 1;
973 }
974
975 long iter;
976 double fom, prefom(-1), bestfom(-1), bestcv(0);
977 double a, irm(1.0/get_rand_max());
978 double mag = p->image->magnification();
979 double bestmag(mag), premag(mag);
980 Vector3<double> origin(p->image->origin());
981 Vector3<double> r, bestorigin = origin;
982 View view(p->image->view());
983 View bestview = view, preview = view;
984
985 for ( iter = 0; iter<max_iter; iter++ ) {
986 if ( verbose & VERB_DEBUG )
987 cout << "DEBUG img_refine_monte: iter=" << iter << endl;
988 if ( iter > 0 ) {
989 r = vector3_random_gaussian(0, view_std);
990 a = max_angle*(random()*irm*2 - 1);
991 view[0] += r[0];
992 view[1] += r[1];
993 view[2] += r[2];
994 view[3] += a;
995 view.normalize();
996 if ( max_mag > 0 ) mag += max_mag*(random()*irm*2 - 1);
997 }
998 p->view(view);
999 p->image->magnification(mag);
1000 if ( apply_ctf ) em_ctf->defocus_average(def); // Resets defocus to original
1001 p->origin(origin); // Resets origin to original
1002 fom = img_fit_in_recip_space_monte(p, pref, hi_res, lo_res, max_iter, fom_type, weight, em_ctf,
1003 def_std, shift_std, kernel, number);
1004 if ( bestfom < fom ) {
1005 bestfom = fom;
1006 bestview = view;
1007 bestmag = mag;
1008 bestorigin = p->image->origin();
1009 if ( apply_ctf ) bestdef = em_ctf->defocus_average();
1010 bestcv = p->image->FOM();
1011 if ( verbose & VERB_FULL )
1012 cout << iter << tab << fom << endl;
1013 }
1014 if ( fom/prefom > random()*irm ) {
1015 preview = view;
1016 premag = mag;
1017 prefom = fom;
1018 } else {
1019 view = preview;
1020 mag = premag;
1021 fom = prefom;
1022 }
1023 }
1024
1025 p->view(bestview);
1026 p->image->origin(bestorigin);
1027 p->image->magnification(bestmag);
1028 p->image->FOM(bestcv);
1029 if ( apply_ctf ) em_ctf->defocus_average(bestdef);
1030
1031 return bestfom;
1032 }
1033
1060 double img_refine_grid(Bimage* p, Bimage* pref, double hi_res, double lo_res,
1061 double alpha_step, double accuracy, double shift_step,
1062 double shift_accuracy, double max_mag, int fom_type, vector<double>& weight,
1063 CTFparam* em_ctf, double def_std, FSI_Kernel* kernel, long &number)
1064 {
1065 if ( alpha_step < SMALLFLOAT || accuracy < SMALLFLOAT ) {
1066 if ( alpha_step < SMALLFLOAT )
1067 cerr << "Error: The angular step size is too small! (" << alpha_step*180.0/M_PI << ")" << endl;
1068 if ( accuracy < SMALLFLOAT )
1069 cerr << "Error: The accuracy is too small! (" << accuracy*180.0/M_PI << ")" << endl;
1070 return -1;
1071 }
1072
1073 if ( alpha_step < accuracy ) {
1074 cerr << "Error: The angular step size is smaller than the accuracy! (" << alpha_step*180.0/M_PI << " < " << accuracy*180.0/M_PI << ")" << endl;
1075 return -1;
1076 }
1077
1078 int apply_ctf(0);
1079 double def, bestdef(0);
1080 if ( def_std && em_ctf && em_ctf->defocus_average() ) {
1081 def = bestdef = em_ctf->defocus_average();
1082 apply_ctf = 1;
1083 }
1084
1085 int i, ibest;
1086 double fom, prefom, bestfom(-1), bestcv(0);
1087 double mag = p->image->magnification(), bestmag = mag;
1088 Vector3<double> ori(p->image->origin());
1089 Vector3<double> bestorigin = ori;
1090 View view(p->image->view());
1091 View bestview = view;
1092 View *views, *v;
1093
1094 while ( alpha_step >= accuracy ) {
1095 prefom = bestfom;
1096 bestfom = -1;
1097 views = views_for_refinement(bestview, alpha_step);
1098 for ( i=ibest=0, v = views; v; v = v->next, i++ ) {
1099 p->view(*v);
1100 if ( apply_ctf ) em_ctf->defocus_average(def); // Resets defocus to original
1101 p->origin(ori); // Resets origin to original
1102 p->image->magnification(mag); // Resets magnification to original
1103 if ( verbose & VERB_DEBUG )
1104 cout << "DEBUG img_refine_grid: view=" << *v << endl;
1105 fom = img_fit_in_recip_space_grid(p, pref, hi_res, lo_res, shift_step, shift_accuracy, fom_type, weight, em_ctf, def_std, kernel, number);
1106 if ( bestfom < fom ) {
1107 bestfom = fom;
1108 ibest = i;
1109 bestview = *v;
1110 bestorigin = p->image->origin();
1111 if ( apply_ctf ) bestdef = em_ctf->defocus_average();
1112 bestcv = p->image->FOM();
1113 }
1114 }
1115 kill_list((char *) views, sizeof(View));
1116 if ( verbose & VERB_FULL )
1117 cout << alpha_step << tab << bestfom << tab << bestcv << endl;
1118 if ( ibest == i/2 || fabs(prefom - bestfom) < 1e-6 ) alpha_step /= 2; // Contract around best case
1119 }
1120
1121 p->view(bestview);
1122 p->origin(bestorigin);
1123 if ( apply_ctf ) em_ctf->defocus_average(bestdef);
1124
1125 if ( max_mag > 0 ) {
1126 prefom = bestfom;
1127 bestfom = -1;
1128 for ( mag = 1-max_mag; mag <= 1+max_mag; mag += 0.001 ) {
1129 p->image->magnification(mag);
1130 if ( verbose & VERB_DEBUG )
1131 cout << "DEBUG img_refine_grid: mag=" << mag << endl;
1132 fom = img_fit_in_recip_space_grid(p, pref, hi_res, lo_res, 0.4, 0.1, fom_type, weight, em_ctf, def_std, kernel, number);
1133 if ( bestfom < fom ) {
1134 bestfom = fom;
1135 bestmag = mag;
1136 bestorigin = p->image->origin();
1137 if ( apply_ctf ) bestdef = em_ctf->defocus_average();
1138 bestcv = p->image->FOM();
1139 if ( verbose & VERB_FULL )
1140 cout << mag << tab << fom << tab << bestcv << endl;
1141 }
1142 }
1143 }
1144
1145 p->view(bestview);
1146 p->origin(bestorigin);
1147 p->image->magnification(bestmag);
1148 p->image->FOM(bestcv);
1149 if ( apply_ctf ) em_ctf->defocus_average(bestdef);
1150
1151 return bestfom;
1152 }
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bparticle::id
int id
Definition: mg_processing.h:92
rwmg.h
Header file for reading and writing micrograph parameters.
Bparticle::ast
double ast
Definition: mg_processing.h:97
Bparticle::mag
double mag
Definition: mg_processing.h:94
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
Vector3::normalize
double normalize()
Definition: Vector3.h:236
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:143
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
vector3_xy_random_gaussian
Vector3< double > vector3_xy_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length in the xy plane.
Definition: random_numbers.cpp:522
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
View::next
View * next
Definition: View.h:28
vector3_random_gaussian
Vector3< double > vector3_random_gaussian(double avg, double std)
Generates a random vector within a random gaussian-distributed length.
Definition: random_numbers.cpp:502
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
views_for_refinement
View * views_for_refinement(View theview, double alpha_step)
Generates a 3x3 grid of views around an input view.
Definition: View.cpp:285
project_mg_particle_array
Bparticle ** project_mg_particle_array(Bproject *project, int part_select, long &npart)
Sets up an array of selected particle pointers.
Definition: mg_processing.cpp:2029
img_refine_monte
double img_refine_monte(Bimage *p, Bimage *pref, double hi_res, double lo_res, int max_iter, int fom_type, vector< double > &weight, CTFparam *em_ctf, double def_std, double shift_std, double view_std, double max_angle, double max_mag, FSI_Kernel *kernel, long &number)
Refine the orientation and origin of one particle with respect to a reference map.
Definition: mg_refine.cpp:963
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:45
Bimage::fft
int fft()
Definition: Bimage.h:822
utilities.h
Header file for general utilities.
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
planf
fft_plan planf
Definition: bico.cpp:24
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
CTFparam::update
int update(CTFparam *ctf)
Definition: ctf.h:77
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:319
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
Complex.h
Class for complex numbers.
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
Matrix3
Definition: Matrix3.h:17
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
project
Bproject * project
Definition: bshow.cpp:31
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
part_refine_orientation
long part_refine_orientation(Bparticle *part, Bstring &partfile, double pixel_size, Bimage *pref, Bimage *pmask, Bsymmetry *sym, int max_iter, double alpha_step, double accuracy, double shift_step, double shift_accuracy, double hi_res, double lo_res, int fom_type, vector< double > weight, double edge_radius, CTFparam *em_ctf, double def_std, double shift_std, double view_std, double max_angle, double max_mag, int flags, FSI_Kernel *kernel, fft_plan planf)
Refine the orientation and origin of one particle with respect to a reference map.
Definition: mg_refine.cpp:492
FSI_Kernel
Definition: FSI_Kernel.h:14
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:432
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:312
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
CHECK_PPX
#define CHECK_PPX
Definition: mg_processing.h:27
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
ppx_filename
Bstring ppx_filename(Bstring &mg_id, int part_id)
Definition: rwmg.cpp:412
Bfield::next
Bfield * next
Definition: mg_processing.h:258
img_refine_grid
double img_refine_grid(Bimage *p, Bimage *pref, double hi_res, double lo_res, double alpha_step, double accuracy, double shift_step, double shift_accuracy, double max_mag, int fom_type, vector< double > &weight, CTFparam *em_ctf, double def_std, FSI_Kernel *kernel, long &number)
Refine the orientation and origin of one particle with respect to a reference map.
Definition: mg_refine.cpp:1060
Matrix3.h
3x3 Matrix manipulation functions
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
TSimple
Definition: Bimage.h:58
Float
Definition: utilities.h:157
FOM_CV
Definition: mg_processing.h:42
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:487
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
random_gaussian
double random_gaussian(double avg, double std)
Generates a value with a gaussian random distribution.
Definition: random_numbers.cpp:123
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:104
Bimage::shift
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
Definition: Bimage_transform.cpp:587
img_fit_in_recip_space_monte
double img_fit_in_recip_space_monte(Bimage *p, Bimage *pref, double hi_res, double lo_res, int max_iter, int fom_type, vector< double > &weight, CTFparam *em_ctf, double def_std, double shift_std, FSI_Kernel *kernel, long &number)
Definition: mg_refine.cpp:769
NFOM
#define NFOM
Definition: mg_processing.h:16
mg_refine_orientations
long mg_refine_orientations(Bproject *project, Bstring &reffile, Bstring &maskfile, Bstring &sym_string, int part_select, int max_iter, double alpha_step, double accuracy, double shift_step, double shift_accuracy, int fom_type, vector< double > weight, double hi_res, double lo_res, int kernel_width, int kernel_power, double edge_radius, double def_std, double shift_std, double view_std, double max_angle, double max_mag, int flags)
Refine the orientation and origin with respect to a reference map.
Definition: mg_refine.cpp:77
ppx_check
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:418
write_particle
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:403
Bproject::field
Bfield * field
Definition: mg_processing.h:343
fft_plan
fftwf_plan fft_plan
Definition: fft.h:16
Bsub_image::FOM
double FOM()
Definition: Bimage.h:151
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
CTFparam::calculate
double calculate(double s2, double angle)
Definition: ctf.h:149
Complex::amp
double amp()
Definition: Complex.h:104
Bimage::phase_shift_to_origin
int phase_shift_to_origin()
Phase shifts a set of reflections to the image origin.
Definition: Bimage_complex.cpp:327
Bmicrograph
Definition: mg_processing.h:200
irm
double irm(1.0L/get_rand_max())
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
img_fit_in_recip_space_grid
double img_fit_in_recip_space_grid(Bimage *p, Bimage *pref, double hi_res, double lo_res, double step, double accuracy, int fom_type, vector< double > &weight, CTFparam *em_ctf, double def_std, FSI_Kernel *kernel, long &number)
Definition: mg_refine.cpp:849
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Vector3::length2
double length2()
Definition: Vector3.h:221
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
C_curve
vector< double > C_curve(long n, double freq_step)
Calculates the carbon scattering curve.
Definition: ctf.cpp:462
Bimage::view
void view(double vx, double vy, double vz, double va)
Definition: Bimage.h:589
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
Bsymmetry
Definition: symmetry.h:38
FOM
Definition: mg_processing.h:40
Bparticle::dev
double dev
Definition: mg_processing.h:96
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:105
Complex
Definition: Complex.h:23
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
Bparticle
Definition: mg_processing.h:89
random_numbers.h
Header file for functions for creating random images.
Bimage::central_section
Bimage * central_section(Matrix3 mat, double resolution, FSI_Kernel *kernel)
Calculates a central section of a 3D fourier transform.
Definition: Bimage_project.cpp:287
Bstring
Definition: Bstring.h:29
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2695
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
mg_refine.h
Reciprocal space refinement of orientation parameters of particle images.
FOMType
FOMType
Definition: mg_processing.h:38
img_recip_space_fom
double img_recip_space_fom(Bimage *p, Bimage *pref, double hi_res, double lo_res, int fom_type, vector< double > &weight, int apply_ctf, CTFparam *em_ctf)
Definition: mg_refine.cpp:654
Complex::phi
double phi()
Definition: Complex.h:105
Vector3< long >
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
Complex::imag
Type imag()
Definition: Complex.h:102
View::angle
double angle()
Definition: View.h:95
View
Definition: View.h:26
Bsub_image::magnification
double magnification()
Definition: Bimage.h:149
fft_setup_plan
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
Definition: fft.cpp:31
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:100
Bparticle::def
double def
Definition: mg_processing.h:95
mg_processing.h
Header file for micrograph processing.
rwimg.h
Header file for 2D and 3D image I/O.
Complex::power
double power()
Definition: Complex.h:103
Complex::real
Type real()
Definition: Complex.h:101
kernel
Definition: kernlut.h:13
project_refine_orientations
long project_refine_orientations(Bproject *project, Bstring &reffile, Bstring &maskfile, Bstring &sym_string, int part_select, int max_iter, double alpha_step, double accuracy, double shift_step, double shift_accuracy, int fom_type, vector< double > weight, double hi_res, double lo_res, int kernel_width, int kernel_power, double edge_radius, double def_std, double shift_std, double view_std, double max_angle, double max_mag, int flags)
Definition: mg_refine.cpp:251
verbose
int verbose
Bimage::change_transform_size
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
Definition: Bimage_fft.cpp:239
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:448
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:333
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
CTFparam
Definition: ctf.h:26
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201