 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
26 if ( fom_index < 0 ) fom_index = 0;
27 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
40 cerr <<
"Error: No particles found!" << endl;
44 double slope, intercept, fom_adjust(0);
47 cout <<
"Ordering " << npart <<
" particles based on FOM:" << endl;
54 for ( mg = field->
mg; mg; mg = mg->
next ) {
56 for ( part = mg->
part; part; part = part->
next ) {
60 rank[nn].
f = part->
fom[fom_index] - fom_adjust;
69 for ( part = rec->
part; part; part = part->
next ) {
72 rank[nn].
f = part->
fom[fom_index];
81 cout <<
"DEBUG project_fom_order: Ranking the FOMs:" << endl;
84 qsort((
void *) rank, npart,
sizeof(
int_float),
92 if ( fom_index < 0 ) fom_index = 0;
93 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
102 cerr <<
"Error: No particles found!" << endl;
107 cout <<
"Ordering " << npart <<
" particles based on FOM:" << endl;
111 for ( part = partlist; part; part = part->
next )
if ( part->
sel ) {
113 rank[nn].
f = part->
fom[fom_index];
118 cout <<
"DEBUG part_fom_order: Ranking the FOMs:" << endl;
121 qsort((
void *) rank, npart,
sizeof(
int_float),
143 cout <<
"Resetting reconstruction particle selections" << endl << endl;
145 if ( flag & 1 ) rec->
select = 1;
146 if ( flag & 2 )
for ( part = rec->
part; part; part = part->
next, npart++ )
151 cout <<
"Resetting micrograph particle selections" << endl << endl;
153 for ( mg = field->
mg; mg; mg = mg->
next ) {
154 if ( flag & 1 ) mg->
select = 1;
155 if ( flag & 2 )
for ( part = mg->
part; part; part = part->
next, npart++ )
178 cout <<
"Unsetting reconstruction particle selections" << endl << endl;
181 for ( part = rec->
part; part; part = part->
next, npart++ )
186 cout <<
"Unsetting micrograph particle selections" << endl << endl;
188 for ( mg = field->
mg; mg; mg = mg->
next ) {
190 for ( part = mg->
part; part; part = part->
next, npart++ )
214 cout <<
"Inverts reconstruction particle selections" << endl << endl;
217 for ( part = rec->
part; part; part = part->
next, npart++ ) {
218 if ( part->
sel ) part->
sel = 0;
224 cout <<
"Inverts micrograph particle selections" << endl << endl;
226 for ( mg = field->
mg; mg; mg = mg->
next ) {
228 for ( part = mg->
part; part; part = part->
next, npart++ ) {
229 if ( part->
sel ) part->
sel = 0;
259 for ( i=1; i<=nmg; ++i )
if ( numsel[i] ) nsel++;
262 cout <<
"Micrographs selected: " << nsel <<
" (" << nsel*100.0/nmg <<
" %)" << endl;
265 for ( mg = field->
mg; mg; mg = mg->
next, ++i ) {
268 for ( part = mg->
part; part; part = part->
next )
269 if ( part->
sel ) nsel++;
293 for ( part = rec->
part; part; part = part->
next )
294 if ( part->
sel > 0 ) {
300 for ( mg = field->
mg; mg; mg = mg->
next )
301 for ( part = mg->
part; part; part = part->
next )
302 if ( part->
sel > 0 ) {
327 for ( part = rec->
part; part; part = part->
next )
328 if ( part->
sel == number ) {
335 for ( mg = field->
mg; mg; mg = mg->
next )
336 for ( part = mg->
part; part; part = part->
next )
337 if ( part->
sel == number ) {
362 for ( part = rec->
part; part; part = part->
next )
363 if ( part->
sel ) part->
sel = ++cnt;
366 for ( mg = field->
mg; mg; mg = mg->
next )
367 for ( part = mg->
part; part; part = part->
next )
368 if ( part->
sel ) part->
sel = ++cnt;
384 if ( fom_index < 0 ) fom_index = 0;
385 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
395 for ( part = rec->
part; part; part = part->
next, npart++ )
396 part->
fom[fom_index] = fom;
399 for ( mg = field->
mg; mg; mg = mg->
next )
400 for ( part = mg->
part; part; part = part->
next, npart++ )
401 part->
fom[fom_index] = fom;
416 if ( list.
length() < 1 )
return nsel;
434 for ( part = rec->
part; part; part = part->
next ) {
435 if ( part->
sel > 0 ) {
436 if ( numsel[part->
sel] ) part->
sel = 0;
442 for ( mg = field->
mg; mg; mg = mg->
next )
443 for ( part = mg->
part; part; part = part->
next ) {
444 if ( part->
sel > 0 ) {
445 if ( numsel[part->
sel-1] ) part->
sel = 0;
454 cout <<
"Particles selected: " << nsel << endl << endl;
470 if ( fom_index < 0 ) fom_index = 0;
471 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
481 for ( part = rec->
part; part; part = part->
next ) {
482 if ( part->
fom[fom_index] < fommin || part->
fom[fom_index] > fommax )
484 if ( part->
sel ) nsel++;
488 for ( mg = field->
mg; mg; mg = mg->
next )
489 for ( part = mg->
part; part; part = part->
next ) {
490 if ( part->
fom[fom_index] < fommin || part->
fom[fom_index] > fommax )
492 if ( part->
sel ) nsel++;
497 cout <<
"FOM range: " << fommin <<
" - " << fommax << endl;
498 cout <<
"Particles selected: " << nsel << endl << endl;
508 if( (*part1)->fom[0] > (*part2)->fom[0] )
return -1;
522 if ( fom_index < 0 ) fom_index = 0;
523 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
525 long i, j, npart(0), nsel(0);
530 qsort((
void *) parr, npart,
sizeof(
Bparticle*),
533 for ( i=0; i<npart; i++ ) {
534 for ( j=i+1; j<npart; j++ )
if ( parr[j]->sel ) {
535 if ( parr[i]->loc.distance(parr[j]->loc) < excl_dist )
538 if ( parr[i]->sel ) nsel++;
554 if ( fom_index < 0 ) fom_index = 0;
555 if ( fom_index >=
NFOM ) fom_index =
NFOM - 1;
567 for ( mg = field->
mg; mg; mg = mg->
next )
572 cout <<
"Exclusion distance: " << excl_dist << endl;
573 cout <<
"Particles selected: " << nsel << endl << endl;
599 if ( nmaps < 1 ) nmaps = 1;
603 for ( part = rec->
part; part; part = part->
next ) {
605 if ( part->
sel > 0 ) part->
sel = i;
613 if ( i > nmaps ) i = 1;
618 for ( mg = field->
mg; mg; mg = mg->
next )
619 for ( part = mg->
part; part; part = part->
next ) {
621 if ( part->
sel > 0 ) part->
sel = i;
629 if ( i > nmaps ) i = 1;
635 cout <<
"Particles selected: " << nsel << endl << endl;
656 for ( part = rec->
part; part; part = part->
next ) {
657 if ( part->
sel > 0 ) {
658 if ( part->
group != prev_group ) {
660 prev_group = part->
group;
669 for ( mg = field->
mg; mg; mg = mg->
next ) {
670 for ( part = mg->
part; part; part = part->
next ) {
671 if ( part->
sel > 0 ) {
672 if ( part->
group != prev_group ) {
674 prev_group = part->
group;
685 cout <<
"Maps selected: " << nsel << endl << endl;
692 int float_flag(1), idata(0);
696 fdata = reselect_min - 1;
730 if ( idata < reselect_min || idata > reselect_max ) part->
sel = 0;
732 if ( fdata < reselect_min || fdata > reselect_max ) part->
sel = 0;
751 long npart(0), nmg(0), nrec(0), npsel(0), nmsel(0), nrsel(0);
752 double fdata, mpct(0), rpct(0), ppct(0);
758 if ( tag[0] ==
'_' ) tag = tag.
erase(0);
761 cout <<
"Reselecting on tag: " << tag << endl;
762 cout <<
"Range: " << reselect_min <<
" - " << reselect_max << endl;
767 for ( mg = field->
mg; mg; mg = mg->
next ) {
768 fdata = reselect_min - 1;
773 if ( fdata < reselect_min || fdata > reselect_max ) mg->
select = 0;
776 for ( part = mg->
part; part; part = part->
next )
778 if ( mg->
select ) nmsel++;
779 else for ( part = mg->
part; part; part = part->
next ) part->
sel = 0;
780 for ( part = mg->
part; part; part = part->
next, npart++ )
if ( part->
sel ) npsel++;
786 fdata = reselect_min - 1;
791 if ( fdata < reselect_min || fdata > reselect_max ) rec->
select = 0;
794 for ( part = rec->
part; part; part = part->
next )
796 if ( rec->
select ) nrsel++;
797 else for ( part = rec->
part; part; part = part->
next ) part->
sel = 0;
798 for ( part = rec->
part; part; part = part->
next, npart++ )
if ( part->
sel ) npsel++;
803 if ( npart ) ppct = npsel*100.0/npart;
804 if ( nmg ) mpct = nmsel*100.0/nmg;
805 if ( nrec ) rpct = nrsel*100.0/nrec;
809 cout <<
"Micrographs reselected: " << nmsel <<
" (" << mpct <<
" %)" << endl;
811 cout <<
"Reconstructions reselected: " << nrsel <<
" (" << rpct <<
" %)" << endl;
812 cout <<
"Particles reselected: " << npsel <<
" (" << ppct <<
" %)" << endl << endl;
830 int i, max(0), nsel(0);
831 double angle, min_angle, avg_angle(0);
842 for ( i=0; i<180; i++ ) hist[i] = 0;
845 for ( i=0; i<sym->
n; i++ ) nsymviews *= sym->
op[i].
order;
848 cout <<
"Comparison of particles in micrograph series with " << angle_cutoff*180.0/
M_PI <<
" degrees cutoff" << endl;
857 for ( part=mg->
part, part0=mg0->
part; part; part=part->
next, part0=part0->
next ) {
863 for ( i=0; i<nsymviews; i++ ) {
864 angle = view_pred.
angle(symview[i]);
865 if ( min_angle > angle ) min_angle = angle;
867 if ( min_angle > angle_cutoff ) {
870 avg_angle += min_angle;
873 i = (int) (min_angle*180.0/
M_PI);
875 if ( max < i ) max = i;
880 for ( part=mg->
part, part0=mg0->
part; part; part=part->
next, part0=part0->
next )
883 if ( nsel ) avg_angle /= nsel;
886 cout <<
"Angular deviation histogram:\nAngle\tCount" << endl;
887 for ( i=0; i<max; i++ ) cout << i <<
tab << hist[i] << endl;
892 cout <<
"Average angle deviation: " << avg_angle*180/
M_PI << endl;
893 cout <<
"Particle sets selected: " << nsel << endl << endl;
909 for ( mg = field->
mg; mg; mg = mg->
next ) {
910 for ( part = mg->
part; part; part = part->
next ) {
912 if ( part->
sel > 0 ) nsel++;
919 for ( part = rec->
part; part; part = part->
next ) {
921 if ( part->
sel > 0 ) nsel++;
947 long i, n(0), npart(0), nsel(0);
950 cout <<
"Selecting " << ngroups <<
" particle groups based on FOM ranking:" << endl;
955 cerr <<
"Error: No particles found!" << endl;
962 int* sel =
new int[npart];
965 cout <<
"DEBUG part_select_FOM_groups: Writing the selection array:" << endl;
967 for ( i=0; i<nsel; i++ ) {
968 n = ngroups - (i*ngroups)/nsel;
971 for ( ; i<npart; i++ ) sel[rank[i].i] = 0;
997 if ( percentage < 0 ) percentage = 0;
998 if ( percentage > 100 ) percentage = 100;
1000 long npart(0), nsel(0), n;
1003 cout <<
"Selecting " << percentage <<
"% particles based on FOM[" << fom_index <<
"] ranking:" << endl;
1008 cerr <<
"Error: No particles found!" << endl;
1016 cout <<
"DEBUG part_select_percentage: npart=" << npart <<
" nsel=" << nsel << endl;
1019 long num_to_select = (long) (nsel*percentage/100.0);
1020 if ( num_to_select < 0 ) num_to_select = 0;
1021 if ( num_to_select >= npart ) num_to_select = npart - 1;
1023 int* sel =
new int[npart];
1026 cout <<
"DEBUG part_select_percentage: Writing the selection array:" << endl;
1028 for ( n=0; n<num_to_select; n++ ) sel[rank[n].i] = 1;
1029 for ( ; n<npart; n++ ) sel[rank[n].i] = 0;
1054 if ( number < 1 )
return 0;
1056 long npart(0), nsel(0), n;
1061 if ( number > nsel ) number = nsel;
1064 cout <<
"Selecting " << number <<
" particles based on FOM[" << fom_index <<
"] ranking:" << endl;
1069 cerr <<
"Error: No particles found!" << endl;
1074 cout <<
"DEBUG part_select_best: npart=" << npart <<
" nsel=" << nsel << endl;
1076 int* sel =
new int[npart];
1079 cout <<
"DEBUG part_select_best: Writing the selection array:" << endl;
1082 for ( n=0; n<number; n++ ) sel[rank[n].i] = 1;
1083 for ( ; n<npart; n++ ) sel[rank[n].i] = 0;
1111 double avg(0), std(0);
1119 cout <<
"Selecting particles based on the FOM average and standard deviation" << endl;
1123 for ( mg = field->
mg; mg; mg = mg->
next ) {
1124 for ( part = mg->
part; part; part = part->
next ) {
1125 avg += part->
fom[fom_index];
1126 std += part->
fom[fom_index]*part->
fom[fom_index];
1133 for ( part = rec->
part; part; part = part->
next ) {
1134 avg += part->
fom[fom_index];
1135 std += part->
fom[fom_index]*part->
fom[fom_index];
1142 if ( n > 1 ) std = sqrt(std/n - avg*avg);
1146 cout <<
"Average and standard deviation: " << avg <<
" " << std << endl << endl;
1175 if ( number >= nsel )
return nsel;
1180 int v = (number < nsel/2)? 1: 0;
1181 int* narr =
new int[nsel];
1182 for ( i=0; i<nsel; i++ ) narr[i] = 1-v;
1184 for ( i=0; i<number; i++ ) {
1185 while ( ( n = random()/d ) >= nsel ) ;
1186 while ( n < nsel && narr[n] == v ) n++;
1187 if ( n >= nsel ) n = nsel - 1;
1188 while ( n >= 0 && narr[n] == v ) n--;
1191 cerr <<
"Warning: A random selection has been missed!" << endl;
1202 cout <<
"Selecting " << number <<
" particles randomly" << endl;
1207 for ( mg = field->
mg; mg; mg = mg->
next ) {
1208 for ( part = mg->
part; part; part = part->
next )
if ( part->
sel ) {
1209 if ( narr[n] < 1 ) part->
sel = 0;
1210 if ( part->
sel ) nsel++;
1217 for ( part = rec->
part; part; part = part->
next )
if ( part->
sel ) {
1218 if ( narr[n] < 1 ) part->
sel = 0;
1219 if ( part->
sel ) nsel++;
1228 cout <<
"Particles selected: " << nsel << endl << endl;
1256 cout <<
"Selecting " << fraction*100 <<
"% of the particles randomly" << endl;
1260 for ( mg = field->
mg; mg; mg = mg->
next ) {
1261 for ( part = mg->
part; part; part = part->
next ) {
1262 if ( random() > cut ) part->
sel = 0;
1263 if ( part->
sel ) nsel++;
1269 for ( part = rec->
part; part; part = part->
next ) {
1270 if ( random() > cut ) part->
sel = 0;
1271 if ( part->
sel ) nsel++;
1277 cout <<
"Particles selected: " << nsel << endl << endl;
1296 long i, max(0), nsel(0);
1306 cout <<
"Picking groups randomly to select at least " << number <<
" particles" << endl;
1310 for ( mg = field->
mg; mg; mg = mg->
next )
1311 for ( part = mg->
part; part; part = part->
next )
1312 if ( max < part->group ) max = part->
group;
1315 for ( part = rec->
part; part; part = part->
next )
1316 if ( max < part->group ) max = part->
group;
1320 cout <<
"DEBUG part_select_random_group: max=" << max << endl;
1325 for ( i=0; i<max; i++ ) sel[i] = 0;
1329 for ( mg = field->
mg; mg; mg = mg->
next )
1330 for ( part = mg->
part; part; part = part->
next )
1334 for ( part = rec->
part; part; part = part->
next )
1338 while ( nsel < number ) {
1339 i = (long) (
irm * random());
1350 for ( mg = field->
mg; mg; mg = mg->
next )
1351 for ( part = mg->
part; part; part = part->
next ) {
1352 if ( sel[part->
group] <= 0 ) part->
sel = 0;
1353 if ( part->
sel ) nsel++;
1357 for ( part = rec->
part; part; part = part->
next ) {
1358 if ( sel[part->
group] <= 0 ) part->
sel = 0;
1359 if ( part->
sel ) nsel++;
1366 cout <<
"Particles selected: " << nsel << endl << endl;
1390 cout <<
"Selecting " << number <<
" from " << n <<
" particles randomly with replacement for bootstrapping" << endl;
1394 int* sel =
new int[n];
1395 for ( i=0; i<n; i++ ) sel[i] = 0;
1397 for ( i=0; i<number; i++ ) {
1399 while ( rn >= n ) rn = (long) (rnf*random());
1408 for ( mg = field->
mg; mg; mg = mg->
next ) {
1409 for ( part = mg->
part; part; part = part->
next ) {
1411 part->
sel = sel[i++];
1412 if ( part->
sel ) nsel++;
1421 cout <<
"Particles selected: " << nsel << endl << endl;
1443 double theta_step,
double phi_step,
int number)
1454 int* np =
new int[nview];
1455 int* nr =
new int[number];
1456 int* nrn =
new int[number];
1457 for ( i=0; i<nview; i++ ) np[i] = 0;
1458 for ( i=0; i<number; i++ ) nr[i] = nrn[i] = 0;
1467 for ( mg = field->
mg; mg; mg = mg->
next ) {
1468 for ( part = mg->
part; part; part = part->
next ) {
1469 if ( part->
sel > 0 ) {
1470 for ( j=0, dmin=10, view = viewlist; view; view = view->
next, j++ ) {
1485 for ( j=n0=0; j<nview; j++ )
if ( np[j] < 1 ) n0++;
1488 cout <<
"Selecting a maximum of " << number <<
" particles from each view:" << endl;
1489 cout <<
"Symmetry: " << sym->
label << endl;
1490 cout <<
"Number of views: " << nview << endl;
1491 cout <<
"View coverage: " << 100*(1 - n0*1.0/nview) <<
" %" << endl;
1495 for ( j=0; j<nview; j++ )
if ( np[j] ) {
1496 for ( k=0; k<number; k++ ) {
1497 nr[k] = (int) (random()*rnf*np[j]);
1499 for ( i=0; i<k; i++ )
if ( nr[i] == nr[k] ) nrn[i]++;
1502 cout <<
"DEBUG part_select_random_within_view: " << j+1 <<
"(" << np[j] <<
") ";
1503 for ( k=0; k<number; k++ ) cout << nr[k] <<
"(" << nrn[k] <<
") ";
1507 for ( mg = field->
mg; mg; mg = mg->
next ) {
1508 for ( part = mg->
part; part; part = part->
next ) {
1509 if ( part->
sel == -(j+1) ) {
1510 for ( k=0; k<number && nr[k] != i; k++ ) ;
1511 if ( k >= number ) part->
sel = 0;
1512 else part->
sel = nrn[k];
1527 cout <<
"Particles selected: " << nsel << endl << endl;
1547 double theta_step,
double phi_step,
double threshfrac,
double sigma,
int fom_index)
1553 double isig2(-0.5/(sigma*sigma)), d, dmin, f;
1555 long* np =
new long[nview];
1556 double* fommax =
new double[nview];
1557 for ( i=0; i<nview; i++ ) fommax[i] = np[i] = 0;
1562 View *view, *view2, symview;
1566 for ( mg = field->
mg; mg; mg = mg->
next ) {
1567 for ( part = mg->
part; part; part = part->
next ) {
1568 if ( part->
sel > 0 ) {
1569 for ( j=0, dmin=10, view = viewlist; view; view = view->
next, j++ ) {
1577 if ( fommax[part->
sel-1] < part->
fom[fom_index] )
1578 fommax[part->
sel-1] = part->
fom[fom_index];
1584 for ( i=n0=0; i<nview; i++ )
if ( np[i] < 1 ) n0++;
1587 cout <<
"Selecting based on smoothed maxima surface:" << endl;
1588 cout <<
"Symmetry: " << sym->
label << endl;
1589 cout <<
"Number of views: " << nview << endl;
1590 cout <<
"View coverage: " << 100*(1 - n0*1.0/nview) <<
" %" << endl;
1591 cout <<
"Threshold fraction: " << threshfrac << endl;
1592 cout <<
"Smoothing sigma: " << sigma*180.0/
M_PI <<
" degrees" << endl << endl;
1596 cout <<
"Maxima:" << endl <<
"#\tViewX\tViewY\tCount\tFOMmax" << endl;
1597 for ( i=0, view = viewlist; view; view = view->
next, i++ )
1598 cout << i+1 <<
tab << view->
x() <<
tab << view->
y() <<
tab << np[i] <<
tab << fommax[i] << endl;
1602 for ( i=0, view = viewlist; view; view = view->
next, i++ ) {
1603 for ( j=0, view2 = viewlist; view2; view2 = view2->
next, j++ )
1606 d = view->
angle(symview);
1608 if ( fommax[i] > fommax[j] ) {
1610 if ( fommax[j] < f ) fommax[j] = f;
1613 if ( fommax[i] < f ) fommax[i] = f;
1619 cout <<
"Smoothed maxima:" << endl <<
"#\tViewX\tViewY\tCount\tFOMmax" << endl;
1620 for ( i=0, view = viewlist; view; view = view->
next, i++ )
1621 cout << i+1 <<
tab << view->
x() <<
tab << view->
y() <<
tab << np[i] <<
tab << fommax[i] << endl;
1627 for ( i=0; i<nview; i++ ) fommax[i] *= threshfrac;
1631 for ( mg = field->
mg; mg; mg = mg->
next )
1632 for ( part = mg->
part; part; part = part->
next )
1633 if ( part->
sel > 0 )
1634 if ( part->
fom[fom_index] < fommax[part->
sel-1] )
1640 cout <<
"Particles selected: " << nsel << endl << endl;
1660 double theta_step,
double phi_step,
int number,
int fom_index)
1665 long j, k, n, n0, imin;
1666 double d, dmin, fommin;
1668 int* np =
new int[nview];
1670 for ( j=0; j<nview; j++ ) np[j] = 0;
1679 for ( mg = field->
mg; mg; mg = mg->
next ) {
1680 for ( part = mg->
part; part; part = part->
next ) {
1681 if ( part->
sel > 0 ) {
1682 for ( j=0, dmin=10, view = viewlist; view; view = view->
next, j++ ) {
1697 for ( j=n0=0; j<nview; j++ )
if ( np[j] < 1 ) n0++;
1700 cout <<
"Selecting a maximum of " << number <<
" best particles from each view:" << endl;
1701 cout <<
"Symmetry: " << sym->
label << endl;
1702 cout <<
"Number of views: " << nview << endl;
1703 cout <<
"View coverage: " << 100*(1 - n0*1.0/nview) <<
" %" << endl;
1707 for ( j=0; j<nview; j++ )
if ( np[j] ) {
1708 for ( k=n=0; k<number; k++ ) bestpart[k] = NULL;
1710 for ( mg = field->
mg; mg; mg = mg->
next ) {
1711 for ( part = mg->
part; part; part = part->
next ) {
1712 if ( part->
sel == j+1 ) {
1713 if ( n < number ) bestpart[n++] = part;
1715 for ( k=0, imin=0, fommin=1e30; k<number; k++ ) {
1716 if ( fommin > bestpart[k]->fom[fom_index] ) {
1717 fommin = bestpart[k]->
fom[fom_index];
1721 if ( part->
fom[fom_index] > fommin ) {
1722 bestpart[imin]->
sel = 0;
1723 bestpart[imin] = part;
1724 }
else part->
sel = 0;
1738 cout <<
"Particles selected: " << nsel << endl << endl;
1760 cout <<
"Transferring selections to groups:" << endl;
1764 for ( part = rec->
part; part; part = part->
next ) {
1766 if ( part->
sel ) ++nsel;
1771 for ( mg = field->
mg; mg; mg = mg->
next ) {
1772 for ( part = mg->
part; part; part = part->
next ) {
1774 if ( part->
sel ) ++nsel;
1781 cout <<
"Particles selected: " << nsel << endl << endl;
1804 cout <<
"Selecting particles of group " << group << endl;
1808 for ( part = rec->
part; part; part = part->
next )
if ( part->
sel ) {
1809 if ( part->
group == group ) part->
sel = ++nsel;
1815 for ( mg = field->
mg; mg; mg = mg->
next ) {
1816 for ( part = mg->
part; part; part = part->
next )
if ( part->
sel ) {
1817 if ( part->
group == group ) part->
sel = ++nsel;
1825 cout <<
"Particles selected: " << nsel << endl << endl;
1843 if ( !
project || size <= 0 )
return 0;
1845 long nsel(0), count(0), np, number(0), ntot(0);
1853 cout <<
"Generating sets of " << size <<
" particles each" << endl;
1857 for ( mg = field->
mg; mg; mg = mg->
next ) mg->
select = 0;
1859 if ( flag && count ) {
1863 for ( np=0, part = rec->
part; part; part = part->
next, ntot++ ) {
1865 if ( count >= size ) {
1869 if ( number < 1 ) number = 1;
1876 if ( np < 1 ) rec->
select = 0;
1881 for ( mg = field->
mg; mg; mg = mg->
next ) {
1882 if ( flag && count ) {
1886 for ( np=0, part = mg->
part; part; part = part->
next, ntot++ ) {
1888 if ( count >= size ) {
1892 if ( number < 1 ) number = 1;
1899 if ( np < 1 ) mg->
select = 0;
1905 if ( ntot < 1 ) ntot = 1;
1906 cout <<
"Number of sets generated: " << number << endl;
1907 cout <<
"Number of particles selected: " << nsel <<
" (" << nsel*100.0/ntot <<
" %)" << endl << endl;
1933 cout <<
"Selecting particle series." << endl;
1936 for ( n=1, mg = field->
mg; mg; mg = mg->
next, n++ ) {
1938 if ( n >= frame_start && n <= frame_end ) sel = 1;
1939 for ( part = mg->
part; part; part = part->
next ) {
1940 if ( !sel ) part->
sel = 0;
1941 if ( part->
sel ) nsel++;
1953 int i, group(-1), n[2], dir(0);
1960 for ( part = partlist; part; part = part->
next ) {
1962 if ( part->
group != group ) {
1968 group = part->
group;
1970 da = view.
angle(pview);
1975 cout << group <<
tab << part->
id <<
tab << da <<
tab << 1-2*dir << endl;
1980 cout << group <<
tab << part->
id <<
tab << da <<
tab << 1-2*dir << endl;
1983 for ( i=0; i<2; i++ )
if ( n[i] ) a[i] = sqrt(a[i]/n[i]);
1986 a[0]*180.0/
M_PI <<
tab << a[1]*180.0/
M_PI << endl;
1988 if ( n[1] > n[0] ) { pview.
negate(); pview[3] = -pview.
angle(); }
1989 for ( fil_part = fil_start; fil_part && fil_part->
group == group; fil_part = fil_part->
next ) {
1991 da = view.
angle(pview);
2008 if ( minpct < 1 ) minpct *= 100;
2010 long n(0), up(0), dn(0), nt(0);
2011 int group(-1), fin(0), dir;
2012 double tol(20*
M_PI/180), pup, pdn;
2018 cout <<
"Fil#\t#part\tup\t%up\tdown\t%down\toutliers" << endl;
2020 for ( part = partlist; part; part = part->
next ) {
2023 if ( part->
group != group ) {
2024 n = up = dn = fin = 0;
2026 group = part->
group;
2035 if ( part->
next->
group != group ) fin = 1;
2046 cout << group <<
tab << n <<
tab << up <<
tab << pup <<
tab << dn <<
tab << pdn <<
tab << n-up-dn << endl;
2048 if ( pup >= minpct ) {
2050 }
else if ( pdn >= minpct ) {
2056 for ( ; fil_part && fil_part->
group == group; fil_part = fil_part->
next )
if ( fil_part->
sel > 0 ) {
2084 if ( minpct < 1 ) minpct *= 100;
2086 long npart(0), ndir(0);
2093 cout <<
"Checking filament directions:" << endl;
2094 cout <<
"Minimum percentage directed particles: " << minpct << endl << endl;
2101 cout <<
"Reconstruction: " << rec->
id << endl;
2107 for ( mg = field->
mg; mg; mg = mg->
next ) {
2109 cout <<
"Micrograph: " << mg->
id << endl;
2115 cout << endl <<
"Particles with direction: " << ndir <<
" (" << ndir*100.0/npart <<
"%)" << endl << endl;
2140 cout <<
"Selecting particles based on a view" << endl;
2142 cout <<
"View: " << view << endl;
2143 cout <<
"Deviation angle: " << angle*180/
M_PI <<
" degrees" << endl;
2148 for ( mg = field->
mg; mg; mg = mg->
next ) {
2149 for ( part = mg->
part; part; part = part->
next ) {
2151 if ( da > angle ) part->
sel = 0;
2152 if ( part->
sel ) nsel++;
2158 for ( part = rec->
part; part; part = part->
next ) {
2160 if ( da > angle ) part->
sel = 0;
2161 if ( part->
sel ) nsel++;
2167 cout <<
"Particles selected: " << nsel << endl << endl;
2184 double dz(sin(angle));
2191 cout <<
"Selecting particles with side views" << endl;
2193 cout <<
"Deviation angle: " << angle*180/
M_PI <<
" degrees" << endl;
2198 for ( mg = field->
mg; mg; mg = mg->
next ) {
2199 for ( part = mg->
part; part; part = part->
next ) {
2200 if ( part->
view[2] > dz ) part->
sel = 0;
2201 if ( part->
sel ) nsel++;
2207 for ( part = rec->
part; part; part = part->
next ) {
2208 if ( part->
view[2] > dz ) part->
sel = 0;
2209 if ( part->
sel ) nsel++;
2215 cout <<
"Particles selected: " << nsel << endl << endl;
2240 cout <<
"Selecting particles based on Euler angle limits" << endl;
2242 cout <<
"Psi limits: " << euler6[0]*180/
M_PI <<
" - " << euler6[1]*180/
M_PI <<
" degrees" << endl;
2243 cout <<
"Theta limits: " << euler6[2]*180/
M_PI <<
" - " << euler6[3]*180/
M_PI <<
" degrees" << endl;
2244 cout <<
"Phi limits: " << euler6[4]*180/
M_PI <<
" - " << euler6[5]*180/
M_PI <<
" degrees" << endl;
2249 for ( mg = field->
mg; mg; mg = mg->
next ) {
2250 for ( part = mg->
part; part; part = part->
next )
if ( part->
sel ) {
2252 for ( i=0; i<3; i++ ) {
2253 if ( euler[i] < euler6[2*i] ) euler[i] +=
TWOPI;
2254 if ( euler[i] > euler6[2*i+1] ) euler[i] -=
TWOPI;
2255 if ( euler[i] < euler6[2*i] || euler[i] > euler6[2*i+1] ) part->
sel = 0;
2257 if ( part->
sel ) nsel++;
2263 for ( part = rec->
part; part; part = part->
next )
if ( part->
sel ) {
2265 for ( i=0; i<3; i++ ) {
2266 if ( euler[i] < euler6[2*i] ) euler[i] +=
TWOPI;
2267 if ( euler[i] > euler6[2*i+1] ) euler[i] -=
TWOPI;
2268 if ( euler[i] < euler6[2*i] || euler[i] > euler6[2*i+1] ) part->
sel = 0;
2270 if ( part->
sel ) nsel++;
2276 cout <<
"Particles selected: " << nsel << endl << endl;
2301 cout <<
"Selecting particles based on the origin" << endl;
2303 cout <<
"Origin: " << origin << endl;
2304 cout <<
"Maximum distance: " <<
distance <<
" pixels" << endl;
2309 for ( mg = field->
mg; mg; mg = mg->
next ) {
2310 for ( part = mg->
part; part; part = part->
next ) {
2313 if ( part->
sel ) nsel++;
2319 for ( part = rec->
part; part; part = part->
next ) {
2322 if ( part->
sel ) nsel++;
2328 cout <<
"Particles selected: " << nsel << endl << endl;
2351 cout <<
"Setting all to the first orientations in the first micrograph in the field-of-view" << endl;
2354 for ( mg0=field->
mg, mg=field->
mg->
next; mg; mg=mg->
next ) {
2355 for ( part=mg->
part, part0=mg0->
part; part; part=part->
next, part0=part0->
next ) {
2356 for ( f=0; f<
NFOM; f++ ) part->
fom[f] = part0->
fom[f];
2385 cout <<
"Setting all to the best orientations in the field-of-view" << endl;
2388 for ( mg0=field->
mg, mg=field->
mg->
next; mg; mg=mg->
next ) {
2389 for ( part=mg->
part, part0=mg0->
part; part; part=part->
next, part0=part0->
next ) {
2390 if ( part->
fom[fom_index] > part0->
fom[fom_index] ) {
2391 for ( f=0; f<
NFOM; f++ ) part0->
fom[f] = part->
fom[f];
2397 for ( mg0=field->
mg, mg=field->
mg->
next; mg; mg=mg->
next ) {
2398 for ( part=mg->
part, part0=mg0->
part; part; part=part->
next, part0=part0->
next ) {
2399 for ( f=0; f<
NFOM; f++ ) part->
fom[f] = part0->
fom[f];
2423 if ( size < 1 ) size = 1000000000;
2426 long count(0), nser(0), nsel(0);
2432 cout <<
"Selecting particle series." << endl;
2435 if ( flag ) nser = 0;
2436 for ( n=0, mg0=field->
mg, mg = field->
mg; mg; mg = mg->
next, n++ ) {
2437 for ( part0=mg0->
part, part = mg->
part; part; part = part->
next, part0=part0->
next ) {
2439 if ( mg0 == mg ) part0->
sel = 1;
2444 for ( part0=field->
mg->
part; part0; part0=part0->
next ) {
2445 if ( part0->
sel == n ) {
2446 if ( nser%size == 0 ) count++;
2453 for ( mg0=field->
mg, mg = field->
mg; mg; mg = mg->
next ) {
2454 for ( part0=mg0->
part, part = mg->
part; part; part = part->
next, part0=part0->
next ) {
2482 int zflip(flags & 1), use_view(flags & 2);
2483 long i, n, npart(0);
2499 cout <<
"Calculating micrograph particle locations from 3D locations" << endl;
2501 if ( rec->
part )
break;
2503 part_list = rec->
part;
2505 scale /= rec->
scale;
2510 cout <<
"Calculating micrograph particle locations from zero-tilt micrograph" << endl;
2512 for ( mg = field->
mg; mg && !part_list; mg = mg->
next )
if ( mg->
part ) {
2514 part_list = mg->
part;
2522 cerr <<
"Error: No particle records found!" << endl;
2527 part_ori = part_size/2;
2530 for ( n=0, part_ref=part_list; part_ref; part_ref=part_ref->
next )
2531 part_ref->
sel = ++n;
2533 double ca(1), sa(0), tt(0);
2537 cout <<
"Number of particles: " << n << endl;
2539 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg != mg_ref ) {
2541 mg->
part = part = NULL;
2546 for ( part_ref=part_list; part_ref; part_ref=part_ref->
next ) {
2549 loc = (part_ref->
loc - origin)*scale;
2550 if ( zflip ) loc[2] = -loc[2];
2552 part->
ori = part_ori;
2556 for ( i=0; i<
NFOM; i++ ) part->
fom[i] = part_ref->
fom[i];
2557 part->
sel = part_ref->
sel;
2561 (loc[0]*sa - loc[1]*ca)*tt;
2595 double* x =
new double[nmg];
2596 double* y =
new double[nmg];
2597 for ( i=0; i<nmg; i++ ) x[i] = y[i] = 0;
2600 cout <<
"Defocus\tFOMavg" << endl;
2602 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg->
ctf ) {
2603 for ( npart=0, sum=0, part = mg->
part; part; part = part->
next )
2605 sum += part->
fom[fom_index];
2612 cout << x[i] <<
tab << y[i] << endl;
2625 cout <<
"Linear fit: FOM = " << slope <<
" * defocus + " << intercept << endl;
2626 cout <<
"Correlation index: " << CI << endl << endl;
2650 double slope, intercept, this_cutoff;
2654 for ( mg = field->
mg; mg; mg = mg->
next ) {
2657 for ( part = mg->
part; part; part = part->
next )
2658 if ( part->
fom[fom_index] < this_cutoff) part->
sel = 0;
2681 for ( mg = field->
mg; mg; mg = mg->
next ) {
2683 for ( part = mg->
part; part; part = part->
next )
2686 for ( part = mg->
part; part; part = part->
next )
2687 if ( part->
sel ) nsel++;
2711 for ( mg = field->
mg; mg; mg = mg->
next ) {
2713 for ( part = mg->
part; part; part = part->
next )
2716 for ( part = mg->
part; part; part = part->
next )
2717 if ( part->
sel ) nsel++;
2739 for (
id=0, part_list = NULL, part = rec->
part; part; part = part->
next ) {
2746 rec->
part = part_list;
2751 for ( mg = field->
mg; mg; mg = mg->
next ) {
2752 for (
id=0, part_list = NULL, part = mg->
part; part; part = part->
next ) {
2759 mg->
part = part_list;
2766 cout <<
"Particles selected: " << nsel << endl << endl;
2784 for ( nulist = NULL, part = *partlist; part; part = part->
next ) {
2813 cout <<
"Resetting particle defocus:" << endl;
2814 cout <<
"Maximum difference allowed: " << max_dev <<
" A" << endl;
2818 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg->
ctf ) {
2821 for ( part = mg->
part; part; part = part->
next ) {
2822 if ( part->
def < dmin || part->
def > dmax ) {
2831 cout <<
"Number of defocus values reset: " << nd << endl << endl;
2848 vector<std::pair<Bparticle*,double>> part_value;
2849 pair<Bparticle*,double> pv;
2852 for ( mg = field->
mg; mg; mg = mg->
next ) {
2853 for ( part = mg->
part; part; part = part->
next ) {
2857 part_value.push_back(pv);
2862 sort(part_value.begin(), part_value.end(), [=](pair<Bparticle*,double> a, std::pair<Bparticle*,double> b) {
2863 return a.second < b.second;
Bparticle ** particle_array(Bparticle *partlist, int part_select, long &npart)
Sets up an array of selected particle pointers.
Bstring erase(const long i)
long part_set_FOM(Bproject *project, int fom_index, double fom)
Sets the FOM for all particles.
long part_select_FOM_avg_std(Bproject *project, double factor, int fom_index)
Selects particles based on FOM average and standard deviation.
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
long part_filament_direction(Bproject *project, double minpct)
Checks the direction of particles associated with filaments.
Header file for matrix functions.
double distance(const View &view)
long part_select_random_fraction(Bproject *project, double fraction)
Selects particles randomly based on a fraction of the total.
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
long part_fix_defocus(Bproject *project, double max_dev)
Resets defocus values for particles thata are too far off.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
long part_set_selection(Bproject *project, int number)
Selects one selection number and sets all others to zero.
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.
Header file for general symmetry functions.
long part_unset_selection(Bproject *project)
Unsets selection to no particles.
double astigmatism_angle()
Header file for functions for creating random images.
Header file for micrograph processing.
long part_select_frames(Bproject *project, int frame_start, int frame_end)
Select particles from frames in a series.
long part_deselect_redundant(Bparticle *partlist, double excl_dist, int part_select, int fom_index)
Deselects particles overlapping with better ones.
long part_select_series(Bproject *project, int size, int flag)
Select series where all are already selected.
long part_select_closest_to_focus(Bproject *project)
Deselects all particles except those from micrographs closest to focus.
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.
long part_set_multi_maps(Bproject *project, int part_select, int nmaps)
Sets selection for generating multiple maps.
long part_select_sets(Bproject *project, int size, int flag)
Selects sets of particles, each set with the same size.
long count_list(char *list)
Counts the number of items in a linked list.
long project_maximum_selection(Bproject *project)
Finds the maximum selection number for a project.
long part_consolidate_selection(Bproject *project, int number)
Consolidates selected particles under one selection number.
long part_select_bootstrap(Bproject *project, int number)
Selects a given number of particles randomly with replacement.
double distance(const Vector3 &v)
long part_select_micrograph(Bproject *project, Bstring &mgselect)
Sets selection to the micrographs indicated.
long part_select_random(Bproject *project, long number)
Selects a specific number of particles randomly.
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.
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.
long part_delete_deselected(Bproject *project)
Deletes deselected particles and renumber the remaining.
long part_series_from_seed(Bproject *project, int flags)
Calculates the locations of particles in a series from a seed.
long part_select_to_group(Bproject *project)
Transfer selection numbers to the group identifiers.
long part_view_select(Bproject *project, View view, double angle)
Selects particles based on a distance from a reference view.
long part_convert_selection(Bproject *project, int *sel)
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.
long project_count_mg_part_selected(Bproject *project)
Counts the number of particles in a project.
long part_set_first_view_in_series(Bproject *project)
Sets all orientation parameters for a particle to the first in the set.
long part_reset_selection(Bproject *project, int flag)
Resets selection to all particles.
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.
long part_deselect(Bproject *project, int fom_index, double fommin, double fommax)
Deselects particles below a given FOM cutoff.
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
double distance(vector< T1 > &v1, vector< T2 > &v2)
long part_fil_dir_stats(Bparticle *partlist)
long part_side_view_select(Bproject *project, double angle)
Selects particles based on a distance from a side view.
double defocus_deviation()
int QsortLargeToSmallParticle(const void *x, const void *y)
int_float * project_fom_order(Bproject *project, long &npart, int fom_index, int defocus_fit)
long part_origin_select(Bproject *project, Vector3< double > origin, double distance)
Selects particles based on the distance from the nominal origin.
Header file for general utilities.
vector< pair< Bparticle *, double > > project_part_sort(Bproject *project, Bstring tag)
Sorts the Particles by a selected parameter.
ostream & tab(ostream &out)
long part_select_furthest_from_focus(Bproject *project)
Deselects all particles except those from micrographs furthest from focus.
double part_fom_defocus_fit_deselect(Bproject *project, int fom_index, double cutoff)
Deselects particles below a given FOM cutoff, adjusted for the defocus.
View find_closest_symmetric_view(Bsymmetry *sym, View view_ref, View view)
Finds the closest symmetric match between two views.
long part_set_filament_maps(Bproject *project)
Generates a selection number from the group number for each filament.
long part_set_sequential(Bproject *project)
Selects one selection number and sets all others to zero.
int mg_ctf(Bmicrograph *mg, Bimage *pmg, int action, double lores, double hires, double wiener, Vector3< long > tile_size, DataType datatype, Bstring &newname, int flags)
long random_seed()
Gets a random seed and sets the flag.
long part_invert_selection(Bproject *project)
Inverts the selection.
int part_reselect(Bparticle *part, Bstring &tag, double reselect_min, double reselect_max)
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
long project_count_rec_part_selected(Bproject *project)
Counts all the particles in the project structure.
Generalized matrix class.
Header file for micrograph processing.
Header file for generalized linked list functions.
double part_fom_defocus_fit(Bproject *project, int fom_index, double &intercept, double &slope)
Fits the particle FOMs as a function of the defocus.
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
long part_select_random_group(Bproject *project, long number)
Selects groups randomly to give at least a number of particles.
Vector3< double > pixel_size
double irm(1.0L/get_rand_max())
int QsortLargeToSmallIntFloat(const void *x, const void *y)
Utility function for sorting int float pairs in qsort.
long part_euler_angle_select(Bproject *project, double *euler6)
Selects particles based on Euler angle limits.
long get_rand_max()
Finds the maximum random number for a system.
long part_select_best(Bproject *project, long number, int fom_index, int defocus_fit)
Selects the best particles based on the FOM.
bool contains(const Bstring &s)
int particle_kill(Bparticle *part)
Frees a list of particles.
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
long part_select_group(Bproject *project, int group)
Selects particles with a given group identifier.
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.
int_float * part_fom_order(Bparticle *partlist, long &npart, int fom_index)
long part_select_percentage(Bproject *project, double percentage, int fom_index, int defocus_fit)
Selects a percentage of particles based on the FOM.
int select_numbers(Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
long part_deselect_from_list(Bproject *project, Bstring list)
Deselects particles with selection numbers from a list.
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.
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Header file for single particle image processing in Bsoft.
long part_select_FOM_groups(Bproject *project, int ngroups, int fom_index, int defocus_fit)
Selects groups of particles based on the FOM.
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.