| Bsoft 2.0.5 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 " ",
49 NULL
50 };
51
52
53 int main(int argc, char** argv)
54 {
55 // Initializing variables
56 DataType datatype(Unknown_Type); // Conversion to new type
57 long iter(0); // Number of alignment iterations
58 double dchange(1); // Threshold for change in origins
59 long dimg(5); // Number of adjacent images in reconstructions
60 Vector3<double> sampling; // Units for the three axes (A/pixel)
61 long thickness(0); // Reconstruction thickness
62 double lambda(0); // Calculates the thickness
63 double hi_res(0), lo_res(1e10); // Default resolution range
64 double shift_limit(-1); // Micrograph shift search limit
65 Vector3<double> origin; // Tilt axis origin
66 double edge_width(0), gauss_width(0); // Edge parameters
67 int fill_type(FILL_BACKGROUND);
68 double fill(0);
69 Bstring paramfile; // Output parameter file
70 Bstring imgfile; // Output multi-image file
71
72 int optind;
73 Boption* option = get_option_list(use, argc, argv, optind);
74 Boption* curropt;
75 for ( curropt = option; curropt; curropt = curropt->next ) {
76 if ( curropt->tag == "align" )
77 if ( curropt->values(iter, dchange, dimg) < 1 )
78 cerr << "-align: A number of iterations must be specified." << endl;
79 if ( curropt->tag == "lambda" )
80 if ( ( lambda = curropt->value.real() ) < 1 )
81 cerr << "-lambda: A mean free path must be specified!" << endl;
82 if ( curropt->tag == "datatype" )
83 datatype = curropt->datatype();
84 if ( curropt->tag == "thickness" ) thickness = curropt->value.integer();
85 if ( curropt->tag == "sampling" )
86 sampling = curropt->sampling();
87 if ( curropt->tag == "resolution" ) {
88 if ( curropt->values(hi_res, lo_res) < 1 )
89 cerr << "-resolution: Resolution limits must be specified." << endl;
90 else if ( hi_res > lo_res )
91 swap(hi_res, lo_res);
92 }
93 if ( curropt->tag == "shiftlimit" )
94 if ( ( shift_limit = curropt->value.real() ) < 1 )
95 cerr << "-shiftlimit: A shift limit in pixels must be specified." << endl;
96 if ( curropt->tag == "origin" )
97 origin = curropt->origin();
98 if ( curropt->tag == "edge" )
99 if ( curropt->values(edge_width, gauss_width) < 1 )
100 cerr << "-edge: An edge width must be specified." << endl;
101 if ( curropt->tag == "fill" )
102 fill = curropt->fill(fill_type);
103 if ( curropt->tag == "output" )
104 paramfile = curropt->filename();
105 if ( curropt->tag == "image" )
106 imgfile = curropt->filename();
107 }
108 option_kill(option);
109
110 double ti = timer_start();
111
112 // Read all the parameter files
113 Bstring* file_list = NULL;
114 while ( optind < argc ) string_add(&file_list, argv[optind++]);
115 if ( !file_list ) {
116 cerr << "Error: No parameter or image files specified!" << endl;
117 bexit(-1);
118 }
119
120 Bproject* project = read_project(file_list);
121 string_kill(file_list);
122
123 if ( !project ) {
124 cerr << "Error: Input file not read!" << endl;
125 bexit(-1);
126 }
127
128 project_update_comment(project, argc, argv);
129
130 Bstring label = get_cmd_line(argc, argv);
131
132 if ( sampling[0] > 0 )
133 project_set_pixel_size(project, sampling[0]);
134
135 if ( lambda )
136 project_thickness(project, lambda);
137
138 if ( iter > 0 )
139 project_tomo_align(project, thickness, iter, dchange, dimg, hi_res, shift_limit, edge_width, gauss_width);
140
141 if ( imgfile.length() )
142 project_write_aligned_images(project, NULL, imgfile, datatype, label);
143
144 if ( paramfile.length() )
145 write_project(paramfile, project, 0, 0);
146
147 project_kill(project);
148
149 if ( verbose & VERB_TIME )
150 timer_report(ti);
151
152 bexit(0);
153 }
154
155
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
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
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
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
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
verbose
int verbose
use
const char * use[]
Definition: btomaln.cpp:22
timer.h
Utilities for timing functions.
mg_align.h
Header file for functions to align micrographs or coordinates from micrographs and apply the resultan...
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
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
mg_tomography.h
Header file for single particle image processing in Bsoft.
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 >
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
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
double project_thickness(Bproject *project, double lambda)
Determines the thickness from a tilt series and mean free path.
Definition: mg_tomography.cpp:623
main
int main(int argc, char **argv)
Definition: btomaln.cpp:53
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
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)
Definition: mg_align.cpp:1783
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