| Bsoft 2.0.5 Bernard's software package

mg_orient.cpp
Go to the documentation of this file.
1
9 #include "mg_orient.h"
10 #include "mg_processing.h"
11 #include "rwmg.h"
12 #include "mg_particle_select.h"
13 #include "mg_ctf.h"
14 #include "symmetry.h"
15 #include "linked_list.h"
16 #include "rwimg.h"
17 #include "ps_views.h"
18 #include "utilities.h"
19
20 #include <fstream>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23
24
25 // Declaration of global variables
26 extern int verbose; // Level of output to the screen
27
28 int part_determine_orientation(Bparticle* part, Bimage* proj, Bimage* part_mask,
29 Bimage* prs_mask, Bsymmetry* sym, int bin,
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,
32 fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D);
33
34
35 double correlation_coefficient_adjust(double cc, double std)
36 {
37 int i;
38 double ccc = cc, ccd = 1;
39 double fac = sqrt(2.0)*std;
40
41 for ( i=0; i<100 && fabs(ccd) > 1e-10; i++ ) {
42 ccd = cc - ccc*ccc*ccc - fac*ccc*(1-ccc);
43 ccc += ccd;
44 }
45
46 // if ( verbose & VERB_DEBUG )
47 // cout << "DEBUG correlation_coefficient_adjust: i=" << i << " ccd=" << ccd << endl;
48
49 return ccc;
50 }
51
65 Bimage* project_prepare_2D_references(Bproject* project, long first,
66 long number, int bin, int ctf_action, double wiener)
67 {
68 if ( bin < 1 ) bin = 1;
69 if ( bin > 4 ) bin = 4;
70
71 Bparticle* part = part_find_first(project);
72 Bmicrograph* mg = part->mg;
73 Bfield* field = project->field;
74 Bimage* p = NULL;
75 double pixel_size(part->pixel_size);
76
77 if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
78 else p = read_img(mg->fpart, 1, part->id - 1);
79
80 if ( pixel_size < 0.01 ) pixel_size = p->sampling()[0];
81 if ( pixel_size < 0.01 ) pixel_size = mg->pixel_size;
82
83 Bimage* pref = new Bimage(Float, TSimple, p->size(), number);
84 pref->sampling(pixel_size, pixel_size, 1);
85 pref->origin(pref->size()/2);
86
87 delete p;
88
89 if ( verbose ) {
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;
95 }
96
97 long i(0), npart(0);
98
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 )
102 if ( i > first ) {
103 if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
104 else p = read_img(mg->fpart, 1, part->id - 1);
105 if ( !p ) {
106 error_show("project_prepare_2D_references", __FILE__, __LINE__);
107 return NULL;
108 }
109 p->change_type(Float);
110 p->sampling(pixel_size, pixel_size, 1);
111 if ( ctf_action && mg->ctf )
112 img_ctf_apply(p, *mg->ctf, ctf_action, wiener, 0, 0);
113 p->rescale_to_avg_std(0, 1);
114 p->shift_background(0);
115 if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->origin(part->ori);
116 else p->origin(p->size()/2);
117 if ( verbose )
118 cout << mg->id << tab << part->id << tab << p->image->origin() << endl;
119 p->center();
120 pref->replace(npart, p);
121 npart++;
122 delete p;
123 }
124 }
125 }
126
127 if ( bin > 1 ) pref->bin(bin);
128
129 pref->statistics();
130 pref->shift_background(0);
131
132 if ( verbose & VERB_DEBUG )
133 write_img("ref.pif", pref, 0);
134
135 return pref;
136 }
137
156 Bimage* img_prepare_projections(Bstring& filename, Bstring& mask_file,
157 int bin, Bsymmetry* sym,
158 double theta_step, double phi_step, double side_ang)
159 {
160 if ( theta_step < SMALLFLOAT || phi_step < SMALLFLOAT ) {
161 if ( theta_step < SMALLFLOAT )
162 cerr << "Error: The theta step size is too small! (" << theta_step*180.0/M_PI << ")" << endl;
163 if ( phi_step < SMALLFLOAT )
164 cerr << "Error: The phi step size is too small! (" << phi_step*180.0/M_PI << ")" << endl;
165 return NULL;
166 }
167
168 // Read the reference
169 Bimage* pref = read_img(filename, 1, -1);
170 if ( pref == NULL ) {
171 error_show("Error in img_prepare_projections", __FILE__, __LINE__);
172 return NULL;
173 }
174
175 pref->change_type(Float);
176 pref->rescale_to_avg_std(0, 1);
177 pref->statistics();
178
179 if ( bin < 1 ) bin = 1;
180 if ( bin > 4 ) bin = 4;
181 if ( bin > 1 ) pref->bin(bin);
182
183 int i;
184 Vector3<double> origin;
185 for ( i=0; i<pref->images(); i++ ) {
186 origin = pref->image[i].origin();
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;
194 pref->image[i].origin(origin);
195 }
196
197 if ( verbose ) {
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;
203 if ( side_ang < 0 )
204 cout << "Symmetry: " << sym->label << endl;
205 else
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;
208 }
209
210 Bimage* proj = NULL;
211 View* views = NULL;
212 int nviews(0);
213
214 time_t t = time(NULL);
215
216 FSI_Kernel* kernel = new FSI_Kernel(10, 2);
217
218 // Mask to apply to projections
219 Bimage* pmask = NULL;
220 if ( mask_file.length() ) {
221 pmask = read_img(mask_file, 1, 0);
222 if ( bin > 1 ) pmask->bin(bin);
223 }
224
225 long mem_req(0);
226 long mem_avail = system_memory();
227
228 if ( pref->sizeZ() > 1 && pref->images() < 2 ) {
229 if ( side_ang < 0 )
230 views = asymmetric_unit_views(sym, theta_step, phi_step, 1);
231 else
232 views = side_views(sym, side_ang, theta_step, phi_step);
233 nviews = count_list((char *)views);
234 mem_req = pref->size()[0]*pref->size()[1]*sizeof(float)*nviews;
235 if ( verbose ) {
236 cout << "Number of projections: " << nviews << endl;
237 cout << "Memory required: " << mem_req << endl;
238 cout << "Memory available: " << mem_avail << endl;
239 }
240 if ( mem_req > mem_avail ) {
241 cerr << "Not enough memory to run!" << endl;
242 bexit(-1);
243 }
244 proj = pref->project(views, pref->sampling()[0], kernel);
245 if ( pmask ) proj->multiply(pmask);
246 kill_list((char *) views, sizeof(View));
247 delete pref;
248 if ( verbose )
249 cout << "Time to generate projections: " << (long)(time(NULL) - t) << " seconds" << endl << endl;
250 } else {
251 proj = pref;
252 proj->shift_background(0);
253 mem_req = proj->size()[0]*proj->size()[1]*proj->images()*sizeof(float);
254 if ( verbose ) {
255 cout << "Number of projections: " << proj->images() << endl;
256 cout << "Memory required: " << mem_req << endl;
257 cout << "Memory available: " << mem_avail << endl;
258 }
259 if ( mem_req > mem_avail ) {
260 cerr << "Not enough memory to run!" << endl;
261 bexit(-1);
262 }
263 }
264
265 delete kernel;
266 delete pmask;
267
268 return proj;
269 }
270
271 Bimage* img_read_projection(Bstring& proj_file, int multi_file, int proj_num)
272 {
273 if ( verbose & VERB_DEBUG )
274 cout << "DEBUG img_read_projection: proj_file=" << proj_file << " proj_num=" << proj_num << endl;
275
276 Bimage* proj = NULL;
277 Bstring proj_name = NULL;
278
279 if ( multi_file ) {
280 proj_name = proj_file.pre_rev('.') + Bstring(proj_num, "%04d.") + proj_file.post_rev('.');
281 proj = read_img(proj_name, 1, 0);
282 } else
283 proj = read_img(proj_file, 1, proj_num);
284
285 if ( !proj )
286 error_show("Error in img_read_projection", __FILE__, __LINE__);
287
288 return proj;
289 }
290
329 int project_determine_orientations(Bproject* project, Bimage* proj, Bstring& mask_file,
330 int bin, Bsymmetry* sym, int part_select, vector<double>& band,
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)
333 {
334 int mode = flags & MODE;
335 int ctf_apply = (flags & APPLY_CTF)? 1: 0;
336 int part_log = (flags & PART_LOG)? 1: 0;
337
338 // Bfield* field = project->field;
339
340 Bparticle* part = part_find_first(project);
341 Bmicrograph* mg = part->mg;
342
343 if ( !part ) {
344 cerr << "Error in project_determine_orientations: No particles found!" << endl;
345 return -1;
346 }
347
348 // cout << proj->image->origin() << endl;
349
350 // Note that the reference projections are already binned
351 if ( bin < 1 ) bin = 1;
352 if ( bin > 4 ) bin = 4;
353 edge_radius /= bin;
354
355 double pixel_size = bin*mg->pixel_size;
356
357 // Read the reference (model) projections, convert to floating point and clean up
358 long i, nproj(0), npix(0);
359
360 nproj = proj->images();
361
362 npix = proj->sizeX()*proj->sizeY();
363
364 // cout << "Projection size:" << tab << proj->size() << tab << proj->images() << endl;
365
366 // Specify FFTW arrays
367 fft_plan planf_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_FORWARD, 1);
368 fft_plan planb_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_BACKWARD, 1);
369 fft_plan planf_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_FORWARD, 1);
370 fft_plan planb_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_BACKWARD, 1);
371
372 // Set resolution limits
373 if ( res_lo < res_hi ) swap(res_hi, res_lo);
374 if ( res_lo > proj->sizeX()*mg->pixel_size ) res_lo = proj->sizeX()*mg->pixel_size;
375 if ( res_hi > proj->sizeX()*mg->pixel_size/2 ) res_hi = proj->sizeX()*mg->pixel_size/2;
376 if ( res_lo < 4*pixel_size ) res_lo = 4*pixel_size;
377 if ( res_hi < 2*pixel_size ) res_hi = 2*pixel_size;
378
379 // cout << "Resolution:" << tab << res_hi << tab << res_lo << endl;
380
381 // Check the annulus limits
382 ann_min /= bin;
383 ann_max /= bin;
384 if ( ann_min > ann_max ) swap(ann_min, ann_max);
385 if ( ann_min < 0 ) ann_min = 0;
386 if ( ann_max > proj->sizeX()/2 - 1 ) ann_max = proj->sizeX()/2 - 1;
387
388 // cout << "Annuli:" << tab << ann_min << tab << ann_max << endl;
389
390 // Check the shift limit
391 shift_limit /= bin;
392 if ( shift_limit < 0 ) shift_limit = proj->sizeX()/10; // Default shift limit
393
394 // Generate the masks for cross-correlation and cross-validation
395 Bimage* prs_mask = new Bimage(SCharacter, TSimple, proj->size(), 1);
396 prs_mask->sampling(pixel_size, pixel_size, 1);
397 if ( band.size() < 2 || band[0] < 1 )
398 band = prs_mask->fspace_default_bands(res_lo, res_hi);
399
400 prs_mask->mask_fspace_banded(band);
401 write_img("mask.map", prs_mask, 0);
402
403 if ( prs_mask->minimum() < 0 ) project->fom_tag[1] = FOM_CV;
404
405 // Mask to apply to particles
406 Bimage* part_mask = NULL;
407 if ( mask_file.length() ) {
408 part_mask = read_img(mask_file, 1, 0);
409 if ( bin > 1 ) part_mask->bin(bin);
410 }
411
412 long npart(0);
413 Bparticle** partarr = project_mg_particle_array(project, part_select, npart);
414
415 if ( verbose & VERB_RESULT ) {
416 cout << "Determining orientations:" << endl;
417 if ( mode == 0 ) cout << "Mode: PPS based followed by one CC (fast)" << endl;
418 if ( mode == 1 ) cout << "Mode: PPS followed by selected CC's" << endl;
419 if ( mode == 2 ) cout << "Mode: PPS followed by all CC's (slow)" << endl;
420 cout << "Projection file name: " << proj->file_name() << endl;
421 cout << "Number of projections: " << nproj << endl;
422 cout << "Binning: " << bin << endl;
423 cout << "Pixel size: " << pixel_size << endl;
424 if ( prs_mask->minimum() < 0 ) cout << "Reciprocal space mask file: " << prs_mask->file_name() << endl;
425 if ( band[0] > 0 ) {
426 cout << "Reciprocal space bands:" << endl;
427 for ( i=0; band[i+1]; i+=2 ) {
428 cout << tab << setw(5) << band[i] << " - " << setw(5) << band[i+2];
429 if ( band[i+1] > 0 ) cout << "\tcross-correlation" << endl;
430 else cout << "\tcross-validation" << endl;
431 }
432 }
433 if ( ctf_apply ) cout << "CTF applied to projections." << endl;
434 cout << "Resolution limits (low, high): " << res_lo << " - " << res_hi << " A" << endl;
435 if ( res_polar ) cout << "Polar resolution limit: " << res_polar << " A" << endl;
436 cout << "Annular range: " << ann_min << " - " << ann_max << " (max = " << proj->sizeX()/2 - 1 << ")" << endl;
437 cout << "Shift limit: " << shift_limit << " pixels" << endl;
438 if ( angle_limit )
439 cout << "Angle limit: " << angle_limit*180.0/M_PI << " degrees" << endl;
440 if ( edge_radius ) cout << "Edge mask radius: " << edge_radius << " pixels" << endl;
441 if ( mask_file.length() ) cout << "Real space mask file: " << mask_file << endl;
442 cout << endl;
443 cout << "Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
444 }
445
446 // Directory for individual particle log files
447 if ( part_log ) {
448 mkdir("log", O_CREAT );
449 chmod("log", 0755);
450 }
451
452 // Directory for individual particle parameter files
453 if ( flags & WRITE_PPX ) {
454 mkdir("ppx", O_CREAT );
455 chmod("ppx", 0755);
456 }
457
458 time_t t = time(NULL);
459
460 #ifdef HAVE_GCD
461 dispatch_queue_t myq = dispatch_queue_create(NULL, NULL);
462 dispatch_apply(npart, dispatch_get_global_queue(0, 0), ^(size_t i){
463 Bparticle* part = partarr[i];
464 Bmicrograph* mg = part->mg;
465 part_determine_orientation(part, proj, part_mask,
466 prs_mask, sym, bin,
467 res_lo, res_hi, res_polar, ann_min, ann_max,
468 shift_limit, angle_limit, edge_radius, flags,
469 planf_1D, planb_1D, planf_2D, planb_2D);
470 dispatch_sync(myq, ^{
471 if ( verbose & VERB_RESULT ) {
472 cout << setw(15) << mg->id << tab << part->id << tab << fixed <<
473 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
474 setprecision(4) << part->view[0] << tab <<
475 part->view[1] << tab << part->view[2] << tab <<
476 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
477 setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
478 (long)(time(NULL) - t) << endl << flush;
479 }
480 });
481 });
482 #else
483 #pragma omp parallel for
484 for ( i=0; i<npart; i++ ) {
485 Bparticle* part = partarr[i];
486 Bmicrograph* mg = part->mg;
487 part_determine_orientation(part, proj, part_mask,
488 prs_mask, sym, bin,
489 res_lo, res_hi, res_polar, ann_min, ann_max,
490 shift_limit, angle_limit, edge_radius, flags,
491 planf_1D, planb_1D, planf_2D, planb_2D);
492 #pragma omp critical
493 {
494 if ( verbose & VERB_RESULT ) {
495 cout << setw(15) << mg->id << tab << part->id << tab << fixed <<
496 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
497 setprecision(4) << part->view[0] << tab <<
498 part->view[1] << tab << part->view[2] << tab <<
499 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
500 setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
501 (long)(time(NULL) - t) << endl << flush;
502 }
503 }
504 }
505 #endif
506
507 t = (time(NULL) - t);
508
509 long ts = (long) t;
510 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
511
512 if ( verbose & VERB_RESULT && npart ) {
513 cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
514 cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
515 cout << "Algorithm time: " << ts*1.0e6/(npart*nproj*npix) << " us/pixel" << endl << endl;
516 }
517
518 delete[] partarr;
519 delete prs_mask;
520 delete part_mask;
521
522 fft_destroy_plan(planf_1D);
523 fft_destroy_plan(planb_1D);
524 fft_destroy_plan(planf_2D);
525 fft_destroy_plan(planb_2D);
526
527 return 0;
528 }
529
530 int part_determine_orientation(Bparticle* part, Bimage* proj, Bimage* part_mask,
531 Bimage* prs_mask, Bsymmetry* sym, int bin,
532 double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
533 double shift_limit, double angle_limit, double edge_radius, int flags,
534 fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
535 {
536 FOMType fom_tag[NFOM] = {FOM, FOM_CV};
537
538 if ( flags & CHECK_PPX )
539 if ( ppx_check(part, fom_tag) ) return 0;
540
541 if ( verbose & VERB_DEBUG )
542 cout << "DEBUG part_determine_orientation: id=" << part->id << " flags=" << flags << endl;
543
544 int mode = flags & MODE;
545 int ctf_apply = (flags & APPLY_CTF)? 1: 0;
546 int part_log = (flags & PART_LOG)? 1: 0;
547
548 long k, imax(0), nproj(proj->images());
549 double cc_best(-1e37), cc_min, cc_max, cc_avg, cc_std, cc_cut;
550 double* angle = new double[nproj];
551 double* ox = new double[nproj];
552 double* oy = new double[nproj];
553 View* view = new View[nproj];
554 double* cc = new double[nproj];
555
556 Bmicrograph* mg = part->mg;
557 double pixel_size = bin*mg->pixel_size;
558 ofstream flog;
559 Bstring log_name;
560 long edge_size = (long) (2*edge_radius);
561 Vector3<long> size(edge_size, edge_size, 1);
562 Vector3<double> start, shift;
563
564 Bimage* p = NULL;
565 Bimage* pm;
566 Bimage* proj1;
567
568 if ( part_log ) {
569 log_name = "log/" + mg->id + "_" + Bstring(part->id, "%04d") + "_orient.log";
570 flog.open(log_name.c_str());
571 if ( flog.fail() )
572 return error_show("Log file cannot be written!", __FILE__, __LINE__);
573 flog << mg->id << ": " << part->id << endl;
574 }
575
576 // cout << "Reading particle " << part->id << endl;
577 if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
578 else if ( mg->fpart.length() ) p = read_img(mg->fpart, 1, part->id - 1);
579 if ( !p )
580 return error_show("part_determine_orientation", __FILE__, __LINE__);
581
582 // cout << "Preparing particle " << part->id << endl;
583 p->change_type(Float);
584 if ( bin > 1 ) p->bin(bin);
585 p->statistics();
586 p->sampling(pixel_size, pixel_size, 1);
587 // cout << "Image sampling = " << p->sampling() << endl;
588 // if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->image->origin(part->ori/bin);
589 // else p->image->origin(p->size());
590 if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->origin(part->ori/bin);
591 else p->origin(p->size()/2);
592
593 p->rescale_to_avg_std(0, 1);
594 p->shift_background(0);
595
596 if ( part_mask ) {
597 pm = part_mask->copy();
598 shift = p->image->origin() - pm->image->origin();
599 pm->shift(shift);
600 p->multiply(pm);
601 delete pm;
602 p->rescale_to_avg_std(0, 1);
603 p->shift_background(0);
604 }
605
606 if ( edge_size ) {
607 // cout << "Edge masking" << endl;
608 start = Vector3<double>(p->image->origin()[0]-edge_radius, p->image->origin()[1]-edge_radius, 0);
609 p->edge(1, size, start, 1, FILL_BACKGROUND, 0);
610 }
611
612 if ( verbose & VERB_DEBUG )
613 cout << "DEBUG part_determine_orientation: preprocessing done for image " << part->id << endl;
614 if ( part_log )
615 flog << "PartID\tProjID\tox\toy\tvx\tvy\tvz\tva\tcc" << endl;
616
617 for ( k=0; k<nproj; k++ ) {
618 if ( verbose & VERB_DEBUG )
619 cout << "DEBUG part_determine_orientation: pps with proj " << k << endl;
620 proj1 = proj->extract(k);
621 if ( !proj1 )
622 return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
623 proj1->sampling(pixel_size, pixel_size, 1);
624 // cout << "Projection sampling = " << proj1->sampling() << endl;
625 if ( ctf_apply && mg->ctf )
626 img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
627 p->image->view(part->view);
628 cc[k] = p->align2D_pps(proj1, res_hi, res_lo, shift_limit, angle_limit, planf_2D, planb_2D);
629 angle[k] = p->image->view_angle();
630 ox[k] = p->image->origin()[0];
631 oy[k] = p->image->origin()[1];
632 view[k] = proj1->image->view();
633 // cout << ox[k] << tab << oy[k] << endl;
634 if ( angle[k] < 0 ) {
635 view[k].negate();
636 view[k][3] = angle_set_negPI_to_PI(M_PI - view[k].angle() + angle[k]);
637 } else {
638 view[k][3] = angle_set_negPI_to_PI(view[k].angle() - angle[k]);
639 }
640 // if ( verbose & VERB_DEBUG )
641 if ( part_log )
642 flog << fixed << setprecision(4) <<
643 part->id << tab << k+1 << tab <<
644 bin*ox[k] << tab << bin*oy[k] << tab << view[k][0] << tab << view[k][1] << tab <<
645 view[k][2] << tab << view[k].angle()*180.0/M_PI << tab << cc[k] << endl;
646 // cout << part->id << " " << k+1 << " " << ox[k] << " " << oy[k]
647 // << " " << view[k][0] << " " << view[k][1] << " " << view[k][2]
648 // << " " << view[k].angle()*180.0/M_PI << " " << cc[k] << endl;
649 if ( cc_best < cc[k] ) {
650 cc_best = cc[k];
651 imax = k;
652 }
653 delete proj1;
654 }
655
656 cc_avg = cc_std = 0;
657 cc_min = cc_max = cc[0];
658 for ( k=imax=0; k<nproj; k++ ) {
659 if ( cc_min > cc[k] ) cc_min = cc[k];
660 if ( cc_max < cc[k] ) {
661 cc_max = cc[k];
662 imax = k;
663 }
664 cc_avg += cc[k];
665 cc_std += cc[k]*cc[k];
666 }
667 cc_avg /= nproj;
668 cc_std = cc_std/nproj - cc_avg*cc_avg;
669 if ( cc_std > 0 ) cc_std = sqrt(cc_std);
670 else cc_std = 0;
671 cc_cut = cc_avg + cc_std;
672 if ( cc_cut >= cc_max ) cc_cut = cc_max - 0.01;
673 if ( mode < 1 ) cc_cut = cc_max - 0.01;
674 else if ( mode > 1 ) cc_cut = cc_min - 1;
675 if ( verbose & VERB_DEBUG )
676 if ( part_log )
677 flog << "Particle, min, max, avg, std, max/avg:" <<
678 part->id << tab << cc_min << tab << cc_max << tab <<
679 cc_avg << tab << cc_std << tab << cc_max/cc_avg << endl;
680 if ( verbose & VERB_DEBUG ) {
681 cout << "DEBUG part_determine_orientation: cc_avg=" << cc_avg << " cc_std=" << cc_std << endl;
682 cout << "DEBUG part_determine_orientation: cc_min=" << cc_min << " cc_max=" << cc_max << endl;
683 cout << "DEBUG part_determine_orientation: cc_cut=" << cc_cut << endl;
684 }
685
686 cc_best = -1e37;
687 // if ( mode > 0 )
688 for ( k=0; k<nproj; k++ ) if ( cc[k] > cc_cut ) {
689 if ( verbose & VERB_DEBUG )
690 cout << "DEBUG part_determine_orientation: cc with proj " << k << endl;
691 proj1 = proj->extract(k);
692 if ( !proj1 )
693 return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
694 proj1->sampling(pixel_size, pixel_size, 1);
695 if ( ctf_apply && mg->ctf )
696 img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
697 p->image->view(part->view);
698 p->image->view_angle(angle[k]);
699 p->image->origin(ox[k], oy[k], 0);
700 // cc[k] = img_align2D(p, proj1, 1, res_polar, ann_min, ann_max,
701 // prs_mask, shift_limit, planf_1D, planb_1D, planf_2D, planb_2D);
702 cc[k] = p->align2D(proj1, res_polar, ann_min, ann_max,
703 prs_mask, shift_limit, angle_limit, planf_1D, planb_1D, planf_2D, planb_2D);
704 angle[k] = p->image->view_angle();
705 ox[k] = p->image->origin()[0];
706 oy[k] = p->image->origin()[1];
707 view[k] = proj1->image->view();
708 if ( angle[k] < 0 ) {
709 view[k].negate();
710 view[k][3] = angle_set_negPI_to_PI(M_PI - view[k].angle() + angle[k]);
711 } else {
712 view[k][3] = angle_set_negPI_to_PI(view[k].angle() - angle[k]);
713 }
714 if ( part_log )
715 flog << fixed << setprecision(4) <<
716 part->id << tab << k+1 << tab <<
717 bin*ox[k] << tab << bin*oy[k] << tab << view[k][0] << tab << view[k][1] << tab <<
718 view[k][2] << tab << view[k].angle()*180.0/M_PI << tab << cc[k] << endl;
719 // cout << part->id << " " << k+1 << " " << ox[k] << " " << oy[k]
720 // << " " << view[k][0] << " " << view[k][1] << " " << view[k][2]
721 // << " " << view[k].angle()*180.0/M_PI << " " << cc[k] << endl;
722 if ( cc_best < cc[k] ) {
723 cc_best = cc[k];
724 imax = k;
725 }
726 delete proj1;
727 }
728
729 if ( verbose & VERB_DEBUG )
730 cout << "DEBUG part_determine_orientation: projection matching done for image " << part->id << endl;
731 part->ori = Vector3<double>(bin*ox[imax], bin*oy[imax], 0);
732 part->view = view[imax];
733 part->fom[0] = cc[imax];
734 if ( prs_mask->minimum() < 0 ) {
735 proj1 = proj->extract(imax);
736 if ( !proj1 )
737 return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
738 proj1->sampling(pixel_size, pixel_size, 1);
739 if ( ctf_apply && mg->ctf )
740 img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
741 p->image->view_angle(angle[imax]);
742 p->image->origin(ox[imax], oy[imax], 0);
743 p->origin(0, ox[imax], oy[imax], 0.0);
744 part->fom[1] = img_cross_validate(p, proj1, prs_mask, planf_2D);
745 delete proj1;
746 }
747 part->view = find_asymmetric_unit_view(sym, part->view);
748 part->view[3] = angle_set_negPI_to_PI(part->view.angle());
749 part->sel = imax + 1;
750 if ( part_log ) {
751 flog << "Particle, min, max, avg, std, max/avg, cv:" << tab <<
752 part->id << tab << cc_min << tab << cc_max << tab <<
753 cc_avg << tab << cc_std << tab << cc_max/cc_avg << tab << part->fom[1] << endl;
754 flog << fixed << setprecision(4) <<
755 part->id << tab << part->ori[0] << tab << part->ori[1] << tab <<
756 part->view[0] << tab << part->view[1] << tab <<
757 part->view[2] << tab << part->view.angle()*180.0/M_PI << tab <<
758 part->fom[0] << tab << part->fom[1] << endl;
759 flog.close();
760 }
761
762 delete[] angle;
763 delete[] ox;
764 delete[] oy;
765 delete[] view;
766 delete[] cc;
767 delete p;
768
769 if ( flags & WRITE_PPX ) {
770 log_name = ppx_filename(mg->id, part->id);
771 write_particle(log_name, part, 0, 0, fom_tag);
772 }
773
774 return 1;
775 }
776
797 int project_determine_origins(Bproject* project, Bimage* proj, int bin,
798 Bsymmetry* sym, int part_select, double res_lo, double res_hi,
799 double shift_limit, int flags)
800 {
801 int part_log = (flags & PART_LOG)? 1: 0;
802
803 Bfield* field = project->field;
804
805 Bparticle* part = part_find_first(project);
806 Bmicrograph* mg = part->mg;
807
808 if ( !part ) {
809 cerr << "Error in project_determine_origins: No particles found!" << endl;
810 return -1;
811 }
812
813 Bimage* p = NULL;
814 Bimage* prs_mask = NULL;
815
816 if ( bin < 1 ) bin = 1;
817 if ( bin > 4 ) bin = 4;
818
819 double pixel_size = bin*mg->pixel_size;
820
821 // Read the reference (model) projections, convert to floating point and clean up
822 long i, nproj(0), npart(0), npix(0), vmin(0);
823
824 nproj = proj->images();
825
826 npix = proj->sizeX()*proj->sizeY();
827
828 // Specify FFTW arrays
829 fft_plan planf_2D = proj->fft_setup(FFTW_FORWARD, 1);
830 fft_plan planb_2D = proj->fft_setup(FFTW_BACKWARD, 1);
831
832 // Set resolution limits
833 if ( res_lo < res_hi ) swap(res_hi, res_lo);
834 if ( res_lo < 4*pixel_size ) res_lo = 4*pixel_size;
835 if ( res_hi < 2*pixel_size ) res_hi = 2*pixel_size;
836
837 // Check the shift limit
838 shift_limit /= bin;
839 if ( shift_limit < 0 ) shift_limit = proj->sizeX()/10; // Default shift limit
840
841 double cc, angle, da, da_min;
842 View* pv = new View[nproj];
843 View hasu_view;
844
845 for ( i=0; i<nproj; i++ )
846 pv[i] = proj->image->view();
847
848 if ( verbose & VERB_RESULT ) {
849 cout << "Determining origins:" << endl;
850 cout << "Projection file name: " << proj->file_name() << endl;
851 cout << "Number of projections: " << nproj << endl;
852 cout << "Pixel size: " << pixel_size << endl;
853 cout << "Resolution limits (low, high): " << res_lo << " - " << res_hi << " A" << endl;
854 cout << "Shift limit: " << shift_limit << " pixels" << endl << endl;
855 cout << "Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tTime" << endl;
856 }
857
858
859 ofstream flog;
860 Bstring log_name;
861 Bimage* proj1;
862 Vector3<double> shift;
863
864 // Directory for individual particle log files
865 if ( part_log ) {
866 mkdir("log", O_CREAT );
867 chmod("log", 0755);
868 }
869
870 time_t t = time(NULL);
871
872 for ( field=project->field; field; field=field->next ) {
873 for ( mg=field->mg; mg; mg=mg->next ) if ( mg->part ) {
874 for ( part=mg->part; part; part=part->next )
875 if ( ( part_select<0 && part->sel ) || ( part->sel==part_select ) ) {
876 if ( verbose & VERB_DEBUG ) {
877 cout << "DEBUG project_determine_origins: file=";
878 if ( part->fpart.length() ) cout << mg->fpart;
879 else cout << part->fpart;
880 cout << " image=" << part->id << endl;
881 }
882 if ( part_log ) {
883 log_name = "log/" + mg->id + "_" + Bstring(part->id, "%04d") + "_orient.log";
884 flog.open(log_name.c_str());
885 if ( flog.fail() )
886 return error_show("Error in project_determine_origins: Log file cannot be written!", __FILE__, __LINE__);
887 flog << field->id << ": " << mg->id << ": " << part->id << endl;
888 }
889 if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
890 else p = read_img(mg->fpart, 1, part->id - 1);
891 if ( !p )
892 return error_show("Error in project_determine_origins", __FILE__, __LINE__);
893 p->change_type(Float);
894 if ( bin > 1 ) p->bin(bin);
895 p->statistics();
896 p->rescale_to_avg_std(0, 1);
897 p->shift_background(0);
898 p->sampling(pixel_size, pixel_size, 1);
899 hasu_view = part->view;
900 hasu_view[3] += TWOPI;
901 for ( i=vmin=0, da_min = 1e10; i<nproj; i++ ) {
902 da = hasu_view.angle(pv[i]);
903 da = fabs(angle_set_negPI_to_PI(da));
904 if ( da < da_min ) {
905 da_min = da;
906 vmin = i;
907 }
908 }
909 part->sel = vmin + 1;
910 proj1 = proj->extract(vmin);
911 if ( !proj ) {
912 error_show("Error in project_determine_origins", __FILE__, __LINE__);
913 return -1;
914 }
915 angle = hasu_view.angle() - pv[vmin].angle();
916 proj1->rotate(angle);
917 shift = p->find_shift(proj1, prs_mask, res_hi, res_lo, shift_limit, 0, 1, planf_2D, planb_2D, cc);
918 part->ori = (proj1->image->origin() + shift) * bin;
919 part->fom[0] = cc;
920 delete proj1;
921 if ( part_log ) {
922 flog << part->id << tab << part->ori[0] << tab << part->ori[1] << tab << cc << endl;
923 flog.close();
924 }
925 if ( verbose & VERB_RESULT )
926 cout << setw(15) << mg->id << tab << part->id << tab <<
927 setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
928 setprecision(4) << part->view[0] << tab <<
929 part->view[1] << tab << part->view[2] << tab <<
930 setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
931 setprecision(4) << part->fom[0] << tab <<
932 (long)(time(NULL) - t) << endl;
933 delete p;
934 npart++;
935 } else part->fom[0] = part->sel = 0;
936 }
937 }
938
939 t = (time(NULL) - t);
940
941 long ts = (long) t;
942 long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
943
944 if ( verbose & VERB_RESULT ) {
945 cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
946 cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
947 cout << "Algorithm time: " << ts*1.0e6/(npart*nproj*npix) << " us/pixel" << endl << endl;
948 }
949
950 fft_destroy_plan(planf_2D);
951 fft_destroy_plan(planb_2D);
952
953 delete[] pv;
954
955 return 0;
956 }
957
958
976 double img_cross_validate(Bimage* p, Bimage* pref, Bimage* prs_mask, fft_plan planf)
977 {
978 Bimage* prot = pref->rotate(pref->size(), fabs(p->image->view_angle() - pref->image->view_angle()));
979
980 Bimage* pcc = prot->pack_two_in_complex(p);
981
982 delete prot;
983
984 pcc->fft(planf, 0);
985 pcc->complex_apply_negative_mask(prs_mask);
986 pcc->combined_complex_product();
987
988 double cv(0);
989 long i, datasize = pcc->sizeX()*pcc->sizeY()*pcc->sizeZ()*pcc->images();
990
991 for ( i=0; i<datasize; i++ )
992 if ( (*prs_mask)[i] < 0 )
993 cv += (pcc->complex(i)).real();
994
995 delete pcc;
996
997 if ( verbose & VERB_DEBUG )
998 cout << "DEBUG img_cross_validate: cv=" << cv << endl;
999
1000 return cv;
1001 }
1002
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bparticle::id
int id
Definition: mg_processing.h:92
rwmg.h
Header file for reading and writing micrograph parameters.
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2828
NPOLANG
#define NPOLANG
Definition: Bimage.h:29
Bparticle::pixel_size
double pixel_size
Definition: mg_processing.h:98
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:143
PART_LOG
#define PART_LOG
Definition: mg_processing.h:25
Bimage::combined_complex_product
int combined_complex_product()
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
Definition: Bimage_complex.cpp:813
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
img_prepare_projections
Bimage * img_prepare_projections(Bstring &filename, Bstring &mask_file, int bin, Bsymmetry *sym, double theta_step, double phi_step, double side_ang)
Generate projections if a 3D file, otherwise clean projections.
Definition: mg_orient.cpp:156
mg_particle_select.h
Select particles.
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
project_mg_particle_array
Bparticle ** project_mg_particle_array(Bproject *project, int part_select, long &npart)
Sets up an array of selected particle pointers.
Definition: mg_processing.cpp:2029
symmetry.h
Header file for general symmetry functions.
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:45
Bimage::fft
int fft()
Definition: Bimage.h:822
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
planf
fft_plan planf
Definition: bico.cpp:24
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:319
Bimage::align2D
double align2D(Bimage *pref, double res_polar, int ann_min, int ann_max, Bimage *prs_mask, double shift_limit, double angle_limit, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Finds the best in-plane alignment for two 2D images using polar power spectra.
Definition: Bimage_align.cpp:886
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
project_prepare_2D_references
Bimage * project_prepare_2D_references(Bproject *project, long first, long number, int bin, int ctf_action, double wiener)
Prepare reference images from particles.
Definition: mg_orient.cpp:65
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
part_find_first
Bparticle * part_find_first(Bproject *project)
Finds the first particle in a project.
Definition: mg_processing.cpp:589
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
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1005
Bimage::mask_fspace_banded
int mask_fspace_banded(vector< double > &band)
Generate reciprocal space mask based on a specification of bands.
Definition: Bimage_mask.cpp:814
mg_orient.h
Library routines for single particle analysis.
SCharacter
Definition: utilities.h:150
FSI_Kernel
Definition: FSI_Kernel.h:14
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:432
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:312
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage::shift_background
int shift_background(double bkg)
Sets the background for each sub-image to a given value.
Definition: Bimage_background.cpp:351
CHECK_PPX
#define CHECK_PPX
Definition: mg_processing.h:27
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
ppx_filename
Bstring ppx_filename(Bstring &mg_id, int part_id)
Definition: rwmg.cpp:412
Bfield::next
Bfield * next
Definition: mg_processing.h:258
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
TSimple
Definition: Bimage.h:58
img_ctf_apply_to_proj
int img_ctf_apply_to_proj(Bimage *proj, CTFparam em_ctf, double defocus, double res_lo, double res_hi, fft_plan planf_2D, fft_plan planb_2D)
Applies a CTF to a projection image.
Definition: mg_ctf.cpp:354
Float
Definition: utilities.h:157
FOM_CV
Definition: mg_processing.h:42
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
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.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:104
Bimage::shift
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
Definition: Bimage_transform.cpp:587
side_views
View * side_views(Bsymmetry *sym, double side_ang, double theta_step, double phi_step)
Initializes a set of views around the z-axis for helical projection.
Definition: symmetry.cpp:769
NFOM
#define NFOM
Definition: mg_processing.h:16
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bfield::id
Bstring id
Definition: mg_processing.h:259
ppx_check
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:418
write_particle
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:403
Bproject::field
Bfield * field
Definition: mg_processing.h:343
Bproject::fom_tag
FOMType fom_tag[NFOM]
Definition: mg_processing.h:342
fft_plan
fftwf_plan fft_plan
Definition: fft.h:16
img_ctf_apply
int img_ctf_apply(Bimage *p, CTFparam em_ctf, int action, double wiener, double lores, double hires)
Applies or corrects for the contrast transfer function (CTF).
Definition: mg_ctf.cpp:238
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
Bimage::project
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Definition: Bimage_project.cpp:31
system_memory
long system_memory()
Returns system memory size.
Definition: utilities.cpp:204
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
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
APPLY_CTF
#define APPLY_CTF
Definition: mg_processing.h:24
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:91
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
project_determine_orientations
int project_determine_orientations(Bproject *project, Bimage *proj, Bstring &mask_file, int bin, Bsymmetry *sym, int part_select, vector< double > &band, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags)
Find the orientation and origin of every image in a project.
Definition: mg_orient.cpp:329
Bsymmetry
Definition: symmetry.h:38
FOM
Definition: mg_processing.h:40
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:105
MODE
#define MODE
Definition: mg_processing.h:21
Bparticle
Definition: mg_processing.h:89
Bstring
Definition: Bstring.h:29
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2695
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bimage::fft_setup
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
Definition: Bimage_fft.cpp:29
FOMType
FOMType
Definition: mg_processing.h:38
find_asymmetric_unit_view
View find_asymmetric_unit_view(Bsymmetry *sym, View theview)
Finds the corresponding view in the asymmetric unit.
Definition: symmetry.cpp:856
Bimage::fspace_default_bands
vector< double > fspace_default_bands(double res_lo, double res_hi)
Sets up default frequency space bands to generate a mask.
Definition: Bimage_mask.cpp:772
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< double >
correlation_coefficient_adjust
double correlation_coefficient_adjust(double cc, double std)
Definition: mg_orient.cpp:35
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
View::angle
double angle()
Definition: View.h:95
View
Definition: View.h:26
part_determine_orientation
int part_determine_orientation(Bparticle *part, Bimage *proj, Bimage *part_mask, Bimage *prs_mask, Bsymmetry *sym, int bin, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Definition: mg_orient.cpp:530
project_determine_origins
int project_determine_origins(Bproject *project, Bimage *proj, int bin, Bsymmetry *sym, int part_select, double res_lo, double res_hi, double shift_limit, int flags)
Find the origin of every image in a project.
Definition: mg_orient.cpp:797
verbose
int verbose
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:253
Bimage::find_shift
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Definition: Bimage_correlate.cpp:932
fft_setup_plan
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
Definition: fft.cpp:31
Bparticle::def
double def
Definition: mg_processing.h:95
mg_processing.h
Header file for micrograph processing.
rwimg.h
Header file for 2D and 3D image I/O.
Bimage::center
int center(int fill_type=0, double fill=0)
Centers an image.
Definition: Bimage_transform.cpp:699
kernel
Definition: kernlut.h:13
img_cross_validate
double img_cross_validate(Bimage *p, Bimage *pref, Bimage *prs_mask, fft_plan planf)
Rotates and shifts a reference image and calculates a cross-validation coefficient.
Definition: mg_orient.cpp:976
Bimage::images
long images()
Definition: Bimage.h:491
Bimage::pack_two_in_complex
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
Definition: Bimage_complex.cpp:679
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
View::negate
void negate()
Definition: View.h:114
ps_views.h
Header file for postscript tools dealing with views.
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
Bimage::complex_apply_negative_mask
int complex_apply_negative_mask(Bimage *pmask)
Applies a negative mask to a complex image.
Definition: Bimage_complex.cpp:550
img_read_projection
Bimage * img_read_projection(Bstring &proj_file, int multi_file, int proj_num)
Definition: mg_orient.cpp:271
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
Bimage::minimum
double minimum()
Definition: Bimage.h:534
Bsub_image::view_angle
void view_angle(double d)
Definition: Bimage.h:147
Bimage::align2D_pps
double align2D_pps(Bimage *pref, double res_hi, double res_lo, double shift_limit, double angle_limit, fft_plan planf, fft_plan planb)
Finds the best in-plane alignment for two 2D images using polar power spectra.
Definition: Bimage_align.cpp:796
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
TWOPI
#define TWOPI
Definition: utilities.h:68
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:333
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201