| Bsoft 2.0.5 Bernard's software package

mg_ctf.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "mg_ctf.h"
11 #include "mg_ctf_fit.h"
12 #include "ps_plot.h"
13 #include "ps_ctf_plot.h"
14 #include "mg_processing.h"
15 #include "utilities.h"
16 #include "timer.h"
17
18 #include <sys/stat.h>
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
45 Bimage* img_ctf_calculate(CTFparam cp, int action, double wiener, Vector3<long> size,
46 Vector3<double> sam, double lores, double hires)
47 {
48 // if ( cp.check_defocus() || cp.check_Cs() )
49 // cerr << "in img_ctf_calculate" << endl;
50
51 if ( lores < 0 ) lores = 0;
52 if ( hires <= 0 ) hires = sam[0];
53 if ( lores > 0 && lores < hires ) swap(lores, hires);
54
55 double shi(1/hires);
56 double slo = (lores > 0)? 1/lores: 0;
57
58 Bimage* p = new Bimage(Float, TSimple, size, 1);
59 if ( sam.volume() > 0 ) p->sampling(sam);
60 // cout << p->sampling() << endl;
61
62 long i, x, y, z, sign;
63 double sx, sy, sz, s, s2, w, ctf_fac, base(0), env(0), ctf_env;
64 Vector3<double> freq_scale(1.0/p->real_size());
65 Vector3<double> h((p->size() - 1)/2);
66
67 Bstring base_eq = cp.baseline_equation();
68 Bstring env_eq = cp.envelope_equation();
69
70 if ( verbose & ( VERB_LABEL | VERB_PROCESS ) ) {
71 cout << "Calculating a CTF function:" << endl;
72 switch ( action ) {
73 case 1: cout << "Flipping phases" << endl; break;
74 case 2: cout << "Applying a CTF" << endl; break;
75 case 3: cout << "Correcting for the CTF" << endl; break;
76 case 4: cout << "Correcting for the CTF with an optimal Wiener filter" << endl; break;
77 case 5: cout << "Correcting for the CTF with baseline enhancement" << endl; break;
78 case 6: cout << "Correcting for the CTF with baseline2 enhancement" << endl; break;
79 case 7: cout << "Flipping phases with baseline enhancement" << endl; break;
80 case 8: cout << "Correcting for the CTF with baseline3 enhancement" << endl; break;
81 // case 9: cout << "Applying theoretical envelopes" << endl; break;
82 // case 10: cout << "Applying a CTF with theoretical envelopes" << endl; break;
83 default: break;
84 }
85 }
86 if ( verbose & VERB_PROCESS ) {
87 cp.show();
88 cout << "Resolution range: " << hires << " - ";
89 if ( lores > 0 ) cout << lores << " A" << endl;
90 else cout << "inf A" << endl;
91 if ( action == 3 || action == 5 || action == 6 )
92 cout << "Wiener factor: " << wiener << endl;
93 if ( action >= 4 ) {
94 cout << "Envelope: " << env_eq << endl;
95 cout << "Noise: " << base_eq << endl;
96 }
97 cout << endl;
98 }
99
100 for ( i=z=0; z<p->sizeZ(); z++ ) {
101 sz = z;
102 if ( z > h[2] ) sz -= p->sizeZ();
103 sz *= freq_scale[2];
104 for ( y=0; y<p->sizeY(); y++ ) {
105 sy = y;
106 if ( y > h[1] ) sy -= p->sizeY();
107 sy *= freq_scale[1];
108 for ( x=0; x<p->sizeX(); x++, i++ ) {
109 sx = x;
110 if ( x > h[0] ) sx -= p->sizeX();
111 sx *= freq_scale[0];
112 s2 = sx*sx + sy*sy + sz*sz;
113 s = sqrt(s2);
114 if ( s >= slo && s <= shi ) {
115 ctf_fac = cp.calculate(s2, atan2(sy,sx));
116 w = 0;
117 sign = ( ctf_fac < 0 )? -1: 1;
118 if ( action > 3 ) base = cp.calc_baseline(s);
119 switch ( action ) {
120 case 1: w = sign; break; // Flip the phase
121 case 2: w = ctf_fac; break; // Apply the CTF
122 case 3:
123 w = ctf_fac/(ctf_fac*ctf_fac + wiener);
124 break; // Spider method
125 case 4:
126 if ( base > 0 ) {
127 env = cp.calc_envelope(s);
128 ctf_env = ctf_fac*env;
129 w = ctf_fac*sqrt(env)/(ctf_fac*ctf_env + base);
130 }
131 break; // Wiener filter method
132 case 5:
133 w = ctf_fac/(ctf_fac*ctf_fac*base + wiener);
134 break; // Baseline enhancement
135 case 6:
136 w = 1/(ctf_fac*base + sign*wiener);
137 break; // Baseline enhancement
138 case 7:
139 if ( base > 0 ) w = sign/sqrt(base);
140 break; // Flip phase with baseline enhancement
141 case 8:
142 env = cp.calc_envelope(s);
143 w = sign/sqrt(ctf_fac*ctf_fac*env + base);
144 break; // Baseline enhancement
145 default: break;
146 }
147 p->set(i, w);
148 }
149 }
150 }
151 }
152
153 p->statistics();
154
155 return p;
156 }
157
175 Bimage* img_wave_aberration(CTFparam cp, Vector3<long> size, Vector3<double> sam)
176 {
177 Bimage* p = new Bimage(Float, TSimple, size, 1);
178 if ( sam.volume() > 0 ) p->sampling(sam);
179
180 long i, n, x, y, z;
181 double sx, sy, sz, s2;
182 Vector3<double> freq_scale(1.0/p->real_size());
183 Vector3<double> h((p->sizeX() - 1)/2, (p->sizeY() - 1)/2, (p->sizeZ() - 1)/2);
184
185 if ( verbose & VERB_PROCESS ) {
186 cout << "Calculating a wave aberration function:" << endl;
187 cout << "Defocus average & deviation: " << cp.defocus_average() << " A " << cp.defocus_deviation() << " A" << endl;
188 cout << "Astigmatism angle: " << cp.astigmatism_angle()*180/M_PI << " degrees" << endl;
189 cout << "Voltage: " << cp.volt() << " V" << endl;
190 cout << "Wavelength: " << cp.lambda() << " A" << endl;
191 cout << "Cs: " << cp.Cs() << " A" << endl;
192 cout << "Amplitude contrast: " << sin(cp.amp_shift()) << endl;
193 cout << endl;
194 }
195
196 for ( i=n=0; n<p->images(); n++ ) {
197 for ( z=0; z<p->sizeZ(); z++ ) {
198 sz = z;
199 if ( z > h[2] ) sz -= p->sizeZ();
200 sz *= freq_scale[2];
201 for ( y=0; y<p->sizeY(); y++ ) {
202 sy = y;
203 if ( y > h[1] ) sy -= p->sizeY();
204 sy *= freq_scale[1];
205 for ( x=0; x<p->sizeX(); x++, i++ ) {
206 sx = x;
207 if ( x > h[0] ) sx -= p->sizeX();
208 sx *= freq_scale[0];
209 s2 = sx*sx + sy*sy + sz*sz;
210 p->set(i, cp.delta_phi(s2, atan2(sy,sx)));
211 }
212 }
213 }
214 }
215
216 return p;
217 }
218
238 int img_ctf_apply(Bimage* p, CTFparam em_ctf, int action, double wiener,
239 double lores, double hires)
240 {
241 if ( action < 1 || action > 10 ) return 0;
242
243 if ( wiener < 0.01 ) wiener = 0.01;
244
245 Bimage* pctf = img_ctf_calculate(em_ctf, action, wiener, p->size(),
246 p->sampling(0), lores, hires);
247 pctf->invert();
248
249 // write_img("pctf.pif", pctf);
250
251 int back_transform(0);
252 if ( p->fourier_type() == NoTransform ) {
253 p->fft();
254 back_transform = 1;
255 }
256
257 // write_img("p.pif", p);
258
259 long i, j, nn;
260
261 for ( nn=j=0; nn<p->images(); nn++ )
262 for ( i=0; i<p->image_size(); i++, j++ )
263 p->set(j, p->complex(j) * (*pctf)[i]);
264
265 // write_img("pf.pif", p);
266
267 delete pctf;
268
269 if ( back_transform ) p->fft(FFTW_BACKWARD);
270
271 // p->statistics(); // fft includes statistics
272
273 return 0;
274 }
275
276 int img_ctf_apply(Bimage* p, CTFparam em_ctf, int action, double wiener,
277 double lores, double hires, fft_plan planf_2D, fft_plan planb_2D)
278 {
279 if ( action < 1 || action > 10 ) return 0;
280
281 if ( wiener < 0.01 ) wiener = 0.01;
282
283 Bimage* pctf = img_ctf_calculate(em_ctf, action, wiener, p->size(),
284 p->sampling(0), lores, hires);
285 pctf->invert();
286
287 int back_transform(0);
288 if ( p->fourier_type() == NoTransform ) {
289 p->fft(planf_2D, 1);
290 back_transform = 1;
291 if ( verbose & VERB_DEBUG )
292 cout << "DEBUG img_ctf_apply: image transformed" << endl;
293 }
294
295 long i, j, nn;
296
297 for ( nn=j=0; nn<p->images(); nn++ )
298 for ( i=0; i<p->image_size(); i++, j++ )
299 p->set(j, p->complex(j) * (*pctf)[i]);
300
301 delete pctf;
302
303 if ( back_transform ) {
304 p->fft(planb_2D, 1);
305 p->complex_to_real();
306 if ( verbose & VERB_DEBUG )
307 cout << "DEBUG img_ctf_apply: image back-transformed" << endl;
308 }
309
310 p->statistics();
311
312 return 0;
313 }
314
315 int img_ttf_apply_one(Bimage* p, long nn, CTFparam ctf, int action,
316 double wiener, double def, double res_lo, double res_hi,
317 Vector3<long> psize, fft_plan planf, fft_plan planb)
318 {
319 verbose = 1;
320
321 ctf.defocus_average(def);
322
323 Bimage* pt = p->extract(nn);
324
325 pt->calculate_background();
326
327 Vector3<long> oldsize(pt->size()), translate;
328
329 pt->pad(psize);
330
331 img_ctf_apply(pt, ctf, action, wiener, res_lo, res_hi, planf, planb);
332
333 pt->resize(oldsize, translate);
334
335 p->replace(nn, pt);
336
337 delete pt;
338
339 return 0;
340 }
341
354 int img_ctf_apply_to_proj(Bimage* proj, CTFparam em_ctf, double defocus, double res_lo, double res_hi, fft_plan planf_2D, fft_plan planb_2D)
355 {
356 if ( verbose & VERB_DEBUG )
357 cout << "DEBUG img_ctf_apply_to_proj: def_avg=" << em_ctf.defocus_average() << endl;
358
359 if ( defocus > 0 ) em_ctf.defocus_average(defocus);
360
361 img_ctf_apply(proj, em_ctf, 2, 0, res_lo, res_hi, planf_2D, planb_2D);
362
363 return 0;
364 }
365
388 int img_ttf_apply(Bimage* p, CTFparam ctf, int action, double wiener,
389 Vector3<long> tile_size, double tilt, double axis, double res_lo, double res_hi)
390 {
391 if ( res_lo > 0 && res_lo < res_hi ) swap(res_lo, res_hi);
392
393 // Minimum and maximum tile sizes allowed
394 long min_size(64);
395 long max_size(2048);
396 Vector3<long> start;
397 Vector3<long> ext_size;
398
399 tile_size = tile_size.min(p->size());
400
401 tile_size = tile_size.max(min_size);
402 tile_size = tile_size.min(max_size);
403
404 tile_size = tile_size.min(p->size());
405
406 p->change_type(Float);
407
408 // if ( verbose )
409 // cout << "Extracting tiles" << endl;
410 Bimage* pt = p->extract_tiles(0, tile_size, 0.5);
411
412 long nn;
413 double ca(cos(axis)), sa(sin(axis)), tt(tan(tilt));
414 Vector3<double> coor;
415 double* d = new double[pt->images()];
416
417 // cout << p->image->origin() << endl;
418 // if ( verbose )
419 // cout << "Tile\tx\ty\t∆f" << endl;
420 for ( nn=0; nn<pt->images(); nn++ ) {
421 coor = (pt->image[nn].origin() + pt->size()/2 - p->image->origin()) * p->sampling(); // Center coordinates
422 d[nn] = ctf.defocus_average() + (coor[0]*sa - coor[1]*ca)*tt;
423 // if ( verbose )
424 // cout << nn << tab << coor[0] << tab << coor[1] << tab << d[nn]-ctf.defocus_average() << endl;
425 }
426 // if ( verbose & VERB_FULL )
427 // cout << ctf.defocus_average() << tab << d[0] << endl;
428 // bexit(0);
429
430 Bstring base_eq = ctf.baseline_equation();
431 Bstring env_eq = ctf.envelope_equation();
432
433 if ( verbose & ( VERB_LABEL | VERB_PROCESS ) ) {
434 cout << "Applying a tilted image transfer function:" << endl;
435 switch ( action ) {
436 case 1: cout << "Flipping phases" << endl; break;
437 case 2: cout << "Applying a CTF" << endl; break;
438 case 3: cout << "Correcting for the CTF" << endl; break;
439 case 4: cout << "Correcting for the CTF with an optimal Wiener filter" << endl; break;
440 case 5: cout << "Correcting for the CTF with baseline enhancement" << endl; break;
441 case 6: cout << "Correcting for the CTF with baseline2 enhancement" << endl; break;
442 case 7: cout << "Flipping phases with baseline enhancement" << endl; break;
443 case 8: cout << "Correcting for the CTF with baseline3 enhancement" << endl; break;
444 default: break;
445 }
446 }
447 if ( verbose & VERB_PROCESS ) {
448 cout << "Tile size: " << tile_size << endl;
449 cout << "Defocus range: " << d[0] << " - " << d[nn-1] << " (" << nn << ")" << endl;
450 cout << "Tilt angle and axis: " << tilt*180.0/M_PI << " " << axis*180.0/M_PI << endl;
451 ctf.show();
452 cout << "Resolution range: " << res_hi << " - ";
453 if ( res_lo > 0 ) cout << res_lo << " A" << endl;
454 else cout << "inf A" << endl;
455 if ( action == 3 || action == 5 || action == 6 )
456 cout << "Wiener factor: " << wiener << endl;
457 if ( action >= 4 ) {
458 cout << "Envelope: " << env_eq << endl;
459 cout << "Noise: " << base_eq << endl;
460 }
461 cout << endl;
462 }
463
464 long pad_factor(2);
465 long ft_size = findNextPowerOf((int)(pad_factor*pt->sizeX()), 2);
466 Vector3<long> psize(ft_size, ft_size, 1);
467
468 fft_plan planf = fft_setup_plan(psize, FFTW_FORWARD, 1);
469 fft_plan planb = fft_setup_plan(psize, FFTW_BACKWARD, 1);
470
471 #ifdef HAVE_GCD
472 dispatch_apply(pt->images(), dispatch_get_global_queue(0, 0), ^(size_t i){
473 img_ttf_apply_one(pt, i, ctf, action, wiener, d[i], res_lo, res_hi, psize, planf, planb);
474 });
475 #else
476 #pragma omp parallel for
477 for ( long i=0; i<pt->images(); i++ )
478 img_ttf_apply_one(pt, i, ctf, action, wiener, d[i], res_lo, res_hi, psize, planf, planb);
479 #endif
480
481 fft_destroy_plan(planf);
482 fft_destroy_plan(planb);
483
484 p->assemble_tiles(pt, 1);
485
486 delete pt;
487 delete[] d;
488
489 return 0;
490 }
491
492
493 int mg_ps_name(Bmicrograph* mg, int img_num, Bstring& path, Bstring& newname, Bstring insert)
494 {
495 Bstring fn, ext;
496
497 mg->fps = newname;
498
499 if ( mg->fps.length() < 3 ) {
500 if ( img_num >= 0 ) insert = Bstring(img_num, "_%03d") + insert;
501 fn = mg->fmg;
502 if ( fn.length() < 1 ) fn = mg->fframe;
503 if ( fn.length() < 1 ) fn = mg->fpart;
504 if ( fn.length() ) {
505 ext = fn.extension();
506 if ( ( ext == "tif" ) || ( ext == "jpg" ) || ( ext == "jpeg" )
507 || ( ext == "png" ) || ext.contains("dm") )
508 ext = "mrc";
509 mg->fps = fn.pre_rev('.') + insert + ext;
510 } else {
511 mg->fps = "ps" + insert + ext;
512 }
513 }
514
515 if ( path.length() > 1 )
516 mg->fps = path + mg->fps.post_rev('/');
517
518 return 0;
519 }
520
521
522 Bimage* mg_ctf_prepare(Bmicrograph* mg, int action, double lores, double hires,
523 Vector3<long> tile_size, double def_start, double def_end, double def_inc, int flags)
524 {
525 int img_type(0), img_num(-1);
526 int ps_flags(7);
527 double pixel_size(mg->pixel_size);
528
529 if ( !mg->ctf ) mg->ctf = new CTFparam;
530
531 Bstring filename, insert, ext;
532 if ( action == 12 && mg->fps.length() ) {
533 filename = mg->fps;
534 img_type = 3;
535 img_num = mg->img_num;
536 if ( verbose & VERB_PROCESS )
537 cout << "Processing power spectrum " << mg->fps << " (" << img_num << ")" << endl;
538 } else if ( flags & 1 ) {
539 if ( mg->fframe.length() && ( flags & 16 ) ) {
540 filename = mg->fframe;
541 ps_flags |= 16;
542 } else {
543 filename = mg->fmg;
544 img_num = mg->img_num;
545 }
546 img_type = 1;
547 if ( verbose & VERB_PROCESS )
548 cout << "Processing micrograph " << filename << " (" << img_num << ")" << endl;
549 } else if ( mg->fpart.length() ) {
550 filename = mg->fpart;
551 img_type = 2;
552 if ( mg->part->pixel_size > 0 ) pixel_size = mg->part->pixel_size;
553 if ( verbose & VERB_PROCESS )
554 cout << "Processing particles " << filename << endl;
555 } else if ( mg->part && mg->part->fpart.length() ) {
556 img_type = 4;
557 if ( verbose & VERB_PROCESS )
558 cout << "Processing particles from micrograph " << mg->id << endl;
559 }
560
561 if ( img_type < 4 && !filename.length() ) {
562 if ( verbose & VERB_FULL )
563 cerr << "Warning: no file specified for micrograph " << mg->id << endl;
564 mg->select = 0;
565 return NULL;
566 }
567
568 if ( verbose && filename.length() )
569 cout << "Processing file " << filename << " (" << img_num << ")" << endl;
570
571 if ( action == 11 || action == 13 ) insert = "_ps.";
572 else insert = "_ctf.";
573
574 Bimage* p = NULL;
575 if ( filename.length() ) {
576 p = read_img(filename, 1, img_num);
577 if ( !p ) {
578 cerr << "Warning: File " << filename << " not found or read!" << endl;
579 mg->select = 0;
580 return NULL;
581 }
582 p->sampling(pixel_size, pixel_size, 1);
583 p->change_type(Float);
584 if ( ( flags & 16 ) && p->sizeZ() > 1 ) p->slices_to_images();
585 }
586
587 if ( !p ) return NULL;
588
589 Bimage* ps = NULL;
590
591 if ( flags & 2 )
592 p->filter_extremes();
593
594 // cout << "volt=" << mg->ctf->volt() << " Cs=" << mg->ctf->Cs() << endl;
595 // cout << "p sampling = " << p->image->sampling() << endl;
596
597 if ( action == 11 || action == 13 ) {
598 double lamda(electron_wavelength(mg->ctf->volt()));
599 double iCL2(1.0/(mg->ctf->Cs()*lamda*lamda));
600 ps = p->powerspectrum_tiled_and_tilted(tile_size, mg->tilt_axis,
601 mg->tilt_angle, 0, mg->ctf->defocus_average(), iCL2, ps_flags);
602 // ps = p->powerspectrum_tiled(0, tile_size, ps_flags);
603 delete p;
604 p = ps;
605 }
606
607 // cout << "ps sampling = " << ps->image->sampling() << endl;
608
609 if ( action == 12 || action == 13 )
610 mg->fom = img_ctf_fit(p, 0, *mg->ctf, lores, hires, def_start, def_end, def_inc, (flags & 8));
611
612 return p;
613 }
614
615 int rec_ctf_prepare(Breconstruction* rec, int action, double lores, double hires,
616 Vector3<long> tile_size, double def_start, double def_end, double def_inc,
617 Bstring& newname, Bstring& label, int flags)
618 {
619 int img_type(0);
620
621 if ( !rec->ctf ) rec->ctf = new CTFparam;
622
623 if ( verbose & VERB_PROCESS )
624 cout << "Processing reconstruction " << rec->id << " (" << rec->frec << ")" << endl;
625
626 Bstring filename, insert, ext;
627 if ( action == 12 && rec->fps.length() ) {
628 filename = rec->fps;
629 img_type = 3;
630 } else if ( ( flags & 1 ) && rec->frec.length() ) {
631 filename = rec->frec;
632 img_type = 1;
633 } else if ( rec->fpart.length() ) {
634 filename = rec->fpart;
635 img_type = 2;
636 } else if ( rec->part && rec->part->fpart.length() ) {
637 img_type = 4;
638 }
639
640 if ( img_type < 4 && !filename.length() ) {
641 if ( verbose & VERB_FULL )
642 cerr << "Warning: no file specified for reconstruction " << rec->id << endl;
643 rec->select = 0;
644 return -1;
645 }
646
647 if ( verbose && filename.length() )
648 cout << "Processing file " << filename << endl;
649
650 if ( action == 11 || action == 13 ) insert = "_ps.";
651 else insert = "_ctf.";
652
653 Bimage* p = NULL;
654 if ( filename.length() ) {
655 p = read_img(filename, 1, -1);
656 if ( !p ) {
657 cerr << "Warning: File " << filename << " not found or read!" << endl;
658 rec->select = 0;
659 return -1;
660 }
661 p->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
662 p->change_type(Float);
663 if ( verbose & VERB_LABEL )
664 cout << "Processing image " << p->file_name() << endl;
665 }
666
667 Bimage* pex = NULL;
668
669 if ( p && ( flags & 2 ) )
670 p->filter_extremes();
671
672 if ( p && ( action == 11 || action == 13 ) ) {
673 pex = p->powerspectrum_tiled(0, tile_size, 7);
674 delete p;
675 p = pex;
676 if ( newname.length() )
677 rec->fps = newname;
678 else if ( rec->fps.length() < 3 ) {
679 ext = filename.extension();
680 if ( ( ext == "tif" ) || ( ext == "jpg" ) || ( ext == "jpeg" )
681 || ( ext == "png" ) || ext.contains("dm") )
682 ext = "pif";
683 rec->fps = filename.pre_rev('.') + insert + ext;
684 }
685 p->label(label.str());
686 write_img(rec->fps, p, 0);
687 }
688
689 if ( action == 12 || action == 13 )
690 rec->fom = img_ctf_fit(p, 0, *rec->ctf, lores, hires, def_start, def_end, def_inc, (flags & 8));
691
692 delete p;
693
694 return 0;
695 }
696
717 int project_ctf_prepare(Bproject* project, int action, double lores,
718 double hires, Vector3<long> tile_size,
719 double def_start, double def_end, double def_inc,
720 Bstring& path, Bstring& newname, Bstring& label, int flags)
721 {
722 if ( action < 1 ) return 0;
723
724 if ( lores < 0 ) lores = 0;
725 if ( lores > 0 && lores < hires ) swap(lores, hires);
726
727 if ( path.length() > 1 ) {
728 mkdir(path.c_str(), (mode_t)0755);
729 if ( path[-1] != '/' ) path += "/";
730 }
731
732 Bfield* field;
733 Bmicrograph* mg;
734 Breconstruction* rec;
735 CTFparam* em_ctf = project->field->mg->ctf;
736
737 if ( verbose ) {
738 if ( project->select < 1 )
739 cout << "CTF operations on all micrographs:" << endl;
740 else
741 cout << "CTF operations on all reconstructions:" << endl;
742 switch ( action ) {
743 case 11: cout << "Calculating power spectra" << endl; break;
744 case 12: cout << "Fitting power spectra" << endl; break;
745 case 13: cout << "Calculating and fitting power spectra" << endl; break;
746 default: break;
747 }
748 if ( action == 12 || action == 13 ) {
749 em_ctf->show();
750 cout << "Baseline type: " << em_ctf->baseline_type() << endl;
751 cout << "Envelope type: " << em_ctf->envelope_type() << endl;
752 cout << "Defocus min, max, inc: " << def_start << " - " << def_end << " ∆ " << def_inc << endl << endl;
753 }
754 cout << "Resolution range: " << hires << " - ";
755 if ( lores > 0 ) cout << lores << " A" << endl;
756 else cout << "inf A" << endl;
757 cout << "Flags: " << flags << endl << endl;
758 }
759
760 long nmg;
761 Bimage* ps = NULL;;
762 Bimage* ps1;
763
764 Bstring filename, insert, ext;
765 if ( action == 11 || action == 13 ) insert = "_ps.";
766 else insert = "_ctf.";
767
768 if ( project->select < 1 ) {
769 for ( field = project->field; field; field = field->next ) {
770 for ( nmg = 1, mg = field->mg; mg->next; mg = mg->next ) nmg++;
771 if ( ( action == 11 || action == 13 ) && ( field->mg->fmg == mg->fmg ) ) {
772 ps = new Bimage(Float, TSimple, tile_size, nmg);
773 ps->sampling(field->mg->pixel_size, field->mg->pixel_size, 1);
774 }
775 for ( mg = field->mg; mg; mg = mg->next ) {
776 ps1 = mg_ctf_prepare(mg, action, lores, hires, tile_size, def_start, def_end, def_inc, flags);
777 if ( ps1 ) {
778 if ( action == 11 || action == 13 ) {
779 if ( ps ) {
780 ps->replace(mg->img_num, ps1);
781 ps->sampling(ps1->sampling());
782 mg_ps_name(mg, -1, path, newname, insert);
783 } else {
784 // mg_ps_name(mg, mg->img_num, path, newname, insert);
785 mg_ps_name(mg, -1, path, newname, insert);
786 ps1->label(label.str());
787 write_img(mg->fps, ps1, 0);
788 }
789 }
790 delete ps1;
791 } else {
792 cerr << "Warning: No power spectrum calculated for micrograph "
793 << mg->id << endl;
794 }
795 }
796 if ( ps ) {
797 ps->label(label.str());
798 write_img(field->mg->fps, ps, 0);
799 delete ps;
800 }
801 }
802 } else {
803 for ( rec = project->rec; rec; rec = rec->next ) {
804 rec_ctf_prepare(rec, action, lores, hires, tile_size,
805 def_start, def_end, def_inc, newname, label, flags);
806 }
807 }
808
809
810 return 0;
811 }
812
813
814 int part_ctf(Bparticle* partlist, int action, double lores, double hires,
815 double wiener, DataType datatype, Bstring& partpath,
816 Bstring& newname, Bstring& label, int flags)
817 {
818 if ( verbose & VERB_DEBUG )
819 cout << "DEBUG part_ctf: partlist=" << partlist << endl;
820
821 Bparticle* part = partlist;
822 if ( !part ) return -1;
823
824 Bmicrograph* mg = part->mg;
825 Breconstruction* rec = part->rec;
826
827 if ( verbose & VERB_DEBUG )
828 cout << "DEBUG part_ctf: mg=" << mg << " rec=" << rec << endl;
829
830 int fn_flag(0); // particle file flag: 0=mg, 1=part
831 long npart(0);
832 double pixel_size(0);
833 Bstring filename, insert("_ctf."), ext;
834 Bimage* p = NULL;
835 Bimage* pnu = NULL;
836
837 CTFparam* ctf = NULL;
838 if ( mg ) {
839 filename = mg->fpart;
840 pixel_size = mg->pixel_size;
841 if ( mg->ctf ) ctf = mg->ctf;
842 else ctf = new CTFparam;
843 } else if ( rec ) {
844 filename = rec->fpart;
845 pixel_size = rec->voxel_size;
846 if ( rec->ctf ) ctf = rec->ctf;
847 else ctf = new CTFparam;
848 }
849
850 for ( part = partlist; part; part = part->next ) npart++;
851 part = partlist;
852
853 if ( part->fpart.length() ) {
854 filename = part->fpart;
855 fn_flag = 1;
856 }
857
858 if ( !filename.length() ) {
859 if ( verbose & VERB_FULL )
860 cerr << "Warning: no particle file specified!" << endl;
861 return -1;
862 }
863
864 p = read_img(filename, 0, -1);
865 if ( !p ) {
866 if ( verbose & VERB_FULL )
867 cerr << "Warning: particle file " << filename << " not read!" << endl;
868 return -1;
869 }
870
871 if ( verbose )
872 cout << p->file_name() << " (" << p->images() << ")" << endl;
873
874 if ( pixel_size < 0.01 ) pixel_size = p->sampling()[0];
875
876 DataType nudatatype = datatype;
877 if ( nudatatype == Unknown_Type ) nudatatype = p->data_type();
878
879 if ( verbose & VERB_DEBUG )
880 cout << "DEBUG part_ctf: p->images()=" << p->images() << " npart=" << npart << endl;
881
882 if ( fn_flag < 1 || p->images() > 1 ) {
883 if ( p->images() != npart ) {
884 cerr << "Error: Micrograph " << mg->id << " has " << npart << " particles," << endl;
885 cerr << " but particle image file " << p->file_name() << " has " << p->images() << " images!" << endl;
886 delete p;
887 // return -2;
888 bexit(-1);
889 }
890 pnu = p->copy_header();
891 pnu->data_type(nudatatype);
892 pnu->data_alloc();
893 if ( mg ) pnu->sampling(pixel_size, pixel_size, 1);
894 else if ( rec ) pnu->sampling(pixel_size, pixel_size, pixel_size);
895 // pnu->change_type(nudatatype);
896 pnu->label(label.str());
897 }
898
899 delete p;
900
901 CTFparam part_ctf;
902 part_ctf.update(ctf);
903
904 double cosax(1), sinax(0), sintilt(0);
905
906 if ( mg ) {
907 cosax = cos(mg->tilt_axis);
908 sinax = sin(mg->tilt_axis);
909 sintilt = sin(mg->tilt_angle);
910 }
911
912 for ( part = partlist; part; part = part->next ) {
913 if ( part->def > 0 ) part_ctf.defocus_average(part->def);
914 else if ( mg )
915 part_ctf.defocus_average(mg->ctf->defocus_average() +
916 fabs(cosax*part->loc[0] - sinax*part->loc[1])*sintilt);
917 if ( part->dev ) part_ctf.defocus_deviation(part->dev);
918 if ( part->ast ) part_ctf.astigmatism_angle(part->ast);
919 part->pixel_size = pixel_size;
920
921 if ( part->fpart.length() ) filename = part->fpart;
922 else if ( mg ) filename = mg->fpart;
923 else if ( rec ) filename = rec->fpart;
924 if ( part->fpart.length() ) p = read_img(filename, 1, 0);
925 else p = read_img(filename, 1, part->id - 1);
926 if ( mg ) p->sampling(pixel_size, pixel_size, 1);
927 else if ( rec ) p->sampling(pixel_size, pixel_size, pixel_size);
928 p->change_type(Float);
929
930 if ( verbose & VERB_LABEL )
931 cout << "Processing image " << p->file_name() << " (" << part->id << ")" << endl;
932
933 img_ctf_apply(p, part_ctf, action, wiener, lores, hires);
934
935 if ( flags & 4 ) p->correct_background();
936 p->change_type(nudatatype);
937
938 // if ( nimg == 1 ) insert = Bstring(part->id, "_%04d.");
939 if ( newname.length() ) filename = newname;
940 else filename = filename.pre_rev('.') + insert + filename.post_rev('.');
941
942 if ( partpath.length() > 1 ) {
943 if ( filename.contains("/") ) filename = filename.post_rev('/');
944 filename = partpath + filename;
945 }
946
947 if ( part->fpart.length() ) {
948 p->label(label.str());
949 write_img(filename, p, 0);
950 part->fpart = filename;
951 } else {
952 pnu->replace(part->id - 1, p);
953 }
954
955 delete p;
956
957 if ( fabs(sintilt) > 1e-6 ) part->def = part_ctf.defocus_average();
958 }
959
960 if ( pnu ) {
961 write_img(filename, pnu, 0);
962 if ( mg ) mg->fpart = filename;
963 else if ( rec ) rec->fpart = filename;
964 }
965
966 delete pnu;
967
968 return 0;
969 }
970
971 int mg_ctf(Bmicrograph* mg, Bimage* pmg, int action, double lores, double hires, double wiener,
972 Vector3<long> tile_size, DataType datatype, Bstring& newname, Bstring& label, int flags)
973 {
974 if ( !mg->ctf ) mg->ctf = new CTFparam;
975
976 Bstring filename(mg->fmg), insert("_ctf."), ext("pif");
977
978 if ( !filename.length() ) {
979 if ( verbose & VERB_FULL )
980 cerr << "Warning: no file specified for micrograph " << mg->id << endl;
981 mg->select = 0;
982 return -1;
983 }
984
985 Bimage* p = NULL;
986 if ( !pmg ) p = read_img(filename, 1, mg->img_num);
987 else p = pmg->extract(mg->img_num);
988
989 if ( !p ) {
990 cerr << "Warning: File " << filename << " not found or read!" << endl;
991 mg->select = 0;
992 return -1;
993 }
994
995 p->origin(mg->origin);
996 if ( p->image->origin().length() < 1 ) p->origin(p->size()/2);
997 p->sampling(mg->pixel_size, mg->pixel_size, 1);
998 p->change_type(Float);
999
1000 DataType nudatatype = datatype;
1001 if ( pmg ) nudatatype = pmg->data_type();
1002 else if ( nudatatype == Unknown_Type ) nudatatype = p->data_type();
1003
1004 if ( p && ( flags & 2 ) )
1005 p->filter_extremes();
1006
1007 if ( mg->tilt_angle ) {
1008 if ( verbose )
1009 cout << p->file_name() << " (" << mg->img_num << ") " << mg->tilt_angle*180.0/M_PI << endl;
1010 img_ttf_apply(p, *(mg->ctf), action, wiener,
1011 tile_size, mg->tilt_angle, mg->tilt_axis, lores, hires);
1012 } else {
1013 if ( verbose )
1014 cout << p->file_name() << " (" << mg->img_num << ")" << endl;
1015 img_ctf_apply(p, *(mg->ctf), action, wiener, lores, hires);
1016 }
1017
1018
1019 if ( flags & 4 ) p->correct_background();
1020 p->change_type(nudatatype);
1021
1022 if ( pmg ) {
1023 pmg->replace(mg->img_num, p);
1024 } else {
1025 if ( newname.length() ) filename = newname;
1026 else {
1027 insert = Bstring(mg->img_num, "_%03d_ctf.");
1028 if ( filename.contains(".dm") )
1029 filename = filename.pre_rev('.') + insert + ext;
1030 else
1031 filename = filename.pre_rev('.') + insert + filename.post_rev('.');
1032 }
1033 mg->fmg = filename;
1034 mg->img_num = 0;
1035 if ( verbose & VERB_DEBUG )
1036 cout << "DEBUG mg_ctf: Writing file " << filename << endl;
1037 p->label(label.str());
1038 write_img(filename, p, 0);
1039 }
1040
1041 delete p;
1042
1043 return 0;
1044 }
1045
1046 int rec_ctf(Breconstruction* rec, int action, double lores, double hires, double wiener,
1047 DataType datatype, Bstring& newname, Bstring& label, int flags)
1048 {
1049 if ( !rec->ctf ) rec->ctf = new CTFparam;
1050
1051 Bstring filename(rec->frec), insert("_ctf."), ext;
1052
1053 if ( !filename.length() ) {
1054 if ( verbose & VERB_FULL )
1055 cerr << "Warning: no file specified for reconstruction " << rec->id << endl;
1056 rec->select = 0;
1057 return -1;
1058 }
1059
1060 Bimage* p = read_img(filename, 1, 0);
1061 if ( !p ) {
1062 cerr << "Warning: File " << filename << " not found or read!" << endl;
1063 rec->select = 0;
1064 return -1;
1065 }
1066
1067 p->origin(rec->origin);
1068 p->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
1069 p->change_type(Float);
1070
1071 if ( verbose )
1072 cout << p->file_name() << endl;
1073
1074 DataType nudatatype = datatype;
1075 if ( nudatatype == Unknown_Type ) nudatatype = p->data_type();
1076
1077 if ( flags & 2 )
1078 p->filter_extremes();
1079
1080 img_ctf_apply(p, *(rec->ctf), action, wiener, lores, hires);
1081
1082 if ( newname.length() ) filename = newname;
1083 else filename = filename.pre_rev('.') + insert + filename.post_rev('.');
1084
1085 rec->frec = filename;
1086
1087 if ( p ) {
1088 if ( flags & 4 ) p->correct_background();
1089 if ( verbose & VERB_DEBUG )
1090 cout << "DEBUG rec_ctf: Writing file " << filename << endl;
1091 p->change_type(nudatatype);
1092 p->label(label.str());
1093 write_img(filename, p, 0);
1094 }
1095
1096 delete p;
1097
1098 return 0;
1099 }
1100
1121 int project_ctf(Bproject* project, int action, double lores,
1122 double hires, Vector3<long> tile_size, double wiener,
1123 DataType datatype, Bstring& partpath, Bstring& newname,
1124 Bstring& label, int flags)
1125 {
1126 if ( action < 1 ) return 0;
1127
1128 if ( lores < 0 ) lores = 0;
1129 if ( lores > 0 && lores < hires ) swap(lores, hires);
1130
1131 Bfield* field;
1132 Bmicrograph* mg;
1133 Breconstruction* rec;
1134 Bimage* p = NULL;
1135 Bstring filename, insert("_ctf."), ext("pif");
1136
1137 if ( verbose ) {
1138 if ( project->select < 1 )
1139 cout << "CTF operations on all micrographs:" << endl;
1140 else
1141 cout << "CTF operations on all reconstructions:" << endl;
1142 switch ( action ) {
1143 case 1: cout << "Flipping phases" << endl; break;
1144 case 2: cout << "Applying a CTF" << endl; break;
1145 case 3: cout << "Correcting for the CTF" << endl; break;
1146 case 4: cout << "Correcting for the CTF with an optimal Wiener filter" << endl; break;
1147 case 5: cout << "Correcting for the CTF with baseline enhancement" << endl; break;
1148 case 6: cout << "Correcting for the CTF with baseline2 enhancement" << endl; break;
1149 case 7: cout << "Flipping phases with baseline enhancement" << endl; break;
1150 case 8: cout << "Correcting for the CTF with baseline3 enhancement" << endl; break;
1151 default: break;
1152 }
1153 cout << "Resolution range: " << hires << " - ";
1154 if ( lores > 0 ) cout << lores << " A" << endl;
1155 else cout << "inf A" << endl;
1156 cout << "Flags: " << flags << endl << endl;
1157 }
1158
1159 if ( project->select < 1 ) {
1160 for ( field = project->field; field; field = field->next ) {
1161 if ( flags & 1 ) {
1162 for ( mg = field->mg; mg->next; mg = mg->next ) ;
1163 if ( field->mg->fmg == mg->fmg ) {
1164 if ( verbose )
1165 cout << "Reading: " << mg->fmg << " (" << mg->img_num + 1 << ")" << endl;
1166 p = read_img(mg->fmg, 1, -1);
1167 }
1168 }
1169 if ( verbose )
1170 cout << "Image\tNumber\tTilt" << endl;
1171 for ( mg = field->mg; mg; mg = mg->next ) {
1172 if ( flags & 1 )
1173 mg_ctf(mg, p, action, lores, hires, wiener, tile_size,
1174 datatype, newname, label, flags);
1175 else
1176 part_ctf(mg->part, action, lores, hires, wiener,
1177 datatype, partpath, newname, label, flags);
1178 }
1179 if ( p ) {
1180 filename = p->file_name();
1181 if ( newname.length() ) filename = newname;
1182 else {
1183 if ( filename.contains(".dm") )
1184 filename = filename.pre_rev('.') + insert + ext;
1185 else
1186 filename = filename.pre_rev('.') + insert + filename.post_rev('.');
1187 }
1188 for ( mg = field->mg; mg; mg = mg->next ) mg->fmg = filename;
1189 if ( verbose )
1190 cout << "Writing: " << filename << endl;
1191 p->label(label.str());
1192 write_img(filename, p, 0);
1193 delete p;
1194 }
1195 }
1196 } else {
1197 for ( rec = project->rec; rec; rec = rec->next ) {
1198 if ( flags & 1 )
1199 rec_ctf(rec, action, lores, hires, wiener,
1200 datatype, newname, label, flags);
1201 else
1202 part_ctf(rec->part, action, lores, hires, wiener,
1203 datatype, partpath, newname, label, flags);
1204 }
1205 }
1206
1207 return 0;
1208 }
1209
1221 int project_ctf_average(Bproject* project, Bstring& psname)
1222 {
1223 Bfield* field;
1224 Bmicrograph* mg = NULL;
1225
1226 for ( field = project->field; field; field = field->next )
1227 for ( mg = field->mg; mg; mg = mg->next )
1228 if ( mg->box_size[0] ) break;
1229
1230 if ( !mg ) {
1231 cerr << "Error: No micrograph with a box size specified!" << endl;
1232 return -1;
1233 }
1234
1235 int i, j, n(0), maxrad = mg->box_size[0]/2;
1236 double recip_interval = 1.0/(2*maxrad*mg->pixel_size);
1237 vector<double> ctf;
1238
1239 int ncol = 2;
1240 Bstring title("Compound CTF curves"), txt;
1241 Bplot* plot = new Bplot(1, maxrad, ncol);
1242 plot->title(title);
1243
1244 plot->page(0).title(title);
1245 plot->page(0).columns(ncol);
1246 for ( i=0; i<ncol; i++ ) plot->page(0).column(i).number(i);
1247 plot->page(0).column(0).label("s");
1248 plot->page(0).column(1).label("CTFavg");
1249 plot->page(0).column(0).axis(1);
1250 plot->page(0).column(1).axis(3);
1251 plot->page(0).column(1).type(2);
1252 plot->page(0).axis(1).flags(1);
1253 plot->page(0).axis(1).label("Resolution (A)");
1254 // plot->page(0).axis(1).min(0);
1255 // plot->page(0).axis(1).max(x_max);
1256 plot->page(0).axis(3).label("Average CTF");
1257 plot->page(0).axis(3).min(0);
1258 plot->page(0).axis(3).max(1);
1259
1260 for ( field = project->field; field; field = field->next ) {
1261 for ( mg = field->mg; mg; mg = mg->next ) {
1262 if ( mg->ctf ) {
1263 ctf = mg->ctf->calculate(maxrad, 1, recip_interval);
1264 for ( i=0, j=maxrad; i<maxrad; i++, j++ )
1265 (*plot)[j] += ctf[i]*ctf[i];
1266 // delete ctf;
1267 n++;
1268 }
1269 }
1270 }
1271
1272 for ( i=0, j=maxrad; i<maxrad; i++, j++ ) {
1273 (*plot)[i] = i*recip_interval;
1274 (*plot)[j] /= n;
1275 }
1276
1277 txt = "Number of micrographs: " + Bstring(n, "%d");
1278 plot->page(0).add_text(txt);
1279
1280 ps_plot(psname, plot);
1281
1282 delete plot;
1283
1284 return 0;
1285 }
1286
1294 Bimage* project_powerspectrum_average(Bproject* project, double deftarget)
1295 {
1296 long n(0);
1297 Bimage* ps = NULL;
1298 Bimage* pt = NULL;
1299 Bimage* psavg = NULL;
1300 Bfield* field;
1301 Bmicrograph* mg = NULL;
1302 Vector3<double> origin, scale(1,1,1), translate;
1303 Matrix3 mat(1);
1304
1305 if ( verbose ) {
1306 cout << "Calculating an average power spectrum with target defocus: " << deftarget << endl;
1307 cout << "Micrograph\tDefocus\tScale" << endl;
1308 }
1309
1310 for ( field = project->field; field; field = field->next ) {
1311 for ( mg = field->mg; mg; mg = mg->next ) {
1312 if ( mg->fps.length() )
1313 ps = read_img(mg->fps, 1, mg->img_num);
1314 if ( ps ) {
1315 if ( !psavg ) {
1316 psavg = ps->copy(1);
1317 psavg->origin(ps->size()/2);
1318 psavg->fill(0);
1319 psavg->sampling(mg->pixel_size, mg->pixel_size, 1);
1320 }
1321 ps->calculate_background();
1322 scale[0] = scale[1] = sqrt(mg->ctf->defocus_average()/deftarget);
1323 if ( verbose )
1324 cout << mg->id << tab << mg->ctf->defocus_average() << tab << scale << endl;
1325 pt = ps->transform(0, ps->size(), scale, psavg->image->origin(), translate, mat, FILL_BACKGROUND);
1326 psavg->add(pt);
1327 delete pt;
1328 delete ps;
1329 n++;
1330 }
1331 }
1332 }
1333
1334 if ( n ) psavg->multiply(1.0/n);
1335
1336 return psavg;
1337 }
1338
1345 int project_merge_CTF_parameters(Bproject* project, Bproject* ctfproject)
1346 {
1347 if ( !project || ! ctfproject ) return 0;
1348
1349 Bfield *field, *ctffield;
1350 Bmicrograph *mg, *ctfmg;
1351 Breconstruction *rec, *ctfrec;
1352
1353 if ( verbose & VERB_PROCESS )
1354 cout << "Merging CTF parameters into the main project" << endl << endl;
1355
1356 for ( field=project->field, ctffield=ctfproject->field; field; field=field->next, ctffield=ctffield->next ) {
1357 for ( mg=field->mg, ctfmg=ctffield->mg; mg && ctfmg; mg=mg->next, ctfmg=ctfmg->next ) {
1358 if ( ctfmg->fps.length() > 0 ) mg->fps = ctfmg->fps;
1359 if ( ctfmg->magnification ) mg->magnification = ctfmg->magnification;
1360 if ( ctfmg->sampling ) mg->sampling = ctfmg->sampling;
1361 if ( ctfmg->ctf ) {
1362 if ( !mg->ctf ) mg->ctf = new CTFparam;
1363 mg->ctf->update(ctfmg->ctf);
1364 }
1365 }
1366 }
1367
1368 for ( rec=project->rec, ctfrec=ctfproject->rec; rec && ctfrec; rec=rec->next, ctfrec=ctfrec->next ) {
1369 if ( ctfrec->fps.length() > 0 ) rec->fps = ctfrec->fps;
1370 if ( ctfrec->ctf ) {
1371 if ( !rec->ctf ) rec->ctf = new CTFparam;
1372 rec->ctf->update(ctfrec->ctf);
1373 }
1374 }
1375
1376 return 0;
1377 }
1378
1384 int project_CTF_to_part(Bproject* project)
1385 {
1386 if ( !project ) return 0;
1387
1388 Bfield* field;
1389 Bmicrograph* mg;
1390 Breconstruction* rec;
1391 Bparticle* part;
1392
1393 if ( verbose & VERB_PROCESS )
1394 cout << "Transferring CTF parameters to particles" << endl << endl;
1395
1396 for ( field = project->field; field; field = field->next ) {
1397 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
1398 for ( part = mg->part; part; part = part->next ) {
1399 part->def = mg->ctf->defocus_average();
1400 part->dev = mg->ctf->defocus_deviation();
1401 part->ast = mg->ctf->astigmatism_angle();
1402 }
1403 }
1404 }
1405
1406 for ( rec = project->rec; rec; rec = rec->next ) if ( rec->ctf ) {
1407 for ( part = rec->part; part; part = part->next ) {
1408 part->def = rec->ctf->defocus_average();
1409 part->dev = rec->ctf->defocus_deviation();
1410 part->ast = rec->ctf->astigmatism_angle();
1411 }
1412 }
1413
1414 return 0;
1415 }
1416
1425 int project_set_defocus(Bproject* project, double def_avg,
1426 double def_dev, double ast_angle)
1427 {
1428 if ( !project ) return 0;
1429
1430 long n(0);
1431 Bfield* field;
1432 Bmicrograph* mg;
1433 Breconstruction* rec;
1434
1435 if ( verbose & VERB_DEBUG )
1436 cout << "DEBUG project_set_defocus: avg=" << def_avg << " dev=" << def_dev << " ang=" << ast_angle*180.0/M_PI << endl;
1437
1438 for ( n=0, field = project->field; field; field = field->next ) {
1439 for ( mg = field->mg; mg; mg = mg->next ) {
1440 if ( !mg->ctf ) mg->ctf = new CTFparam;
1441 mg->ctf->defocus_average(def_avg);
1442 if ( def_dev ) {
1443 mg->ctf->defocus_deviation(def_dev);
1444 mg->ctf->astigmatism_angle(ast_angle);
1445 }
1446 n++;
1447 }
1448 }
1449
1450 if ( verbose & VERB_DEBUG )
1451 cout << "DEBUG project_set_defocus: micrographs set = " << n << endl;
1452
1453 for ( n=0, rec = project->rec; rec; rec = rec->next ) {
1454 if ( !rec->ctf ) rec->ctf = new CTFparam;
1455 rec->ctf->defocus_average(def_avg);
1456 if ( def_dev ) {
1457 rec->ctf->defocus_deviation(def_dev);
1458 rec->ctf->astigmatism_angle(ast_angle);
1459 }
1460 n++;
1461 }
1462
1463 if ( verbose & VERB_DEBUG )
1464 cout << "DEBUG project_set_defocus: reconstructions set = " << n << endl;
1465
1466 return 0;
1467 }
1468
1476 int project_set_astigmatism(Bproject* project, double def_dev, double ast_angle)
1477 {
1478 if ( !project ) return 0;
1479
1480 Bfield* field;
1481 Bmicrograph* mg;
1482 Breconstruction* rec;
1483
1484 if ( verbose & VERB_DEBUG )
1485 cout << "DEBUG project_set_astigmatism: dev=" << def_dev << " ang=" << ast_angle*180.0/M_PI << endl;
1486
1487 for ( field = project->field; field; field = field->next ) {
1488 for ( mg = field->mg; mg; mg = mg->next ) {
1489 if ( !mg->ctf ) mg->ctf = new CTFparam;
1490 mg->ctf->defocus_deviation(def_dev);
1491 mg->ctf->astigmatism_angle(ast_angle);
1492 }
1493 }
1494
1495 for ( rec = project->rec; rec; rec = rec->next ) {
1496 if ( !rec->ctf ) rec->ctf = new CTFparam;
1497 rec->ctf->defocus_deviation(def_dev);
1498 rec->ctf->astigmatism_angle(ast_angle);
1499 }
1500
1501 return 0;
1502 }
1503
1510 int project_set_volts(Bproject* project, double volts)
1511 {
1512 if ( !project ) return 0;
1513
1514 if ( volts < 1e4 ) volts *= 1000;
1515
1516 Bfield* field;
1517 Bmicrograph* mg;
1518 Breconstruction* rec;
1519
1520 for ( field = project->field; field; field = field->next )
1521 for ( mg = field->mg; mg; mg = mg->next ) {
1522 if ( !mg->ctf ) mg->ctf = new CTFparam;
1523 mg->ctf->volt(volts);
1524 }
1525
1526 for ( rec = project->rec; rec; rec = rec->next ) {
1527 if ( !rec->ctf ) rec->ctf = new CTFparam;
1528 rec->ctf->volt(volts);
1529 }
1530
1531 return 0;
1532 }
1533
1540 int project_set_Cs(Bproject* project, double Cs)
1541 {
1542 if ( !project ) return 0;
1543
1544 Bfield* field;
1545 Bmicrograph* mg;
1546 Breconstruction* rec;
1547
1548 for ( field = project->field; field; field = field->next )
1549 for ( mg = field->mg; mg; mg = mg->next ) {
1550 if ( !mg->ctf ) mg->ctf = new CTFparam;
1551 mg->ctf->Cs(Cs);
1552 }
1553
1554 for ( rec = project->rec; rec; rec = rec->next ) {
1555 if ( !rec->ctf ) rec->ctf = new CTFparam;
1556 rec->ctf->Cs(Cs);
1557 }
1558
1559 return 0;
1560 }
1561
1568 int project_set_amp_shift(Bproject* project, double amp_shift)
1569 {
1570 if ( !project ) return 0;
1571
1572 Bfield* field;
1573 Bmicrograph* mg;
1574 Breconstruction* rec;
1575
1576 for ( field = project->field; field; field = field->next )
1577 for ( mg = field->mg; mg; mg = mg->next ) {
1578 if ( !mg->ctf ) mg->ctf = new CTFparam;
1579 mg->ctf->amp_shift(amp_shift);
1580 }
1581
1582 for ( rec = project->rec; rec; rec = rec->next ) {
1583 if ( !rec->ctf ) rec->ctf = new CTFparam;
1584 rec->ctf->amp_shift(amp_shift);
1585 }
1586
1587 return 0;
1588 }
1589
1596 int project_set_alpha(Bproject* project, double alpha)
1597 {
1598 if ( !project ) return 0;
1599
1600 Bfield* field;
1601 Bmicrograph* mg;
1602 Breconstruction* rec;
1603
1604 for ( field = project->field; field; field = field->next )
1605 for ( mg = field->mg; mg; mg = mg->next ) {
1606 if ( !mg->ctf ) mg->ctf = new CTFparam;
1607 mg->ctf->alpha(alpha);
1608 }
1609
1610 for ( rec = project->rec; rec; rec = rec->next ) {
1611 if ( !rec->ctf ) rec->ctf = new CTFparam;
1612 rec->ctf->alpha(alpha);
1613 }
1614
1615 return 0;
1616 }
1617
1624 int project_set_envelope_type(Bproject* project, int type)
1625 {
1626 if ( !project ) return 0;
1627
1628 Bfield* field;
1629 Bmicrograph* mg;
1630 Breconstruction* rec;
1631
1632 for ( field = project->field; field; field = field->next )
1633 for ( mg = field->mg; mg; mg = mg->next ) {
1634 if ( !mg->ctf ) mg->ctf = new CTFparam;
1635 mg->ctf->envelope_type(type);
1636 }
1637
1638 for ( rec = project->rec; rec; rec = rec->next ) {
1639 if ( !rec->ctf ) rec->ctf = new CTFparam;
1640 rec->ctf->envelope_type(type);
1641 }
1642
1643 return 0;
1644 }
1645
1653 int project_set_envelope(Bproject* project, int type, double* coeff)
1654 {
1655 if ( !project ) return 0;
1656
1657 Bfield* field;
1658 Bmicrograph* mg;
1659 Breconstruction* rec;
1660
1661 for ( field = project->field; field; field = field->next )
1662 for ( mg = field->mg; mg; mg = mg->next ) {
1663 if ( !mg->ctf ) mg->ctf = new CTFparam;
1664 mg->ctf->envelope_type(type);
1665 mg->ctf->envelope(coeff);
1666 }
1667
1668 for ( rec = project->rec; rec; rec = rec->next ) {
1669 if ( !rec->ctf ) rec->ctf = new CTFparam;
1670 rec->ctf->envelope_type(type);
1671 rec->ctf->envelope(coeff);
1672 }
1673
1674 return 0;
1675 }
1676
1688 int project_set_coherence_envelope(Bproject* project)
1689 {
1690 if ( !project ) return 0;
1691
1692 Bfield* field;
1693 Bmicrograph* mg;
1694 Breconstruction* rec;
1695
1696 for ( field = project->field; field; field = field->next )
1697 for ( mg = field->mg; mg; mg = mg->next ) {
1698 if ( !mg->ctf ) mg->ctf = new CTFparam;
1699 mg->ctf->envelope(1, -M_PI*M_PI*mg->ctf->alpha()*mg->ctf->alpha()*mg->ctf->defocus_average()*mg->ctf->defocus_average());
1700 }
1701
1702 for ( rec = project->rec; rec; rec = rec->next ) {
1703 if ( !rec->ctf ) rec->ctf = new CTFparam;
1704 rec->ctf->envelope(1, -M_PI*M_PI*rec->ctf->alpha()*rec->ctf->alpha()*rec->ctf->defocus_average()*rec->ctf->defocus_average());
1705 }
1706
1707 return 0;
1708 }
1709
1716 int project_set_baseline_type(Bproject* project, int type)
1717 {
1718 if ( !project ) return 0;
1719
1720 Bfield* field;
1721 Bmicrograph* mg;
1722 Breconstruction* rec;
1723
1724 for ( field = project->field; field; field = field->next ) {
1725 for ( mg = field->mg; mg; mg = mg->next ) {
1726 if ( !mg->ctf ) mg->ctf = new CTFparam;
1727 mg->ctf->baseline_type(type);
1728 }
1729 }
1730
1731 for ( rec = project->rec; rec; rec = rec->next ) {
1732 if ( !rec->ctf ) rec->ctf = new CTFparam;
1733 rec->ctf->baseline_type(type);
1734 }
1735
1736 return 0;
1737 }
1738
1746 int project_set_baseline(Bproject* project, int type, double* coeff)
1747 {
1748 if ( !project ) return 0;
1749
1750 Bfield* field;
1751 Bmicrograph* mg;
1752 Breconstruction* rec;
1753
1754 for ( field = project->field; field; field = field->next ) {
1755 for ( mg = field->mg; mg; mg = mg->next ) {
1756 if ( !mg->ctf ) mg->ctf = new CTFparam;
1757 mg->ctf->baseline_type(type);
1758 mg->ctf->baseline(coeff);
1759 }
1760 }
1761
1762 for ( rec = project->rec; rec; rec = rec->next ) {
1763 if ( !rec->ctf ) rec->ctf = new CTFparam;
1764 rec->ctf->baseline_type(type);
1765 rec->ctf->baseline(coeff);
1766 }
1767
1768 return 0;
1769 }
1770
1776 int project_update_first_zero(Bproject* project)
1777 {
1778 if ( !project ) return 0;
1779
1780 Bfield* field;
1781 Bmicrograph* mg;
1782 Breconstruction* rec;
1783
1784 if ( verbose & VERB_DEBUG )
1785 cout << "DEBUG project_update_first_zero: start" << endl;
1786
1787 for ( field = project->field; field; field = field->next ) {
1788 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
1789 if ( mg->ctf && mg->ctf->defocus_average() > 0 && mg->ctf->volt() > 0 && mg->ctf->Cs() > 0 )
1790 mg->ctf->zero(1);
1791 }
1792 }
1793
1794 for ( rec = project->rec; rec; rec = rec->next ) {
1795 if ( rec->ctf && rec->ctf->defocus_average() > 0 && rec->ctf->volt() > 0 && rec->ctf->Cs() > 0 )
1796 rec->ctf->zero(1);
1797 }
1798
1799 if ( verbose & VERB_DEBUG )
1800 cout << "DEBUG project_update_first_zero: done" << endl;
1801
1802 return 0;
1803 }
1804
1811 int project_plot_ctf(Bproject* project, Bstring& filename)
1812 {
1813 if ( !project ) return 0;
1814
1815 Bfield* field;
1816 Bmicrograph* mg;
1817 Bimage* p;
1818 Bimage* prad;
1819 Bstring basename = filename.pre_rev('.');
1820 Bstring psname;
1821
1822 for ( field = project->field; field; field = field->next ) {
1823 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
1824 p = read_img(mg->fps, 1, 0);
1825 if ( p ) {
1826 psname = basename + "_" + mg->fps.pre_rev('.') + ".ps";
1827 prad = img_ctf_radial_average(p, 0, *mg->ctf);
1828 ps_ctf_plot(prad->sizeX(), (double *)prad->data_pointer(),
1829 1.0/p->real_size()[0], mg->ctf, psname);
1830 delete prad;
1831 }
1832 }
1833 }
1834
1835 return 0;
1836 }
1837
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bimage::extract_tiles
Bimage * extract_tiles(long nn, vector< Vector3< long >> &coords, Vector3< long > tile_size)
Extracts a set of tiles at specified positions from an image into a new image.
Definition: Bimage_extract.cpp:335
img_wave_aberration
Bimage * img_wave_aberration(CTFparam cp, Vector3< long > size, Vector3< double > sam)
Calculates a wave aberration function.
Definition: mg_ctf.cpp:175
Bparticle::id
int id
Definition: mg_processing.h:92
CTFparam::zero
double zero(int i)
Definition: ctf.h:218
rec_ctf
int rec_ctf(Breconstruction *rec, int action, double lores, double hires, double wiener, DataType datatype, Bstring &newname, Bstring &label, int flags)
Definition: mg_ctf.cpp:1046
CTFparam::Cs
double Cs()
Definition: ctf.h:87
Baxis::label
Bstring & label()
Definition: Bplot.h:28
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2828
Bparticle::pixel_size
double pixel_size
Definition: mg_processing.h:98
CTFparam::baseline_type
long baseline_type()
Definition: ctf.h:106
Bimage::copy_header
Bimage * copy_header()
Definition: Bimage.h:650
Bparticle::ast
double ast
Definition: mg_processing.h:97
rec_ctf_prepare
int rec_ctf_prepare(Breconstruction *rec, int action, double lores, double hires, Vector3< long > tile_size, double def_start, double def_end, double def_inc, Bstring &newname, Bstring &label, int flags)
Definition: mg_ctf.cpp:615
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
project_CTF_to_part
int project_CTF_to_part(Bproject *project)
Transfers CTF parameters from micrographs to particles.
Definition: mg_ctf.cpp:1384
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:105
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bimage::powerspectrum_tiled_and_tilted
Bimage * powerspectrum_tiled_and_tilted(Vector3< long > tile_size, double tilt_axis, double tilt_angle, double tilt_offset, double defocus, double iCL2, int flags=0)
Prepares a tiled powerspectrum from a tilted image for determining CTF parameters.
Definition: Bimage_powerspectrum.cpp:354
Baxis::min
double min()
Definition: Bplot.h:30
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
planb
fft_plan planb
Definition: bico.cpp:24
Bimage::add
void add(long j, double v)
Definition: Bimage.h:308
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
Bimage::slices_to_images
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Definition: Bimage.cpp:2052
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
Bimage::invert
void invert()
Inverts the data in the image.
Definition: Bimage.cpp:3108
Bplot::title
Bstring & title()
Definition: Bplot.h:189
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:211
Bimage::image_size
long image_size()
Definition: Bimage.h:267
part_ctf
int part_ctf(Bparticle *partlist, int action, double lores, double hires, double wiener, DataType datatype, Bstring &partpath, Bstring &newname, Bstring &label, int flags)
Definition: mg_ctf.cpp:814
project_set_baseline
int project_set_baseline(Bproject *project, int type, double *coeff)
Sets the baseline equations of all the micrographs.
Definition: mg_ctf.cpp:1746
Bimage::fft
int fft()
Definition: Bimage.h:822
project_plot_ctf
int project_plot_ctf(Bproject *project, Bstring &filename)
Plots the CTF curves.
Definition: mg_ctf.cpp:1811
Bmicrograph::sampling
double sampling
Definition: mg_processing.h:213
utilities.h
Header file for general utilities.
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
Breconstruction::fom
double fom
Definition: mg_processing.h:302
Bimage::powerspectrum_tiled
Bimage * powerspectrum_tiled(long img_num, Vector3< long > tile_size, int flags=0)
Prepares a tiled power spectrum from an image for determining CTF parameters.
Definition: Bimage_powerspectrum.cpp:97
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Breconstruction
Definition: mg_processing.h:280
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
CTFparam::calc_envelope
double calc_envelope(double s)
Definition: ctf.h:189
planf
fft_plan planf
Definition: bico.cpp:24
CTFparam::update
int update(CTFparam *ctf)
Definition: ctf.h:77
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
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1005
Breconstruction::ctf
CTFparam * ctf
Definition: mg_processing.h:303
project_powerspectrum_average
Bimage * project_powerspectrum_average(Bproject *project, double deftarget)
Averages multiple power spectra based on defocus estimates.
Definition: mg_ctf.cpp:1294
project_set_amp_shift
int project_set_amp_shift(Bproject *project, double amp_shift)
Sets the amplitude contribution of all the micrographs.
Definition: mg_ctf.cpp:1568
Bimage::assemble_tiles
int assemble_tiles(Bimage *pt, int flag=0)
Assembles overlapping tiles into this image.
Definition: Bimage_combine.cpp:432
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
project_set_envelope_type
int project_set_envelope_type(Bproject *project, int type)
Sets the envelope type of all the micrographs.
Definition: mg_ctf.cpp:1624
img_ctf_radial_average
Bimage * img_ctf_radial_average(Bimage *p, long n, CTFparam &em_ctf)
Calculates the power spectrum radial average corrected for astigmatism.
Definition: mg_ctf_fit.cpp:46
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.
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:217
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
Bfield::next
Bfield * next
Definition: mg_processing.h:258
img_ctf_fit
double img_ctf_fit(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires, double def_start=1e3, double def_end=2e5, double def_inc=1e3, int flag=0)
Determines the CTF parameters from a power spectrum.
Definition: mg_ctf_fit.cpp:209
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
TSimple
Definition: Bimage.h:58
timer.h
Utilities for timing functions.
Baxis::max
double max()
Definition: Bplot.h:32
img_ctf_calculate
Bimage * img_ctf_calculate(CTFparam cp, int action, double wiener, Vector3< long > size, Vector3< double > sam, double lores, double hires)
Calculates a CTF complex image.
Definition: mg_ctf.cpp:45
Float
Definition: utilities.h:157
ps_ctf_plot
int ps_ctf_plot(Bstring &filename, CTFparam &em_ctf, size_t n, double freq_step)
Generates a postscript plot from CTF parameters for defocus and the envelope.
Definition: ps_ctf_plot.cpp:71
Vector3::max
Type max()
Definition: Vector3.h:175
Bimage
General image parameter class.
Definition: Bimage.h:163
project_set_volts
int project_set_volts(Bproject *project, double volts)
Sets the acceleration voltage of all the micrographs.
Definition: mg_ctf.cpp:1510
project_set_astigmatism
int project_set_astigmatism(Bproject *project, double def_dev, double ast_angle)
Sets the defocus deviation and astigmatism angle of all the micrographs.
Definition: mg_ctf.cpp:1476
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:487
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:216
img_ttf_apply_one
int img_ttf_apply_one(Bimage *p, long nn, CTFparam ctf, int action, double wiener, double def, double res_lo, double res_hi, Vector3< long > psize, fft_plan planf, fft_plan planb)
Definition: mg_ctf.cpp:315
CTFparam::calc_baseline
double calc_baseline(double s)
Definition: ctf.h:161
Bimage::data_alloc
unsigned char * data_alloc()
Definition: Bimage.h:256
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bimage::transform
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Definition: Bimage_transform.cpp:37
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:104
project_merge_CTF_parameters
int project_merge_CTF_parameters(Bproject *project, Bproject *ctfproject)
Puts CTF parameters from one project into another.
Definition: mg_ctf.cpp:1345
base
string base(string &filename)
Definition: string_util.cpp:28
Bimage::correct_background
int correct_background(long nn, int flag)
Corrects the background for one sub-image.
Definition: Bimage_background.cpp:202
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:206
project_set_coherence_envelope
int project_set_coherence_envelope(Bproject *project)
Replaces envelope equations with those based on partial coherence in all micrographs.
Definition: mg_ctf.cpp:1688
Bcolumn::number
long number()
Definition: Bplot.h:61
mg_ps_name
int mg_ps_name(Bmicrograph *mg, int img_num, Bstring &path, Bstring &newname, Bstring insert)
Definition: mg_ctf.cpp:493
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bmicrograph::select
long select
Definition: mg_processing.h:203
CTFparam::delta_phi
double delta_phi(double s2, double angle)
Definition: ctf.h:145
Bimage::label
void label(string s)
Definition: Bimage.h:235
project_update_first_zero
int project_update_first_zero(Bproject *project)
Updates the first zero from the defocus average for all the micrographs.
Definition: mg_ctf.cpp:1776
Bproject::field
Bfield * field
Definition: mg_processing.h:343
Bimage::resize
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:28
Bcolumn::type
long type()
Definition: Bplot.h:66
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:515
fft_plan
fftwf_plan fft_plan
Definition: fft.h:16
project_set_alpha
int project_set_alpha(Bproject *project, double alpha)
Sets the beam source size/divergence angle of all the micrographs.
Definition: mg_ctf.cpp:1596
Bpage::axis
Baxis & axis(long id)
Definition: Bplot.h:117
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
CTFparam::calculate
double calculate(double s2, double angle)
Definition: ctf.h:149
Bpage::title
Bstring & title()
Definition: Bplot.h:100
project_ctf
int project_ctf(Bproject *project, int action, double lores, double hires, Vector3< long > tile_size, double wiener, DataType datatype, Bstring &partpath, Bstring &newname, Bstring &label, int flags)
Calculates or fits CTF curves to multiple power spectra.
Definition: mg_ctf.cpp:1121
CTFparam::lambda
double lambda()
Definition: ctf.h:139
CTFparam::show
void show()
Definition: ctf.h:232
Bmicrograph
Definition: mg_processing.h:200
CTFparam::envelope_equation
Bstring envelope_equation()
Generates an envelope equation string from 4 coefficients.
Definition: ctf.cpp:209
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
CTFparam::envelope_type
long envelope_type()
Definition: ctf.h:113
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
verbose
int verbose
img_ctf_apply
int img_ctf_apply(Bimage *p, CTFparam em_ctf, int action, double wiener, double lores, double hires)
Applies or corrects for the contrast transfer function (CTF).
Definition: mg_ctf.cpp:238
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:91
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
mg_ctf
int mg_ctf(Bmicrograph *mg, Bimage *pmg, int action, double lores, double hires, double wiener, Vector3< long > tile_size, DataType datatype, Bstring &newname, Bstring &label, int flags)
Definition: mg_ctf.cpp:971
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
ps_ctf_plot.h
Header file for postscript output functions.
Bparticle::dev
double dev
Definition: mg_processing.h:96
Bpage::add_text
void add_text(Bstring &s)
Definition: Bplot.h:122
Bimage::complex_to_real
void complex_to_real()
The real part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:50
img_ctf_apply_to_proj
int img_ctf_apply_to_proj(Bimage *proj, CTFparam em_ctf, double defocus, double res_lo, double res_hi, fft_plan planf_2D, fft_plan planb_2D)
Applies a CTF to a projection image.
Definition: mg_ctf.cpp:354
Bimage::filter_extremes
int filter_extremes()
Filters the extremes out of a micrograph image.
Definition: Bimage_segment.cpp:634
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
Bmicrograph::fps
Bstring fps
Definition: mg_processing.h:210
Bparticle
Definition: mg_processing.h:89
Baxis::flags
long flags()
Definition: Bplot.h:38
Bstring
Definition: Bstring.h:29
Bimage::pad
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Definition: Bimage_resize.cpp:351
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
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:211
Bproject::select
int select
Definition: mg_processing.h:339
CTFparam::volt
double volt()
Definition: ctf.h:83
Breconstruction::select
long select
Definition: mg_processing.h:283
ps_plot.h
Header file for postscript output functions.
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
project_set_defocus
int project_set_defocus(Bproject *project, double def_avg, double def_dev, double ast_angle)
Sets the defocus values of all the micrographs.
Definition: mg_ctf.cpp:1425
CTFparam::baseline_equation
Bstring baseline_equation()
Generates a baseline equation string from 4 to 10 coefficients.
Definition: ctf.cpp:165
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< long >
project_ctf_average
int project_ctf_average(Bproject *project, Bstring &psname)
Calculates or fits CTF curves to multiple power spectra.
Definition: mg_ctf.cpp:1221
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:205
img_ttf_apply
int img_ttf_apply(Bimage *p, CTFparam ctf, int action, double wiener, Vector3< long > tile_size, double tilt, double axis, double res_lo, double res_hi)
Applies or corrects for the tilted contrast transfer function (TTF).
Definition: mg_ctf.cpp:388
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
project_ctf_prepare
int project_ctf_prepare(Bproject *project, int action, double lores, double hires, Vector3< long > tile_size, double def_start, double def_end, double def_inc, Bstring &path, Bstring &newname, Bstring &label, int flags)
Calculates power spectra and optionally fits CTF curves.
Definition: mg_ctf.cpp:717
Bmicrograph::magnification
double magnification
Definition: mg_processing.h:212
Bmicrograph::fom
double fom
Definition: mg_processing.h:236
Vector3::min
Type min()
Definition: Vector3.h:169
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
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:100
Bparticle::def
double def
Definition: mg_processing.h:95
Breconstruction::fps
Bstring fps
Definition: mg_processing.h:291
mg_processing.h
Header file for micrograph processing.
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
CTFparam::baseline
vector< double > & baseline()
Definition: ctf.h:108
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
mg_ctf_prepare
Bimage * mg_ctf_prepare(Bmicrograph *mg, int action, double lores, double hires, Vector3< long > tile_size, double def_start, double def_end, double def_inc, int flags)
Definition: mg_ctf.cpp:522
CTFparam::envelope
vector< double > & envelope()
Definition: ctf.h:115
Bimage::images
long images()
Definition: Bimage.h:491
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:95
project_set_baseline_type
int project_set_baseline_type(Bproject *project, int type)
Sets the baseline type of all the micrographs.
Definition: mg_ctf.cpp:1716
mg_ctf_fit.h
Header file for CTF (contrast transfer function) functions.
NoTransform
Definition: Bimage.h:40
Bimage::fill
void fill(double v)
Definition: Bimage.h:698
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
project_set_envelope
int project_set_envelope(Bproject *project, int type, double *coeff)
Sets the envelope equations of all the micrographs.
Definition: mg_ctf.cpp:1653
findNextPowerOf
int findNextPowerOf(int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
Definition: utilities.cpp:433
Vector3::volume
double volume()
Definition: Vector3.h:235
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
project_set_Cs
int project_set_Cs(Bproject *project, double Cs)
Sets the spherical aberation constant of all the micrographs.
Definition: mg_ctf.cpp:1540
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
electron_wavelength
double electron_wavelength(double volt)
Calculates the wavelength in angstrom from the acceleration voltage.
Definition: ctf.cpp:403
Bstring::str
string str()
Definition: Bstring.h:42
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:367
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
CTFparam::alpha
double alpha()
Definition: ctf.h:91
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
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
Bcolumn::axis
long axis()
Definition: Bplot.h:68
CTFparam
Definition: ctf.h:26
Bplot
Definition: Bplot.h:146
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201