Bsoft  2.1.0
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 micrographs in a tilt series.",
25 "If the -micrograph option is used, only one micrograph will be processed",
26 "and the postscript file will contain the FSC plot."
27 "If the -micrograph option is not used, the whole tilt series will be",
28 "processed and the postrscript file will contain a plot of the tilt angle",
29 "versus the resolution, as well as a second plot, the NLOO3D FSC curve."
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbosity of output.",
33 "-datatype u Force writing of a new data type.",
34 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
35 "-resolution 20 Resolution limit (angstrom, default Nyquist).",
36 "-ratio 2.5 Radial sampling to Cartesian sampling ratio (default 1).",
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 "-cutoff 0.3 Resolution cutoff for FRC (default 0.5).",
40 "-micrograph 56 Micrograph number to use for the resolution test (first = 0).",
41 "-fast 10 Fast mode, only use micrographs within the given angle from the selected one (default all).",
42 "-CTF flip Apply CTF correction to images before reconstruction (default not).",
43 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
44 " ",
45 "Output:",
46 "-output file.star Output parameter file name.",
47 "-reconstruction file.mrc Output 2D reconstruction file name.",
48 "-Postscript file.ps Postscript output filename.",
49 " ",
50 NULL
51 };
52 
53 int main(int argc, char **argv)
54 {
55  DataType nudatatype(Unknown_Type); // Conversion to new type
56  Vector3<double> sam; // Units for the three axes (A/pixel)
57  Vector3<long> size; // Size of reconstruction
58  double scale(1); // Scale or magnification of reconstruction compared to original images
59  double resolution(0); // Must be set > 0 to limit resolution
60  double sampling_ratio(1); // Averaging ratio for FRC calculation
61  double cutoff(0.5); // FRC cutoff
62  int mg_num(-1); // Default use all micrographs
63  double fast_angle(M_PI); // Select all micrographs to do a reconstruction
64  int ctf_action(0); // Default no CTF operation
65  double wiener(0.2); // Wiener for CTF correction
66  Bstring outfile; // Output parameter file
67  Bstring recfile; // Output reconstruction file
68  Bstring ps_file; // Output postscript file
69 
70  int optind;
71  Boption* option = get_option_list(use, argc, argv, optind);
72  Boption* curropt;
73  for ( curropt = option; curropt; curropt = curropt->next ) {
74  if ( curropt->tag == "datatype" )
75  nudatatype = curropt->datatype();
76  if ( curropt->tag == "sampling" )
77  sam = curropt->scale();
78  if ( curropt->tag == "resolution" )
79  if ( ( resolution = curropt->value.real() ) < 0.1 )
80  cerr << "-resolution: A positive resolution limit must be specified!" << endl;
81  if ( curropt->tag == "ratio" )
82  if ( ( sampling_ratio = curropt->value.real() ) < 1 )
83  cerr << "-ratio: A ratio must be specified!" << endl;
84  if ( curropt->tag == "resolution" )
85  if ( ( resolution = curropt->value.real() ) < 0.1 )
86  cerr << "-resolution: A positive resolution limit must be specified!" << endl;
87  if ( curropt->tag == "size" )
88  size = curropt->size();
89  if ( curropt->tag == "scale" )
90  if ( ( scale = curropt->value.real() ) < 0.1 )
91  cerr << "-scale: A scale must be specified!" << endl;
92  if ( curropt->tag == "cutoff" )
93  if ( ( cutoff = curropt->value.real() ) < 0.01 )
94  cerr << "-cutoff: A cuttoff must be specified!" << endl;
95  if ( curropt->tag == "micrograph" )
96  if ( ( mg_num = curropt->value.integer() ) < 0 )
97  cerr << "-micrograph: A micrograph number must be specified!" << endl;
98  if ( curropt->tag == "fast" ) {
99  if ( ( fast_angle = curropt->value.real() ) < 0.1 )
100  cerr << "-fast: An angle must be specified!" << endl;
101  else
102  fast_angle *= M_PI/180.0;
103  }
104  if ( curropt->tag == "CTF" )
105  ctf_action = curropt->ctf_action();
106  if ( curropt->tag == "wiener" ) {
107  if ( ( wiener = curropt->value.real() ) < 0.000001 )
108  cerr << "-wiener: A Wiener factor must be specified!" << endl;
109  else {
110  if ( wiener < 0.01 ) wiener = 0.01;
111 // if ( wiener > 1 ) wiener = 1;
112  }
113  }
114  if ( curropt->tag == "output" )
115  outfile = curropt->filename();
116  if ( curropt->tag == "reconstruction" )
117  recfile = curropt->filename();
118  if ( curropt->tag == "Postscript" )
119  ps_file = curropt->filename();
120  }
121  option_kill(option);
122 
123  double ti = timer_start();
124 
125  // Read all the parameter files
126  Bstring* file_list = NULL;
127  while ( optind < argc ) string_add(&file_list, argv[optind++]);
128  if ( !file_list ) {
129  cerr << "Error: No parameter files specified!" << endl;
130  bexit(-1);
131  }
132 
133  Bproject* project = read_project(file_list);
134  string_kill(file_list);
135 
136  if ( project == NULL ) {
137  cerr << "Error: No input file read!" << endl;
138  bexit(-1);
139  }
140 
141  if ( sam[0] > 0 ) {
142  if ( sam[0] < 0.1 ) sam = Vector3<double>(1,1,1);
144  }
145 
146  long i;
147  Bfield* field = project->field;
148  Bmicrograph* mg = NULL;
149  Bmicrograph* mg_res = NULL;
150  Bimage* prec = NULL;
151  Bstring title("Micrograph resolution for a tilt series");
152 
153  if ( mg_num >= 0 ) {
154  prec = mg_tomo_resolution(project, mg_num, resolution, sampling_ratio,
155  scale, size, fast_angle, ctf_action, wiener, cutoff, ps_file);
156 
157  for ( mg = field->mg, i=0; mg; mg = mg->next, i++ )
158  if ( i == mg_num ) mg_res = mg;
159  else mg->select = 0;
160 
161  if ( prec && recfile.length() ) {
162  prec->origin(0, 0, 0);
163  prec->phase_shift_to_center();
164  prec->fft_back();
165  prec->statistics();
166  prec->change_type(nudatatype);
167  write_img(recfile, prec, 0);
168  if ( mg_res ) {
169  mg_res->fmg = recfile;
170  mg_res->img_num = 0;
171  mg_res->origin = prec->image->origin();
172  }
173  }
174 
175  delete prec;
176 
177  } else {
178  vector<Bplot*> plot = project_tomo_resolution(project,
179  resolution, sampling_ratio, scale, size,
180  fast_angle, ctf_action, wiener, cutoff);
181 
182  if ( ps_file.length() ) {
183  ps_plot(ps_file, plot[0]);
184  ps_file = ps_file.pre_rev('.') + "_nloo3d." + ps_file.post_rev('.');
185  ps_plot(ps_file, plot[1]);
186  }
187 
188  delete plot[0];
189  delete plot[1];
190  }
191 
192  if ( project && outfile.length() ) {
193  write_project(outfile, project, 1, 0);
194  }
195 
197 
198  if ( verbose & VERB_TIME )
199  timer_report(ti);
200 
201  bexit(0);
202 }
203 
204 
Boption
A class for a command line input option.
Definition: options.h:26
project_tomo_resolution
vector< 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:346
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
Bmicrograph
Definition: mg_processing.h:201
main
int main(int argc, char **argv)
Definition: btomres.cpp:53
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:129
Boption::scale
Vector3< double > scale()
Definition: options.h:190
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Bstring
Definition: Bstring.h:29
use
const char * use[]
Definition: btomres.cpp:20
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Bimage::fft_back
int fft_back()
Definition: Bimage.h:831
Bfield
Definition: mg_processing.h:260
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
mg_tomo_resol.h
Functions to assess the resoltion of a tomographic tilt series.
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
rwmg.h
Header file for reading and writing micrograph parameters.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
project_set_mg_pixel_size
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:1997
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Boption::ctf_action
int ctf_action()
Definition: options.h:291
Boption::value
Bstring value
Definition: options.h:30
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
M_PI
#define M_PI
Definition: utilities.h:63
verbose
int verbose
utilities.h
Header file for general utilities.
Boption::size
Vector3< long > size()
Definition: options.h:163
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:267
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
Boption::filename
Bstring filename()
Definition: options.h:85
Bmicrograph::select
long select
Definition: mg_processing.h:204
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
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
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22