Bsoft  2.1.0
Bernard's software package
mg_tomo_resol.cpp
Go to the documentation of this file.
1 
9 #include "mg_tomo_resol.h"
10 #include "mg_tomo_rec.h"
11 #include "mg_reconstruct.h"
12 #include "rwimg.h"
13 #include "mg_ctf.h"
14 #include "Complex.h"
15 #include "linked_list.h"
16 #include "utilities.h"
17 
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20 
21 Bplot* img_calculate_FRC_curve(vector<Bimage*> parr, double hi_res, double sampling_ratio);
22 double plot_calculate_resolution(Bplot* plot, double cutoff);
23 int plot_resolution(Bplot* plot, double hi_res, Bstring& psfile, Bstring& title);
24 
26  long ft_size, int zsize, double scale, double hi_res,
27  Matrix3 matr, Matrix3 mat, int inplane);
28 
29 
62 vector<Bimage*> mg_tomo_res_reconstruct(Bproject* project, int micrograph_id, double hi_res,
63  double sampling_ratio, double scale, Vector3<long> size,
64  double fast_angle, int action, double wiener)
65 {
66  vector<Bimage*> parr;
67  long i;
68  int pad_factor(0);
69  Vector3<long> tile_size(128,128,1);
70 
71  Bfield* field = project->field;
72  Bmicrograph* mg_res;
73  Bmicrograph* mg;
74 
75  for ( mg_res = field->mg, i=0; mg_res && i < micrograph_id; mg_res = mg_res->next, i++ ) ;
76 
77  if ( !mg_res ) {
78  error_show("Error in mg_tomo_res_reconstruct", __FILE__, __LINE__);
79  cerr << "Micrograph number " << micrograph_id << " not found!" << endl << endl;
80  return parr;
81  }
82 
83  if ( !mg_res->select ) {
84  if ( verbose & VERB_FULL )
85  cout << "Skipping micrograph number %d!" << micrograph_id << endl << endl;
86  return parr;
87  }
88 
89  if ( mg_res->fmg.length() < 0 ) {
90  error_show("Error in mg_tomo_res_reconstruct", __FILE__, __LINE__);
91  cerr << "No micrograph image file name given for micrograph " << mg_res->id << endl;
92  return parr;
93  }
94 
95  if ( hi_res < 2*mg_res->pixel_size[0] )
96  hi_res = 2*mg_res->pixel_size[0];
97 
98  Bimage* pt;
99  Bimage* p = NULL;
100  if ( pad_factor < 1 && mg_res->fft.length() > 0 ) p = read_img(mg_res->fft, 1, mg_res->img_num);
101  else p = read_img(mg_res->fmg, 1, mg_res->img_num);
102 
103  p->sampling(mg_res->pixel_size);
104  p->origin(mg_res->origin[0], mg_res->origin[1], 0.0);
105 
106  if ( size[2] < 1 ) size[2] = p->sizeX();
107  if ( size.volume() < 1 ) size = Vector3<long>(p->size());
108  if ( size[2] > p->sizeX() ) size[2] = p->sizeX();
109  if ( size[2] > p->sizeY() ) size[2] = p->sizeY();
110 
111  long ft_size = findNextPowerOf((int)(pad_factor*size[0]*scale), 2);
112  if ( ft_size < p->sizeX() ) ft_size = p->sizeX();
113  if ( ft_size < p->sizeY() ) ft_size = p->sizeY();
114 
115  if ( verbose & VERB_DEBUG )
116  cout << "DEBUG mg_tomo_res_reconstruct: size=" << size << " ft_size=" << ft_size << endl;
117 
118  if ( action )
119  img_ttf_apply(p, *(mg_res->ctf), action, wiener,
120  tile_size, mg_res->tilt_angle, mg_res->tilt_axis, 0, 0);
121 
122  // Do transformation if not already done
123  if ( p->compound_type() == TSimple ) {
124  if ( pad_factor ) {
125  ft_size = findNextPowerOf((int)(pad_factor*size[0]*scale), 2);
127  }
128  p->pad(ft_size, FILL_AVERAGE, p->average());
129  p->fft();
131  }
132 
133  // Header structure for the final reconstruction
134  Bimage* prec = new Bimage(Float, TComplex, ft_size, ft_size, 1, 1);
135  prec->sampling(mg_res->pixel_size);
136  prec->origin(prec->size()/2);
137 
138  Bimage* prec2 = prec->copy();
139 
140  prec->next = new Bimage(Float, TSimple, prec->size(), 1);
141  prec2->next = new Bimage(Float, TSimple, prec2->size(), 1);
142 
143  float* fom = (float *) prec->next->data_pointer();
144  float* fom2 = (float *) prec2->next->data_pointer();
145 
146  long data_size = (long) prec->size().volume();
147 
148 // if ( verbose & VERB_PROCESS ) {
149  if ( verbose ) {
150  cout << "NLOO resolution test:" << endl;
151  cout << "Micrograph: " << mg_res->id << " (" << mg_res->img_num << ")" << endl;
152  cout << "Tilt angle: " << mg_res->tilt_angle*180.0/M_PI << endl;
153  if ( fast_angle )
154  cout << "Maximum angular offset: " << fast_angle*180.0/M_PI << endl;
155  cout << "Fourier transform size: " << ft_size << " x " << ft_size << endl;
156  cout << "Reconstruction size: " << size << endl;
157  cout << "Resolution limit: " << hi_res << " A" << endl;
158  cout << "Sampling ratio: " << sampling_ratio << endl;
159  if ( action )
160  cout << "CTF correction: " << action << " (wiener=" << wiener << ")" << endl;
161  }
162 
163  long nrec(0);
164  long nmg = count_list((char *) field->mg);
165 
166  for ( mg=field->mg; mg; mg=mg->next ) if ( mg->select )
167  if ( fabs(mg->tilt_angle - mg_res->tilt_angle) <= fast_angle ) {
168  if ( verbose )
169  cout << "Reading image " << mg->img_num << " (micrograph " << mg->id << ")" << endl;
170  pt = NULL;
171  if ( mg->fft.length() > 0 )
172  pt = read_img(mg->fft, 1, 0);
173  if ( !pt ) {
174  if ( ( pt = read_img(mg->fmg, 1, mg->img_num) ) == NULL ) {
175  error_show("mg_tomo_res_reconstruct", __FILE__, __LINE__);
176  return parr;
177  }
178  }
179 
180  if ( mg == mg_res ) mg->fom = p->average();
181 
182  pt->origin(mg->origin[0], mg->origin[1], 0.0);
183 
184  if ( action )
185  img_ttf_apply(pt, *(mg->ctf), action, wiener,
186  tile_size, mg->tilt_angle, mg->tilt_axis, 0, 0);
187 
188  if ( pt->compound_type() == TSimple ) {
189  pt->pad(ft_size, FILL_AVERAGE, pt->average());
190  pt->fft();
191  pt->phase_shift_to_origin();
192  }
193 
194  img_pack_2D_into_central_section_old(pt, prec, prec2, ft_size, size[2], 1, hi_res,
195  mg_res->matrix, mg->matrix, (mg==mg_res));
196 // img_pack_2D_into_central_section(pt, prec, prec2, ft_size, 1, hi_res,
197 // mg_res->matrix, mg->matrix, (mg==mg_res));
198 
199  delete pt;
200 
201  nrec++;
202 
203  if ( verbose & ( VERB_TIME | VERB_PROCESS ) ) {
204  cout << "Complete: " << nrec*100.0/nmg << "%\r";
205  cout.flush();
206  }
207 
208  }
209 
210  if ( nrec < 1 ) {
211  delete prec;
212  delete prec2;
213  error_show("Error in mg_tomo_res_reconstruct: No micrographs used in this reconstruction!", __FILE__, __LINE__);
214  return parr;
215  }
216 
217  if ( verbose )
218  cout << "Weighing reconstruction. " << endl;
219 
220  for ( i=0; i<data_size; i++ ) {
221  if ( fom[i] ) prec->set(i, prec->complex(i) / fom[i]);
222  if ( fom2[i] ) prec2->set(i, prec2->complex(i) / fom2[i]);
223  fom[i] = fom[i]/(fom[i] + 1);
224  fom2[i] = fom2[i]/(fom2[i] + 1);
225  }
226 
227  parr.push_back(p);
228  parr.push_back(prec);
229  parr.push_back(prec2);
230 
231  return parr;
232 }
233 
267 Bimage* mg_tomo_resolution(Bproject* project, int micrograph_id, double hi_res,
268  double sampling_ratio, double scale, Vector3<long> size,
269  double fast_angle, int action, double wiener, double cutoff, Bstring& psfile)
270 {
271  long i;
272  Bfield* field = project->field;
273  Bmicrograph* mg_res;
274 
275  for ( mg_res = field->mg, i=0; mg_res && i < micrograph_id; mg_res = mg_res->next, i++ ) ;
276 
277  if ( !mg_res ) {
278  error_show("Error in mg_tomo_resolution", __FILE__, __LINE__);
279  cerr << "Micrograph number " << micrograph_id << " not found!" << endl << endl;
280  return NULL;
281  }
282 
283  vector<Bimage*> parr = mg_tomo_res_reconstruct(project, micrograph_id, hi_res,
284  sampling_ratio, scale, size, fast_angle, action, wiener);
285 
286  Bplot* plot = img_calculate_FRC_curve(parr, hi_res, sampling_ratio);
287  double resolution = plot_calculate_resolution(plot, cutoff);
288  mg_res->fom = resolution;
289 
290  Bstring filename(parr[0]->file_name());
291  Bstring title = "Resolution for " + filename + ": image " + Bstring(mg_res->img_num+1, "%d");
292  if ( psfile.length() > 0 ) plot_resolution(plot, hi_res, psfile, title);
293 
294  if ( verbose )
295  cout << "Resolution: " << setprecision(2) << resolution << endl << endl;
296 
297 
298  delete parr[0];
299  delete parr[2];
300  delete plot;
301 
302  return parr[1];
303 }
304 
305 int plot_nloo3d(Bplot* plot)
306 {
307  long i, j, k, l, m, nr(plot->rows());
308 
309  for ( i=nr, j=2*nr, k=3*nr, l=4*nr, m=5*nr; i<2*nr; i++, j++, k++, l++, m++ )
310  (*plot)[i] = ((*plot)[m]/(*plot)[l])*sqrt((*plot)[j]/(*plot)[k]);
311 
312  return 0;
313 }
314 
346 vector<Bplot*> project_tomo_resolution(Bproject* project, double hi_res,
347  double sampling_ratio, double scale, Vector3<long> size,
348  double fast_angle, int action, double wiener, double cutoff)
349 {
350  long nmg, i;
351  Bfield* field = project->field;
352  Bmicrograph* mg = NULL;
353 // Bstring title("Micrograph resolution for a tilt series");
354  Bstring label;
355 
356  for ( nmg=0, field = project->field; field; field = field->next )
357  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) nmg++;
358 
359 /* Bplot* plot = new Bplot(1, nmg, 2);
360  plot->title(title);
361  plot->page(0).title(title);
362  plot->page(0).columns(2);
363  for ( i=0; i<2; i++ ) plot->page(0).column(i).number(i);
364  plot->page(0).column(0).label("TiltAngle");
365  plot->page(0).column(1).label("NLOO");
366  plot->page(0).column(1).type(2);
367  plot->page(0).column(0).axis(1);
368  plot->page(0).column(1).axis(3);
369  plot->page(0).column(1).color(0,0,0);
370 */
371  Bplot* mgplot = NULL;
372  Bplot* tomoplot = NULL;
373 
374  for ( i=0, field = project->field; field; field = field->next ) {
375  for ( mg = field->mg; mg; mg = mg->next, i++ ) if ( mg->select ) {
376  vector<Bimage*> parr = mg_tomo_res_reconstruct(project, i, hi_res,
377  sampling_ratio, scale, size, fast_angle, action, wiener);
378  if ( verbose )
379  cout << "Intensity: " << setprecision(2) << mg->fom << endl << endl;
380  mgplot = img_calculate_FRC_curve(parr, hi_res, sampling_ratio);
381  mg->fom = plot_calculate_resolution(mgplot, cutoff);
382  if ( verbose )
383  cout << "Resolution: " << setprecision(2) << mg->fom << endl << endl;
384  delete parr[0];
385  delete parr[1];
386  delete parr[2];
387  if ( tomoplot ) {
388  tomoplot->add(mgplot, 1);
389  delete mgplot;
390  } else {
391  tomoplot = mgplot;
392  }
393 // (*plot)[i] = mg->tilt_angle*180.0/M_PI;
394 // (*plot)[i+nmg] = mg->fom;
395  }
396  }
397 
398  plot_nloo3d(tomoplot);
399 
400 // plot->page(0).axis(1).label("Tilt Angle (degrees)");
401 // plot->page(0).axis(3).label("Resolution (A)");
402 
403  Bplot* tiltplot = plot_tilt_resolution(project);
404  label = Bstring(cutoff, "NLOO cutoff: %g");
405  tiltplot->page(0).add_text(label);
406 
407 // Bstring filename(parr[0]->file_name());
408 // Bstring title = "Resolution for " + filename + ": image " + Bstring(mg_res->img_num+1, "%d");
409 // if ( psfile.length() > 0 ) plot_resolution(plot, hi_res, psfile, title);
410 
411  vector<Bplot*> plot;
412  plot.push_back(tiltplot);
413  plot.push_back(tomoplot);
414 
415  return plot;
416 }
417 
432  double sampling_ratio, double fast_angle, double cutoff)
433 {
434  long i, j, nmg(0);
435  long npart(0);
436  int pad_factor(0);
437  double scale(1), resolution;
438  Bfield* field, *field_res;
439  Bmicrograph* mg, *mg_res;
440  Breconstruction* rec;
441  Bparticle* partlist = NULL;
442  Bparticle* recpart = NULL;
443  Bparticle* part = NULL, *part_res = NULL;
444  Bimage* prec, *prec2;
445  Bimage* pmg;
446  Bimage* ppart, *ppart_res = NULL;
447  Bplot* plot = NULL;
448  Bstring psfile;
449 
450  for ( rec = project->rec; rec; rec = rec->next )
451  if ( rec->part ) {
452  partlist = rec->part;
453  break;
454  }
455 
456  if ( !partlist ) {
457  cerr << "No particle list found!" << endl << endl;
458  return NULL;
459  }
460 
461  for ( nmg=0, field = project->field; field; field = field->next )
462  for ( mg = field->mg; mg; mg = mg->next ) nmg++;
463 
464  if ( !nmg ) {
465  cerr << "No micrographs found!" << endl << endl;
466  return NULL;
467  }
468 
469  for ( field = project->field; field; field = field->next ) {
470  for ( mg = field->mg; mg; mg = mg->next )
471  if ( mg && mg->part ) break;
472  if ( mg && mg->part ) break;
473  }
474 
475  if ( !mg || !mg->part ) {
476  cerr << "No micrograph particles found!" << endl << endl;
477  return NULL;
478  }
479 
480  double* res_avg = new double[nmg];
481  double* res_std = new double[nmg];
482  for ( i=0; i<nmg; i++ ) res_avg[i] = res_std[i] = 0;
483 
484  Vector3<long> boxsize(mg->box_size);
485 
486  if ( hi_res < 2*mg->pixel_size[0] ) hi_res = 2*mg->pixel_size[0];
487 
488  Vector3<double> realsize(boxsize[0]*mg->pixel_size[0], boxsize[1]*mg->pixel_size[1], 1);
489  double rad_scale = realsize[0];
490  if ( rad_scale < realsize[1] ) rad_scale = realsize[1];
491  if ( rad_scale < realsize[2] ) rad_scale = realsize[2];
492  if ( boxsize[0] > 256 ) rad_scale *= 256.0/boxsize[0];
493  long maxrad = (long) (rad_scale/hi_res);
494 
495  int ft_size = boxsize[0];
496  if ( pad_factor ) ft_size = part_ft_size(boxsize[0], scale, pad_factor);
497 
498  fft_plan planp = fft_setup_plan(ft_size, ft_size, 1, FFTW_FORWARD, 1);
499 
500  if ( verbose ) {
501  cout << "Calculating individual particle resolutions:" << endl;
502  cout << "Number of micrographs: " << nmg << endl;
503  cout << "Particle size: " << boxsize << endl;
504  cout << "Fourier transform size: " << ft_size << " x " << ft_size << endl;
505  cout << "High resolution limit: " << hi_res << " A" << endl;
506  cout << "FRC cutoff: " << cutoff << endl;
507  cout << endl;
508  }
509 
510  double s, sp, FRC, FRCp, fraction;
511  double* sum_r_2 = new double[maxrad] ;
512  double* sum_r2_2 = new double[maxrad] ;
513  double* sum_i_r = new double[maxrad] ;
514  double* sum_i_r2 = new double[maxrad] ;
515 
516  for ( npart=0, recpart = partlist; recpart; recpart = recpart->next ) {
517  if ( verbose ) {
518  cout << "Resolution for particle " << recpart->id << ":" << endl;
519  cout << "#mg\tAngle\tNLOO(" << cutoff << ")" << endl;
520  }
521 
522  for ( j=0; j<maxrad; j++ ) sum_r_2[j] = sum_r2_2[j] = sum_i_r[j] = sum_i_r2[j] = 0;
523 
524  for ( i=0, field_res = project->field; field_res; field_res = field_res->next ) if ( field_res->select ) {
525  for ( mg_res = field_res->mg; mg_res; mg_res = mg_res->next ) if ( mg_res->select ) {
526  for ( part_res = mg_res->part; part_res; part_res = part_res->next )
527  if ( recpart->id == part_res->id ) break;
528 
529  if ( part_res ) {
530 
531  prec = new Bimage(Float, TComplex, ft_size, ft_size, 1, 1);
532  prec->sampling(mg_res->pixel_size);
533  prec->origin(prec->size()/2);
534 
535  prec2 = prec->copy();
536 
537  prec->next = new Bimage(Float, TSimple, prec->size(), 1);
538  prec2->next = new Bimage(Float, TSimple, prec2->size(), 1);
539 
540  for ( field = project->field; field; field = field->next ) if ( field->select ) {
541  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select )
542  if ( fabs(mg->tilt_angle - mg_res->tilt_angle) <= fast_angle ) {
543  for ( part = mg->part; part; part = part->next )
544  if ( recpart->id == part->id ) break;
545 
546  if ( part ) {
547  if ( ( pmg = read_img(mg->fmg, 1, mg->img_num) ) == NULL ) {
548  error_show("project_tomo_particle_resolution", __FILE__, __LINE__);
549  return NULL;
550  }
551  ppart = pmg->extract(0, part->loc - boxsize/2, boxsize);
552  delete pmg;
553  ppart->sampling(part->pixel_size);
554 // ppart->image->origin(part->ori);
555  ppart->origin(part->ori);
556  ppart->image->view(part->view);
557  ppart->fft(planp);
558  ppart->phase_shift_to_origin();
559  img_pack_2D_into_central_section_old(ppart, prec, prec2,
560  ft_size, ppart->sizeX(), scale, hi_res,
561  mg_res->matrix, mg->matrix, (mg==mg_res));
562  if ( mg == mg_res ) ppart_res = ppart;
563  else delete ppart;
564  }
565  }
566  }
567  vector<Bimage*> parr;
568  parr.push_back(ppart_res);
569  parr.push_back(prec);
570  parr.push_back(prec2);
571  plot = img_calculate_FRC_curve(parr, hi_res, sampling_ratio);
572  resolution = plot_calculate_resolution(plot, cutoff);
573  delete ppart_res;
574  delete prec;
575  delete prec2;
576  for ( j=0; j<maxrad; j++ ) {
577  sum_r_2[j] += (*plot)[2*maxrad+j];
578  sum_r2_2[j] += (*plot)[3*maxrad+j];
579  sum_i_r[j] += (*plot)[4*maxrad+j];
580  sum_i_r2[j] += (*plot)[5*maxrad+j];
581  }
582  delete plot;
583  part_res->fom[0] = resolution;
584  res_avg[i] += resolution;
585  res_std[i] += resolution*resolution;
586  i++;
587  if ( verbose )
588  cout << i << tab << setprecision(2) << mg_res->tilt_angle*180.0/M_PI << tab << resolution << endl;
589  }
590  }
591  }
592  npart++;
593  if ( verbose ) {
594  cout << endl;
595  cout << "3D resolution: " << endl;
596  cout << "s(1/A)\tRes(A)\tNLOO3D" << endl;
597  sp = 0;
598  FRCp = 1;
599  resolution = 1/rad_scale;
600  for ( j=1; j<maxrad; j++ ) {
601  s = j/rad_scale;
602  if ( fabs(sum_i_r2[j]) < SMALLFLOAT || fabs(sum_i_r[j]) < SMALLFLOAT )
603  FRC = 0;
604  else
605  FRC = (sum_i_r2[j]*sqrt(sum_r_2[j]))/(sum_i_r[j]*sqrt(sum_r2_2[j]));
606  if ( FRC < 0 ) FRC = 0;
607  if ( FRC > cutoff ) resolution = 1/s;
608  if ( FRCp > cutoff && FRC <= cutoff ) {
609  fraction = (FRCp - cutoff)/(FRCp - FRC);
610  if ( sp ) resolution = (1-fraction)/sp + fraction/s;
611  }
612  sp = s;
613  FRCp = FRC;
614  cout << setprecision(4) << s << tab << setprecision(1) << 1/s << tab << setprecision(4) << FRC << endl;
615  }
616  cout << "NLOO3D resolution: " << resolution << endl << endl;
617  }
618  }
619 
620  delete[] sum_r_2;
621  delete[] sum_r2_2;
622  delete[] sum_i_r;
623  delete[] sum_i_r2;
624 
625  fft_destroy_plan(planp);
626 
627  Bstring title("Particle resolution for a tilt series");
628  plot = new Bplot(1, nmg, 3);
629  plot->title(title);
630  plot->page(0).title(title);
631  plot->page(0).columns(3);
632  for ( i=0; i<3; i++ ) plot->page(0).column(i).number(i);
633  plot->page(0).column(0).label("TiltAngle");
634  plot->page(0).column(1).label("NLOOavg");
635  plot->page(0).column(2).label("NLOOstd");
636 // plot->page(0).axis(1).min(0);
637 // plot->page(0).axis(1).max(1/hi_res);
638 // plot->page(0).axis(1).inc(0.1/hi_res);
639  plot->page(0).column(1).type(2);
640  plot->page(0).column(2).type(3);
641  plot->page(0).column(0).axis(1);
642  plot->page(0).column(1).axis(3);
643  plot->page(0).column(2).axis(3);
644  plot->page(0).column(1).color(0,0,0);
645  plot->page(0).column(2).color(1,0,0);
646 
647  Bstring label = Bstring(cutoff, "NLOO cutoff: %g");
648  plot->page(0).add_text(label);
649  label = Bstring(boxsize[0], "Box size: %g") + Bstring(boxsize[1], " x %g");
650  plot->page(0).add_text(label);
651 
652  double min(1e37), max(0);
653 
654  if ( verbose ) {
655  cout << "Average resolution for " << npart << " particles:" << endl;
656  cout << "#mg\tAngle\tFRCavg\tFRCstd" << endl;
657  }
658  for ( i=0, field = project->field; field; field = field->next ) {
659  for ( mg = field->mg; mg; mg = mg->next, i++ ) {
660  res_avg[i] /= npart;
661  res_std[i] = res_std[i]/npart - res_avg[i]*res_avg[i];
662  if ( res_std[i] > 0 ) res_std[i] = sqrt(res_std[i]);
663  else res_std[i] = 0;
664  if ( min > res_avg[i] - res_std[i] ) min = res_avg[i] - res_std[i];
665  if ( max < res_avg[i] + res_std[i] ) max = res_avg[i] + res_std[i];
666  (*plot)[i] = mg->tilt_angle*180.0/M_PI;
667  (*plot)[i+nmg] = res_avg[i];
668  (*plot)[i+2*nmg] = res_std[i];
669  if ( verbose )
670  cout << i+1 << tab << setprecision(2) << mg->tilt_angle*180.0/M_PI << tab <<
671  res_avg[i] << tab << res_std[i] << endl;
672  }
673  }
674  if ( verbose )
675  cout << endl;
676 
677  delete[] res_avg;
678  delete[] res_std;
679 
680  if ( verbose & VERB_DEBUG )
681  cout << "DEBUG project_tomo_particle_resolution: min=" << min << " max=" << max << endl;
682 
683  plot->page(0).axis(1).label("Tilt Angle (degrees)");
684  plot->page(0).axis(3).label("Resolution (A)");
685  plot->page(0).axis(3).min(min);
686  plot->page(0).axis(3).max(max);
687 
688  return plot;
689 }
690 
713  long ft_size, double scale, double hi_res,
714  Matrix3 matr, Matrix3 mat, int inplane)
715 {
716  if ( !p->data_pointer() ) return 0;
717 
718  prec->check_resolution(hi_res);
719 
720  if ( verbose & VERB_FULL )
721  cout << "Packing an image into reciprocal space up to " << hi_res << " A resolution" << endl << endl;
722 
723  long i, j, x, y, kx, ky;
724  long ix, iy, ixx, iyy, nover(0);
725  double w, dx, dy, d2;
726  Vector3<double> m, d(0,0,1), iv;
727 
728 // Vector3<double> vscale(prec->sizeX()/(scale*ft_size), prec->sizeY()/(scale*ft_size), 1/scale);
729 
730  float* fom = (float *) prec->next->data_pointer();
731  float* fom2 = (float *) prec2->next->data_pointer();
732 
733  int notinplane = 1 - inplane; // Flag to indicate if this image corresponds to testing image
734 
735  if ( verbose & VERB_FULL & inplane ) cout << "In plane image" << endl;
736  if ( verbose & VERB_FULL )
737  cout << mat << endl;
738 
739  double maxrad = p->sampling(0)[0]/hi_res;
740  double maxrad_sq = maxrad*maxrad; // Maximum radius squared on map scale
741  double ymin = floor(-maxrad*p->sizeY());
742  double ymax = -ymin;
743  double xmin = floor(-maxrad*p->sizeX());
744  double xmax = -xmin;
745 
746  // Vector to calculate z-shift
747  Vector3<double> vn(matr[2][0]/matr[2][2], matr[2][1]/matr[2][2], 0);
748 
749  matr = matr.transpose();
750 // matr = vscale * matr;
751 
752  for ( iv[1]=ymin; iv[1]<=ymax; iv[1]+=1 ) {
753  if ( iv[1] >= 0 ) y = (long)iv[1];
754  else y = (long)(iv[1] + p->sizeY());
755  dy = iv[1]/p->sizeY();
756  for ( iv[0]=xmin; iv[0]<=xmax; iv[0]+=1 ) {
757  if ( iv[0] >= 0 ) x = (long)iv[0];
758  else x = (long)(iv[0] + p->sizeX());
759  dx = iv[0]/p->sizeX();
760  d2 = dx*dx + dy*dy;
761  if ( d2 <= maxrad_sq ) {
762  m = mat * iv;
763  m[2] = m.scalar(vn);
764  m = matr * m;
765  d[2] = fabs(m[2]);
766  if ( d[2] <= 1 ) {
767  ix = (long) floor(m[0]);
768  iy = (long) floor(m[1]);
769  d[0] = m[0] - ix;
770  d[1] = m[1] - iy;
771  i = y*p->sizeX() + x;
772  for ( ky=0; ky<2; ky++ ) {
773  iyy = iy + ky;
774  if ( iyy < 0 ) iyy += prec->sizeY();
775  d[1] = 1 - d[1];
776  for ( kx=0; kx<2; kx++ ) {
777  ixx = ix + kx;
778  if ( ixx < 0 ) ixx += prec->sizeX();
779  d[0] = 1 - d[0];
780  j = iyy*prec->sizeX() + ixx;
781  w = d.volume();
782  fom[j] += w;
783  prec->add(j, p->complex(i) * w);
784  if ( notinplane ) {
785  fom2[j] += w;
786  prec2->add(j, p->complex(i) * w);
787  }
788  }
789  }
790  nover++;
791  }
792  }
793  }
794  }
795 
796  return nover;
797 }
798 
800  long ft_size, int zsize, double scale, double hi_res,
801  Matrix3 matr, Matrix3 mat, int inplane)
802 {
803  if ( !p->data_pointer() ) return 0;
804 
805  prec->check_resolution(hi_res);
806 
807  if ( verbose & VERB_FULL )
808  cout << "Packing an image into reciprocal space up to " << hi_res << " A resolution" << endl << endl;
809 
810  long i, j, x, y, kx, ky;
811  long ix, iy, ixx, iyy;
812  double w, d2;
813  Vector3<double> m, d, iv;
814 
815  Vector3<double> invsize(1.0/prec->sizeX(), 1.0/prec->sizeY(), 1.0/zsize);
816  Vector3<double> vscale(prec->sizeX()/(scale*ft_size), prec->sizeY()/(scale*ft_size), zsize/(scale*ft_size));
817 
818  float* fom = (float *) prec->next->data_pointer();
819  float* fom2 = (float *) prec2->next->data_pointer();
820 
821  int notinplane = 1 - inplane; // Flag to indicate if this image corresponds to testing image
822 
823  if ( verbose & VERB_FULL & inplane ) cout << "In plane image" << endl;
824  if ( verbose & VERB_FULL )
825  cout << mat << endl;
826 
827  double maxrad = prec->sampling(0)[0]/hi_res;
828  double maxrad_sq = maxrad*maxrad; // Maximum radius squared on map scale
829  double ymin = floor(-maxrad*p->sizeY());
830  double ymax = -ymin;
831  double xmin = floor(-maxrad*p->sizeX());
832  double xmax = -xmin;
833 
834  Vector3<double> vt(mat[0][2], mat[1][2], 0);
835  if ( vt[0] || vt[1] ) vt.normalize();
836  vt *= 1 - mat[2][2]/matr[2][2];
837 // if ( fabs(mat[2]) > fabs(mat[5]) ) { if ( mat[2] > 0 ) vt *= -1; }
838 // else { if ( mat[5] > 0 ) vt *= -1; }
839 // if ( tilt_angle < 0 ) vt *= -1;
840  if ( mat[0][2] > 0 ) vt *= -1;
841 // vt = 0;
842 
843 // cout << mat << endl;
844 
845  mat = mat.transpose();
846  mat = vscale * mat;
847  mat = mat * matr;
848 
849  for ( iv[1]=ymin; iv[1]<=ymax; iv[1]+=1 ) {
850  if ( iv[1] >= 0 ) y = (long)iv[1];
851  else y = (long)(p->sizeY() + iv[1]);
852  for ( iv[0]=xmin; iv[0]<=xmax; iv[0]+=1 ) {
853  if ( iv[0] >= 0 ) x = (long)iv[0];
854  else x = (long)(p->sizeX() + iv[0]);
855  m = mat * iv;
856  m += iv * vt;
857  d[2] = fabs(m[2]);
858  if ( d[2] <= 1 ) {
859 // d[2] = 1 - d[2];
860  d[2] = 1;
861  d2 = (m * invsize).length2();
862  if ( d2 <= maxrad_sq ) {
863  ix = (long) floor(m[0]);
864  iy = (long) floor(m[1]);
865  d[0] = m[0] - ix;
866  d[1] = m[1] - iy;
867  i = y*p->sizeX() + x;
868  for ( ky=0; ky<2; ky++ ) {
869  iyy = iy + ky;
870  if ( iyy < 0 ) iyy += prec->sizeY();
871  d[1] = 1 - d[1];
872  for ( kx=0; kx<2; kx++ ) {
873  ixx = ix + kx;
874  if ( ixx < 0 ) ixx += prec->sizeX();
875  d[0] = 1 - d[0];
876  j = iyy*prec->sizeX() + ixx;
877  w = d.volume();
878  fom[j] += w;
879  prec->add(j, p->complex(i) * w);
880  if ( notinplane ) {
881  fom2[j] += w;
882  prec2->add(j, p->complex(i) * w);
883  }
884  }
885  }
886  }
887  }
888  }
889  }
890 
891  return 0;
892 }
893 
894 
902 Bplot* img_calculate_FRC_curve(vector<Bimage*> parr, double hi_res, double sampling_ratio)
903 {
904  if ( parr.size() < 3 ) return NULL;
905 
906  Bimage* p = parr[0];
907  Bimage* prec = parr[1];
908  Bimage* prec2 = parr[2];
909 
910  if ( !p->data_pointer() ) return NULL;
911 
912  prec->check_resolution(hi_res);
913 
914  if ( sampling_ratio < 1 ) sampling_ratio = 1;
915 
916  long i, j, x, y, z, iradius, iradius2, nt(0), nf(0);
917  long xx, yy, zz;
918  double rx, ry, rz, radius, fraction, fraction2, v;
919 
920  Vector3<double> realsize(p->real_size());
921  Vector3<double> freq_scale(1.0/realsize);
922  double rad_scale_max(realsize[0]/sampling_ratio);
923  double rad_scale = realsize[0];
924  if ( rad_scale < realsize[1] ) rad_scale = realsize[1];
925  if ( rad_scale < realsize[2] ) rad_scale = realsize[2];
926 
927 // if ( p->sizeX() > rad_scale_max ) rad_scale *= rad_scale_max/p->sizeX();
928  if ( rad_scale > rad_scale_max ) rad_scale = rad_scale_max;
929  long maxrad = (long) (rad_scale/hi_res);
930 
931  if ( verbose & VERB_DEBUG )
932  cout << "DEBUG img_calculate_FRC_curve: maxrad=" << maxrad << endl;
933 
934  vector<double> n(maxrad);
935  vector<double> sum_i_2(maxrad);
936  vector<double> sum_r_2(maxrad);
937  vector<double> sum_r2_2(maxrad);
938  vector<double> sum_i_r(maxrad);
939  vector<double> sum_i_r2(maxrad);
940 
941  for ( i=0; i<maxrad; i++ )
942  n[i] = sum_i_2[i] = sum_r_2[i] = sum_r2_2[i] = sum_i_r[i] = sum_i_r2[i] = 0;
943 
944  float* fom = (float *) prec2->next->data_pointer();
945 
946  for ( i=z=0; z<p->sizeZ(); z++ ) {
947  zz = z;
948  if ( z > (p->sizeZ() - 1)/2 ) zz -= p->sizeZ();
949  rz = zz*freq_scale[2];
950  for ( y=0; y<p->sizeY(); y++ ) {
951  yy = y;
952  if ( y > (p->sizeY() - 1)/2 ) yy -= p->sizeY();
953  ry = yy*freq_scale[1];
954  for ( x=0; x<p->sizeX(); x++, i++ ) {
955  xx = x;
956  if ( x > (p->sizeX() - 1)/2 ) xx -= p->sizeX();
957  rx = xx*freq_scale[0];
958  radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
959  iradius = (long) radius;
960  iradius2 = iradius + 1;
961 // if ( fom[i] && ( iradius < maxrad ) ) {
962  if ( iradius2 < maxrad ) {
963  fraction = radius - iradius;
964  fraction2 = 1.0 - fraction;
965  v = (p->complex(i)).power();
966  sum_i_2[iradius] += fraction2*v;
967  sum_i_2[iradius2] += fraction*v;
968  v = (prec->complex(i)).power();
969  sum_r_2[iradius] += fraction2*v;
970  sum_r_2[iradius2] += fraction*v;
971  v = (prec2->complex(i)).power();
972  sum_r2_2[iradius] += fraction2*v;
973  sum_r2_2[iradius2] += fraction*v;
974  v = (p->complex(i)).real()*(prec->complex(i)).real() + (p->complex(i)).imag()*(prec->complex(i)).imag();
975  sum_i_r[iradius] += fraction2*v;
976  sum_i_r[iradius2] += fraction*v;
977  v = (p->complex(i)).real()*(prec2->complex(i)).real() + (p->complex(i)).imag()*(prec2->complex(i)).imag();
978  sum_i_r2[iradius] += fraction2*v;
979  sum_i_r2[iradius2] += fraction*v;
980  n[iradius] += fraction2;
981  n[iradius2] += fraction;
982  nt++;
983  if ( fom[i] ) nf++;
984  }
985  }
986  }
987  }
988 
989  Bplot* plot = new Bplot(1, maxrad, 6);
990  (*plot)[0] = 0;
991  (*plot)[maxrad] = 1;
992 
993  double s, FRC;
994 
995  if ( verbose & VERB_PROCESS )
996  cout << "Pixel\ts\tResol\tsumI2\tsumR2\tsumRo2\tsumIR\tsumIRo\tFRC\tNum" << endl;
997  else if ( verbose )
998  cout << "Pixel\ts\tResol\tFRC" << endl;
999  for ( i=1; i<maxrad; i++ ) {
1000  s = i/rad_scale;
1001  FRC = 1.;
1002  if ( sum_i_r[i] < SMALLFLOAT || sum_r2_2[i] < SMALLFLOAT )
1003  FRC = 0;
1004  else
1005 // FRC = (sum_i_r2[i]*sqrt(sum_r_2[i]))/(sum_i_r[i]*sqrt(sum_r2_2[i]));
1006  FRC = (sum_i_r2[i]/sum_i_r[i])*sqrt(sum_r_2[i]/sum_r2_2[i]);
1007  if ( FRC > 1 ) FRC = 1;
1008  if ( FRC < 0 ) FRC = 0;
1009  if ( verbose & VERB_PROCESS )
1010  cout << i << tab
1011  << setprecision(4) << s << tab
1012  << setprecision(2) << 1/s << tab
1013  << setprecision(0) << sum_i_2[i] << tab
1014  << sum_r_2[i] << tab << sum_r2_2[i] << tab
1015  << sum_i_r[i] << tab << sum_i_r2[i] << tab
1016  << setprecision(4) << FRC << tab
1017  << setprecision(0) << n[i] << endl;
1018  else if ( verbose )
1019  cout << i << tab
1020  << setprecision(4) << s << tab
1021  << setprecision(2) << 1/s << tab
1022  << setprecision(4) << FRC << endl;
1023  (*plot)[i] = s;
1024  j = i + maxrad;
1025  (*plot)[j] = FRC;
1026  j += maxrad;
1027  (*plot)[j] = sum_r_2[i];
1028  j += maxrad;
1029  (*plot)[j] = sum_r2_2[i];
1030  j += maxrad;
1031  (*plot)[j] = sum_i_r[i];
1032  j += maxrad;
1033  (*plot)[j] = sum_i_r2[i];
1034  }
1035 
1036  if ( verbose & VERB_PROCESS ) {
1037  cout << "Total voxels: " << nt << endl;
1038  cout << "Coverage: " << nf << " (" << nf*100.0/nt << " %)" << endl;
1039  }
1040 
1041  return plot;
1042 }
1043 
1050 double plot_calculate_resolution(Bplot* plot, double cutoff)
1051 {
1052  double s, sp(0), FRC, FRCp(1), fraction, resolution(1000);
1053  long i, maxrad = (long) plot->rows();
1054 
1055  for ( i=1; i<maxrad; i++ ) {
1056  s = (*plot)[i];
1057  FRC = (*plot)[i+maxrad];
1058  if ( FRC > cutoff ) resolution = 1/s;
1059  if ( FRCp > cutoff && FRC <= cutoff ) {
1060  fraction = (FRCp - cutoff)/(FRCp - FRC);
1061  if ( sp ) resolution = (1-fraction)/sp + fraction/s;
1062  }
1063  sp = s;
1064  FRCp = FRC;
1065  }
1066 
1067  Bstring txt = Bstring(cutoff, "FSC(%g): ") + Bstring(resolution, "%g A");
1068  plot->page(0).add_text(txt);
1069 
1070  return resolution;
1071 }
1072 
1081 int plot_resolution(Bplot* plot, double hi_res, Bstring& psfile, Bstring& title)
1082 {
1083  plot->title("Resolution");
1084  plot->page(0).title(title);
1085  plot->page(0).columns(2);
1086  plot->page(0).column(1).number(1);
1087  plot->page(0).column(0).label("Resolution(A)");
1088  plot->page(0).column(1).label("FRC");
1089  plot->page(0).axis(1).min(0);
1090  plot->page(0).axis(1).max(1/hi_res);
1091  plot->page(0).axis(1).inc(0.1/hi_res);
1092  plot->page(0).axis(1).flags(1);
1093  plot->page(0).axis(3).min(0);
1094  plot->page(0).axis(3).max(1);
1095  plot->page(0).axis(3).inc(0.1);
1096  plot->page(0).column(1).type(2);
1097  plot->page(0).column(0).axis(1);
1098  plot->page(0).column(1).axis(3);
1099 
1100  if ( psfile.length() > 0 ) ps_plot(psfile, plot);
1101 
1102  return 0;
1103 }
1104 
1113 {
1114  long nmg(0), i;
1115  Bfield* field = project->field;
1116  Bmicrograph* mg = NULL;
1117  Bstring title("Micrograph resolution for a tilt series");
1118 
1119  for ( nmg=0, field = project->field; field; field = field->next )
1120  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) nmg++;
1121 
1122  Bplot* plot = new Bplot(1, nmg, 2);
1123  plot->title(title);
1124  plot->page(0).title(title);
1125  plot->page(0).columns(2);
1126  for ( i=0; i<2; i++ ) plot->page(0).column(i).number(i);
1127  plot->page(0).column(0).label("TiltAngle");
1128  plot->page(0).column(1).label("NLOO");
1129  plot->page(0).column(1).type(2);
1130  plot->page(0).column(0).axis(1);
1131  plot->page(0).column(1).axis(3);
1132  plot->page(0).column(1).color(0,0,0);
1133 
1134  for ( i=0, field = project->field; field; field = field->next ) {
1135  for ( mg = field->mg; mg; mg = mg->next, i++ ) if ( mg->select ) {
1136  (*plot)[i] = mg->tilt_angle*180.0/M_PI;
1137  (*plot)[i+nmg] = mg->fom;
1138  }
1139  }
1140 
1141  plot->page(0).axis(1).label("Tilt Angle (degrees)");
1142  plot->page(0).axis(3).label("Resolution (A)");
1143 
1144  return plot;
1145 }
mg_reconstruct.h
Functions for reconstruction.
length2
double length2(vector< T > v)
Definition: Vector3.h:519
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:500
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:129
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Baxis::flags
long flags()
Definition: Bplot.h:38
Bparticle::view
View view
Definition: mg_processing.h:102
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bstring
Definition: Bstring.h:29
Bplot::rows
void rows(long n)
Definition: Bplot.h:212
Bimage::next
Bimage * next
Definition: Bimage.h:179
Bparticle
Definition: mg_processing.h:90
Matrix3::transpose
Matrix3 transpose() const
Definition: Matrix3.h:268
Bproject::field
Bfield * field
Definition: mg_processing.h:346
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2702
Bcolumn::color
double * color()
Definition: Bplot.h:76
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:220
Vector3< long >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
mg_tomo_res_reconstruct
vector< Bimage * > mg_tomo_res_reconstruct(Bproject *project, int micrograph_id, double hi_res, double sampling_ratio, double scale, Vector3< long > size, double fast_angle, int action, double wiener)
Estimating the resolution of one micrograph in an aligned tilt series.
Definition: mg_tomo_resol.cpp:62
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Complex.h
Class for complex numbers.
img_pack_2D_into_central_section_old
int img_pack_2D_into_central_section_old(Bimage *p, Bimage *prec, Bimage *prec2, long ft_size, int zsize, double scale, double hi_res, Matrix3 matr, Matrix3 mat, int inplane)
Definition: mg_tomo_resol.cpp:799
TComplex
@ TComplex
Definition: Bimage.h:60
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
part_ft_size
int part_ft_size(int xsize, double scale, int pad_factor)
Sets the Fourier transform size for 2D particle images for reconstruction.
Definition: mg_reconstruct.cpp:38
Bplot
Definition: Bplot.h:146
img_calculate_FRC_curve
Bplot * img_calculate_FRC_curve(vector< Bimage * > parr, double hi_res, double sampling_ratio)
Calculates the FRC/FSC for a micrograph or particle image in a series.
Definition: mg_tomo_resol.cpp:902
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:177
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
Bcolumn::type
long type()
Definition: Bplot.h:66
plot_resolution
int plot_resolution(Bplot *plot, double hi_res, Bstring &psfile, Bstring &title)
Plots the resolution curve in a plot structure.
Definition: mg_tomo_resol.cpp:1081
Bfield
Definition: mg_processing.h:260
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:249
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
Bcolumn::axis
long axis()
Definition: Bplot.h:68
mg_tomo_resol.h
Functions to assess the resoltion of a tomographic tilt series.
Bpage::axis
Baxis & axis(long id)
Definition: Bplot.h:117
Bpage::title
Bstring & title()
Definition: Bplot.h:100
project
Bproject * project
Definition: bshow.cpp:33
Matrix3
Definition: Matrix3.h:18
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
TSimple
@ TSimple
Definition: Bimage.h:59
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
plot_calculate_resolution
double plot_calculate_resolution(Bplot *plot, double cutoff)
Calculates the resolution estimate from a FRC/FSC curve.
Definition: mg_tomo_resol.cpp:1050
Vector3::normalize
double normalize()
Definition: Vector3.h:238
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
Baxis::inc
double inc()
Definition: Bplot.h:34
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:46
Bimage::fft
int fft()
Definition: Bimage.h:830
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:219
Bpage::add_text
void add_text(Bstring &s)
Definition: Bplot.h:122
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1371
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Bproject
Definition: mg_processing.h:336
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
Bplot::title
Bstring & title()
Definition: Bplot.h:194
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1027
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Baxis::min
double min()
Definition: Bplot.h:30
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
project_tomo_particle_resolution
Bplot * project_tomo_particle_resolution(Bproject *project, double hi_res, double sampling_ratio, double fast_angle, double cutoff)
Estimates the resolution for each particle image in each micrograph.
Definition: mg_tomo_resol.cpp:431
Baxis::label
Bstring & label()
Definition: Bplot.h:28
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
Bimage::check_resolution
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
Definition: Bimage.cpp:635
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
Breconstruction
Definition: mg_processing.h:283
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
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:225
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
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
Bfield::select
long select
Definition: mg_processing.h:265
plot_tilt_resolution
Bplot * plot_tilt_resolution(Bproject *project)
Plots the estimated resolution against the tilt angle.
Definition: mg_tomo_resol.cpp:1112
Vector3::volume
double volume()
Definition: Vector3.h:237
Bmicrograph::fom
double fom
Definition: mg_processing.h:239
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_tomo_resolution
Bimage * mg_tomo_resolution(Bproject *project, int micrograph_id, double hi_res, double sampling_ratio, double scale, Vector3< long > size, double fast_angle, int action, double wiener, double cutoff, Bstring &psfile)
Estimating the resolution of one micrograph in an aligned tilt series.
Definition: mg_tomo_resol.cpp:267
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
linked_list.h
Header file for generalized linked list functions.
Bmicrograph::select
long select
Definition: mg_processing.h:204
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:284
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:347
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
plot_nloo3d
int plot_nloo3d(Bplot *plot)
Definition: mg_tomo_resol.cpp:305
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:216
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
img_pack_2D_into_central_section
long img_pack_2D_into_central_section(Bimage *p, Bimage *prec, Bimage *prec2, long ft_size, double scale, double hi_res, Matrix3 matr, Matrix3 mat, int inplane)
Packs a 2D Fourier transform into a 3D reciprocal space volume.
Definition: mg_tomo_resol.cpp:712
verbose
int verbose
Bcolumn::number
long number()
Definition: Bplot.h:61
project_tomo_resolution
vector< Bplot * > project_tomo_resolution(Bproject *project, double hi_res, double sampling_ratio, double scale, Vector3< long > size, double fast_angle, int action, double wiener, double cutoff)
Estimating the resolution of the tomogram from an aligned tilt series.
Definition: mg_tomo_resol.cpp:346
Float
@ Float
Definition: utilities.h:161
Baxis::max
double max()
Definition: Bplot.h:32
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bplot::add
void add(Bplot *p, long start=0)
Definition: Bplot.h:245
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
findNextPowerOf
int findNextPowerOf(int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
Definition: utilities.cpp:397
Bparticle::id
int id
Definition: mg_processing.h:93
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
Bmicrograph::fft
Bstring fft
Definition: mg_processing.h:210
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284