| Bsoft 2.0.5 Bernard's software package

btompart.cpp
Go to the documentation of this file.
1
9 #include "rwmg.h"
10 #include "mg_reconstruct.h"
11 #include "mg_tomo_rec.h"
12 #include "mg_tomo_resol.h"
13 #include "mg_tomography.h"
14 #include "mg_particle_select.h"
15 #include "symmetry.h"
16 #include "utilities.h"
17 #include "options.h"
18 #include "timer.h"
19
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22
23
24 // Usage assistance
25 const char* use[] = {
26 " ",
27 "Usage: btompart [options] input.star [input.star]",
28 "-------------------------------------------------",
29 "Averages reconstructions or subvolumes of reconstructions based on",
30 "the selection in parameter files.",
31 " ",
32 "Actions:",
33 "-add Adjust micrograph coordinates to particle origins.",
34 "-zflip Invert the particle z coordinate before transfer.",
35 "-transfer mg Calculate micrograph particle coordinates from micrograph (mg) or reconstruction (rec).",
36 "-reconstruct Reconstruct individual particles from micrographs.",
37 "-removemarkers 14 Mask out markers with this radius (pixels) before reconstruction.",
38 "-nloo 34.7,0.3 Determine particle resolution up to the given limit and with the given cutoff.",
39 " ",
40 "Parameters:",
41 "-verbose 7 Verbosity of output.",
42 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from parameter file; a single value can be given).",
43 "-views Use particle views during transfer.",
44 "-boxsize 55 Set the particle box size (default from parameter file).",
45 //"-resolution 4.5,130 Resolution range for correlation (default 0 - 1e6 angstrom).",
46 " ",
47 "Parameters for particle reconstruction:",
48 "-maxresolution 20 Reconstruction resolution limit (angstrom, default Nyquist).",
49 "-interpolation weighted Interpolation type: nearest (default), weighted, trilinear.",
50 "-pad 3 Image padding factor (default 2).",
51 "-CTF flip Apply CTF correction to images before reconstruction (default not).",
52 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
53 "-symmetry C5 Point group symmetry.",
54 "-base subvol Set the particle base file name (no extension).",
55 "-path dir/subdir Set the particle file paths.",
56 "-extension pif Set the particle image file format.",
57 " ",
58 "Parameters for particle resolution estimation:",
59 "-ratio 2.5 Radial sampling to Cartesian sampling ratio (default 1).",
60 "-fast 10 Fast mode, only use micrographs within the given angle from the selected one (default all).",
61 " ",
62 "Output:",
63 "-output file.star Output parameter file.",
64 "-Postscript file.ps Output plot file.",
65 " ",
66 NULL
67 };
68
69 int main(int argc, char **argv)
70 {
71 // Initialize variables
72 int add_coordinates(1); // Add coordinates and origins before other operations
73 int transfer(0); // Flag to transfer particle coordinates
74 int zflip(0); // Flag to invert z coordinate before transfer
75 int use_view(0); // Flag to use original particle views during transfer
76 int part_recon(0); // Flag to reconstruct individual particles
77 double marker_radius(0); // Radius to mask out markers
78 double nloo(0); // Flag and resolution for NLOO resolution estimation
79 double sampling_ratio(1); // Averaging ratio for FRC calculation
80 double fast_angle(M_PI); // Select all micrographs to do a reconstruction
81 double cutoff(0.3); // NLOO cutoff
82 // DataType nudatatype(Unknown_Type); // Conversion to new type
83 Vector3<double> sam; // Units for the three axes (A/pixel)
84 int box_size(0); // Particle box size
85 double hires(0), lores(1e6); // Limiting resolution range (hires must be > 0 to be set)
86 double resolution(0); // Must be set > 0 to limit resolution
87 int interp_type(0); // Interpolation type
88 int pad_factor(2); // Image padding factor
89 int ctf_action(0); // Default no CTF operation
90 double wiener(0.2); // Wiener for CTF correction
91 Bstring symmetry_string("C1"); // Point group
92 Bstring partbase; // Particle base file name
93 Bstring partpath; // Particle file path
94 Bstring partext; // Particle image file format
95 Bstring outfile; // Output parameter file name
96 Bstring psfile; // Output Postscript file name
97
98 int optind;
99 Boption* option = get_option_list(use, argc, argv, optind);
100 Boption* curropt;
101 for ( curropt = option; curropt; curropt = curropt->next ) {
102 if ( curropt->tag == "add" ) add_coordinates = 1;
103 if ( curropt->tag == "zflip" ) zflip = 1;
104 if ( curropt->tag == "transfer" ) {
105 if ( curropt->value[0] == 'm' ) transfer = 1;
106 if ( curropt->value[0] == 'r' ) transfer = 2;
107 }
108 if ( curropt->tag == "reconstruct" ) part_recon = 1;
109 if ( curropt->tag == "removemarkers" )
110 if ( ( marker_radius = curropt->value.real() ) < 1 )
111 cerr << "-removemarkers: A marker radius must be specified!" << endl;
112 if ( curropt->tag == "nloo" )
113 if ( curropt->values(nloo, cutoff) < 1 )
114 cerr << "-nloo: A resolution limit must be specified!" << endl;
115 // if ( curropt->tag == "datatype" )
116 // nudatatype = curropt->datatype();
117 if ( curropt->tag == "views" ) use_view = 2;
118 if ( curropt->tag == "sampling" )
119 sam = curropt->sampling();
120 if ( curropt->tag == "boxsize" )
121 if ( ( box_size = curropt->value.integer() ) < 1 )
122 cerr << "-boxsize: A particle box size in pixels must be specified" << endl;
123 if ( curropt->tag == "resolution" )
124 if ( curropt->values(hires, lores) < 1 )
125 cerr << "-resolution: A high resolution limit must be specified" << endl;
126 if ( curropt->tag == "maxresolution" )
127 if ( ( resolution = curropt->value.real() ) < 0.001 )
128 cerr << "-maxresolution: A resolution limit must be specified!" << endl;
129 if ( curropt->tag == "interpolation" ) {
130 if ( curropt->value[0] == 'n' ) interp_type = 0;
131 if ( curropt->value[0] == 'w' ) interp_type = 1;
132 if ( curropt->value[0] == 't' ) interp_type = 2;
133 }
134 if ( curropt->tag == "pad" )
135 if ( ( pad_factor = curropt->value.integer() ) < 0 )
136 cerr << "-pad: An integer factor must be specified!" << endl;
137 if ( curropt->tag == "CTF" )
138 ctf_action = curropt->ctf_action();
139 if ( curropt->tag == "wiener" ) {
140 if ( ( wiener = curropt->value.real() ) < 0.000001 )
141 cerr << "-wiener: A Wiener factor must be specified!" << endl;
142 else {
143 if ( wiener < 0.01 ) wiener = 0.01;
144 // if ( wiener > 1 ) wiener = 1;
145 }
146 }
147 if ( curropt->tag == "ratio" )
148 if ( ( sampling_ratio = curropt->value.real() ) < 1 )
149 cerr << "-ratio: A ratio must be specified!" << endl;
150 if ( curropt->tag == "fast" ) {
151 if ( ( fast_angle = curropt->value.real() ) < 1 )
152 cerr << "-fast: An angle must be specified!" << endl;
153 else
154 fast_angle *= M_PI/180.0;
155 }
156 if ( curropt->tag == "symmetry" )
157 symmetry_string = curropt->symmetry_string();
158 if ( curropt->tag == "base" ) {
159 partbase = curropt->value;
160 if ( partbase.length() < 1 )
161 cerr << "-base: The particle base file name must be specified!" << endl;
162 }
163 if ( curropt->tag == "path" ) {
164 partpath = curropt->value;
165 if ( partpath.length() < 1 )
166 cerr << "-path: The particle file path must be specified!" << endl;
167 else
168 if ( partpath[-1] != '/' ) partpath += "/";
169 }
170 if ( curropt->tag == "extension" ) {
171 partext = curropt->value;
172 if ( partext.length() < 1 )
173 cerr << "-extension: The particle file extension must be specified!" << endl;
174 }
175 if ( curropt->tag == "output" )
176 outfile = curropt->filename();
177 if ( curropt->tag == "Postscript" )
178 psfile = curropt->filename();
179 }
180 option_kill(option);
181
182 double ti = timer_start();
183
184 // Read all the parameter files
185 Bstring* file_list = NULL;
186 while ( optind < argc ) string_add(&file_list, argv[optind++]);
187 if ( !file_list ) {
188 cerr << "Error: No parameter files specified!" << endl;
189 bexit(-1);
190 }
191
192 Bproject* project = read_project(file_list);
193 string_kill(file_list);
194
195 if ( !project ) {
196 cerr << "Error: No input file read!" << endl;
197 bexit(-1);
198 }
199
200 if ( add_coordinates ) {
201 project->select = transfer - 1;
202 project_add_origins_to_coords(project);
203 }
204
205 if ( sam[0] ) {
206 project->select = 0;
207 project_set_pixel_size(project, sam[0]);
208 project->select = 1;
209 project_set_pixel_size(project, sam[0]);
210 }
211
212 if ( box_size ) {
213 project->select = 0;
214 project_set_particle_box_size(project, box_size);
215 project->select = 1;
216 project_set_particle_box_size(project, box_size);
217 }
218
219 if ( transfer ) {
220 project->select = transfer - 1;
221 if ( !part_series_from_seed(project, zflip | use_view) ) {
222 cerr << "Error: No particles transferred!" << endl;
223 bexit(-1);
224 }
225 }
226
227 Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
228
229 if ( part_recon )
230 project_tomo_reconstruct_particles(project, resolution,
231 interp_type, pad_factor, ctf_action, wiener, sym,
232 partbase, partpath, partext);
233
234 Bplot* plot = NULL;
235 if ( nloo ) {
236 plot = project_tomo_particle_resolution(project, nloo, sampling_ratio,
237 fast_angle, cutoff);
238 if ( psfile.length() ) ps_plot(psfile, plot);
239 delete plot;
240 }
241
242 if ( outfile.length() ) {
243 project_update_comment(project, argc, argv);
244 write_project(outfile, project, 0, 0);
245 }
246
247 kill_symmetry(sym);
248 project_kill(project);
249
250 if ( verbose & VERB_TIME )
251 timer_report(ti);
252
253 bexit(0);
254 }
255
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: btompart.cpp:25
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
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:245
mg_particle_select.h
Select particles.
symmetry.h
Header file for general symmetry functions.
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
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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
verbose
int verbose
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
project_set_particle_box_size
int project_set_particle_box_size(Bproject *project, Vector3< long > box_size)
Sets particle box size to the given value.
Definition: mg_processing.cpp:3693
M_PI
#define M_PI
Definition: utilities.h:59
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
part_series_from_seed
long part_series_from_seed(Bproject *project, int flags)
Calculates the locations of particles in a series from a seed.
Definition: mg_particle_select.cpp:2454
mg_tomography.h
Header file for single particle image processing in Bsoft.
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
project_add_origins_to_coords
int project_add_origins_to_coords(Bproject *project)
Adds the particle origins to the micrograph coordinates.
Definition: mg_processing.cpp:3563
Bsymmetry
Definition: symmetry.h:38
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
Bproject::select
int select
Definition: mg_processing.h:339
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 >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
project_tomo_reconstruct_particles
long project_tomo_reconstruct_particles(Bproject *project, double resolution, int interp_type, int pad_factor, int ctf_action, double wiener, Bsymmetry *sym, Bstring &partbase, Bstring &partpath, Bstring &partext)
Reconstructs particles from a tilt series.
Definition: mg_tomo_rec.cpp:604
project_tomo_particle_resolution
Bplot * project_tomo_particle_resolution(Bproject *project, double hi_res, double sampling_ratio, double fast_angle, double cutoff)
Estimates the resolution for each particle image in each micrograph.
Definition: mg_tomo_resol.cpp:408
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
options.h
Header file for option handlers.
mg_reconstruct.h
Functions for reconstruction.
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
main
int main(int argc, char **argv)
Definition: btompart.cpp:69
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
Bplot
Definition: Bplot.h:146