| Bsoft 2.0.5 Bernard's software package

bctf.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "mg_ctf.h"
11 #include "mg_ctf_fit.h"
12 #include "ps_ctf_plot.h"
13 #include "ps_micrograph.h"
14 #include "mg_processing.h"
15 #include "mg_tomography.h"
16 #include "rwmg.h"
17 #include "file_util.h"
18 #include "utilities.h"
19 #include "options.h"
20 #include "timer.h"
21
22 // Declaration of global variables
23 extern int verbose; // Level of output to the screen
24
25 // Usage assistance
26 const char* use[] = {
27 " ",
28 "Usage: bctf [options] input.star/input.img [input2.star/output.img]",
29 "-------------------------------------------------------------------",
30 "Applies, determines or corrects for the CTF (contrast transfer function) in electron micrographs.",
31 " ",
32 "Actions:",
33 "-action correct Action: 1=flip, 2=apply, 3=correct, 4=wienerfilter,",
34 " 5=baseline, 6=baseline2, 7=baseflip, 8=basecorrect,",
35 " 11=prepare, 12=fit, 13=prepfit (default 0=none).",
36 "-invertaxis Inverts the tilt axis to correct for improper setup.",
37 "-filter Filter extremes before doing anything with the image.",
38 "-background Correct background after applying CTF (default not).",
39 "-fitastigmatism 2 Fit astigmatism for individual micrographs (1) or combined (2) (default not).",
40 "-toparticle Transfer micrograph CTF parameters to particle records (default not).",
41 "-ctf 512,512,2 Generate a CTF image of this size with flag: 1=center, 2=power, 3=both.",
42 " ",
43 "Parameters:",
44 "-verbose 7 Verbosity of output.",
45 "-datatype u Force writing of a new data type.",
46 "-mgpath dir/subdir Set the micrograph file paths.",
47 "-pspath dir/subdir Set the power spectrum file paths.",
48 "-partpath dir/subdir Set the particle file paths.",
49 "-tile 1024,1024,1 Size of power spectrum generated during preparation (default 512,512,1).",
50 "-micrograph Use micrograph file given in parameter file instead of particle file.",
51 "-frames Use micrograph frames file given in parameter file instead of particle file.",
52 "-sampling 1.5,1.5,1.5 Sampling (angstrom/pixel, a single value sets all three).",
53 "-resolution 27.5,125.3 Resolution limits for CTF determination and application (default 0.1,1e6).",
54 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
55 "-Defocus 1.2,1.0,47 Defocus average & deviation, and astigmatism angle (default 2 um, 0 um, 0).",
56 "-Astigmatism 0.3,-34 Set defocus deviation and astigmatism angle (um, degrees).",
57 "-axis 74.7 Tilt axis angle relative to x-axis (default 0 or from parameter file).",
58 "-tilt 15 Tilt angle (default from parameter file).",
59 "-Volt 100 Set the acceleration voltage (default 120 kV).",
60 "-Amplitude 0.07 Set the amplitude contrast (default 0.07).",
61 "-Cs 2.0 Set the spherical aberration, Cs (default 2.0 mm).",
62 "-Cc 2.0 Set the chromatic aberration, Cc (default 2.0 mm).",
63 "-alpha 0.15 Set the illumination half-angle (default 0.1 milliradians).",
64 "-energyspread 0.9 Set the effective energy spread (default 1 eV).",
65 "-basetype 2 Baseline type: (default 1)",
66 " Type 1: Polynomial with 5 coefficients.",
67 " Type 2: Double Gaussian with 5 coefficients.",
68 " Type 3: EMAN style with 4 coefficients.",
69 " Types 4-6: 1-3 with gaussian fit of water ring (only for high resolution limit < 3 A).",
70 "-baseline 1,1.5,-2.6,12.9,30,118 Baseline type and 4 or 5 coefficients: (default 1,0,0,0,0)",
71 "-envtype 3 Envelope type: (default 4)",
72 " Type 1: Single gaussian (2 coefficients).",
73 " Type 2: Single gaussian with constant (3 coefficients).",
74 " Type 3: Double gaussian (4 coefficients).",
75 " Type 4: Double gaussian with constant (5 coefficients).",
76 "-envelope 28,-563,0.78,-215 Envelope coefficients: Double gaussian with 4 coefficients (default 1,-10,0,0).",
77 " ",
78 "Fitting parameters:",
79 "-Range 0.6,3.5,0.2 Defocus minimum, maximum and increment for fitting (default 0.1,20,0.1 um).",
80 " ",
81 "Output:",
82 "-output file.star Output parameter file.",
83 "-PSaverage file.mrc Output average power spectrum.",
84 "-Postscript file.ps Postscript output file name for CTF fit.",
85 "-Histogram file.ps Postscript output file name for defocus histogram.",
86 "-Plotastigmatism file.ps Postscript output file name for astigmatism.",
87 "-Average file.ps Postscript output file name for average of all CTF curves.",
88 "-Zeroes file.ps Postscript output file name for defocus-vs-zeroes plot.",
89 "-Envelope file.ps Envelope curve output file name.",
90 "-Pointspread file.ps Point spread curve output file name.",
91 "-Function ctf.mrc Contrast transfer function output file name.",
92 " ",
93 "Examples:",
94 "To apply the CTF:",
95 "bctf -verbose 7 -action apply -Defocus 2.3 input.img distorted.img",
96 " ",
97 "To prepare a power spectrum from a micrograph and to fit the CTF:",
98 "bctf -v 7 -datatype float -action prepfit -sam 1.842 -out new.star mg0001.tif mg0001_ps.pif",
99 " This is a good way to generate the initial STAR file for each micrograph",
100 " of a single particle analysis effort, as well as a power spectrum file.",
101 " Subsequently, the automatic fit should be checked and corrected in bshow.",
102 " ",
103 "To correct for the CTF by simply flipping the phases in every second Thon ring:",
104 "bctf -verbose 7 -action flip -Defocus 1.4 part.pif part_flip.pif",
105 " Applying the same flipping operation twice will recover the original image.",
106 " ",
107 "To correct for the CTF:",
108 "bctf -v 7 -action correct -Defocus 1.9 -wiener 0.1 part.pif part_corr.pif",
109 " The equation used for the correction is:",
110 " U = I*C/(C^2 + w)",
111 " where:",
112 " U: corrected image",
113 " I: distorted image",
114 " C: CTF",
115 " w: Wiener factor, default 0.2",
116 " ",
117 "To correct for the CTF with baseline compensation:",
118 "bctf -v 7 -act baseline -Def 1.2 -wien 0.2 -base 1,1.5,-2.6,12.9,30,118 part.pif part_corr.pif",
119 " The equation used for the correction is:",
120 " U = I*C/(B*C^2 + w)",
121 " where:",
122 " U: corrected image",
123 " I: distorted image",
124 " C: CTF",
125 " B: baseline",
126 " w: Wiener factor, default 0.2",
127 " Baseline equations:",
128 " 1. a0 + a1*s + a2*s^2 + a3*s^3 + a4*s^4",
129 " 2. a0 + a1*e^(a2*s^2) + a3*e^(a4*s^2)",
130 " 3. a0 + a1*e^(a2*s^0.5 + a3*s^2)",
131 " ",
132 NULL
133 };
134
135 int main(int argc, char **argv)
136 {
137 // Initialize variables
138 DataType nudatatype(Unknown_Type); // Conversion to new type
139 int invert_axis(0); // Flag to invert micrograph matrices
140 int toparticle(0); // Flag to transfer parameters to particles
141 Bstring mgpath; // Micrograph file path
142 Bstring pspath; // Power spectrum file path
143 Bstring partpath; // Particle file path
144 Vector3<double> sam; // Pixel size
145 Vector3<long> tile_size(512,512,1); // Size of power spectrum
146 double resolution_lo(0); // Low resolution limit
147 double resolution_hi(0); // High resolution limit
148 int action(0); // Default no CTF operation
149 int ctf_flag(0); // Flag for CTF image: bit 1 = center, bit 2 = power
150 double wiener(0.2); // Wiener for CTF correction
151 double def_avg(2e4); // In angstrom
152 double def_dev(0); // In angstrom
153 double ast_angle(-1); // Used to limit astigmatism
154 double tilt_axis(0); // Tilt axis angle in radians
155 double tilt_angle(0); // Tilt angle start in radians
156 double volts(120000); // In volts
157 double amp_fac(0.07); // Amplitude fraction
158 double Cs(2e7); // Spherical aberration (angstrom)
159 double Cc(2e7); // Chromatic aberration (angstrom)
160 double alpha(0.0001); // Beam source size (radians)
161 double energy_spread(1); // Effective energy spread (eV)
162 int basetype(1); // Baseline type: 1=poly, 2=double_gauss, 3=EMAN
163 double base[5] = {1,0,0,0,0}; // Baseline coefficients
164 int envtype(4); // Envelope type: 1=gauss, 2=gauss+, 3=double_gauss, 4=double_gauss+
165 double env[5] = {1,-10,0,0,0}; // Envelope coefficients
166 double def_start(1e3), def_end(2e5), def_inc(1e3); // Defocus fitting range and increment
167 int setDefocus(0); // Flags
168 int setvolts(0);
169 int setamp(0);
170 int setCs(0);
171 // int setCc(0);
172 // int setalpha(0);
173 // int setespread(0);
174 int setbase(0);
175 int setenv(0);
176 int flags(0); // Flags for using mg (1), filter extremes (2), background (4), astigmatism (8), use frames (16)
177 int fitastig(0); // Flag to fit astigmatism individually (1) or global (2)
178 Vector3<long> size(1,1,1); // Size of CTF output file
179 Bstring outfile; // Output STAR file name
180 Bstring psaverage; // Output power spectrum average file name
181 Bstring psctffile; // Output postscript file for CTF fit
182 Bstring pshisfile; // Output postscript file for defocus histogram
183 Bstring psastfile; // Astigmatism plot file
184 Bstring psavgfile; // Output postscript file for average CTF
185 Bstring pszeroesfile; // Output postscript file for zeroes
186 Bstring psenvfile; // Output postscript file for envelope
187 Bstring pspointfile; // Output postscript file for point spread function
188 Bstring funcfile; // Output image file for CTF
189 int wave_aberration(0); // Flag to output wave aberration function
190
191 int i, optind;
192 Boption* option = get_option_list(use, argc, argv, optind);
193 Boption* curropt;
194 for ( curropt = option; curropt; curropt = curropt->next ) {
195 if ( curropt->tag == "datatype" )
196 nudatatype = curropt->datatype();
197 if ( curropt->tag == "action" )
198 action = curropt->ctf_action();
199 if ( curropt->tag == "invertaxis" )
200 invert_axis = 1;
201 if ( curropt->tag == "toparticle" ) toparticle = 1;
202 if ( curropt->tag == "ctf" ) {
203 size = curropt->size();
204 ctf_flag = size[2];
205 size[2] = 1;
206 if ( size.volume() < 1 )
207 cerr << "-size: All three dimensions must be specified." << endl;
208 }
209 if ( curropt->tag == "tile" ) {
210 tile_size = curropt->size();
211 if ( tile_size.volume() < 1 )
212 cerr << "-tile: All three dimensions must be specified." << endl;
213 }
214 if ( curropt->tag == "micrograph" )
215 flags |= 1;
216 if ( curropt->tag == "frames" )
217 flags |= 17;
218 if ( curropt->tag == "filter" )
219 flags |= 2;
220 if ( curropt->tag == "background" )
221 flags |= 4;
222 if ( curropt->tag == "fitastigmatism" ) {
223 fitastig = curropt->value.integer();
224 if ( fitastig == 1 ) flags |= 8;
225 }
226 if ( curropt->tag == "mgpath" ) {
227 mgpath = curropt->value;
228 if ( mgpath.length() < 1 )
229 cerr << "-mgpath: The micrograph file path must be specified!" << endl;
230 else
231 if ( mgpath[-1] != '/' ) mgpath += "/";
232 }
233 if ( curropt->tag == "pspath" ) {
234 pspath = curropt->value;
235 if ( pspath.length() < 1 )
236 cerr << "-pspath: The power spectrum file path must be specified!" << endl;
237 else
238 if ( pspath[-1] != '/' ) pspath += "/";
239 }
240 if ( curropt->tag == "partpath" ) {
241 partpath = curropt->value;
242 if ( partpath.length() < 1 )
243 cerr << "-partpath: The particle file path must be specified!" << endl;
244 else
245 if ( partpath[-1] != '/' ) partpath += "/";
246 }
247 if ( curropt->tag == "sampling" )
248 sam = curropt->sampling();
249 if ( curropt->tag == "resolution" )
250 if ( curropt->values(resolution_hi, resolution_lo) < 1 )
251 cerr << "-resolution: At least one resolution limit must be specified!" << endl;
252 if ( curropt->tag == "wiener" ) {
253 if ( ( wiener = curropt->value.real() ) < 0.000001 )
254 cerr << "-wiener: A Wiener factor must be specified!" << endl;
255 else {
256 if ( wiener < 0.01 ) wiener = 0.01;
257 // if ( wiener > 1 ) wiener = 1;
258 }
259 }
260 if ( curropt->tag == "Defocus" ) {
261 if ( curropt->values(def_avg, def_dev, ast_angle) < 1 )
262 cerr << "-Defocus: At least the defocus average must be specified!" << endl;
263 else {
264 if ( fabs(def_avg) < 20 ) def_avg *= 1e4; // Assume um
265 if ( fabs(def_dev) < 10 ) def_dev *= 1e4; // Assume um
266 ast_angle *= M_PI/180; // Assume degrees
267 setDefocus = 1;
268 }
269 }
270 if ( curropt->tag == "Astigmatism" ) {
271 if ( curropt->values(def_dev, ast_angle) < 1 )
272 cerr << "-Astigmatism: A defocus value must be specified!" << endl;
273 else {
274 if ( def_dev < 1e3 ) def_dev *= 1e4; // Assume um
275 ast_angle *= M_PI/180.0; // Assume degrees
276 }
277 }
278 if ( curropt->tag == "axis" ) {
279 tilt_axis = curropt->value.real();
280 tilt_axis = angle_set_negPI_to_PI(tilt_axis*M_PI/180.0);
281 }
282 if ( curropt->tag == "Volt" ) {
283 if ( ( volts = curropt->value.real() ) < 1 )
284 cerr << "-Volt: A voltage must be specified!" << endl;
285 else {
286 if ( volts < 1e3 ) volts *= 1e3; // Assume kilovolts
287 setvolts = 1;
288 }
289 }
290 if ( curropt->tag == "Amplitude" ) {
291 if ( ( amp_fac = curropt->value.real() ) < 0 ) {
292 cerr << "-Amplitude: A fraction must be specified!" << endl;
293 amp_fac = 0;
294 } else {
295 if ( amp_fac > 1 ) amp_fac /= 100; // Assume percentage
296 if ( amp_fac > 1 ) amp_fac = 1;
297 setamp = 1;
298 }
299 }
300 if ( curropt->tag == "tilt" ) {
301 tilt_angle = curropt->value.real();
302 tilt_angle = angle_set_negPI_to_PI(tilt_angle*M_PI/180.0);
303 }
304 if ( curropt->tag == "Cs" ) {
305 Cs = curropt->value.real();
306 // if ( ( Cs = curropt->value.real() ) < 1e-6 )
307 // cerr << "-Cs: A Cs value must be specified!" << endl;
308 // else {
309 if ( fabs(Cs) < 10 ) Cs *= 1e7; // Assume mm
310 setCs = 1;
311 // }
312 }
313 if ( curropt->tag == "Cc" ) {
314 if ( ( Cc = curropt->value.real() ) < 0.1 )
315 cerr << "-Cc: A Cc value must be specified!" << endl;
316 else {
317 if ( Cc < 1e3 ) Cc *= 1e7; // Assume mm
318 // setCc = 1;
319 }
320 }
321 if ( curropt->tag == "alpha" ) {
322 if ( ( alpha = curropt->value.real() ) < 1e-10 )
323 cerr << "-alpha: A value must be specified!" << endl;
324 else {
325 if ( alpha > 0.01 ) alpha /= 1000; // Assume milliradians
326 // setalpha = 1;
327 }
328 }
329 if ( curropt->tag == "energyspread" ) {
330 if ( ( energy_spread = curropt->value.real() ) < 1e-10 )
331 cerr << "-energyspread: A value must be specified!" << endl;
332 else {
333 if ( energy_spread > 0.001 ) energy_spread /= 1e5; // Assume eV
334 // setespread = 1;
335 }
336 }
337 if ( curropt->tag == "basetype" ) {
338 basetype = curropt->value.integer();
339 if ( basetype < 1 || basetype > 6 ) {
340 basetype = 1;
341 cerr << "Warning: The baseline type must be 1, 2 or 3. Reset to 1." << endl;
342 } else
343 setbase = 1;
344 }
345 if ( curropt->tag == "baseline" ) {
346 vector<double> d = curropt->value.split_into_doubles(",");
347 for ( size_t i=0; i<d.size(); i++ ) base[i] = d[i];
348 if ( d.size() < 1 )
349 cerr << "-baseline: At least one coefficient must be specified!" << endl;
350 else
351 setbase = 2;
352 }
353 if ( curropt->tag == "envtype" ) {
354 envtype = curropt->value.integer();
355 if ( envtype < 1 || envtype > 4 ) {
356 envtype = 4;
357 cerr << "Warning: The envelope type must be 1, 2, 3 or 4. Reset to 4." << endl;
358 } else
359 setenv = 1;
360 }
361 if ( curropt->tag == "envelope" ) {
362 vector<double> d = curropt->value.split_into_doubles(",");
363 for ( size_t i=0; i<d.size(); i++ ) env[i] = d[i];
364 if ( d.size() < 1 )
365 cerr << "-envelope: At least an envelope amplitude must be specified!" << endl;
366 else
367 setenv = 2;
368 }
369 if ( curropt->tag == "Range" ) {
370 if ( curropt->values(def_start, def_end, def_inc) < 1 )
371 cerr << "-Range: At least two values must be specified!" << endl;
372 else {
373 if ( def_start < 100 ) def_start *= 1e4; // Assume um
374 if ( def_end < 100 ) def_end *= 1e4; // Assume um
375 if ( def_inc < 10 ) def_inc *= 1e4; // Assume um
376 }
377 }
378 if ( curropt->tag == "output" )
379 outfile = curropt->filename();
380 if ( curropt->tag == "PSaverage" ) {
381 psaverage = curropt->filename();
382 fitastig = 2;
383 }
384 if ( curropt->tag == "Postscript" )
385 psctffile = curropt->filename();
386 if ( curropt->tag == "Histogram" )
387 pshisfile = curropt->filename();
388 if ( curropt->tag == "Plotastigmatism" )
389 psastfile = curropt->filename();
390 if ( curropt->tag == "Average" )
391 psavgfile = curropt->filename();
392 if ( curropt->tag == "Zeroes" )
393 pszeroesfile = curropt->filename();
394 if ( curropt->tag == "Envelope" )
395 psenvfile = curropt->filename();
396 if ( curropt->tag == "Pointspread" )
397 pspointfile = curropt->filename();
398 if ( curropt->tag == "Function" ) {
399 funcfile = curropt->filename();
400 // wave_aberration = 1;
401 }
402 }
403 option_kill(option);
404
405 double ti = timer_start();
406
407 if ( pszeroesfile.length() ) if ( pszeroesfile.contains(".ps") )
408 ps_ctf_defocus_zeroes(pszeroesfile, volts, Cs, asin(amp_fac));
409
410 string label = get_cmd_line(argc, argv);
411
412 Bimage* p = NULL;
413 CTFparam cp;
414 cp.defocus_average(def_avg);
415 cp.defocus_deviation(def_dev);
416 cp.astigmatism_angle(ast_angle);
417 cp.volt(volts);
418 cp.amp_shift(asin(amp_fac));
419 cp.Cs(Cs);
420 cp.Cc(Cc);
421 cp.alpha(alpha);
422 cp.dE(energy_spread);
423
424 if ( psenvfile.length() ) {
425 cp.show();
426 double freq_step = (resolution_hi)? 0.001/resolution_hi: 0.0005;
427 ps_ctf_plot(psenvfile, cp, 1000, freq_step);
428 }
429
430 if ( pspointfile.length() ) {
431 cp.show();
432 double freq_step = (resolution_hi)? 0.001/resolution_hi: 0.0005;
433 ps_point_spread(pspointfile, cp, 1000, freq_step);
434 }
435
436 if ( funcfile.length() ) {
437 if ( size.volume() < 2 && optind < argc ) {
438 if ( file_type(argv[optind]) == Image ) {
439 p = read_img(argv[optind], 0, 0);
440 if ( p ) {
441 size = p->size();
442 delete p;
443 }
444 }
445 }
446 if ( size.volume() > 1 ) {
447 if ( action < 1 ) action = 2; // Only CTF function - no baseline or envelope
448 if ( wave_aberration )
449 p = img_wave_aberration(cp, size, sam);
450 else
451 p = img_ctf_calculate(cp, action, wiener, size,
452 sam, resolution_lo, resolution_hi);
453 if ( ctf_flag & 1 ) p->center_wrap();
454 if ( ctf_flag & 2 ) p->square();
455 p->change_type(nudatatype);
456 p->label(label);
457 write_img(funcfile, p, 0);
458 delete p;
459 } else {
460 cerr << "Error: A size needs to be given for the CTF function image!" << endl;
461 bexit(-1);
462 }
463 }
464
465 Bproject* project = NULL;
466 Bfield* field = NULL;
467 Bmicrograph* mg = NULL;
468 Breconstruction* rec = NULL;
469 Bparticle* part = NULL;
470 Bstring* file_list = NULL;
471 Bstring basename, newfilename;
472
473 if ( optind < argc ) {
474 if ( file_type(argv[optind]) == Micrograph ) {
475 while ( optind < argc ) string_add(&file_list, argv[optind++]);
476 project = read_project(file_list);
477 string_kill(file_list);
478 if ( project_count_mg_particles(project) < 1 ) flags |= 1;
479 } else {
480 p = read_img(argv[optind++], 0, -1);
481 if ( !p ) bexit(-1);
482 if ( nudatatype == Unknown_Type )
483 nudatatype = p->data_type();
484 project = project_init();
485 basename = (Bstring(p->file_name())).base();
486 if ( p->sizeZ() < 2 ) { // Create a micrograph record
487 field = field_add(&project->field, basename);
488 mg = micrograph_add(&field->mg, basename);
489 mg->ctf = new CTFparam;
490 mg->ctf->update(cp);
491 mg->pixel_size = p->sampling()[0];
492 mg->tilt_angle = tilt_angle;
493 mg->tilt_axis = tilt_axis;
494 mg->origin = p->image->origin();
495 if ( action == 12 ) {
496 mg->fps = p->file_name();
497 } else if ( p->images() > 1 ) {
498 mg->fpart = p->file_name();
499 for ( i=1; i<=p->images(); i++ ) {
500 part = particle_add(&part, i);
501 if ( !mg->part ) mg->part = part;
502 }
503 } else {
504 mg->fmg = p->file_name();
505 flags |= 1;
506 }
507 } else { // Create a reconstruction record
508 project->select = 1;
509 rec = reconstruction_add(&project->rec, basename);
510 rec->ctf = new CTFparam;
511 rec->ctf->update(cp);
512 rec->voxel_size = p->sampling()[0];
513 rec->origin = p->image->origin();
514 if ( p->images() > 1 ) {
515 rec->fpart = p->file_name();
516 for ( i=1; i<=p->images(); i++ ) {
517 part = particle_add(&part, i);
518 if ( !rec->part ) rec->part = part;
519 }
520 } else {
521 rec->frec = p->file_name();
522 flags |= 1;
523 }
524 }
525 if ( optind < argc ) newfilename = argv[optind];
526 delete p;
527 if ( access(newfilename.c_str(), F_OK) == 0 ) {
528 cerr << "Error: The output file, " << newfilename << ", already exists!" << endl;
529 bexit(-1);
530 }
531 }
532 }
533
534 if ( project == NULL ) {
535 cerr << "Error: No input file read!" << endl;
536 bexit(-1);
537 }
538
539 if ( mgpath.length() )
540 project_set_micrograph_path(project, mgpath);
541
542 // Set the sampling for all the micrographs
543 if ( sam[0] )
544 project_set_pixel_size(project, sam[0]);
545
546 // Set the defocus values for all the micrographs
547 if ( setDefocus )
548 project_set_defocus(project, def_avg, def_dev, ast_angle);
549 else if ( def_dev )
550 project_set_astigmatism(project, def_dev, ast_angle);
551
552 // Set the tile parameters for all the micrographs
553 if ( tilt_angle )
554 project_set_tilt(project, tilt_axis, tilt_angle);
555
556 // Invert the geometry in case it is incorrectly set up
557 if ( invert_axis )
558 project_invert_tilt_axis(project);
559
560 // Set other parameters
561 if ( setvolts )
562 project_set_volts(project, volts);
563 if ( setCs )
564 project_set_Cs(project, Cs);
565 if ( setamp )
566 project_set_amp_shift(project, sin(amp_fac));
567 if ( setbase == 1 )
568 project_set_baseline_type(project, basetype);
569 if ( setenv == 1 )
570 project_set_envelope_type(project, envtype);
571 if ( setbase > 1 )
572 project_set_baseline(project, basetype, base);
573 if ( setenv > 1 )
574 project_set_envelope(project, envtype, env);
575
576 if ( toparticle )
577 project_CTF_to_part(project);
578
579 // cout << " action = " << action << endl;
580
581 // Determine the CTF in all micrographs
582 Bstring blabel(label);
583 if ( action > 0 && action < 11 )
584 project_ctf(project, action, resolution_lo, resolution_hi, tile_size, wiener,
585 nudatatype, partpath, newfilename, blabel, flags);
586 else if ( action > 10 )
587 project_ctf_prepare(project, action, resolution_lo, resolution_hi, tile_size,
588 def_start, def_end, def_inc, pspath, newfilename, blabel, flags);
589
590 if ( psctffile.length() )
591 project_plot_ctf(project, psctffile);
592
593 if ( pshisfile.length() )
594 ps_defocus_histogram(pshisfile, project);
595
596 if ( psastfile.length() )
597 ps_astigmatism_plot(psastfile, project);
598
599 if ( psavgfile.length() )
600 project_ctf_average(project, psavgfile);
601
602 // Write an average power spectrum if a file name is given
603 Bimage* ps = NULL;
604 if ( fitastig == 2 ) {
605 cp.update(project->field->mg->ctf);
606 cp.defocus_average(2e4);
607 ps = project_powerspectrum_average(project, cp.defocus_average());
608 if ( ps ) {
609 img_ctf_fit_astigmatism(ps, 0, cp, resolution_lo, resolution_hi);
610 if ( verbose )
611 cout << "Astigmatism deviation and angle: " << cp.defocus_deviation() <<
612 tab << cp.astigmatism_angle()*180.0/M_PI << endl;
613 project_set_astigmatism(project, cp.defocus_deviation(), cp.astigmatism_angle());
614 } else {
615 cerr << "Error: Failed to calculate an average power spectrum!" << endl;
616 }
617 }
618
619 if ( ps && psaverage.length() ) {
620 ps->label(get_cmd_line(argc, argv));
621 write_img(psaverage, ps, 0);
622 }
623
624 delete ps;
625
626 // Write an output STAR format file if a name is given
627 if ( project && outfile.length() ) {
628 project_update_comment(project, argc, argv);
629 write_project(outfile, project, 0, 0);
630 }
631
632 project_kill(project);
633
634 if ( verbose & VERB_TIME )
635 timer_report(ti);
636
637 bexit(0);
638 }
639
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.
CTFparam::Cs
double Cs()
Definition: ctf.h:87
project_set_defocus
int project_set_defocus(Bproject *project, double def_avg, double def_dev, double ast_angle)
Sets the defocus values of all the micrographs.
Definition: mg_ctf.cpp:1425
Bstring::real
double real()
Definition: Bstring.cpp:545
Bimage::square
void square()
Calculates the square of an image.
Definition: Bimage_rescale.cpp:678
ps_micrograph.h
Header file for postscript tools dealing with micrograph particle sets.
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
CTFparam::dE
double dE()
Definition: ctf.h:93
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
ps_defocus_histogram
int ps_defocus_histogram(Bstring &filename, Bproject *project)
Postscript histogram plot of micrograph defocus parameters.
Definition: ps_micrograph.cpp:558
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
img_ctf_calculate
Bimage * img_ctf_calculate(CTFparam cp, int action, double wiener, Vector3< long > size, Vector3< double > sam, double lores=0, double hires=0)
Calculates a CTF complex image.
Definition: mg_ctf.cpp:45
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
ps_point_spread
int ps_point_spread(Bstring &filename, CTFparam &em_ctf, size_t n, double freq_step)
Generates a point spread plot from CTF envelope parameters.
Definition: ps_ctf_plot.cpp:337
utilities.h
Header file for general utilities.
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Breconstruction
Definition: mg_processing.h:280
Boption::tag
Bstring tag
Definition: options.h:29
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
project_set_envelope
int project_set_envelope(Bproject *project, int type, double *coeff)
Sets the envelope equations of all the micrographs.
Definition: mg_ctf.cpp:1653
CTFparam::update
int update(CTFparam *ctf)
Definition: ctf.h:77
project_invert_tilt_axis
int project_invert_tilt_axis(Bproject *project)
Inverts the tilt axis in a project parameter structure.
Definition: mg_tomography.cpp:1694
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
project
Bproject * project
Definition: bshow.cpp:31
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_processing.cpp:811
Breconstruction::ctf
CTFparam * ctf
Definition: mg_processing.h:303
project_set_tilt
int project_set_tilt(Bproject *project, double tilt_axis, double tilt_angle)
Sets the tilt parameters for all the micrographs.
Definition: mg_processing.cpp:3427
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
Bimage::center_wrap
int center_wrap()
Centers an image with wrapping.
Definition: Bimage_transform.cpp:713
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
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
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:217
project_set_baseline
int project_set_baseline(Bproject *project, int type, double *coeff)
Sets the baseline equations of all the micrographs.
Definition: mg_ctf.cpp:1746
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
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
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:29
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
timer.h
Utilities for timing functions.
ps_ctf_plot
int ps_ctf_plot(Bstring &filename, CTFparam &em_ctf, size_t n, double freq_step)
Generates a postscript plot from CTF parameters for defocus and the envelope.
Definition: ps_ctf_plot.cpp:71
Bimage
General image parameter class.
Definition: Bimage.h:163
project_ctf_prepare
int project_ctf_prepare(Bproject *project, int action, double lores, double hires, Vector3< long > tile_size, double def_start, double def_end, double def_inc, Bstring &path, Bstring &newname, Bstring &label, int flags)
Calculates power spectra and optionally fits CTF curves.
Definition: mg_ctf.cpp:717
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Boption::size
Vector3< long > size()
Definition: options.h:163
Micrograph
Definition: file_util.h:23
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:216
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
ps_ctf_defocus_zeroes
int ps_ctf_defocus_zeroes(Bstring &filename, double volts, double Cs, double amp_shift)
Generates a postscript plot of defocus versus zeroes.
Definition: ps_ctf_plot.cpp:233
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bfield
Definition: mg_processing.h:257
M_PI
#define M_PI
Definition: utilities.h:59
project_set_volts
int project_set_volts(Bproject *project, double volts)
Sets the acceleration voltage of all the micrographs.
Definition: mg_ctf.cpp:1510
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
base
string base(string &filename)
Definition: string_util.cpp:28
project_ctf_average
int project_ctf_average(Bproject *project, Bstring &psname)
Calculates or fits CTF curves to multiple power spectra.
Definition: mg_ctf.cpp:1221
Boption
A class for a command line input option.
Definition: options.h:26
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
img_ctf_fit_astigmatism
double img_ctf_fit_astigmatism(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires)
Fits the astigmatism with a given defocus, baseline and envelope.
Definition: mg_ctf_fit.cpp:557
project_set_astigmatism
int project_set_astigmatism(Bproject *project, double def_dev, double ast_angle)
Sets the defocus deviation and astigmatism angle of all the micrographs.
Definition: mg_ctf.cpp:1476
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
project_set_micrograph_path
int project_set_micrograph_path(Bproject *project, Bstring &path)
Sets the path to micrograph files for all the micrographs.
Definition: mg_processing.cpp:3167
CTFparam::show
void show()
Definition: ctf.h:232
Bmicrograph
Definition: mg_processing.h:200
project_plot_ctf
int project_plot_ctf(Bproject *project, Bstring &filename)
Plots the CTF curves.
Definition: mg_ctf.cpp:1811
mg_tomography.h
Header file for single particle image processing in Bsoft.
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
main
int main(int argc, char **argv)
Definition: bctf.cpp:135
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
project_set_baseline_type
int project_set_baseline_type(Bproject *project, int type)
Sets the baseline type of all the micrographs.
Definition: mg_ctf.cpp:1716
file_util.h
Header file for file checking functions.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
verbose
int verbose
project_set_envelope_type
int project_set_envelope_type(Bproject *project, int type)
Sets the envelope type of all the micrographs.
Definition: mg_ctf.cpp:1624
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
ps_ctf_plot.h
Header file for postscript output functions.
field_add
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
Definition: mg_processing.cpp:120
Bstring::base
Bstring base()
Definition: Bstring.cpp:508
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bmicrograph::fps
Bstring fps
Definition: mg_processing.h:210
Bparticle
Definition: mg_processing.h:89
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
CTFparam::volt
double volt()
Definition: ctf.h:83
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
use
const char * use[]
Definition: bctf.cpp:26
Image
Definition: file_util.h:22
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
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
Boption::ctf_action
int ctf_action()
Definition: options.h:303
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:100
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_ctf
int project_ctf(Bproject *project, int action, double lores, double hires, Vector3< long > tile_size, double wiener, DataType datatype, Bstring &partpath, Bstring &newname, Bstring &label, int flags)
Calculates or fits CTF curves to multiple power spectra.
Definition: mg_ctf.cpp:1121
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
project_set_Cs
int project_set_Cs(Bproject *project, double Cs)
Sets the spherical aberation constant of all the micrographs.
Definition: mg_ctf.cpp:1540
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bimage::images
long images()
Definition: Bimage.h:491
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:95
mg_ctf_fit.h
Header file for CTF (contrast transfer function) functions.
ps_astigmatism_plot
int ps_astigmatism_plot(Bstring &filename, Bproject *project)
Postscript plot of micrograph astigmatism parameters.
Definition: ps_micrograph.cpp:655
project_CTF_to_part
int project_CTF_to_part(Bproject *project)
Transfers CTF parameters from micrographs to particles.
Definition: mg_ctf.cpp:1384
Vector3::volume
double volume()
Definition: Vector3.h:235
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
project_set_amp_shift
int project_set_amp_shift(Bproject *project, double amp_shift)
Sets the amplitude contribution of all the micrographs.
Definition: mg_ctf.cpp:1568
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:461
CTFparam::Cc
double Cc()
Definition: ctf.h:89
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
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
CTFparam::alpha
double alpha()
Definition: ctf.h:91
Bproject
Definition: mg_processing.h:333
project_powerspectrum_average
Bimage * project_powerspectrum_average(Bproject *project, double deftarget)
Averages multiple power spectra based on defocus estimates.
Definition: mg_ctf.cpp:1294
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
CTFparam
Definition: ctf.h:26
img_wave_aberration
Bimage * img_wave_aberration(CTFparam cp, Vector3< long > size, Vector3< double > sam)
Calculates a wave aberration function.
Definition: mg_ctf.cpp:175