Bsoft  2.1.0
Bernard's software package
mg_select.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "mg_select.h"
11 #include "mg_tags.h"
12 #include "qsort_functions.h"
13 #include "linked_list.h"
14 #include "math_util.h"
15 #include "random_numbers.h"
16 #include "utilities.h"
17 #include <fstream>
18 
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21 
33 Bfield* field_find_id(Bfield* field, Bstring& field_id)
34 {
35  while ( field && field->id != field_id )
36  field = field->next;
37 
38  return field;
39 }
40 
64 Bmicrograph* field_find_micrograph(Bfield* field, int mg_select, int mg_index, double mg_ang)
65 {
66  Bmicrograph* mg = NULL; // Selected micrograph
67 
68  switch ( mg_select ) {
69  case 0:
70  case 1:
71  mg = field_find_micrograph_by_focus(field, mg_select, mg_index);
72  break;
73  case 2:
74  mg = field_find_micrograph_n(field, mg_index);
75  break;
76  case 3:
77  mg = field_find_micrograph_by_rotang(field, mg_ang);
78  break;
79  case 4:
80  mg = field_find_micrograph_by_tiltang(field, mg_ang);
81  break;
82  }
83 
84  // Error checking (primarily to catch programming mistakes)
85  if ( !mg )
86  error_show("Error: No appropriate micrograph has been selected!", __FILE__, __LINE__);
87 
88  return mg;
89 }
90 
105 {
106  int i; // index
107  Bmicrograph* mg = NULL; // micrograph
108 
109  for ( i=1, mg = field->mg; mg && i < n; mg = mg->next, i++ ) ;
110 
111  if ( !mg ) { // Make sure n is in appropriate range
112  cerr << "Error: The micrograph index you wish to find (" << n << ") is greater" << endl;
113  cerr << "than the number of micrographs (" << i << ") in the field (" << field->id << ")" << endl;
114  }
115 
116  return mg;
117 }
118 
142 Bmicrograph* field_find_micrograph_by_focus(Bfield* field, int focus_opt, int iselect)
143 {
144  int i; // index
145  int nmgs; // number of micrographs in field
146  int count; // used to test if multiple micrographs have same focus level
147  double focus(0); // designated focus level, depends on focus_opt and index
148  Bmicrograph* mg = NULL; // pointer to micrograph at desired focal level
149 
150  nmgs = field_count_micrographs(field);
151 
152  float* focal_series = new float[nmgs];
153 
154  // Put defocal values into an array, then put in order min to max
155  for ( i = 0, mg = field->mg; mg; mg = mg->next, i++ ) {
156  focal_series[i] = 0;
157  if ( mg->ctf ) focal_series[i] = mg->ctf->defocus_average();
158  else cerr << "Warning in field_find_micrograph_by_focus: CTF structure not allocated!" << endl;
159  }
160 
161  qsort((void *) focal_series, nmgs, sizeof(float), (int (*)(const void *, const void *)) QsortSmallToLargeFloat);
162 
163  // Select (index+1)th closest-to-focus or farthest-from-focus value
164  if ( focus_opt == 0 ) focus = focal_series[0+iselect];
165  if ( focus_opt == 1 ) focus = focal_series[nmgs-1-iselect];
166  for ( count = 0, i=0; i<nmgs; i++ ) if ( focus == focal_series[i] ) count++;
167 
168  delete[] focal_series;
169 
170  // Find micrograph with the selected focus level
171  for ( mg = field->mg; mg && mg->ctf && mg->ctf->defocus_average() != focus; mg = mg->next ) ;
172 
173  if (verbose & VERB_PROCESS)
174  cout << "Focus of selected micrograph: " << focus << endl;
175 
176  if ( (count > 1) || (count == 0) ) {
177  cerr << "Error: There are " << count << " micrographs with focus levels of " << focus << endl;
178  cerr << "Please check data or select with a different criterion" << endl;
179  }
180 
181  return mg;
182 }
183 
200 {
201  int count; // used to test if multiple micrographs have same rotang
202  double closest_angle(0); // Closest angle to requested angle
203  double mindiff = 1e37; // Minimum difference between requested and available angle
204  Bmicrograph* mg = NULL; // pointer to micrograph with specified rotang
205 
206  // Find micrograph with the input rot. angle
207  for ( mindiff = 1e37, mg = field->mg; mg; mg = mg->next ) {
208  if ( fabs(rotang - mg->rot_angle) < mindiff ) {
209  mindiff = fabs(rotang - mg->rot_angle);
210  closest_angle = mg->rot_angle;
211  }
212  }
213 
214  for ( count = 0, mg = field->mg; mg; mg = mg->next)
215  if ( fabs(closest_angle - mg->rot_angle) < 1e-10 ) count++;
216 
217  for ( mg = field->mg; mg && closest_angle != mg->rot_angle; mg = mg->next ) ;
218 
219  if ( (count > 1) || (count == 0) ) {
220  cerr << "Error: There are " << count << " micrographs with the rotational angle of "
221  << closest_angle*180/M_PI << endl;
222  cerr << "Please check data or select with a different criterion" << endl;
223  }
224 
225  return mg;
226 }
227 
244 {
245  int count; // used to test if multiple micrographs have same rotang
246  double closest_angle(0); // Closest angle to requested angle
247  double mindiff = 1e37; // Minimum difference between requested and available angle
248  Bmicrograph* mg = NULL; // pointer to micrograph with specified rotang
249 
250  // Find micrograph with the input tilt angle
251  for ( mindiff = 1e37, mg = field->mg; mg; mg = mg->next ) {
252  if ( fabs(tiltang - mg->tilt_angle) < mindiff ) {
253  mindiff = fabs(tiltang - mg->tilt_angle);
254  closest_angle = mg->tilt_angle;
255  }
256  }
257 
258  for ( count = 0, mg = field->mg; mg; mg = mg->next)
259  if ( fabs(closest_angle - mg->tilt_angle) < 1e-10 ) count++;
260 
261  for ( mg = field->mg; mg && (closest_angle != mg->tilt_angle); mg = mg->next ) ;
262 
263  if ( (count > 1) || (count == 0) ) {
264  cerr << "Error: There are " << count << " micrographs with the tilt angle of "
265  << closest_angle*180/M_PI << endl;
266  cerr << "Please check data or select with a different criterion" << endl;
267  }
268 
269  return mg;
270 }
271 
282 {
283  if ( !field ) return NULL;
284 
285  double min_angle(M_PI);
286  Bmicrograph* mg;
287  Bmicrograph* mg_ref = field->mg;
288 
289  for ( mg = field->mg; mg; mg = mg->next ) {
290  if ( min_angle > fabs(mg->tilt_angle) ) {
291  min_angle = fabs(mg->tilt_angle);
292  mg_ref = mg;
293  }
294 // cout << mg->tilt_angle << tab << min_angle << endl;
295  }
296 
297  if ( !mg_ref )
298  cerr << "Warning: No zero tilt micrograph found!" << endl;
299 
300  return mg_ref;
301 }
302 
313 {
314  if ( !field ) return NULL;
315 
316  double min_angle = M_PI;
317  Bmicrograph* mg;
318  Bmicrograph* mg_ref = NULL;
319 
320  for ( mg = field->mg; mg; mg = mg->next ) {
321  if ( mg->mark && min_angle > fabs(mg->tilt_angle) ) {
322  min_angle = fabs(mg->tilt_angle);
323  mg_ref = mg;
324  }
325  }
326 
327  return mg_ref;
328 }
329 
336 {
337  Bfield* field;
338  long nfield(0);
339 
340  for ( field = project->field; field; field = field->next ) nfield++;
341 
342  return nfield;
343 }
344 
351 {
352  Bfield* field;
353  Bmicrograph* mg;
354  long nmg(0);
355 
356  for ( field = project->field; field; field = field->next )
357  for ( mg = field->mg; mg; mg = mg->next ) nmg++;
358 
359  return nmg;
360 }
361 
368 {
369  Bfield* field;
370  Bmicrograph* mg;
371  long nmg(0);
372 
373  for ( field = project->field; field; field = field->next )
374  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) nmg++;
375 
376  return nmg;
377 }
378 
385 {
386  Breconstruction* rec;
387  long nrec(0);
388 
389  for ( rec = project->rec; rec; rec = rec->next ) nrec++;
390 
391  return nrec;
392 }
393 
400 {
401  Breconstruction* rec;
402  long nrec(0);
403 
404  for ( rec = project->rec; rec; rec = rec->next )
405  if ( rec->select ) nrec++;
406 
407  return nrec;
408 }
409 
416 {
417  Bfield* field;
418  Bmicrograph* mg;
419  Bparticle* part;
420  long npart(0);
421 
422  for ( field = project->field; field; field = field->next )
423  for ( mg = field->mg; mg; mg = mg->next )
424  for ( part = mg->part; part; part = part->next ) npart++;
425 
426  return npart;
427 }
428 
438 {
439  long nsel(0);
440  Bfield* field = NULL;
441  Bmicrograph* mg = NULL;
442  Bparticle* part = NULL;
443 
444  for ( field = project->field; field; field = field->next )
445  for ( mg = field->mg; mg; mg = mg->next )
446  for ( part = mg->part; part; part = part->next )
447  if ( part->sel > 0 ) nsel++;
448 
449  return nsel;
450 }
451 
462 {
463  if ( num_select < 0 ) return project_count_mg_part_selected(project);
464 
465  long nsel(0);
466  Bfield* field = NULL;
467  Bmicrograph* mg = NULL;
468  Bparticle* part = NULL;
469 
470  for ( field = project->field; field; field = field->next )
471  for ( mg = field->mg; mg; mg = mg->next )
472  for ( part = mg->part; part; part = part->next )
473  if ( part->sel == num_select ) nsel++;
474 
475  return nsel;
476 }
477 
484 {
485  Bfield* field;
486  Bmicrograph* mg;
487  Bparticle* part;
488  long ngrp(0);
489 
490  for ( field = project->field; field; field = field->next )
491  for ( mg = field->mg; mg; mg = mg->next ) {
492  for ( part = mg->part; part && part->next; part = part->next )
493  if ( part->group != part->next->group ) ngrp++;
494  if ( part ) ngrp++;
495  }
496 
497  return ngrp;
498 }
499 
500 
507 {
508  Breconstruction* rec;
509  Bparticle* part;
510  long npart(0);
511 
512  for ( rec = project->rec; rec; rec = rec->next )
513  for ( part = rec->part; part; part = part->next ) npart++;
514 
515  return npart;
516 }
517 
524 {
525  Breconstruction* rec;
526  Bparticle* part;
527  long npart(0);
528 
529  for ( rec = project->rec; rec; rec = rec->next )
530  for ( part = rec->part; part; part = part->next )
531  if ( part->sel ) npart++;
532 
533  return npart;
534 }
535 
542 {
543  Breconstruction* rec;
544  Bparticle* part;
545  long ngrp(0);
546 
547  for ( rec = project->rec; rec; rec = rec->next ) {
548  for ( part = rec->part; part && part->next; part = part->next )
549  if ( part->group != part->next->group ) ngrp++;
550  if ( part ) ngrp++;
551  }
552 
553  return ngrp;
554 }
555 
565 {
566  long nfil(0);
567  Bfield* field = NULL;
568  Bmicrograph* mg = NULL;
569  Bfilament* fil = NULL;
570 
571  for ( field = project->field; field; field = field->next )
572  for ( mg = field->mg; mg; mg = mg->next )
573  for ( fil=mg->fil; fil; fil=fil->next )
574  nfil++;
575 
576  return nfil;
577 }
578 
588 {
589  long nfn(0);
590  Bfield* field = NULL;
591  Bmicrograph* mg = NULL;
592  Bfilament* fil = NULL;
593  Bfilnode* fnode = NULL;
594 
595  for ( field = project->field; field; field = field->next )
596  for ( mg = field->mg; mg; mg = mg->next )
597  for ( fil=mg->fil; fil; fil=fil->next )
598  for ( fnode=fil->node; fnode; fnode=fnode->next )
599  nfn++;
600 
601  return nfn;
602 }
603 
613 {
614  long nfil(0);
615  Breconstruction* rec;
616  Bfilament* fil = NULL;
617 
618  for ( rec = project->rec; rec; rec = rec->next )
619  for ( fil = rec->fil; fil; fil = fil->next )
620  nfil++;
621 
622  return nfil;
623 }
624 
634 {
635  long nfil(0);
636  Breconstruction* rec;
637  Bfilament* fil = NULL;
638  Bfilnode* fnode = NULL;
639 
640  for ( rec = project->rec; rec; rec = rec->next )
641  for ( fil = rec->fil; fil; fil = fil->next )
642  for ( fnode = fil->node; fnode; fnode = fnode->next )
643  nfil++;
644 
645  return nfil;
646 }
647 
657 long field_count(Bfield* field)
658 {
659  long nfield;
660 
661  for ( nfield=0; field; nfield++ ) field = field->next;
662 
663  return nfield;
664 }
665 
672 {
673  Bmicrograph* mg;
674  long nmg(0);
675 
676  for ( mg = field->mg; mg; mg = mg->next ) nmg++;
677 
678  return nmg;
679 }
680 
687 {
688  Bmicrograph* mg;
689  long nmg(0);
690 
691  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) nmg++;
692 
693  return nmg;
694 }
695 
702 {
703  Bmicrograph* mg;
704  Bparticle* part;
705  long npart(0);
706 
707  for ( mg = field->mg; mg; mg = mg->next )
708  for ( part = mg->part; part; part = part->next ) npart++;
709 
710  return npart;
711 }
712 
723 {
724  long nmg;
725 
726  for ( nmg=0; mg; nmg++ ) mg = mg->next;
727 
728  return nmg;
729 }
730 
737 {
738  Bparticle* part;
739  long npart(0);
740 
741  for ( part = mg->part; part; part = part->next ) npart++;
742 
743  return npart;
744 }
745 
756 {
757  long npart;
758 
759  for ( npart=0; part; npart++ ) part = part->next;
760 
761  return npart;
762 }
763 
774 {
775  long nsel;
776 
777  for ( nsel=0; part; part=part->next ) if ( part->sel > 0 ) nsel++;
778 
779  return nsel;
780 }
781 
792 {
793  long nfil;
794 
795  for ( nfil=0; fil; fil=fil->next ) nfil++;
796 
797  return nfil;
798 }
799 
810 {
811  long nfil;
812  Bfilnode* fnode;
813 
814  for ( nfil=0; fil; fil=fil->next )
815  for ( fnode=fil->node; fnode; fnode=fnode->next ) nfil++;
816 
817  return nfil;
818 }
819 
826 {
827  long smax(0);
828  Bfield* field = project->field;
829  Breconstruction* rec = project->rec;
830  Bmicrograph* mg;
831  Bparticle* part;
832 
833  if ( project->select < 1 ) {
834  for ( field = project->field; field; field = field->next )
835  for ( mg = field->mg; mg; mg = mg->next )
836  for ( part = mg->part; part; part = part->next )
837  if ( smax < part->sel ) smax = part->sel;
838  } else {
839  for ( rec = project->rec; rec; rec = rec->next )
840  for ( part = rec->part; part; part = part->next )
841  if ( smax < part->sel ) smax = part->sel;
842  }
843 
844  return smax;
845 }
846 
853 {
854  if ( !project ) return 0;
855 
856  long i, maxsel, nsel(0);
857  Bfield* field = project->field;
858  Breconstruction* rec = project->rec;
859  Bmicrograph* mg;
860  Bparticle* part;
861  int* sel = NULL;
862 
863  if ( field && field->mg && field->mg->part ) {
864  for ( maxsel=0, field = project->field; field; field = field->next )
865  for ( mg = field->mg; mg; mg = mg->next )
866  for ( part = mg->part; part; part = part->next )
867  if ( maxsel < part->sel ) maxsel = part->sel;
868  maxsel++;
869  sel = new int[maxsel];
870  for ( i=0; i<maxsel; i++ ) sel[i] = 0;
871  for ( field = project->field; field; field = field->next )
872  for ( mg = field->mg; mg; mg = mg->next )
873  for ( part = mg->part; part; part = part->next )
874  if ( part->sel > 0 ) sel[part->sel]++;
875  cout << "Micrograph selection numbers: ";
876  for ( i=1; i<maxsel; i++ )
877  if ( sel[i] ) cout << tab << i;
878  cout << endl;
879  delete[] sel;
880  }
881 
882  if ( rec && rec->part ) {
883  for ( maxsel=0, rec = project->rec; rec; rec = rec->next )
884  for ( part = rec->part; part; part = part->next )
885  if ( maxsel < part->sel ) maxsel = part->sel;
886  maxsel++;
887  sel = new int[maxsel];
888  for ( i=0; i<maxsel; i++ ) sel[i] = 0;
889  for ( rec = project->rec; rec; rec = rec->next )
890  for ( part = rec->part; part; part = part->next )
891  if ( part->sel > 0 ) sel[part->sel]++;
892  cout << "Reconstruction selection numbers: ";
893  for ( i=1; i<maxsel; i++ )
894  if ( sel[i] ) cout << tab << i;
895  cout << endl;
896  delete[] sel;
897  }
898 
899  return nsel;
900 }
901 
908 {
909  if ( !project ) return 0;
910 
911  long i, f, smax(0);
912  long nmg(0), nrec(0), ntotsel(0);
913  Bfield* field = project->field;
914  Breconstruction* rec = project->rec;
915  Bmicrograph* mg;
916  Bparticle* part;
917 
918  double pp(0), fomavg[NFOM], fomstd[NFOM], fommin[NFOM], fommax[NFOM];
919 
920  long npart = project_count_mg_particles(project);
921 
922  if ( npart && field && field->mg ) {
924  for ( smax=0, field = project->field; field; field = field->next )
925  if ( field->select )
926  for ( mg = field->mg; mg; mg = mg->next )
927  if ( mg->select )
928  for ( part = mg->part; part; part = part->next )
929  if ( smax < part->sel ) smax = part->sel;
930  if ( verbose ) {
931  cout << "Micrographs selected: " << nmg << endl;
932  cout << "Maximum selection number: " << smax << endl;
933  }
934  vector<int> nsel(smax+1, 0);
935  vector<int> ntot(smax+1, 0);
936  vector<int> npercent(smax+1, 0);
937  vector<int> fom(smax+1, 0);
938  for ( f=0; f<NFOM; f++ ) {
939  fomavg[f] = fomstd[f] = 0;
940  fommin[f] = 1;
941  fommax[f] = -1;
942  }
943  if ( verbose & VERB_PROCESS ) {
944  cout << "Field\tMgraph";
945  for ( i=0; i<=smax; i++ ) cout << tab << i;
946  cout << endl;
947  }
948  for ( field = project->field; field; field = field->next ) if ( field->select ) {
949  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
950  for ( i=0; i<=smax; i++ ) nsel[i] = 0;
951  for ( part = mg->part; part; part = part->next ) {
952  if ( part->sel > -1 ) {
953  nsel[part->sel]++;
954  fom[part->sel] += part->fom[0];
955  if ( part->sel > 0 ) {
956  ntotsel++;
957  for ( f=0; f<NFOM; f++ ) {
958  fomavg[f] += part->fom[f];
959  fomstd[f] += part->fom[f]*part->fom[f];
960  if ( fommin[f] > part->fom[f] ) fommin[f] = part->fom[f];
961  if ( fommax[f] < part->fom[f] ) fommax[f] = part->fom[f];
962  }
963  }
964  }
965  }
966  for ( i=0; i<=smax; i++ ) ntot[i] += nsel[i];
967  if ( verbose & VERB_PROCESS ) {
968  cout << field->id << tab << mg->id;
969  for ( i=0; i<=smax; i++ ) cout << tab << nsel[i];
970  cout << endl;
971  }
972  }
973  }
974  for ( i=0; i<=smax; i++ ) {
975  if ( ntot[i] ) fom[i] /= ntot[i];
976  if ( npart ) npercent[i] = ntot[i]*100.0/npart;
977  }
978  if ( ntotsel ) {
979  for ( f=0; f<NFOM; f++ ) {
980  fomavg[f] /= ntotsel;
981  fomstd[f] = fomstd[f]/ntotsel - fomavg[f]*fomavg[f];
982  if ( fomstd[f] > 0 ) fomstd[f] = sqrt(fomstd[f]);
983  else fomstd[f] = 0;
984  }
985  }
986  if ( verbose & VERB_PROCESS ) {
987  cout << "Totals\t";
988  for ( i=0; i<=smax; i++ ) cout << tab << ntot[i];
989  cout << endl << "Percent\t";
990  for ( i=0; i<=smax; i++ ) cout << tab << npercent[i];
991  cout << endl << "FOM\t";
992  for ( i=0; i<=smax; i++ ) cout << tab << fom[i];
993  cout << endl << endl;
994  }
995  if ( npart ) pp = ntotsel*100.0/npart;
996  cout << "Overall selected FOM average and standard deviation:" << endl;
997  cout << "Selected particle images: " << ntotsel << " (" << pp << "%)" << endl;
998  for ( f=0; f<NFOM; f++ ) if ( project->fom_tag[f] )
999  cout << "FOM" << f << ": " <<
1000  fommin[f] << tab << fommax[f] << tab << fomavg[f] << tab << fomstd[f] << endl;
1001  cout << endl;
1002  }
1003 
1005 
1006  if ( npart && rec && rec->part ) {
1008  for ( smax=0, rec = project->rec; rec; rec = rec->next )
1009  if ( rec->select )
1010  for ( part = rec->part; part; part = part->next )
1011  if ( smax < part->sel ) smax = part->sel;
1012  if ( verbose ) {
1013  cout << "Reconstructions selected: " << nrec << endl;
1014  cout << "Maximum particle selection number:" << smax << endl;
1015  }
1016  vector<int> nsel(smax+1, 0);
1017  vector<int> ntot(smax+1, 0);
1018  vector<int> npercent(smax+1, 0);
1019  vector<int> fom(smax+1, 0);
1020  for ( f=0; f<NFOM; f++ ) {
1021  fomavg[f] = fomstd[f] = 0;
1022  fommin[f] = 1;
1023  fommax[f] = -1;
1024  }
1025  if ( verbose & VERB_PROCESS ) {
1026  cout << "Recons";
1027  for ( i=0; i<=smax; i++ ) cout << tab << i;
1028  cout << endl;
1029  }
1030  for ( rec = project->rec; rec; rec = rec->next ) if ( rec->select ) {
1031  for ( i=0; i<=smax; i++ ) nsel[i] = 0;
1032  for ( part = rec->part; part; part = part->next ) {
1033  if ( part->sel > -1 ) {
1034  nsel[part->sel]++;
1035  fom[part->sel] += part->fom[0];
1036  if ( part->sel > 0 ) {
1037  ntotsel++;
1038  for ( f=0; f<NFOM; f++ ) {
1039  fomavg[f] += part->fom[f];
1040  fomstd[f] += part->fom[f]*part->fom[f];
1041  if ( fommin[f] > part->fom[f] ) fommin[f] = part->fom[f];
1042  if ( fommax[f] < part->fom[f] ) fommax[f] = part->fom[f];
1043  }
1044  }
1045  }
1046  }
1047  for ( i=0; i<=smax; i++ ) ntot[i] += nsel[i];
1048  if ( verbose & VERB_PROCESS ) {
1049  cout << rec->id;
1050  for ( i=0; i<=smax; i++ ) cout << tab << nsel[i];
1051  cout << endl;
1052  }
1053  }
1054  for ( i=0; i<=smax; i++ ) {
1055  if ( ntot[i] ) fom[i] /= ntot[i];
1056  if ( npart ) npercent[i] = ntot[i]*100.0/npart;
1057  }
1058  if ( ntotsel ) {
1059  for ( f=0; f<NFOM; f++ ) {
1060  fomavg[f] /= ntotsel;
1061  fomstd[f] = fomstd[f]/ntotsel - fomavg[f]*fomavg[f];
1062  if ( fomstd[f] > 0 ) fomstd[f] = sqrt(fomstd[f]);
1063  else fomstd[f] = 0;
1064  }
1065  }
1066  if ( verbose & VERB_PROCESS ) {
1067  cout << "Totals";
1068  for ( i=0; i<=smax; i++ ) cout << tab << ntot[i];
1069  cout << endl << "Percent";
1070  for ( i=0; i<=smax; i++ ) cout << tab << npercent[i];
1071  cout << endl << "FOM";
1072  for ( i=0; i<=smax; i++ ) cout << tab << fom[i];
1073  cout << endl << endl;
1074  }
1075  pp = 0;
1076  if ( npart ) pp = ntotsel*100.0/npart;
1077  cout << "Overall selected FOM average and standard deviation:" << endl;
1078  cout << "Selected particle images: " << ntotsel << " (" << pp << " %)" << endl;
1079  for ( f=0; f<NFOM; f++ ) if ( project->fom_tag[f] )
1080  cout << "FOM" << f << ": " <<
1081  fommin[f] << tab << fommax[f] << tab << fomavg[f] << tab << fomstd[f] << endl;
1082  cout <<endl;
1083  }
1084 
1085  if ( project->class_avg ) {
1086  cout << "Class averages: " << particle_count(project->class_avg) << endl << endl;
1087  }
1088 
1089  return ntotsel;
1090 }
1091 
1099 {
1100  if ( !project ) return 0;
1101 
1102  if ( show < 0 ) return 0;
1103 
1104  int f;
1105  long nsel(0), npart(0);
1106  Bfield* field = project->field;
1107  Breconstruction* rec = project->rec;
1108  Bmicrograph* mg;
1109  Bparticle* part;
1110 
1111  if ( field && field->mg && field->mg->part ) {
1112  for ( field = project->field; field; field = field->next ) if ( field->select ) {
1113  cout << "Field: " << field->id << endl;
1114  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
1115  cout << "Micrograph: " << mg->id << endl;
1116  for ( part = mg->part; part; part = part->next ) {
1117  if ( part->sel == show ) {
1118  cout << part->id << tab << part->ori[0] << tab
1119  << part->ori[1] << tab << part->view[0] << tab
1120  << part->view[1] << tab << part->view[2] << tab
1121  << part->view.angle()*180/M_PI;
1122  for ( f=0; f<NFOM; f++ ) cout << tab << part->fom[f];
1123  cout << endl;
1124  nsel++;
1125  }
1126  npart++;
1127  }
1128  cout << endl;
1129  }
1130  }
1131  cout << "Particles selected: " << nsel << " (" << nsel*100.0/npart << " %)" << endl << endl;
1132  }
1133 
1134  if ( rec && rec->part ) {
1135  for ( npart=nsel=0, rec = project->rec; rec; rec = rec->next ) if ( rec->select ) {
1136  cout << "Reconstruction: " << rec->id << endl;
1137  for ( part = rec->part; part; part = part->next ) {
1138  if ( part->sel == show ) {
1139  cout << part->id << tab << part->ori[0] << tab
1140  << part->ori[1] << tab << part->view[0] << tab
1141  << part->view[1] << tab << part->view[2] << tab
1142  << part->view.angle()*180/M_PI;
1143  for ( f=0; f<NFOM; f++ ) cout << tab << part->fom[f];
1144  cout << endl;
1145  nsel++;
1146  }
1147  npart++;
1148  }
1149  cout << endl;
1150  }
1151  cout << "Particles selected: " << nsel << " (" << nsel*100.0/npart << " %)" << endl << endl;
1152  }
1153 
1154  return nsel;
1155 }
1156 
1158 {
1159  cout << mg->id << tab;
1160 
1161  if ( tag == MICROGRAPH_FILE ) cout << mg->fmg;
1162  else if ( tag == MICROGRAPH_FRAMES_FILE ) cout << mg->fframe;
1163  else if ( tag == PARTICLE_FILE ) cout << mg->fpart;
1164  else if ( tag == MICROGRAPH_FILAMENT_FILE ) cout << mg->ffil;
1165  else if ( tag == MICROGRAPH_TRANSFORM_FILE ) cout << mg->fft;
1166  else if ( tag == MICROGRAPH_POWERSPEC_FILE ) cout << mg->fps;
1167  else if ( tag == MICROGRAPH_NUMBER ) cout << mg->img_num;
1168  else if ( tag == MICROGRAPH_SELECT ) cout << mg->select;
1169  else if ( tag == MICROGRAPH_FOM ) cout << mg->fom;
1170  else if ( tag == MICROGRAPH_PIXEL_X ) cout << mg->pixel_size[0];
1171  else if ( tag == MICROGRAPH_PIXEL_Y ) cout << mg->pixel_size[1];
1172  else if ( tag == MICROGRAPH_DOSE ) cout << mg->dose;
1173  else if ( tag == MICROGRAPH_WATER_RING ) cout << mg->wri;
1174  else if ( tag == MICROGRAPH_ORIGIN_X ) cout << mg->origin[0];
1175  else if ( tag == MICROGRAPH_ORIGIN_Y ) cout << mg->origin[1];
1176  else if ( tag == MICROGRAPH_SCALE_X ) cout << mg->scale[0];
1177  else if ( tag == MICROGRAPH_SCALE_Y ) cout << mg->scale[1];
1178  else if ( tag == MICROGRAPH_TILT_AXIS ) cout << mg->tilt_axis;
1179  else if ( tag == MICROGRAPH_TILT_ANGLE) cout << mg->tilt_angle;
1180  else if ( tag == MICROGRAPH_LEVEL_ANGLE) cout << mg->level_angle;
1181  else if ( tag == MICROGRAPH_ROT_ANGLE ) cout << mg->rot_angle;
1182  cout << endl;
1183 
1184  return 0;
1185 }
1186 
1188 {
1189  int float_flag(1), idata(0);
1190  float fdata(0);
1191  Euler euler;
1192 
1193  euler = Euler(part->view);
1194  if ( tag == PARTICLE_X ) fdata = part->loc[0];
1195  else if ( tag == PARTICLE_Y ) fdata = part->loc[1];
1196  else if ( tag == PARTICLE_Z ) fdata = part->loc[2];
1197  else if ( tag == PARTICLE_PIXEL ) fdata = part->pixel_size[0];
1198  else if ( tag == PARTICLE_PIXEL_X ) fdata = part->pixel_size[0];
1199  else if ( tag == PARTICLE_PIXEL_Y ) fdata = part->pixel_size[1];
1200  else if ( tag == PARTICLE_PIXEL_Z ) fdata = part->pixel_size[2];
1201  else if ( tag == PARTICLE_ORIGIN_X ) fdata = part->ori[0];
1202  else if ( tag == PARTICLE_ORIGIN_Y ) fdata = part->ori[1];
1203  else if ( tag == PARTICLE_ORIGIN_Z ) fdata = part->ori[2];
1204  else if ( tag == PARTICLE_DEFOCUS ) fdata = part->def;
1205  else if ( tag == PARTICLE_DEF_DEV ) fdata = part->dev;
1206  else if ( tag == PARTICLE_AST_ANG ) fdata = part->ast;
1207  else if ( tag == PARTICLE_MAGNIF ) fdata = part->mag;
1208  else if ( tag == PARTICLE_VIEW_X ) fdata = part->view[0];
1209  else if ( tag == PARTICLE_VIEW_Y ) fdata = part->view[1];
1210  else if ( tag == PARTICLE_VIEW_Z ) fdata = part->view[2];
1211  else if ( tag == PARTICLE_VIEW_ANGLE ) fdata = part->view.angle();
1212  else if ( tag == PARTICLE_PSI ) fdata = euler.psi()*180/M_PI;
1213  else if ( tag == PARTICLE_THETA ) fdata = euler.theta()*180/M_PI;
1214  else if ( tag == PARTICLE_PHI ) fdata = euler.phi()*180/M_PI;
1215  else if ( tag == PARTICLE_OMEGA ) fdata = -euler.psi()*180/M_PI;
1216  else if ( tag == PARTICLE_FOM ) fdata = part->fom[0];
1217  else if ( tag == PARTICLE_FOM_CV ) fdata = part->fom[1];
1218  else if ( tag == PARTICLE_HANDA_FOM ) fdata = part->fom[1];
1219  else if ( tag == PARTICLE_HANDB_FOM ) fdata = part->fom[2];
1220  else if ( tag == PARTICLE_SELECT ) {
1221  idata = part->sel;
1222  float_flag = 0;
1223  } else float_flag = -1;
1224 
1225  if ( float_flag == 0 ) {
1226  cout << part->id << tab << idata << endl;
1227  } else {
1228  cout << part->id << tab << fdata << endl;
1229  }
1230 
1231  return 0;
1232 }
1233 
1241 {
1242  if ( !project ) return 0;
1243 
1244  if ( tag.length() < 1 ) return 0;
1245 
1246  long nsel(0);
1247  Bfield* field = project->field;
1248  Bmicrograph* mg;
1249 
1250  cout << "MGID" << tab << tag << endl;
1251 
1252  for ( field = project->field; field; field = field->next ) if ( field->select ) {
1253  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
1254  mg_show_parameter(mg, tag);
1255  nsel++;
1256  }
1257  }
1258 
1259  return nsel;
1260 }
1261 
1269 {
1270  if ( !project ) return 0;
1271 
1272  if ( tag.length() < 1 ) return 0;
1273 
1274  long nsel(0), npart(0);
1275  Bfield* field = project->field;
1276  Breconstruction* rec = project->rec;
1277  Bmicrograph* mg;
1278  Bparticle* part;
1279 
1280  cout << "PID" << tab << tag << endl;
1281 
1282  if ( field && field->mg && field->mg->part ) {
1283  for ( field = project->field; field; field = field->next ) {
1284  for ( mg = field->mg; mg; mg = mg->next ) {
1285  for ( part = mg->part; part; part = part->next ) {
1286  if ( part->sel ) {
1287  part_show_parameter(part, tag);
1288  nsel++;
1289  }
1290  npart++;
1291  }
1292  }
1293  }
1294  }
1295 
1296  if ( rec && rec->part ) {
1297  for ( npart=nsel=0, rec = project->rec; rec; rec = rec->next ) {
1298  for ( part = rec->part; part; part = part->next ) {
1299  if ( part->sel ) {
1300  part_show_parameter(part, tag);
1301  nsel++;
1302  }
1303  npart++;
1304  }
1305  }
1306  }
1307 
1308  return nsel;
1309 }
1310 
1320  double min, double max)
1321 {
1322  if ( !project ) return 0;
1323  if ( bins < 2 ) bins = 100;
1324  if ( max < min ) swap(min, max);
1325  if ( max == 0 ) max = 1;
1326 
1327  int f;
1328  long i, nh(bins-1), sum, ssum, nsel(0), npart;
1329  double scale(nh*1.0/(max - min));
1330  Bfield* field = project->field;
1331  Breconstruction* rec = project->rec;
1332  Bmicrograph* mg;
1333  Bparticle* part;
1334 
1335  vector<long> hist(bins);
1336  vector<long> hsel(bins);
1337 
1338  if ( field && field->mg && field->mg->part )
1339  cout << "Micrograph figures-of-merit:" << endl;
1340  for ( f=0; f<NFOM; f++ ) if ( project->fom_tag[f] ) {
1341  nsel = npart = 0;
1342  for ( i=0; i<=nh; i++ ) hist[i] = hsel[i] = 0;
1343  for ( field = project->field; field; field = field->next ) {
1344  for ( mg = field->mg; mg; mg = mg->next ) {
1345  for ( part = mg->part; part; part = part->next ) {
1346  i = (long) ((part->fom[f]-min)*scale + 0.5);
1347  if ( i < 0 ) i = 0;
1348  if ( i > nh ) i = nh;
1349  hist[i]++;
1350  npart++;
1351  if ( part->sel ) {
1352  hsel[i]++;
1353  nsel++;
1354  }
1355  }
1356  }
1357  }
1358  if ( nsel ) {
1359  cout << endl << "FOM" << f << " histogram:" << endl;
1360  cout << " Bin\tFOM\tCount\t%%\tSum\tSel\t%%\tSelSum" << endl;
1361  sum = npart;
1362  ssum = nsel;
1363  for ( i=0; i<=nh; i++ ) {
1364  cout << i << tab << i*1.0/scale + min
1365  << tab << hist[i] << tab
1366  << hist[i]*100.0/npart << tab
1367  << sum << tab << hsel[i] << tab
1368  << hsel[i]*100.0/nsel << tab << ssum << endl;
1369  sum -= hist[i];
1370  ssum -= hsel[i];
1371  }
1372  cout << endl;
1373  }
1374  }
1375 
1376  if ( rec && rec->part )
1377  cout << "Reconstruction figures-of-merit:" << endl;
1378  for ( f=0; f<NFOM; f++ ) if ( project->fom_tag[f] ) {
1379  nsel = npart = 0;
1380  for ( i=0; i<=nh; i++ ) hist[i] = hsel[i] = 0;
1381  for ( rec = project->rec; rec; rec = rec->next ) {
1382  for ( part = rec->part; part; part = part->next ) {
1383  i = (long) ((part->fom[f]-min)*scale + 0.5);
1384  if ( i < 0 ) i = 0;
1385  if ( i > nh ) i = nh;
1386  hist[i]++;
1387  npart++;
1388  if ( part->sel ) {
1389  hsel[i]++;
1390  nsel++;
1391  }
1392  }
1393  }
1394  if ( nsel ) {
1395  cout << endl << "FOM" << f << " histogram:" << endl;
1396  cout << " Bin\tFOM\tCount\t%%\tSum\tSel\t%%\tSelSum" << endl;
1397  sum = npart;
1398  ssum = nsel;
1399  for ( i=0; i<=nh; i++ ) {
1400  cout << i << tab << i*1.0/scale + min
1401  << tab << hist[i] << tab
1402  << hist[i]*100.0/npart << tab
1403  << sum << tab << hsel[i] << tab
1404  << hsel[i]*100.0/nsel << tab << ssum << endl;
1405  sum -= hist[i];
1406  ssum -= hsel[i];
1407  }
1408  cout << endl;
1409  }
1410  }
1411 
1412  return nsel;
1413 }
1414 
1422 long project_show_mag_histogram(Bproject* project, long bins, double increment)
1423 {
1424  if ( !project ) return 0;
1425 
1426  int i, nsel(0);
1427  Bfield* field;
1428  Bmicrograph* mg;
1429  Bparticle* part;
1430 
1431  double min = 1 - (bins - 1)*increment/2;
1432 // int* hist = new int[bins];
1433 // for ( i=0; i<bins; i++ ) hist[i] = 0;
1434  vector<long> hist(bins,0);
1435 
1436  for ( field = project->field; field; field = field->next ) {
1437  for ( mg = field->mg; mg; mg = mg->next ) {
1438  for ( part = mg->part; part; part = part->next ) {
1439  if ( part->sel ) {
1440  i = (int) ((part->mag - min)/increment + 0.5);
1441  if ( i < 0 ) i = 0;
1442  if ( i >=bins ) i = bins - 1;
1443  hist[i]++;
1444  nsel++;
1445  }
1446  }
1447  }
1448  }
1449 
1450  cout << "Mag\tCount" << endl;
1451 
1452  for ( i=0; i<bins; i++ )
1453  cout << min + i*increment << tab << hist[i] << endl;
1454 
1455  cout << endl << "Total\t" << nsel << endl << endl;
1456 
1457 // delete[] hist;
1458 
1459  return nsel;
1460 }
1461 
1469 {
1470  if ( !project ) return 0;
1471 
1472  Bfield* field;
1473  Bfield* selected_field = NULL;
1474 
1475  if ( project->field->id == field_id ) {
1476  selected_field = project->field;
1477  } else {
1478  for ( field=project->field; field && !selected_field; field=field->next ) {
1479  if ( field->next->id == field_id ) {
1480  selected_field = field->next;
1481  field->next = NULL;
1482  }
1483  }
1485  }
1486 
1487  field_kill(selected_field->next);
1488  selected_field->next = NULL;
1489  project->field = selected_field;
1490 
1491  return 0;
1492 }
1493 
1501 {
1502  if ( !project ) return 0;
1503 
1504  Bfield* field;
1505  Bmicrograph* mg;
1506  Bmicrograph* selected_mg = NULL;
1507 
1508  for ( field=project->field; field && !selected_mg; field=field->next )
1509  for ( mg = field->mg; mg; mg = mg->next )
1510  if ( mg->id == mg_id ) {
1511  selected_mg = mg;
1512  project_select_field(project, field->id);
1513  }
1514 
1515  field=project->field;
1516  if ( field->mg->id == mg_id ) {
1517  selected_mg = field->mg;
1518  } else {
1519  for ( mg = field->mg; mg; mg = mg->next ) {
1520  if ( mg->next->id == mg_id ) {
1521  selected_mg = mg->next;
1522  mg->next = NULL;
1523  }
1524  }
1525  micrograph_kill(field->mg);
1526  }
1527 
1528  micrograph_kill(selected_mg->next);
1529  selected_mg->next = NULL;
1530  field->mg = selected_mg;
1531 
1532  return 0;
1533 }
1534 
1542 {
1543  if ( !project ) return 0;
1544 
1546  Bfield* field;
1547  Bmicrograph* mg;
1548  Bparticle* part;
1549 
1550  for ( field=project->field; field; field=field->next )
1551  for ( mg = field->mg; mg; mg = mg->next ) {
1552  mg->select = 0;
1553  if ( part_sel < -1 ) {
1554  if ( mg->part ) mg->select = 1;
1555  } else if ( part_sel < 0 ) {
1556  for ( part = mg->part; part; part = part->next )
1557  if ( part->sel ) mg->select = 1;
1558  } else {
1559  for ( part = mg->part; part; part = part->next )
1560  if ( part->sel == part_sel ) mg->select = 1;
1561  }
1562  }
1563 
1564  return np;
1565 }
1566 
1573 {
1574  if ( !field ) return 0;
1575 
1576  long i(0), nmg = field_count_micrographs(field);
1577  double minang;
1578 
1579  vector<Bmicrograph*> mgarr(nmg);
1580 
1581  Bmicrograph* mg, *mg2;
1582  Bmicrograph* mgsel = NULL;
1583 
1584  for ( mg = field->mg; mg; mg = mg->next ) mg->select = 1;
1585 
1586  for ( mg = field->mg; mg; mg = mg->next ) {
1587  minang = 100;
1588  for ( mg2 = field->mg; mg2; mg2 = mg2->next ) if ( mg2->select ) {
1589  if ( minang > mg2->tilt_angle ) {
1590  minang = mg2->tilt_angle;
1591  mgsel = mg2;
1592  }
1593  }
1594  mgarr[i++] = mgsel;
1595  mgsel->select = 0;
1596  }
1597 
1598  field->mg = mg = mgarr[0];
1599 
1600  for ( i=1; i<nmg; ++i, mg = mg->next ) mg->next = mgarr[i];
1601  mg->next = NULL;
1602 
1603  for ( mg = field->mg; mg; mg = mg->next ) mg->select = 1;
1604 
1605  return 0;
1606 }
1607 
1614 {
1615  if ( !project ) return 0;
1616 
1617  Bfield* field;
1618 
1619  for ( field = project->field; field; field = field->next )
1620  field_sort_by_tilt(field);
1621 
1622  return 0;
1623 }
1624 
1631 vector<pair<Bmicrograph*,double>> project_mg_sort(Bproject* project, Bstring tag)
1632 {
1633  long i(0);
1634  Bfield* field = project->field;
1635  Bmicrograph* mg = field->mg;
1636  vector<std::pair<Bmicrograph*,double>> mg_value;
1637  pair<Bmicrograph*,double> mgvp;
1638 
1639  if ( !mg ) {
1640  cerr << "Error: Micrograph parameters not defined!" << endl;
1641  return mg_value;
1642  }
1643 
1644  if ( tag == CTF_DEF_AVG && !mg->ctf ) {
1645  cerr << "Error: CTF parameters not defined!" << endl;
1646  return mg_value;
1647  }
1648 
1649  if ( verbose )
1650  cout << "Ordering micrographs based on tag " << tag << endl;
1651 
1652 
1653  for ( field = project->field; field; field = field->next ) {
1654  for ( mg = field->mg; mg; mg = mg->next ) {
1655  i++;
1656  mgvp.first = mg;
1657  if ( tag == MICROGRAPH_FOM ) mgvp.second = mg->fom;
1658  else if ( tag == MICROGRAPH_INTENSITY )
1659  mgvp.second = mg->intensity;
1660  else if ( tag == CTF_DEF_AVG )
1661  mgvp.second = mg->ctf->defocus_average();
1662  else if ( tag == MICROGRAPH_TILT_ANGLE )
1663  mgvp.second = mg->tilt_angle;
1664  else if ( tag == MICROGRAPH_WATER_RING )
1665  mgvp.second = mg->wri;
1666  else if ( tag == PARTICLE )
1667  mgvp.second = particle_count(mg->part);
1668  else
1669  mgvp.second = i;
1670  mg_value.push_back(mgvp);
1671  }
1672  }
1673 
1674  if ( tag.length() ) {
1675  sort(mg_value.begin(), mg_value.end(),
1676  [=](pair<Bmicrograph*,double> a, pair<Bmicrograph*,double> b) {
1677  return a.second < b.second;
1678  }
1679  );
1680  }
1681 
1682  return mg_value;
1683 }
qsort_functions.h
Header file for utility functions for use in qsort calls.
Bmicrograph::scale
Vector3< double > scale
Definition: mg_processing.h:224
MICROGRAPH_ROT_ANGLE
#define MICROGRAPH_ROT_ANGLE
Definition: mg_tags.h:98
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
MICROGRAPH_FRAMES_FILE
#define MICROGRAPH_FRAMES_FILE
Definition: mg_tags.h:64
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
field_kill
int field_kill(Bfield *field)
Frees a whole field-of-view structure.
Definition: mg_processing.cpp:466
part_show_parameter
int part_show_parameter(Bparticle *part, Bstring &tag)
Definition: mg_select.cpp:1187
field_count_mg_selected
long field_count_mg_selected(Bfield *field)
Counts all the micrographs in the field-of-view structure.
Definition: mg_select.cpp:686
project_count_mg_filament_nodes
long project_count_mg_filament_nodes(Bproject *project)
Counts the number of filament nodes in a project.
Definition: mg_select.cpp:587
Breconstruction::fil
Bfilament * fil
Definition: mg_processing.h:308
field_count
long field_count(Bfield *field)
Counts the number of fields-of-view in a linked list.
Definition: mg_select.cpp:657
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
MICROGRAPH_POWERSPEC_FILE
#define MICROGRAPH_POWERSPEC_FILE
Definition: mg_tags.h:73
PARTICLE_PIXEL_X
#define PARTICLE_PIXEL_X
Definition: mg_tags.h:209
PARTICLE_PIXEL_Z
#define PARTICLE_PIXEL_Z
Definition: mg_tags.h:211
MICROGRAPH_PIXEL_X
#define MICROGRAPH_PIXEL_X
Definition: mg_tags.h:82
PARTICLE_DEFOCUS
#define PARTICLE_DEFOCUS
Definition: mg_tags.h:212
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
Bfilament
Definition: mg_processing.h:129
Bstring
Definition: Bstring.h:29
filament_count
long filament_count(Bfilament *fil)
Counts the number of filaments in a linked list of filaments.
Definition: mg_select.cpp:791
project_count_fields
long project_count_fields(Bproject *project)
Counts all the fields in the project structure.
Definition: mg_select.cpp:335
micrograph_count_particles
long micrograph_count_particles(Bmicrograph *mg)
Counts all the particles in the micrograph structure.
Definition: mg_select.cpp:736
Bparticle
Definition: mg_processing.h:90
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
Bproject::field
Bfield * field
Definition: mg_processing.h:346
PARTICLE_ORIGIN_X
#define PARTICLE_ORIGIN_X
Definition: mg_tags.h:196
micrograph_kill
int micrograph_kill(Bmicrograph *mg)
Frees a whole micrograph parameter structure.
Definition: mg_processing.cpp:493
Euler::theta
double theta()
Definition: Euler.h:57
project_select_with_particles
long project_select_with_particles(Bproject *project, long part_sel)
Selects micrographs with particles.
Definition: mg_select.cpp:1541
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:220
MICROGRAPH_FILE
#define MICROGRAPH_FILE
Definition: mg_tags.h:63
MICROGRAPH_NUMBER
#define MICROGRAPH_NUMBER
Definition: mg_tags.h:76
random_numbers.h
Header file for functions for creating random images.
PARTICLE_VIEW_X
#define PARTICLE_VIEW_X
Definition: mg_tags.h:203
Bparticle::ast
double ast
Definition: mg_processing.h:98
MICROGRAPH_FOM
#define MICROGRAPH_FOM
Definition: mg_tags.h:78
MICROGRAPH_SCALE_X
#define MICROGRAPH_SCALE_X
Definition: mg_tags.h:92
Bfilament::next
Bfilament * next
Definition: mg_processing.h:130
Euler::psi
double psi()
Definition: Euler.h:56
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
project_sort_by_tilt
int project_sort_by_tilt(Bproject *project)
Sorts the micrographs in each field by tilt angle.
Definition: mg_select.cpp:1613
project_mg_sort
vector< pair< Bmicrograph *, double > > project_mg_sort(Bproject *project, Bstring tag)
Sorts the micrographs by a selected parameter.
Definition: mg_select.cpp:1631
mg_select.h
Header file for micrograph processing.
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
MICROGRAPH_FILAMENT_FILE
#define MICROGRAPH_FILAMENT_FILE
Definition: mg_tags.h:71
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
MICROGRAPH_ORIGIN_X
#define MICROGRAPH_ORIGIN_X
Definition: mg_tags.h:89
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
PARTICLE_OMEGA
#define PARTICLE_OMEGA
Definition: mg_tags.h:202
Bfield::id
Bstring id
Definition: mg_processing.h:262
verbose
int verbose
project_select_micrograph
int project_select_micrograph(Bproject *project, Bstring &mg_id)
Selects a micrograph from the project and deletes the rest.
Definition: mg_select.cpp:1500
field_count_particles
long field_count_particles(Bfield *field)
Counts all the particles in the field-of-view structure.
Definition: mg_select.cpp:701
PARTICLE_X
#define PARTICLE_X
Definition: mg_tags.h:190
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_select.cpp:350
project_show_selection_numbers
long project_show_selection_numbers(Bproject *project)
Shows the selection numbers for the particles in a project.
Definition: mg_select.cpp:852
Bfield
Definition: mg_processing.h:260
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:207
PARTICLE
#define PARTICLE
Definition: mg_tags.h:181
PARTICLE_AST_ANG
#define PARTICLE_AST_ANG
Definition: mg_tags.h:214
project_count_rec_groups
long project_count_rec_groups(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:541
Bmicrograph::dose
double dose
Definition: mg_processing.h:216
PARTICLE_ORIGIN_Y
#define PARTICLE_ORIGIN_Y
Definition: mg_tags.h:197
PARTICLE_Z
#define PARTICLE_Z
Definition: mg_tags.h:192
Bmicrograph::fil
Bfilament * fil
Definition: mg_processing.h:243
PARTICLE_HANDA_FOM
#define PARTICLE_HANDA_FOM
Definition: mg_tags.h:230
MICROGRAPH_TRANSFORM_FILE
#define MICROGRAPH_TRANSFORM_FILE
Definition: mg_tags.h:72
project
Bproject * project
Definition: bshow.cpp:33
project_show_mg_parameter
long project_show_mg_parameter(Bproject *project, Bstring &tag)
Shows the micrograph parameter indicated by the tag in a project.
Definition: mg_select.cpp:1240
particle_count_selected
long particle_count_selected(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_select.cpp:773
field_find_micrograph_by_focus
Bmicrograph * field_find_micrograph_by_focus(Bfield *field, int focus_opt, int iselect)
Returns a pointer to the micrograph in a field-of-view structure based on the focus level and iterati...
Definition: mg_select.cpp:142
CTF_DEF_AVG
#define CTF_DEF_AVG
Definition: mg_tags.h:172
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:209
PARTICLE_VIEW_Y
#define PARTICLE_VIEW_Y
Definition: mg_tags.h:204
PARTICLE_PIXEL_Y
#define PARTICLE_PIXEL_Y
Definition: mg_tags.h:210
project_count_rec_particles
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:506
MICROGRAPH_ORIGIN_Y
#define MICROGRAPH_ORIGIN_Y
Definition: mg_tags.h:90
Bmicrograph::level_angle
double level_angle
Definition: mg_processing.h:221
PARTICLE_FOM_CV
#define PARTICLE_FOM_CV
Definition: mg_tags.h:217
field_find_low_tilt_mg_with_markers
Bmicrograph * field_find_low_tilt_mg_with_markers(Bfield *field)
Finds the micrograph closest to a zero degree tilt in a series with markers.
Definition: mg_select.cpp:312
PARTICLE_PIXEL
#define PARTICLE_PIXEL
Definition: mg_tags.h:208
project_show_selected_parameters
long project_show_selected_parameters(Bproject *project, int show)
Shows the selected particle parameters in a project.
Definition: mg_select.cpp:1098
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
PARTICLE_FILE
#define PARTICLE_FILE
Definition: mg_tags.h:182
PARTICLE_PSI
#define PARTICLE_PSI
Definition: mg_tags.h:199
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:219
project_count_rec_selected
long project_count_rec_selected(Bproject *project)
Counts all the selected reconstructions in the project structure.
Definition: mg_select.cpp:399
mg_show_parameter
int mg_show_parameter(Bmicrograph *mg, Bstring &tag)
Definition: mg_select.cpp:1157
Bfilament::node
Bfilnode * node
Definition: mg_processing.h:133
Bproject
Definition: mg_processing.h:336
show
int show(0)
project_count_rec_filament_nodes
long project_count_rec_filament_nodes(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:633
Bparticle::sel
long sel
Definition: mg_processing.h:104
micrograph_count
long micrograph_count(Bmicrograph *mg)
Counts the number of micrographs in a linked list.
Definition: mg_select.cpp:722
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
field_count_micrographs
long field_count_micrographs(Bfield *field)
Counts all the micrographs in the field-of-view structure.
Definition: mg_select.cpp:671
PARTICLE_PHI
#define PARTICLE_PHI
Definition: mg_tags.h:201
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Euler::phi
double phi()
Definition: Euler.h:58
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
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_select.cpp:755
PARTICLE_HANDB_FOM
#define PARTICLE_HANDB_FOM
Definition: mg_tags.h:231
mg_tags.h
All STAR and XML file format tags for micrographs and reconstructions.
Bfilnode::next
Bfilnode * next
Definition: mg_processing.h:117
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
field_sort_by_tilt
int field_sort_by_tilt(Bfield *field)
Sorts the micrographs in a field by tilt angle.
Definition: mg_select.cpp:1572
PARTICLE_THETA
#define PARTICLE_THETA
Definition: mg_tags.h:200
project_show_mag_histogram
long project_show_mag_histogram(Bproject *project, long bins, double increment)
Shows the histogram for magnification values for selected particles.
Definition: mg_select.cpp:1422
PARTICLE_MAGNIF
#define PARTICLE_MAGNIF
Definition: mg_tags.h:207
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
Breconstruction::select
long select
Definition: mg_processing.h:286
PARTICLE_VIEW_ANGLE
#define PARTICLE_VIEW_ANGLE
Definition: mg_tags.h:206
MICROGRAPH_SCALE_Y
#define MICROGRAPH_SCALE_Y
Definition: mg_tags.h:93
Bparticle::def
double def
Definition: mg_processing.h:96
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:348
Bfield::select
long select
Definition: mg_processing.h:265
project_select_field
int project_select_field(Bproject *project, Bstring &field_id)
Selects a field from the project and deletes the rest.
Definition: mg_select.cpp:1468
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:415
Bmicrograph::fom
double fom
Definition: mg_processing.h:239
MICROGRAPH_LEVEL_ANGLE
#define MICROGRAPH_LEVEL_ANGLE
Definition: mg_tags.h:97
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
project_count_reconstructions
long project_count_reconstructions(Bproject *project)
Counts all the reconstructions in the project structure.
Definition: mg_select.cpp:384
project_maximum_selection
long project_maximum_selection(Bproject *project)
Finds the maximum selection number for a project.
Definition: mg_select.cpp:825
Bparticle::dev
double dev
Definition: mg_processing.h:97
PARTICLE_VIEW_Z
#define PARTICLE_VIEW_Z
Definition: mg_tags.h:205
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:245
project_count_mg_groups
long project_count_mg_groups(Bproject *project)
Counts the number of groups of particles in the project structure.
Definition: mg_select.cpp:483
project_count_mg_filaments
long project_count_mg_filaments(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:564
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
field_find_id
Bfield * field_find_id(Bfield *field, Bstring &field_id)
Finds a field-of-view based on its identifier.
Definition: mg_select.cpp:33
QsortSmallToLargeFloat
int QsortSmallToLargeFloat(const void *x, const void *y)
Utility function for sorting floating point values in qsort.
Definition: qsort_functions.cpp:17
Bparticle::group
int group
Definition: mg_processing.h:94
mg_processing.h
Header file for micrograph processing.
Bmicrograph::intensity
double intensity
Definition: mg_processing.h:217
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
PARTICLE_FOM
#define PARTICLE_FOM
Definition: mg_tags.h:216
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
Bmicrograph::rot_angle
double rot_angle
Definition: mg_processing.h:222
PARTICLE_DEF_DEV
#define PARTICLE_DEF_DEV
Definition: mg_tags.h:213
MICROGRAPH_TILT_ANGLE
#define MICROGRAPH_TILT_ANGLE
Definition: mg_tags.h:96
linked_list.h
Header file for generalized linked list functions.
math_util.h
Header file for general utilities.
Bmicrograph::select
long select
Definition: mg_processing.h:204
Bmicrograph::fps
Bstring fps
Definition: mg_processing.h:211
project_show_fom_histogram
long project_show_fom_histogram(Bproject *project, long bins, double min, double max)
Shows a histogram of the FOM values.
Definition: mg_select.cpp:1319
project_show_selected
long project_show_selected(Bproject *project)
Shows the selected particles in a project.
Definition: mg_select.cpp:907
field_find_micrograph_by_rotang
Bmicrograph * field_find_micrograph_by_rotang(Bfield *field, double rotang)
Returns a pointer to the micrograph in a field-of-view structure with the specified in-plane rotation...
Definition: mg_select.cpp:199
Bmicrograph::wri
double wri
Definition: mg_processing.h:218
project_count_rec_filaments
long project_count_rec_filaments(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:612
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
filament_node_count
long filament_node_count(Bfilament *fil)
Counts the number of filament nodes in a linked list of filaments.
Definition: mg_select.cpp:809
PARTICLE_SELECT
#define PARTICLE_SELECT
Definition: mg_tags.h:215
Bfilnode
Definition: mg_processing.h:116
MICROGRAPH_INTENSITY
#define MICROGRAPH_INTENSITY
Definition: mg_tags.h:87
field_find_micrograph
Bmicrograph * field_find_micrograph(Bfield *field, int mg_select, int mg_index, double mg_ang)
Returns a pointer to a specific micrograph in a field-of-view structure based on a unique characteris...
Definition: mg_select.cpp:64
Bparticle::mag
double mag
Definition: mg_processing.h:95
PARTICLE_Y
#define PARTICLE_Y
Definition: mg_tags.h:191
MICROGRAPH_TILT_AXIS
#define MICROGRAPH_TILT_AXIS
Definition: mg_tags.h:95
MICROGRAPH_PIXEL_Y
#define MICROGRAPH_PIXEL_Y
Definition: mg_tags.h:83
field_find_micrograph_by_tiltang
Bmicrograph * field_find_micrograph_by_tiltang(Bfield *field, double tiltang)
Returns a pointer to the micrograph in a field-of-view structure with the specified tilt angle.
Definition: mg_select.cpp:243
field_find_zero_tilt_mg
Bmicrograph * field_find_zero_tilt_mg(Bfield *field)
Finds the micrograph closest to a zero degree tilt in a series.
Definition: mg_select.cpp:281
View::angle
double angle()
Definition: View.h:98
Euler
Definition: Euler.h:28
project_show_part_parameter
long project_show_part_parameter(Bproject *project, Bstring &tag)
Shows the particle parameter indicated by the tag in a project.
Definition: mg_select.cpp:1268
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
MICROGRAPH_DOSE
#define MICROGRAPH_DOSE
Definition: mg_tags.h:86
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
MICROGRAPH_SELECT
#define MICROGRAPH_SELECT
Definition: mg_tags.h:77
PARTICLE_ORIGIN_Z
#define PARTICLE_ORIGIN_Z
Definition: mg_tags.h:198
MICROGRAPH_WATER_RING
#define MICROGRAPH_WATER_RING
Definition: mg_tags.h:88
Bmicrograph::fft
Bstring fft
Definition: mg_processing.h:210
field_find_micrograph_n
Bmicrograph * field_find_micrograph_n(Bfield *field, int n)
Returns a pointer to the nth micrograph in a field-of-view structure.
Definition: mg_select.cpp:104
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
Bproject::fom_tag
FOMType fom_tag[NFOM]
Definition: mg_processing.h:345