Bsoft  2.1.0
Bernard's software package
ps_micrograph.cpp
Go to the documentation of this file.
1 
9 #include "ps_micrograph.h"
10 #include "ps_plot.h"
11 #include "ps_views.h"
12 #include "rwimg.h"
13 #include "symmetry.h"
14 #include "linked_list.h"
15 #include "utilities.h"
16 
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19 
20 // Internal function prototypes
21 int ps_origins(ofstream* fps, Bstring& title, Bproject* project, int flags);
22 
31 {
32  int i, width = 0, height = 0, left=50, bottom=50, nmg = 0;
33 
34  Bfield* field = project->field;
35  if ( !field ) return -1;
36 
37  Bmicrograph* mg = field->mg;
38  if ( !mg ) return -1;
39 
40  Bparticle* part = mg->part;
41  if ( !part ) return -1;
42 
43  Bimage* p;
44 
45  // Find the dimensions of the micrographs from the coordinate sets
46  for ( field=project->field; field; field=field->next ) {
47  for ( mg=field->mg; mg; mg=mg->next ) {
48  p = read_img(mg->fmg, 0, 0);
49  if ( !p ) {
50  error_show("Error in ps_mg_particle_positions", __FILE__, __LINE__);
51  cerr << "Micrograph " << mg->fmg << " not found" << endl;
52  return -1;
53  }
54  if ( width < p->sizeX() ) width = p->sizeX();
55  if ( height < p->sizeY() ) height = p->sizeY();
56  delete p;
57  nmg++;
58  }
59  }
60  if ( verbose & VERB_DEBUG )
61  cout << "DEBUG ps_mg_particle_positions: width=" << width << " height=" << height << endl;
62 
63  float scale(500.0/width);
64  if ( scale > 700.0/height ) scale = 700.0/height;
65 
66  ofstream* fps = ps_open_and_init(filename, title, nmg, 600, 800);
67 
68  for ( field=project->field; field; field=field->next ) {
69  for ( i=0, mg=field->mg; mg; mg=mg->next, i++ ) {
70  *fps << "%%%%Page: " << i+1 << " " << i+1 << endl;
71  *fps << "/Helvetica findfont 12 scalefont setfont" << endl;
72  *fps << "50 755 moveto (" << title << ": " << mg->fpart << ") show" << endl;
73  *fps << "/Scale " << scale << " def" << endl;
74  *fps << "/Height 700 def\n/Width 500 def" << endl;
75  *fps << "/Frame { newpath 0 0 moveto Width 0 lineto Width Height lineto 0 Height lineto closepath } def" << endl;
76 
77  *fps << "/Data [\n%x y mag sel" << endl;
78  for ( part=mg->part; part; part=part->next ) if ( part->sel )
79  *fps << part->loc[0] << " " << part->loc[1] << " " <<
80  part->mag << " " << part->sel << endl;
81  *fps << "] def" << endl;
82 
83  *fps << "gsave" << endl;
84  *fps << " " << left << " " << bottom << " translate" << endl;
85  *fps << " Frame stroke" << endl;
86 // *fps << " Frame clip" << endl;
87  *fps << " Scale Scale scale" << endl;
88  *fps << " /Helvetica findfont 64 scalefont setfont" << endl;
89  *fps << " 0 4 Data length 4 sub { " << endl;
90  *fps << " /Index exch def" << endl;
91  *fps << " /x Data Index get def" << endl;
92  *fps << " /y Data Index 1 add get def" << endl;
93  *fps << " /mag Data Index 2 add get def" << endl;
94  *fps << " /sel Data Index 3 add get def" << endl;
95  *fps << " x y moveto 0 30 rmoveto sel cvi (xxxx) cvs show stroke" << endl;
96  *fps << " x y moveto 0 -30 rmoveto mag cvr (x.xxx) cvs show stroke" << endl;
97  *fps << " } for" << endl;
98  *fps << "grestore" << endl;
99 
100  *fps << "showpage" << endl;
101  }
102  }
103 
104  ps_close(fps);
105 
106  return 0;
107 }
108 
122  Bstring& symmetry_string, Bproject* project, int selection)
123 {
124  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
125 
126  View* view = views_from_project(project, selection);
127 
129 
130  kill_symmetry(sym);
131 
132  if ( verbose & VERB_LABEL )
133  cout << "Writing postscript file: " << filename << endl << endl;
134 
135  ofstream* fps = ps_open_and_init(filename, symmetry_string, 1, 600, 800);
136 
137  *fps << "/Helvetica-Bold findfont 20 scalefont setfont" << endl;
138  *fps << "40 740 moveto (" << filename << ") show" << endl;
139 
140  ps_views(fps, symmetry_string, view, 2);
141 
142  kill_list((char *) view, sizeof(View));
143 
144  *fps << "/Helvetica-Bold findfont 20 scalefont setfont" << endl;
145  *fps << "40 740 moveto (" << filename << ") show" << endl;
146 
147  ps_origins(fps, title, project, 2);
148 
149  ps_close(fps);
150 
151  return 0;
152 }
153 
170 int ps_origins(Bstring& filename, Bstring& title, Bproject* project, int flags)
171 {
172  if ( verbose & VERB_LABEL )
173  cout << "Writing postscript file: " << filename << endl << endl;
174 
175  ofstream* fps = ps_open_and_init(filename, title, 1, 600, 800);
176 
177  *fps << "/Helvetica-Bold findfont 20 scalefont setfont" << endl;
178  *fps << "40 740 moveto (" << filename << ") show" << endl;
179 
180  ps_origins(fps, title, project, flags);
181 
182  ps_close(fps);
183 
184  return 0;
185 }
186 
187 int ps_origins(ofstream* fps, Bstring& title, Bproject* project, int flags)
188 {
189  if ( verbose & VERB_DEBUG )
190  cout << "DEBUG ps_origins: flags=" << flags << endl;
191 
192  int left(50), bottom(150), width(500), height(500);
193  Bfield* field = project->field;
194  Bmicrograph* mg = NULL;
195  Breconstruction* rec = project->rec;
196  Bparticle* part = NULL;
197 
198  // Discover the dimension of the first particle image
199  // I supposed that the rest have the same dimentions (not always true).
200  Bimage* p = NULL;
201  long nx = 0, ny = 0, nz = 0;
202 
203  if ( project->select < 1 ) {
204  if ( field && field->mg ) {
205  nx = (long) field->mg->box_size[0];
206  ny = (long) field->mg->box_size[1];
207  nz = 1;
208  }
209  for ( field = project->field; field && !p; field = field->next )
210  for ( mg = field->mg; mg && !p; mg = mg->next )
211  if ( ! access(mg->fpart.c_str(), R_OK) )
212  p = read_img(mg->fpart, 0, 0); // Read one image header
213  } else {
214  if ( rec ) {
215  nx = (long) rec->box_size[0];
216  ny = (long) rec->box_size[1];
217  nz = (long) rec->box_size[2];
218  }
219  for ( rec = project->rec; rec && !p; rec = rec->next ) {
220  if ( ! access(rec->fpart.c_str(), R_OK) )
221  p = read_img(rec->fpart, 0, 0); // Read one image header
222  for ( part = rec->part; part && !p; part = part->next )
223  if ( ! access(part->fpart.c_str(), R_OK) )
224  p = read_img(part->fpart, 0, 0); // Read one image header
225  }
226  }
227 
228  if ( p ) {
229  nx = p->sizeX();
230  ny = p->sizeY();
231  nz = p->sizeZ();
232  delete p;
233  }
234 
235  if ( nx*ny < 1 ) {
236  error_show("Error in ps_origins: zero image size!", __FILE__, __LINE__);
237  return -1;
238  }
239 
240  long n = 0; // number of particles
241  float cx = nx/2;
242  float cy = ny/2;
243  float scale = width*1.0/nx;
244  if ( verbose & VERB_FULL ) {
245  cout << "Dimensions of the image particles: " << nx << " * " << ny << endl;
246  cout << "Center of the particle images: " << cx << " * " << cy << endl;
247  }
248 
249  long i, m, ix, iy;
250  float* count = NULL;
251 
252  if ( flags == 2 ) {
253  count = new float[nx*ny];
254  for ( i=0; i<nx*ny; i++ ) count[i] = 0;
255  if ( project->select < 1 ) {
256  for ( n=m=0, field = project->field; field; field = field->next )
257  for ( mg = field->mg; mg; mg = mg->next )
258  for ( part = mg->part; part; part = part->next )
259  if ( part->sel > 0 ) {
260  ix = (long) part->ori[0];
261  iy = (long) part->ori[1];
262  if ( ix < 0 ) ix += nx;
263  if ( iy < 0 ) iy += ny;
264  if ( ix >= 0 && iy >= 0 && ix < nx && iy < ny ) {
265  i = iy*nx+ix;
266  count[i]++;
267  if ( m < count[i] ) m = (int) count[i];
268  n++;
269  }
270  }
271  } else {
272  for ( n=m=0, rec = project->rec; rec; rec = rec->next )
273  for ( part = rec->part; part; part = part->next )
274  if ( part->sel > 0 ) {
275  ix = (long) part->ori[0];
276  iy = (long) part->ori[1];
277  if ( ix < 0 ) ix += nx;
278  if ( iy < 0 ) iy += ny;
279  if ( ix >= 0 && iy >= 0 && ix < nx && iy < ny ) {
280  i = iy*nx+ix;
281  count[i]++;
282  if ( m < count[i] ) m = (int) count[i];
283  n++;
284  }
285  }
286  }
287  }
288 
289  if ( verbose & VERB_DEBUG )
290  cout << "DEBUG ps_origins: number of particles selected = " << n << endl;
291 
292  *fps << "%%%%Page: Origins 2" << endl;
293  *fps << "/Helvetica-Bold findfont 14 scalefont setfont" << endl;
294  *fps << "/Left " << left << " def\n/Bottom " << bottom << " def\n/Height " << height << " def\n/Width " << width << " def" << endl;
295 
296  *fps << "/Origin [" << endl;
297  if ( flags == 2 ) {
298  *fps << "%x y count weight" << endl;
299  for ( i=iy=0; iy<ny; iy++ )
300  for ( ix=0; ix<nx; ix++, i++ )
301  if ( count[i] ) *fps << ix << " " << iy << " " << count[i] << " " << count[i]/m << endl;
302  delete[] count;
303  } else {
304  *fps << "%x y count weight" << endl;
305  if ( project->select < 1 ) {
306  for ( n=0, field = project->field; field; field = field->next )
307  for ( mg = field->mg; mg; mg = mg->next )
308  for ( part = mg->part; part; part = part->next )
309  if ( part->sel > 0 ) {
310  *fps << part->ori[0] << " " << part->ori[1] << " 0.0 0.0" << endl;
311  n++;
312  }
313  } else {
314  for ( rec = project->rec; rec; rec = rec->next )
315  for ( part = rec->part; part; part = part->next )
316  if ( part->sel > 0 ) {
317  *fps << part->ori[0] << " " << part->ori[1] << " 0.0 0.0" << endl;
318  n++;
319  }
320  }
321  }
322 
323  *fps << "] def" << endl;
324 
325  *fps << "/Dim " << nx << " def" << endl;
326  *fps << "/Rad Dim 2 div def" << endl;
327  *fps << "/Scale Width Dim div def" << endl;
328  *fps << "/Box { newpath " << endl;
329  *fps << " Rad Rad Rad 0 360 arc stroke" << endl; // Circle
330  *fps << " 0 0 moveto 0 Dim rlineto Dim 0 rlineto 0 Dim neg rlineto Dim neg 0 rlineto" << endl; // Square
331  *fps << " 0 Rad moveto Dim 0 rlineto" << endl; // Cross
332  *fps << " Rad 0 moveto 0 Dim rlineto" << endl;
333  *fps << " closepath } def" << endl;
334 
335  *fps << "40 720 moveto (Number of origins: " << n << ") show" << endl;
336  if ( nz < 2 ) *fps << "40 700 moveto (Particle dimensions: " << nx << " x " << ny << ") show" << endl;
337  else *fps << "40 700 moveto (Particle dimensions: " << nx << " x " << ny << " x " << nz << ") show" << endl;
338  *fps << "40 680 moveto (Maximum count: " << m << ") show" << endl;
339  *fps << "/Helvetica findfont 16 scalefont setfont" << endl;
340  *fps << "gsave" << endl;
341  *fps << " Left Bottom translate Scale Scale scale" << endl;
342  *fps << " " << 1/scale << " setlinewidth Box stroke" << endl;
343  if ( flags == 2 ) {
344  *fps << " 0 0.1 1 {" << endl;
345  *fps << " /f exch def" << endl;
346  *fps << " 0 4 Origin length 4 sub {" << endl;
347  *fps << " /Index exch def" << endl;
348  *fps << " /x Origin Index get def" << endl;
349  *fps << " /y Origin Index 1 add get def" << endl;
350  *fps << " /v Origin Index 3 add get def" << endl;
351  *fps << " v f ge {" << endl;
352  *fps << " 1 v sub setgray" << endl;
353  *fps << " x y 0.5 0 360 arc fill" << endl;
354  *fps << " } if" << endl;
355  *fps << " } for stroke" << endl;
356  *fps << " } for" << endl;
357  } else {
358  *fps << " /n 0 def" << endl;
359  *fps << " 0 4 Origin length 4 sub {" << endl;
360  *fps << " /Index exch def" << endl;
361  *fps << " /x Origin Index get def" << endl;
362  *fps << " /y Origin Index 1 add get def" << endl;
363  *fps << " x y 0.5 0 360 arc fill" << endl;
364  if ( flags == 1 ) {
365  *fps << " /n n 1 add def" << endl;
366  *fps << " x y moveto 0.02 0.02 rmoveto n cvi (xxxx) cvs show stroke" << endl;
367  }
368  *fps << " } for stroke" << endl;
369  }
370  *fps << "grestore" << endl;
371  *fps << "showpage" << endl;
372 
373  return 0;
374 }
375 
383 {
384  if ( !project ) return 0;
385 
386  int f, nfom;
387  long i, j, nh(200);
388  char tag[256];
389  Bfield* field;
390  Bmicrograph* mg;
391  Breconstruction* rec;
392  Bparticle* part;
393 
394  for ( f=nfom=0; f<NFOM; f++ ) if ( project->fom_tag[f] ) nfom = f + 1;
395 
396  Bstring title("FOM histogram");
397  Bplot* plot = new Bplot(1, nh+1, nfom+1);
398  plot->title(title);
399 
400  plot->page(0).title(title);
401  plot->page(0).columns(nfom+1);
402  for ( i=0; i<=nfom; i++ ) plot->page(0).column(i).number(i);
403  plot->page(0).column(0).label("FOM");
404  plot->page(0).column(0).axis(1);
405  for ( i=1; i<=nfom; i++ ) {
406  get_fom_tag(project->fom_tag[i-1], tag);
407  plot->page(0).column(i).type(1);
408 // plot->page(0).column(i).label("Count");
409  plot->page(0).column(i).label(tag);
410  plot->page(0).column(i).axis(3);
411  plot->page(0).column(i).element_size(0.5);
412  }
413 // plot->page(0).column(nfom).label("Count");
414  plot->page(0).column(1).color(0,0,0);
415  if ( nfom > 1 ) plot->page(0).column(2).color(1,0,0);
416  if ( nfom > 2 ) plot->page(0).column(3).color(0,1,0);
417  if ( nfom > 3 ) plot->page(0).column(4).color(0,0,1);
418  if ( nfom > 4 ) plot->page(0).column(5).color(1,1,0);
419  plot->page(0).axis(1).min(-1);
420  plot->page(0).axis(1).max(1);
421  plot->page(0).axis(1).inc(0.2);
422  plot->page(0).axis(1).label("FOM");
423  plot->page(0).axis(3).label("Count");
424 
425 /*
426  for ( f=i=0; f<NFOM; f++ ) if ( project->fom_tag[f] ) {
427  get_fom_tag(project->fom_tag[f], tag);
428  switch ( i ) {
429  case 0: *fps << " 0 0 0 setcolor" << endl; break;
430  case 1: *fps << " 1 0 0 setcolor" << endl; break;
431  case 2: *fps << " 0 1 0 setcolor" << endl; break;
432  case 3: *fps << " 0 0 1 setcolor" << endl; break;
433  case 4: *fps << " 1 1 0 setcolor" << endl; break;
434  }
435  *fps << left << " " << bottom-100-20*i << " moveto (" << tag << ") show" << endl;
436  i++;
437  }
438 */
439  for ( i=0; i<=nh; i++ ) (*plot)[i] = i*2.0/nh - 1;
440 
441  if ( verbose & VERB_PROCESS ) {
442  if ( nfom < 2 )
443  cout << "Generating file " << filename << " with a FOM histogram" << endl << endl;
444  else
445  cout << "Generating file " << filename << " with " << nfom << " FOM histograms" << endl << endl;
446  }
447 
448  for ( f=0, j=plot->rows(); f<nfom; f++, j+=plot->rows() ) if ( project->fom_tag[f] ) {
449  if ( project->select < 1 ) {
450  for ( field = project->field; field; field = field->next ) {
451  for ( mg = field->mg; mg; mg = mg->next ) {
452  for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
453  i = (long) ((part->fom[f]+1)*nh/2 + 0.5);
454  if ( i < 0 ) i = 0;
455  if ( i > nh ) i = nh;
456  (*plot)[i+j] += 1;
457  }
458  }
459  }
460  } else {
461  for ( rec = project->rec; rec; rec = rec->next ) {
462  for ( part = rec->part; part; part = part->next ) if ( part->sel ) {
463  i = (long) ((part->fom[f]+1)*nh/2 + 0.5);
464  if ( i < 0 ) i = 0;
465  if ( i > nh ) i = nh;
466  (*plot)[i+j] += 1;
467  }
468  }
469  }
470  }
471 
472  if ( verbose & VERB_DEBUG )
473  cout << "DEBUG ps_part_fom_histogram: Histogram data transferred" << endl;
474 
475  ofstream* fps = ps_open_and_init(filename, plot);
476 
477  ps_graph(fps, plot, 1);
478 
479  delete plot;
480 
481 
482  long npart(0);
485 
486  if ( nfom > 1 && npart > 0) {
487  title = "FOM plot";
488  plot = new Bplot(1, npart, nfom);
489  plot->title(title);
490 // cout << "DEBUG ps_part_fom_histogram: page=" << plot->page(0).number() << endl;
491 
492  plot->page(0).title(title);
493  plot->page(0).columns(nfom);
494  for ( i=0; i<nfom; i++ ) plot->page(0).column(i).number(i);
495  get_fom_tag(project->fom_tag[0], tag);
496  plot->page(0).column(0).label(tag);
497  plot->page(0).column(0).axis(1);
498  for ( i=1; i<nfom; i++ ) {
499  get_fom_tag(project->fom_tag[i], tag);
500  plot->page(0).column(i).type(0);
501  plot->page(0).column(i).label(tag);
502  plot->page(0).column(i).axis(3);
503  plot->page(0).column(i).element_size(0.9);
504  }
505 
506  plot->page(0).column(1).color(1,0,0);
507  if ( nfom > 2 ) plot->page(0).column(2).color(0,1,0);
508  if ( nfom > 3 ) plot->page(0).column(3).color(0,0,1);
509  if ( nfom > 4 ) plot->page(0).column(4).color(1,1,0);
510 
511  for ( i=1; i<4; i+=2 ) {
512  plot->page(0).axis(i).min(-1);
513  plot->page(0).axis(i).max(1);
514  plot->page(0).axis(i).inc(0.2);
515  }
516 
517  for ( f=0, j=0; f<nfom; f++, j+=npart ) if ( project->fom_tag[f] ) {
518  if ( project->select < 1 ) {
519  for ( i=0, field = project->field; field; field = field->next ) {
520  for ( mg = field->mg; mg; mg = mg->next ) {
521  for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
522  (*plot)[i+j] = part->fom[f];
523  i++;
524  }
525  }
526  }
527  } else {
528  for ( i=0, rec = project->rec; rec; rec = rec->next ) {
529  for ( part = rec->part; part; part = part->next ) if ( part->sel ) {
530  (*plot)[i+j] = part->fom[f];
531  i++;
532  }
533  }
534  }
535  }
536 
537  if ( verbose & VERB_DEBUG )
538  cout << "DEBUG ps_part_fom_histogram: FOM data: npart=" << npart << " transferred=" << i << endl;
539 
540  ps_graph(fps, plot, 1);
541 
542  delete plot;
543  }
544 
546 
547  ps_close(fps);
548 
549  return 0;
550 }
551 
559 {
560  if ( !project ) return 0;
561 
562  int n(0);
563  long i, nc(2), nh(100);
564  double damax(10), da, dd, a, c, s, ca(0), sa(0), r2(0);
565  double daa(0), das(0), dda(0), dds(0);
566  Bfield* field;
567  Bmicrograph* mg;
568 // Breconstruction* rec;
569 
570  Bstring title("Defocus histogram");
571  Bplot* plot = new Bplot(1, nh+1, nc);
572  plot->title(title);
573 
574  plot->page(0).title(title);
575  plot->page(0).columns(nc);
576  for ( i=0; i<nc; i++ ) plot->page(0).column(i).number(i);
577  plot->page(0).column(0).label("Defocus");
578  plot->page(0).column(0).axis(1);
579  plot->page(0).column(1).type(1);
580  plot->page(0).column(1).label("Count");
581  plot->page(0).column(1).axis(3);
582  plot->page(0).column(1).element_size(0.5);
583  plot->page(0).column(1).color(0,0,0);
584  plot->page(0).axis(1).min(0);
585  plot->page(0).axis(1).max(damax);
586  plot->page(0).axis(1).inc(2);
587  plot->page(0).axis(1).label("Defocus");
588  plot->page(0).axis(3).label("Count");
589 
590  for ( i=0; i<=nh; i++ ) (*plot)[i] = i*damax/nh;
591 
592  for ( field = project->field; field; field = field->next ) {
593  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
594  da = mg->ctf->defocus_average() * 1e-4;
595  dd = mg->ctf->defocus_deviation() * 1e-4;
596  a = mg->ctf->astigmatism_angle();
597  c = cos(a);
598  s = sin(a);
599  ca += c;
600  sa += s;
601 // r2 += c*c + s*s;
602  daa += da;
603  dda += dd;
604  das += da*da;
605  dds += dd*dd;
606  n++;
607  i = (long) (nh*da/damax + 0.5);
608  if ( i < 0 ) i = 0;
609  if ( i > nh ) i = nh;
610  (*plot)[i+nh] += 1;
611  }
612  }
613 
614  daa /= n;
615  dda /= n;
616  das = das/n - daa*daa;
617  dds = dds/n - dda*dda;
618  if ( das > 0 ) das = sqrt(das);
619  else das = 0;
620  if ( dds > 0 ) dds = sqrt(dds);
621  else dds = 0;
622 
623  ca /= n;
624  sa /= n;
625  a = atan2(sa, ca);
626  r2 = ca*ca + sa*sa;
627 
628  if ( verbose ) {
629  cout << "Defocus average: " << daa << " (" << das << ")" << endl;
630  cout << "Defocus deviation: " << dda << " (" << dds << ")" << endl;
631  cout << "Astigmatism angle: " << a*180/M_PI << " (" << sqrt(-log(r2)) << ")" << endl;
632  }
633 
634  if ( verbose & VERB_PROCESS )
635  cout << "Generating file " << filename << " with defocus histograms" << endl << endl;
636 
637  ofstream* fps = ps_open_and_init(filename, plot);
638 
639  ps_graph(fps, plot, 1);
640 
641  delete plot;
642 
643 
644  ps_close(fps);
645 
646  return 0;
647 }
648 
656 {
657  if ( !project ) return 0;
658 
659  long i, j, nc(2);
660  Bfield* field;
661  Bmicrograph* mg;
662 
664 
665  Bstring title("Astigmatism plot");
666  Bplot* plot = new Bplot(1, nmg, nc);
667  plot->title(title);
668 
669  plot->page(0).title(title);
670  plot->page(0).columns(nc);
671  for ( i=0; i<nc; i++ ) plot->page(0).column(i).number(i);
672  plot->page(0).column(0).label("Defocus Deviation");
673  plot->page(0).column(0).axis(1);
674  plot->page(0).column(1).type(0);
675  plot->page(0).column(1).label("Astigmatism Angle");
676  plot->page(0).column(1).axis(3);
677  plot->page(0).column(1).element_size(2);
678  plot->page(0).column(1).color(0,0,0);
679 // plot->page(0).axis(1).min(0);
680 // plot->page(0).axis(1).max(1e4);
681 // plot->page(0).axis(1).inc(1e3);
682  plot->page(0).axis(1).label("Defocus Deviation");
683 // plot->page(0).axis(3).min(-90);
684 // plot->page(0).axis(3).max(90);
685 // plot->page(0).axis(3).inc(15);
686  plot->page(0).axis(3).label("Astigmatism Angle");
687 
688  for ( i=0, j=nmg, field = project->field; field; field = field->next ) {
689  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
690  (*plot)[i++] = mg->ctf->defocus_deviation();
691  (*plot)[j++] = mg->ctf->astigmatism_angle()*180.0/M_PI;
692  }
693  }
694 
695  if ( verbose & VERB_PROCESS )
696  cout << "Generating file " << filename << " with an astigmatism plot" << endl << endl;
697 
698  ofstream* fps = ps_open_and_init(filename, plot);
699 
700  ps_graph(fps, plot, 1);
701 
702  delete plot;
703 
704  ps_close(fps);
705 
706  return 0;
707 }
708 
709 
717 {
718  if ( !project ) return 0;
719  if ( !project->class_avg ) return 0;
720 
721  long i, nc(0), nmax(0), nt(0);
722  double fommax(0);
723  Bparticle* ca = project->class_avg;
724 
725  for ( ca = project->class_avg; ca; ca = ca->next ) if ( ca->sel ) {
726  if ( nmax < ca->sel ) nmax = ca->sel;
727  if ( fommax < ca->fom[0] ) fommax = ca->fom[0];
728  nt += ca->sel;
729  nc++;
730  }
731 
732  nmax = log(nmax) + 1;
733 
734  if ( verbose & VERB_PROCESS )
735  cout << "Generating a class average plot" << endl << endl;
736 
737  Bstring title("Class average FOMs");
738  Bplot* plot = new Bplot(1, nc, 2);
739  plot->title(title);
740 
741  plot->page(0).title(title);
742  plot->page(0).columns(2);
743  for ( i=0; i<2; i++ ) plot->page(0).column(i).number(i);
744  plot->page(0).column(0).label("log(number)");
745  plot->page(0).column(0).axis(1);
746  plot->page(0).column(1).type(0);
747  plot->page(0).column(1).label("FOM");
748  plot->page(0).column(1).axis(3);
749  plot->page(0).column(1).element_size(5);
750  plot->page(0).column(1).color(0,0,0);
751  plot->page(0).axis(1).min(0);
752  plot->page(0).axis(1).max(nmax);
753  plot->page(0).axis(1).flags(2);
754 // plot->page(0).axis(1).inc(2);
755  plot->page(0).axis(1).label("log(number)");
756  plot->page(0).axis(3).min(0);
757  plot->page(0).axis(3).max(fommax);
758  plot->page(0).axis(3).label("FOM");
759 
760  for ( i=0, ca = project->class_avg; ca; ca = ca->next ) if ( ca->sel ) {
761  (*plot)[i] = log(ca->sel);
762  (*plot)[i+nc] = ca->fom[0];
763  i++;
764  }
765 
766  Bstring txt;
767  txt = Bstring(nc, "Number of class averages: %ld");
768  plot->page(0).add_text(txt);
769  txt = Bstring(nt, "Number of particles: %ld");
770  plot->page(0).add_text(txt);
771 
772  ps_graph(fps, plot, 1);
773 
774  delete plot;
775 
776  return 0;
777 }
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
ps_micrograph.h
Header file for postscript tools dealing with micrograph particle sets.
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
ps_defocus_histogram
int ps_defocus_histogram(Bstring &filename, Bproject *project)
Postscript histogram plot of micrograph defocus parameters.
Definition: ps_micrograph.cpp:558
Baxis::flags
long flags()
Definition: Bplot.h:38
Bproject::select
int select
Definition: mg_processing.h:342
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
NFOM
#define NFOM
Definition: mg_processing.h:16
ps_class_average_fom
int ps_class_average_fom(ofstream *fps, Bproject *project)
Postscript histogram plot of class average FOM's.
Definition: ps_micrograph.cpp:716
Bstring
Definition: Bstring.h:29
Bplot::rows
void rows(long n)
Definition: Bplot.h:212
Bparticle
Definition: mg_processing.h:90
Bproject::field
Bfield * field
Definition: mg_processing.h:346
symmetry.h
Header file for general symmetry functions.
Bcolumn::color
double * color()
Definition: Bplot.h:76
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:110
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bcolumn::element_size
double element_size()
Definition: Bplot.h:74
ps_part_fom_histogram
int ps_part_fom_histogram(Bstring &filename, Bproject *project)
Postscript plot of the particle FOM histogram.
Definition: ps_micrograph.cpp:382
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
Bplot
Definition: Bplot.h:146
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
View
Definition: View.h:26
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bcolumn::type
long type()
Definition: Bplot.h:66
Bfield
Definition: mg_processing.h:260
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bsymmetry
Definition: symmetry.h:38
Bcolumn::axis
long axis()
Definition: Bplot.h:68
ps_plot.h
Header file for postscript output functions.
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
change_views_to_asymmetric_unit
int change_views_to_asymmetric_unit(Bsymmetry *sym, View *view)
Change the views to those in the asymmetric unit.
Definition: symmetry.cpp:828
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
ps_close
int ps_close(ofstream *fps)
Closes a postscript file.
Definition: ps_plot.cpp:105
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
ps_open_and_init
ofstream * ps_open_and_init(Bstring filename, Bstring title, int npages, int width, int height)
Opens and initializes a postscript file.
Definition: ps_plot.cpp:32
Baxis::inc
double inc()
Definition: Bplot.h:34
ps_mg_particle_positions
int ps_mg_particle_positions(Bstring &filename, Bstring &title, Bproject *project)
Postscript plot of the positions of particles on micrographs.
Definition: ps_micrograph.cpp:30
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
get_fom_tag
Bstring get_fom_tag(FOMType fom_type)
Returns the tag associated with a particular FOM.
Definition: mg_processing.cpp:2612
verbose
int verbose
Bpage::add_text
void add_text(Bstring &s)
Definition: Bplot.h:122
Bimage
General image parameter class.
Definition: Bimage.h:177
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Bproject
Definition: mg_processing.h:336
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bplot::title
Bstring & title()
Definition: Bplot.h:194
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:108
ps_astigmatism_plot
int ps_astigmatism_plot(Bstring &filename, Bproject *project)
Postscript plot of micrograph astigmatism parameters.
Definition: ps_micrograph.cpp:655
Baxis::min
double min()
Definition: Bplot.h:30
ps_views
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
Definition: ps_views.cpp:34
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
ps_graph
int ps_graph(ofstream *fps, Bplot *plot, int page_number)
Generates postscript graphs.
Definition: ps_plot.cpp:247
Baxis::label
Bstring & label()
Definition: Bplot.h:28
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
Breconstruction
Definition: mg_processing.h:283
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:348
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
project_count_rec_part_selected
long project_count_rec_part_selected(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:523
Bfield::next
Bfield * next
Definition: mg_processing.h:261
ps_particle_views_origins
int ps_particle_views_origins(Bstring &filename, Bstring &title, Bstring &symmetry_string, Bproject *project, int selection)
Generates asymmetric unit particle view and origin postscript plots.
Definition: ps_micrograph.cpp:121
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
ps_origins
int ps_origins(ofstream *fps, Bstring &title, Bproject *project, int flags)
Definition: ps_micrograph.cpp:187
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
linked_list.h
Header file for generalized linked list functions.
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
views_from_project
View * views_from_project(Bproject *project, int selection)
Retrieves the particle views from a project.
Definition: mg_processing.cpp:2566
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:216
Bparticle::mag
double mag
Definition: mg_processing.h:95
Bcolumn::number
long number()
Definition: Bplot.h:61
Baxis::max
double max()
Definition: Bplot.h:32
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
ps_views.h
Header file for postscript tools dealing with views.
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_select.cpp:350
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
Bproject::fom_tag
FOMType fom_tag[NFOM]
Definition: mg_processing.h:345