| Bsoft 2.0.5 Bernard's software package

bmgconvert.cpp
Go to the documentation of this file.
1
13 #include "mg_processing.h"
14 #include "rwmg.h"
15 #include "rwmgSTAR.h"
16 #include "rwmgRELION.h"
17 #include "rwmgXML.h"
18 #include "mg_ctf.h"
19 #include "file_util.h"
20 #include "linked_list.h"
21 #include "utilities.h"
22 #include "options.h"
23 #include "timer.h"
24
25 #define DATLINELENGTH 120
26
27 // Declaration of global variables
28 extern int verbose; // Level of output to the screen
29
30 // Function prototypes
31 Bproject* read_project_conv(Bstring* file_list);
32 int write_project_conv(Bstring& filename, Bproject* project, int mg_select, int rec_select);
33 int read_project_dat(Bstring& filename, Bproject* project);
34 int write_project_dat(Bstring& filename, Bproject* project, int mg_select, int rec_select);
35 int read_project_crd(Bstring& filename, Bproject* project);
36 int write_project_crd(Bstring& filename, Bproject* project, int mg_select, int rec_select);
37 int project_modify_parameters(Bproject* project, char flags);
38
39 // Usage assistence
40 const char* use[] = {
41 " ",
42 "Usage: bmgconvert [options] input.star [input2.star]",
43 "----------------------------------------------------",
44 "Converts micrograph parameter files.",
45 "Supported formats:",
46 " PIC CRD files",
47 " PFT3DR DAT files",
48 " Relion STAR files",
49 "DAT and CRD files only hold one micrograph per file:",
50 " multiple micrographs are written as numbered DAT or CRD files.",
51 " use -mgselect to select only one micrograph.",
52 " ",
53 "Parameters:",
54 "-verbose 7 Verbosity of output.",
55 "-sampling 1.5 Sampling (A/pixel).",
56 "-mgselect 5 Selected micrograph (default all, first micrograph = 1).",
57 "-recselect 5 Selected reconstruction (default all, first reconstruction = 1).",
58 "-euler Convert views to Euler angles.",
59 "-omega Add or subtract 90 degrees to or from the OMEGA angle.",
60 "-magnification Invert the magnification factor: 1/mag.",
61 "-path part Path for new particles file (default current directory).",
62 "-extension pif Set the particle image file format.",
63 " ",
64 "Input:",
65 "-particles part.mrcs Input file with a stack of particles (Relion).",
66 " ",
67 "Output:",
68 "-output file.star Output parameter file.",
69 " ",
70 NULL
71 };
72
73 int main(int argc, char** argv)
74 {
75 // Initializing variables
76 double sampling(0); // A/pixel
77 int mg_select(-1);
78 int rec_select(-1);
79 int euler(0); // Flag to specify Euler angles
80 char flags(0); // Flags to modify some input parameters
81 Bstring partfile; // Relion stack of particles file
82 Bstring path; // Path for new particle files
83 Bstring partext; // Particle image file format
84 Bstring outfile; // Output parameter file
85
86 int optind;
87 Boption* option = get_option_list(use, argc, argv, optind);
88 Boption* curropt;
89 for ( curropt = option; curropt; curropt = curropt->next ) {
90 if ( curropt->tag == "sampling" )
91 if ( ( sampling = curropt->value.real() ) < 0.1 )
92 cerr << "-sampling: A pixel size must be specified" << endl;
93 if ( curropt->tag == "mgselect" )
94 if ( ( mg_select = curropt->value.integer() ) < 0 )
95 cerr << "-mgselect: A number must be specified" << endl;
96 if ( curropt->tag == "recselect" )
97 if ( ( rec_select = curropt->value.integer() ) < 0 )
98 cerr << "-recselect: A number must be specified" << endl;
99 if ( curropt->tag == "euler" )
100 euler = 1;
101 if ( curropt->tag == "magnification" )
102 flags += 1;
103 if ( curropt->tag == "omega" )
104 flags += 2;
105 if ( curropt->tag == "path" )
106 path = curropt->value;
107 if ( curropt->tag == "extension" ) {
108 partext = curropt->value;
109 if ( partext.length() < 1 )
110 cerr << "-extension: The particle file extension must be specified!" << endl;
111 }
112 if ( curropt->tag == "particles" )
113 partfile = curropt->filename();
114 if ( curropt->tag == "output" )
115 outfile = curropt->filename();
116 }
117 option_kill(option);
118
119 double ti = timer_start();
120
121 // Read all the parameter files
122 Bstring* file_list = NULL;
123 while ( optind < argc ) string_add(&file_list, argv[optind++]);
124 if ( !file_list ) {
125 cerr << "Error: No parameter files specified!" << endl;
126 bexit(-1);
127 }
128
129 Bproject* project = read_project_conv(file_list);
130
131 string_kill(file_list);
132
133 if ( project == NULL ) {
134 cerr << "Error: No project generated!" << endl;
135 bexit(-1);
136 }
137
138 if ( sampling > 0.1 )
139 project_set_pixel_size(project, sampling);
140
141 if ( flags )
142 project_modify_parameters(project, flags);
143
144 if ( euler ) project->euler_flag = 1;
145
146 if ( partfile.length() || partext.length() )
147 project_split_particles(project, partfile, path, partext);
148
149 // Write an output parameter file if a name is given
150 if ( outfile.length() ) {
151 project_update_comment(project, argc, argv);
152 write_project_conv(outfile, project, mg_select, rec_select);
153 }
154
155 project_kill(project);
156
157 if ( verbose & VERB_TIME )
158 timer_report(ti);
159
160 bexit(0);
161 }
162
163 Bproject* read_project_conv(Bstring* file_list)
164 {
165 if ( !file_list ) {
166 cerr << "Error: No micrograph parameter filename!" << endl;
167 return NULL;
168 }
169
170 Bstring ext;
171 Bstring* thisfile;
172
173 if ( verbose & VERB_LABEL ) {
174 cout << "Parameter filenames:";
175 for ( thisfile = file_list; thisfile; thisfile = thisfile->next )
176 cout << " " << *thisfile;
177 cout << endl;
178 }
179
180 int err(0);
181 FileType type;
182 Bproject* project = project_init();
183 Bfield* field = NULL;
184 Bmicrograph* mg = NULL;
185 Breconstruction* rec = NULL;
186 project->filename = *file_list;
187
188 for ( thisfile = file_list; thisfile; thisfile = thisfile->next ) {
189 for ( field = project->field; field && field->next; field = field->next ) ;
190 if ( field ) for ( mg = field->mg; mg && mg->next; mg = mg->next ) ;
191 for ( rec = project->rec; rec && rec->next; rec = rec->next) ;
192 ext = thisfile->extension();
193 err = -1;
194 if ( ext.contains("star") ) {
195 type = file_type(*thisfile);
196 if ( type == Micrograph )
197 err = read_project_star(*thisfile, project);
198 else if ( type == MgRelion )
199 err = read_project_relion(*thisfile, project);
200 else
201 cerr << "Error: The STAR file is not a valid form Bsoft can read!" << endl;
202 } else if ( ext.contains("xml") ) {
203 err = read_project_xml(*thisfile, project);
204 } else if ( ext.contains("dat") ) {
205 err = read_project_dat(*thisfile, project);
206 } else if ( ext.contains("crd") ) {
207 err = read_project_crd(*thisfile, project);
208 } else {
209 cerr << "Error: Extension " << ext << " not valid for parameter files!" << endl;
210 }
211 if ( !err ) {
212 if ( !field ) field = project->field;
213 else field = field->next;
214 if ( field ) {
215 if ( !mg ) mg = field->mg;
216 else mg = mg->next;
217 // if ( mg ) field_resolve_file_access(field, mg, *thisfile);
218 }
219 if ( !rec ) rec = project->rec;
220 else rec = rec->next;
221 // if ( rec ) reconstruction_resolve_file_access(rec, *thisfile);
222 } else {
223 cerr << " Parameter file " << *thisfile << " not read." << endl;
224 }
225 }
226
227 if ( err < 0 ) {
228 error_show(file_list->c_str(), __FILE__, __LINE__);
229 project_kill(project);
230 return NULL;
231 }
232
233 project_update_first_zero(project);
234
235 // project_check(project);
236
237 // if ( verbose & VERB_PROCESS )
238 // project_display_counts(project);
239
240 return project;
241 }
242
243 int write_project_conv(Bstring& filename, Bproject* project, int mg_select, int rec_select)
244 {
245 int err(0);
246
247 if ( filename.empty() ) {
248 cerr << "Error: No micrograph parameter filename!" << endl;
249 return -1;
250 }
251
252 project_update_first_zero(project);
253
254 // project_check(project);
255
256 // if ( verbose & VERB_PROCESS )
257 // project_display_counts(project);
258
259 Bstring ext = filename.extension();
260
261 if ( ext.contains("star") && project->split == 9 ) {
262 err = write_project_star(filename, project, mg_select, rec_select);
263 return err;
264 }
265
266 if ( verbose & VERB_LABEL )
267 cout << "Parameter filename: " << filename << endl;
268
269 if ( ext.contains("star") ) {
270 err = write_project_star(filename, project, mg_select, rec_select);
271 } else if ( ext.contains("xml") ) {
272 err = write_project_xml(filename, project, mg_select, rec_select);
273 } else if ( ext.contains("dat") ) {
274 err = write_project_dat(filename, project, mg_select, rec_select);
275 } else if ( ext.contains("crd") ) {
276 err = write_project_crd(filename, project, mg_select, rec_select);
277 } else {
278 cerr << "Error: Extension " << ext << " not valid for parameter files!" << endl;
279 cerr << " Parameter file " << filename << " not written." << endl;
280 err = -1;
281 }
282
283 if ( err < 0 )
284 error_show(filename.c_str(), __FILE__, __LINE__);
285
286 return err;
287 }
288
289
296 int read_project_dat(Bstring& filename, Bproject* project)
297 {
298 int err(0), nx(0), ny(0), n(0);
299 char inputLine[1024];
300 int unitsInHeaderI;
301 char unitsInHeaderC[10]; // "angstrom", "nm" or "pixel"
302 double px, volt, amp, def, dev, ast, cs;
303
304 Bstring field_id = filename.base();
305 Bstring mg_id = field_id;
306 Bfield* field = field_add(&project->field, field_id);
307 Bmicrograph* mg = micrograph_add(&field->mg, mg_id);
308 Bparticle* part = NULL;
309 CTFparam* ctf = mg->ctf = new CTFparam;
310
311 if ( verbose ) cout << "Reading a DAT file: " << filename << endl;
312
313 /*========================
314 Read DAT-format file
315 ========================*/
316 ifstream fdat(filename.c_str());
317 if ( fdat.fail() ) {
318 cerr << "File " << filename << " does not exist!. Exit program." << endl;
319 bexit(-1);
320 }
321
322 fdat.getline(inputLine, 1023);
323 mg->fpart = inputLine;
324 mg->fpart = mg->fpart.no_lead_space();
325 mg->fpart = mg->fpart.pre(' ');
326 mg->fpart = mg->fpart.remove('\n');
327 if ( mg->fpart.empty() ) {
328 cerr << "ERROR reading line 1 of PFT-format DAT file. Exit program" << endl;
329 exit(-1);
330 }
331
332 // General micrograph parameters
333 sscanf(strchr(inputLine+mg->fpart.length(), ' '), " %d %d %d", &nx, &ny, &n);
334 // cout << "\"" << inputLine << "\"" << nx << " " << ny << " " << n << endl;
335
336 fdat.getline(inputLine, 1023);
337 if ( !fdat.good() ) {
338 cout << "ERROR reading line 2 of PFT-format DAT file. Exit program" << endl;
339 exit(-1);
340 }
341 if ( sscanf(inputLine, "%lf,%d,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &unitsInHeaderI,
342 &volt, &amp, &def, &dev, &ast, &cs) == 8) {
343 switch(unitsInHeaderI) {
344 case 0:
345 strcpy(unitsInHeaderC, "pixels");
346 break;
347 case 1:
348 strcpy(unitsInHeaderC, "angstroms");
349 break;
350 case 2:
351 strcpy(unitsInHeaderC, "nm");
352 default:
353 break;
354 }
355 } else if ( sscanf(inputLine, "%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &volt,
356 &amp, &def, &dev, &ast, &cs) == 7) {
357 } else {
358 cout << "ERROR interpreting line 2 of PFT-format DAT file. Exit program" << endl;
359 exit(-1);
360 }
361
362 if ( volt < 1000.0 ) volt *= 1000; // Volt units for STAR-format file
363 cs *= 10000000; // Angstrom units for STAR-format file
364 if ( def < 100 ) def *= 1e4; // Angstrom units for STAR-format file
365 if ( dev < 100 ) dev *= 1e4; // Angstrom units for STAR-format file
366 def = (def + dev)/2;
367 dev -= def;
368 if ( dev < 0 ) dev = -dev;
369
370 if ( nx && ny ) mg->box_size = Vector3<int>(nx, ny, 1);
371 mg->pixel_size = px;
372 ctf->volt(volt);
373 ctf->amp_shift(asin(amp));
374 ctf->defocus_average(def);
375 ctf->defocus_deviation(dev);
376 ctf->astigmatism_angle(ast*M_PI/180.0);
377 ctf->Cs(cs);
378
379 char line[DATLINELENGTH];
380 int numpart(0), pid;
381 float theta, phi, omega, ox, oy, mag, fom1, fom2, fom3;
382
383 while ( fdat.getline(line, DATLINELENGTH) && fdat.good() ) {
384 if ( sscanf(line, "%d,%f,%f,%f,%f,%f,%f,%f,%f,%f", &pid, &theta, &phi, &omega, &ox, &oy, &mag, &fom1, &fom2, &fom3) > 6 ) {
385 part = particle_add(&part, pid);
386 if ( !mg->part ) mg->part = part;
387 part->ori[0] = ox;
388 part->ori[1] = oy;
389 part->mag = mag;
390 part->fom[0] = fom1;
391 part->fom[1] = fom2;
392 part->fom[2] = fom3;
393 part->view = Euler(-omega*M_PI/180.0,
394 theta*M_PI/180.0, phi*M_PI/180.0).view();
395 numpart++;
396 }
397 }
398
399 fdat.close(); // close input DAT file
400
401 if ( n && numpart != n )
402 cerr << "Warning: The number of particles (" << numpart <<
403 ") does not agree with the number in the header (" << n << ")" << endl;
404
405 if ( verbose )
406 cout << "Number of particles read: " << numpart << endl << endl;
407
408 return err;
409 }
410
419 int write_project_dat(Bstring& filename, Bproject* project, int mg_select, int rec_select)
420 {
421 int err(0);
422 int i, f, numpart(0);
423 double def_min, def_max, omega;
424 Euler euler;
425 Bfield* field = NULL;
426 Bmicrograph* mg = NULL;
427 Bparticle* part = NULL;
428 CTFparam* ctf;
429 ofstream fdat;
430 Bstring outname = filename;
431
432 if ( verbose ) cout << "Writing a DAT file: " << filename << endl;
433
434 if ( project_count_micrographs(project) < 2 ) mg_select = 1;
435
436 for ( i=1, field = project->field; field; field = field->next ) {
437 for ( mg = field->mg; mg; mg = mg->next, i++ ) if ( mg_select < 1 || mg_select == i ) {
438 if ( mg_select < 1 ) outname = filename.pre_rev('.') + Bstring(i, "_%06d.") + filename.post_rev('.');
439 for ( part = mg->part; part; part = part->next ) numpart++;
440 ctf = mg->ctf;
441 if ( !ctf ) ctf = mg->ctf = new CTFparam;
442 def_min = ctf->defocus_average() - ctf->defocus_deviation();
443 def_max = ctf->defocus_average() + ctf->defocus_deviation();
444 fdat.open(outname.c_str());
445 if ( fdat.fail() ) { // make sure input file exists
446 cerr << "Unable to create file " << filename << "!. Exit program." << endl;
447 bexit(-1);
448 }
449 fdat << mg->fpart << " " << mg->box_size[0] << " " << mg->box_size[1] << " " << numpart << endl;
450 fdat << fixed << right << setprecision(4) << setw(9) << mg->pixel_size << ", "
451 << 1 << ", "
452 << setprecision(1) << setw(8) << ctf->volt() << ", "
453 << setprecision(4) << setw(10) << sin(ctf->amp_shift()) << ", "
454 << setprecision(4) << setw(9) << def_max/1e4 << ", "
455 << setprecision(4) << setw(9) << def_min/1e4 << ", "
456 << setprecision(3) << setw(9) << ctf->astigmatism_angle()*180.0/M_PI << ", "
457 << setprecision(2) << setw(7) << ctf->Cs()/1e7 << endl;
458 for ( part = mg->part; part; part = part->next ) {
459 euler = Euler(part->view);
460 omega = -euler.psi()*180.0/M_PI;
461 if ( omega < 0 ) omega += 360;
462 fdat << setw(7) << part->id << ", "
463 << setprecision(3) << setw(7) << euler.theta()*180.0/M_PI << ", "
464 << setprecision(3) << setw(7) << euler.phi()*180.0/M_PI << ", "
465 << setprecision(3) << setw(7) << omega << ", "
466 << setprecision(3) << setw(7) << part->ori[0] << ", "
467 << setprecision(3) << setw(7) << part->ori[1] << ", "
468 << setprecision(3) << setw(5) << part->mag;
469 for ( f=0; f<3; f++ ) fdat << ", " << setprecision(3) << setw(5) << part->fom[f];
470 fdat << endl;
471 }
472 fdat.close();
473 }
474 }
475
476 if ( verbose )
477 cout << "Number of particles written: " << numpart << endl << endl;
478
479 return err;
480 }
481
488 int read_project_crd(Bstring& filename, Bproject* project)
489 {
490 int err(0);
491 char line[DATLINELENGTH];
492 char* value;
493 double d;
494
495 Bstring field_id = filename.base();
496 Bstring mg_id = field_id;
497 Bfield* field = field_add(&project->field, field_id);
498 Bmicrograph* mg = micrograph_add(&field->mg, mg_id);
499 Bparticle* part = NULL;
500 Bbadarea* bad = NULL;
501 Bstring part_prefix;
502 Bstring part_ext;
503
504 if ( verbose ) cout << "Reading a CRD file: " << filename << endl;
505
506 /*========================
507 Read CRD-format file
508 ========================*/
509 ifstream fcrd(filename.c_str());
510 if ( fcrd.fail() ) {
511 cerr << "File " << filename << " does not exist!. Exit program." << endl;
512 bexit(-1);
513 }
514
515 fcrd.getline(line, DATLINELENGTH);
516
517 // General micrograph parameters
518 while ( fcrd.getline(line, DATLINELENGTH) && !strstr(line, "$END") ) {
519 value = strchr(line, '=') + 1;
520 while ( isspace(value[0]) ) value++;
521 if ( strstr(line, "PIC_FILENAME") ) {
522 mg->fmg = value;
523 mg->fmg = mg->fmg.remove('\n');
524 mg->fmg = mg->fmg.remove(',');
525 mg->fmg = mg->fmg.remove('\'');
526 } else if ( strstr(line, "OUTFILE_PREFIX") ) {
527 part_prefix = value;
528 part_prefix = part_prefix.remove('\n');
529 part_prefix = part_prefix.remove(',');
530 part_prefix = part_prefix.remove('\'');
531 } else if ( strstr(line, "OUTFILE_TYPE") ) {
532 part_ext = value;
533 part_ext = part_ext.remove('\n');
534 part_ext = part_ext.remove(',');
535 part_ext = part_ext.remove('\'');
536 } else if ( strstr(line, "ANGSTROMS") ) {
537 sscanf(value, "%lf", &d);
538 if ( d > 0 ) mg->pixel_size = d;
539 } else if ( strstr(line, "RADIUS_PICK") ) {
540 sscanf(value, "%lf", &d);
541 mg->box_size[0] = mg->box_size[1] = 2*d;
542 mg->box_size[2] = 1;
543 } else if ( strstr(line, "RADIUS_BAD") ) {
544 sscanf(value, "%lf", &mg->bad_radius);
545 }
546 }
547
548 if ( part_prefix.length() )
549 mg->fpart = part_prefix + "." + part_ext;
550
551 int numpart(0), numbad(0), pid;
552 float x, y;
553
554 while ( fcrd.getline(line, DATLINELENGTH) ) {
555 if ( sscanf(line, "%d %f %f", &pid, &x, &y) > 2 ) {
556 if ( pid > 0 ) {
557 part = particle_add(&part, pid);
558 if ( !mg->part ) mg->part = part;
559 part->loc[0] = x;
560 part->loc[1] = y;
561 numpart++;
562 } else {
563 bad = (Bbadarea *) add_item((char **) &bad, sizeof(Bbadarea));
564 if ( !mg->bad ) mg->bad = bad;
565 bad->loc[0] = x;
566 bad->loc[1] = y;
567 numbad++;
568 }
569 }
570 }
571
572 fcrd.close(); // close input CRD file
573
574 if ( verbose )
575 cout << "Number of particles written: " << numpart << " (" << numbad << ")" << endl << endl;
576
577 return err;
578 }
579
588 int write_project_crd(Bstring& filename, Bproject* project, int mg_select, int rec_select)
589 {
590 int err(0);
591 int i, numpart(0), numbad(0);
592 Bfield* field = NULL;
593 Bmicrograph* mg = NULL;
594 Bparticle* part = NULL;
595 Bbadarea* bad = NULL;
596 ofstream fcrd;
597 Bstring outname = filename;
598 Bstring prefix, type;
599
600 if ( verbose ) cout << "Writing a CRD file: " << filename << endl;
601
602 if ( project_count_micrographs(project) < 2 ) mg_select = 1;
603
604 for ( i=1, field = project->field; field; field = field->next ) {
605 for ( mg = field->mg; mg; mg = mg->next, i++ ) if ( mg_select < 1 || mg_select == i ) {
606 if ( mg_select < 1 ) outname = filename.pre_rev('.') + Bstring(i, "_%06d.") + filename.post_rev('.');
607 if ( mg->fpart.length() ) {
608 prefix = mg->fpart.pre_rev('.');
609 type = mg->fpart.post_rev('.');
610 }
611 fcrd.open(outname.c_str());
612 if ( fcrd.fail() ) { // make sure input file exists
613 cerr << "Unable to create file " << filename << "!. Exit program." << endl;
614 bexit(-1);
615 }
616 fcrd << " $TRIMNEWPARAMETERS" << endl;
617 fcrd << " CRD_VERSION = 3," << endl;
618 fcrd << " PIC_FILENAME = '" << mg->fmg << "'," << endl;
619 fcrd << " PIC_FLIPFLAG = F," << endl;
620 fcrd << " FLIPALLROWSFLAG = F," << endl;
621 fcrd << " FLIPALLCOLSFLAG = F," << endl;
622 fcrd << " INVERT_INTENSTY = F," << endl;
623 fcrd << " ANGSTROMS = " << mg->pixel_size << "," << endl;
624 fcrd << " CONTRAST = 1.380000" << endl;
625 fcrd << " BRIGHTNESS = 0.120000" << endl;
626 fcrd << " OUTFILE_PREFIX = '" << prefix << "'," << endl;
627 fcrd << " OUTFILE_START = 1," << endl;
628 fcrd << " OUTFILE_WIDTH = 3," << endl;
629 fcrd << " OUTFILE_TYPE = '" << type << "'," << endl;
630 fcrd << " OD_CONVERT = F," << endl;
631 fcrd << " RADIUS = 50," << endl;
632 fcrd << " RADIUS_BAD = " << mg->bad_radius << "," << endl;
633 fcrd << " RADIUS_PICK = " << mg->box_size[0]/2.0 << "," << endl;
634 fcrd << " FADE = 9," << endl;
635 fcrd << " EXTRACT_DX = 501," << endl;
636 fcrd << " EXTRACT_DY = 501," << endl;
637 fcrd << " FINAL_DX = 401," << endl;
638 fcrd << " FINAL_DY = 401," << endl;
639 fcrd << " FINAL_MEAN = 127," << endl;
640 fcrd << " FINAL_STDDEV = 40," << endl;
641 fcrd << " SKIPMASKFLAG = F," << endl;
642 fcrd << " SKIPGRADIENTFLAG= T" << endl;
643 fcrd << " SELECTEXTENDED = T" << endl;
644 fcrd << " SELECTEXTLENMODE= FIXED" << endl;
645 fcrd << " SELECTEXTFLENGTH= 40" << endl;
646 fcrd << " $END" << endl;
647 for ( part = mg->part; part; part = part->next, numpart++ )
648 fcrd << right << setw(6) << part->id << setw(8) << part->loc[0] << setw(8) << part->loc[1] << endl;
649 for ( bad = mg->bad; bad; bad = bad->next, numbad++ )
650 fcrd << right << setw(6) << -numbad-1 << setw(8) << bad->loc[0] << setw(8) << bad->loc[1] << endl;
651 fcrd.close();
652 }
653 }
654
655 if ( verbose )
656 cout << "Number of particles written: " << numpart << " (" << numbad << ")" << endl << endl;
657
658 return err;
659 }
660
661
662
669 int project_modify_parameters(Bproject* project, char flags)
670 {
671 Bfield* field = NULL;
672 Bmicrograph* mg = NULL;
673 Bparticle* part = NULL;
674
675 for ( field = project->field; field; field = field->next ) {
676 for ( mg = field->mg; mg; mg = mg->next ) {
677 for ( part = mg->part; part; part = part->next ) {
678 if ( flags & 1 ) part->mag = 1.0/part->mag;
679 if ( flags & 2 ) part->view[3] -= M_PI_2;
680 }
681 }
682 }
683
684 return 0;
685 }
686
Bparticle::id
int id
Definition: mg_processing.h:92
FileType
FileType
File type enumeration.
Definition: file_util.h:20
rwmg.h
Header file for reading and writing micrograph parameters.
M_PI_2
#define M_PI_2
Definition: utilities.h:62
CTFparam::Cs
double Cs()
Definition: ctf.h:87
Bstring::real
double real()
Definition: Bstring.cpp:545
read_project_star
int read_project_star(Bstring &filename, Bproject *project)
Reading micrograph parameters from STAR files.
Definition: rwmgSTAR.cpp:29
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
Bparticle::mag
double mag
Definition: mg_processing.h:94
Euler
Definition: Euler.h:28
read_project_relion
int read_project_relion(Bstring &filename, Bproject *project)
Reading micrograph parameters from a Relion file.
Definition: rwmgRELION.cpp:249
Bparticle::view
View view
Definition: mg_processing.h:101
Bproject::filename
Bstring filename
Definition: mg_processing.h:335
write_project_conv
int write_project_conv(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Definition: bmgconvert.cpp:243
Bbadarea
Definition: mg_processing.h:142
utilities.h
Header file for general utilities.
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:104
Boption::value
Bstring value
Definition: options.h:30
Breconstruction
Definition: mg_processing.h:280
Bproject::split
int split
Definition: mg_processing.h:337
Boption::tag
Bstring tag
Definition: options.h:29
Bbadarea::loc
Vector3< double > loc
Definition: mg_processing.h:145
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
project_update_first_zero
int project_update_first_zero(Bproject *project)
Updates the first zero from the defocus average for all the micrographs.
Definition: mg_ctf.cpp:1776
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
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
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:465
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_processing.cpp:746
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
main
int main(int argc, char **argv)
Definition: bmgconvert.cpp:73
Boption::filename
Bstring filename()
Definition: options.h:85
Bfield::next
Bfield * next
Definition: mg_processing.h:258
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.
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
verbose
int verbose
Micrograph
Definition: file_util.h:23
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
linked_list.h
Header file for generalized linked list functions.
read_project_dat
int read_project_dat(Bstring &filename, Bproject *project)
Reading micrograph parameters from a DAT file.
Definition: bmgconvert.cpp:296
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:238
rwmgXML.h
Reads and writes micrograph XML files.
Euler::psi
double psi()
Definition: Euler.h:56
Euler::phi
double phi()
Definition: Euler.h:58
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:143
Bstring::next
Bstring * next
Definition: Bstring.h:31
Boption
A class for a command line input option.
Definition: options.h:26
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:381
Bproject::field
Bfield * field
Definition: mg_processing.h:343
rwmgSTAR.h
Header file for reading and writing micrograph parameters from and to the STAR format.
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:515
project_modify_parameters
int project_modify_parameters(Bproject *project, char flags)
Modifies some micrograph parameters.
Definition: bmgconvert.cpp:669
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:102
write_project_crd
int write_project_crd(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a CRD file.
Definition: bmgconvert.cpp:588
Bmicrograph
Definition: mg_processing.h:200
read_project_xml
int read_project_xml(Bstring &filename, Bproject *project)
Reading micrograph parameters from XML files.
Definition: rwmgXML.cpp:144
file_util.h
Header file for file checking functions.
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
MgRelion
Definition: file_util.h:26
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bstring::no_lead_space
Bstring no_lead_space()
Definition: Bstring.cpp:341
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
write_project_star
int write_project_star(const char *filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a STAR file.
Definition: rwmgSTAR.cpp:56
read_project_crd
int read_project_crd(Bstring &filename, Bproject *project)
Reading micrograph parameters from a CRD file.
Definition: bmgconvert.cpp:488
Euler::theta
double theta()
Definition: Euler.h:57
Boption::next
Boption * next
Definition: options.h:28
Bparticle
Definition: mg_processing.h:89
write_project_dat
int write_project_dat(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a DAT file.
Definition: bmgconvert.cpp:419
Bstring
Definition: Bstring.h:29
write_project_xml
int write_project_xml(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a XML file.
Definition: rwmgXML.cpp:258
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
read_project_conv
Bproject * read_project_conv(Bstring *file_list)
Definition: bmgconvert.cpp:163
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
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
use
const char * use[]
Definition: bmgconvert.cpp:40
DATLINELENGTH
#define DATLINELENGTH
Definition: bmgconvert.cpp:25
Vector3< int >
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:205
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:241
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
Euler::view
View view()
Definition: Euler.h:62
Bstring::integer
long integer()
Definition: Bstring.cpp:539
mg_processing.h
Header file for micrograph processing.
options.h
Header file for option handlers.
rwmgRELION.h
Header file for reading and writing micrograph parameters from and to the RELION STAR format.
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:95
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:233
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
Bstring::empty
bool empty()
Definition: Bstring.h:71
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
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
Bproject::euler_flag
int euler_flag
Definition: mg_processing.h:340
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:106
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:461
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
Bproject
Definition: mg_processing.h:333
project_split_particles
int project_split_particles(Bproject *project, Bstring partfile, Bstring path, Bstring partext)
Modifies some micrograph parameters.
Definition: rwmgRELION.cpp:303
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
CTFparam
Definition: ctf.h:26
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201