| Bsoft 2.0.5 Bernard's software package

btomrec.cpp
Go to the documentation of this file.
1
9 #include "mg_tomo_rec.h"
10 #include "rwmg.h"
11 #include "utilities.h"
12 #include "options.h"
13 #include "timer.h"
14
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17
18 // Usage assistance
19 const char* use[] = {
20 " ",
21 "Usage: btomrec [options] input.star [input2.star]",
22 "-------------------------------------------------",
23 "Reconstructs a tomogram from an aligned tilt series in Fourier space.",
24 "Requires large amounts of disk space.",
25 " ",
26 "Actions:",
27 "-removemarkers 14 Mask out markers with this radius (pixels) before reconstruction.",
28 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
29 "-slab 25,40 Reconstruct a slab of these slices (default all).",
30 "-transform 2D Back transform reconstruction: none (default), full, slices.",
31 " ",
32 "Parameters:",
33 "-verbose 7 Verbosity of output.",
34 "-datatype u Force writing of a new data type.",
35 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
36 "-resolution 20 Resolution limit (angstrom, default Nyquist).",
37 "-scale 1.2 Scale or magnification of reconstruction compared to original images (default 1).",
38 "-size 100,120,90 Size of reconstruction (default from images).",
39 "-interpolation weighted Interpolation type: nearest (default), weighted, trilinear.",
40 "-pad 3 Image padding factor (default 2).",
41 "-edge 15 An edge smoothing width (default 0).",
42 "-fill 127 Fill value for erasing/painting markers (default average).",
43 "-CTF flip Apply CTF correction to images before reconstruction (default not).",
44 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
45 " ",
46 "Output:",
47 "-reconstruction file.ext Reconstruction file name.",
48 "-output file.star Output STAR file name.",
49 " ",
50 NULL
51 };
52
53 int main(int argc, char **argv)
54 {
55 double marker_radius(0); // Radius to mask out markers
56 DataType nudatatype(Unknown_Type); // Conversion to new type
57 double nuavg(0), nustd(0); // Values for rescaling
58 Vector3<double> sam; // Units for the three axes (A/pixel)
59 Vector3<long> size; // Size of reconstruction
60 int slab_start(0), slab_end(-1);// Slab definition
61 int interp_type(0); // Interpolation type
62 int pad_factor(2); // Image padding factor
63 double edge_width(0); // An edge smoothing width
64 double scale(1); // Scale or magnification of reconstruction compared to original images
65 double resolution(0); // Must be set > 0 to limit resolution
66 int transform(0); // No back transform
67 int fill_type(FILL_AVERAGE); // Type of fill value
68 double fill(0); // Fill value for new areas
69 int ctf_action(0); // Default no CTF operation
70 double wiener(0.2); // Wiener for CTF correction
71 Bstring reconsfile; // Output reconstruction file
72 Bstring outfile; // Output STAR file
73
74 int optind;
75 Boption* option = get_option_list(use, argc, argv, optind);
76 Boption* curropt;
77 for ( curropt = option; curropt; curropt = curropt->next ) {
78 if ( curropt->tag == "removemarkers" )
79 if ( ( marker_radius = curropt->value.real() ) < 1 )
80 cerr << "-removemarkers: A marker radius must be specified!" << endl;
81 if ( curropt->tag == "rescale" ) {
82 if ( curropt->values(nuavg, nustd) < 2 )
83 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
84 if ( nustd <= 0 )
85 cerr << "-rescale: A positive standard deviation must be specified!" << endl;
86 }
87 if ( curropt->tag == "slab" )
88 if ( curropt->values(slab_start, slab_end) < 1 )
89 cerr << "-slab: A slab size must be specified!" << endl;
90 if ( curropt->tag == "transform" ) {
91 if ( curropt->value[0] == 'n' ) transform = 0;
92 if ( curropt->value[0] == 'f' ) transform = 1;
93 if ( curropt->value[0] == 's' ) transform = 2;
94 }
95 if ( curropt->tag == "datatype" )
96 nudatatype = curropt->datatype();
97 if ( curropt->tag == "sampling" )
98 sam = curropt->sampling();
99 if ( curropt->tag == "resolution" )
100 if ( ( resolution = curropt->value.real() ) < 0.1 )
101 cerr << "-resolution: A resolution limit must be specified!" << endl;
102 if ( curropt->tag == "size" )
103 size = curropt->size();
104 if ( curropt->tag == "scale" )
105 if ( ( scale = curropt->value.real() ) < 0.001 )
106 cerr << "-scale: A scale must be specified!" << endl;
107 if ( curropt->tag == "interpolation" ) {
108 interp_type = curropt->value.integer();
109 if ( curropt->value[0] == 'n' ) interp_type = 0;
110 if ( curropt->value[0] == 'w' ) interp_type = 1;
111 if ( curropt->value[0] == 't' ) interp_type = 2;
112 }
113 if ( curropt->tag == "pad" )
114 if ( ( pad_factor = curropt->value.integer() ) < 0 )
115 cerr << "-pad: An integer factor must be specified!" << endl;
116 if ( curropt->tag == "edge" )
117 if ( ( edge_width = curropt->value.real() ) < 0 )
118 cerr << "-edge: An edge smoothing width must be specified!" << endl;
119 if ( curropt->tag == "fill" )
120 fill = curropt->fill(fill_type);
121 if ( curropt->tag == "CTF" )
122 ctf_action = curropt->ctf_action();
123 if ( curropt->tag == "wiener" ) {
124 if ( ( wiener = curropt->value.real() ) < 0.000001 )
125 cerr << "-wiener: A Wiener factor must be specified!" << endl;
126 else {
127 if ( wiener < 0.01 ) wiener = 0.01;
128 // if ( wiener > 1 ) wiener = 1;
129 }
130 }
131 if ( curropt->tag == "reconstruction" )
132 reconsfile = curropt->filename();
133 if ( curropt->tag == "output" )
134 outfile = curropt->filename();
135 }
136 option_kill(option);
137
138 double ti = timer_start();
139
140 #ifdef HAVE_GCD
141 fftwf_init_threads();
142 fftwf_plan_with_nthreads(system_processors());
143 #endif
144 if ( verbose )
145 cout << "Number of threads: " << system_processors() << endl;
146
147
148 // Read all the parameter files
149 Bstring* file_list = NULL;
150 while ( optind < argc ) string_add(&file_list, argv[optind++]);
151 if ( !file_list ) {
152 cerr << "Error: No parameter files specified!" << endl;
153 bexit(-1);
154 }
155
156 Bproject* project = read_project(file_list);
157 string_kill(file_list);
158
159 if ( project == NULL ) {
160 cerr << "Error: No input file read!" << endl;
161 bexit(-1);
162 }
163
164 if ( sam[0] > 0 ) {
165 if ( sam[0] < 0.1 ) sam[0] = 1;
166 project_set_pixel_size(project, sam[0]);
167 }
168
169 Bimage* prec = NULL;
170
171 if ( slab_end > 0 ) {
172 prec = project_fourier_reconstruction_slab(project, resolution,
173 scale, size, slab_start, slab_end, marker_radius,
174 fill_type, fill, ctf_action, wiener);
175 } else {
176 prec = project_tomo_reconstruct(project, resolution,
177 scale, size, interp_type, pad_factor,
178 edge_width, marker_radius,
179 fill_type, fill, ctf_action, wiener);
180 prec->change_transform_size(size);
181 }
182
183 Bstring id("1");
184 Bmicrograph* mg = field_find_zero_tilt_mg(project->field);
185 Vector3<double> ori(mg->origin);
186 Vector3<double> trans(prec->image->origin() - ori*scale);
187 if ( verbose )
188 cout << "Translating markers: " << trans << endl;
189
190 if ( transform == 1 ) {
191 if ( verbose )
192 cout << "Full Fourier transform" << endl;
193 prec->fft_back();
194 } else if ( transform == 2 ) {
195 if ( verbose )
196 cout << "Fourier transforming slices" << endl;
197 img_backtransform_slices(prec);
198 }
199
200 if ( prec && reconsfile.length() ) {
201 if ( nustd > 0 ) prec->rescale_to_avg_std(nuavg, nustd);
202 prec->change_type(nudatatype);
203 prec->label(get_cmd_line(argc, argv));
204 if ( verbose )
205 cout << "Writing " << reconsfile << endl;
206 write_img(reconsfile, prec, 0);
207 }
208
209 if ( project && outfile.length() ) {
210 if ( !project->rec )
211 reconstruction_add(&project->rec, id);
212 project->rec->frec = reconsfile;
213 project->rec->voxel_size = project->field->mg->pixel_size/scale;
214 project->rec->origin = prec->image->origin();
215 project->rec->scale = Vector3<double>(scale, scale, scale);
216 project->rec->box_size = project->field->mg->box_size * scale;
217 project->rec->filament_width = project->field->mg->filament_width * scale;
218 project->rec->fil_node_radius = project->field->mg->fil_node_radius * scale;
219 project->rec->bad_radius = project->field->mg->bad_radius * scale;
220 project->rec->sf_radius = project->field->mg->sf_radius * scale;
221 project->rec->mark_radius = project->field->mg->mark_radius * scale;
222 // marker_transform(project->rec->mark, tf);
223 marker_scale(project->rec->mark, project->rec->scale);
224 marker_shift(project->rec->mark, trans);
225 project_update_comment(project, argc, argv);
226 if ( verbose )
227 cout << "Writing " << outfile << endl;
228 write_project(outfile, project, 0, 0);
229 }
230
231 delete prec;
232 project_kill(project);
233
234 #ifdef HAVE_GCD
235 fftwf_cleanup_threads();
236 #endif
237
238 if ( verbose & VERB_TIME )
239 timer_report(ti);
240
241 bexit(0);
242 }
243
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
rwmg.h
Header file for reading and writing micrograph parameters.
use
const char * use[]
Definition: btomrec.cpp:19
Bstring::real
double real()
Definition: Bstring.cpp:545
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
Bmicrograph::sf_radius
double sf_radius
Definition: mg_processing.h:234
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
project_tomo_reconstruct
Bimage * project_tomo_reconstruct(Bproject *project, double hi_res, double scale, Vector3< long > size, int interp_type, int pad_factor, double edge_width, double marker_radius, int fill_type, double fill, int action, double wiener)
Reciprocal space reconstruction from the images in a multi-image file.
Definition: mg_tomo_rec.cpp:113
project_fourier_reconstruction_slab
Bimage * project_fourier_reconstruction_slab(Bproject *project, double hi_res, double scale, Vector3< long > size, int slab_start, int slab_end, double marker_radius, int fill_type, double fill, int action, double wiener)
Reciprocal space reconstruction from the images in a multi-image file.
Definition: mg_tomo_rec.cpp:299
Breconstruction::filament_width
double filament_width
Definition: mg_processing.h:297
Bimage::fft_back
int fft_back()
Definition: Bimage.h:823
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Bmicrograph::filament_width
double filament_width
Definition: mg_processing.h:231
Boption::tag
Bstring tag
Definition: options.h:29
system_processors
size_t system_processors()
Returns the number of processors.
Definition: utilities.cpp:186
Breconstruction::sf_radius
double sf_radius
Definition: mg_processing.h:300
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
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
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
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:296
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
timer.h
Utilities for timing functions.
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:301
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
Boption
A class for a command line input option.
Definition: options.h:26
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:235
Bimage::label
void label(string s)
Definition: Bimage.h:235
Bproject::field
Bfield * field
Definition: mg_processing.h:343
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
verbose
int verbose
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
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
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:220
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::fil_node_radius
double fil_node_radius
Definition: mg_processing.h:298
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
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
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
Breconstruction::bad_radius
double bad_radius
Definition: mg_processing.h:299
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
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
Breconstruction::scale
Vector3< double > scale
Definition: mg_processing.h:294
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bmicrograph::fil_node_radius
double fil_node_radius
Definition: mg_processing.h:232
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
Boption::ctf_action
int ctf_action()
Definition: options.h:303
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
main
int main(int argc, char **argv)
Definition: btomrec.cpp:53
Bstring::integer
long integer()
Definition: Bstring.cpp:539
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
options.h
Header file for option handlers.
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:233
Bimage::change_transform_size
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
Definition: Bimage_fft.cpp:239
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
img_backtransform_slices
int img_backtransform_slices(Bimage *p)
Backtransforms 2D slices in a 3D volume.
Definition: mg_tomo_rec.cpp:731
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
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
marker_scale
int marker_scale(Bmarker *markers, Vector3< double > scale)
Scaling markers.
Definition: marker.cpp:208
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
marker_shift
int marker_shift(Bmarker *markers, Vector3< double > shift)
Shifting markers.
Definition: marker.cpp:192