30 double res_lo,
double res_hi,
double res_polar,
int ann_min,
int ann_max,
31 double shift_limit,
double angle_limit,
double edge_radius,
int flags,
38 double ccc = cc, ccd = 1;
39 double fac = sqrt(2.0)*std;
41 for ( i=0; i<100 && fabs(ccd) > 1e-10; i++ ) {
42 ccd = cc - ccc*ccc*ccc - fac*ccc*(1-ccc);
66 long number,
int bin,
int ctf_action,
double wiener)
68 if ( bin < 1 ) bin = 1;
69 if ( bin > 4 ) bin = 4;
80 if ( pixel_size[0] < 0.01 ) pixel_size = p->
sampling(0);
81 if ( pixel_size[0] < 0.01 ) pixel_size = mg->
pixel_size;
90 cout <<
"Preparing particle images as references: " << endl;
91 cout <<
"Size: " << pref->
size() << endl;
92 cout <<
"Pixel size: " << pixel_size << endl;
93 cout <<
"Number: " << number << endl;
94 cout <<
"Binning: " << bin << endl;
99 for ( field =
project->
field; field && npart < number; field = field->next ) {
100 for ( mg = field->
mg; mg && npart < number; mg = mg->next ) {
101 for ( part = mg->
part; part && npart < number; part = part->next, ++i )
106 error_show(
"project_prepare_2D_references", __FILE__, __LINE__);
111 if ( ctf_action && mg->
ctf )
127 if ( bin > 1 ) pref->bin(bin);
158 double theta_step,
double phi_step,
double side_ang)
162 cerr <<
"Error: The theta step size is too small! (" << theta_step*180.0/
M_PI <<
")" << endl;
164 cerr <<
"Error: The phi step size is too small! (" << phi_step*180.0/
M_PI <<
")" << endl;
170 if ( pref == NULL ) {
171 error_show(
"Error in img_prepare_projections", __FILE__, __LINE__);
179 if ( bin < 1 ) bin = 1;
180 if ( bin > 4 ) bin = 4;
181 if ( bin > 1 ) pref->bin(bin);
185 for ( i=0; i<pref->
images(); i++ ) {
187 if ( fabs(origin[0] - pref->
sizeX()/2) > pref->
sizeX()/10 )
188 origin[0] = pref->
sizeX()/2;
189 if ( fabs(origin[1] - pref->
sizeY()/2) > pref->
sizeY()/10 )
190 origin[1] = pref->
sizeY()/2;
191 if ( fabs(origin[2] - pref->
sizeZ()/2) > pref->
sizeZ()/10 )
192 origin[2] = pref->
sizeZ()/2;
193 if ( pref->
sizeZ() < 2 ) origin[2] = 0;
198 cout <<
"Preparing projections for the full asymmetric unit: " << endl;
199 cout <<
"Reference: " << pref->
file_name() << endl;
200 if ( pref->
images() > 1 ) cout <<
" (" << pref->
images() <<
" projections)" << endl;
201 cout <<
"Reference origin: " << pref->
image->
origin() << endl;
202 cout <<
"Theta and phi steps: " << theta_step*180.0/
M_PI <<
" " << phi_step*180.0/
M_PI << endl;
204 cout <<
"Symmetry: " << sym->
label << endl;
206 cout <<
"Side views within: " << side_ang*180.0/
M_PI <<
" degrees" << endl;
207 if ( mask_file.
length() ) cout <<
"Mask file name: " << mask_file << endl;
214 time_t t = time(NULL);
220 if ( mask_file.
length() ) {
222 if ( bin > 1 ) pmask->bin(bin);
232 views =
side_views(sym, side_ang, theta_step, phi_step);
234 mem_req = pref->
size()[0]*pref->
size()[1]*
sizeof(float)*nviews;
236 cout <<
"Number of projections: " << nviews << endl;
237 cout <<
"Memory required: " << mem_req << endl;
238 cout <<
"Memory available: " << mem_avail << endl;
240 if ( mem_req > mem_avail ) {
241 cerr <<
"Not enough memory to run!" << endl;
249 cout <<
"Time to generate projections: " << (long)(time(NULL) - t) <<
" seconds" << endl << endl;
253 mem_req = proj->
size()[0]*proj->
size()[1]*proj->
images()*
sizeof(float);
255 cout <<
"Number of projections: " << proj->
images() << endl;
256 cout <<
"Memory required: " << mem_req << endl;
257 cout <<
"Memory available: " << mem_avail << endl;
259 if ( mem_req > mem_avail ) {
260 cerr <<
"Not enough memory to run!" << endl;
274 cout <<
"DEBUG img_read_projection: proj_file=" << proj_file <<
" proj_num=" << proj_num << endl;
283 proj =
read_img(proj_file, 1, proj_num);
286 error_show(
"Error in img_read_projection", __FILE__, __LINE__);
331 double res_lo,
double res_hi,
double res_polar,
int ann_min,
int ann_max,
332 double shift_limit,
double angle_limit,
double edge_radius,
int flags)
334 int mode = flags &
MODE;
335 int ctf_apply = (flags &
APPLY_CTF)? 1: 0;
336 int part_log = (flags &
PART_LOG)? 1: 0;
344 cerr <<
"Error in project_determine_orientations: No particles found!" << endl;
351 if ( bin < 1 ) bin = 1;
352 if ( bin > 4 ) bin = 4;
358 long i, nproj(0), npix(0);
373 if ( res_lo < res_hi ) swap(res_hi, res_lo);
378 if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
379 if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
386 if ( ann_min > ann_max ) swap(ann_min, ann_max);
387 if ( ann_min < 0 ) ann_min = 0;
388 if ( ann_max > proj->
sizeX()/2 - 1 ) ann_max = proj->
sizeX()/2 - 1;
394 if ( shift_limit < 0 ) shift_limit = proj->
sizeX()/10;
399 if ( band.size() < 2 || band[0] < 1 )
409 if ( mask_file.
length() ) {
410 part_mask =
read_img(mask_file, 1, 0);
411 if ( bin > 1 ) part_mask->bin(bin);
418 cout <<
"Determining orientations:" << endl;
419 if ( mode == 0 ) cout <<
"Mode: PPS based followed by one CC (fast)" << endl;
420 if ( mode == 1 ) cout <<
"Mode: PPS followed by selected CC's" << endl;
421 if ( mode == 2 ) cout <<
"Mode: PPS followed by all CC's (slow)" << endl;
422 cout <<
"Projection file name: " << proj->
file_name() << endl;
423 cout <<
"Number of projections: " << nproj << endl;
424 cout <<
"Binning: " << bin << endl;
425 cout <<
"Pixel size: " << pixel_size << endl;
426 if ( prs_mask->
minimum() < 0 ) cout <<
"Reciprocal space mask file: " << prs_mask->
file_name() << endl;
428 cout <<
"Reciprocal space bands:" << endl;
429 for ( i=0; band[i+1]; i+=2 ) {
430 cout <<
tab << setw(5) << band[i] <<
" - " << setw(5) << band[i+2];
431 if ( band[i+1] > 0 ) cout <<
"\tcross-correlation" << endl;
432 else cout <<
"\tcross-validation" << endl;
435 if ( ctf_apply ) cout <<
"CTF applied to projections." << endl;
436 cout <<
"Resolution limits (low, high): " << res_lo <<
" - " << res_hi <<
" A" << endl;
437 if ( res_polar ) cout <<
"Polar resolution limit: " << res_polar <<
" A" << endl;
438 cout <<
"Annular range: " << ann_min <<
" - " << ann_max <<
" (max = " << proj->
sizeX()/2 - 1 <<
")" << endl;
439 cout <<
"Shift limit: " << shift_limit <<
" pixels" << endl;
441 cout <<
"Angle limit: " << angle_limit*180.0/
M_PI <<
" degrees" << endl;
442 if ( edge_radius ) cout <<
"Edge mask radius: " << edge_radius <<
" pixels" << endl;
443 if ( mask_file.
length() ) cout <<
"Real space mask file: " << mask_file << endl;
445 cout <<
"Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
450 mkdir(
"log", O_CREAT );
456 mkdir(
"ppx", O_CREAT );
460 time_t t = time(NULL);
463 dispatch_queue_t myq = dispatch_queue_create(NULL, NULL);
464 dispatch_apply(npart, dispatch_get_global_queue(0, 0), ^(
size_t i){
469 res_lo, res_hi, res_polar, ann_min, ann_max,
470 shift_limit, angle_limit, edge_radius, flags,
471 planf_1D, planb_1D, planf_2D, planb_2D);
472 dispatch_sync(myq, ^{
474 cout << setw(15) << mg->
id <<
tab << part->
id <<
tab << fixed <<
475 setprecision(2) << part->
ori[0] <<
tab << part->
ori[1] <<
tab <<
476 setprecision(4) << part->
view[0] <<
tab <<
479 setprecision(4) << part->
fom[0] <<
tab << part->
fom[1] <<
tab <<
480 (long)(time(NULL) - t) << endl << flush;
485 #pragma omp parallel for
486 for ( i=0; i<npart; i++ ) {
491 res_lo, res_hi, res_polar, ann_min, ann_max,
492 shift_limit, angle_limit, edge_radius, flags,
493 planf_1D, planb_1D, planf_2D, planb_2D);
497 cout << setw(15) << mg->
id <<
tab << part->
id <<
tab << fixed <<
498 setprecision(2) << part->
ori[0] <<
tab << part->
ori[1] <<
tab <<
499 setprecision(4) << part->
view[0] <<
tab <<
502 setprecision(4) << part->
fom[0] <<
tab << part->
fom[1] <<
tab <<
503 (long)(time(NULL) - t) << endl << flush;
510 cout <<
"DEBUG project_determine_orientations: done, npart=" << npart << endl;
512 t = (time(NULL) - t);
515 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
518 cout <<
"Time: " << ts <<
" s (" << hr <<
":" << min <<
":" << sec <<
")" << endl;
519 cout <<
"Time per particle: " << ts*1.0/npart <<
" s/particle" << endl;
520 cout <<
"Algorithm time: " << ts*1.0e6/(npart*nproj*npix) <<
" us/pixel" << endl << endl;
537 double res_lo,
double res_hi,
double res_polar,
int ann_min,
int ann_max,
538 double shift_limit,
double angle_limit,
double edge_radius,
int flags,
544 if (
ppx_check(part, fom_tag) )
return 0;
547 cout <<
"DEBUG part_determine_orientation: id=" << part->
id <<
" flags=" << flags << endl;
549 int mode = flags &
MODE;
550 int ctf_apply = (flags &
APPLY_CTF)? 1: 0;
551 int part_log = (flags &
PART_LOG)? 1: 0;
553 long k, imax(0), nproj(proj->
images());
554 double cc_best(-1e37), cc_min, cc_max, cc_avg, cc_std, cc_cut;
555 double* angle =
new double[nproj];
556 double* ox =
new double[nproj];
557 double* oy =
new double[nproj];
559 double* cc =
new double[nproj];
563 return error_show(
"part_determine_orientation", __FILE__, __LINE__);
568 long edge_size = (long) (2*edge_radius);
577 log_name =
"log/" + mg->
id +
"_" +
Bstring(part->
id,
"%04d") +
"_orient.log";
578 flog.open(log_name.
c_str());
580 return error_show(
"Log file cannot be written!", __FILE__, __LINE__);
581 flog << mg->
id <<
": " << part->
id << endl;
588 return error_show(
"part_determine_orientation", __FILE__, __LINE__);
592 if ( bin > 1 ) p->bin(bin);
605 pm = part_mask->
copy();
621 cout <<
"DEBUG part_determine_orientation: preprocessing done for image " << part->
id << endl;
623 flog <<
"PartID\tProjID\tox\toy\tvx\tvy\tvz\tva\tcc" << endl;
625 for ( k=0; k<nproj; k++ ) {
627 cout <<
"DEBUG part_determine_orientation: pps with proj " << k << endl;
630 return error_show(
"Error in part_determine_orientation", __FILE__, __LINE__);
633 if ( ctf_apply && mg->
ctf )
636 cc[k] = p->
align2D_pps(proj1, res_hi, res_lo, shift_limit, angle_limit, planf_2D, planb_2D);
642 if ( angle[k] < 0 ) {
650 flog << fixed << setprecision(4) <<
652 bin*ox[k] <<
tab << bin*oy[k] <<
tab << view[k][0] <<
tab << view[k][1] <<
tab <<
653 view[k][2] <<
tab << view[k].
angle()*180.0/
M_PI <<
tab << cc[k] << endl;
657 if ( cc_best < cc[k] ) {
665 cc_min = cc_max = cc[0];
666 for ( k=imax=0; k<nproj; k++ ) {
667 if ( cc_min > cc[k] ) cc_min = cc[k];
668 if ( cc_max < cc[k] ) {
673 cc_std += cc[k]*cc[k];
676 cc_std = cc_std/nproj - cc_avg*cc_avg;
677 if ( cc_std > 0 ) cc_std = sqrt(cc_std);
679 cc_cut = cc_avg + cc_std;
680 if ( cc_cut >= cc_max ) cc_cut = cc_max - 0.01;
681 if ( mode < 1 ) cc_cut = cc_max - 0.01;
682 else if ( mode > 1 ) cc_cut = cc_min - 1;
685 flog <<
"Particle, min, max, avg, std, max/avg:" <<
686 part->
id <<
tab << cc_min <<
tab << cc_max <<
tab <<
687 cc_avg <<
tab << cc_std <<
tab << cc_max/cc_avg << endl;
689 cout <<
"DEBUG part_determine_orientation: cc_avg=" << cc_avg <<
" cc_std=" << cc_std << endl;
690 cout <<
"DEBUG part_determine_orientation: cc_min=" << cc_min <<
" cc_max=" << cc_max << endl;
691 cout <<
"DEBUG part_determine_orientation: cc_cut=" << cc_cut << endl;
696 for ( k=0; k<nproj; k++ )
if ( cc[k] > cc_cut ) {
698 cout <<
"DEBUG part_determine_orientation: cc with proj " << k << endl;
701 return error_show(
"Error in part_determine_orientation", __FILE__, __LINE__);
703 if ( ctf_apply && mg->
ctf )
710 cc[k] = p->
align2D(proj1, res_polar, ann_min, ann_max,
711 prs_mask, shift_limit, angle_limit, planf_1D, planb_1D, planf_2D, planb_2D);
720 if ( angle[k] < 0 ) {
727 flog << fixed << setprecision(4) <<
729 bin*ox[k] <<
tab << bin*oy[k] <<
tab << view[k][0] <<
tab << view[k][1] <<
tab <<
730 view[k][2] <<
tab << view[k].
angle()*180.0/
M_PI <<
tab << cc[k] << endl;
734 if ( cc_best < cc[k] ) {
742 cout <<
"DEBUG part_determine_orientation: projection matching done for image " << part->
id << endl;
744 part->
view = view[imax];
745 part->
fom[0] = cc[imax];
746 if ( prs_mask->
minimum() < 0 ) {
749 return error_show(
"Error in part_determine_orientation", __FILE__, __LINE__);
751 if ( ctf_apply && mg->
ctf )
755 p->
origin(0, ox[imax], oy[imax], 0.0);
761 part->
sel = imax + 1;
763 flog <<
"Particle, min, max, avg, std, max/avg, cv:" <<
tab <<
764 part->
id <<
tab << cc_min <<
tab << cc_max <<
tab <<
765 cc_avg <<
tab << cc_std <<
tab << cc_max/cc_avg <<
tab << part->
fom[1] << endl;
766 flog << fixed << setprecision(4) <<
770 part->
fom[0] <<
tab << part->
fom[1] << endl;
791 double res_lo,
double res_hi,
double res_polar,
long ann_min,
long ann_max,
792 double shift_limit,
double angle_limit,
double edge_radius,
int flags,
799 cout <<
"DEBUG part_compare: proj " << k << endl;
803 error_show(
"Error in part_compare", __FILE__, __LINE__);
812 part.
fom[0] = pcopy->
align2D_pps(proj1, res_hi, res_lo, shift_limit, angle_limit, planf_2D, planb_2D);
815 part.
fom[0] = pcopy->
align2D(proj1, res_polar, ann_min, ann_max,
816 prs_mask, shift_limit, angle_limit, planf_1D, planb_1D, planf_2D, planb_2D);
839 double res_lo,
double res_hi,
double res_polar,
int ann_min,
int ann_max,
840 double shift_limit,
double angle_limit,
double edge_radius,
int flags,
846 if (
ppx_check(part, fom_tag) )
return 0;
849 cout <<
"DEBUG part_determine_orientation: id=" << part->
id <<
" flags=" << flags << endl;
851 int ctf_apply = (flags &
APPLY_CTF)? 1: 0;
852 int part_log = (flags &
PART_LOG)? 1: 0;
854 long k, imax(0), nproj(proj->
images());
858 return error_show(
"part_determine_orientation", __FILE__, __LINE__);
863 long edge_size = (long) (2*edge_radius);
872 log_name =
"log/" + mg->
id +
"_" +
Bstring(part->
id,
"%04d") +
"_orient.log";
873 flog.open(log_name.
c_str());
875 return error_show(
"Log file cannot be written!", __FILE__, __LINE__);
876 flog << mg->
id <<
": " << part->
id << endl;
883 return error_show(
"part_determine_orientation", __FILE__, __LINE__);
887 if ( bin > 1 ) p->bin(bin);
900 pm = part_mask->
copy();
919 cout <<
"DEBUG part_determine_orientation: preprocessing done for image " << part->
id << endl;
921 flog <<
"PartID\tProjID\tox\toy\tvx\tvy\tvz\tva\tcc" << endl;
924 dispatch_apply(nproj, dispatch_get_global_queue(0, 0), ^(
size_t k){
927 res_lo, res_hi, res_polar, ann_min, ann_max,
928 shift_limit, angle_limit, edge_radius, flags,
929 planf_1D, planb_1D, planf_2D, planb_2D);
932 #pragma omp parallel for
933 for ( k=0; k<nproj; ++k ) {
936 res_lo, res_hi, res_polar, ann_min, ann_max,
937 shift_limit, angle_limit, edge_radius, flags,
938 planf_1D, planb_1D, planf_2D, planb_2D);
942 double cc, cc_min(1), cc_avg(0), cc_std(0);
945 for ( k=0; k<nproj; ++k ) {
946 cc = partarr[k].
fom[0];
949 if ( part->
fom[0] < cc ) {
953 if ( cc_min > cc ) cc_min = cc;
957 cc_std -= cc_avg * cc_avg;
958 if ( cc_std > 0 ) cc_std = sqrt(cc_std);
962 cout <<
"DEBUG part_determine_orientation: projection matching done for image " << part->
id << endl;
963 part->
ori = partarr[imax].
ori;
966 if ( prs_mask->
minimum() < 0 ) {
969 return error_show(
"Error in part_determine_orientation", __FILE__, __LINE__);
971 if ( ctf_apply && mg->
ctf )
982 part->
sel = imax + 1;
985 flog <<
"Particle, min, max, avg, std, max/avg, cv:" <<
tab <<
987 cc_avg <<
tab << cc_std <<
tab << part->
fom[0]/cc_avg <<
tab << part->
fom[1] << endl;
988 flog << fixed << setprecision(4) <<
992 part->
fom[0] <<
tab << part->
fom[1] << endl;
1048 double res_lo,
double res_hi,
double res_polar,
int ann_min,
int ann_max,
1049 double shift_limit,
double angle_limit,
double edge_radius,
int flags)
1051 int mode = flags &
MODE;
1052 int ctf_apply = (flags &
APPLY_CTF)? 1: 0;
1053 int part_log = (flags &
PART_LOG)? 1: 0;
1061 cerr <<
"Error in project_determine_orientations: No particles found!" << endl;
1068 if ( bin < 1 ) bin = 1;
1069 if ( bin > 4 ) bin = 4;
1075 long i, nproj(0), npix(0);
1090 if ( res_lo < res_hi ) swap(res_hi, res_lo);
1091 if ( res_lo > proj->
sizeX()*pixel_size[0] )
1092 res_lo = proj->
sizeX()*pixel_size[0];
1093 if ( res_hi > proj->
sizeX()*pixel_size[0]/2 )
1094 res_hi = proj->
sizeX()*pixel_size[0]/2;
1095 if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
1096 if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
1103 if ( ann_min > ann_max ) swap(ann_min, ann_max);
1104 if ( ann_min < 0 ) ann_min = 0;
1105 if ( ann_max > proj->
sizeX()/2 - 1 ) ann_max = proj->
sizeX()/2 - 1;
1111 if ( shift_limit < 0 ) shift_limit = proj->
sizeX()/10;
1116 if ( band.size() < 2 || band[0] < 1 )
1125 Bimage* part_mask = NULL;
1126 if ( mask_file.
length() ) {
1127 part_mask =
read_img(mask_file, 1, 0);
1128 if ( bin > 1 ) part_mask->bin(bin);
1135 cout <<
"Determining orientations:" << endl;
1136 if ( mode == 0 ) cout <<
"Mode: PPS based followed by one CC (fast)" << endl;
1137 if ( mode == 1 ) cout <<
"Mode: PPS followed by selected CC's" << endl;
1138 if ( mode == 2 ) cout <<
"Mode: PPS followed by all CC's (slow)" << endl;
1139 cout <<
"Projection file name: " << proj->
file_name() << endl;
1140 cout <<
"Number of projections: " << nproj << endl;
1141 cout <<
"Binning: " << bin << endl;
1142 cout <<
"Pixel size: " << pixel_size << endl;
1143 if ( prs_mask->
minimum() < 0 ) cout <<
"Reciprocal space mask file: " << prs_mask->
file_name() << endl;
1144 if ( band[0] > 0 ) {
1145 cout <<
"Reciprocal space bands:" << endl;
1146 for ( i=0; band[i+1]; i+=2 ) {
1147 cout <<
tab << setw(5) << band[i] <<
" - " << setw(5) << band[i+2];
1148 if ( band[i+1] > 0 ) cout <<
"\tcross-correlation" << endl;
1149 else cout <<
"\tcross-validation" << endl;
1152 if ( ctf_apply ) cout <<
"CTF applied to projections." << endl;
1153 cout <<
"Resolution limits (low, high): " << res_lo <<
" - " << res_hi <<
" A" << endl;
1154 if ( res_polar ) cout <<
"Polar resolution limit: " << res_polar <<
" A" << endl;
1155 cout <<
"Annular range: " << ann_min <<
" - " << ann_max <<
" (max = " << proj->
sizeX()/2 - 1 <<
")" << endl;
1156 cout <<
"Shift limit: " << shift_limit <<
" pixels" << endl;
1158 cout <<
"Angle limit: " << angle_limit*180.0/
M_PI <<
" degrees" << endl;
1159 if ( edge_radius ) cout <<
"Edge mask radius: " << edge_radius <<
" pixels" << endl;
1160 if ( mask_file.
length() ) cout <<
"Real space mask file: " << mask_file << endl;
1162 cout <<
"Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
1167 mkdir(
"log", O_CREAT );
1173 mkdir(
"ppx", O_CREAT );
1177 time_t t = time(NULL);
1179 for ( i=0; i<npart; ++i ) {
1183 res_lo, res_hi, res_polar, ann_min, ann_max,
1184 shift_limit, angle_limit, edge_radius, flags,
1185 planf_1D, planb_1D, planf_2D, planb_2D);
1187 cout << setw(15) << mg->
id <<
tab << part->
id <<
tab << fixed <<
1188 setprecision(2) << part->
ori[0] <<
tab << part->
ori[1] <<
tab <<
1189 setprecision(4) << part->
view[0] <<
tab <<
1192 setprecision(4) << part->
fom[0] <<
tab << part->
fom[1] <<
tab <<
1193 (long)(time(NULL) - t) << endl << flush;
1198 cout <<
"DEBUG project_determine_orientations: done, npart=" << npart << endl;
1200 t = (time(NULL) - t);
1203 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
1206 cout <<
"Time: " << ts <<
" s (" << hr <<
":" << min <<
":" << sec <<
")" << endl;
1207 cout <<
"Time per particle: " << ts*1.0/npart <<
" s/particle" << endl;
1208 cout <<
"Algorithm time: " << ts*1.0e6/(npart*nproj*npix) <<
" us/pixel" << endl << endl;
1245 double shift_limit,
int flags)
1247 int part_log = (flags &
PART_LOG)? 1: 0;
1255 cerr <<
"Error in project_determine_origins: No particles found!" << endl;
1262 if ( bin < 1 ) bin = 1;
1263 if ( bin > 4 ) bin = 4;
1268 long i, nproj(0), npart(0), npix(0), vmin(0);
1279 if ( res_lo < res_hi ) swap(res_hi, res_lo);
1280 if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
1281 if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
1285 if ( shift_limit < 0 ) shift_limit = proj->
sizeX()/10;
1287 double cc, angle, da, da_min;
1291 for ( i=0; i<nproj; i++ )
1295 cout <<
"Determining origins:" << endl;
1296 cout <<
"Projection file name: " << proj->
file_name() << endl;
1297 cout <<
"Number of projections: " << nproj << endl;
1298 cout <<
"Pixel size: " << pixel_size << endl;
1299 cout <<
"Resolution limits (low, high): " << res_lo <<
" - " << res_hi <<
" A" << endl;
1300 cout <<
"Shift limit: " << shift_limit <<
" pixels" << endl << endl;
1301 cout <<
"Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tTime" << endl;
1312 mkdir(
"log", O_CREAT );
1316 time_t t = time(NULL);
1319 for ( mg=field->
mg; mg; mg=mg->
next )
if ( mg->
part ) {
1320 for ( part=mg->
part; part; part=part->
next )
1321 if ( ( part_select<0 && part->sel ) || ( part->
sel==
part_select ) ) {
1323 cout <<
"DEBUG project_determine_origins: file=";
1325 else cout << part->
fpart;
1326 cout <<
" image=" << part->
id << endl;
1329 log_name =
"log/" + mg->
id +
"_" +
Bstring(part->
id,
"%04d") +
"_orient.log";
1330 flog.open(log_name.
c_str());
1332 return error_show(
"Error in project_determine_origins: Log file cannot be written!", __FILE__, __LINE__);
1333 flog << field->
id <<
": " << mg->
id <<
": " << part->
id << endl;
1338 return error_show(
"Error in project_determine_origins", __FILE__, __LINE__);
1340 if ( bin > 1 ) p->bin(bin);
1345 hasu_view = part->
view;
1346 hasu_view[3] +=
TWOPI;
1347 for ( i=vmin=0, da_min = 1e10; i<nproj; i++ ) {
1348 da = hasu_view.
angle(pv[i]);
1350 if ( da < da_min ) {
1355 part->
sel = vmin + 1;
1358 error_show(
"Error in project_determine_origins", __FILE__, __LINE__);
1361 angle = hasu_view.
angle() - pv[vmin].
angle();
1363 shift = p->
find_shift(proj1, prs_mask, res_hi, res_lo, shift_limit, 0, 1, planf_2D, planb_2D, cc);
1368 flog << part->
id <<
tab << part->
ori[0] <<
tab << part->
ori[1] <<
tab << cc << endl;
1372 cout << setw(15) << mg->
id <<
tab << part->
id <<
tab <<
1373 setprecision(2) << part->
ori[0] <<
tab << part->
ori[1] <<
tab <<
1374 setprecision(4) << part->
view[0] <<
tab <<
1377 setprecision(4) << part->
fom[0] <<
tab <<
1378 (long)(time(NULL) - t) << endl;
1381 }
else part->
fom[0] = part->
sel = 0;
1385 t = (time(NULL) - t);
1388 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
1391 cout <<
"Time: " << ts <<
" s (" << hr <<
":" << min <<
":" << sec <<
")" << endl;
1392 cout <<
"Time per particle: " << ts*1.0/npart <<
" s/particle" << endl;
1393 cout <<
"Algorithm time: " << ts*1.0e6/(npart*nproj*npix) <<
" us/pixel" << endl << endl;
1437 for ( i=0; i<datasize; i++ )
1438 if ( (*prs_mask)[i] < 0 )
1439 cv += (pcc->
complex(i)).real();
1444 cout <<
"DEBUG img_cross_validate: cv=" << cv << endl;