 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
35 "Usage: bfcc [options] input.img/input.star output.img",
36 "-----------------------------------------------------",
37 "Fast cross-correlation for the best fit of a 3D map to a template.",
38 "Modes: Global: Search an asymmetric unit with a fixed angular step size.",
39 " Directional: Do a search around a view within an angular distance (-limit option).",
40 " Refine: Refine iteratively around a view to some accuracy (-accuracy option).",
41 " Symmetry: Search all symmetry-related views using a given view.",
42 "For modes other than global, the view is taken from the command line (-View option),",
43 " or from the parameter file, or as a last resort from the image header.",
44 "If a parameter file is used as input, the input image is selected based on ",
45 " the reconstruction ID and the particle image number.",
46 "Only one image in a multi-image file will be used (see -image option).",
47 "The output file contains the transformed map only if the input is an image (i.e., not a parameter file).",
48 "Output of the transformed map or template can be specified with the",
49 " -particle and -newtemplate options.",
52 "-global Global search before other modes.",
53 "-mode refine Local modes: directional, refine or symmetric.",
56 "-verbose 7 Verbosity of output.",
57 "-datatype u Force writing of a new data type.",
58 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
59 "-origin 110,50,44 Template image origin (default taken from template file).",
60 "-partorigin 50,80,47 Particle image origin (default taken from particle file).",
61 "-kernel 6,2 Kernel for reciprocal space interpolation: size and power.",
62 "-resolution 15.6,200 Resolution limits for cross-correlation (default 0).",
63 "-shiftlimit 5.2 Radial limit to search for shift in cross-correlation map (default 1/4 of map).",
66 "-setsequential Set particle selection numbers sequentially.",
67 "-recid A435 The 3D reconstruction ID (should correspond to that in the parameter file).",
68 "-image 2 Image number in a multi-image file or particle number (default 1=first image).",
69 "-select 5 Particle selection number in parameter file (default not used).",
72 "-angles 8.8,2.5,5.2 Step size for alpha, theta and phi, one value sets all (default 45 degrees).",
73 "-side 15 Generate side view projections within the given angle from the equator.",
75 "Parameters for the global and symmetric modes:",
76 "-symmetry D6 Symmetry: Point group identifier.",
78 "Parameters for the directional and refinement modes:",
79 "-View 0.3,-0.5,0.8,33 View to initiate search: vector {xyz} and angle.",
81 "Parameters for the directional mode:",
82 "-limit 17.5 Radial limit around given view (default 20 degrees).",
84 "Parameters for the refinement mode:",
85 "-accuracy 0.3 Accuracy (default 0.5 degrees).",
88 "-Template image.map Template to search for.",
89 "-Mask mask.tif Mask in reciprocal space to apply during cross-correlation.",
93 "-output file.star Parameter output file with best orientation.",
94 "-particle newpart.pif New transformed particle file.",
95 "-newtemplate newtemp.pif New transformed template file.",
100 int main(
int argc,
char **argv)
116 double alpha_step(
M_PI_4);
117 double theta_step(
M_PI_4);
120 double angle_limit(
M_PI/9.0);
122 double hires(0), lores(0);
123 double search_radius(-1);
128 double accuracy(
M_PI/360.0);
139 for ( curropt = option; curropt; curropt = curropt->
next ) {
140 if ( curropt->
tag ==
"global" ) global = 1;
141 if ( curropt->
tag ==
"mode" ) {
143 if ( curropt->
value[0] ==
'd' || curropt->
value[0] ==
'D' ) mode =
"directional";
144 if ( curropt->
value[0] ==
'r' || curropt->
value[0] ==
'R' ) mode =
"refine";
145 if ( curropt->
value[0] ==
's' || curropt->
value[0] ==
'S' ) mode =
"symmetric";
147 cerr <<
"-mode: A mode must be specified" << endl;
149 if ( curropt->
tag ==
"setsequential" ) set_seq_sel = 1;
150 if ( curropt->
tag ==
"image" )
152 cerr <<
"-image: An image number must be specified" << endl;
153 if ( curropt->
tag ==
"select" )
155 cerr <<
"-select: A selection number must be specified" << endl;
156 if ( curropt->
tag ==
"datatype" )
158 if ( curropt->
tag ==
"sampling" )
159 sam = curropt->
scale();
160 if ( curropt->
tag ==
"origin" ) {
161 if ( curropt->
value[0] ==
'c' ) {
164 origin = curropt->
origin();
168 if ( curropt->
tag ==
"partorigin" )
169 part_ori = curropt->
origin();
170 if ( curropt->
tag ==
"kernel" )
171 if ( curropt->
values(kernel_width, kernel_power) < 1 )
172 cerr <<
"-kernel: At least the kernel size must be specified!" << endl;
173 if ( curropt->
tag ==
"angles" ) {
174 if ( ( i = curropt->
values(alpha_step, theta_step, phi_step) ) < 1 )
175 cerr <<
"-angles: An angle step size must be specified" << endl;
177 if ( i < 2 ) phi_step = theta_step = alpha_step;
178 else if ( i < 3 ) phi_step = theta_step;
179 alpha_step *=
M_PI/180.0;
180 theta_step *=
M_PI/180.0;
181 phi_step *=
M_PI/180.0;
184 if ( curropt->
tag ==
"side" ) {
185 if ( ( side_ang = curropt->
value.
real() ) < 0.1 )
186 cerr <<
"-side: One angle must be specified!" << endl;
188 side_ang *=
M_PI/180.0;
190 if ( curropt->
tag ==
"limit" ) {
191 if ( ( angle_limit = curropt->
value.
real() ) < 0.1 )
192 cerr <<
"-limit: An angular limit must be specified!" << endl;
194 angle_limit *=
M_PI/180.0;
196 if ( curropt->
tag ==
"View" ) {
197 currview = curropt->
view();
200 if ( curropt->
tag ==
"resolution" )
201 if ( curropt->
values(hires, lores) < 1 )
202 cerr <<
"-resolution: A resolution must be specified!" << endl;
203 if ( curropt->
tag ==
"shiftlimit" )
204 if ( ( search_radius = curropt->
value.
real() ) < 1 )
205 cerr <<
"-shiftlimit: A shift search radius must be specified!" << endl;
206 if ( curropt->
tag ==
"symmetry" )
208 if ( curropt->
tag ==
"accuracy" ) {
209 if ( ( accuracy = curropt->
value.
real() ) < 0.1 )
210 cerr <<
"-accuracy: An accuracy in degrees must be specified!" << endl;
212 accuracy *=
M_PI/180.0;
214 if ( curropt->
tag ==
"recid" )
215 rec_id = curropt->
value;
216 if ( curropt->
tag ==
"Template" )
217 template_file = curropt->
filename();
218 if ( curropt->
tag ==
"Mask" )
220 if ( curropt->
tag ==
"Postscript" )
222 if ( curropt->
tag ==
"output" )
224 if ( curropt->
tag ==
"particle" )
226 if ( curropt->
tag ==
"newtemplate" )
233 int read_img_num = img_num - 1;
247 if ( kernel_width < 4 ) kernel_width = 4;
248 if ( kernel_power < 2 ) kernel_power = 2;
252 if ( optind < argc ) {
253 filename = argv[optind++];
259 for ( part = rec->
part; part; part = part->
next ) part->
sel = cnt++;
262 for ( found=0, rec =
project->
rec; rec && !found; ) {
263 for ( part = rec->
part; part && !found; ) {
264 if ( part->
sel == sel_num ) found = 1;
265 else part = part->
next;
267 if ( !found ) rec = rec->
next;
273 for ( part = rec->
part; part && part->
id != img_num; part = part->
next ) ;
275 cerr <<
"Error: No reconstruction with ID = " << rec_id << endl;
280 filename = rec->
frec;
284 read_img_num = part->
id - 1;
285 if ( !currview_set ) {
286 currview = part->
view;
292 filename = part->
fpart;
296 cerr <<
"Error: Particle not defined!" << endl;
299 if ( !currview_set ) {
300 currview = rec->
view;
304 cerr <<
"Error: Reconstruction not defined!" << endl;
308 if ( filename.
length() < 1 ) {
309 cerr <<
"Error: No image file name found!" << endl;
316 if ( filename.
length() < 1 ) {
317 cerr <<
"Error: No image file name specified!" << endl;
319 p =
read_img(filename, 1, read_img_num);
325 cerr <<
"Error: %s not read!" << filename << endl;
329 if ( template_file.
length() < 1 ) {
330 cerr <<
"Error: No input template file specified!" << endl;
332 ptemp =
read_img(template_file, 1, 0);
336 if ( set_origin == 2 ) ptemp->
origin(ptemp->
size()/2);
337 else ptemp->
origin(origin);
340 cerr <<
"Error: " << template_file <<
" not read!" << endl;
344 if ( mask_file.
length() ) {
347 cerr <<
"Error: " << mask_file <<
" not read!" << endl;
351 if ( search_radius < 1 ) search_radius = ptemp->
sizeX()/4;
356 cout <<
"Finding a template in a map:" << endl;
357 cout <<
"Template: " << ptemp->
file_name() << endl;
358 cout <<
"Map: " << p->
file_name() <<
" (" << read_img_num <<
")" << endl;
359 if ( pmask ) cout <<
"Mask: " << pmask->
file_name() << endl;
360 cout <<
"Template origin: " << ptemp->
image->
origin() << endl;
361 cout <<
"Map origin: " << p->
image->
origin() << endl;
362 cout <<
"Resolution range: ";
363 if ( lores <= 0 ) cout <<
"inf";
365 cout <<
" - " << hires <<
" A" << endl;
366 cout <<
"Shift search radius: " << search_radius <<
" pixels" << endl;
367 cout <<
"Kernel width and power: " << kernel_width <<
" " << kernel_power << endl << endl;
368 cout <<
"Angle\tShift\t\t\tView\t\t\t\tCC" << endl;
373 if ( !pc )
bexit(-1);
379 pc->
fft(FFTW_FORWARD, 0);
391 View* view = NULL, *view2 = NULL;
393 double cc, best_cc = -1e37;
397 for ( i=0; i<sym->
n; i++ )
402 if ( global || !currview_set ) {
408 view =
side_views(sym, side_ang, theta_step, phi_step);
425 search_radius, pmask);
430 cout << alpha_step*180.0/
M_PI <<
tab << bestshift <<
tab << bestview <<
tab << best_cc << endl;
436 if ( mode ==
"directional" ) {
439 cout <<
"Central view: " << bestview << endl;
440 cout <<
"Number of directional views: " <<
count_list((
char *) view) << endl << endl;
442 }
else if ( mode ==
"symmetric" ) {
445 cout <<
"Number of symmetry views: " <<
count_list((
char *) view) << endl << endl;
451 if ( mode ==
"directional" || mode ==
"symmetric" ) {
456 }
else if ( mode ==
"refine" ) {
459 while ( alpha_step >= accuracy ) {
463 if ( currview.
residual(bestview) < 1e-6 ) alpha_step /= 2;
464 if ( best_cc < cc ) {
471 cout << alpha_step*180.0/
M_PI <<
tab << bestshift <<
tab << bestview <<
tab << best_cc << endl;
478 search_radius, pmask);
483 cout <<
"Best view:\t" << setprecision(4) <<
484 bestshift[0] <<
tab << bestshift[1] <<
tab << bestshift[2] <<
tab <<
485 bestview[0] <<
tab << bestview[1] <<
tab << bestview[2] <<
tab <<
493 if ( newpart_file.
length() < 1 && optind < argc ) newpart_file = argv[optind];
495 if ( newtemp_file.
length() ) {
496 ptemp =
read_img(template_file, 1, 0);
502 ptemp->
view(bestview);
509 if ( newpart_file.
length() ) {
510 p =
read_img(filename, 1, read_img_num);
523 if ( param_file.
length() ) {
527 if ( rec_id.
length() < 1 ) {
538 part->
fpart = filename;
539 if ( newpart_file.
length() ) {
540 part->
fpart = newpart_file;
543 part->
view = bestview;
544 part->
ori = origin - bestshift;
546 for ( part = rec->
part; part; part = part->
next )
547 if ( part->
id == img_num ) part->
fom[0] = best_cc;
548 else part->
fom[0] = 0;
550 rec->
frec = filename;
551 if ( newpart_file.
length() ) {
552 rec->
frec = newpart_file;
555 rec->
view = bestview;
556 rec->
origin = origin - bestshift;
559 if ( rec->
id == rec_id ) rec->
fom = best_cc;
594 if ( !p )
return -1e37;
596 long n, nviews, ibest;
601 double* cc =
new double[nviews];
604 cout <<
"Number of views: " << nviews << endl;
607 dispatch_apply(nviews, dispatch_get_global_queue(0, 0), ^(
size_t k){
611 #pragma omp parallel for
612 for ( n=0; n<nviews; n++ )
616 double ccmin(1), ccmax(-1), ccavg(0), ccstd(0);
618 for ( n=ibest=0; n<nviews; n++ ) {
619 if ( best < cc[n] ) {
623 if ( ccmin > cc[n] ) ccmin = cc[n];
624 if ( ccmax < cc[n] ) ccmax = cc[n];
626 ccstd += cc[n]*cc[n];
630 ccstd = ccstd/n - ccavg*ccavg;
631 if ( ccstd > 0 ) ccstd = sqrt(ccstd);
635 cout <<
"Min, max, avg, std: " << ccmin <<
" " << ccmax <<
" " << ccavg <<
" " << ccstd << endl;
637 p->
view(view_arr[ibest]);
668 double minrad = (lores>0)? ptemp->
real_size()[0]/lores: 0;
669 double maxrad = (hires>0)? ptemp->
real_size()[0]/hires: ptemp->
sizeX()/2;
670 if ( maxrad > ptemp->
sizeX()/2 ) maxrad = ptemp->
sizeX()/2;
679 double d, pwr1(0), pwr2(0), cc(0);
683 for ( c[2]=min[2]; c[2]<=max[2]; c[2]+=1 ) {
684 for ( c[1]=min[1]; c[1]<=max[1]; c[1]+=1 ) {
685 for ( c[0]=min[0]; c[0]<=max[0]; c[0]+=1 ) {
687 if ( d >= minrad && d <= maxrad ) {
689 if ( ci[0] < 0 ) ci[0] += p->
sizeX();
690 if ( ci[1] < 0 ) ci[1] += p->
sizeY();
691 if ( ci[2] < 0 ) ci[2] += p->
sizeZ();
692 i = (ci[2]*p->
sizeY() + ci[1])*p->
sizeX() + ci[0];
693 if ( !pmask || ( pmask && (*pmask)[i] ) ) {
708 if ( d > 0 ) cc = cv.
amp()/sqrt(d);
711 cout << view <<
tab << n <<
tab << cc << endl;
741 double minrad = (lores>0)? ptemp->
real_size()[0]/lores: 0;
742 double maxrad = ptemp->
real_size()[0]/hires;
743 if ( maxrad > ptemp->
sizeX()/2 ) maxrad = ptemp->
sizeX()/2;
750 double d, pwr1(0), pwr2(0);
755 for ( c[2]=min[2]; c[2]<=max[2]; c[2]+=1 ) {
756 for ( c[1]=min[1]; c[1]<=max[1]; c[1]+=1 ) {
757 for ( c[0]=min[0]; c[0]<=max[0]; c[0]+=1 ) {
759 if ( d >= minrad && d <= maxrad ) {
761 if ( ci[0] < 0 ) ci[0] += p->
sizeX();
762 if ( ci[1] < 0 ) ci[1] += p->
sizeY();
763 if ( ci[2] < 0 ) ci[2] += p->
sizeZ();
764 i = (ci[2]*p->
sizeY() + ci[1])*p->
sizeX() + ci[0];
765 if ( !pmask || ( pmask && (*pmask)[i] ) ) {
778 double scale = 1/sqrt(pwr1*pwr2);
780 for ( i=0; i<pcc->
data_size(); i++ ) pcc->
set(i, (*pcc)[i] * scale);
782 pcc->
fft(FFTW_BACKWARD, 0);
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
View * views_for_refinement(View theview, double alpha_step)
Generates a 3x3 grid of views around an input view.
Vector3< double > real_size()
Vector3< double > scale()
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Header file for file checking functions.
void set(long j, double v)
Sets a single value at the given index.
Vector3< double > voxel_size
Matrix3 transpose() const
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
int find_peak(double radius=1e30, double sigma=0)
Finds the peak in an image to the nearest voxel.
int bexit(int value)
Exit function for cleanup and debugging.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Vector3< long > size() const
Header file for option handlers.
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
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.
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.
void view(double x, double y, double z, double a)
Vector3< double > origin()
long count_list(char *list)
Counts the number of items in a linked list.
View * view_array(View *views, long &n)
Copies views from a list into an array.
int refine_peak()
Refines the position of a peak to sub-voxel resolution.
int phase_shift(Vector3< double > shift)
Phase shifts a complex image.
Bimage * unpack_combined_transform()
Unpacks a complex transform obtained from two real images.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for reading and writing micrograph parameters.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
View * view_list_expand_angles(View *views, double amin, double amax, double astep)
Expands each view to several views with different rotation angles.
long part_set_FOM(Bproject *project, int fom_index, double fom)
Sets the FOM for all particles.
General image parameter class.
Utilities for timing functions.
double img_fcc_search(Bimage *p, Bimage *ptemp, View *view, FSI_Kernel *kernel, double hires, double lores, Bimage *pmask)
Fast cross-correlation searches a 2D/3D density map for a template.
int main(int argc, char **argv)
Complex< double > fspace_interpolate(long img_num, Vector3< double > m, FSI_Kernel *kernel)
Calculates the complex value at an image location by kernel-based interpolation.
Complex< double > complex(long j)
Returns a complex value at the given index.
double img_fcc_for_view(Bimage *p, Bimage *ptemp, View view, FSI_Kernel *kernel, double hires, double lores, Bimage *pmask)
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.
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.
double timer_start()
Starts timer and prints the time.
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Header file for general utilities.
ostream & tab(ostream &out)
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Header file for 2D and 3D image I/O.
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Header file for micrograph processing.
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Header file for generalized linked list functions.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
double residual(const View &view)
DataType
Base data type specifier.
int phase_shift_to_origin()
Phase shifts a set of reflections to the image origin.
int show_views(View *v)
Displays a linked list of views.
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
double img_cc_for_view(Bimage *p, Bimage *ptemp, View view, FSI_Kernel *kernel, double hires, double lores, double searchrad, Bimage *pmask)
void view(double vx, double vy, double vz, double va)
void complex_to_real()
The real part of a complex image is written to a simple image.
FileType file_type(const char *filename)
Checks the file type using the extension and contents.