Bsoft  2.1.0
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
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);
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,1.5,1 Sampling (A/pixel, one value sets all).",
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  Vector3<double> sam; // 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  sam = curropt->scale();
92 // if ( ( sampling = curropt->value.real() ) < 0.1 )
93 // cerr << "-sampling: A pixel size must be specified" << endl;
94  if ( curropt->tag == "mgselect" )
95  if ( ( mg_select = curropt->value.integer() ) < 0 )
96  cerr << "-mgselect: A number must be specified" << endl;
97  if ( curropt->tag == "recselect" )
98  if ( ( rec_select = curropt->value.integer() ) < 0 )
99  cerr << "-recselect: A number must be specified" << endl;
100  if ( curropt->tag == "euler" )
101  euler = 1;
102  if ( curropt->tag == "magnification" )
103  flags += 1;
104  if ( curropt->tag == "omega" )
105  flags += 2;
106  if ( curropt->tag == "path" )
107  path = curropt->value;
108  if ( curropt->tag == "extension" ) {
109  partext = curropt->value;
110  if ( partext.length() < 1 )
111  cerr << "-extension: The particle file extension must be specified!" << endl;
112  }
113  if ( curropt->tag == "particles" )
114  partfile = curropt->filename();
115  if ( curropt->tag == "output" )
116  outfile = curropt->filename();
117  }
118  option_kill(option);
119 
120  double ti = timer_start();
121 
122  // Read all the parameter files
123  Bstring* file_list = NULL;
124  while ( optind < argc ) string_add(&file_list, argv[optind++]);
125  if ( !file_list ) {
126  cerr << "Error: No parameter files specified!" << endl;
127  bexit(-1);
128  }
129 
130  Bproject* project = read_project_conv(file_list);
131 
132  string_kill(file_list);
133 
134  if ( project == NULL ) {
135  cerr << "Error: No project generated!" << endl;
136  bexit(-1);
137  }
138 
139  if ( sam[0] > 0.1 )
141 
142  if ( flags )
144 
145  if ( euler ) project->euler_flag = 1;
146 
147  if ( partfile.length() || partext.length() )
148  project_split_particles(project, partfile, path, partext);
149 
150  // Write an output parameter file if a name is given
151  if ( outfile.length() ) {
152  write_project_conv(outfile, project, mg_select, rec_select);
153  }
154 
156 
157  if ( verbose & VERB_TIME )
158  timer_report(ti);
159 
160  bexit(0);
161 }
162 
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;
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__);
230  return NULL;
231  }
232 
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 
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 
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 = Vector3<double>(px, px, 1);
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[0] << ", "
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 
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[0] = mg->pixel_size[1] = 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[0] << "," << 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 
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 
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
Bbadarea::loc
Vector3< double > loc
Definition: mg_processing.h:146
Bmicrograph
Definition: mg_processing.h:201
rwmgXML.h
Reads and writes micrograph XML files.
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:473
Boption::scale
Vector3< double > scale()
Definition: options.h:190
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
Bparticle::view
View view
Definition: mg_processing.h:102
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
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
add_item
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Definition: linked_list.cpp:26
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
write_project_conv
int write_project_conv(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Definition: bmgconvert.cpp:243
Bproject::split
int split
Definition: mg_processing.h:340
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
Bstring::integer
long integer()
Definition: Bstring.cpp:547
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:1932
Euler::theta
double theta()
Definition: Euler.h:57
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:236
Boption::next
Boption * next
Definition: options.h:28
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:110
Bstring::no_lead_space
Bstring no_lead_space()
Definition: Bstring.cpp:349
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
Euler::psi
double psi()
Definition: Euler.h:56
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
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bproject::filename
Bstring filename
Definition: mg_processing.h:338
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:30
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bstring::empty
bool empty()
Definition: Bstring.h:71
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::part
Bparticle * part
Definition: mg_processing.h:242
read_project_xml
int read_project_xml(Bstring &filename, Bproject *project)
Reading micrograph parameters from XML files.
Definition: rwmgXML.cpp:144
options.h
Header file for option handlers.
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bfield
Definition: mg_processing.h:260
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
M_PI_2
#define M_PI_2
Definition: utilities.h:66
verbose
int verbose
project_split_particles
int project_split_particles(Bproject *project, Bstring partfile, Bstring path, Bstring partext)
Modifies some micrograph parameters.
Definition: rwmgRELION.cpp:303
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
read_project_relion
int read_project_relion(Bstring &filename, Bproject *project)
Reading micrograph parameters from a Relion file.
Definition: rwmgRELION.cpp:249
Bbadarea
Definition: mg_processing.h:143
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
read_project_dat
int read_project_dat(Bstring &filename, Bproject *project)
Reading micrograph parameters from a DAT file.
Definition: bmgconvert.cpp:296
rwmg.h
Header file for reading and writing micrograph parameters.
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
main
int main(int argc, char **argv)
Definition: bmgconvert.cpp:73
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:389
Micrograph
@ Micrograph
Definition: file_util.h:23
Boption::value
Bstring value
Definition: options.h:30
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
FileType
FileType
File type enumeration.
Definition: file_util.h:20
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:144
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
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
use
const char * use[]
Definition: bmgconvert.cpp:40
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Euler::phi
double phi()
Definition: Euler.h:58
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
Euler::view
View view()
Definition: Euler.h:62
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
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
CTFparam
Definition: ctf.h:28
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:221
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
Bproject::euler_flag
int euler_flag
Definition: mg_processing.h:343
Bfield::next
Bfield * next
Definition: mg_processing.h:261
rwmgSTAR.h
Header file for reading and writing micrograph parameters from and to the STAR format.
MgRelion
@ MgRelion
Definition: file_util.h:26
Bstring::next
Bstring * next
Definition: Bstring.h:31
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_processing.h
Header file for micrograph processing.
rwmgRELION.h
Header file for reading and writing micrograph parameters from and to the RELION STAR format.
CTFparam::defocus_average
double defocus_average()
Definition: ctf.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:154
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
linked_list.h
Header file for generalized linked list functions.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
Bstring::base
Bstring base()
Definition: Bstring.cpp:516
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:99
DATLINELENGTH
#define DATLINELENGTH
Definition: bmgconvert.cpp:25
project_modify_parameters
int project_modify_parameters(Bproject *project, char flags)
Modifies some micrograph parameters.
Definition: bmgconvert.cpp:669
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
read_project_conv
Bproject * read_project_conv(Bstring *file_list)
Definition: bmgconvert.cpp:163
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:244
Bparticle::mag
double mag
Definition: mg_processing.h:95
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
read_project_crd
int read_project_crd(Bstring &filename, Bproject *project)
Reading micrograph parameters from a CRD file.
Definition: bmgconvert.cpp:488
read_project_star
int read_project_star(Bstring &filename, Bproject *project)
Reading micrograph parameters from STAR files.
Definition: rwmgSTAR.cpp:29
Euler
Definition: Euler.h:28
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
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
Bparticle::id
int id
Definition: mg_processing.h:93
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_select.cpp:350
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
CTFparam::Cs
double Cs()
Definition: ctf.h:91
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284