Bsoft  2.1.0
Bernard's software package
btomaln.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "mg_align.h"
11 #include "mg_tomography.h"
12 #include "rwmg.h"
13 #include "rwimg.h"
14 #include "utilities.h"
15 #include "options.h"
16 #include "timer.h"
17 
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20 
21 // Usage assistance
22 const char* use[] = {
23 " ",
24 "Usage: btomaln [options] input.star [input.star]",
25 "------------------------------------------------",
26 "Aligns a tilt series of micrographs by progressive reconstruction.",
27 " ",
28 "Actions:",
29 "-align 5,1.5,8 Align micrographs: number of iterations, stopping change,",
30 " and number of adjacent images for limited reconstructions",
31 " (defaults 1 and ± 5 images).",
32 "-lambda 2650 Calculate thickness from proportionality coefficient (in angstrom).",
33 " ",
34 "Parameters:",
35 "-verbose 7 Verbosity of output.",
36 "-datatype u Force writing of a new data type.",
37 "-thickness 235 Reconstruction thickness (default 20% of x size).",
38 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
39 "-resolution 900,300 High and low resolution limits for cross-correlation (default 0.1,1000 angstrom).",
40 "-shiftlimit 155.5 Limit on micrograph shift search in pixels (default 25% of micrograph width).",
41 "-origin 110,50,44 Origin for tilt axis (default 0,0,0).",
42 "-edge 23,12 Smooth the edge to a given width, with gaussian decay of a given width.",
43 "-fill 127 Fill value for particles extending beyond image (default background).",
44 " ",
45 "Output:",
46 "-output file.star Output parameter file.",
47 "-image file.pif Output multi-image file with aligned images.",
48 "-Postscript inten.ps Postscript file with fit of tilt series intensities.",
49 " ",
50 NULL
51 };
52 
53 
54 int main(int argc, char** argv)
55 {
56  // Initializing variables
57  DataType datatype(Unknown_Type); // Conversion to new type
58  long iter(0); // Number of alignment iterations
59  double dchange(1); // Threshold for change in origins
60  long dimg(5); // Number of adjacent images in reconstructions
61  Vector3<double> sampling; // Units for the three axes (A/pixel)
62  long thickness(0); // Reconstruction thickness
63  double lambda(0); // Calculates the thickness
64  double hi_res(0), lo_res(1e10); // Default resolution range
65  double shift_limit(-1); // Micrograph shift search limit
66  Vector3<double> origin; // Tilt axis origin
67  double edge_width(0), gauss_width(0); // Edge parameters
68  int fill_type(FILL_BACKGROUND);
69  double fill(0);
70  Bstring paramfile; // Output parameter file
71  Bstring imgfile; // Output multi-image file
72  Bstring psfile; // Output Postscript intensities plot 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 == "align" )
79  if ( curropt->values(iter, dchange, dimg) < 1 )
80  cerr << "-align: A number of iterations must be specified." << endl;
81  if ( curropt->tag == "lambda" )
82  if ( ( lambda = curropt->value.real() ) < 1 )
83  cerr << "-lambda: A mean free path must be specified!" << endl;
84  if ( curropt->tag == "datatype" )
85  datatype = curropt->datatype();
86  if ( curropt->tag == "thickness" ) thickness = curropt->value.integer();
87  if ( curropt->tag == "sampling" )
88  sampling = curropt->scale();
89  if ( curropt->tag == "resolution" ) {
90  if ( curropt->values(hi_res, lo_res) < 1 )
91  cerr << "-resolution: Resolution limits must be specified." << endl;
92  else if ( hi_res > lo_res )
93  swap(hi_res, lo_res);
94  }
95  if ( curropt->tag == "shiftlimit" )
96  if ( ( shift_limit = curropt->value.real() ) < 1 )
97  cerr << "-shiftlimit: A shift limit in pixels must be specified." << endl;
98  if ( curropt->tag == "origin" )
99  origin = curropt->origin();
100  if ( curropt->tag == "edge" )
101  if ( curropt->values(edge_width, gauss_width) < 1 )
102  cerr << "-edge: An edge width must be specified." << endl;
103  if ( curropt->tag == "fill" )
104  fill = curropt->fill(fill_type);
105  if ( curropt->tag == "output" )
106  paramfile = curropt->filename();
107  if ( curropt->tag == "image" )
108  imgfile = curropt->filename();
109  if ( curropt->tag == "Postscript" )
110  psfile = curropt->filename();
111  }
112  option_kill(option);
113 
114  double ti = timer_start();
115 
116  // Read all the parameter files
117  Bstring* file_list = NULL;
118  while ( optind < argc ) string_add(&file_list, argv[optind++]);
119  if ( !file_list ) {
120  cerr << "Error: No parameter or image files specified!" << endl;
121  bexit(-1);
122  }
123 
124  Bproject* project = read_project(file_list);
125  string_kill(file_list);
126 
127  if ( !project ) {
128  cerr << "Error: Input file not read!" << endl;
129  bexit(-1);
130  }
131 
132  if ( sampling[0] > 0 )
134 
135  double tlr(0);
136  Bplot* plot = NULL;
137  if ( thickness || lambda ) {
139  tlr = project_fit_intensities(project, plot);
140  if ( plot && psfile.length() )
141  ps_plot(psfile, plot);
142  if ( thickness ) lambda = thickness/tlr;
143  if ( lambda ) thickness = lambda*tlr;
144  if ( thickness && lambda ) {
145  if ( verbose ) {
146  cout << "Thickness: " << thickness << " A" << endl;
147  cout << "Proportionality parameter: " << lambda << " A" << endl << endl;
148  }
149  }
150  }
151 
152 
153  if ( iter > 0 ) {
154  thickness *= 1.5;
155  project_tomo_align(project, thickness, iter, dchange, dimg, hi_res, shift_limit, edge_width, gauss_width);
156  }
157 
158  if ( imgfile.length() )
159  project_write_aligned_images(project, NULL, imgfile, datatype);
160 
161  if ( paramfile.length() )
162  write_project(paramfile, project, 0, 0);
163 
165 
166  if ( verbose & VERB_TIME )
167  timer_report(ti);
168 
169  bexit(0);
170 }
171 
172 
Boption
A class for a command line input option.
Definition: options.h:26
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
verbose
int verbose
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
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
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
Bplot
Definition: Bplot.h:146
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Boption::origin
Vector3< double > origin()
Definition: options.h:180
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
rwmg.h
Header file for reading and writing micrograph parameters.
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
Boption::value
Bstring value
Definition: options.h:30
project_fit_intensities
double project_fit_intensities(Bproject *project, Bplot *plot=NULL, int flag=0)
Determines the thickness to mean free path ratio from a tilt series.
Definition: mg_tomography.cpp:619
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
project_write_aligned_images
double project_write_aligned_images(Bproject *project, Bimage *pgr, Bstring &imgfile, DataType datatype)
Calculates aligned micrograph images and write them to a file.
Definition: mg_align.cpp:952
project_intensity_plot
Bplot * project_intensity_plot(Bproject *project)
Transfers the micrograph intensities for a field into a plot.
Definition: mg_tomography.cpp:515
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
utilities.h
Header file for general utilities.
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
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
rwimg.h
Header file for 2D and 3D image I/O.
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
mg_processing.h
Header file for micrograph processing.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
project_tomo_align
long project_tomo_align(Bproject *project, long thickness, long iter, double dchange, long dimg, double resolution, double shift_limit, double edge_width, double gauss_width)
Aligns a series of micrographs by cross-correlation sequentially.
Definition: mg_align.cpp:1764
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
use
const char * use[]
Definition: btomaln.cpp:22
mg_align.h
Header file for functions to align micrographs or coordinates from micrographs and apply the resultan...
main
int main(int argc, char **argv)
Definition: btomaln.cpp:54
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
mg_tomography.h
Header file for single particle image processing in Bsoft.