 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
36 "Usage: bfind [options] input.img/input.star output.img",
37 "------------------------------------------------------",
38 "Searches orientation space for the best fit of a 3D map to a template.",
39 "Modes: Global: Search an asymmetric unit with a fixed angular step size.",
40 " Directional: Do a search around a view within an angular distance (-limit option).",
41 " Refine: Refine iteratively around a view to some accuracy (-accuracy option).",
42 " Symmetry: Search all symmetry-related views using a given view.",
43 "For modes other than global, the view is taken from the command line (-View option),",
44 " or from the parameter file, or as a last resort from the image header.",
45 "If a parameter file is used as input, the input image is selected based on ",
46 " the reconstruction ID and the particle image number.",
47 "Only one image in a multi-image file will be used (see -image option).",
48 "The output file contains the transformed map only if the input is an image (i.e., not a parameter file).",
49 "Specify the output of the transformed map or template with the",
50 " -particle and -newtemplate options.",
53 "-global 2 Global search before other modes with binning.",
54 "-mode refine Local modes: directional, refine or symmetric.",
55 "-setsequential Set particle selection numbers sequentially.",
56 "-subset 25,5 View subset selection from a start offset and with a given size.",
57 "-rescale -0.1,5.2 Rescale output particle to average and standard deviation.",
60 "-verbose 7 Verbosity of output.",
61 "-datatype u Force writing of a new data type.",
62 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
63 "-origin 110,50,44 Template image origin (default taken from template file).",
64 "-partorigin 50,80,47 Particle image origin (default taken from particle file).",
65 "-angles 8.8,2.5,5.2 Step size for alpha, theta and phi, one value sets all (default 45 degrees).",
66 "-side 15 Generate side view projections within the given angle from the equator.",
67 "-resolution 15.6,200 Resolution limits for cross-correlation (default 0).",
68 "-shiftlimit 5.2 Radial limit to search for shift in cross-correlation map (default 1/4 of map).",
69 "-recid A435 The 3D reconstruction ID (should correspond to that in the parameter file).",
70 "-image 2 Image number in a multi-image file or particle number (default 1=first image).",
71 "-select 5 Particle selection number in parameter file (default not used).",
72 "-bin 3 Binning of input, template and mask by given kernel size,",
73 " output image remains same size as input (only for local modes).",
75 "Parameters for the global and symmetric modes:",
76 "-symmetry D6 Symmetry: Point group identifier.",
78 "Paramweters 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 Smallest angle step size (default 0.5 degrees).",
88 "-Template image.map Template to search for.",
89 "-mask rs_mask.mrc Mask in real space to apply before cross-correlation.",
90 "-Mask fs_mask.mrc Mask in reciprocal space to apply during cross-correlation.",
93 "-Postscript plot.ps Output postscript file with a plot of global view vectors.",
94 "-output file.star Parameter output file with best orientation.",
95 "-ppx Write temporary particle parameter files to directory \"ppx\".",
96 "-json file.json JSON single particle output file with best orientation.",
97 "-particle newpart.pif New transformed particle file.",
98 "-newtemplate newtemp.pif New transformed template file.",
103 int main(
int argc,
char **argv)
109 double nuavg(0), nustd(0);
121 double alpha_step(
M_PI_4);
122 double theta_step(
M_PI_4);
125 double angle_limit(
M_PI/9.0);
127 double hires(0), lores(0);
128 double search_radius(-1);
147 for ( curropt = option; curropt; curropt = curropt->
next ) {
148 if ( curropt->
tag ==
"global" ) {
150 cerr <<
"-global: A bin size must be specified!" << endl;
152 if ( global_bin[0] < 1 ) global_bin[0] = 1;
153 global_bin[2] = global_bin[1] = global_bin[0];
156 if ( curropt->
tag ==
"mode" ) {
158 if ( curropt->
value[0] ==
'd' || curropt->
value[0] ==
'D' ) mode =
"directional";
159 if ( curropt->
value[0] ==
'r' || curropt->
value[0] ==
'R' ) mode =
"refine";
160 if ( curropt->
value[0] ==
's' || curropt->
value[0] ==
'S' ) mode =
"symmetric";
162 cerr <<
"-mode: A mode must be specified" << endl;
164 if ( curropt->
tag ==
"setsequential" ) set_seq_sel = 1;
165 if ( curropt->
tag ==
"subset" )
166 if ( curropt->
values(view_start, view_subset) < 2 )
167 cerr <<
"-subset: A view subset start and size must be specified" << endl;
168 if ( curropt->
tag ==
"rescale" )
169 if ( curropt->
values(nuavg, nustd) < 2 )
170 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
171 if ( curropt->
tag ==
"image" )
173 cerr <<
"-image: An image number must be specified" << endl;
174 if ( curropt->
tag ==
"select" )
176 cerr <<
"-select: A selection number must be specified" << endl;
177 if ( curropt->
tag ==
"datatype" )
179 if ( curropt->
tag ==
"sampling" )
180 sam = curropt->
scale();
181 if ( curropt->
tag ==
"origin" ) {
182 if ( curropt->
value[0] ==
'c' ) {
185 temp_ori = curropt->
origin();
189 if ( curropt->
tag ==
"partorigin" ) {
190 if ( curropt->
value[0] ==
'c' ) {
193 part_ori = curropt->
origin();
197 if ( curropt->
tag ==
"angles" ) {
198 if ( ( i = curropt->
values(alpha_step, theta_step, phi_step) ) < 1 )
199 cerr <<
"-angles: An angle step size must be specified" << endl;
201 if ( i < 2 ) phi_step = theta_step = alpha_step;
202 else if ( i < 3 ) phi_step = theta_step;
203 alpha_step *=
M_PI/180.0;
204 theta_step *=
M_PI/180.0;
205 phi_step *=
M_PI/180.0;
208 if ( curropt->
tag ==
"side" ) {
209 if ( ( side_ang = curropt->
value.
real() ) < 0.001 )
210 cerr <<
"-side: One angle must be specified!" << endl;
212 side_ang *=
M_PI/180.0;
214 if ( curropt->
tag ==
"limit" ) {
215 if ( ( angle_limit = curropt->
value.
real() ) < 0.001 )
216 cerr <<
"-limit: An angular limit must be specified!" << endl;
218 angle_limit *=
M_PI/180.0;
220 if ( curropt->
tag ==
"View" ) {
221 currview = curropt->
view();
224 if ( curropt->
tag ==
"resolution" )
225 if ( curropt->
values(hires, lores) < 1 )
226 cerr <<
"-resolution: A resolution must be specified!" << endl;
227 if ( curropt->
tag ==
"shiftlimit" )
228 if ( ( search_radius = curropt->
value.
real() ) < 0.001 )
229 cerr <<
"-shiftlimit: A shift search radius must be specified!" << endl;
230 if ( curropt->
tag ==
"symmetry" )
232 if ( curropt->
tag ==
"bin" ) {
234 cerr <<
"-bin: A bin size must be specified!" << endl;
236 if ( bin[0] < 1 ) bin[0] = 1;
237 bin[2] = bin[1] = bin[0];
240 if ( curropt->
tag ==
"accuracy" ) {
241 if ( ( accuracy = curropt->
value.
real() ) < 0.001 )
242 cerr <<
"-accuracy: An accuracy in degrees must be specified!" << endl;
244 accuracy *=
M_PI/180.0;
247 if ( curropt->
tag ==
"recid" )
248 rec_id = curropt->
value;
249 if ( curropt->
tag ==
"Template" )
250 template_file = curropt->
filename();
251 if ( curropt->
tag ==
"mask" )
253 if ( curropt->
tag ==
"Mask" )
255 if ( curropt->
tag ==
"Postscript" )
257 if ( curropt->
tag ==
"output" )
259 if ( curropt->
tag ==
"json" )
261 if ( curropt->
tag ==
"particle" )
263 if ( curropt->
tag ==
"newtemplate" )
270 int read_img_num = img_num - 1;
271 int cnt(1), found(0);
283 if ( optind < argc ) {
284 filename = argv[optind++];
294 for ( found=0, rec =
project->
rec; rec && !found; ) {
295 for ( part = rec->
part; part && !found; ) {
296 if ( part->
sel == sel_num ) found = 1;
297 else part = part->
next;
299 if ( !found ) rec = rec->
next;
305 for ( part = rec->
part; part && part->
id != img_num; part = part->
next ) ;
307 cerr <<
"Error: No reconstruction with ID = " << rec_id << endl;
312 filename = rec->
frec;
316 read_img_num = part->
id - 1;
317 if ( !currview_set ) {
318 currview = part->
view;
324 filename = part->
fpart;
328 cout <<
"Processing particle " << part->
id <<
":" << endl;
329 cout <<
"Origin: " << part->
ori << endl;
330 cout <<
"View: " << part->
view << endl;
334 cerr <<
"Error: Particle not defined!" << endl;
337 if ( !currview_set ) {
338 currview = rec->
view;
342 cerr <<
"Error: Reconstruction not defined!" << endl;
346 if ( filename.
length() < 1 ) {
347 cerr <<
"Error: No image file name found!" << endl;
356 mkdir(
"ppx", O_CREAT );
360 cerr << filename <<
" already done! Aborting" << endl;
369 double cc, best_cc(-1e37);
373 for ( i=0; i<sym->
n; i++ )
378 if ( global_bin[0] > 0 || !currview_set ) {
383 view =
side_views(sym, side_ang, theta_step, phi_step, alpha_step);
388 if ( view_subset > 0 )
if (
view_list_subset(&view, view_start, view_subset) < 1 ) {
389 cerr <<
"Error: At least one view must be selected!" << endl;
396 cout <<
"Number of global views: " <<
count_list((
char *) view) << endl << endl;
400 vector<Bimage*> imgvec =
setup_images(filename, template_file, rs_mask, fs_mask,
401 read_img_num, global_bin, sam, set_origin, origin, part_ori);
405 best_cc = p->
search_views(imgvec[1], view, hires, lores,
406 search_radius/global_bin[0], imgvec[2], bestview, bestshift);
411 if ( global_bin[0] != bin[0] )
412 bestshift *=
Vector3<double>(global_bin[0]/bin[0], global_bin[1]/bin[1], global_bin[2]/bin[2]);
418 for (
auto it = imgvec.begin(); it != imgvec.end(); ++it )
delete *it;
422 if ( bin[0] > 1 ) search_radius /= bin[0];
425 vector<Bimage*> imgvec =
setup_images(filename, template_file, rs_mask, fs_mask,
426 read_img_num, bin, sam, set_origin, origin, part_ori);
430 if ( mode ==
"directional" ) {
433 cout <<
"Central view: " << bestview << endl;
434 cout <<
"Number of directional views: " <<
count_list((
char *) view) << endl << endl;
436 }
else if ( mode ==
"symmetric" ) {
439 cout <<
"Number of symmetry views: " <<
count_list((
char *) view) << endl << endl;
442 if ( mode ==
"directional" || mode ==
"symmetric" ) {
443 best_cc = p->
search_views(imgvec[1], view, hires, lores,
444 search_radius, imgvec[2], bestview, bestshift);
446 }
else if ( mode ==
"refine" ) {
450 if ( accuracy < 2.0/p->sizeX() ) accuracy = 2.0/p->
sizeX();
451 while ( alpha_step >= accuracy ) {
452 if ( hires > alpha_step * p->
real_size()[0] )
456 search_radius, imgvec[2], bestview, currshift);
457 if ( currview.
residual(bestview) < 1e-6 ||
458 fabs(cc - best_cc) < 1e-6 ||
463 if ( best_cc < cc ) {
466 bestshift = currshift;
477 for (
auto it = imgvec.begin(); it != imgvec.end(); ++it )
delete *it;
482 if ( newpart_file.
length() < 1 && optind < argc ) newpart_file = argv[optind];
484 currshift = -bestshift;
486 if ( newtemp_file.
length() ) {
488 ptemp =
read_img(template_file, 1, 0);
489 if ( set_origin & 1 ) ptemp->
origin(temp_ori);
490 else if ( set_origin & 2) ptemp->
origin(ptemp->
size()/2);
494 ptemp->
view(bestview);
503 if ( newpart_file.
length() ) {
506 p =
read_img(filename, 1, read_img_num);
507 ptemp =
read_img(template_file, 0, 0);
529 if ( rec_id.
length() < 1 ) {
542 if ( newpart_file.
length() ) {
543 part->
fpart = newpart_file;
545 part->
view = bestview;
546 part->
ori = origin + currshift;
548 part->
fom[0] = best_cc;
557 rec->
frec = filename;
558 if ( newpart_file.
length() ) {
559 rec->
frec = newpart_file;
561 rec->
view = bestview;
562 rec->
origin = origin + currshift;
565 if ( rec->
id == rec_id ) rec->
fom = best_cc;
569 if ( param_file.
length() ) {
595 if ( map_file.
length() < 1 ) {
596 cerr <<
"Error: No image file name specified!" << endl;
599 p =
read_img(map_file, 1, read_img_num);
602 if ( set_origin & 4 ) p->
origin(part_ori);
603 else if ( set_origin & 8 ) p->
origin(p->
size()/2);
606 cerr <<
"Error: " << map_file <<
" not read!" << endl;
611 if ( template_file.
length() < 1 ) {
612 cerr <<
"Error: No input template file specified!" << endl;
615 ptemp =
read_img(template_file, 1, 0);
618 if ( set_origin & 1 ) ptemp->
origin(origin);
619 else if ( set_origin & 2 ) ptemp->
origin(ptemp->
size()/2);
622 cerr <<
"Error: " << template_file <<
" not read!" << endl;
630 cerr <<
"Error: " << rs_mask <<
" not read!" << endl;
640 cerr <<
"Error: " << fs_mask <<
" not read!" << endl;
646 cerr <<
"Too many errors! (" << -err <<
")" << endl;
659 if ( p ) p->bin(bin);
660 if ( ptemp ) ptemp->bin(bin);
661 if ( pfs_mask ) pfs_mask->bin(bin);
668 cout <<
"Map file: " << p->
file_name() <<
" (" << read_img_num <<
")" << endl;
670 cout <<
"Template file: " << ptemp->
file_name() << endl;
672 cout <<
"Mask file: " << pfs_mask->
file_name() << endl;
673 cout <<
"Size: " << p->
size() << endl;
677 vector<Bimage*> imgvec;
679 imgvec.push_back(ptemp);
680 imgvec.push_back(pfs_mask);
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
int view_list_subset(View **view_list, int start, int size)
Replaces a view list with a subset of it.
View * views_for_refinement(View theview, double alpha_step)
Generates a 3x3 grid of views around an input view.
Bimage * scale_to_same_size(Bimage *pref)
Scales and image to the given reference.
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.
Vector3< double > voxel_size
Matrix3 transpose() const
Header file for general symmetry functions.
int bexit(int value)
Exit function for cleanup and debugging.
int main(int argc, char **argv)
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.
long part_set_sequential(Bproject *project)
Selects one selection number and sets all others to zero.
void view(double x, double y, double z, double a)
Bstring ppx_filename(Bstring &id, int part_id)
Vector3< double > origin()
long count_list(char *list)
Counts the number of items in a linked list.
double distance(const Vector3 &v)
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)
void multiply(long j, Complex< double > cv)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
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.
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
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.
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.
void meta_data_update()
Update metadata from the sub-image information.
Header file for micrograph processing.
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
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.
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)
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.
void sampling(long nn, Vector3< double > u)
double residual(const View &view)
DataType
Base data type specifier.
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
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.
void write(string filename)
Header file for postscript tools dealing with views.
void view(double vx, double vy, double vz, double va)
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.