| Bsoft 2.0.5 Bernard's software package

btomo.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_img_proc.h"
11 #include "mg_tomography.h"
12 #include "mg_align.h"
13 #include "rwmg.h"
14 #include "rwmgIMOD.h"
15 #include "matrix_linear.h"
16 #include "rwimg.h"
17 #include "qsort_functions.h"
18 #include "linked_list.h"
19 #include "random_numbers.h"
20 #include "file_util.h"
21 #include "utilities.h"
22 #include "options.h"
23 #include "timer.h"
24
25 // Declaration of global variables
26 extern int verbose; // Level of output to the screen
27
28 // Internal function prototype
29 int read_imod_tlt(Bstring& filename, Bproject* project);
30
31 // Usage assistance
32 const char* use[] = {
33 " ",
34 "Usage: btomo [options] input.star/input.img [input.star/input.img]",
35 "------------------------------------------------------------------",
36 "Manipulates parameter files for tilt series and aligns them by cross-correlation.",
37 " ",
38 "Actions:",
39 "-all Select all markers.",
40 "-updatematrix Update micrograph matrices from tilt and axis angles.",
41 "-resetmodel Reset the x and y coordinates to that of the zero-degree tilt image.",
42 "-checkmarkers Determine if markers all fall within micrograph boundaries.",
43 "-deselect 5-9,33 Deselect markers by id from all micrographs and models.",
44 "-deletemarkers 5-9,33 Delete markers by id from all micrographs and models.",
45 "-rotationaxis Determine the best rotation axis from refined markers.",
46 "-clear 240,7.5 Clear extraneous areas on micrographs with this intended reconstruction thickness",
47 " and smoothing edge width (default 5).",
48 "-removemarkers 14 Mask out markers with this radius (pixels) before transformation.",
49 "-thickness 234 Calculate mean free path from a given thickness (in angstrom).",
50 "-lambda 2650 Calculate thickness from proportionality coefficient (in angstrom).",
51 " ",
52 "Parameters:",
53 "-verbose 7 Verbosity of output.",
54 "-datatype u Force writing of a new data type.",
55 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
56 "-origin 110,50,44 Origin for tilt axis (default 0,0,0).",
57 "-axis 74.7 Tilt axis angle relative to x-axis (default 0 or from parameter file).",
58 "-tilt -65,1.5 Tilt series start and step size (default from parameter file).",
59 "-reference 48 Reference image for alignment (default closest to zero tilt).",
60 "-goldradius 12 Gold particle radius (default from parameter file).",
61 " ",
62 "Input:",
63 "-rawtlt series.rawtlt Text file with tilt angles.",
64 " ",
65 "Output:",
66 "-output file.star Output parameter file.",
67 "-image file.pif Output multi-image file with aligned images.",
68 " ",
69 NULL
70 };
71
72
73 int main(int argc, char** argv)
74 {
75 // Initializing variables
76 int select_all(0); // Flag to select all markers
77 int update_matrix(0); // Flag to update micrograph matrix
78 int reset_model(0); // Flag to reset the x and y coordinates of the model
79 int checkmarkers(0); // Flag to determine if markers all fall within micrograph boundaries
80 Bstring deselect; // String specifying markers to deselect
81 Bstring deletemarkers; // String specifying markers to delete
82 int rotation_axis(0); // Flag to determine the best rotation axis
83 // int crosscorrelate(0); // Flag to align by cross-correlation
84 double thickness(0); // Calculates the mean free path
85 double lambda(0); // Calculates the thickness
86 int clearareas(0); // Thickness for clearing extraneous areas
87 double edge_width(5); // Smoothing edge width
88 double marker_erase_radius(0); // Radius to mask out markers
89 double marker_radius(0); // Gold marker radius
90 DataType datatype = Unknown_Type; // Conversion to new type
91 int ref_img(-1); // Reference image for alignment, <0 means find zero tilt
92 Vector3<double> sam; // Units for the three axes (A/pixel)
93 Vector3<double> origin; // Tilt axis origin
94 double tilt_axis(0); // Tilt axis angle
95 double tilt_start(0); // Tilt angle start
96 double tilt_step(0); // Tilt_angle step size
97 // int fill_type(FILL_USER); // Type of fill value
98 // double fill(0); // Fill value for new areas
99 Bstring tltfile; // Input tilt angle file
100 Bstring maskfile; // Mask to use for cross-correlation
101 Bstring paramfile; // Output parameter file
102 Bstring imgfile; // Output multi-image file
103
104 int optind;
105 Boption* option = get_option_list(use, argc, argv, optind);
106 Boption* curropt;
107 for ( curropt = option; curropt; curropt = curropt->next ) {
108 if ( curropt->tag == "all" ) select_all = 1;
109 if ( curropt->tag == "resetmodel" ) reset_model = 1;
110 if ( curropt->tag == "updatematrix" ) update_matrix = 1;
111 if ( curropt->tag == "checkmarkers" ) checkmarkers = 1;
112 if ( curropt->tag == "deselect" ) deselect = curropt->value;
113 if ( curropt->tag == "deletemarkers" ) deletemarkers = curropt->value;
114 if ( curropt->tag == "rotationaxis" ) rotation_axis = 1;
115 // if ( curropt->tag == "crosscorrelate" ) crosscorrelate = 1;
116 if ( curropt->tag == "thickness" )
117 if ( ( thickness = curropt->value.real() ) < 1 )
118 cerr << "-thickness: A thickness must be specified!" << endl;
119 if ( curropt->tag == "lambda" )
120 if ( ( lambda = curropt->value.real() ) < 1 )
121 cerr << "-lambda: A mean free path must be specified!" << endl;
122 if ( curropt->tag == "clear" )
123 if ( curropt->values(clearareas, edge_width) < 1 )
124 cerr << "-clear: A thickness must be specified." << endl;
125 if ( curropt->tag == "removemarkers" )
126 if ( ( marker_erase_radius = curropt->value.real() ) < 1 )
127 cerr << "-removemarkers: A marker radius must be specified!" << endl;
128 if ( curropt->tag == "datatype" )
129 datatype = curropt->datatype();
130 if ( curropt->tag == "sampling" )
131 sam = curropt->sampling();
132 if ( curropt->tag == "reference" )
133 if ( ( ref_img = curropt->value.integer() ) < 0 )
134 cerr << "-reference: An image number must be specified." << endl;
135 if ( curropt->tag == "origin" )
136 origin = curropt->origin();
137 if ( curropt->tag == "axis" ) {
138 tilt_axis = angle_set_negPI_to_PI(curropt->value.real()*M_PI/180.0);
139 update_matrix = 1;
140 }
141 if ( curropt->tag == "tilt" ) {
142 if ( curropt->values(tilt_start, tilt_step) < 2 )
143 cerr << "-tilt: Two angles must be specified." << endl;
144 else {
145 tilt_start = angle_set_negPI_to_PI(tilt_start*M_PI/180.0);
146 tilt_step = angle_set_negPI_to_PI(tilt_step*M_PI/180.0);
147 update_matrix = 1;
148 }
149 }
150 if ( curropt->tag == "goldradius" )
151 if ( ( marker_radius = curropt->value.real() ) < 1 )
152 cerr << "-goldradius: A gold marker radius must be specified." << endl;
153 // if ( curropt->tag == "fill" )
154 // fill = curropt->fill(fill_type);
155 if ( curropt->tag == "rawtlt" )
156 tltfile = curropt->filename();
157 if ( curropt->tag == "Mask" )
158 maskfile = curropt->filename();
159 if ( curropt->tag == "output" )
160 paramfile = curropt->filename();
161 if ( curropt->tag == "image" )
162 imgfile = curropt->filename();
163 }
164 option_kill(option);
165
166 double ti = timer_start();
167
168 Bproject* project = NULL;
169
170 // Read all the parameter files
171 Bstring* file_list = NULL;
172 while ( optind < argc ) string_add(&file_list, argv[optind++]);
173 if ( !file_list ) {
174 cerr << "Error: No parameter or image files specified!" << endl;
175 bexit(-1);
176 }
177
178 if ( file_type(*file_list) == Micrograph )
179 project = read_project(file_list);
180 else
181 project = project_create_from_images(file_list, "mg");
182
183 string_kill(file_list);
184
185 if ( !project ) {
186 cerr << "Error: Input file not read!" << endl;
187 bexit(-1);
188 }
189
190 if ( verbose & VERB_PROCESS )
191 project_show_markers(project);
192
193 project_update_comment(project, argc, argv);
194
195 Bstring label = get_cmd_line(argc, argv);
196
197 if ( origin[0] )
198 project_set_micrograph_origins(project, origin);
199
200 if ( project->field && project->field->mg->origin.length() < 1 )
201 project_set_nominal_mg_origins(project);
202
203 if ( tilt_axis )
204 project_set_tilt_axis(project, tilt_axis);
205
206 if ( tltfile.length() )
207 read_imod_tlt(tltfile, project);
208 else if ( tilt_step )
209 project_set_tilt_angles(project, tilt_start, tilt_step);
210
211 if ( project->field && project->field->mg->matrix.determinant() < 0.5 )
212 update_matrix = 1;
213
214 if ( update_matrix )
215 project_mg_tilt_to_matrix(project);
216
217 if ( sam[0] > 0 )
218 project_set_pixel_size(project, sam[0]);
219
220 if ( clearareas )
221 project_clear_extraneous_areas(project, clearareas, edge_width);
222
223 double tlr = project_thickness_to_lambda_ratio(project);
224
225 if ( thickness ) lambda = thickness/tlr;
226 if ( lambda ) thickness = lambda*tlr;
227
228 if ( thickness && lambda ) {
229 if ( verbose ) {
230 cout << "Thickness: " << thickness << " A" << endl;
231 cout << "Proportionality parameter: " << lambda << " A" << endl << endl;
232 }
233 }
234
235 int i;
236 Bmicrograph* mg_ref = NULL;
237
238 if ( marker_radius )
239 project_set_marker_radius(project, marker_radius);
240
241 if ( ref_img > -1 && project->field )
242 for ( i=0, mg_ref=project->field->mg; mg_ref && ( i<ref_img ); mg_ref=mg_ref->next, i++ ) ;
243
244 if ( !mg_ref )
245 mg_ref = field_find_zero_tilt_mg(project->field);
246
247 if ( checkmarkers )
248 project_check_markers(project, 1);
249
250 if ( select_all )
251 project_mg_marker_select(project, -1);
252
253 if ( deselect.length() )
254 project_deselect_markers(project, deselect);
255
256 if ( deletemarkers.length() )
257 project_delete_markers(project, deletemarkers);
258
259 if ( reset_model && project->rec && project->rec->mark )
260 mg_reset_model(mg_ref, project->rec->mark);
261
262 if ( rotation_axis )
263 project_marker_rotation_axis(project);
264
265 if ( project->rec && project->rec->mark )
266 project_tomo_residuals(project, 1);
267
268 if ( marker_erase_radius )
269 project_erase_markers(project, marker_erase_radius);
270
271 if ( imgfile.length() )
272 project_write_aligned_images(project, NULL, imgfile, datatype, label);
273
274 if ( paramfile.length() )
275 write_project(paramfile, project, 0, 0);
276
277 project_kill(project);
278
279 if ( verbose & VERB_TIME )
280 timer_report(ti);
281
282 bexit(0);
283 }
284
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
rwmg.h
Header file for reading and writing micrograph parameters.
use
const char * use[]
Definition: btomo.cpp:32
Bstring::real
double real()
Definition: Bstring.cpp:545
qsort_functions.h
Header file for utility functions for use in qsort calls.
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
Matrix3::determinant
double determinant()
Definition: Matrix3.h:260
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
rwmgIMOD.h
Converts between IMOD files and a micrograph parameter file.
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
project_set_micrograph_origins
int project_set_micrograph_origins(Bproject *project, Vector3< float > origin)
Sets micrograph origins to the given origin.
Definition: mg_processing.cpp:3531
project_delete_markers
long project_delete_markers(Bproject *project, Bstring &delete_list)
Deletes selected markers in a project hierarchy.
Definition: mg_tomography.cpp:1445
Vector3::length
double length()
Definition: Vector3.h:222
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
project_set_nominal_mg_origins
int project_set_nominal_mg_origins(Bproject *project)
Sets micrograph origins to the centers of the micrographs.
Definition: mg_img_proc.cpp:660
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
project_show_markers
long project_show_markers(Bproject *project)
Shows the markers in a project hierarchy.
Definition: mg_tomography.cpp:1321
Boption::tag
Bstring tag
Definition: options.h:29
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
mg_img_proc.h
Header file for image processing from micrograph structures.
project_create_from_images
Bproject * project_create_from_images(Bstring *file_list, Bstring type)
Creates a project structure using image file names.
Definition: mg_img_proc.cpp:224
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
read_imod_tlt
int read_imod_tlt(Bstring &filename, Bproject *project)
Definition: rwmgIMOD.cpp:48
project_marker_rotation_axis
double project_marker_rotation_axis(Bproject *project)
Determines the most likely rotation axis location for a tilt series.
Definition: mg_tomography.cpp:2124
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
project_erase_markers
int project_erase_markers(Bproject *project, double marker_radius)
Erases or paints markers in micrographs.
Definition: mg_tomography.cpp:1080
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
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
timer.h
Utilities for timing functions.
project_set_marker_radius
int project_set_marker_radius(Bproject *project, double mark_radius)
Sets the marker radius in a project parameter structure.
Definition: mg_tomography.cpp:1862
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:222
verbose
int verbose
main
int main(int argc, char **argv)
Definition: btomo.cpp:73
Micrograph
Definition: file_util.h:23
mg_align.h
Header file for functions to align micrographs or coordinates from micrographs and apply the resultan...
project_check_markers
int project_check_markers(Bproject *project, int flags)
Checks if the markers in a project parameter structure fall within micrographs.
Definition: mg_tomography.cpp:1891
M_PI
#define M_PI
Definition: utilities.h:59
linked_list.h
Header file for generalized linked list functions.
project_write_aligned_images
double project_write_aligned_images(Bproject *project, Bimage *pgr, Bstring &imgfile, DataType datatype, Bstring &label)
Calculates aligned micrograph images and write them to a file.
Definition: mg_align.cpp:950
Boption
A class for a command line input option.
Definition: options.h:26
Bproject::field
Bfield * field
Definition: mg_processing.h:343
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
project_mg_tilt_to_matrix
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
Definition: mg_tomography.cpp:1960
field_find_zero_tilt_mg
Bmicrograph * field_find_zero_tilt_mg(Bfield *field)
Finds the micrograph closest to a zero degree tilt in a series.
Definition: mg_processing.cpp:400
Bmicrograph
Definition: mg_processing.h:200
project_tomo_residuals
double project_tomo_residuals(Bproject *project, int show)
Calculates the residuals for an alignment solution.
Definition: mg_tomography.cpp:671
mg_tomography.h
Header file for single particle image processing in Bsoft.
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
file_util.h
Header file for file checking functions.
mg_reset_model
int mg_reset_model(Bmicrograph *mg, Bmarker *model)
Resets the model x and y coordinates from the zero-tilt micrograph.
Definition: mg_tomography.cpp:1135
project_set_tilt_angles
int project_set_tilt_angles(Bproject *project, double tilt_start, double tilt_step)
Sets the tilt and tilt axis angles in a project parameter structure.
Definition: mg_tomography.cpp:1719
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
random_numbers.h
Header file for functions for creating random images.
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
matrix_linear.h
Header file for matrix functions.
project_set_pixel_size
int project_set_pixel_size(Bproject *project, double pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:3398
project_clear_extraneous_areas
int project_clear_extraneous_areas(Bproject *project, long thickness, double width)
Clears areas from a tilt series not used in a reconstruction.
Definition: mg_tomography.cpp:2043
project_deselect_markers
long project_deselect_markers(Bproject *project, Bstring &deselect_list)
Deletes selected markers in a project hierarchy.
Definition: mg_tomography.cpp:1389
Vector3< double >
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
project_set_tilt_axis
int project_set_tilt_axis(Bproject *project, double tilt_axis)
Sets the tilt axis angle in a project parameter structure.
Definition: mg_tomography.cpp:1672
project_mg_marker_select
int project_mg_marker_select(Bproject *project, double fom)
Selects markers.
Definition: mg_tomography.cpp:1841
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.
project_thickness_to_lambda_ratio
double project_thickness_to_lambda_ratio(Bproject *project)
Determines the thickness to mean free path ratio from a tilt series.
Definition: mg_tomography.cpp:504
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
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
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
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bproject
Definition: mg_processing.h:333
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201