| Bsoft 2.0.5 Bernard's software package

mg_particle_select.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_tomography.h"
11 #include "mg_particle_select.h"
12 #include "mg_tags.h"
13 #include "symmetry.h"
14 #include "matrix_linear.h"
15 #include "Matrix.h"
16 #include "random_numbers.h"
17 #include "linked_list.h"
18 #include "utilities.h"
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
23 int_float* project_fom_order(Bproject* project, long& npart, int fom_index, int defocus_fit)
24 {
25 if ( fom_index < 0 ) fom_index = 0;
26 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
27
28 long nn(0);
29
30 Bfield* field;
31 Bmicrograph* mg;
32 Breconstruction* rec;
33 Bparticle* part;
34
35 if ( project->select < 1 ) npart = project_count_mg_particles(project);
36 else npart = project_count_rec_particles(project);
37
38 if ( npart < 1 ) {
39 cerr << "Error: No particles found!" << endl;
40 return NULL;
41 }
42
43 double slope, intercept, fom_adjust(0);
44
45 if ( verbose & VERB_FULL )
46 cout << "Ordering " << npart << " particles based on FOM:" << endl;
47
48 int_float* rank = new int_float[npart];
49
50 if ( project->select < 1 ) {
51 if ( defocus_fit ) part_fom_defocus_fit(project, fom_index, intercept, slope);
52 for ( field = project->field; field; field = field->next ) {
53 for ( mg = field->mg; mg; mg = mg->next ) {
54 if ( defocus_fit && mg->ctf ) fom_adjust = slope*(mg->ctf->defocus_average() - 1e4);
55 for ( part = mg->part; part; part = part->next ) {
56 rank[nn].i = nn;
57 if ( part->sel > 0 )
58 // rank[nn].f = fom_adjust + part->fom[fom_index];
59 rank[nn].f = part->fom[fom_index] - fom_adjust;
60 else
61 rank[nn].f = 0;
62 nn++;
63 }
64 }
65 }
66 } else {
67 for ( rec = project->rec; rec; rec = rec->next ) {
68 for ( part = rec->part; part; part = part->next ) {
69 rank[nn].i = nn;
70 if ( part->sel > 0 )
71 rank[nn].f = part->fom[fom_index];
72 else
73 rank[nn].f = 0;
74 nn++;
75 }
76 }
77 }
78
79 if ( verbose & VERB_DEBUG )
80 cout << "DEBUG project_fom_order: Ranking the FOMs:" << endl;
81
82 // Rank according to the FOMs
83 qsort((void *) rank, npart, sizeof(int_float),
84 (int (*)(const void *, const void *)) QsortLargeToSmallIntFloat);
85
86 return rank;
87 }
88
89 int_float* part_fom_order(Bparticle* partlist, long& npart, int fom_index)
90 {
91 if ( fom_index < 0 ) fom_index = 0;
92 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
93
94 long nn(0);
95
96 Bparticle* part;
97
98 npart = particle_count(partlist);
99
100 if ( npart < 1 ) {
101 cerr << "Error: No particles found!" << endl;
102 return NULL;
103 }
104
105 if ( verbose & VERB_FULL )
106 cout << "Ordering " << npart << " particles based on FOM:" << endl;
107
108 int_float* rank = new int_float[npart];
109
110 for ( part = partlist; part; part = part->next ) if ( part->sel ) {
111 rank[nn].i = nn;
112 rank[nn].f = part->fom[fom_index];
113 nn++;
114 }
115
116 if ( verbose & VERB_DEBUG )
117 cout << "DEBUG part_fom_order: Ranking the FOMs:" << endl;
118
119 // Rank according to the FOMs
120 qsort((void *) rank, npart, sizeof(int_float),
121 (int (*)(const void *, const void *)) QsortLargeToSmallIntFloat);
122
123 return rank;
124 }
125
131 long part_reset_selection(Bproject* project)
132 {
133 long npart(0);
134 Bfield* field;
135 Bmicrograph* mg;
136 Breconstruction* rec;
137 Bparticle* part;
138
139 if ( project->select ) {
140 if ( verbose & VERB_PROCESS )
141 cout << "Resetting reconstruction particle selections" << endl << endl;
142 for ( rec = project->rec; rec; rec = rec->next ) {
143 rec->select = 1;
144 for ( part = rec->part; part; part = part->next, npart++ )
145 part->sel = 1;
146 }
147 } else {
148 if ( verbose & VERB_PROCESS )
149 cout << "Resetting micrograph particle selections" << endl << endl;
150 for ( field = project->field; field; field = field->next )
151 for ( mg = field->mg; mg; mg = mg->next ) {
152 mg->select = 1;
153 for ( part = mg->part; part; part = part->next, npart++ )
154 part->sel = 1;
155 }
156 }
157
158 return npart;
159 }
160
166 long part_unset_selection(Bproject* project)
167 {
168 long npart(0);
169 Bfield* field;
170 Bmicrograph* mg;
171 Breconstruction* rec;
172 Bparticle* part;
173
174 if ( project->select ) {
175 if ( verbose & VERB_PROCESS )
176 cout << "Unsetting reconstruction particle selections" << endl << endl;
177 for ( rec = project->rec; rec; rec = rec->next ) {
178 // rec->select = 1;
179 for ( part = rec->part; part; part = part->next, npart++ )
180 part->sel = 0;
181 }
182 } else {
183 if ( verbose & VERB_PROCESS )
184 cout << "Unsetting micrograph particle selections" << endl << endl;
185 for ( field = project->field; field; field = field->next )
186 for ( mg = field->mg; mg; mg = mg->next ) {
187 // mg->select = 1;
188 for ( part = mg->part; part; part = part->next, npart++ )
189 part->sel = 0;
190 }
191 }
192
193 return npart;
194 }
195
196
202 long part_invert_selection(Bproject* project)
203 {
204 long npart(0);
205 Bfield* field;
206 Bmicrograph* mg;
207 Breconstruction* rec;
208 Bparticle* part;
209
210 if ( project->select ) {
211 if ( verbose & VERB_PROCESS )
212 cout << "Inverts reconstruction particle selections" << endl << endl;
213 for ( rec = project->rec; rec; rec = rec->next ) {
214 // rec->select = 1;
215 for ( part = rec->part; part; part = part->next, npart++ ) {
216 if ( part->sel ) part->sel = 0;
217 else part->sel = 1;
218 }
219 }
220 } else {
221 if ( verbose & VERB_PROCESS )
222 cout << "Inverts micrograph particle selections" << endl << endl;
223 for ( field = project->field; field; field = field->next )
224 for ( mg = field->mg; mg; mg = mg->next ) {
225 // mg->select = 1;
226 for ( part = mg->part; part; part = part->next, npart++ ) {
227 if ( part->sel ) part->sel = 0;
228 else part->sel = 1;
229 }
230 }
231 }
232
233 return npart;
234 }
235
236
245 long part_select_micrograph(Bproject* project, Bstring& mgselect)
246 {
247 long i, nsel(0);
248
249 Bfield* field;
250 Bmicrograph* mg;
251 Bparticle* part;
252
253 long nmg = project_count_micrographs(project);
254 int* numsel = new int[nmg+1];
255
256 select_numbers(mgselect, nmg+1, numsel);
257
258 for ( i=1; i<=nmg; ++i ) if ( numsel[i] ) nsel++;
259
260 if ( verbose )
261 cout << "Micrographs selected: " << nsel << " (" << nsel*100.0/nmg << " %)" << endl;
262
263 for ( i=1, nsel=0, field = project->field; field; field = field->next ) {
264 for ( mg = field->mg; mg; mg = mg->next, ++i ) {
265 if ( numsel[i] ) {
266 mg->select = 1;
267 for ( part = mg->part; part; part = part->next )
268 if ( part->sel ) nsel++;
269 } else mg->select = 0;
270 }
271 }
272
273 delete[] numsel;
274
275 return nsel;
276 }
277
284 long part_consolidate_selection(Bproject* project, int number)
285 {
286 long nsel(0);
287 Bfield* field;
288 Bmicrograph* mg;
289 Breconstruction* rec;
290 Bparticle* part;
291
292 if ( project->select ) {
293 for ( rec = project->rec; rec; rec = rec->next )
294 for ( part = rec->part; part; part = part->next )
295 if ( part->sel > 0 ) {
296 part->sel = number;
297 nsel++;
298 }
299 } else {
300 for ( field = project->field; field; field = field->next )
301 for ( mg = field->mg; mg; mg = mg->next )
302 for ( part = mg->part; part; part = part->next )
303 if ( part->sel > 0 ) {
304 part->sel = number;
305 nsel++;
306 }
307 }
308
309 return nsel;
310 }
311
318 long part_set_selection(Bproject* project, int number)
319 {
320 long nsel(0);
321 Bfield* field;
322 Bmicrograph* mg;
323 Breconstruction* rec;
324 Bparticle* part;
325
326 if ( project->select ) {
327 for ( rec = project->rec; rec; rec = rec->next )
328 for ( part = rec->part; part; part = part->next )
329 if ( part->sel == number ) {
330 part->sel = 1;
331 nsel++;
332 } else {
333 part->sel = 0;
334 }
335 } else {
336 for ( field = project->field; field; field = field->next )
337 for ( mg = field->mg; mg; mg = mg->next )
338 for ( part = mg->part; part; part = part->next )
339 if ( part->sel == number ) {
340 part->sel = 1;
341 nsel++;
342 } else {
343 part->sel = 0;
344 }
345 }
346
347 return nsel;
348 }
349
357 long part_set_FOM(Bproject* project, int fom_index, double fom)
358 {
359 if ( fom_index < 0 ) fom_index = 0;
360 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
361
362 long npart(0);
363 Bfield* field;
364 Bmicrograph* mg;
365 Breconstruction* rec;
366 Bparticle* part;
367
368 if ( project->select )
369 for ( rec = project->rec; rec; rec = rec->next )
370 for ( part = rec->part; part; part = part->next, npart++ )
371 part->fom[fom_index] = fom;
372 else
373 for ( field = project->field; field; field = field->next )
374 for ( mg = field->mg; mg; mg = mg->next )
375 for ( part = mg->part; part; part = part->next, npart++ )
376 part->fom[fom_index] = fom;
377
378 return npart;
379 }
380
387 long part_deselect_from_list(Bproject* project, Bstring list)
388 {
389 long nsel = project_count_mg_part_selected(project);
390
391 if ( list.length() < 1 ) return nsel;
392
393 long smax = project_maximum_selection(project);
394
395 Bfield* field;
396 Bmicrograph* mg;
397 Breconstruction* rec;
398 Bparticle* part;
399
400 long n(smax+1);
401 int* numsel = new int[n];
402 select_numbers(list, n, numsel);
403
404 nsel = 0;
405
406 if ( project->select ) {
407 for ( rec = project->rec; rec; rec = rec->next )
408 for ( part = rec->part; part; part = part->next ) {
409 if ( part->sel > 0 ) {
410 if ( numsel[part->sel] ) part->sel = 0;
411 else nsel++;
412 }
413 }
414 } else {
415 for ( field = project->field; field; field = field->next )
416 for ( mg = field->mg; mg; mg = mg->next )
417 for ( part = mg->part; part; part = part->next ) {
418 if ( part->sel > 0 ) {
419 if ( numsel[part->sel-1] ) part->sel = 0;
420 else nsel++;
421 }
422 }
423 }
424
425 delete[] numsel;
426
427 if ( verbose & VERB_PROCESS )
428 cout << "Particles selected: " << nsel << endl << endl;
429
430 return nsel;
431 }
432
433
442 long part_deselect(Bproject* project, int fom_index, double fommin, double fommax)
443 {
444 if ( fom_index < 0 ) fom_index = 0;
445 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
446
447 long nsel(0);
448 Bfield* field;
449 Bmicrograph* mg;
450 Breconstruction* rec;
451 Bparticle* part;
452
453 if ( project->select ) {
454 for ( rec = project->rec; rec; rec = rec->next )
455 for ( part = rec->part; part; part = part->next ) {
456 if ( part->fom[fom_index] < fommin || part->fom[fom_index] > fommax )
457 part->sel = 0;
458 if ( part->sel ) nsel++;
459 }
460 } else {
461 for ( field = project->field; field; field = field->next )
462 for ( mg = field->mg; mg; mg = mg->next )
463 for ( part = mg->part; part; part = part->next ) {
464 if ( part->fom[fom_index] < fommin || part->fom[fom_index] > fommax )
465 part->sel = 0;
466 if ( part->sel ) nsel++;
467 }
468 }
469
470 if ( verbose & VERB_PROCESS ) {
471 cout << "FOM range: " << fommin << " - " << fommax << endl;
472 cout << "Particles selected: " << nsel << endl << endl;
473 }
474
475 return nsel;
476 }
477
478 int QsortLargeToSmallParticle(const void *x, const void *y)
479 {
480 Bparticle** part1 = (Bparticle**) x;
481 Bparticle** part2 = (Bparticle**) y;
482 if( (*part1)->fom[0] > (*part2)->fom[0] ) return -1;
483 else return 1;
484 }
485
494 long part_deselect_redundant(Bparticle* partlist, double excl_dist, int part_select, int fom_index)
495 {
496 if ( fom_index < 0 ) fom_index = 0;
497 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
498
499 long i, j, npart(0), nsel(0);
500
501 Bparticle** parr = particle_array(partlist, part_select, npart);
502
503 // Rank according to the FOMs
504 qsort((void *) parr, npart, sizeof(Bparticle*),
505 (int (*)(const void *, const void *)) QsortLargeToSmallParticle);
506
507 for ( i=0; i<npart; i++ ) {
508 for ( j=i+1; j<npart; j++ ) if ( parr[j]->sel ) {
509 if ( parr[i]->loc.distance(parr[j]->loc) < excl_dist )
510 parr[j]->sel = 0;
511 }
512 if ( parr[i]->sel ) nsel++;
513 }
514
515 return nsel;
516 }
517
526 long part_deselect_redundant(Bproject* project, double excl_dist, int part_select, int fom_index)
527 {
528 if ( fom_index < 0 ) fom_index = 0;
529 if ( fom_index >= NFOM ) fom_index = NFOM - 1;
530
531 long nsel(0);
532 Bfield* field;
533 Bmicrograph* mg;
534 Breconstruction* rec;
535
536 if ( project->select ) {
537 for ( rec = project->rec; rec; rec = rec->next )
538 nsel += part_deselect_redundant(rec->part, excl_dist, part_select, fom_index);
539 } else {
540 for ( field = project->field; field; field = field->next )
541 for ( mg = field->mg; mg; mg = mg->next )
542 nsel += part_deselect_redundant(mg->part, excl_dist, part_select, fom_index);
543 }
544
545 if ( verbose & VERB_PROCESS ) {
546 cout << "Exclusion distance: " << excl_dist << endl;
547 cout << "Particles selected: " << nsel << endl << endl;
548 }
549
550 return nsel;
551 }
552
564 long part_set_multi_maps(Bproject* project, int part_select, int nmaps)
565 {
566 long nsel(0);
567 int i = 1;
568 Bfield* field;
569 Bmicrograph* mg;
570 Breconstruction* rec;
571 Bparticle* part;
572
573 if ( nmaps < 1 ) nmaps = 1;
574
575 if ( project->select ) {
576 for ( rec = project->rec; rec; rec = rec->next )
577 for ( part = rec->part; part; part = part->next ) {
578 if ( part_select < 0 ) {
579 if ( part->sel > 0 ) part->sel = i;
580 } else {
581 if ( part->sel == part_select ) part->sel = i;
582 else part->sel = 0;
583 }
584 if ( part->sel ) {
585 nsel++;
586 i++;
587 if ( i > nmaps ) i = 1;
588 }
589 }
590 } else {
591 for ( field = project->field; field; field = field->next )
592 for ( mg = field->mg; mg; mg = mg->next )
593 for ( part = mg->part; part; part = part->next ) {
594 if ( part_select < 0 ) {
595 if ( part->sel > 0 ) part->sel = i;
596 } else {
597 if ( part->sel == part_select ) part->sel = i;
598 else part->sel = 0;
599 }
600 if ( part->sel ) {
601 nsel++;
602 i++;
603 if ( i > nmaps ) i = 1;
604 }
605 }
606 }
607
608 if ( verbose & VERB_PROCESS )
609 cout << "Particles selected: " << nsel << endl << endl;
610
611 return nsel;
612 }
613
619 long part_set_filament_maps(Bproject* project)
620 {
621 long nsel(0);
622 int prev_group(0);
623 Bfield* field;
624 Bmicrograph* mg;
625 Breconstruction* rec;
626 Bparticle* part;
627
628 if ( project->select ) {
629 for ( rec = project->rec; rec; rec = rec->next ) {
630 for ( part = rec->part; part; part = part->next ) {
631 if ( part->sel > 0 ) {
632 if ( part->group != prev_group ) {
633 nsel++;
634 prev_group = part->group;
635 }
636 part->sel = nsel;
637 }
638 }
639 prev_group = 0;
640 }
641 } else {
642 for ( field = project->field; field; field = field->next ) {
643 for ( mg = field->mg; mg; mg = mg->next ) {
644 for ( part = mg->part; part; part = part->next ) {
645 if ( part->sel > 0 ) {
646 if ( part->group != prev_group ) {
647 nsel++;
648 prev_group = part->group;
649 }
650 part->sel = nsel;
651 }
652 }
653 prev_group = 0;
654 }
655 }
656 }
657
658 if ( verbose & VERB_PROCESS )
659 cout << "Maps selected: " << nsel << endl << endl;
660
661 return nsel;
662 }
663
664 int part_reselect(Bparticle* part, Bstring& tag, double reselect_min, double reselect_max)
665 {
666 int float_flag(1), idata(0);
667 double fdata;
668 Euler euler;
669
670 fdata = reselect_min - 1;
671 euler = Euler(part->view);
672 if ( tag == PARTICLE_ID ) {
673 idata = part->id;
674 float_flag = 0;
675 }
676 if ( tag == PARTICLE_X ) fdata = part->loc[0];
677 if ( tag == PARTICLE_Y ) fdata = part->loc[1];
678 if ( tag == PARTICLE_Z ) fdata = part->loc[2];
679 if ( tag == PARTICLE_ORIGIN_X ) fdata = part->ori[0];
680 if ( tag == PARTICLE_ORIGIN_Y ) fdata = part->ori[1];
681 if ( tag == PARTICLE_ORIGIN_Z ) fdata = part->ori[2];
682 if ( tag == PARTICLE_DEFOCUS ) fdata = part->def;
683 if ( tag == PARTICLE_DEF_DEV ) fdata = part->dev;
684 if ( tag == PARTICLE_AST_ANG ) fdata = part->ast;
685 if ( tag == PARTICLE_MAGNIF ) fdata = part->mag;
686 if ( tag == PARTICLE_VIEW_X ) fdata = part->view[0];
687 if ( tag == PARTICLE_VIEW_Y ) fdata = part->view[1];
688 if ( tag == PARTICLE_VIEW_Z ) fdata = part->view[2];
689 if ( tag == PARTICLE_VIEW_ANGLE ) fdata = part->view.angle();
690 if ( tag == PARTICLE_PSI ) fdata = euler.psi()*180/M_PI;
691 if ( tag == PARTICLE_THETA ) fdata = euler.theta()*180/M_PI;
692 if ( tag == PARTICLE_PHI ) fdata = euler.phi()*180/M_PI;
693 if ( tag == PARTICLE_OMEGA ) fdata = -euler.psi()*180/M_PI;
694 if ( tag == PARTICLE_FOM ) fdata = part->fom[0];
695 if ( tag == PARTICLE_FOM_CV ) fdata = part->fom[1];
696 if ( tag == PARTICLE_HANDA_FOM ) fdata = part->fom[1];
697 if ( tag == PARTICLE_HANDB_FOM ) fdata = part->fom[2];
698 if ( tag == PARTICLE_SELECT ) {
699 idata = part->sel;
700 float_flag = 0;
701 }
702
703 if ( !float_flag ) {
704 if ( idata < reselect_min || idata > reselect_max ) part->sel = 0;
705 } else {
706 if ( fdata < reselect_min || fdata > reselect_max ) part->sel = 0;
707 }
708
709 return 0;
710 }
711
723 long part_reselect(Bproject* project, Bstring& tag, double reselect_min, double reselect_max)
724 {
725 long npart(0), nmg(0), nrec(0), npsel(0), nmsel(0), nrsel(0);
726 double fdata, mpct(0), rpct(0), ppct(0);
727 Bfield* field;
728 Bmicrograph* mg;
729 Breconstruction* rec;
730 Bparticle* part;
731
732 if ( tag[0] == '_' ) tag = tag.erase(0);
733
734 if ( verbose ) {
735 cout << "Reselecting on tag: " << tag << endl;
736 cout << "Range: " << reselect_min << " - " << reselect_max << endl;
737 }
738
739 if ( project->select < 1 ) {
740 for ( field = project->field; field; field = field->next ) {
741 for ( mg = field->mg; mg; mg = mg->next ) {
742 fdata = reselect_min - 1;
743 if ( mg->ctf && tag.contains(CTF) ) {
744 if ( tag == CTF_DEF_AVG ) fdata = mg->ctf->defocus_average();
745 if ( tag == CTF_DEF_DEV ) fdata = mg->ctf->defocus_deviation();
746 if ( tag == CTF_AST_ANG ) fdata = mg->ctf->astigmatism_angle();
747 if ( fdata < reselect_min || fdata > reselect_max ) mg->select = 0;
748 }
749 if ( tag.contains(PARTICLE) )
750 for ( part = mg->part; part; part = part->next )
751 part_reselect(part, tag, reselect_min, reselect_max);
752 if ( mg->select ) nmsel++;
753 else for ( part = mg->part; part; part = part->next ) part->sel = 0;
754 for ( part = mg->part; part; part = part->next, npart++ ) if ( part->sel ) npsel++;
755 nmg++;
756 }
757 }
758 } else {
759 for ( rec = project->rec; rec; rec = rec->next ) {
760 fdata = reselect_min - 1;
761 if ( rec->ctf && tag.contains(CTF) ) {
762 if ( tag == CTF_DEF_AVG ) fdata = rec->ctf->defocus_average();
763 if ( tag == CTF_DEF_DEV ) fdata = rec->ctf->defocus_deviation();
764 if ( tag == CTF_AST_ANG ) fdata = rec->ctf->astigmatism_angle();
765 if ( fdata < reselect_min || fdata > reselect_max ) rec->select = 0;
766 }
767 if ( tag.contains(PARTICLE) )
768 for ( part = rec->part; part; part = part->next )
769 part_reselect(part, tag, reselect_min, reselect_max);
770 if ( rec->select ) nrsel++;
771 else for ( part = rec->part; part; part = part->next ) part->sel = 0;
772 for ( part = rec->part; part; part = part->next, npart++ ) if ( part->sel ) npsel++;
773 nrec++;
774 }
775 }
776
777 if ( npart ) ppct = npsel*100.0/npart;
778 if ( nmg ) mpct = nmsel*100.0/nmg;
779 if ( nrec ) rpct = nrsel*100.0/nrec;
780
781 if ( verbose & VERB_PROCESS ) {
782 if ( project->select < 1 )
783 cout << "Micrographs reselected: " << nmsel << " (" << mpct << " %)" << endl;
784 else
785 cout << "Reconstructions reselected: " << nrsel << " (" << rpct << " %)" << endl;
786 cout << "Particles reselected: " << npsel << " (" << ppct << " %)" << endl << endl;
787 }
788
789 return npsel;
790 }
791
802 double part_series_comparison(Bproject* project, Bsymmetry* sym, double angle_cutoff)
803 {
804 int i, max(0), nsel(0);
805 double angle, min_angle, avg_angle(0);
806 View view_pred;
807 View* symview;
808 Vector3<double> axis(1,0,0);
809 Quaternion qt, q;
810
811 Bfield* field;
812 Bmicrograph* mg, *mg0;
813 Bparticle* part, *part0;
814
815 int hist[180];
816 for ( i=0; i<180; i++ ) hist[i] = 0;
817
818 int nsymviews = 1;
819 for ( i=0; i<sym->n; i++ ) nsymviews *= sym->op[i].order;
820
821 if ( verbose & VERB_LABEL )
822 cout << "Comparison of particles in micrograph series with " << angle_cutoff*180.0/M_PI << " degrees cutoff" << endl;
823
824 for ( field = project->field; field; field = field->next ) {
825 mg0 = field->mg;
826 axis[0] = cos(mg0->tilt_axis);
827 axis[1] = sin(mg0->tilt_axis);
828 for ( mg=field->mg->next; mg; mg=mg->next ) {
829 // qt = quaternion_from_angle_and_axis3(mg0->tilt_angle - mg->tilt_angle, axis);
830 qt = Quaternion(axis, mg0->tilt_angle - mg->tilt_angle);
831 for ( part=mg->part, part0=mg0->part; part; part=part->next, part0=part0->next ) {
832 q = part->view.quaternion();
833 q = qt * q;
834 view_pred = View(q);
835 symview = symmetry_get_all_views(sym, part0->view);
836 min_angle = M_PI;
837 for ( i=0; i<nsymviews; i++ ) {
838 angle = view_pred.angle(symview[i]);
839 if ( min_angle > angle ) min_angle = angle;
840 }
841 if ( min_angle > angle_cutoff ) {
842 part0->sel = 0;
843 } else {
844 avg_angle += min_angle;
845 nsel++;
846 }
847 i = (int) (min_angle*180.0/M_PI);
848 hist[i]++;
849 if ( max < i ) max = i;
850 delete[] symview;
851 }
852 }
853 for ( mg=field->mg->next; mg; mg=mg->next )
854 for ( part=mg->part, part0=mg0->part; part; part=part->next, part0=part0->next )
855 part->sel = part0->sel; // Set all micrographs to have the same selection
856 }
857 if ( nsel ) avg_angle /= nsel;
858
859 if ( verbose & VERB_PROCESS ) {
860 cout << "Angular deviation histogram:\nAngle\tCount" << endl;
861 for ( i=0; i<max; i++ ) cout << i << tab << hist[i] << endl;
862 cout << endl;
863 }
864
865 if ( verbose & VERB_LABEL ) {
866 cout << "Average angle deviation: " << avg_angle*180/M_PI << endl;
867 cout << "Particle sets selected: " << nsel << endl << endl;
868 }
869
870 return avg_angle;
871 }
872
873 long part_convert_selection(Bproject* project, int* sel)
874 {
875 long n(0), nsel(0);
876 Bfield* field;
877 Bmicrograph* mg;
878 Breconstruction* rec;
879 Bparticle* part;
880
881 if ( project->select < 1 ) {
882 for ( field = project->field; field; field = field->next ) {
883 for ( mg = field->mg; mg; mg = mg->next ) {
884 for ( part = mg->part; part; part = part->next ) {
885 part->sel = sel[n];
886 if ( part->sel > 0 ) nsel++;
887 n++;
888 }
889 }
890 }
891 } else {
892 for ( rec = project->rec; rec; rec = rec->next ) {
893 for ( part = rec->part; part; part = part->next ) {
894 part->sel = sel[n];
895 if ( part->sel > 0 ) nsel++;
896 n++;
897 }
898 }
899 }
900
901 return nsel;
902 }
903
919 long part_select_FOM_groups(Bproject* project, int ngroups, int fom_index, int defocus_fit)
920 {
921 long i, n(0), npart(0), nsel(0);
922
923 if ( verbose & VERB_LABEL )
924 cout << "Selecting " << ngroups << " particle groups based on FOM ranking:" << endl;
925
926 int_float* rank = project_fom_order(project, npart, fom_index, defocus_fit);
927
928 if ( npart < 1 ) {
929 cerr << "Error: No particles found!" << endl;
930 return -1;
931 }
932
933 if ( project->select < 1 ) nsel = project_count_mg_part_selected(project);
934 else nsel = project_count_rec_part_selected(project);
935
936 int* sel = new int[npart];
937
938 if ( verbose & VERB_DEBUG )
939 cout << "DEBUG part_select_FOM_groups: Writing the selection array:" << endl;
940 // Write the ranking groups into the selection array
941 for ( i=0; i<nsel; i++ ) {
942 n = ngroups - (i*ngroups)/nsel;
943 sel[rank[i].i] = n;
944 }
945 for ( ; i<npart; i++ ) sel[rank[i].i] = 0;
946
947 // Write the selection array back into the parameter hierarchy
948 nsel = part_convert_selection(project, sel);
949
950 delete[] sel;
951 delete[] rank;
952
953 return nsel;
954 }
955
969 long part_select_percentage(Bproject* project, double percentage, int fom_index, int defocus_fit)
970 {
971 if ( percentage < 0 ) percentage = 0;
972 if ( percentage > 100 ) percentage = 100;
973
974 long npart(0), nsel(0), n;
975
976 if ( verbose & VERB_LABEL )
977 cout << "Selecting " << percentage << "% particles based on FOM[" << fom_index << "] ranking:" << endl;
978
979 int_float* rank = project_fom_order(project, npart, fom_index, defocus_fit);
980
981 if ( npart < 1 ) {
982 cerr << "Error: No particles found!" << endl;
983 return -1;
984 }
985
986 if ( project->select < 1 ) nsel = project_count_mg_part_selected(project);
987 else nsel = project_count_rec_part_selected(project);
988
989 if ( verbose & VERB_DEBUG )
990 cout << "DEBUG part_select_percentage: npart=" << npart << " nsel=" << nsel << endl;
991
992 // Get the FOM cutoff
993 long num_to_select = (long) (nsel*percentage/100.0);
994 if ( num_to_select < 0 ) num_to_select = 0;
995 if ( num_to_select >= npart ) num_to_select = npart - 1;
996
997 int* sel = new int[npart];
998
999 if ( verbose & VERB_DEBUG )
1000 cout << "DEBUG part_select_percentage: Writing the selection array:" << endl;
1001 // Write the top number into the selection array
1002 for ( n=0; n<num_to_select; n++ ) sel[rank[n].i] = 1;
1003 for ( ; n<npart; n++ ) sel[rank[n].i] = 0;
1004
1005 // Write the selection array back into the parameter hierarchy
1006 nsel = part_convert_selection(project, sel);
1007
1008 delete[] sel;
1009 delete[] rank;
1010
1011 return nsel;
1012 }
1013
1026 long part_select_best(Bproject* project, long number, int fom_index, int defocus_fit)
1027 {
1028 if ( number < 1 ) return 0;
1029
1030 long npart(0), nsel(0), n;
1031
1032 if ( project->select < 1 ) nsel = project_count_mg_part_selected(project);
1033 else nsel = project_count_rec_part_selected(project);
1034
1035 if ( number > nsel ) number = nsel;
1036
1037 if ( verbose & VERB_LABEL )
1038 cout << "Selecting " << number << " particles based on FOM[" << fom_index << "] ranking:" << endl;
1039
1040 int_float* rank = project_fom_order(project, npart, fom_index, defocus_fit);
1041
1042 if ( npart < 1 ) {
1043 cerr << "Error: No particles found!" << endl;
1044 return -1;
1045 }
1046
1047 if ( verbose & VERB_DEBUG )
1048 cout << "DEBUG part_select_best: npart=" << npart << " nsel=" << nsel << endl;
1049
1050 int* sel = new int[npart];
1051
1052 if ( verbose & VERB_DEBUG )
1053 cout << "DEBUG part_select_best: Writing the selection array:" << endl;
1054
1055 // Write the top number into the selection array
1056 for ( n=0; n<number; n++ ) sel[rank[n].i] = 1;
1057 for ( ; n<npart; n++ ) sel[rank[n].i] = 0;
1058
1059 // Write the selection array back into the parameter hierarchy
1060 nsel = part_convert_selection(project, sel);
1061
1062 delete[] sel;
1063 delete[] rank;
1064
1065 return nsel;
1066 }
1067
1082 long part_select_FOM_avg_std(Bproject* project, double factor, int fom_index)
1083 {
1084 long n(0);
1085 double avg(0), std(0);
1086
1087 Bfield* field;
1088 Bmicrograph* mg;
1089 Breconstruction* rec;
1090 Bparticle* part;
1091
1092 if ( verbose & (VERB_LABEL | VERB_PROCESS) )
1093 cout << "Selecting particles based on the FOM average and standard deviation" << endl;
1094
1095 if ( project->select < 1 ) {
1096 for ( field = project->field; field; field = field->next ) {
1097 for ( mg = field->mg; mg; mg = mg->next ) {
1098 for ( part = mg->part; part; part = part->next ) {
1099 avg += part->fom[fom_index];
1100 std += part->fom[fom_index]*part->fom[fom_index];
1101 n++;
1102 }
1103 }
1104 }
1105 } else {
1106 for ( rec = project->rec; rec; rec = rec->next ) {
1107 for ( part = rec->part; part; part = part->next ) {
1108 avg += part->fom[fom_index];
1109 std += part->fom[fom_index]*part->fom[fom_index];
1110 n++;
1111 }
1112 }
1113 }
1114
1115 if ( n ) avg /= n;
1116 if ( n > 1 ) std = sqrt(std/n - avg*avg);
1117 else std = 0;
1118
1119 if ( verbose & VERB_PROCESS )
1120 cout << "Average and standard deviation: " << avg << " " << std << endl << endl;
1121
1122 long nsel = part_deselect(project, fom_index, avg + factor*std);
1123
1124 return nsel;
1125 }
1126
1137 long part_select_random(Bproject* project, long number)
1138 {
1139 random_seed();
1140
1141 long i, n, nsel;
1142
1143 if ( project->select < 1 ) {
1144 nsel = project_count_mg_part_selected(project);
1145 } else {
1146 nsel = project_count_rec_part_selected(project);
1147 }
1148
1149 if ( number >= nsel ) return nsel;
1150
1151 long d = (long) (get_rand_max()/nsel);
1152 if ( d < 1 ) d = 1;
1153
1154 int v = (number < nsel/2)? 1: 0;
1155 int* narr = new int[nsel];
1156 for ( i=0; i<nsel; i++ ) narr[i] = 1-v;
1157
1158 for ( i=0; i<number; i++ ) {
1159 while ( ( n = random()/d ) >= nsel ) ;
1160 while ( n < nsel && narr[n] == v ) n++;
1161 if ( n >= nsel ) n = nsel - 1;
1162 while ( n >= 0 && narr[n] == v ) n--;
1163 if ( n < 0 ) n = 0;
1164 if ( narr[n] == v )
1165 cerr << "Warning: A random selection has been missed!" << endl;
1166 else
1167 narr[n] = v;
1168 }
1169
1170 Bfield* field;
1171 Bmicrograph* mg;
1172 Breconstruction* rec;
1173 Bparticle* part;
1174
1175 if ( verbose & VERB_PROCESS )
1176 cout << "Selecting " << number << " particles randomly" << endl;
1177
1178 n = nsel = 0;
1179 if ( project->select < 1 ) {
1180 for ( field = project->field; field; field = field->next ) {
1181 for ( mg = field->mg; mg; mg = mg->next ) {
1182 for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
1183 if ( narr[n] < 1 ) part->sel = 0;
1184 if ( part->sel ) nsel++;
1185 n++;
1186 }
1187 }
1188 }
1189 } else {
1190 for ( rec = project->rec; rec; rec = rec->next ) {
1191 for ( part = rec->part; part; part = part->next ) if ( part->sel ) {
1192 if ( narr[n] < 1 ) part->sel = 0;
1193 if ( part->sel ) nsel++;
1194 n++;
1195 }
1196 }
1197 }
1198
1199 delete[] narr;
1200
1201 if ( verbose & VERB_PROCESS )
1202 cout << "Particles selected: " << nsel << endl << endl;
1203
1204 return nsel;
1205 }
1206
1217 long part_select_random_fraction(Bproject* project, double fraction)
1218 {
1219 random_seed();
1220
1221 long nsel(0);
1222 long cut = (long) (fraction*get_rand_max());
1223
1224 Bfield* field;
1225 Bmicrograph* mg;
1226 Breconstruction* rec;
1227 Bparticle* part;
1228
1229 if ( verbose & VERB_PROCESS )
1230 cout << "Selecting " << fraction*100 << "% of the particles randomly" << endl;
1231
1232 if ( project->select < 1 ) {
1233 for ( field = project->field; field; field = field->next ) {
1234 for ( mg = field->mg; mg; mg = mg->next ) {
1235 for ( part = mg->part; part; part = part->next ) {
1236 if ( random() > cut ) part->sel = 0;
1237 if ( part->sel ) nsel++;
1238 }
1239 }
1240 }
1241 } else {
1242 for ( rec = project->rec; rec; rec = rec->next ) {
1243 for ( part = rec->part; part; part = part->next ) {
1244 if ( random() > cut ) part->sel = 0;
1245 if ( part->sel ) nsel++;
1246 }
1247 }
1248 }
1249
1250 if ( verbose & VERB_PROCESS )
1251 cout << "Particles selected: " << nsel << endl << endl;
1252
1253 return nsel;
1254 }
1255
1266 long part_select_random_group(Bproject* project, long number)
1267 {
1268 random_seed();
1269
1270 long i, max(0), nsel(0);
1271 double irm;
1272 int* sel;
1273
1274 Bfield* field;
1275 Bmicrograph* mg;
1276 Breconstruction* rec;
1277 Bparticle* part;
1278
1279 if ( verbose & VERB_PROCESS )
1280 cout << "Picking groups randomly to select at least " << number << " particles" << endl;
1281
1282 if ( project->select < 1 ) {
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 ( max < part->group ) max = part->group;
1287 } else {
1288 for ( rec = project->rec; rec; rec = rec->next )
1289 for ( part = rec->part; part; part = part->next )
1290 if ( max < part->group ) max = part->group;
1291 }
1292
1293 if ( verbose & VERB_DEBUG )
1294 cout << "DEBUG part_select_random_group: max=" << max << endl;
1295
1296 max++;
1297 irm = max*1.0L/(get_rand_max() + 1.0L);
1298 sel = new int[max];
1299 for ( i=0; i<max; i++ ) sel[i] = 0;
1300
1301 if ( project->select < 1 ) {
1302 for ( field = project->field; field; field = field->next )
1303 for ( mg = field->mg; mg; mg = mg->next )
1304 for ( part = mg->part; part; part = part->next )
1305 sel[part->group]--;
1306 } else {
1307 for ( rec = project->rec; rec; rec = rec->next )
1308 for ( part = rec->part; part; part = part->next )
1309 sel[part->group]--;
1310 }
1311
1312 while ( nsel < number ) {
1313 i = (long) (irm * random());
1314 if ( sel[i] < 0 ) {
1315 sel[i] = -sel[i];
1316 nsel += sel[i];
1317 }
1318 }
1319
1320 nsel = 0;
1321
1322 if ( project->select < 1 ) {
1323 for ( field = project->field; field; field = field->next )
1324 for ( mg = field->mg; mg; mg = mg->next )
1325 for ( part = mg->part; part; part = part->next ) {
1326 if ( sel[part->group] <= 0 ) part->sel = 0;
1327 if ( part->sel ) nsel++;
1328 }
1329 } else {
1330 for ( rec = project->rec; rec; rec = rec->next )
1331 for ( part = rec->part; part; part = part->next ) {
1332 if ( sel[part->group] <= 0 ) part->sel = 0;
1333 if ( part->sel ) nsel++;
1334 }
1335 }
1336
1337 delete[] sel;
1338
1339 if ( verbose & VERB_PROCESS )
1340 cout << "Particles selected: " << nsel << endl << endl;
1341
1342 return nsel;
1343 }
1344
1357 long part_select_bootstrap(Bproject* project, int number)
1358 {
1359 random_seed();
1360
1361 long i, rn, n = project_count_mg_part_selected(project), nsel(0);
1362
1363 if ( verbose & VERB_PROCESS )
1364 cout << "Selecting " << number << " from " << n << " particles randomly with replacement for bootstrapping" << endl;
1365
1366 double rnf = n*1.0L/get_rand_max();
1367
1368 int* sel = new int[n];
1369 for ( i=0; i<n; i++ ) sel[i] = 0;
1370
1371 for ( i=0; i<number; i++ ) {
1372 rn = n;
1373 while ( rn >= n ) rn = (long) (rnf*random());
1374 sel[rn]++;
1375 }
1376
1377 Bfield* field;
1378 Bmicrograph* mg;
1379 Bparticle* part;
1380
1381 for ( i=nsel=0, field = project->field; field; field = field->next ) {
1382 for ( mg = field->mg; mg; mg = mg->next ) {
1383 for ( part = mg->part; part; part = part->next ) {
1384 if ( part->sel ) {
1385 part->sel = sel[i++];
1386 if ( part->sel ) nsel++;
1387 }
1388 }
1389 }
1390 }
1391
1392 delete[] sel;
1393
1394 if ( verbose & VERB_PROCESS )
1395 cout << "Particles selected: " << nsel << endl << endl;
1396
1397 return nsel;
1398 }
1399
1416 long part_select_random_within_view(Bproject* project, Bsymmetry* sym,
1417 double theta_step, double phi_step, int number)
1418 {
1419 random_seed();
1420
1421 View* viewlist = asymmetric_unit_views(sym, theta_step, phi_step, 1);
1422
1423 long nview = count_list((char *) viewlist);
1424 long i, j, k, n0;
1425 double d, dmin;
1426 double rnf = 1.0L/get_rand_max();
1427
1428 int* np = new int[nview];
1429 int* nr = new int[number];
1430 int* nrn = new int[number];
1431 for ( i=0; i<nview; i++ ) np[i] = 0;
1432 for ( i=0; i<number; i++ ) nr[i] = nrn[i] = 0;
1433
1434 Bfield* field;
1435 Bmicrograph* mg;
1436 Bparticle* part;
1437 View* view;
1438
1439 // Assign views and count the number of particles per view
1440 for ( i=0, field = project->field; field; field = field->next ) {
1441 for ( mg = field->mg; mg; mg = mg->next ) {
1442 for ( part = mg->part; part; part = part->next ) {
1443 if ( part->sel > 0 ) {
1444 for ( j=0, dmin=10, view = viewlist; view; view = view->next, j++ ) {
1445 d = view->distance(part->view);
1446 if ( d < dmin ) {
1447 dmin = d;
1448 part->sel = -(j+1); // Negative to not be confused with positive selection later
1449 }
1450 }
1451 np[-part->sel-1]++;
1452 }
1453 }
1454 }
1455 }
1456
1457 kill_list((char *) viewlist, sizeof(View));
1458
1459 for ( j=n0=0; j<nview; j++ ) if ( np[j] < 1 ) n0++;
1460
1461 if ( verbose ) {
1462 cout << "Selecting a maximum of " << number << " particles from each view:" << endl;
1463 cout << "Symmetry: " << sym->label << endl;
1464 cout << "Number of views: " << nview << endl;
1465 cout << "View coverage: " << 100*(1 - n0*1.0/nview) << " %" << endl;
1466 }
1467
1468 // For each view, select the desired number of particles randomly
1469 for ( j=0; j<nview; j++ ) if ( np[j] ) {
1470 for ( k=0; k<number; k++ ) {
1471 nr[k] = (int) (random()*rnf*np[j]);
1472 nrn[k] = 1;
1473 for ( i=0; i<k; i++ ) if ( nr[i] == nr[k] ) nrn[i]++;
1474 }
1475 if ( verbose & VERB_DEBUG ) {
1476 cout << "DEBUG part_select_random_within_view: " << j+1 << "(" << np[j] << ") ";
1477 for ( k=0; k<number; k++ ) cout << nr[k] << "(" << nrn[k] << ") ";
1478 cout << endl;
1479 }
1480 for ( i=0, field = project->field; field; field = field->next ) {
1481 for ( mg = field->mg; mg; mg = mg->next ) {
1482 for ( part = mg->part; part; part = part->next ) {
1483 if ( part->sel == -(j+1) ) {
1484 for ( k=0; k<number && nr[k] != i; k++ ) ;
1485 if ( k >= number ) part->sel = 0;
1486 else part->sel = nrn[k]; // Selection is set to be used with bootstrapping reconstruction
1487 i++;
1488 }
1489 }
1490 }
1491 }
1492 }
1493
1494 delete[] np;
1495 delete[] nr;
1496 delete[] nrn;
1497
1498 long nsel = project_count_mg_part_selected(project);
1499
1500 if ( verbose & VERB_PROCESS )
1501 cout << "Particles selected: " << nsel << endl << endl;
1502
1503 return nsel;
1504 }
1505
1520 long part_select_maxsmooth(Bproject* project, Bsymmetry* sym,
1521 double theta_step, double phi_step, double threshfrac, double sigma, int fom_index)
1522 {
1523 View* viewlist = asymmetric_unit_views(sym, theta_step, phi_step, 1);
1524
1525 long nview = count_list((char *) viewlist);
1526 long i, j, n0;
1527 double isig2(-0.5/(sigma*sigma)), d, dmin, f;
1528
1529 long* np = new long[nview];
1530 double* fommax = new double[nview];
1531 for ( i=0; i<nview; i++ ) fommax[i] = np[i] = 0;
1532
1533 Bfield* field;
1534 Bmicrograph* mg;
1535 Bparticle* part;
1536 View *view, *view2, symview;
1537
1538 // Assign views and count the number of particles per view
1539 for ( field = project->field; field; field = field->next ) {
1540 for ( mg = field->mg; mg; mg = mg->next ) {
1541 for ( part = mg->part; part; part = part->next ) {
1542 if ( part->sel > 0 ) {
1543 for ( j=0, dmin=10, view = viewlist; view; view = view->next, j++ ) {
1544 d = view->angle(part->view);
1545 if ( d < dmin ) {
1546 dmin = d;
1547 part->sel = j+1;
1548 }
1549 }
1550 np[part->sel-1]++;
1551 if ( fommax[part->sel-1] < part->fom[fom_index] )
1552 fommax[part->sel-1] = part->fom[fom_index];
1553 }
1554 }
1555 }
1556 }
1557
1558 for ( i=n0=0; i<nview; i++ ) if ( np[i] < 1 ) n0++;
1559
1560 if ( verbose ) {
1561 cout << "Selecting based on smoothed maxima surface:" << endl;
1562 cout << "Symmetry: " << sym->label << endl;
1563 cout << "Number of views: " << nview << endl;
1564 cout << "View coverage: " << 100*(1 - n0*1.0/nview) << " %" << endl;
1565 cout << "Threshold fraction: " << threshfrac << endl;
1566 cout << "Smoothing sigma: " << sigma*180.0/M_PI << " degrees" << endl << endl;
1567 }
1568
1569 if ( verbose & VERB_FULL ) {
1570 cout << "Maxima:" << endl << "#\tViewX\tViewY\tCount\tFOMmax" << endl;
1571 for ( i=0, view = viewlist; view; view = view->next, i++ )
1572 cout << i+1 << tab << view->x() << tab << view->y() << tab << np[i] << tab << fommax[i] << endl;
1573 }
1574
1575 // Smooth maxima surface
1576 for ( i=0, view = viewlist; view; view = view->next, i++ ) {
1577 for ( j=0, view2 = viewlist; view2; view2 = view2->next, j++ )
1578 if ( i != j ) {
1579 symview = find_closest_symmetric_view(sym, *view, *view2);
1580 d = view->angle(symview);
1581 f = exp(d*d*isig2);
1582 if ( fommax[i] > fommax[j] ) {
1583 f *= fommax[i];
1584 if ( fommax[j] < f ) fommax[j] = f;
1585 } else {
1586 f *= fommax[j];
1587 if ( fommax[i] < f ) fommax[i] = f;
1588 }
1589 }
1590 }
1591
1592 if ( verbose & VERB_FULL ) {
1593 cout << "Smoothed maxima:" << endl << "#\tViewX\tViewY\tCount\tFOMmax" << endl;
1594 for ( i=0, view = viewlist; view; view = view->next, i++ )
1595 cout << i+1 << tab << view->x() << tab << view->y() << tab << np[i] << tab << fommax[i] << endl;
1596 }
1597
1598 kill_list((char *) viewlist, sizeof(View));
1599
1600 // Set the thresholds
1601 for ( i=0; i<nview; i++ ) fommax[i] *= threshfrac;
1602
1603 // Select particles based on smoothed maxima surface
1604 for ( field = project->field; field; field = field->next )
1605 for ( mg = field->mg; mg; mg = mg->next )
1606 for ( part = mg->part; part; part = part->next )
1607 if ( part->sel > 0 )
1608 if ( part->fom[fom_index] < fommax[part->sel-1] )
1609 part->sel = 0;
1610
1611 long nsel = project_count_mg_part_selected(project);
1612
1613 if ( verbose & VERB_PROCESS )
1614 cout << "Particles selected: " << nsel << endl << endl;
1615
1616 return nsel;
1617 }
1618
1619
1633 long part_select_best_within_view(Bproject* project, Bsymmetry* sym,
1634 double theta_step, double phi_step, int number, int fom_index)
1635 {
1636 View* viewlist = asymmetric_unit_views(sym, theta_step, phi_step, 1);
1637
1638 long nview = count_list((char *) viewlist);
1639 long j, k, n, n0, imin;
1640 double d, dmin, fommin;
1641
1642 int* np = new int[nview];
1643 Bparticle** bestpart = new Bparticle*[number];
1644 for ( j=0; j<nview; j++ ) np[j] = 0;
1645
1646 Bfield* field;
1647 Bmicrograph* mg;
1648 Bparticle* part;
1649 View* view;
1650
1651 // Assign views and count the number of particles per view
1652 for ( field = project->field; field; field = field->next ) {
1653 for ( mg = field->mg; mg; mg = mg->next ) {
1654 for ( part = mg->part; part; part = part->next ) {
1655 if ( part->sel > 0 ) {
1656 for ( j=0, dmin=10, view = viewlist; view; view = view->next, j++ ) {
1657 d = view->distance(part->view);
1658 if ( d < dmin ) {
1659 dmin = d;
1660 part->sel = j+1;
1661 }
1662 }
1663 np[part->sel-1]++;
1664 }
1665 }
1666 }
1667 }
1668
1669 kill_list((char *) viewlist, sizeof(View));
1670
1671 for ( j=n0=0; j<nview; j++ ) if ( np[j] < 1 ) n0++;
1672
1673 if ( verbose ) {
1674 cout << "Selecting a maximum of " << number << " best particles from each view:" << endl;
1675 cout << "Symmetry: " << sym->label << endl;
1676 cout << "Number of views: " << nview << endl;
1677 cout << "View coverage: " << 100*(1 - n0*1.0/nview) << " %" << endl;
1678 }
1679
1680 // For each view, select the best desired number of particles
1681 for ( j=0; j<nview; j++ ) if ( np[j] ) {
1682 for ( k=n=0; k<number; k++ ) bestpart[k] = NULL;
1683 for ( field = project->field; field; field = field->next ) {
1684 for ( mg = field->mg; mg; mg = mg->next ) {
1685 for ( part = mg->part; part; part = part->next ) {
1686 if ( part->sel == j+1 ) {
1687 if ( n < number ) bestpart[n++] = part; // Fill up the array
1688 else {
1689 for ( k=0, imin=0, fommin=1e30; k<number; k++ ) { // Find the minimum
1690 if ( fommin > bestpart[k]->fom[fom_index] ) {
1691 fommin = bestpart[k]->fom[fom_index];
1692 imin = k;
1693 }
1694 }
1695 if ( part->fom[fom_index] > fommin ) { // Replace the minimum
1696 bestpart[imin]->sel = 0;
1697 bestpart[imin] = part;
1698 } else part->sel = 0;
1699 }
1700 }
1701 }
1702 }
1703 }
1704 }
1705
1706 delete[] np;
1707 delete[] bestpart;
1708
1709 long nsel = project_count_mg_part_selected(project);
1710
1711 if ( verbose & VERB_PROCESS )
1712 cout << "Particles selected: " << nsel << endl << endl;
1713
1714 return nsel;
1715 }
1716
1722 long part_select_to_group(Bproject* project)
1723 {
1724 if ( !project ) return 0;
1725
1726 long nsel(0);
1727
1728 Bfield* field;
1729 Bmicrograph* mg;
1730 Breconstruction* rec;
1731 Bparticle* part;
1732
1733 if ( verbose & VERB_LABEL )
1734 cout << "Transferring selections to groups:" << endl;
1735
1736 if ( project->select ) {
1737 for ( rec = project->rec; rec; rec = rec->next ) {
1738 for ( part = rec->part; part; part = part->next ) {
1739 part->group = part->sel;
1740 if ( part->sel ) ++nsel;
1741 }
1742 }
1743 } else {
1744 for ( field = project->field; field; field = field->next ) {
1745 for ( mg = field->mg; mg; mg = mg->next ) {
1746 for ( part = mg->part; part; part = part->next ) {
1747 part->group = part->sel;
1748 if ( part->sel ) ++nsel;
1749 }
1750 }
1751 }
1752 }
1753
1754 if ( verbose & VERB_LABEL )
1755 cout << "Particles selected: " << nsel << endl << endl;
1756
1757 return nsel;
1758 }
1759
1766 long part_select_group(Bproject* project, int group)
1767 {
1768 if ( !project ) return 0;
1769
1770 long nsel(0);
1771
1772 Bfield* field;
1773 Bmicrograph* mg;
1774 Breconstruction* rec;
1775 Bparticle* part;
1776
1777 if ( verbose & VERB_LABEL )
1778 cout << "Selecting particles of group " << group << endl;
1779
1780 if ( project->select ) {
1781 for ( rec = project->rec; rec; rec = rec->next ) {
1782 for ( part = rec->part; part; part = part->next ) if ( part->sel ) {
1783 if ( part->group == group ) part->sel = ++nsel;
1784 else part->sel = 0;
1785 }
1786 }
1787 } else {
1788 for ( field = project->field; field; field = field->next ) {
1789 for ( mg = field->mg; mg; mg = mg->next ) {
1790 for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
1791 if ( part->group == group ) part->sel = ++nsel;
1792 else part->sel = 0;
1793 }
1794 }
1795 }
1796 }
1797
1798 if ( verbose & VERB_LABEL )
1799 cout << "Particles selected: " << nsel << endl << endl;
1800
1801 return nsel;
1802 }
1803
1815 long part_select_sets(Bproject* project, int size, int flag)
1816 {
1817 if ( !project || size <= 0 ) return 0;
1818
1819 long nsel(0), count(0), np, number(0), ntot(0);
1820
1821 Bfield* field;
1822 Bmicrograph* mg;
1823 Breconstruction* rec;
1824 Bparticle* part;
1825
1826 if ( verbose & VERB_LABEL )
1827 cout << "Generating sets of " << size << " particles each" << endl;
1828
1829 if ( project->select ) {
1830 for ( field = project->field; field; field = field->next )
1831 for ( mg = field->mg; mg; mg = mg->next ) mg->select = 0;
1832 for ( rec = project->rec; rec; rec = rec->next ) {
1833 if ( flag && count ) {
1834 count = 0;
1835 number++;
1836 }
1837 for ( np=0, part = rec->part; part; part = part->next, ntot++ ) {
1838 if ( part->sel ) {
1839 if ( count >= size ) {
1840 number++;
1841 count = 0;
1842 }
1843 if ( number < 1 ) number = 1;
1844 part->sel = number;
1845 count++;
1846 nsel++;
1847 np++;
1848 }
1849 }
1850 if ( np < 1 ) rec->select = 0;
1851 }
1852 } else {
1853 for ( rec = project->rec; rec; rec = rec->next ) rec->select = 0;
1854 for ( field = project->field; field; field = field->next ) {
1855 for ( mg = field->mg; mg; mg = mg->next ) {
1856 if ( flag && count ) {
1857 count = 0;
1858 number++;
1859 }
1860 for ( np=0, part = mg->part; part; part = part->next, ntot++ ) {
1861 if ( part->sel ) {
1862 if ( count >= size ) {
1863 number++;
1864 count = 0;
1865 }
1866 if ( number < 1 ) number = 1;
1867 part->sel = number;
1868 count++;
1869 nsel++;
1870 np++;
1871 }
1872 }
1873 if ( np < 1 ) mg->select = 0;
1874 }
1875 }
1876 }
1877
1878 if ( verbose ) {
1879 if ( ntot < 1 ) ntot = 1;
1880 cout << "Number of sets generated: " << number << endl;
1881 cout << "Number of particles selected: " << nsel << " (" << nsel*100.0/ntot << " %)" << endl << endl;
1882 }
1883
1884 return nsel;
1885 }
1886
1898 long part_select_frames(Bproject* project, int frame_start, int frame_end)
1899 {
1900 int n, sel;
1901 long nsel(0);
1902 Bfield* field;
1903 Bmicrograph* mg;
1904 Bparticle* part;
1905
1906 if ( verbose & (VERB_LABEL | VERB_PROCESS) )
1907 cout << "Selecting particle series." << endl;
1908
1909 for ( field = project->field; field; field = field->next ) {
1910 for ( n=1, mg = field->mg; mg; mg = mg->next, n++ ) {
1911 sel = 0;
1912 if ( n >= frame_start && n <= frame_end ) sel = 1;
1913 for ( part = mg->part; part; part = part->next ) {
1914 if ( !sel ) part->sel = 0;
1915 if ( part->sel ) nsel++;
1916 }
1917 }
1918 }
1919
1920 return nsel;
1921 }
1922
1923
1924 long part_fil_dir_stats(Bparticle* partlist)
1925 {
1926 long nchanged(0);
1927 int i, group(-1), n[2], dir(0);
1928 double da, a[2];
1929 View view, pview;
1930 Bparticle* part;
1931 Bparticle* fil_start = NULL;
1932 Bparticle* fil_part = NULL;
1933
1934 for ( part = partlist; part; part = part->next ) {
1935 view = part->view.backward();
1936 if ( part->group != group ) {
1937 fil_start = part;
1938 dir = 0;
1939 n[0] = 1;
1940 n[1] = 0;
1941 a[0] = a[1] = 0;
1942 group = part->group;
1943 } else {
1944 da = view.angle(pview);
1945 if ( da > M_PI_2 ) {
1946 dir = 1 - dir;
1947 da -= M_PI;
1948 if ( verbose & VERB_FULL )
1949 cout << group << tab << part->id << tab << da << tab << 1-2*dir << endl;
1950 }
1951 a[dir] += da*da;
1952 n[dir]++;
1953 if ( verbose & VERB_FULL )
1954 cout << group << tab << part->id << tab << da << tab << 1-2*dir << endl;
1955 }
1956 if ( part->next == NULL || part->next->group != group ) {
1957 for ( i=0; i<2; i++ ) if ( n[i] ) a[i] = sqrt(a[i]/n[i]);
1958 if ( verbose & VERB_PROCESS )
1959 cout << part->group << tab << n[0] << tab << n[1] << tab <<
1960 a[0]*180.0/M_PI << tab << a[1]*180.0/M_PI << endl;
1961 pview = fil_start->view.backward();
1962 if ( n[1] > n[0] ) { pview.negate(); pview[3] = -pview.angle(); }
1963 for ( fil_part = fil_start; fil_part && fil_part->group == group; fil_part = fil_part->next ) {
1964 view = fil_part->view.backward();
1965 da = view.angle(pview);
1966 if ( da > M_PI_2 ) {
1967 view.negate(); view[3] = -view.angle();
1968 fil_part->view = view.backward();
1969 nchanged++;
1970 }
1971 pview = view;
1972 }
1973 }
1974 pview = part->view.backward();
1975 }
1976
1977 return nchanged;
1978 }
1979
1980 long part_fil_dir_stats(Bparticle* partlist, double minpct)
1981 {
1982 if ( minpct < 1 ) minpct *= 100;
1983
1984 long n(0), up(0), dn(0), nt(0);
1985 int group(-1), fin(0), dir;
1986 double tol(20*M_PI/180), pup, pdn;
1987 Euler euler;
1988 Bparticle* part;
1989 Bparticle* fil_part = NULL;
1990
1991 if ( verbose & VERB_PROCESS )
1992 cout << "Fil#\t#part\tup\t%up\tdown\t%down\toutliers" << endl;
1993
1994 for ( part = partlist; part; part = part->next ) {
1995 euler = Euler(part->view);
1996
1997 if ( part->group != group ) {
1998 n = up = dn = fin = 0;
1999 pup = pdn = 0;
2000 group = part->group;
2001 fil_part = part;
2002 }
2003
2004 n++;
2005 if ( euler.psi() <= -M_PI_2 + tol && euler.psi() >= -M_PI_2 - tol ) up++;
2006 if ( euler.psi() <= M_PI_2 + tol && euler.psi() >= M_PI_2 - tol ) dn++;
2007
2008 if ( part->next ) {
2009 if ( part->next->group != group ) fin = 1;
2010 } else fin = 1;
2011
2012 if ( fin ) {
2013 if ( n ) {
2014 pup = up*100.0/n;
2015 pdn = dn*100.0/n;
2016 nt += up + dn;
2017 }
2018
2019 if ( verbose & VERB_PROCESS )
2020 cout << group << tab << n << tab << up << tab << pup << tab << dn << tab << pdn << tab << n-up-dn << endl;
2021
2022 if ( pup >= minpct ) {
2023 dir = 1;
2024 } else if ( pdn >= minpct ) {
2025 dir = -1;
2026 } else {
2027 dir = 0;
2028 }
2029
2030 for ( ; fil_part && fil_part->group == group; fil_part = fil_part->next ) if ( fil_part->sel > 0 ) {
2031 euler = Euler(fil_part->view);
2032 fil_part->sel = 0;
2033 if ( euler.psi() <= -M_PI_2 + tol && euler.psi() >= -M_PI_2 - tol && dir == 1 ) fil_part->sel = 1;
2034 if ( euler.psi() <= M_PI_2 + tol && euler.psi() >= M_PI_2 - tol && dir == -1 ) fil_part->sel = 1;
2035 }
2036 }
2037 }
2038
2039 return nt;
2040 }
2041
2042
2055 long part_filament_direction(Bproject* project, double minpct)
2056 {
2057 if ( !project ) return 0;
2058 if ( minpct < 1 ) minpct *= 100;
2059
2060 long npart(0), ndir(0);
2061
2062 Bfield* field;
2063 Bmicrograph* mg;
2064 Breconstruction* rec;
2065
2066 if ( verbose & ( VERB_LABEL | VERB_PROCESS ) ) {
2067 cout << "Checking filament directions:" << endl;
2068 cout << "Minimum percentage directed particles: " << minpct << endl << endl;
2069 }
2070
2071 if ( project->select ) {
2072 npart = project_count_rec_particles(project);
2073 for ( rec = project->rec; rec; rec = rec->next ) {
2074 if ( verbose )
2075 cout << "Reconstruction: " << rec->id << endl;
2076 ndir += part_fil_dir_stats(rec->part, minpct);
2077 }
2078 } else {
2079 npart = project_count_mg_particles(project);
2080 for ( field = project->field; field; field = field->next )
2081 for ( mg = field->mg; mg; mg = mg->next ) {
2082 if ( verbose )
2083 cout << "Micrograph: " << mg->id << endl;
2084 ndir += part_fil_dir_stats(mg->part, minpct);
2085 }
2086 }
2087
2088 if ( verbose & VERB_LABEL )
2089 cout << endl << "Particles with direction: " << ndir << " (" << ndir*100.0/npart << "%)" << endl << endl;
2090
2091 return ndir;
2092 }
2093
2104 long part_view_select(Bproject* project, View view, double angle)
2105 {
2106 long nsel(0);
2107 double da;
2108 Bfield* field;
2109 Bmicrograph* mg;
2110 Breconstruction* rec;
2111 Bparticle* part;
2112
2113 if ( verbose & (VERB_LABEL|VERB_PROCESS) )
2114 cout << "Selecting particles based on a view" << endl;
2115 if ( verbose & VERB_PROCESS ) {
2116 cout << "View: " << view << endl;
2117 cout << "Deviation angle: " << angle*180/M_PI << " degrees" << endl;
2118 }
2119
2120 if ( project->select < 1 ) {
2121 for ( field = project->field; field; field = field->next ) {
2122 for ( mg = field->mg; mg; mg = mg->next ) {
2123 for ( part = mg->part; part; part = part->next ) {
2124 da = part->view.angle(view);
2125 if ( da > angle ) part->sel = 0;
2126 if ( part->sel ) nsel++;
2127 }
2128 }
2129 }
2130 } else {
2131 for ( rec = project->rec; rec; rec = rec->next ) {
2132 for ( part = rec->part; part; part = part->next ) {
2133 da = part->view.angle(view);
2134 if ( da > angle ) part->sel = 0;
2135 if ( part->sel ) nsel++;
2136 }
2137 }
2138 }
2139
2140 if ( verbose & VERB_PROCESS )
2141 cout << "Particles selected: " << nsel << endl << endl;
2142
2143 return nsel;
2144 }
2145
2155 long part_side_view_select(Bproject* project, double angle)
2156 {
2157 long nsel(0);
2158 double dz(sin(angle));
2159 Bfield* field;
2160 Bmicrograph* mg;
2161 Breconstruction* rec;
2162 Bparticle* part;
2163
2164 if ( verbose & (VERB_LABEL|VERB_PROCESS) )
2165 cout << "Selecting particles with side views" << endl;
2166 if ( verbose & VERB_PROCESS ) {
2167 cout << "Deviation angle: " << angle*180/M_PI << " degrees" << endl;
2168 }
2169
2170 if ( project->select < 1 ) {
2171 for ( field = project->field; field; field = field->next ) {
2172 for ( mg = field->mg; mg; mg = mg->next ) {
2173 for ( part = mg->part; part; part = part->next ) {
2174 if ( part->view[2] > dz ) part->sel = 0;
2175 if ( part->sel ) nsel++;
2176 }
2177 }
2178 }
2179 } else {
2180 for ( rec = project->rec; rec; rec = rec->next ) {
2181 for ( part = rec->part; part; part = part->next ) {
2182 if ( part->view[2] > dz ) part->sel = 0;
2183 if ( part->sel ) nsel++;
2184 }
2185 }
2186 }
2187
2188 if ( verbose & VERB_PROCESS )
2189 cout << "Particles selected: " << nsel << endl << endl;
2190
2191 return nsel;
2192 }
2193
2203 long part_euler_angle_select(Bproject* project, double* euler6)
2204 {
2205 long i, nsel(0);
2206
2207 Bfield* field;
2208 Bmicrograph* mg;
2209 Breconstruction* rec;
2210 Bparticle* part;
2211 Euler euler;
2212
2213 if ( verbose & (VERB_LABEL|VERB_PROCESS) )
2214 cout << "Selecting particles based on Euler angle limits" << endl;
2215 if ( verbose & VERB_PROCESS ) {
2216 cout << "Psi limits: " << euler6[0]*180/M_PI << " - " << euler6[1]*180/M_PI << " degrees" << endl;
2217 cout << "Theta limits: " << euler6[2]*180/M_PI << " - " << euler6[3]*180/M_PI << " degrees" << endl;
2218 cout << "Phi limits: " << euler6[4]*180/M_PI << " - " << euler6[5]*180/M_PI << " degrees" << endl;
2219 }
2220
2221 if ( project->select < 1 ) {
2222 for ( field = project->field; field; field = field->next ) {
2223 for ( mg = field->mg; mg; mg = mg->next ) {
2224 for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
2225 euler = Euler(part->view);
2226 for ( i=0; i<3; i++ ) {
2227 if ( euler[i] < euler6[2*i] ) euler[i] += TWOPI;
2228 if ( euler[i] > euler6[2*i+1] ) euler[i] -= TWOPI;
2229 if ( euler[i] < euler6[2*i] || euler[i] > euler6[2*i+1] ) part->sel = 0;
2230 }
2231 if ( part->sel ) nsel++;
2232 }
2233 }
2234 }
2235 } else {
2236 for ( rec = project->rec; rec; rec = rec->next ) {
2237 for ( part = rec->part; part; part = part->next ) if ( part->sel ) {
2238 euler = Euler(part->view);
2239 for ( i=0; i<3; i++ ) {
2240 if ( euler[i] < euler6[2*i] ) euler[i] += TWOPI;
2241 if ( euler[i] > euler6[2*i+1] ) euler[i] -= TWOPI;
2242 if ( euler[i] < euler6[2*i] || euler[i] > euler6[2*i+1] ) part->sel = 0;
2243 }
2244 if ( part->sel ) nsel++;
2245 }
2246 }
2247 }
2248
2249 if ( verbose & VERB_PROCESS )
2250 cout << "Particles selected: " << nsel << endl << endl;
2251
2252 return nsel;
2253 }
2254
2265 long part_origin_select(Bproject* project, Vector3<double> origin, double distance)
2266 {
2267 long nsel(0);
2268 double dd;
2269 Bfield* field;
2270 Bmicrograph* mg;
2271 Breconstruction* rec;
2272 Bparticle* part;
2273
2274 if ( verbose & (VERB_LABEL|VERB_PROCESS) )
2275 cout << "Selecting particles based on the origin" << endl;
2276 if ( verbose & VERB_PROCESS ) {
2277 cout << "Origin: " << origin << endl;
2278 cout << "Maximum distance: " << distance << " pixels" << endl;
2279 }
2280
2281 if ( project->select < 1 ) {
2282 for ( field = project->field; field; field = field->next ) {
2283 for ( mg = field->mg; mg; mg = mg->next ) {
2284 for ( part = mg->part; part; part = part->next ) {
2285 dd = part->ori.distance(origin);
2286 if ( dd > distance ) part->sel = 0;
2287 if ( part->sel ) nsel++;
2288 }
2289 }
2290 }
2291 } else {
2292 for ( rec = project->rec; rec; rec = rec->next ) {
2293 for ( part = rec->part; part; part = part->next ) {
2294 dd = part->ori.distance(origin);
2295 if ( dd > distance ) part->sel = 0;
2296 if ( part->sel ) nsel++;
2297 }
2298 }
2299 }
2300
2301 if ( verbose & VERB_PROCESS )
2302 cout << "Particles selected: " << nsel << endl << endl;
2303
2304 return nsel;
2305 }
2306
2307
2317 long part_set_first_view_in_series(Bproject* project)
2318 {
2319 int f;
2320 Bfield* field;
2321 Bmicrograph* mg, *mg0;
2322 Bparticle* part, *part0;
2323
2324 if ( verbose & (VERB_LABEL | VERB_PROCESS) )
2325 cout << "Setting all to the first orientations in the first micrograph in the field-of-view" << endl;
2326
2327 for ( field = project->field; field; field = field->next ) {
2328 for ( mg0=field->mg, mg=field->mg->next; mg; mg=mg->next ) {
2329 for ( part=mg->part, part0=mg0->part; part; part=part->next, part0=part0->next ) {
2330 for ( f=0; f<NFOM; f++ ) part->fom[f] = part0->fom[f];
2331 part->sel = part0->sel;
2332 part->view = part0->view;
2333 }
2334 }
2335 }
2336
2337 return 0;
2338 }
2339
2351 long part_set_best_view_in_series(Bproject* project, int fom_index)
2352 {
2353 int f;
2354 Bfield* field;
2355 Bmicrograph* mg, *mg0;
2356 Bparticle* part, *part0;
2357
2358 if ( verbose & (VERB_LABEL | VERB_PROCESS) )
2359 cout << "Setting all to the best orientations in the field-of-view" << endl;
2360
2361 for ( field = project->field; field; field = field->next ) {
2362 for ( mg0=field->mg, mg=field->mg->next; mg; mg=mg->next ) {
2363 for ( part=mg->part, part0=mg0->part; part; part=part->next, part0=part0->next ) {
2364 if ( part->fom[fom_index] > part0->fom[fom_index] ) {
2365 for ( f=0; f<NFOM; f++ ) part0->fom[f] = part->fom[f];
2366 part0->sel = part->sel;
2367 part0->view = part->view;
2368 }
2369 }
2370 }
2371 for ( mg0=field->mg, mg=field->mg->next; mg; mg=mg->next ) {
2372 for ( part=mg->part, part0=mg0->part; part; part=part->next, part0=part0->next ) {
2373 for ( f=0; f<NFOM; f++ ) part->fom[f] = part0->fom[f];
2374 part->sel = part0->sel;
2375 part->view = part0->view;
2376 }
2377 }
2378 }
2379
2380 return 0;
2381 }
2382
2395 long part_select_series(Bproject* project, int size, int flag)
2396 {
2397 if ( size < 1 ) size = 1000000000;
2398
2399 int n;
2400 long count(0), nser(0), nsel(0);
2401 Bfield* field;
2402 Bmicrograph* mg, *mg0;
2403 Bparticle* part, *part0;
2404
2405 if ( verbose & (VERB_LABEL | VERB_PROCESS) )
2406 cout << "Selecting particle series." << endl;
2407
2408 for ( field = project->field; field; field = field->next ) {
2409 if ( flag ) nser = 0;
2410 for ( n=0, mg0=field->mg, mg = field->mg; mg; mg = mg->next, n++ ) {
2411 for ( part0=mg0->part, part = mg->part; part; part = part->next, part0=part0->next ) {
2412 if ( part->sel ) {
2413 if ( mg0 == mg ) part0->sel = 1;
2414 else part0->sel++;
2415 }
2416 }
2417 }
2418 for ( part0=field->mg->part; part0; part0=part0->next ) {
2419 if ( part0->sel == n ) {
2420 if ( nser%size == 0 ) count++;
2421 part0->sel = count;
2422 nser++;
2423 } else {
2424 part0->sel = 0;
2425 }
2426 }
2427 for ( mg0=field->mg, mg = field->mg; mg; mg = mg->next ) {
2428 for ( part0=mg0->part, part = mg->part; part; part = part->next, part0=part0->next ) {
2429 if ( part0->sel ) {
2430 part->sel = part0->sel;
2431 nsel++;
2432 } else {
2433 part->sel = 0;
2434 }
2435 }
2436 }
2437 }
2438
2439 return nsel;
2440 }
2441
2454 long part_series_from_seed(Bproject* project, int flags)
2455 {
2456 int zflip(flags & 1), use_view(flags & 2);
2457 long i, n, npart(0);
2458 Matrix3 mat(1);
2459 Bfield* field;
2460 Bmicrograph* mg;
2461 Bmicrograph* mg_ref = NULL;
2462 Breconstruction* rec;
2463 Bparticle* part_list = NULL;
2464 Bparticle *part_ref, *part;
2465 Vector3<long> part_size;
2466 Vector3<double> origin, scale(1,1,1), loc, part_ori;
2467
2468 if ( !project->rec ) project->select = 0;
2469
2470 // Find the reference particle list
2471 if ( project->select ) {
2472 if ( verbose )
2473 cout << "Calculating micrograph particle locations from 3D locations" << endl;
2474 for ( rec = project->rec; rec && !part_list; rec = rec->next )
2475 if ( rec->part ) break;
2476 if ( rec ) {
2477 part_list = rec->part;
2478 origin = rec->origin;
2479 scale /= rec->scale;
2480 part_size = scale*rec->box_size;
2481 }
2482 } else {
2483 if ( verbose )
2484 cout << "Calculating micrograph particle locations from zero-tilt micrograph" << endl;
2485 for ( field = project->field; field && !part_list; field = field->next ) {
2486 for ( mg = field->mg; mg && !part_list; mg = mg->next ) if ( mg->part ) {
2487 mg_ref = mg;
2488 part_list = mg->part;
2489 origin = mg->origin;
2490 part_size = mg->box_size;
2491 }
2492 }
2493 }
2494
2495 if ( !part_list ) {
2496 cerr << "Error: No particle records found!" << endl;
2497 return -1;
2498 }
2499
2500 part_size[2] = 1;
2501 part_ori = part_size/2;
2502
2503 // Set the selection number
2504 for ( n=0, part_ref=part_list; part_ref; part_ref=part_ref->next )
2505 part_ref->sel = ++n;
2506
2507 double ca(1), sa(0), tt(0);
2508
2509 // Generate new particle records
2510 if ( verbose )
2511 cout << "Number of particles: " << n << endl;
2512 for ( field = project->field; field; field = field->next ) {
2513 for ( mg = field->mg; mg; mg = mg->next ) if ( mg != mg_ref ) {
2514 if ( mg->part ) particle_kill(mg->part);
2515 mg->part = part = NULL;
2516 mg->box_size = part_size;
2517 ca = cos(mg->tilt_axis);
2518 sa = sin(mg->tilt_axis);
2519 tt = tan(mg->tilt_angle);
2520 for ( part_ref=part_list; part_ref; part_ref=part_ref->next ) {
2521 part = particle_add(&part, part_ref->id);
2522 if ( !mg->part ) mg->part = part;
2523 loc = (part_ref->loc - origin)*scale;
2524 if ( zflip ) loc[2] = -loc[2];
2525 part->loc = mg_location_from_3D_model(loc, mg->matrix, mg->origin, mg->scale);
2526 part->ori = part_ori;
2527 if ( use_view )
2528 mat = part_ref->view.matrix();
2529 part->view = View(mat * mg->matrix);
2530 for ( i=0; i<NFOM; i++ ) part->fom[i] = part_ref->fom[i];
2531 part->sel = part_ref->sel;
2532 if ( mg->ctf ) {
2533 loc = (part->loc - mg->origin)*mg->pixel_size;
2534 part->def = mg->ctf->defocus_average() +
2535 (loc[0]*sa - loc[1]*ca)*tt;
2536 part->dev = mg->ctf->defocus_deviation();
2537 part->ast = mg->ctf->astigmatism_angle();
2538 }
2539 npart++;
2540 }
2541 }
2542 }
2543
2544 return npart;
2545 }
2546
2558 double part_fom_defocus_fit(Bproject* project, int fom_index, double& intercept, double& slope)
2559 {
2560 slope = 0;
2561 intercept = 1;
2562
2563 Bfield* field;
2564 Bmicrograph* mg;
2565 Bparticle* part;
2566
2567 long i, npart, nmg = project_count_micrographs(project);
2568 double sum, CI(0);
2569 double* x = new double[nmg];
2570 double* y = new double[nmg];
2571 for ( i=0; i<nmg; i++ ) x[i] = y[i] = 0;
2572
2573 if ( verbose & VERB_FULL )
2574 cout << "Defocus\tFOMavg" << endl;
2575 for ( i=0, field = project->field; field; field = field->next )
2576 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
2577 for ( npart=0, sum=0, part = mg->part; part; part = part->next )
2578 if ( part->sel ) {
2579 sum += part->fom[fom_index];
2580 npart++;
2581 }
2582 if ( npart ) {
2583 x[i] = mg->ctf->defocus_average();
2584 y[i] = sum/npart;
2585 if ( verbose & VERB_FULL )
2586 cout << x[i] << tab << y[i] << endl;
2587 i++;
2588 }
2589 }
2590 if ( verbose & VERB_FULL )
2591 cout << endl;
2592
2593 if ( i ) CI = linear_least_squares(0, i-1, x, y, intercept, slope);
2594
2595 delete[] x;
2596 delete[] y;
2597
2598 if ( verbose & VERB_PROCESS ) {
2599 cout << "Linear fit: FOM = " << slope << " * defocus + " << intercept << endl;
2600 cout << "Correlation index: " << CI << endl << endl;
2601 }
2602
2603 return CI;
2604 }
2605
2618 double part_fom_defocus_fit_deselect(Bproject* project, int fom_index, double cutoff)
2619 {
2620 Bfield* field;
2621 Bmicrograph* mg;
2622 Bparticle* part;
2623
2624 double slope, intercept, this_cutoff;
2625 double CI = part_fom_defocus_fit(project, fom_index, intercept, slope);
2626
2627 for ( field = project->field; field; field = field->next )
2628 for ( mg = field->mg; mg; mg = mg->next ) {
2629 // this_cutoff = slope*mg->ctf->defocus_average() + cutoff;
2630 this_cutoff = slope*(mg->ctf->defocus_average() - 1e4) + cutoff;
2631 for ( part = mg->part; part; part = part->next )
2632 if ( part->fom[fom_index] < this_cutoff) part->sel = 0;
2633 }
2634
2635 return CI;
2636 }
2637
2643 long part_select_closest_to_focus(Bproject* project)
2644 {
2645 long nsel(0);
2646 Bfield* field;
2647 Bmicrograph* mg, *mg_ctf;
2648 Bparticle* part;
2649
2650 for ( field = project->field; field; field = field->next ) {
2651 for ( mg = mg_ctf = field->mg; mg; mg = mg->next ) {
2652 if ( mg_ctf->ctf->defocus_average() > mg->ctf->defocus_average() )
2653 mg_ctf = mg;
2654 }
2655 for ( mg = field->mg; mg; mg = mg->next ) {
2656 if ( mg != mg_ctf )
2657 for ( part = mg->part; part; part = part->next )
2658 part->sel = 0;
2659 else
2660 for ( part = mg->part; part; part = part->next )
2661 if ( part->sel ) nsel++;
2662 }
2663 }
2664
2665 return nsel;
2666 }
2667
2673 long part_select_furthest_from_focus(Bproject* project)
2674 {
2675 long nsel(0);
2676 Bfield* field;
2677 Bmicrograph* mg, *mg_ctf;
2678 Bparticle* part;
2679
2680 for ( field = project->field; field; field = field->next ) {
2681 for ( mg = mg_ctf = field->mg; mg; mg = mg->next ) {
2682 if ( mg_ctf->ctf->defocus_average() < mg->ctf->defocus_average() )
2683 mg_ctf = mg;
2684 }
2685 for ( mg = field->mg; mg; mg = mg->next ) {
2686 if ( mg != mg_ctf )
2687 for ( part = mg->part; part; part = part->next )
2688 part->sel = 0;
2689 else
2690 for ( part = mg->part; part; part = part->next )
2691 if ( part->sel ) nsel++;
2692 }
2693 }
2694
2695 return nsel;
2696 }
2697
2703 long part_delete_deselected(Bproject* project)
2704 {
2705 long id, nsel(0);
2706 Bfield* field;
2707 Bmicrograph* mg;
2708 Breconstruction* rec;
2709 Bparticle* part, *part_nu, *part_list;
2710
2711 if ( project->select ) {
2712 for ( rec = project->rec; rec; rec = rec->next ) {
2713 for ( id=0, part_list = NULL, part = rec->part; part; part = part->next ) {
2714 if ( part->sel ) {
2715 part_nu = particle_copy(&part_list, part);
2716 part_nu->id = ++id;
2717 }
2718 }
2719 particle_kill(rec->part);
2720 rec->part = part_list;
2721 nsel += id;
2722 }
2723 } else {
2724 for ( field = project->field; field; field = field->next ) {
2725 for ( mg = field->mg; mg; mg = mg->next ) {
2726 for ( id=0, part_list = NULL, part = mg->part; part; part = part->next ) {
2727 if ( part->sel ) {
2728 part_nu = particle_copy(&part_list, part);
2729 part_nu->id = ++id;
2730 }
2731 }
2732 particle_kill(mg->part);
2733 mg->part = part_list;
2734 nsel += id;
2735 }
2736 }
2737 }
2738
2739 if ( verbose & VERB_PROCESS )
2740 cout << "Particles selected: " << nsel << endl << endl;
2741
2742 return nsel;
2743 }
2744
2751 long part_fix_defocus(Bproject* project, double max_dev)
2752 {
2753 long nd(0);
2754 double dmin, dmax;
2755 Bfield* field;
2756 Bmicrograph* mg;
2757 Bparticle* part;
2758
2759 if ( verbose & VERB_PROCESS ) {
2760 cout << "Resetting particle defocus:" << endl;
2761 cout << "Maximum difference allowed: " << max_dev << " A" << endl;
2762 }
2763
2764 for ( field = project->field; field; field = field->next ) {
2765 for ( mg = field->mg; mg; mg = mg->next ) if ( mg->ctf ) {
2766 dmin = mg->ctf->defocus_average() - max_dev;
2767 dmax = mg->ctf->defocus_average() + max_dev;
2768 for ( part = mg->part; part; part = part->next ) {
2769 if ( part->def < dmin || part->def > dmax ) {
2770 part->def = mg->ctf->defocus_average();
2771 nd++;
2772 }
2773 }
2774 }
2775 }
2776
2777 if ( verbose & VERB_PROCESS )
2778 cout << "Number of defocus values reset: " << nd << endl << endl;
2779
2780 return nd;
2781 }
find_closest_symmetric_view
View find_closest_symmetric_view(Bsymmetry *sym, View view_ref, View view)
Finds the closest symmetric match between two views.
Definition: symmetry.cpp:939
Bparticle::id
int id
Definition: mg_processing.h:92
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
M_PI_2
#define M_PI_2
Definition: utilities.h:62
PARTICLE_OMEGA
#define PARTICLE_OMEGA
Definition: mg_tags.h:192
part_select_best
long part_select_best(Bproject *project, long number, int fom_index, int defocus_fit)
Selects the best particles based on the FOM.
Definition: mg_particle_select.cpp:1026
Bparticle::ast
double ast
Definition: mg_processing.h:97
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
Bparticle::mag
double mag
Definition: mg_processing.h:94
PARTICLE_HANDB_FOM
#define PARTICLE_HANDB_FOM
Definition: mg_tags.h:218
CTF_DEF_DEV
#define CTF_DEF_DEV
Definition: mg_tags.h:163
part_select_sets
long part_select_sets(Bproject *project, int size, int flag)
Selects sets of particles, each set with the same size.
Definition: mg_particle_select.cpp:1815
random_seed
long random_seed()
Gets a random seed and sets the flag.
Definition: random_numbers.cpp:41
PARTICLE_ORIGIN_X
#define PARTICLE_ORIGIN_X
Definition: mg_tags.h:186
CTF
CTFcurrimg
Dialog box to manipulate CTF parameters.
Definition: bshow_ctf.tcl:36
Euler
Definition: Euler.h:28
Bparticle::view
View view
Definition: mg_processing.h:101
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
View::next
View * next
Definition: View.h:28
Bsymmetry::n
int n
Definition: symmetry.h:42
mg_particle_select.h
Select particles.
part_select_random_group
long part_select_random_group(Bproject *project, long number)
Selects groups randomly to give at least a number of particles.
Definition: mg_particle_select.cpp:1266
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
verbose
int verbose
symmetry.h
Header file for general symmetry functions.
PARTICLE_Y
#define PARTICLE_Y
Definition: mg_tags.h:181
part_select_random
long part_select_random(Bproject *project, long number)
Selects a specific number of particles randomly.
Definition: mg_particle_select.cpp:1137
utilities.h
Header file for general utilities.
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
particle_copy
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
Definition: mg_processing.cpp:1409
PARTICLE_ORIGIN_Z
#define PARTICLE_ORIGIN_Z
Definition: mg_tags.h:188
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Breconstruction
Definition: mg_processing.h:280
part_set_first_view_in_series
long part_set_first_view_in_series(Bproject *project)
Sets all orientation parameters for a particle to the first in the set.
Definition: mg_particle_select.cpp:2317
PARTICLE_PHI
#define PARTICLE_PHI
Definition: mg_tags.h:191
part_fix_defocus
long part_fix_defocus(Bproject *project, double max_dev)
Resets defocus values for particles thata are too far off.
Definition: mg_particle_select.cpp:2751
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
project_count_mg_part_selected
long project_count_mg_part_selected(Bproject *project)
Counts the number of particles in a project.
Definition: mg_processing.cpp:833
part_select_furthest_from_focus
long part_select_furthest_from_focus(Bproject *project)
Deselects all particles except those from micrographs furthest from focus.
Definition: mg_particle_select.cpp:2673
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
PARTICLE_PSI
#define PARTICLE_PSI
Definition: mg_tags.h:189
Matrix3
Definition: Matrix3.h:17
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
project
Bproject * project
Definition: bshow.cpp:31
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
part_select_frames
long part_select_frames(Bproject *project, int frame_start, int frame_end)
Select particles from frames in a series.
Definition: mg_particle_select.cpp:1898
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_processing.cpp:811
Quaternion
Definition: Quaternion.h:25
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:1323
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_processing.cpp:1151
Breconstruction::ctf
CTFparam * ctf
Definition: mg_processing.h:303
QsortLargeToSmallIntFloat
int QsortLargeToSmallIntFloat(const void *x, const void *y)
Utility function for sorting int float pairs in qsort.
Definition: qsort_functions.cpp:89
part_select_FOM_avg_std
long part_select_FOM_avg_std(Bproject *project, double factor, int fom_index)
Selects particles based on FOM average and standard deviation.
Definition: mg_particle_select.cpp:1082
Matrix.h
Generalized matrix class.
part_fom_defocus_fit_deselect
double part_fom_defocus_fit_deselect(Bproject *project, int fom_index, double cutoff)
Deselects particles below a given FOM cutoff, adjusted for the defocus.
Definition: mg_particle_select.cpp:2618
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
PARTICLE_THETA
#define PARTICLE_THETA
Definition: mg_tags.h:190
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:432
part_deselect
long part_deselect(Bproject *project, int fom_index, double fommin, double fommax)
Deselects particles below a given FOM cutoff.
Definition: mg_particle_select.cpp:442
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_processing.cpp:746
part_invert_selection
long part_invert_selection(Bproject *project)
Inverts the selection.
Definition: mg_particle_select.cpp:202
View::y
double y()
Definition: View.h:93
project_fom_order
int_float * project_fom_order(Bproject *project, long &npart, int fom_index, int defocus_fit)
Definition: mg_particle_select.cpp:23
PARTICLE_VIEW_Z
#define PARTICLE_VIEW_Z
Definition: mg_tags.h:195
PARTICLE_X
#define PARTICLE_X
Definition: mg_tags.h:180
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:217
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:296
PARTICLE
#define PARTICLE
Definition: mg_tags.h:171
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
part_delete_deselected
long part_delete_deselected(Bproject *project)
Deletes deselected particles and renumber the remaining.
Definition: mg_particle_select.cpp:2703
part_series_from_seed
long part_series_from_seed(Bproject *project, int flags)
Calculates the locations of particles in a series from a seed.
Definition: mg_particle_select.cpp:2454
Bfield::next
Bfield * next
Definition: mg_processing.h:258
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
part_euler_angle_select
long part_euler_angle_select(Bproject *project, double *euler6)
Selects particles based on Euler angle limits.
Definition: mg_particle_select.cpp:2203
project_count_rec_particles
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_processing.cpp:902
part_filament_direction
long part_filament_direction(Bproject *project, double minpct)
Checks the direction of particles associated with filaments.
Definition: mg_particle_select.cpp:2055
int_float::f
float f
Definition: qsort_functions.h:12
PARTICLE_ID
#define PARTICLE_ID
Definition: mg_tags.h:174
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:222
part_reselect
int part_reselect(Bparticle *part, Bstring &tag, double reselect_min, double reselect_max)
Definition: mg_particle_select.cpp:664
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:216
project_count_rec_part_selected
long project_count_rec_part_selected(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_processing.cpp:919
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
part_deselect_from_list
long part_deselect_from_list(Bproject *project, Bstring list)
Deselects particles with selection numbers from a list.
Definition: mg_particle_select.cpp:387
part_set_best_view_in_series
long part_set_best_view_in_series(Bproject *project, int fom_index)
Sets all orientation parameters for a particle to the best in the set.
Definition: mg_particle_select.cpp:2351
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
Euler::psi
double psi()
Definition: Euler.h:56
part_reset_selection
long part_reset_selection(Bproject *project)
Resets selection to all particles.
Definition: mg_particle_select.cpp:131
Euler::phi
double phi()
Definition: Euler.h:58
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:328
NFOM
#define NFOM
Definition: mg_processing.h:16
part_view_select
long part_view_select(Bproject *project, View view, double angle)
Selects particles based on a distance from a reference view.
Definition: mg_particle_select.cpp:2104
CTF_DEF_AVG
#define CTF_DEF_AVG
Definition: mg_tags.h:162
part_fil_dir_stats
long part_fil_dir_stats(Bparticle *partlist)
Definition: mg_particle_select.cpp:1924
part_select_random_fraction
long part_select_random_fraction(Bproject *project, double fraction)
Selects particles randomly based on a fraction of the total.
Definition: mg_particle_select.cpp:1217
Bmicrograph::select
long select
Definition: mg_processing.h:203
Bproject::field
Bfield * field
Definition: mg_processing.h:343
Bstring::erase
Bstring erase(const long i)
Definition: Bstring.cpp:485
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
part_set_FOM
long part_set_FOM(Bproject *project, int fom_index, double fom)
Sets the FOM for all particles.
Definition: mg_particle_select.cpp:357
part_fom_defocus_fit
double part_fom_defocus_fit(Bproject *project, int fom_index, double &intercept, double &slope)
Fits the particle FOMs as a function of the defocus.
Definition: mg_particle_select.cpp:2558
part_unset_selection
long part_unset_selection(Bproject *project)
Unsets selection to no particles.
Definition: mg_particle_select.cpp:166
PARTICLE_DEF_DEV
#define PARTICLE_DEF_DEV
Definition: mg_tags.h:200
Bmicrograph
Definition: mg_processing.h:200
asymmetric_unit_views
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
Definition: symmetry.cpp:570
Bsymop::order
int order
Definition: symmetry.h:26
View::backward
View backward()
Definition: View.h:115
mg_tomography.h
Header file for single particle image processing in Bsoft.
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
irm
double irm(1.0L/get_rand_max())
part_deselect_redundant
long part_deselect_redundant(Bparticle *partlist, double excl_dist, int part_select, int fom_index)
Deselects particles overlapping with better ones.
Definition: mg_particle_select.cpp:494
int_float
Definition: qsort_functions.h:12
part_consolidate_selection
long part_consolidate_selection(Bproject *project, int number)
Consolidates selected particles under one selection number.
Definition: mg_particle_select.cpp:284
Bparticle::group
int group
Definition: mg_processing.h:93
mg_tags.h
All STAR and XML file format tags for micrographs and reconstructions.
part_select_random_within_view
long part_select_random_within_view(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, int number)
Selects a given number of particles within each view.
Definition: mg_particle_select.cpp:1416
project_maximum_selection
long project_maximum_selection(Bproject *project)
Finds the maximum slection number for a project.
Definition: mg_processing.cpp:2364
CTF_AST_ANG
#define CTF_AST_ANG
Definition: mg_tags.h:166
PARTICLE_VIEW_Y
#define PARTICLE_VIEW_Y
Definition: mg_tags.h:194
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
mg_ctf
int mg_ctf(Bmicrograph *mg, Bimage *pmg, int action, double lores, double hires, double wiener, Vector3< long > tile_size, DataType datatype, Bstring &newname, Bstring &label, int flags)
Definition: mg_ctf.cpp:971
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
part_select_maxsmooth
long part_select_maxsmooth(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, double threshfrac, double sigma, int fom_index)
Selects particles based on a smoothed maximum surface.
Definition: mg_particle_select.cpp:1520
part_convert_selection
long part_convert_selection(Bproject *project, int *sel)
Definition: mg_particle_select.cpp:873
Bsymmetry
Definition: symmetry.h:38
Bparticle::dev
double dev
Definition: mg_processing.h:96
PARTICLE_ORIGIN_Y
#define PARTICLE_ORIGIN_Y
Definition: mg_tags.h:187
Euler::theta
double theta()
Definition: Euler.h:57
Bparticle
Definition: mg_processing.h:89
part_select_group
long part_select_group(Bproject *project, int group)
Selects particles with a given group identifier.
Definition: mg_particle_select.cpp:1766
random_numbers.h
Header file for functions for creating random images.
part_select_series
long part_select_series(Bproject *project, int size, int flag)
Select series where all are already selected.
Definition: mg_particle_select.cpp:2395
Bstring
Definition: Bstring.h:29
View::matrix
Matrix3 matrix()
Definition: View.h:150
View::quaternion
Quaternion quaternion()
Definition: View.h:127
PARTICLE_AST_ANG
#define PARTICLE_AST_ANG
Definition: mg_tags.h:201
Bproject::select
int select
Definition: mg_processing.h:339
matrix_linear.h
Header file for matrix functions.
Breconstruction::select
long select
Definition: mg_processing.h:283
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
Breconstruction::scale
Vector3< double > scale
Definition: mg_processing.h:294
PARTICLE_Z
#define PARTICLE_Z
Definition: mg_tags.h:182
particle_array
Bparticle ** particle_array(Bparticle *partlist, int part_select, long &npart)
Sets up an array of selected particle pointers.
Definition: mg_processing.cpp:2107
PARTICLE_FOM
#define PARTICLE_FOM
Definition: mg_tags.h:203
part_select_to_group
long part_select_to_group(Bproject *project)
Transfer selection numbers to the group identifiers.
Definition: mg_particle_select.cpp:1722
Vector3< double >
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
part_select_FOM_groups
long part_select_FOM_groups(Bproject *project, int ngroups, int fom_index, int defocus_fit)
Selects groups of particles based on the FOM.
Definition: mg_particle_select.cpp:919
View::angle
double angle()
Definition: View.h:95
View
Definition: View.h:26
PARTICLE_MAGNIF
#define PARTICLE_MAGNIF
Definition: mg_tags.h:197
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:100
part_fom_order
int_float * part_fom_order(Bparticle *partlist, long &npart, int fom_index)
Definition: mg_particle_select.cpp:89
Bparticle::def
double def
Definition: mg_processing.h:95
PARTICLE_DEFOCUS
#define PARTICLE_DEFOCUS
Definition: mg_tags.h:199
part_select_percentage
long part_select_percentage(Bproject *project, double percentage, int fom_index, int defocus_fit)
Selects a percentage of particles based on the FOM.
Definition: mg_particle_select.cpp:969
part_origin_select
long part_origin_select(Bproject *project, Vector3< double > origin, double distance)
Selects particles based on the distance from the nominal origin.
Definition: mg_particle_select.cpp:2265
mg_processing.h
Header file for micrograph processing.
part_select_bootstrap
long part_select_bootstrap(Bproject *project, int number)
Selects a given number of particles randomly with replacement.
Definition: mg_particle_select.cpp:1357
part_select_best_within_view
long part_select_best_within_view(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, int number, int fom_index)
Selects the best number of particles within each view.
Definition: mg_particle_select.cpp:1633
int_float::i
int i
Definition: qsort_functions.h:12
PARTICLE_VIEW_ANGLE
#define PARTICLE_VIEW_ANGLE
Definition: mg_tags.h:196
part_side_view_select
long part_side_view_select(Bproject *project, double angle)
Selects particles based on a distance from a side view.
Definition: mg_particle_select.cpp:2155
part_set_filament_maps
long part_set_filament_maps(Bproject *project)
Generates a selection number from the group number for each filament.
Definition: mg_particle_select.cpp:619
QsortLargeToSmallParticle
int QsortLargeToSmallParticle(const void *x, const void *y)
Definition: mg_particle_select.cpp:478
Bsymmetry::op
Bsymop * op
Definition: symmetry.h:43
View::negate
void negate()
Definition: View.h:114
View::distance
double distance(const View &view)
Definition: View.h:155
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
PARTICLE_SELECT
#define PARTICLE_SELECT
Definition: mg_tags.h:202
View::x
double x()
Definition: View.h:92
PARTICLE_VIEW_X
#define PARTICLE_VIEW_X
Definition: mg_tags.h:193
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
Bmicrograph::scale
Vector3< double > scale
Definition: mg_processing.h:221
part_set_selection
long part_set_selection(Bproject *project, int number)
Selects one selection number and sets all others to zero.
Definition: mg_particle_select.cpp:318
mg_location_from_3D_model
Vector3< double > mg_location_from_3D_model(Vector3< double > loc, Matrix3 mat, Vector3< double > ori)
Calculates the 2D location of a marker from a 3D model.
Definition: mg_tomography.cpp:139
part_set_multi_maps
long part_set_multi_maps(Bproject *project, int part_select, int nmaps)
Sets selection for generating multiple maps.
Definition: mg_particle_select.cpp:564
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
TWOPI
#define TWOPI
Definition: utilities.h:68
part_series_comparison
double part_series_comparison(Bproject *project, Bsymmetry *sym, double angle_cutoff)
A function to select particles based on comparison of the orientations within a series.
Definition: mg_particle_select.cpp:802
part_select_closest_to_focus
long part_select_closest_to_focus(Bproject *project)
Deselects all particles except those from micrographs closest to focus.
Definition: mg_particle_select.cpp:2643
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:448
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:333
PARTICLE_FOM_CV
#define PARTICLE_FOM_CV
Definition: mg_tags.h:204
PARTICLE_HANDA_FOM
#define PARTICLE_HANDA_FOM
Definition: mg_tags.h:217
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
linear_least_squares
double linear_least_squares(int n1, int n2, double *x, double *y, double &a, double &b)
Does a linear least squares fit between two vectors.
Definition: matrix_linear.cpp:28
part_select_micrograph
long part_select_micrograph(Bproject *project, Bstring &mgselect)
Sets selection to the micrographs indicated.
Definition: mg_particle_select.cpp:245
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201