 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
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.",
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.",
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).",
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).",
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).",
82 "-json file.json Input JSON file with CTF parameters.",
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.",
99 "bctf -verbose 7 -action apply -Defocus 2.3 input.img distorted.img",
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.",
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.",
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)",
116 " U: corrected image",
117 " I: distorted image",
119 " w: Wiener factor, default 0.2",
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)",
126 " U: corrected image",
127 " I: distorted image",
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)",
139 int main(
int argc,
char **argv)
150 double resolution_lo(0);
151 double resolution_hi(0);
157 double ast_angle(-1);
159 double tilt_angle(0);
167 double base[5] = {1,0,0,0,0};
169 double env[5] = {1,-10,0,0,0};
170 double def_start(1e3), def_end(2e5), def_inc(1e3);
189 int wave_aberration(0);
197 for ( curropt = option; curropt; curropt = curropt->
next ) {
198 if ( curropt->
tag ==
"datatype" )
200 if ( curropt->
tag ==
"action" )
202 if ( curropt->
tag ==
"invertaxis" )
204 if ( curropt->
tag ==
"toparticle" ) toparticle = 1;
205 if ( curropt->
tag ==
"ctf" ) {
206 size = curropt->
size();
210 cerr <<
"-size: All three dimensions must be specified." << endl;
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;
217 if ( curropt->
tag ==
"micrograph" )
219 if ( curropt->
tag ==
"frames" )
221 if ( curropt->
tag ==
"filter" )
223 if ( curropt->
tag ==
"background" )
225 if ( curropt->
tag ==
"fitastigmatism" ) {
227 if ( fitastig == 1 ) flags |= 8;
229 if ( curropt->
tag ==
"simulate" )
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;
236 if ( mgpath[-1] !=
'/' ) mgpath +=
"/";
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;
243 if ( pspath[-1] !=
'/' ) pspath +=
"/";
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;
250 if ( partpath[-1] !=
'/' ) partpath +=
"/";
252 if ( curropt->
tag ==
"sampling" )
253 sam = curropt->
scale();
254 if ( curropt->
tag ==
"axis" ) {
258 if ( curropt->
tag ==
"tilt" ) {
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;
269 if ( wiener < 0.01 ) wiener = 0.01;
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;
277 if ( fabs(def_avg) < 20 ) def_avg *= 1e4;
278 if ( fabs(def_dev) < 10 ) def_dev *= 1e4;
279 ast_angle *=
M_PI/180;
283 if ( curropt->
tag ==
"Astigmatism" ) {
284 if ( curropt->
values(def_dev, ast_angle) < 1 )
285 cerr <<
"-Astigmatism: A defocus value must be specified!" << endl;
287 if ( def_dev < 1e3 ) def_dev *= 1e4;
288 ast_angle *=
M_PI/180.0;
292 if ( curropt->
tag ==
"basetype" ) {
294 if ( basetype < 1 || basetype > 6 ) {
296 cerr <<
"Warning: The baseline type must be 1, 2 or 3. Reset to 1." << endl;
300 if ( curropt->
tag ==
"baseline" ) {
302 for (
size_t i=0; i<d.size(); i++ )
base[i] = d[i];
304 cerr <<
"-baseline: At least one coefficient must be specified!" << endl;
308 if ( curropt->
tag ==
"envtype" ) {
310 if ( envtype < 1 || envtype > 4 ) {
312 cerr <<
"Warning: The envelope type must be 1, 2, 3 or 4. Reset to 4." << endl;
316 if ( curropt->
tag ==
"envelope" ) {
318 for (
size_t i=0; i<d.size(); i++ ) env[i] = d[i];
320 cerr <<
"-envelope: At least an envelope amplitude must be specified!" << endl;
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;
328 if ( def_start < 100 ) def_start *= 1e4;
329 if ( def_end < 100 ) def_end *= 1e4;
330 if ( def_inc < 10 ) def_inc *= 1e4;
333 if ( curropt->
tag ==
"json" )
335 if ( curropt->
tag ==
"jsonout" )
337 if ( curropt->
tag ==
"output" )
339 if ( curropt->
tag ==
"PSaverage" ) {
343 if ( curropt->
tag ==
"Postscript" )
345 if ( curropt->
tag ==
"Histogram" )
347 if ( curropt->
tag ==
"Plotastigmatism" )
349 if ( curropt->
tag ==
"Average" )
351 if ( curropt->
tag ==
"Zeroes" )
353 if ( curropt->
tag ==
"Envelope" )
355 if ( curropt->
tag ==
"Pointspread" )
357 if ( curropt->
tag ==
"Function" ) {
377 if ( psenvfile.
length() ) {
379 double freq_step = (resolution_hi)? 0.001/resolution_hi: 0.0005;
383 if ( pspointfile.
length() ) {
385 double freq_step = (resolution_hi)? 0.001/resolution_hi: 0.0005;
389 if ( funcfile.
length() ) {
390 if ( size.
volume() < 2 && optind < argc ) {
399 if ( size.
volume() > 1 ) {
400 if ( action < 1 ) action = 2;
401 if ( wave_aberration )
405 sam, resolution_lo, resolution_hi);
407 if ( ctf_flag & 2 ) p->
square();
412 cerr <<
"Error: A size needs to be given for the CTF function image!" << endl;
423 Bstring basename, filename, newfilename;
425 if ( optind < argc ) {
427 while ( optind < argc )
string_add(&file_list, argv[optind++]);
432 filename = argv[optind++];
433 if ( simulate && fabs(tilt_angle) > 0.001 ) {
447 if ( p->
sizeZ() < 2 ) {
456 if ( action == 12 ) {
458 }
else if ( p->
images() > 1 ) {
460 for ( i=1; i<=p->
images(); i++ ) {
477 for ( i=1; i<=p->
images(); i++ ) {
486 if ( optind < argc ) newfilename = argv[optind];
488 if ( access(newfilename.
c_str(), F_OK) == 0 ) {
489 cerr <<
"Error: The output file, " << newfilename <<
", already exists!" << endl;
496 cerr <<
"Error: No input file read!" << endl;
539 if ( action > 0 && action < 11 )
541 nudatatype, partpath, newfilename, flags);
542 else if ( action > 10 )
544 def_start, def_end, def_inc, pspath, newfilename, flags);
563 if ( fitastig == 2 ) {
574 cerr <<
"Error: Failed to calculate an average power spectrum!" << endl;
578 if ( ps && psaverage.
length() )
int project_set_envelope(Bproject *project, int type, double *coeff)
Sets the envelope equations of all the micrographs.
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
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.
Vector3< double > scale()
Header file for postscript tools dealing with micrograph particle sets.
int string_kill(Bstring *list)
Kills a string linked list.
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.
int project_update_ctf(Bproject *project, JSvalue &jsctf)
Sets the acceleration voltage of all the micrographs.
Header file for file checking functions.
Bimage * img_wave_aberration(CTFparam cp, Vector3< long > size, Vector3< double > sam)
Calculates a wave aberration function.
int update(CTFparam *ctf)
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
Vector3< double > voxel_size
string base(string &filename)
double astigmatism_angle()
int bexit(int value)
Exit function for cleanup and debugging.
int main(int argc, char **argv)
int ps_ctf_defocus_zeroes(Bstring &filename, double volts, double Cs, double amp_shift)
Generates a postscript plot of defocus versus zeroes.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
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.
int project_set_baseline(Bproject *project, int type, double *coeff)
Sets the baseline equations of all the micrographs.
Vector3< long > size() const
int ps_point_spread(Bstring &filename, CTFparam &em_ctf, size_t n, double freq_step)
Generates a point spread plot from CTF envelope parameters.
Header file for option handlers.
int project_ctf_average(Bproject *project, Bstring &psname)
Calculates or fits CTF curves to multiple power spectra.
int ps_astigmatism_plot(Bstring &filename, Bproject *project)
Postscript plot of micrograph astigmatism parameters.
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.
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for reading and writing micrograph parameters.
void origin(double x, double y, double z)
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
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.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Header file for postscript output functions.
int project_plot_ctf(Bproject *project, Bstring &filename)
Plots the CTF curves.
int project_set_astigmatism(Bproject *project, double def_dev, double ast_angle)
Sets the defocus deviation and astigmatism angle of all the micrographs.
Functions for CTF (contrast transfer function) processing.
int project_set_tilt(Bproject *project, double tilt_axis, double tilt_angle)
Sets the tilt parameters for all the micrographs.
General image parameter class.
Utilities for timing functions.
vector< double > split_into_doubles(const Bstring &delim)
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.
double defocus_deviation()
int center_wrap()
Centers an image with wrapping.
double timer_start()
Starts timer and prints the time.
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Header file for general utilities.
ostream & tab(ostream &out)
int project_set_baseline_type(Bproject *project, int type)
Sets the baseline type of all the micrographs.
int project_invert_tilt_axis(Bproject *project)
Inverts the tilt axis in a project parameter structure.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void change_type(char letter)
Get the data type indicated by a single letter code.
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Header file for 2D and 3D image I/O.
void square()
Calculates the square of an image.
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Header file for functions to simulate tilted micrographs.
int project_CTF_to_part(Bproject *project)
Transfers CTF parameters from micrographs to particles.
Header file for micrograph processing.
int project_set_envelope_type(Bproject *project, int type)
Sets the envelope type of all the micrographs.
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Vector3< double > pixel_size
void sampling(long nn, Vector3< double > u)
Header file for CTF (contrast transfer function) functions.
DataType
Base data type specifier.
int ps_defocus_histogram(Bstring &filename, Bproject *project)
Postscript histogram plot of micrograph defocus parameters.
bool contains(const Bstring &s)
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
CTFparam ctf_from_json(JSvalue &js)
Converts a JSON object list to microscope parameters.
void write(string filename)
Bimage * project_powerspectrum_average(Bproject *project, double deftarget)
Averages multiple power spectra based on defocus estimates.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
int project_set_defocus(Bproject *project, double def_avg, double def_dev, double ast_angle)
Sets the defocus values of all the micrographs.
int project_set_micrograph_path(Bproject *project, Bstring &path)
Sets the path to micrograph files for all the micrographs.
Header file for single particle image processing in Bsoft.
FileType file_type(const char *filename)
Checks the file type using the extension and contents.