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