| Bsoft 2.0.5 Bernard's software package

btomres.cpp
Go to the documentation of this file.
1
9 #include "mg_tomo_resol.h"
10 #include "mg_tomo_rec.h"
11 #include "rwmg.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: btomres [options] input.star [input2.star]",
23 "-------------------------------------------------",
24 "Program to determine the resolution of a tilt series.",
25 " ",
26 "Parameters:",
27 "-verbose 7 Verbosity of output.",
28 "-datatype u Force writing of a new data type.",
29 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
30 "-resolution 20 Resolution limit (angstrom, default Nyquist).",
31 "-ratio 2.5 Radial sampling to Cartesian sampling ratio (default 1).",
32 "-scale 1.2 Scale or magnification of reconstruction compared to original images (default 1).",
33 "-size 100,120,90 Size of reconstruction (default from images).",
34 "-cutoff 0.3 Resolution cutoff for FRC (default 0.5).",
35 "-micrograph 56 Micrograph number to use for the resolution test (first = 0).",
36 "-fast 10 Fast mode, only use micrographs within the given angle from the selected one (default all).",
37 "-CTF flip Apply CTF correction to images before reconstruction (default not).",
38 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
39 " ",
40 "Output:",
41 "-output file.star Output parameter file name.",
42 "-reconstruction file.mrc Output 2D reconstruction file name.",
43 "-Postscript file.ps Postscript output filename.",
44 " ",
45 NULL
46 };
47
48 int main(int argc, char **argv)
49 {
50 DataType nudatatype(Unknown_Type); // Conversion to new type
51 Vector3<double> sam; // Units for the three axes (A/pixel)
52 Vector3<long> size; // Size of reconstruction
53 double scale(1); // Scale or magnification of reconstruction compared to original images
54 double resolution(0); // Must be set > 0 to limit resolution
55 double sampling_ratio(1); // Averaging ratio for FRC calculation
56 double cutoff(0.5); // FRC cutoff
57 int mg_num(-1); // Default use all micrographs
58 double fast_angle(M_PI); // Select all micrographs to do a reconstruction
59 int ctf_action(0); // Default no CTF operation
60 double wiener(0.2); // Wiener for CTF correction
61 Bstring outfile; // Output parameter file
62 Bstring recfile; // Output reconstruction file
63 Bstring ps_file; // Output postscript file
64
65 int optind;
66 Boption* option = get_option_list(use, argc, argv, optind);
67 Boption* curropt;
68 for ( curropt = option; curropt; curropt = curropt->next ) {
69 if ( curropt->tag == "datatype" )
70 nudatatype = curropt->datatype();
71 if ( curropt->tag == "sampling" )
72 sam = curropt->sampling();
73 if ( curropt->tag == "resolution" )
74 if ( ( resolution = curropt->value.real() ) < 0.1 )
75 cerr << "-resolution: A positive resolution limit must be specified!" << endl;
76 if ( curropt->tag == "ratio" )
77 if ( ( sampling_ratio = curropt->value.real() ) < 1 )
78 cerr << "-ratio: A ratio must be specified!" << endl;
79 if ( curropt->tag == "resolution" )
80 if ( ( resolution = curropt->value.real() ) < 0.1 )
81 cerr << "-resolution: A positive resolution limit must be specified!" << endl;
82 if ( curropt->tag == "size" )
83 size = curropt->size();
84 if ( curropt->tag == "scale" )
85 if ( ( scale = curropt->value.real() ) < 0.1 )
86 cerr << "-scale: A scale must be specified!" << endl;
87 if ( curropt->tag == "cutoff" )
88 if ( ( cutoff = curropt->value.real() ) < 0.01 )
89 cerr << "-cutoff: A cuttoff must be specified!" << endl;
90 if ( curropt->tag == "micrograph" )
91 if ( ( mg_num = curropt->value.integer() ) < 0 )
92 cerr << "-micrograph: A micrograph number must be specified!" << endl;
93 if ( curropt->tag == "fast" ) {
94 if ( ( fast_angle = curropt->value.real() ) < 0.1 )
95 cerr << "-fast: An angle must be specified!" << endl;
96 else
97 fast_angle *= M_PI/180.0;
98 }
99 if ( curropt->tag == "CTF" )
100 ctf_action = curropt->ctf_action();
101 if ( curropt->tag == "wiener" ) {
102 if ( ( wiener = curropt->value.real() ) < 0.000001 )
103 cerr << "-wiener: A Wiener factor must be specified!" << endl;
104 else {
105 if ( wiener < 0.01 ) wiener = 0.01;
106 // if ( wiener > 1 ) wiener = 1;
107 }
108 }
109 if ( curropt->tag == "output" )
110 outfile = curropt->filename();
111 if ( curropt->tag == "reconstruction" )
112 recfile = curropt->filename();
113 if ( curropt->tag == "Postscript" )
114 ps_file = curropt->filename();
115 }
116 option_kill(option);
117
118 double ti = timer_start();
119
120 // Read all the parameter files
121 Bstring* file_list = NULL;
122 while ( optind < argc ) string_add(&file_list, argv[optind++]);
123 if ( !file_list ) {
124 cerr << "Error: No parameter files specified!" << endl;
125 bexit(-1);
126 }
127
128 Bproject* project = read_project(file_list);
129 string_kill(file_list);
130
131 if ( project == NULL ) {
132 cerr << "Error: No input file read!" << endl;
133 bexit(-1);
134 }
135
136 if ( sam[0] > 0 ) {
137 if ( sam[0] < 0.1 ) sam[0] = 1;
138 project_set_pixel_size(project, sam[0]);
139 }
140
141 long i;
142 Bfield* field = project->field;
143 Bmicrograph* mg = NULL;
144 Bmicrograph* mg_res = NULL;
145 Bimage* prec = NULL;
146 Bplot* plot = NULL;
147 Bstring title("Micrograph resolution for a tilt series");
148
149 if ( mg_num >= 0 ) {
150 prec = mg_tomo_resolution(project, mg_num, resolution, sampling_ratio,
151 scale, size, fast_angle, ctf_action, wiener, cutoff, ps_file);
152
153 for ( mg = field->mg, i=0; mg; mg = mg->next, i++ )
154 if ( i == mg_num ) mg_res = mg;
155 else mg->select = 0;
156
157 if ( prec && recfile.length() ) {
158 prec->origin(0, 0, 0);
159 prec->phase_shift_to_center();
160 prec->fft_back();
161 prec->statistics();
162 prec->change_type(nudatatype);
163 prec->label(get_cmd_line(argc, argv));
164 write_img(recfile, prec, 0);
165 if ( mg_res ) {
166 mg_res->fmg = recfile;
167 mg_res->img_num = 0;
168 mg_res->origin = prec->image->origin();
169 }
170 }
171
172 delete prec;
173
174 } else {
175 plot = project_tomo_resolution(project, resolution, sampling_ratio,
176 scale, size, fast_angle, ctf_action, wiener, cutoff);
177
178 if ( ps_file.length() ) ps_plot(ps_file, plot);
179
180 delete plot;
181 }
182
183 if ( project && outfile.length() ) {
184 project_update_comment(project, argc, argv);
185 write_project(outfile, project, 1, 0);
186 }
187
188 project_kill(project);
189
190 if ( verbose & VERB_TIME )
191 timer_report(ti);
192
193 bexit(0);
194 }
195
196
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.
Bstring::real
double real()
Definition: Bstring.cpp:545
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:211
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
Boption::tag
Bstring tag
Definition: options.h:29
verbose
int verbose
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
mg_tomo_resol.h
Functions to assess the resoltion of a tomographic tilt series.
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.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
Bimage::phase_shift_to_center
int phase_shift_to_center()
Phase shifts a set of reflections to the nominal center of the image origin.
Definition: Bimage_complex.cpp:382
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Boption
A class for a command line input option.
Definition: options.h:26
Bmicrograph::select
long select
Definition: mg_processing.h:203
main
int main(int argc, char **argv)
Definition: btomres.cpp:48
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
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
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
mg_tomo_resolution
Bimage * mg_tomo_resolution(Bproject *project, int micrograph_id, double hi_res, double sampling_ratio, double scale, Vector3< long > size, double fast_angle, int action, double wiener, double cutoff, Bstring &psfile)
Estimating the resolution of one micrograph in an aligned tilt series.
Definition: mg_tomo_resol.cpp:266
project_tomo_resolution
Bplot * project_tomo_resolution(Bproject *project, double hi_res, double sampling_ratio, double scale, Vector3< long > size, double fast_angle, int action, double wiener, double cutoff)
Estimating the resolution of the tomogram from an aligned tilt series.
Definition: mg_tomo_resol.cpp:335
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
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
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
Vector3< double >
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:205
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
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
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Unknown_Type
Definition: utilities.h:147
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
use
const char * use[]
Definition: btomres.cpp:20
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
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
Bplot
Definition: Bplot.h:146
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201