| Bsoft 2.0.5 Bernard's software package

bfind.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "mg_processing.h"
11 #include "mg_particle_select.h"
12 #include "rwmg.h"
13 #include "symmetry.h"
14 #include "ps_views.h"
15 #include "linked_list.h"
16 #include "file_util.h"
17 #include "options.h"
18 #include "utilities.h"
19 #include "timer.h"
20
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23
24 // Function prototypes
25 vector<Bimage*> setup_images(Bstring& map_file, Bstring& template_file,
26 Bstring& rs_mask, Bstring& fs_mask,
27 int read_img_num, Vector3<long>& bin, Vector3<double> sam,
28 int set_origin, Vector3<double>& origin, Vector3<double>& part_ori);
29
30 // Usage assistance
31 const char* use[] = {
32 " ",
33 "Usage: bfind [options] input.img/input.star output.img",
34 "------------------------------------------------------",
35 "Searches orientation space for the best fit of a 3D map to a template.",
36 "Modes: Global: Search an asymmetric unit with a fixed angular step size.",
37 " Directional: Do a search around a view within an angular distance (-limit option).",
38 " Refine: Refine iteratively around a view to some accuracy (-accuracy option).",
39 " Symmetry: Search all symmetry-related views using a given view.",
40 "For modes other than global, the view is taken from the command line (-View option),",
41 " or from the parameter file, or as a last resort from the image header.",
42 "If a parameter file is used as input, the input image is selected based on ",
43 " the reconstruction ID and the particle image number.",
44 "Only one image in a multi-image file will be used (see -image option).",
45 "The output file contains the transformed map only if the input is an image (i.e., not a parameter file).",
46 "Specify the output of the transformed map or template with the",
47 " -particle and -newtemplate options.",
48 " ",
49 "Actions:",
50 "-global 2 Global search before other modes with binning.",
51 "-mode refine Local modes: directional, refine or symmetric.",
52 "-setsequential Set particle selection numbers sequentially.",
53 "-subset 25,5 View subset selection from a start offset and with a given size.",
54 "-rescale -0.1,5.2 Rescale output particle to average and standard deviation.",
55 " ",
56 "Parameters:",
57 "-verbose 7 Verbosity of output.",
58 "-datatype u Force writing of a new data type.",
59 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
60 "-origin 110,50,44 Template image origin (default taken from template file).",
61 "-partorigin 50,80,47 Particle image origin (default taken from particle file).",
62 "-angles 8.8,2.5,5.2 Step size for alpha, theta and phi, one value sets all (default 45 degrees).",
63 "-side 15 Generate side view projections within the given angle from the equator.",
64 "-resolution 15.6,200 Resolution limits for cross-correlation (default 0).",
65 "-shiftlimit 5.2 Radial limit to search for shift in cross-correlation map (default 1/4 of map).",
66 "-recid A435 The 3D reconstruction ID (should correspond to that in the parameter file).",
67 "-image 2 Image number in a multi-image file or particle number (default 1=first image).",
68 "-select 5 Particle selection number in parameter file (default not used).",
69 "-bin 3 Binning of input, template and mask by given kernel size,",
70 " output image remains same size as input (only for local modes).",
71 " ",
72 "Parameters for the global and symmetric modes:",
73 "-symmetry D6 Symmetry: Point group identifier.",
74 " ",
75 "Paramweters for the directional and refinement modes:",
76 "-View 0.3,-0.5,0.8,33 View to initiate search: vector {xyz} and angle.",
77 " ",
78 "Parameters for the directional mode:",
79 "-limit 17.5 Radial limit around given view (default 20 degrees).",
80 " ",
81 "Parameters for the refinement mode:",
82 "-accuracy 0.3 Smallest angle step size (default 0.5 degrees).",
83 " ",
84 "Input:",
85 "-Template image.map Template to search for.",
86 "-mask rs_mask.mrc Mask in real space to apply before cross-correlation.",
87 "-Mask fs_mask.mrc Mask in reciprocal space to apply during cross-correlation.",
88 " ",
89 "Output:",
90 "-Postscript plot.ps Output postscript file with a plot of global view vectors.",
91 "-output file.star Parameter output file with best orientation.",
92 "-particle newpart.pif New transformed particle file.",
93 "-newtemplate newtemp.pif New transformed template file.",
94 " ",
95 NULL
96 };
97
98 int main(int argc, char **argv)
99 {
100 // Initialize variables
101 Vector3<long> global_bin; // Flag and binning for global search
102 Vector3<long> bin(1,1,1); // No binning for local modes
103 Bstring mode; // Mode: directional, refine or symmetric
104 double nuavg(0), nustd(0); // Rescaling to average and stdev
105 int view_start(0); // Subset start
106 int view_subset(0); // Subset size
107 DataType nudatatype(Unknown_Type); // Conversion to new type
108 Bstring rec_id; // Reconstruction ID
109 int img_num(1); // Image number in file
110 int sel_num(-1); // Selection number in parameter file
111 int set_seq_sel(0); // Flag to set selection number sequentially
112 Vector3<double> sam; // Units for the three axes (A/pixel)
113 Vector3<double> temp_ori; // Template origin
114 Vector3<double> part_ori; // Particle origin
115 int set_origin(0); // Flag to set the template origin
116 double alpha_step(M_PI_4); // Angular step size for alpha
117 double theta_step(M_PI_4); // Angular step size for theta
118 double phi_step(M_PI_4); // Angular step size for phi
119 double side_ang(-1); // Side view variation angle
120 double angle_limit(M_PI/9.0); // Angular limit for directional search
121 Bsymmetry* sym = NULL; // Default: asymmetric or C1 point group
122 double hires(0), lores(0); // Limiting resolution for cross-correlation
123 double search_radius(-1); // Use default search radius
124 int currview_set(0); // Flag to indicate current view is set
125 View currview; // View to initiate search from and use as current view
126 View bestview; // Eventually the best view
127 View ref_view; // Reference view
128 double accuracy(0); // Accuracy for refinement: default at Nyquest
129 Bstring template_file; // Reference template file name
130 Bstring rs_mask; // Real space mask file name
131 Bstring fs_mask; // Reciprocal space mask file name
132 Bstring ps_file; // Postscript output file name
133 Bstring param_file; // Parameter file name
134 Bstring newpart_file; // Transformed particle output file name
135 Bstring newtemp_file; // Transformed template output file name
136
137 int i, optind;
138 Boption* option = get_option_list(use, argc, argv, optind);
139 Boption* curropt;
140 for ( curropt = option; curropt; curropt = curropt->next ) {
141 if ( curropt->tag == "global" ) {
142 if ( ( global_bin[0] = curropt->value.integer() ) < 1 )
143 cerr << "-global: A bin size must be specified!" << endl;
144 else {
145 if ( global_bin[0] < 1 ) global_bin[0] = 1;
146 global_bin[2] = global_bin[1] = global_bin[0];
147 }
148 }
149 if ( curropt->tag == "mode" ) {
150 if ( curropt->value.length() > 0 ) {
151 if ( curropt->value[0] == 'd' || curropt->value[0] == 'D' ) mode = "directional";
152 if ( curropt->value[0] == 'r' || curropt->value[0] == 'R' ) mode = "refine";
153 if ( curropt->value[0] == 's' || curropt->value[0] == 'S' ) mode = "symmetric";
154 } else
155 cerr << "-mode: A mode must be specified" << endl;
156 }
157 if ( curropt->tag == "setsequential" ) set_seq_sel = 1;
158 if ( curropt->tag == "subset" )
159 if ( curropt->values(view_start, view_subset) < 2 )
160 cerr << "-subset: A view subset start and size must be specified" << endl;
161 if ( curropt->tag == "rescale" )
162 if ( curropt->values(nuavg, nustd) < 2 )
163 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
164 if ( curropt->tag == "image" )
165 if ( ( img_num = curropt->value.integer() ) < 1 )
166 cerr << "-image: An image number must be specified" << endl;
167 if ( curropt->tag == "select" )
168 if ( ( sel_num = curropt->value.integer() ) < 0 )
169 cerr << "-select: A selection number must be specified" << endl;
170 if ( curropt->tag == "datatype" )
171 nudatatype = curropt->datatype();
172 if ( curropt->tag == "sampling" )
173 sam = curropt->sampling();
174 if ( curropt->tag == "origin" ) {
175 if ( curropt->value[0] == 'c' ) {
176 set_origin |= 2;
177 } else {
178 temp_ori = curropt->origin();
179 set_origin |= 1;
180 }
181 }
182 if ( curropt->tag == "partorigin" ) {
183 if ( curropt->value[0] == 'c' ) {
184 set_origin |= 8;
185 } else {
186 part_ori = curropt->origin();
187 set_origin |= 4;
188 }
189 }
190 if ( curropt->tag == "angles" ) {
191 if ( ( i = curropt->values(alpha_step, theta_step, phi_step) ) < 1 )
192 cerr << "-angles: An angle step size must be specified" << endl;
193 else {
194 if ( i < 2 ) phi_step = theta_step = alpha_step;
195 else if ( i < 3 ) phi_step = theta_step;
196 alpha_step *= M_PI/180.0;
197 theta_step *= M_PI/180.0;
198 phi_step *= M_PI/180.0;
199 }
200 }
201 if ( curropt->tag == "side" ) {
202 if ( ( side_ang = curropt->value.real() ) < 0.001 )
203 cerr << "-side: One angle must be specified!" << endl;
204 else
205 side_ang *= M_PI/180.0;
206 }
207 if ( curropt->tag == "limit" ) {
208 if ( ( angle_limit = curropt->value.real() ) < 0.001 )
209 cerr << "-limit: An angular limit must be specified!" << endl;
210 else
211 angle_limit *= M_PI/180.0;
212 }
213 if ( curropt->tag == "View" ) {
214 currview = curropt->view();
215 currview_set = 1;
216 }
217 if ( curropt->tag == "resolution" )
218 if ( curropt->values(hires, lores) < 1 )
219 cerr << "-resolution: A resolution must be specified!" << endl;
220 if ( curropt->tag == "shiftlimit" )
221 if ( ( search_radius = curropt->value.real() ) < 0.001 )
222 cerr << "-shiftlimit: A shift search radius must be specified!" << endl;
223 if ( curropt->tag == "symmetry" )
224 sym = curropt->symmetry();
225 if ( curropt->tag == "bin" ) {
226 if ( ( bin[0] = curropt->value.integer() ) < 1 )
227 cerr << "-bin: A bin size must be specified!" << endl;
228 else {
229 if ( bin[0] < 1 ) bin[0] = 1;
230 bin[2] = bin[1] = bin[0];
231 }
232 }
233 if ( curropt->tag == "accuracy" ) {
234 if ( ( accuracy = curropt->value.real() ) < 0.001 )
235 cerr << "-accuracy: An accuracy in degrees must be specified!" << endl;
236 else
237 accuracy *= M_PI/180.0;
238 }
239 if ( curropt->tag == "recid" )
240 rec_id = curropt->value;
241 if ( curropt->tag == "Template" )
242 template_file = curropt->filename();
243 if ( curropt->tag == "mask" )
244 rs_mask = curropt->filename();
245 if ( curropt->tag == "Mask" )
246 fs_mask = curropt->filename();
247 if ( curropt->tag == "Postscript" )
248 ps_file = curropt->filename();
249 if ( curropt->tag == "output" )
250 param_file = curropt->filename();
251 if ( curropt->tag == "particle" )
252 newpart_file = curropt->filename();
253 if ( curropt->tag == "newtemplate" )
254 newtemp_file = curropt->filename();
255 }
256 option_kill(option);
257
258 double ti = timer_start();
259
260 int read_img_num = img_num - 1;
261 int cnt(1), found(0);
262 Bimage* p = NULL;
263 Bimage* ptemp = NULL;
264 Bstring filename;
265 Vector3<double> scale(1,1,1);
266 Vector3<long> size;
267 Bproject* project = NULL;
268 Breconstruction* rec = NULL;
269 Bparticle* part = NULL;
270
271 // Sets up the input image filename
272 // If the input file is a parameter file, find the reconstruction or particle to process
273 if ( optind < argc ) {
274 filename = argv[optind++];
275 if ( file_type(filename) == Micrograph ) {
276 project = read_project(filename);
277 part_set_FOM(project, 0, 0);
278 if ( set_seq_sel )
279 for ( rec = project->rec; rec; rec = rec->next )
280 for ( part = rec->part; part; part = part->next ) part->sel = cnt++;
281 rec = project->rec;
282 if ( sel_num > 0 ) { // Finds the first particle with this selection number
283 for ( found=0, rec = project->rec; rec && !found; ) {
284 for ( part = rec->part; part && !found; ) {
285 if ( part->sel == sel_num ) found = 1;
286 else part = part->next;
287 }
288 if ( !found ) rec = rec->next;
289 }
290 } else { // Finds the specified particle and image number
291 if ( rec_id.length() )
292 for ( rec = project->rec; rec && rec_id != rec->id; rec = rec->next ) ;
293 if ( rec ) {
294 for ( part = rec->part; part && part->id != img_num; part = part->next ) ;
295 } else {
296 cerr << "Error: No reconstruction with ID = " << rec_id << endl;
297 bexit(-1);
298 }
299 }
300 if ( rec ) {
301 filename = rec->frec;
302 if ( rec->fpart.length() ) filename = rec->fpart;
303 if ( part ) {
304 img_num = part->id;
305 read_img_num = part->id - 1;
306 if ( !currview_set ) {
307 currview = part->view;
308 currview_set = 1;
309 }
310 // cout << "part->ori=" << part->ori << endl;
311 if ( part_ori.length() < 1 && part->ori.length() ) part_ori = part->ori;
312 if ( part->fpart.length() ) {
313 filename = part->fpart;
314 read_img_num = 0;
315 }
316 if ( verbose ) {
317 cout << "Processing particle " << part->id << ":" << endl;
318 cout << "Origin: " << part->ori << endl;
319 cout << "View: " << part->view << endl;
320 // cout << "Current view: " << currview << endl;
321 }
322 } else {
323 cerr << "Error: Particle not defined!" << endl;
324 bexit(-1);
325 }
326 if ( !currview_set ) {
327 currview = rec->view;
328 currview_set = 1;
329 }
330 } else {
331 cerr << "Error: Reconstruction not defined!" << endl;
332 bexit(-1);
333 }
334 }
335 if ( filename.length() < 1 ) {
336 cerr << "Error: No image file name found!" << endl;
337 bexit (-1);
338 }
339 }
340
341 // cout << "part_ori=" << part_ori << endl;
342
343 View* view = NULL;
344 Vector3<double> origin, currshift, bestshift;
345 double cc, best_cc(-1e37);
346
347 Matrix3 mat = ref_view.matrix();
348 if ( !sym ) sym = init_point_group_symmetry("C1");
349 for ( i=0; i<sym->n; i++ )
350 sym->op[i].axis = mat * sym->op[i].axis;
351
352 bestview = currview;
353
354 if ( global_bin[0] > 0 || !currview_set ) {
355
356 if ( side_ang < 0 )
357 view = asymmetric_unit_views(sym, theta_step, phi_step, alpha_step, 1);
358 else
359 view = side_views(sym, side_ang, theta_step, phi_step, alpha_step);
360
361 if ( verbose & VERB_FULL )
362 show_views(view);
363
364 if ( view_subset > 0 ) if ( view_list_subset(&view, view_start, view_subset) < 1 ) {
365 cerr << "Error: At least one view must be selected!" << endl;
366 bexit(-1);
367 }
368
369 if ( ps_file.length() && view ) ps_views(ps_file, sym->label, view, 0);
370
371 if ( verbose )
372 cout << "Number of global views: " << count_list((char *) view) << endl << endl;
373
374 origin = temp_ori;
375
376 vector<Bimage*> imgvec = setup_images(filename, template_file, rs_mask, fs_mask,
377 read_img_num, global_bin, sam, set_origin, origin, part_ori);
378
379 p = imgvec[0];
380
381 best_cc = p->search_views(imgvec[1], view, hires, lores,
382 search_radius/global_bin[0], imgvec[2], bestview, bestshift);
383
384 kill_list((char *) view, sizeof(View));
385 view = NULL;
386
387 for ( auto it = imgvec.begin(); it != imgvec.end(); ++it ) delete *it;
388
389 if ( global_bin[0] != bin[0] )
390 bestshift *= Vector3<double>(global_bin[0]/bin[0], global_bin[1]/bin[1], global_bin[2]/bin[2]);
391 }
392
393 if ( mode.length() ) {
394 if ( bin[0] > 1 ) search_radius /= bin[0];
395 origin = temp_ori;
396
397 vector<Bimage*> imgvec = setup_images(filename, template_file, rs_mask, fs_mask,
398 read_img_num, bin, sam, set_origin, origin, part_ori);
399
400 p = imgvec[0];
401
402 if ( mode == "directional" ) {
403 view = views_within_limits(bestview, theta_step, phi_step, alpha_step, angle_limit, M_PI);
404 if ( verbose ) {
405 cout << "Central view: " << bestview << endl;
406 cout << "Number of directional views: " << count_list((char *) view) << endl << endl;
407 }
408 } else if ( mode == "symmetric" ) {
409 view = symmetry_get_all_views(sym, bestview);
410 if ( verbose )
411 cout << "Number of symmetry views: " << count_list((char *) view) << endl << endl;
412 }
413
414 if ( mode == "directional" || mode == "symmetric" ) {
415 best_cc = p->search_views(imgvec[1], view, hires, lores,
416 search_radius, imgvec[2], bestview, bestshift);
417 kill_list((char *) view, sizeof(View));
418 } else if ( mode == "refine" ) {
419 currview = bestview;
420 best_cc = -1;
421 cnt = 0;
422 if ( accuracy < 2.0/p->sizeX() ) accuracy = 2.0/p->sizeX();
423 while ( alpha_step >= accuracy ) {
424 if ( hires > alpha_step * p->real_size()[0] )
425 hires = alpha_step * p->real_size()[0];
426 view = views_for_refinement(bestview, alpha_step);
427 cc = p->search_views(imgvec[1], view, hires, lores,
428 search_radius, imgvec[2], bestview, currshift);
429 if ( currview.residual(bestview) < 1e-6 ||
430 fabs(cc - best_cc) < 1e-6 ||
431 cnt > 3 ) {
432 alpha_step /= 2; // Contract around best point
433 cnt = 0;
434 }
435 if ( best_cc < cc ) {
436 best_cc = cc;
437 bestview = currview;
438 bestshift = currshift;
439 }
440 kill_list((char *) view, sizeof(View));
441 cnt++;
442 }
443 }
444
445 for ( auto it = imgvec.begin(); it != imgvec.end(); ++it ) delete *it;
446 }
447
448 if ( bin[0] ) bestshift *= Vector3<double>(bin[0], bin[1], bin[2]);
449
450 if ( newpart_file.length() < 1 && optind < argc ) newpart_file = argv[optind];
451
452 currshift = -bestshift;
453
454 if ( newtemp_file.length() ) { // Output transformed template
455 mat = bestview.matrix();
456 ptemp = read_img(template_file, 1, 0);
457 if ( set_origin & 1 ) ptemp->origin(temp_ori);
458 else if ( set_origin & 2) ptemp->origin(ptemp->size()/2);
459 mat = mat.transpose();
460 ptemp->calculate_background();
461 ptemp->transform(scale, ptemp->image->origin(), currshift, mat, FILL_BACKGROUND, 0);
462 ptemp->view(bestview);
463 if ( nudatatype == Unknown_Type ) nudatatype = p->data_type(); // Preserve the old type
464 ptemp->change_type(nudatatype);
465 ptemp->label(get_cmd_line(argc, argv));
466 write_img(newtemp_file, ptemp, 0);
467 delete ptemp;
468 }
469
470 Bimage* ps = NULL;
471
472 if ( newpart_file.length() ) { // Output transformed image
473 // cout << "origin=" << origin << " shift=" << bestshift << " view=" << bestview << endl;
474 mat = bestview.matrix();
475 p = read_img(filename, 1, read_img_num);
476 ptemp = read_img(template_file, 0, 0);
477 if ( p->size().distance(ptemp->size()) > 0.5 || p->real_size().distance(ptemp->real_size()) > 0.1 ) {
478 ps = p->scale_to_same_size(ptemp);
479 delete p;
480 p = ps;
481 }
482 delete ptemp;
483 origin += currshift; // Origin for rotation
484 p->calculate_background();
485 // cout << "origin=" << origin << " shift=" << bestshift << " view=" << bestview << endl;
486 p->transform(scale, origin, bestshift, mat, FILL_BACKGROUND, 0);
487 p->image->view(0,0,1,0);
488 if ( nudatatype == Unknown_Type ) nudatatype = p->data_type(); // Preserve the old type
489 p->change_type(nudatatype);
490 if ( nustd > 0 ) p->rescale_to_avg_std(nuavg, nustd);
491 p->label(get_cmd_line(argc, argv));
492 write_img(newpart_file, p, 0);
493 delete p;
494 }
495
496 if ( param_file.length() ) {
497 p = read_img(filename, 0, 0);
498 if ( !project ) project = project_init();
499 if ( !rec ) {
500 if ( rec_id.length() < 1 ) {
501 rec_id = p->file_name();
502 rec_id = rec_id.pre_rev('.');
503 }
504 rec = reconstruction_add(&project->rec, rec_id);
505 part = particle_add(&rec->part, img_num);
506 }
507 if ( sam[0] > 0 ) rec->voxel_size = sam[0];
508 else if ( p ) rec->voxel_size = p->sampling()[0];
509 delete p;
510 rec->symmetry = sym->label;
511 if ( part ) {
512 if ( rec->fpart.length() < 1 ) part->fpart = filename;
513 if ( newpart_file.length() ) {
514 part->fpart = newpart_file;
515 } else {
516 part->view = bestview;
517 part->ori = origin + currshift;
518 }
519 for ( part = rec->part; part; part = part->next )
520 if ( part->id == img_num ) part->fom[0] = best_cc;
521 else part->fom[0] = 0;
522 } else {
523 rec->frec = filename;
524 if ( newpart_file.length() ) {
525 rec->frec = newpart_file;
526 } else {
527 rec->view = bestview;
528 rec->origin = origin + currshift;
529 }
530 for ( rec = project->rec; rec; rec = rec->next )
531 if ( rec->id == rec_id ) rec->fom = best_cc;
532 else rec->fom = 0;
533 }
534 project_update_comment(project, argc, argv);
535 write_project(param_file, project, 0, 0);
536 }
537
538 project_kill(project);
539 kill_symmetry(sym);
540
541 if ( verbose & VERB_TIME )
542 timer_report(ti);
543
544 bexit(0);
545 }
546
547
548 vector<Bimage*> setup_images(Bstring& map_file, Bstring& template_file,
549 Bstring& rs_mask, Bstring& fs_mask,
550 int read_img_num, Vector3<long>& bin, Vector3<double> sam,
551 int set_origin, Vector3<double>& origin, Vector3<double>& part_ori)
552 {
553 int err(0);
554
555 Bimage* p = NULL;
556 Bimage* ptemp = NULL;
557 Bimage* prs_mask = NULL;
558 Bimage* pfs_mask = NULL;
559
560 if ( map_file.length() < 1 ) {
561 cerr << "Error: No image file name specified!" << endl;
562 err--;
563 } else {
564 p = read_img(map_file, 1, read_img_num);
565 if ( p ) {
566 if ( sam.volume() > 0 ) p->sampling(sam);
567 if ( set_origin & 4 ) p->origin(part_ori);
568 else if ( set_origin & 8 ) p->origin(p->size()/2);
569 part_ori = p->image->origin();
570 } else {
571 cerr << "Error: " << map_file << " not read!" << endl;
572 err--;
573 }
574 }
575
576 if ( template_file.length() < 1 ) {
577 cerr << "Error: No input template file specified!" << endl;
578 err--;
579 } else {
580 ptemp = read_img(template_file, 1, 0);
581 if ( ptemp ) {
582 if ( sam.volume() > 0 ) ptemp->sampling(sam);
583 if ( set_origin & 1 ) ptemp->origin(origin);
584 else if ( set_origin & 2 ) ptemp->origin(ptemp->size()/2);
585 origin = ptemp->image->origin();
586 } else {
587 cerr << "Error: " << template_file << " not read!" << endl;
588 err--;
589 }
590 }
591
592 if ( rs_mask.length() ) {
593 prs_mask = read_img(rs_mask, 1, 0);
594 if ( !prs_mask ) {
595 cerr << "Error: " << rs_mask << " not read!" << endl;
596 err--;
597 }
598 ptemp->multiply(prs_mask);
599 delete prs_mask;
600 }
601
602 if ( fs_mask.length() ) {
603 pfs_mask = read_img(fs_mask, 1, 0);
604 if ( !pfs_mask ) {
605 cerr << "Error: " << fs_mask << " not read!" << endl;
606 err--;
607 }
608 }
609
610 if ( err ) {
611 cerr << "Too many errors! (" << -err << ")" << endl;
612 bexit(-1);
613 }
614
615 Bimage* ps = NULL;
616
617 if ( p->size().distance(ptemp->size()) > 0.5 && p->real_size().distance(ptemp->real_size()) > 0.1 ) {
618 ps = p->scale_to_same_size(ptemp);
619 delete p;
620 p = ps;
621 }
622
623 if ( bin[0] > 1 ) {
624 if ( p ) p->bin(bin);
625 if ( ptemp ) ptemp->bin(bin);
626 if ( pfs_mask ) pfs_mask->bin(bin);
627 } else {
628 bin = Vector3<long>(1,1,1);
629 }
630
631 if ( verbose ) {
632 if ( p )
633 cout << "Map file: " << p->file_name() << " (" << read_img_num << ")" << endl;
634 if ( ptemp )
635 cout << "Template file: " << ptemp->file_name() << endl;
636 if ( pfs_mask )
637 cout << "Mask file: " << pfs_mask->file_name() << endl;
638 cout << "Size: " << p->size() << endl;
639 cout << endl;
640 }
641
642 vector<Bimage*> imgvec;
643 imgvec.push_back(p);
644 imgvec.push_back(ptemp);
645 imgvec.push_back(pfs_mask);
646
647 return imgvec;
648 }
649
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
Bparticle::id
int id
Definition: mg_processing.h:92
rwmg.h
Header file for reading and writing micrograph parameters.
Bstring::real
double real()
Definition: Bstring.cpp:545
setup_images
vector< Bimage * > setup_images(Bstring &map_file, Bstring &template_file, Bstring &rs_mask, Bstring &fs_mask, int read_img_num, Vector3< long > &bin, Vector3< double > sam, int set_origin, Vector3< double > &origin, Vector3< double > &part_ori)
Definition: bfind.cpp:548
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
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
views_within_limits
View * views_within_limits(View theview, double theta_step, double phi_step, double alpha_step, double view_angle_limit, double alpha_angle_limit)
Generates a list of views within an angular distance from the input view.
Definition: View.cpp:207
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Vector3::length
double length()
Definition: Vector3.h:222
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
Bsymmetry::n
int n
Definition: symmetry.h:42
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
mg_particle_select.h
Select particles.
show_views
int show_views(View *v)
Displays a linked list of views.
Definition: View.cpp:28
views_for_refinement
View * views_for_refinement(View theview, double alpha_step)
Generates a 3x3 grid of views around an input view.
Definition: View.cpp:285
symmetry.h
Header file for general symmetry functions.
utilities.h
Header file for general utilities.
Breconstruction::fom
double fom
Definition: mg_processing.h:302
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Breconstruction
Definition: mg_processing.h:280
Boption::tag
Bstring tag
Definition: options.h:29
Bimage::scale_to_same_size
Bimage * scale_to_same_size(Bimage *pref)
Scales and image to the given reference.
Definition: Bimage_transform.cpp:740
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
Matrix3
Definition: Matrix3.h:17
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
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
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:29
timer.h
Utilities for timing functions.
M_PI_4
#define M_PI_4
Definition: utilities.h:65
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:487
Micrograph
Definition: file_util.h:23
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bimage::transform
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Definition: Bimage_transform.cpp:37
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
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
Boption::view
View view()
Definition: options.h:259
ps_views
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
Definition: ps_views.cpp:34
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
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
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
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
Breconstruction::symmetry
Bstring symmetry
Definition: mg_processing.h:286
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
file_util.h
Header file for file checking functions.
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
part_set_FOM
long part_set_FOM(Bproject *project, int fom_index, double fom)
Sets the FOM for all particles.
Definition: mg_particle_select.cpp:357
use
const char * use[]
Definition: bfind.cpp:31
Bimage::view
void view(double vx, double vy, double vz, double va)
Definition: Bimage.h:589
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
Bsymmetry
Definition: symmetry.h:38
Boption::datatype
DataType datatype()
Definition: options.h:93
view_list_subset
int view_list_subset(View **view_list, int start, int size)
Replaces a view list with a subset of it.
Definition: View.cpp:474
Boption::next
Boption * next
Definition: options.h:28
Bparticle
Definition: mg_processing.h:89
Bstring
Definition: Bstring.h:29
View::residual
double residual(const View &view)
Definition: View.h:165
Bimage::search_views
double search_views(Bimage *ptemp, View *view, double hires, double lores, double search_radius, Bimage *pmask, View &currview, Vector3< double > &currshift)
Searches a 2D/3D density map for a template.
Definition: Bimage_search.cpp:34
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
View::matrix
Matrix3 matrix()
Definition: View.h:150
Matrix3::transpose
Matrix3 transpose() const
Definition: Matrix3.h:268
Vector3< long >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
View
Definition: View.h:26
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
mg_processing.h
Header file for micrograph processing.
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bsymmetry::op
Bsymop * op
Definition: symmetry.h:43
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
ps_views.h
Header file for postscript tools dealing with views.
Vector3::volume
double volume()
Definition: Vector3.h:235
project_update_comment
int project_update_comment(Bproject *project, int n, char **strings)
Puts a set of strings and time in the main comment of a project.
Definition: rwmg.cpp:468
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Bsymop::axis
Vector3< double > axis
Definition: symmetry.h:25
Breconstruction::view
View view
Definition: mg_processing.h:295
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
main
int main(int argc, char **argv)
Definition: bfind.cpp:98
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:448
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
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
verbose
int verbose