Bsoft  2.1.0
Bernard's software package
mg_reconstruct.cpp
Go to the documentation of this file.
1 
9 #include "rwimg.h"
10 #include "rwmg.h"
11 #include "mg_processing.h"
12 #include "mg_select.h"
13 #include "mg_img_proc.h"
14 #include "mg_particle_select.h"
15 #include "mg_reconstruct.h"
16 #include "mg_ctf.h"
17 #include "Complex.h"
18 #include "symmetry.h"
19 #include "utilities.h"
20 
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 
24 
25 // Declaration of global variables
26 extern int verbose; // Level of output to the screen
27 
38 int part_ft_size(int xsize, double scale, int pad_factor)
39 {
40  if ( xsize <= 0 ) {
41  error_show("Error in part_ft_size", __FILE__, __LINE__);
42  cerr << "Size not set!" << endl << endl;
43  return 0;
44  }
45 
46  int ft_size(xsize);
47 
48  if ( scale > 1 ) ft_size = (int) (xsize*scale);
49 
50  if ( pad_factor < 1 ) return ft_size;
51 
52  if ( pad_factor > 8 ) pad_factor = 8;
53 
54  ft_size = findNextPowerOf((int)(pad_factor*xsize*scale), 2);
55 
56  if ( ft_size < xsize )
57 // ft_size = findNextPowerOf(pad_factor*xsize, 2);
58  ft_size = findNextPowerOf(xsize, 2);
59 
60 // if ( ft_size < xsize/scale )
61 // ft_size = findNextPowerOf((int)(xsize/scale), 2);
62 
63  return ft_size;
64 }
65 
100 Bimage* particle_reconstruct(Bparticle* partlist, Bsymmetry* sym, int sym_mode,
101  double hi_res, Vector3<double> scale, Vector3<long> size,
102  int ft_size, fft_plan plan, int interp_type,
103  int ctf_action, double wiener, int twoD_flag,
104  int bootstrap, int first)
105 {
106  random_seed();
107 
108  Bmicrograph* mg = partlist->mg;
109  Bparticle* part = partlist;
110 
111  Vector3<double> pixel_size(part->pixel_size/scale);
112  pixel_size[1] = pixel_size[0];
113  if ( twoD_flag ) pixel_size[2] = 1; // Isotropic sampling in 2D
114  else pixel_size[2] = pixel_size[0]; // Isotropic sampling in 3D
115 
116  Bimage* p;
117  Bimage* prec = new Bimage(Float, TComplex, size, 1);
118  prec->sampling(pixel_size);
119 // prec->origin(prec->size()/2);
120 
121  prec->check_resolution(hi_res);
122 
123  long nsel = particle_count(partlist);
124 
125  if ( verbose & VERB_DEBUG )
126  cout << "DEBUG particle_reconstruct: nsel = " << nsel << endl;
127 
128  CTFparam em_ctf;
129 
130  long nrec(0), img_num;
131  double part_weight(1), pad_ratio(1);
132  Vector3<double> part_scale(scale);
133  View view;
134  Bstring partfile;
135 
136 // cout << "CTF action = " << ctf_action << endl;
137 // cout << "volt=" << partlist->mg->ctf->volt() << endl;
138 
139  for ( part = partlist; part; part = part->next ) {
140 // cout << "Particle: " << part->id << endl;
141 // cout << "pixel_size=" << part->pixel_size << endl;
142  mg = part->mg;
143  if ( mg->ctf ) em_ctf.update(mg->ctf);
144  partfile = mg->fpart;
145  img_num = part->id - 1;
146  if ( partfile.length() < 1 ) {
147  partfile = part->fpart;
148  img_num = 0;
149  }
150  if ( ( p = read_img(partfile, 1, img_num) ) == NULL ) {
151  error_show("particle_reconstruct", __FILE__, __LINE__);
152  return NULL;
153  }
154 
155  p->change_type(Float);
156  p->rescale_to_avg_std(0, 1);
158  p->sampling(part->pixel_size);
159 // cout << "particle sampling = " << p->sampling(0) << endl;
160 
161  // set the origin
162  if ( part->ori[0] <= 0 ) {
163  if ( p->image->origin()[0] > 0 ) part->ori = p->image->origin();
164  else part->ori = prec->image->origin();
165  }
166  part->ori[2] = 0;
167 // p->image->origin(part->ori);
168  p->origin(part->ori);
169 
170  // set the view
171  p->view(part->view);
172  if ( sym_mode == 2 ) view = random_symmetric_view(part->view, sym);
173  else view = part->view;
174 
175  if ( prec->sizeZ() < 2 ) {
176  if ( p->image->view()[2] >= 0 ) p->image->view(0,0,1,p->image->view().angle());
177  else p->image->view(0,0,-1,p->image->view().angle());
178  }
179 
180  // set the scaling
181  if ( part->mag > 0 ) part_scale = scale/part->mag;
182  else part_scale = scale;
183 
184  if ( part->def > 0 ) em_ctf.defocus_average(part->def);
185 
186  part_weight = 1;
187  if ( bootstrap ) part_weight = part->sel;
188 
189  pad_ratio = ft_size*1.0L/p->sizeX();
190 
191  if ( pad_ratio > 1 ) {
192 // pad_ratio *= pad_ratio;
193  pad_ratio *= pad_ratio*0.6;
194 // pad_ratio *= pad_ratio*M_PI/4.0;
195 // pad_ratio *= sqrt(pad_ratio);
196  part_weight /= pad_ratio;
197  p->pad(ft_size, FILL_BACKGROUND);
198 // p->pad(ft_size, FILL_AVERAGE, p->average());
199 // p->pad(ft_size, FILL_USER, 0);
200  }
201 
202  p->fft(plan, 1);
204 
205  if ( ctf_action ) img_ctf_apply(p, em_ctf, ctf_action, wiener, 0, hi_res);
206 
207  if ( sym_mode )
208  prec->fspace_pack_2D(p, view.matrix(), hi_res, 0, part_scale, part_weight, interp_type);
209  else
210  prec->fspace_pack_2D(p, view, sym, hi_res, 0, part_scale, part_weight, interp_type);
211 
212  if ( mg->ctf ) em_ctf.defocus_average(mg->ctf->defocus_average());
213 
214  delete p;
215 
216  nrec++;
217 
218  if ( first && ( verbose & ( VERB_TIME | VERB_PROCESS | VERB_RESULT ) ) )
219  cerr << "Complete: " << setprecision(3)
220  << nrec*100.0/nsel << " % \r" << flush;
221  }
222 
223  prec->image->FOM(nrec);
224 
225  if ( verbose & VERB_FULL )
226  cout << "Particles used: " << nrec << endl << endl;
227 
228  return prec;
229 }
230 
247  int num_select, int bootstrap)
248 {
249  Bfield* field = project->field;
250  Bmicrograph* mg = field->mg;
251  Breconstruction* rec = project->rec;
252  Bparticle* part = mg->part;
253  Bparticle* partlist = NULL;
254 
255  if ( verbose & VERB_DEBUG )
256  cout << "DEBUG project_reconstruction_partlist: num_select = " << num_select << endl;
257 
258  long psel;
259 
260  if ( project->select < 1 ) {
261  for ( field = project->field; field; field = field->next ) {
262  for ( mg = field->mg; mg; mg = mg->next ) {
263  for ( part = mg->part; part; part = part->next ) {
264  psel = 0;
265  if ( part->sel ) {
266  if ( bootstrap ) {
267  psel = 1;
268  } else if ( num_select < 0 ) {
269  psel = 1;
270  } else if ( part->sel == num_select ) {
271  psel = 1;
272  }
273  }
274  if ( psel ) // Use only selected images
275  particle_copy(&partlist, part);
276  }
277  }
278  }
279  } else {
280  for ( rec = project->rec; rec; rec = rec->next ) {
281  for ( part = rec->part; part; part = part->next ) {
282  psel = 0;
283  if ( part->sel ) {
284  if ( bootstrap ) {
285  psel = 1;
286  } else if ( num_select < 0 ) {
287  psel = 1;
288  } else if ( part->sel == num_select ) {
289  psel = 1;
290  }
291  }
292  if ( psel ) // Use only selected images
293  particle_copy(&partlist, part);
294  }
295  }
296  }
297 
298 /* if ( num_select == 4) {
299  cout << num_select;
300  for ( part = partlist; part; part = part->next ) cout << tab << part->id;
301  cout << endl;
302  }
303 */
304  return partlist;
305 }
306 
331 Bimage* img_reconstruction_sum_weigh(Bimage** pacc, int imap, int nmaps, int maps_per_class, double hi_res)
332 {
333  int iclass = imap/nmaps;
334 
335  Bimage* prec = new Bimage(Float, TComplex, pacc[0]->size(), pacc[0]->images());
336  prec->sampling(pacc[0]->sampling(0));
337  prec->fourier_type(Standard);
338 
339  prec->next = new Bimage(Float, TSimple, prec->size(), prec->images());
340  prec->next->next = new Bimage(Float, TSimple, prec->size(), prec->images());
341  prec->next->next->next = new Bimage(Float, TSimple, prec->size(), prec->images());
342  float* fom = (float *) prec->next->data_pointer();
343  float* weight = (float *) prec->next->next->data_pointer();
344  float* weight2 = (float *) prec->next->next->next->data_pointer();
345 
346  long i, j, k, nv(0);
347  long ds = prec->image_size();
348  float* fom_acc;
349  float* w_acc;
350  float* w2_acc;
351 
352  long st(0), inc(1);
353  if ( nmaps == 2 ) {
354  st = imap%2;
355  inc = 2;
356  }
357  if ( nmaps == 3 && imap%3 ) {
358  st = imap%3 - 1;
359  inc = 2;
360  }
361 
362  if ( verbose & VERB_DEBUG ) {
363  cout << "DEBUG img_reconstruction_sum_weigh: maps_per_class=" << maps_per_class << endl;
364  cout << "DEBUG img_reconstruction_sum_weigh: iclass=" << iclass << endl;
365  cout << "DEBUG img_reconstruction_sum_weigh: st=" << st << endl;
366  cout << "DEBUG img_reconstruction_sum_weigh: inc=" << inc << endl;
367  }
368 
369 // double ssw(0);
370 // cout << "maps_per_class = " << maps_per_class << endl;
371  for ( i=iclass*maps_per_class+st, j=0; j<maps_per_class; i+=inc, j+=inc ) {
372  if ( verbose & VERB_DEBUG )
373  cout << "DEBUG img_reconstruction_sum_weigh: Doing map " << i << endl;
374  fom_acc = (float *) pacc[i]->next->data_pointer();
375  w_acc = (float *) pacc[i]->next->next->data_pointer();
376  w2_acc = (float *) pacc[i]->next->next->next->data_pointer();
377 // double sw(0);
378  for ( k=0; k<ds; k++ ) {
379  prec->add(k, pacc[i]->complex(k));
380  fom[k] += fom_acc[k];
381  weight[k] += w_acc[k];
382  weight2[k] += w2_acc[k];
383 // sw += w_acc[k];
384  }
385 // ssw += sw;
386 // if ( imap == 0 ) cout << "total weight for " << i << " = " << sw << endl;
387 // cout << "map " << imap << " block " << i << " = " << sw << endl;
388  nv++;
389  }
390 // cout << "map " << imap << " total weight = " << ssw << endl;
391 
392  if ( verbose & VERB_DEBUG )
393  cout << "DEBUG img_reconstruction_sum_weigh: volumes accumulated: " << nv << endl;
394 
395  long cov = prec->fspace_reconstruction_weigh();
396  double rad = prec->fspace_maximum_radius(hi_res) + 1;
397  double vol = (4.0/3.0)*M_PI*rad*rad*rad;
398 
399  double Rf = prec->friedel_check();
400 // if ( Rf > 0.001 ) prec->friedel_apply();
401 
402  if ( verbose ) {
403  if ( inc == 1 )
404  cout << "Full reconstruction:" << endl;
405  else
406  cout << "Half reconstruction " << st+1 << ":" << endl;
407  cout << "Friedel symmetry residual: " << Rf << endl;
408  cout << "Coverage: " << cov << " (" << cov*100.0/vol << " %)" << endl << endl;
409  }
410 
411  if ( imap%nmaps == 0 )
412  prec->fspace_reconstruction_stats(hi_res);
413 
415 
416  if ( verbose & VERB_DEBUG )
417  write_img("weight.map", prec->next->next, 0);
418 
419  delete prec->next->next;
420  prec->next->next = NULL;
421 
422  prec->phase_shift_to_center();
423  prec->origin(prec->size()/2);
424 
425  return prec;
426 }
427 
428 
429 
431  Bimage* pmask, Bsymmetry* sym, double hi_res,
432  Vector3<double> scale, int ft_size,
433  fft_plan img_plan, fft_plan map_plan, double part_weight,
434  int interp_type, CTFparam* mg_ctf, int ctf_action,
435  double wiener, int flags)
436 {
437  FOMType fom_tag[NFOM] = {DENSITY, COVERAGE};
438 
439  if ( ppx_check(part, fom_tag) ) return part->fom[0];
440 
441  double dens(0);
442  Bparticle* partone = NULL;
443  particle_copy(&partone, part);
444 
445  Bimage* prec = particle_reconstruct(partone, sym, 0, hi_res,
446  scale, size, ft_size, img_plan,
447  interp_type, ctf_action, wiener, 0, 0, 0);
448 
449  long ncov = prec->fspace_reconstruction_weigh();
450  double sf = prec->real_size()[0]/hi_res;
451  double cov = ncov / ((4.0*M_PI/3.0)*sf*sf*sf);
452 
453  prec->phase_shift_to_center();
454  prec->origin(prec->size()/2);
455 
456  prec->fft(map_plan, 1);
457  prec->complex_to_real();
458 
459  prec->statistics();
460 
461 // cout << "avg=" << prec->average() << " std=" << prec->standard_deviation() << endl;
462 
463  if ( pmask ) dens = prec->relative_density(pmask);
464  else dens = prec->standard_deviation();
465 
466 // Bstring fn = "part_" + part->mg->id + Bstring(part->id, "_%04d.mrc");
467 // write_img(fn, prec, 0);
468 
469  delete prec;
470 
471  part->fom[0] = dens;
472  part->fom[1] = cov;
473 
474  if ( flags & WRITE_PPX ) {
475  Bstring ppx_name = ppx_filename(part->mg->id, part->id);
476  write_particle(ppx_name, part, 0, 0, fom_tag);
477  ppx_name = 0;
478  }
479 
480  return dens;
481 }
482 
520  Bstring& maskfile, Bsymmetry* sym,
521  int num_select, double hi_res, Vector3<double> scale, Vector3<long> size,
522  int pad_factor, int interp_type, int ctf_action, double wiener, int flags)
523 {
524  if ( size.volume() <= 0 )
525  size = project_set_reconstruction_size(project, scale[0], 0);
526 
527  if ( size.volume() <= 0 ) {
528  error_show("Error in project_single_particle_reconstruction", __FILE__, __LINE__);
529  cerr << "No particles to determine the size from!" << endl << endl;
530  return -1;
531  }
532 
533  int ft_size = part_ft_size(size[0], scale[0], pad_factor);
534 
535  fft_plan img_plan = fft_setup_plan(ft_size, ft_size, 1, FFTW_FORWARD, 1);
536  fft_plan map_plan = fft_setup_plan(size[0], size[1], size[2], FFTW_BACKWARD, 1);
537 
538  long i, j;
539 
540  Bfield* field = project->field;
541  Bmicrograph* mg = field->mg;
542  Bparticle* part = mg->part;
543 
544  for ( field = project->field; field && part == NULL; field = field->next )
545  for ( mg = field->mg; mg && part == NULL; mg = mg->next )
546  part = mg->part;
547 
548  if ( size.volume() <= 0 ) {
549  error_show("Error in project_single_particle_reconstruction", __FILE__, __LINE__);
550  cerr << "No reconstruction size set!" << endl << endl;
551  return -1;
552  }
553 
554  Bimage* pmask = NULL;
555 
556  if ( hi_res < 2*part->pixel_size[0]/scale[0] ) hi_res = 2*part->pixel_size[0]/scale[0];
557 
558  if ( maskfile.length() )
559  if ( ( pmask = read_img(maskfile, 1, 0) ) == NULL ) {
560  error_show("project_single_particle_reconstruction", __FILE__, __LINE__);
561  return -1;
562  }
563 
564  long datasize = (long) size.volume();
565  long maskedsize = datasize;
566 
567  if ( pmask ) for ( i=maskedsize=0; i<datasize; i++ ) if ( (*pmask)[i] == 1 ) maskedsize++;
568 
569  long nsel = project_count_mg_part_selected(project, num_select);
570 
571  if ( verbose & VERB_DEBUG )
572  cout << "DEBUG project_single_particle_reconstruction: num_select = " << num_select << endl;
573 
574  if ( verbose ) {
575  cout << "3D reciprocal space reconstruction:" << endl;
576  if ( pmask )
577  cout << "Mask: " << pmask->file_name() << endl;
578  cout << "Map size: " << size << endl;
579  cout << "Resolution limit: " << hi_res << " A" << endl;
580  cout << "Scale: " << scale << endl;
581  cout << "Interpolation type: " << interp_type << endl;
582  cout << "CTF application type: " << ctf_action << endl;
583  cout << "Fourier transform size: " << ft_size << " x " << ft_size << endl;
584  cout << "Analysis volume: " << maskedsize << " (" << maskedsize*100.0/datasize << " %)" << endl;
585  cout << "Number of selected particles: " << nsel << endl << endl;
586  }
587 
588  long np(0);
589  double part_weight(1);
590  Bparticle** part_array;
591 
592  // Directory for individual particle parameter files
593  if ( flags & WRITE_PPX ) {
594  mkdir("ppx", O_CREAT );
595  chmod("ppx", 0755);
596  }
597 
598  for ( field = project->field; field; field = field->next ) {
599  for ( mg = field->mg; mg; mg = mg->next ) {
600  for ( i=0, part = mg->part; part; part = part->next ) if ( part->sel ) {
601  if ( num_select < 0 ) i++;
602  else if ( part->sel == num_select ) i++;
603  }
604  part_array = new Bparticle*[i];
605  for ( i=0, part = mg->part; part; part = part->next ) if ( part->sel ) {
606  if ( num_select < 0 ) part_array[i++] = part;
607  else if ( part->sel == num_select ) part_array[i++] = part;
608  }
609 
610 #ifdef HAVE_GCD
611  dispatch_apply(i, dispatch_get_global_queue(0, 0), ^(size_t j){
612  part_array[j]->fom[0] = part_single_reconstruction(part_array[j],
613  size, pmask, sym, hi_res, scale,
614  ft_size, img_plan, map_plan, part_weight,
615  interp_type, mg->ctf, ctf_action, wiener, flags);
616  });
617 #else
618 #pragma omp parallel for
619  for ( j=0; j<i; j++ )
620  part_array[j]->fom[0] = part_single_reconstruction(part_array[j],
621  size, pmask, sym, hi_res, scale,
622  ft_size, img_plan, map_plan, part_weight,
623  interp_type, mg->ctf, ctf_action, wiener, flags);
624 #endif
625 
626  np += i;
627  if ( verbose ) {
628  cout << "Micrograph: " << mg->id << endl;
629  cout << "PID\tFOM\tCov" << endl;
630  for ( j=0; j<i; j++ ) cout << part_array[j]->id << tab << part_array[j]->fom[0]
631  << tab << part_array[j]->fom[1] << endl;
632  cout << "Particles processed: " << np << endl;
633  }
634  delete[] part_array;
635  }
636  }
637 
638  fft_destroy_plan(img_plan);
639  fft_destroy_plan(map_plan);
640 
641  if ( verbose )
642  cout << endl;
643 
644  return np;
645 }
646 
647 
659 {
660  if ( verbose & VERB_DEBUG )
661  cout << "DEBUG project_set_reconstruction_size: scale=" << scale << endl;
662 
663  Vector3<long> size;
664  Bfield* field = NULL;
665  Bmicrograph* mg = NULL;
666  Bparticle* part = NULL;
667  Bstring partfile;
668 
669  for ( field = project->field; field && part == NULL; field = field->next )
670  for ( mg = field->mg; mg && part == NULL; mg = (part)? mg: mg->next )
671  part = mg->part;
672 
673  if ( !mg ) {
674  error_show("Error in project_set_reconstruction_size", __FILE__, __LINE__);
675  cerr << "No micrograph with particles!" << endl << endl;
676  return size ;
677  }
678 
679  partfile = mg->fpart;
680  if ( !partfile.length() ) partfile = part->fpart;
681 
682  if ( !partfile.length() ) {
683  error_show("Error in project_set_reconstruction_size", __FILE__, __LINE__);
684  cerr << "No particle image file name given for micrograph " << mg->id << endl << endl;
685  return size;
686  }
687 
688  Bimage* p = read_img(partfile, 0, 0);
689 
690  size[0] = (int) (p->sizeX()*scale);
691  if ( size[0] < p->sizeY()/scale ) size[0] = (int) (p->sizeY()*scale);
692  if ( size[0] < p->sizeZ()/scale ) size[0] = (int) (p->sizeZ()*scale);
693  size[2] = size[1] = size[0];
694 
695  if ( twoD_flag ) size[2] = 1;
696 
697  delete p;
698 
699  size = size.max(1);
700 
701  if ( verbose & VERB_DEBUG )
702  cout << "DEBUG project_set_reconstruction_size: size=" << size << endl;
703 
704  return size;
705 }
706 
723 int project_configure_for_reconstruction(Bproject* project, Bstring classes, long& nmaps, long& nthreads)
724 {
725  if ( !classes.length() ) classes = "selected";
726  classes = classes.lower();
727  if ( nmaps < 1 ) nmaps = 1;
728  if ( nmaps > 3 ) nmaps = 3;
729  if ( nthreads < 1 ) nthreads = 1;
730  if ( nmaps&2 && nthreads%2 ) nthreads++;
731 
732  long i, msel(1), nsel(0), nclass(0);
733  Bfield* field;
734  Bmicrograph* mg;
735  Breconstruction* rec;
736  Bparticle* part;
737 
738  if ( classes[0] == 'a' ) {
740  } else if ( classes[0] == 's' ) {
742  } else {
743  if ( project->select ) {
744  for ( rec = project->rec; rec; rec = rec->next )
745  for ( part = rec->part; part; part = part->next )
746  if ( msel < part->sel ) msel = part->sel;
747  } else {
748  for ( field = project->field; field; field = field->next )
749  for ( mg = field->mg; mg; mg = mg->next )
750  for ( part = mg->part; part; part = part->next )
751  if ( msel < part->sel ) msel = part->sel;
752  }
753  if ( verbose )
754  cout << "Maximum selection number: " << msel << endl;
755  }
756 
757  msel++;
758 
759  vector<int> sel(msel, 0);
760  vector<int> cnt(msel, 0);
761  vector<int> num(msel, 0);
762 
763  if ( classes[0] == 'a' || classes[0] == 's' ) {
764  sel[1] = 1;
765  nclass = 1;
766  } else {
767 
768  sel = select_numbers(classes, msel);
769  for ( i=1; i<msel; i++ ) if ( sel[i] ) sel[i] = ++nclass;
770  }
771 
772 // if ( verbose & VERB_FULL ) {
773  if ( verbose ) {
774  cout << "Selection:" << endl << "Class\tNumber" << endl;
775  for ( i=0; i<msel; i++ ) cout << i << tab << sel[i] << endl;
776  }
777 
778  // Set up the total number of threads
779  int maps_per_class = nthreads;
780  if ( verbose ) {
781  cout << "Classes: " << classes << " (" << nclass << ")" << endl;
782  cout << "Maps per class: ";
783  if ( nmaps == 1 ) cout << "Full set map" << endl;
784  if ( nmaps == 2 ) cout << "Two half set maps" << endl;
785  if ( nmaps == 3 ) cout << "Full set map and two half set maps" << endl;
786  cout << "Threads per class: " << nthreads << endl;
787  cout << "Total number of threads: " << nclass*nthreads << endl << endl;
788  }
789 
790  if ( project->select ) {
791  for ( rec = project->rec; rec; rec = rec->next )
792  for ( part = rec->part; part; part = part->next ) {
793  i = part->sel;
794  if ( i>0 && i<msel && sel[i] ) {
795  num[i]++;
796  cnt[i]++;
797  part->sel = (sel[i] - 1)*maps_per_class + cnt[i];
798  if ( cnt[i] >= maps_per_class ) cnt[i] = 0;
799  nsel++;
800  } else {
801  part->sel = 0;
802  num[0]++;
803  }
804  }
805  } else {
806  for ( field = project->field; field; field = field->next )
807  for ( mg = field->mg; mg; mg = mg->next )
808  for ( part = mg->part; part; part = part->next ) {
809  i = part->sel;
810 // cout << mg->id << tab << part->id << tab << part->sel << endl;
811  if ( i>0 && i<msel && sel[i] ) {
812  num[i]++;
813  cnt[i]++;
814  part->sel = (sel[i] - 1)*maps_per_class + cnt[i];
815 // cout << sel[i] << tab << cnt[i] << tab << part->sel << endl;
816  if ( cnt[i] >= maps_per_class ) cnt[i] = 0;
817  nsel++;
818  } else {
819  part->sel = 0;
820  num[0]++;
821  }
822  }
823  }
824 
825  if ( verbose ) {
826  cout << "Particles selected:" << endl;
827  cout << "Class\tNumber" << endl;
828  for ( i=0; i<msel; i++ ) if ( sel[i] )
829  cout << i << tab << num[i] << endl;
830  cout << endl;
831  }
832 
833  return nclass;
834 }
835 
851 {
852  long n, i, j, k, npart;
853 
854  Bfield* field = project->field;
855  Bmicrograph* mg = field->mg;
856  Bparticle* part = mg->part;
857 
858  Bimage* p = read_img(mg->fpart, 0, 0);
859 
860  Vector3<long> size(p->size());
861  double px(part->pixel_size[0]), hires(2*px);
862 
863  delete p;
864 
865  // Determine the number of reconstructions to generate
866  long nmap(0);
867  for ( field=project->field; field; field=field->next )
868  for ( mg=field->mg; mg; mg=mg->next )
869  for ( part=mg->part; part; part=part->next )
870  if ( part->sel > nmap ) nmap = part->sel;
871 
872  if ( nmap < 1 ) return NULL;
873 
874  Bimage* prec = new Bimage(Float, TSimple, size, nmap);
875  prec->origin(prec->size()/2);
876  prec->sampling(px, px, 1);
877 
878  Bstring filename;
879 
880  int* num = new int[nmap];
881  float* fom = new float[nmap];
882  for ( i=0; i<nmap; i++ ) {
883  num[i] = 0;
884  fom[i] = 0;
885  }
886 
887  if ( verbose & VERB_RESULT ) {
888  cout << "2D real space reconstruction:" << endl;
889  cout << "Map size: " << prec->size() << endl;
890  cout << "Map origin: " << prec->image->origin() << endl;
891  cout << "Number of maps: " << prec->images() << endl << endl;
892  }
893 
894  Vector3<double> origin, translate;
895  Vector3<double> scale(1,1,1);
896  Vector3<double> axis(0,0,1);
897  Matrix3 mat(1);
898  Euler euler;
899 
900  Bimage* proj = NULL;
901 
902  for ( field=project->field; field; field=field->next ) {
903  for ( mg=field->mg; mg; mg=mg->next ) {
904  npart = micrograph_count_particles(mg);
905  if ( verbose )
906  cout << "Micrograph: " << mg->id << " with " << npart << " particles" << endl;
907  if ( npart ) {
908  if ( transform_output ) {
909  proj = new Bimage(Float, TSimple, size, npart);
910  proj->sampling(px, px, 1);
911  }
912  for ( part=mg->part; part; part=part->next ) {
913  j = part->id - 1;
914  n = part->sel - 1;
915 // p = read_img(mg->fpart, 1, j);
916  p = particle_read_img(part, 1);
917  p->change_type(Float);
918  p->rescale_to_avg_std(0, 1);
919  p->shift_background(0);
920  p->sampling(px, px, 1);
921  if ( mg->ctf ) img_ctf_apply(p, *(mg->ctf), 1, 0.2, 0, hires);
922  if ( n < 0 ) {
923  translate = prec->image->origin() - part->ori;
924  } else {
925  translate = prec->image[n].origin() - part->ori;
926  }
927  origin = part->ori;
928  euler = Euler(part->view);
929  mat = Matrix3(axis, euler.psi());
930 // mat = Matrix3(axis, part->view.angle());
931  p->transform(scale, origin, translate, mat, FILL_BACKGROUND, 0);
932  if ( part->sel ) {
933  num[n]++;
934  fom[n] += part->fom[0];
935  prec->add(n, p);
936  }
937  if ( transform_output ) {
938  proj->image[j].view(0,0,1,0);
939  proj->replace(j, p);
940  }
941  delete p;
942  }
943  if ( transform_output ) {
944  proj->origin(prec->image->origin());
945  filename = mg->fpart.pre_rev('.') + "_proj.spi";
946  if ( verbose & VERB_RESULT )
947  cout << "Writing projections file: " << filename << endl;
948  write_img(filename, proj, 0);
949  delete proj;
950  }
951  }
952  }
953  }
954 
956 
957  // Normalize the new reconstructions
958  for ( i=n=0; n<prec->images(); n++ ) {
959  if ( num[n] ) fom[n] /= num[n];
960  prec->image[n].FOM(num[n]);
961  for ( k=0; k<prec->image_size(); i++, k++ )
962  if ( num[n] ) prec->set(i, (*prec)[i] / num[n]);
963  }
964 
965  prec->statistics();
966 
967  if ( verbose & VERB_RESULT ) {
968  cout << "Particles used in reconstruction:" << endl;
969  cout << "Map\tNumber\t%\tFOM" << endl;
970  for ( n=0; n<nmap; n++ ) {
971  cout << n+1 << tab << num[n] << tab <<
972  num[n]*100.0/npart << tab << fom[n] << endl;
973  }
974  cout << endl;
975  }
976 
977  delete[] num;
978  delete[] fom;
979 
980  return prec;
981 }
982 
984  double hires, fft_plan planf, fft_plan planb)
985 {
986  long n(0);
987  Bfield* field = project->field;
988  Bmicrograph* mg = field->mg;
989  Bparticle* part = mg->part;
990  Bimage* p = NULL;
991 
992  double f(0);
993  Vector3<double> origin, translate;
994  Vector3<double> scale(1,1,1);
995  Vector3<double> axis(0,0,1);
996  Matrix3 mat(1);
997  Euler euler;
998 
999 // cout << "Map: " << i+1 << endl;
1000 
1001  for ( field = project->field; field; field = field->next ) {
1002  for ( mg = field->mg; mg; mg = mg->next ) {
1003  for ( part = mg->part; part; part = part->next ) if ( part->sel == i+1 ) {
1004 // p = read_img(mg->fpart, 1, part->id - 1);
1005  p = particle_read_img(part, 1);
1006  if ( p ) {
1007  p->change_type(Float);
1008  p->rescale_to_avg_std(0, 1);
1009  p->shift_background(0);
1010  p->sampling(part->pixel_size);
1011  if ( mg->ctf ) img_ctf_apply(p, *(mg->ctf), 1, 0.2, 0, hires, planf, planb);
1012  translate = prec->image[i].origin() - part->ori;
1013  origin = part->ori;
1014  euler = Euler(part->view);
1015  mat = Matrix3(axis, euler.psi());
1016 // mat = Matrix3(axis, part->view.angle());
1017  p->transform(scale, origin, translate, mat, FILL_BACKGROUND, 0);
1018  n++;
1019  f += part->fom[0];
1020  prec->add(i, p);
1021  delete p;
1022  }
1023  }
1024  }
1025  }
1026 
1027  if ( n ) {
1028  f /= n;
1029  prec->multiply(i, 1.0L/n);
1030  }
1031 
1032  prec->image[i].FOM(f);
1033  prec->image[i].select(n);
1034 
1035  Bparticle* part_avg = new Bparticle;
1036  memset(part_avg, 0, sizeof(Bparticle));
1037  part_avg->id = i+1;
1038  part_avg->mag = 1;
1039 
1040  part_avg->ori = prec->image[i].origin();
1041  part_avg->fom[0] = f;
1042  part_avg->sel = n;
1043 
1044  return part_avg;
1045 }
1046 
1048  double hires, fft_plan planf, fft_plan planb)
1049 {
1050  long maxrad = ( hires > 0 )? prec->real_size()[0]/hires: prec->sizeX()/2;
1051  if ( maxrad > prec->sizeX()/2 ) maxrad = prec->sizeX()/2;
1052 
1053  long j, n(0);
1054  Bfield* field = project->field;
1055  Bmicrograph* mg = field->mg;
1056  Bparticle* part = mg->part;
1057  Bimage* p = NULL;
1058  Bimage* psum = new Bimage(Float, TComplex, prec->size(), 1);
1059  Bimage* pssq = new Bimage(Float, TSimple, prec->size(), 1);
1060  psum->origin(prec->image->origin());
1061  pssq->origin(prec->image->origin());
1062  psum->sampling(prec->sampling(0));
1063  pssq->sampling(prec->sampling(0));
1064 
1065  double f(0), pwr, t(0.5);
1066  Vector3<double> origin, translate;
1067  Vector3<double> scale(1,1,1);
1068  Vector3<double> axis(0,0,1);
1069  Matrix3 mat(1);
1070  Euler euler;
1071 
1072  long nmg = project_count_mg_selected(project), m(0);
1073 
1074 // cout << "Map: " << i+1 << endl;
1075 
1076  for ( field = project->field; field; field = field->next ) {
1077  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
1078  m++;
1079 // if ( mg->ctf ) cout << "CTF pointer: " << mg->ctf << endl << endl << endl;
1080  if ( verbose && i < 1 ) {
1081  cout << mg->id;
1082  if ( mg->ctf ) cout << tab << mg->ctf->defocus_average();
1083  cout << tab << m*100.0/nmg << "%" << endl;
1084  }
1085  for ( part = mg->part; part; part = part->next ) if ( part->sel == i+1 ) {
1086 // cout << "Reading particle " << part->id << endl;
1087  p = particle_read_img(part, 1);
1088 // cout << "Particle read " << p->file_name() << endl;
1089  if ( p ) {
1090  p->change_type(Float);
1091  p->rescale_to_avg_std(0, 1);
1092  p->shift_background(0);
1093  p->sampling(part->pixel_size);
1094  if ( mg->ctf )
1095  img_ctf_apply(p, *(mg->ctf), 1, 0.2, 0, hires, planf, planb);
1096  translate = prec->image[i].origin() - part->ori;
1097  origin = part->ori;
1098  euler = Euler(part->view);
1099  mat = Matrix3(axis, euler.psi());
1100  p->transform(scale, origin, translate, mat, FILL_BACKGROUND, 0);
1101  n++;
1102  f += part->fom[0];
1103  p->fft(planf);
1104  psum->add(p);
1106  if ( verbose )
1107  cout << "Particle " << part->id << endl;
1108  pssq->add(p);
1109 // cout << "data size = " << p->data_size() << endl;
1110  delete p;
1111  }
1112 // if ( verbose )
1113 // cout << "Particle " << part->id << " done " << endl;
1114  }
1115  }
1116  }
1117 
1118  if ( n ) {
1119  f /= n;
1120  for ( j=0; j<psum->image_size(); ++j ) {
1121  pwr = psum->complex(j).power();
1122  psum->set(j, psum->complex(j)/n);
1123  pssq->set(j, (pwr - (*pssq)[j])/((*pssq)[j] - pwr/n));
1124  }
1125  psum->fft_back(planb);
1126  pssq->origin(Vector3<double>(0,0,0));
1127  Bimage* pr = pssq->radial(0, pssq->sizeX()/2, 1, 1);
1128  if ( verbose ) {
1129  cout << "Radius\tSSNR" << endl;
1130  for ( j=0; j<maxrad; ++j )
1131  cout << j << tab << (*pr)[j] << endl;
1132  cout << endl;
1133  }
1134  for ( j=1; j<maxrad; ++j )
1135  if ( (*pr)[j] < t ) break;
1136  f = prec->real_size()[0]/j;
1137  if ( verbose )
1138  cout << j << tab << f << tab << (*pr)[j] << endl << endl;
1139  delete pr;
1140  prec->replace(i, psum);
1141  prec->image[i].FOM(f);
1142  prec->image[i].select(n);
1143  }
1144 
1145  delete psum;
1146  delete pssq;
1147 
1148  Bparticle* part_avg = new Bparticle;
1149  memset(part_avg, 0, sizeof(Bparticle));
1150  part_avg->id = i+1;
1151  part_avg->mag = 1;
1152 
1153  part_avg->ori = prec->image[i].origin();
1154  part_avg->fom[0] = f;
1155  part_avg->sel = n;
1156 
1157  return part_avg;
1158 }
1159 
1161 {
1162  long i;
1163 
1164  Bfield* field = project->field;
1165  Bmicrograph* mg = field->mg;
1166  Bparticle* part = mg->part;
1167 
1168  Bimage* p = particle_read_img(mg->part, 0);
1169 
1170  Vector3<long> size(p->size());
1171  double px(part->pixel_size[0]), hires(2*px);
1172 
1173  delete p;
1174 
1175  // Determine the number of reconstructions to generate
1176  long nmap(0);
1177  for ( field=project->field; field; field=field->next )
1178  for ( mg=field->mg; mg; mg=mg->next )
1179  for ( part=mg->part; part; part=part->next )
1180  if ( part->sel > nmap ) nmap = part->sel;
1181 
1182  if ( nmap < 1 ) return NULL;
1183 
1184  Bparticle** part_arr = new Bparticle*[nmap];
1185 
1186  Bimage* prec = new Bimage(Float, TSimple, size, nmap);
1187  prec->origin(prec->size()/2);
1188  prec->sampling(px, px, 1);
1189 
1190  if ( verbose & VERB_RESULT ) {
1191  cout << "2D frequency space averaging:" << endl;
1192  cout << "Size: " << prec->size() << endl;
1193  cout << "Origin: " << prec->image->origin() << endl;
1194  cout << "Sampling: " << prec->sampling(0) << " A" << endl;
1195  cout << "Resolution limit: " << hires << " A" << endl;
1196  cout << "Number of averages: " << prec->images() << endl << endl;
1197  }
1198 
1199  fft_plan planf = fft_setup_plan(size, FFTW_FORWARD, 1);
1200  fft_plan planb = fft_setup_plan(size, FFTW_BACKWARD, 1);
1201 
1202 #ifdef HAVE_GCD
1203  dispatch_apply(nmap, dispatch_get_global_queue(0, 0), ^(size_t i){
1204  part_arr[i] = img_reconstruct_2D_fspace(i, project, prec, hires, planf, planb);
1205  if ( verbose )
1206  cout << i+1 << tab << part_arr[i]->sel << tab << part_arr[i]->fom[0] << endl;
1207  });
1208 #else
1209 #pragma omp parallel for
1210  for ( i=0; i<nmap; i++ ) {
1211 
1212  part_arr[i] = img_reconstruct_2D_fspace(i, project, prec, hires, planf, planb);
1213  if ( verbose )
1214  cout << i+1 << tab << part_arr[i]->sel << tab << part_arr[i]->fom[0] << endl;
1215  }
1216 #endif
1217 
1220 
1221  if ( verbose & VERB_DEBUG )
1222  cout << "done" << endl;
1223 
1224  prec->statistics();
1225 
1226  for ( i=0; i<nmap-1; i++ ) part_arr[i]->next = part_arr[i+1];
1227  project->class_avg = part_arr[0];
1228  part_arr[i]->next = NULL;
1229 
1231 /*
1232  long npart = project_count_mg_particles(project);
1233 
1234  if ( verbose & VERB_RESULT ) {
1235  cout << "Particles used in reconstruction:" << endl;
1236  cout << "Map\tNumber\t%\tFOM" << endl;
1237  for ( part = project->class_avg; part; part = part->next ) {
1238  cout << part->id << tab << part->sel << tab <<
1239  part->sel*100.0/npart << tab <<
1240  part->fom[0] << endl;
1241  }
1242  cout << endl;
1243  }
1244 */
1245  return prec;
1246 }
1247 
1248 
1263 Bimage* project_reconstruct_3D(Bproject* project, long selnum, int calcfom, Vector3<long> size)
1264 {
1265  int n(0), img_num;
1266  Breconstruction* rec = project->rec;
1267  Bparticle* part;
1268  Bimage* p = NULL;
1269  Bimage* pmap = NULL;;
1270 
1271  if ( rec->part ) {
1272  if ( rec->part->fpart.length() ) p = read_img(rec->part->fpart, 0, 0);
1273  else if ( rec->fpart.length() ) p = read_img(rec->fpart, 0, 0);
1274  else pmap = read_img(rec->frec, 1, 0);
1275  } else p = read_img(rec->frec, 0, 0);
1276 
1277  if ( !p && !pmap ) {
1278  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1279  return NULL;
1280  }
1281 
1282  if ( p ) {
1283  size = p->size();
1284  delete p;
1285  }
1286 
1287  if ( size.volume() <= 0 ) {
1288  cerr << "Error: The particle box size must be specified!" << endl << endl;
1289  return NULL;
1290  }
1291 
1292  Bimage* prec = new Bimage(Float, TSimple, size, 1);
1293  prec->sampling(rec->voxel_size);
1294  prec->origin(prec->default_origin());
1295  float* fom = NULL;
1296  if ( calcfom ) {
1297  prec->next = new Bimage(Float, TSimple, size, 1);
1298  fom = (float *) prec->next->data_pointer();
1299  }
1300 
1301  long i;
1302  Bstring filename;
1303  Vector3<double> start;
1304  double std_sum(0);
1305 
1306  if ( verbose ) {
1307  cout << "Calculating an average reconstruction" << endl;
1308  cout << "Size: " << size << endl;
1309  }
1310 
1311  if ( rec->part ) {
1312  for ( rec = project->rec; rec; rec = rec->next ) {
1313  filename = rec->fpart;
1314  for ( part = rec->part; part; part = part->next )
1315  if ( ( selnum < 0 && part->sel ) || ( part->sel == selnum ) ) {
1316  img_num = part->id - 1;
1317  if ( part->fpart.length() ) {
1318  filename = part->fpart;
1319  img_num = 0;
1320  }
1321  if ( filename.length() ) {
1322  if ( ( p = read_img(filename, 1, img_num) ) == NULL ) {
1323  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1324  return NULL;
1325  }
1326  if ( verbose )
1327  cout << "Adding particle: " << part->id << " (" << filename << ":" << img_num << ")" << endl;
1328  } else {
1329  start = part->loc - part->ori;
1330  p = pmap->extract(0, start, size);
1331  if ( verbose )
1332  cout << "Adding particle: " << part->id << endl;
1333  }
1334 // p->image->origin(part->ori);
1335  p->origin(part->ori);
1336  p->calculate_background();
1337  std_sum += p->standard_deviation();
1338  prec->rotate_and_add(p, part->ori, part->view);
1339  delete p;
1340  n++;
1341  }
1342  }
1343  } else {
1344  for ( rec = project->rec; rec; rec = rec->next )
1345  if ( ( selnum < 0 && rec->select ) || ( rec->select == selnum ) ) {
1346  if ( verbose )
1347  cout << "Adding reconstruction: " << rec->frec << endl;
1348  if ( ( p = read_img(rec->frec, 1, 0) ) == NULL ) {
1349  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1350  return NULL;
1351  }
1352 // p->image->origin(rec->origin);
1353  p->origin(rec->origin);
1354  p->calculate_background();
1355  std_sum += p->standard_deviation();
1356  prec->rotate_and_add(p, rec->origin, rec->view);
1357  delete p;
1358  n++;
1359  }
1360  }
1361 
1362  if ( pmap ) delete pmap;
1363 
1364  if ( verbose )
1365  cout << "Number of particles: " << n << endl;
1366 
1367  if ( n ) {
1368  for ( i=0; i<prec->data_size(); i++ ) {
1369  prec->set(i, (*prec)[i] / n);
1370  if ( fom ) {
1371  fom[i] = fom[i]/n - (*prec)[i]*(*prec)[i];
1372  if ( fom[i] < 0 ) fom[i] = 0;
1373  if ( calcfom > 1 ) fom[i] = sqrt(fom[i]);
1374  }
1375  }
1376  std_sum /= n;
1377  }
1378 
1379  prec->statistics();
1380  prec->calculate_background();
1381 
1382  if ( verbose )
1383  cout << "Signal enhancement: " <<
1384  (sqrt(n)*prec->standard_deviation()/std_sum - 1)/(sqrt(n) - 1) << endl << endl;
1385 
1386  if ( verbose & VERB_DEBUG )
1387  cout << "DEBUG project_reconstruct_3D: done!" << endl;
1388 
1389  return prec;
1390 }
1391 
1406 Bimage* project_reconstruct_3D(Bproject* project, long selnum, Vector3<long> size, double resolution)
1407 {
1408  long n(0), img_num;
1409  Breconstruction* rec = NULL;
1410  Bparticle* part = NULL;
1411  Bimage* p = NULL;
1412  Bimage* pmap = NULL;
1413 
1414  for ( rec = project->rec; rec; rec = rec->next ) {
1415  part = rec->part;
1416  if ( part ) break;
1417  }
1418 
1419  if ( !part ) {
1420  cerr << "Error in project_reconstruct_3D: No particles found!" << endl;
1421  return NULL;
1422  }
1423 
1424  Vector3<double> voxel_size(rec->voxel_size);
1425 
1426  if ( part ) {
1427  if ( part->fpart.length() ) p = read_img(part->fpart, 0, 0);
1428  else if ( rec->fpart.length() ) p = read_img(rec->fpart, 0, 0);
1429  else pmap = read_img(rec->frec, 1, 0);
1430  if ( part->pixel_size[0] > 0 ) voxel_size = part->pixel_size;
1431  } else p = read_img(rec->frec, 0, 0);
1432 
1433  if ( !p && !pmap ) {
1434  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1435  return NULL;
1436  }
1437 
1438  if ( p ) {
1439  size = p->size();
1440  delete p;
1441  }
1442 
1443  if ( size.volume() <= 0 ) {
1444  cerr << "Error: The particle box size must be specified!" << endl << endl;
1445  return NULL;
1446  }
1447 
1448  Bimage* prec = new Bimage(Float, TComplex, size, 1);
1449  prec->fourier_type(Standard);
1450  prec->sampling(voxel_size);
1451  prec->origin(prec->default_origin());
1452  prec->next = new Bimage(Float, TSimple, size, 1);
1453 
1454  double threshold;
1455  Bstring filename;
1456  Vector3<double> start;
1457 
1458  if ( verbose ) {
1459  cout << "Calculating an average reconstruction" << endl;
1460  cout << "Size: " << size << endl;
1461  cout << "Resolution: " << resolution << endl;
1462  }
1463 
1464  if ( part ) {
1465  for ( rec = project->rec; rec; rec = rec->next ) {
1466  filename = rec->fpart;
1467  for ( part = rec->part; part; part = part->next )
1468  if ( ( selnum < 0 && part->sel ) || ( part->sel == selnum ) ) {
1469  img_num = part->id - 1;
1470  if ( part->fpart.length() ) {
1471  filename = part->fpart;
1472  img_num = 0;
1473  }
1474  if ( filename.length() ) {
1475  if ( ( p = read_img(filename, 1, img_num) ) == NULL ) {
1476  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1477  return NULL;
1478  }
1479  if ( verbose )
1480  cout << "Adding particle: " << part->id << " (" << filename << ":" << img_num << ")" << endl;
1481  } else {
1482  start = part->loc - part->ori;
1483  p = pmap->extract(0, start, size);
1484  if ( verbose )
1485  cout << "Adding particle: " << part->id << endl;
1486  }
1487  threshold = p->standard_deviation()/1000;
1488  p->origin(part->ori);
1489  p->calculate_background();
1490  p->rotate(prec->image->origin() - part->ori, part->view);
1491  p->origin(prec->image->origin());
1492  p->fft();
1493  p->phase_shift_to_origin();
1494 // prec->add(p);
1495  prec->fspace_pack_3D(p, resolution, threshold);
1496  delete p;
1497  n++;
1498  }
1499  }
1500  } else {
1501  for ( rec = project->rec; rec; rec = rec->next )
1502  if ( ( selnum < 0 && rec->select ) || ( rec->select == selnum ) ) {
1503  if ( verbose )
1504  cout << "Adding reconstruction: " << rec->frec << endl;
1505  if ( ( p = read_img(rec->frec, 1, 0) ) == NULL ) {
1506  error_show("project_reconstruct_3D", __FILE__, __LINE__);
1507  return NULL;
1508  }
1509  threshold = p->standard_deviation()/1000;
1510  p->origin(rec->origin);
1511  p->calculate_background();
1512  p->rotate(prec->image->origin() - rec->origin, rec->view);
1513  p->fft();
1514  p->phase_shift_to_origin();
1515 // prec->add(p);
1516  prec->fspace_pack_3D(p, resolution, threshold);
1517  delete p;
1518  n++;
1519  }
1520  }
1521 
1522  if ( pmap ) delete pmap;
1523 
1524  if ( verbose ) {
1525  cout << "Number of particles: " << n << endl;
1526  cout << "Rescaling average" << endl << endl;
1527  }
1528 
1530 
1531  prec->fspace_reconstruction_stats(resolution);
1532 
1533  prec->phase_shift_to_center();
1534  prec->origin(prec->default_origin());
1535 
1536  prec->fft_back();
1537 
1538  prec->statistics();
1539  prec->calculate_background();
1540 
1541  if ( verbose & VERB_DEBUG )
1542  cout << "DEBUG project_reconstruct_3D: done!" << endl;
1543 
1544  return prec;
1545 }
1546 
1569  Vector3<long> map_size, Vector3<double> sam, double scale,
1570  double resolution, fft_plan planf, fft_plan planb)
1571 {
1572  Bfield* field = NULL;
1573  Bmicrograph* mg = NULL;
1574  Bparticle* part = NULL;
1575  Bimage* p = NULL;
1576 
1577  if ( map_size.volume() <= 0 ) {
1578  error_show("Error in project_back_projection", __FILE__, __LINE__);
1579  cerr << "No reconstruction size set!" << endl << endl;
1580  return NULL;
1581  }
1582 
1583  for ( field = project->field; field && part == NULL; field = field->next )
1584  for ( mg = field->mg; mg && part == NULL; mg = mg->next )
1585  if ( ( part = mg->part ) ) break;
1586 
1587  if ( !mg || !part ) {
1588  cerr << "Error: No particles found!" << endl;
1589  return NULL;
1590  }
1591 
1592  // Initialize the new 3D volume
1593  Bimage* pmap = new Bimage(Float, TSimple, map_size, 1);
1594 
1595  if ( sam.volume() > 0 ) pmap->sampling(sam);
1596  else if ( mg ) pmap->sampling(part->pixel_size);
1597 
1598  pmap->origin(pmap->default_origin());
1599 
1600  pmap->check();
1601 
1602  long nsel = project_count_mg_part_selected(project, num_select);
1603  long psel, nrec(0);
1604 
1605  if ( verbose & VERB_FULL ) {
1606  cout << "3D backprojection:" << endl;
1607  cout << "Map size: " << pmap->size() << endl;
1608  cout << "Resolution: " << resolution << " A" << endl;
1609  cout << "Scale: " << scale << endl;
1610  cout << "Sampling: " << pmap->sampling(0) << endl;
1611  cout << "Number of selected particles: " << nsel << endl << endl;
1612  }
1613 
1614  // Do the back projection
1615  for ( field = project->field; field; field = field->next ) {
1616  for ( mg = field->mg; mg; mg = mg->next ) {
1617  for ( part = mg->part; part; part = part->next ) {
1618  psel = 0;
1619  if ( part->sel ) {
1620  if ( num_select < 0 ) {
1621  psel = 1;
1622  } else if ( part->sel == num_select ) {
1623  psel = 1;
1624  }
1625  }
1626  if ( psel ) { // Use only selected images
1627  p = particle_read_img(part, 1);
1628 // if ( ( p = read_img(mg->fpart, 1, part->id-1) ) == NULL ) {
1629  if ( !p ) {
1630  error_show("project_back_projection", __FILE__, __LINE__);
1631  return NULL;
1632  }
1633 
1634  p->sampling(part->pixel_size);
1635 
1636  if ( part->ori[0] <= 0 ) {
1637  if ( p->image->origin()[0] > 0 ) part->ori[0] = p->image->origin()[0];
1638  else part->ori[0] = pmap->image->origin()[0];
1639  }
1640 
1641  if ( part->ori[1] <= 0 ) {
1642  if ( p->image->origin()[1] > 0 ) part->ori[1] = p->image->origin()[1];
1643  else part->ori[1] = pmap->image->origin()[1];
1644  }
1645 
1646  part->ori[2] = 0;
1647 
1648  p->origin(part->ori);
1649 
1650  p->image->view(part->view);
1651 
1652  p->image->magnification(part->mag / scale);
1653 
1654  pmap->back_project(p, resolution, 0, planf, planb);
1655 
1656  delete p;
1657 
1658  nrec++;
1659 
1660  if ( verbose & ( VERB_TIME | VERB_PROCESS | VERB_RESULT ) )
1661  cout << "Complete: " << nrec*100.0/nsel << "%\r" << flush;
1662  }
1663  }
1664  }
1665  }
1666 
1667  if ( verbose ) {
1668  cout << endl << "Particles used: " << nrec << endl << endl;
1669  }
1670 
1671  return pmap;
1672 }
1673 
1684  int nmaps, int nthreads)
1685 {
1686  if ( verbose & VERB_DEBUG )
1687  cout << "DEBUG img_backprojection_accumulate:" << endl;
1688 
1689  int maps_per_class = nthreads;
1690  int iclass = imap/nmaps;
1691 
1692  Bimage* prec = pacc[0]->copy_header();
1693  prec->data_alloc_and_clear();
1694 
1695  long i, j, k;
1696  long datasize = (long) prec->size().volume();
1697 
1698  long st(0), inc(1);
1699  if ( nmaps == 2 ) {
1700  st = imap%2;
1701  inc = 2;
1702  }
1703  if ( nmaps == 3 && imap%3 ) {
1704  st = imap%3 - 1;
1705  inc = 2;
1706  }
1707 
1708  if ( verbose & VERB_DEBUG ) {
1709  cout << "DEBUG img_backprojection_weigh: nmaps=" << nmaps << " imap=" << imap << endl;
1710  cout << "DEBUG img_backprojection_weigh: maps_per_class=" << maps_per_class << " iclass=" << iclass << endl;
1711  cout << "DEBUG img_backprojection_weigh: st=" << st << " inc=" << inc << endl;
1712  }
1713 
1714  for ( i=iclass*maps_per_class+st, j=st; j<maps_per_class; i+=inc, j+=inc ) {
1715 // cout << "Doing map " << i << endl;
1716  for ( k=0; k<datasize; k++ )
1717  prec->add(k, (*pacc[i])[k]);
1718  }
1719 
1720  prec->statistics();
1721  prec->calculate_background();
1722 
1723  if ( verbose & VERB_DEBUG )
1724  cout << "DEBUG img_backprojection_weigh: Accumulation done" << endl;
1725 
1726  return prec;
1727 }
1728 
mg_reconstruct.h
Functions for reconstruction.
project_reconstruct_2D
Bimage * project_reconstruct_2D(Bproject *project, int transform_output)
Creates a 2D reconstruction from the images in a multi-image file.
Definition: mg_reconstruct.cpp:850
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:415
mg_particle_select.h
Select particles.
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Bimage::complex_to_intensities
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:92
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:500
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
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
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
project_set_reconstruction_size
Vector3< long > project_set_reconstruction_size(Bproject *project, double scale, int twoD_flag)
Sets the reconstruction size for reconstruction from 2D particle images.
Definition: mg_reconstruct.cpp:658
Bimage::fspace_reconstruction_weigh
long fspace_reconstruction_weigh()
Weighs a reconstruction.
Definition: Bimage_reconstruct.cpp:412
Bproject::select
int select
Definition: mg_processing.h:342
Bparticle::view
View view
Definition: mg_processing.h:102
NFOM
#define NFOM
Definition: mg_processing.h:16
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
CTFparam::update
int update(CTFparam *ctf)
Definition: ctf.h:81
Bimage::next
Bimage * next
Definition: Bimage.h:179
Breconstruction::voxel_size
Vector3< double > voxel_size
Definition: mg_processing.h:295
Bsub_image::select
long select()
Definition: Bimage.h:167
img_reconstruct_2D_fspace
Bparticle * img_reconstruct_2D_fspace(long i, Bproject *project, Bimage *prec, double hires, fft_plan planf, fft_plan planb)
Definition: mg_reconstruct.cpp:1047
Bparticle
Definition: mg_processing.h:90
Bimage::relative_density
double relative_density(Bimage *pmask)
Calculates the relative density in a region defined by a mask.
Definition: Bimage.cpp:3071
project_reconstruction_partlist
Bparticle * project_reconstruction_partlist(Bproject *project, int num_select, int bootstrap)
List of particle images for reciprocal space reconstruction.
Definition: mg_reconstruct.cpp:246
Bproject::field
Bfield * field
Definition: mg_processing.h:346
img_reconstruct_2D
Bparticle * img_reconstruct_2D(long i, Bproject *project, Bimage *prec, double hires, fft_plan planf, fft_plan planb)
Definition: mg_reconstruct.cpp:983
img_backprojection_accumulate
Bimage * img_backprojection_accumulate(Bimage **pacc, int imap, int nmaps, int nthreads)
Accumulates multiple backprojections.
Definition: mg_reconstruct.cpp:1683
symmetry.h
Header file for general symmetry functions.
FOMType
FOMType
Definition: mg_processing.h:38
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:592
Euler::psi
double psi()
Definition: Euler.h:56
micrograph_count_particles
long micrograph_count_particles(Bmicrograph *mg)
Counts all the particles in the micrograph structure.
Definition: mg_select.cpp:736
mg_select.h
Header file for micrograph processing.
Bimage::fspace_reconstruction_snr
long fspace_reconstruction_snr()
Calculates the SNR map.
Definition: Bimage_reconstruct.cpp:536
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.
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bimage::radial
Bimage * radial(long minrad, long maxrad, double rad_step=1, int wrap=0)
Calculates the radial average of an image.
Definition: Bimage_polar.cpp:33
TComplex
@ TComplex
Definition: Bimage.h:60
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:105
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
project_show_class_averages
long project_show_class_averages(Bproject *project)
Shows the class averages in a project.
Definition: mg_processing.cpp:1617
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
Bimage::fft_back
int fft_back()
Definition: Bimage.h:831
View
Definition: View.h:26
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
ppx_filename
Bstring ppx_filename(Bstring &id, int part_id)
Definition: rwmg.cpp:415
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bfield
Definition: mg_processing.h:260
Bsub_image::FOM
double FOM()
Definition: Bimage.h:165
project_back_projection
Bimage * project_back_projection(Bproject *project, long num_select, Vector3< long > map_size, Vector3< double > sam, double scale, double resolution, fft_plan planf, fft_plan planb)
Back projects a set of 2D images into a 3D volume.
Definition: mg_reconstruct.cpp:1568
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bsymmetry
Definition: symmetry.h:38
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
project_reconstruct_3D
Bimage * project_reconstruct_3D(Bproject *project, long selnum, int calcfom, Vector3< long > size)
Transforms 3D maps and calculates an average.
Definition: mg_reconstruct.cpp:1263
part_consolidate_selection
long part_consolidate_selection(Bproject *project, int number)
Consolidates selected particles under one selection number.
Definition: mg_particle_select.cpp:283
Standard
@ Standard
Definition: Bimage.h:42
planf
fft_plan planf
Definition: bico.cpp:24
Bimage::rotate_and_add
int rotate_and_add(Bimage *p, Vector3< double > origin, View view)
Rotates an image to a specified view and adds it to another image.
Definition: Bimage_transform.cpp:512
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:296
Bimage::images
long images()
Definition: Bimage.h:504
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
rwmg.h
Header file for reading and writing micrograph parameters.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
part_reset_selection
long part_reset_selection(Bproject *project, int flag=0)
Resets selection to all particles.
Definition: mg_particle_select.cpp:133
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:325
TSimple
@ TSimple
Definition: Bimage.h:59
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bimage::shift_background
int shift_background(double bkg)
Sets the background for each sub-image to a given value.
Definition: Bimage_background.cpp:351
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
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
Bimage::fft
int fft()
Definition: Bimage.h:830
Bimage::image_size
long image_size()
Definition: Bimage.h:290
project_count_mg_selected
long project_count_mg_selected(Bproject *project)
Counts all the selected micrographs in the project structure.
Definition: mg_select.cpp:367
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:255
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:380
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
project_count_mg_part_selected
long project_count_mg_part_selected(Bproject *project)
Counts the number of particles in a project.
Definition: mg_select.cpp:437
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:109
Bimage::data_size
long data_size()
Definition: Bimage.h:270
part_single_reconstruction
double part_single_reconstruction(Bparticle *part, Vector3< long > size, Bimage *pmask, Bsymmetry *sym, double hi_res, Vector3< double > scale, int ft_size, fft_plan img_plan, fft_plan map_plan, double part_weight, int interp_type, CTFparam *mg_ctf, int ctf_action, double wiener, int flags)
Definition: mg_reconstruct.cpp:430
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage::back_project
int back_project(Bimage *p, double resolution, double axis, fft_plan planf, fft_plan planb)
Definition: Bimage_project.cpp:437
Bimage
General image parameter class.
Definition: Bimage.h:177
project_single_particle_reconstruction
long project_single_particle_reconstruction(Bproject *project, Bstring &maskfile, Bsymmetry *sym, int num_select, double hi_res, Vector3< double > scale, Vector3< long > size, int pad_factor, int interp_type, int ctf_action, double wiener, int flags)
Reciprocal space reconstruction from the images in a multi-image file.
Definition: mg_reconstruct.cpp:519
Bproject
Definition: mg_processing.h:336
Bimage::fspace_reconstruction_stats
int fspace_reconstruction_stats(double resolution, double sampling_ratio=1)
Calculates Fourier shell statistics.
Definition: Bimage_reconstruct.cpp:452
COVERAGE
@ COVERAGE
Definition: mg_processing.h:52
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2830
mg_img_proc.h
Header file for image processing from micrograph structures.
project_reconstruct_2D_fast
Bimage * project_reconstruct_2D_fast(Bproject *project)
Definition: mg_reconstruct.cpp:1160
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
Bimage::data_alloc_and_clear
unsigned char * data_alloc_and_clear()
Definition: Bimage.h:272
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
Bimage::fspace_maximum_radius
long fspace_maximum_radius(double resolution, double sampling_ratio=1)
Calculates the maximum radius in frequency space from a given resolution.
Definition: Bimage_fspace.cpp:26
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
Bsub_image::magnification
double magnification()
Definition: Bimage.h:163
Bimage::check_resolution
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
Definition: Bimage.cpp:635
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
Breconstruction::select
long select
Definition: mg_processing.h:286
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:237
Bparticle::def
double def
Definition: mg_processing.h:96
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, int flags)
Definition: mg_ctf.cpp:972
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:348
img_reconstruction_sum_weigh
Bimage * img_reconstruction_sum_weigh(Bimage **pacc, int imap, int nmaps, int maps_per_class, double hi_res)
Combines and weighs a map from several partial maps and weight sets.
Definition: mg_reconstruct.cpp:331
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
CTFparam
Definition: ctf.h:28
Vector3::volume
double volume()
Definition: Vector3.h:237
particle_reconstruct
Bimage * particle_reconstruct(Bparticle *partlist, Bsymmetry *sym, int sym_mode, double hi_res, Vector3< double > scale, Vector3< long > size, int ft_size, fft_plan plan, int interp_type, int ctf_action, double wiener, int twoD_flag, int bootstrap, int first)
Reciprocal space reconstruction from 2D particle images.
Definition: mg_reconstruct.cpp:100
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
random_symmetric_view
View random_symmetric_view(View &asu_view, Bsymmetry *sym)
Returns a randomly picked symmetry view.
Definition: symmetry.cpp:1005
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bimage::copy_header
Bimage * copy_header()
Definition: Bimage.h:658
Bimage::fspace_pack_2D
int fspace_pack_2D(Bimage *p, Matrix3 mat, double hi_res, double lo_res, Vector3< double > scale, double part_weight=1, int interp_type=0)
Packs a 2D Fourier transform into a 3D reciprocal space volume.
Definition: Bimage_reconstruct.cpp:107
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_processing.h
Header file for micrograph processing.
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
Bimage::check
void check()
Checks an image for reasonable properties.
Definition: Bimage.cpp:419
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
ppx_check
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:441
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
Bmicrograph::select
long select
Definition: mg_processing.h:204
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
particle_copy
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
Definition: mg_processing.cpp:614
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:284
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
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
planb
fft_plan planb
Definition: bico.cpp:24
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
View::matrix
Matrix3 matrix()
Definition: View.h:153
particle_read_img
Bimage * particle_read_img(Bparticle *part, int readflag)
Reads a particle image file.
Definition: mg_img_proc.cpp:519
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
write_particle
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:406
Bimage::fspace_pack_3D
int fspace_pack_3D(Bimage *p, double hi_res=0, double threshold=0)
Packs a 3D Fourier transform into a 3D reciprocal space volume.
Definition: Bimage_reconstruct.cpp:314
verbose
int verbose
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_select.cpp:755
Bparticle::mag
double mag
Definition: mg_processing.h:95
Float
@ Float
Definition: utilities.h:161
project_configure_for_reconstruction
int project_configure_for_reconstruction(Bproject *project, Bstring classes, long &nmaps, long &nthreads)
Sets up the particle selection for reconstruction.
Definition: mg_reconstruct.cpp:723
Bimage::phase_shift_to_center
int phase_shift_to_center()
Phase shifts a set of reflections to the nominal center of the image origin.
Definition: Bimage_complex.cpp:382
Euler
Definition: Euler.h:28
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bimage::friedel_check
double friedel_check()
Checks Friedel symmetry.
Definition: Bimage_fspace.cpp:1744
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:316
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
select_numbers
int select_numbers(Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
Definition: utilities.cpp:335
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
Bimage::view
void view(double vx, double vy, double vz, double va)
Definition: Bimage.h:596
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
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
DENSITY
@ DENSITY
Definition: mg_processing.h:53
Breconstruction::view
View view
Definition: mg_processing.h:298
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
Vector3::max
Type max()
Definition: Vector3.h:175