Bsoft  2.1.0
Bernard's software package
rwmg.cpp
Go to the documentation of this file.
1 
9 #include "rwmg.h"
10 #include "mg_processing.h"
11 #include "mg_img_proc.h"
12 #include "mg_ctf.h"
13 #include "mg_tags.h"
14 #include "rwmgSTAR.h"
15 #include "rwmgXML.h"
16 #include "rwmgEMX.h"
17 #include "rwmgIMOD.h"
18 #include "rwmgSerialEM.h"
19 #include "file_util.h"
20 #include "utilities.h"
21 
22 // Declaration of global variables
23 extern int verbose; // Level of output to the screen
24 extern string command; // Command line
25 
26 // Internal prototype
27 int project_check(Bproject* project, int flags=0);
28 
30 {
31  long nfield = project_count_fields(project);
34  long npart = project_count_mg_particles(project);
38 
39  cout << endl;
40  cout << "Fields: " << nfield << endl;
41  cout << "Micrographs: " << nmg << " ( " << nmgs << " selected)" << endl;
42  cout << "Particles: " << npart << " ( " << nsel << " selected)" << endl;
43  cout << "Filaments and nodes: " << nfil << " " << nfn << endl;
44  cout << endl;
45 
47  long nrecs = project_count_rec_selected(project);
52 
53  cout << "Reconstructions: " << nrec << " ( " << nrecs << " selected)" << endl;
54  cout << "Particles: " << npart << " ( " << nsel << " selected)" << endl;
55  cout << "Filaments and nodes: " << nfil << " " << nfn << endl;
56  cout << endl;
57 
58  return 0;
59 }
60 
61 /* The filename is for the current input parameter file */
62 int field_resolve_file_access(Bfield* field, Bmicrograph* mg, Bstring filename, int flags)
63 {
64  if ( filename.length() < 1 ) return 0;
65 
66  Bstring path;
67  Bparticle* part;
68 
69  if ( filename.contains("/") ) path = filename.pre_rev('/');
70 
71  if ( verbose & VERB_DEBUG )
72  cout << "DEBUG field_resolve_file_access: file=" << filename << " path=" << path << endl;
73 
74  for ( ; field; field = field->next ) {
75  if ( !mg ) mg = field->mg;
76  for ( ; mg; mg = mg->next ) {
77  mg->fmg = find_file(mg->fmg, path, flags);
78  mg->fframe = find_file(mg->fframe, path, flags);
79  mg->fpart = find_file(mg->fpart, path, flags);
80  mg->ffil = find_file(mg->ffil, path, flags);
81  mg->fft = find_file(mg->fft, path, flags);
82  mg->fps = find_file(mg->fps, path, flags);
83  if ( mg->part && mg->part->fpart.length() )
84  for ( part = mg->part; part; part = part->next )
85  part->fpart = find_file(part->fpart, path, flags);
86  }
87  }
88 
89  return 0;
90 }
91 
92 /* The filename is for the current input parameter file */
94 {
95  if ( filename.length() < 1 ) return 0;
96 
97  Bstring path;
98  Bparticle* part;
99 
100  if ( filename.contains("/") ) path = filename.pre_rev('/');
101 
102  if ( verbose & VERB_DEBUG )
103  cout << "DEBUG reconstruction_resolve_file_access: file=" << filename << " path=" << path << endl;
104 
105  for ( ; rec; rec = rec->next ) {
106  rec->frec = find_file(rec->frec, path, flags);
107  rec->fft = find_file(rec->fft, path, flags);
108  rec->fps = find_file(rec->fps, path, flags);
109  rec->fpart = find_file(rec->fpart, path, flags);
110  rec->ffil = find_file(rec->ffil, path, flags);
111  for ( part = rec->part; part; part = part->next )
112  part->fpart = find_file(part->fpart, path, flags);
113  }
114 
115  return 0;
116 }
117 
119 {
120  if ( filename.length() < 1 ) return 0;
121 
122  field_resolve_file_access(project->field, NULL, filename, flags);
123 
125 
126  return 0;
127 }
128 
141 Bproject* read_project(const char* filename, int flags)
142 {
143  Bstring thefile(filename);
144  return read_project(thefile, flags);
145 }
146 
147 Bproject* read_project(Bstring& filename, int flags)
148 {
149  Bstring xsdfile;
150  return read_project(filename, xsdfile, flags);
151 }
152 
153 Bproject* read_project(Bstring& filename, Bstring& xsdfile, int flags)
154 {
155  if ( filename.empty() ) {
156  error_show("No micrograph parameter filename!", __FILE__, __LINE__);
157  return NULL;
158  }
159 
160  Bstring ext = filename.extension();
161 
162  if ( verbose & VERB_LABEL )
163  cout << "Parameter filename: " << filename << endl;
164 
165  int err;
167  project->filename = filename;
168 
169  if ( ext.contains("star") ) {
170  err = read_project_star(filename, project);
171  } else if ( ext.contains("xml") ) {
172  err = read_project_xml(filename, project);
173  } else if ( ext.contains("emx") ) {
174  err = read_project_emx(filename, project, xsdfile);
175  } else if ( ext.contains("imod") ) {
176  err = read_project_imod(&filename, project, 0);
177  } else if ( ext.contains("mdoc") ) {
178  err = read_project_serialem(filename, project, 0);
179  } else {
180  cerr << "Error: Extension \"" << ext << "\" not valid for parameter files!" << endl;
181  cerr << " Parameter file \"" << filename << "\" not read." << endl;
182  err = -1;
183  }
184 
185  if ( err < 0 ) {
186  error_show(filename.c_str(), __FILE__, __LINE__);
188  return NULL;
189  }
190 
191  field_resolve_file_access(project->field, NULL, filename, flags & 8);
192 
193  reconstruction_resolve_file_access(project->rec, filename, flags & 8);
194 
195  project_check(project, flags);
196 
197  if ( verbose & VERB_PROCESS )
199 
200  return project;
201 }
202 
203 Bproject* read_project(Bstring* file_list, int flags)
204 {
205  Bstring xsdfile;
206  return read_project(file_list, xsdfile, flags);
207 }
208 
209 Bproject* read_project(Bstring* file_list, Bstring& xsdfile, int flags)
210 {
211  if ( !file_list ) {
212  error_show("No micrograph parameter filename!", __FILE__, __LINE__);
213  return NULL;
214  }
215 
216  Bstring ext = file_list->extension();
217  Bstring* thisfile;
218 
219  if ( verbose & VERB_LABEL ) {
220  cout << "Reading parameter files:";
221  for ( thisfile = file_list; thisfile; thisfile = thisfile->next )
222  cout << " " << *thisfile;
223  cout << endl;
224  }
225 
226  int err;
228  Bfield* field = NULL;
229  Bmicrograph* mg = NULL;
230  Breconstruction* rec = NULL;
231  project->filename = *file_list;
232 
233  if ( ext.contains("imod") ) {
234  err = read_project_imod(file_list, project, 0);
235  } else if ( ext.contains("mdoc") ) {
236  err = read_project_serialem(*file_list, project, 0);
237  } else for ( thisfile = file_list; thisfile; thisfile = thisfile->next ) {
238  for ( field = project->field; field && field->next; field = field->next ) ;
239  if ( field ) for ( mg = field->mg; mg && mg->next; mg = mg->next ) ;
240  for ( rec = project->rec; rec && rec->next; rec = rec->next ) ;
241  ext = thisfile->extension();
242  if ( ext.contains("star") ) {
243  err = read_project_star(*thisfile, project);
244  } else if ( ext.contains("xml") ) {
245  err = read_project_xml(*thisfile, project);
246  } else if ( ext.contains("emx") ) {
247  err = read_project_emx(*thisfile, project, xsdfile);
248  } else {
249  cerr << "Error: Extension \"" << ext << "\" not valid for parameter files!" << endl;
250  cerr << " Parameter file \"" << *thisfile << "\" not read." << endl;
251  err = -1;
252  }
253  if ( !err ) {
254  if ( !field ) field = project->field;
255 // else field = field->next;
256 // cout << "field " << field->id << endl;
257  if ( field ) {
258  if ( !mg ) mg = field->mg;
259 // else mg = mg->next;
260 // cout << "mg " << mg->id << endl;
261  if ( mg ) field_resolve_file_access(field, mg, *thisfile, flags & 8);
262  }
263  if ( !rec ) rec = project->rec;
264 // else rec = rec->next;
265  if ( rec ) reconstruction_resolve_file_access(rec, *thisfile, flags & 8);
266  }
267  }
268 
269  if ( err < 0 ) {
270  error_show(file_list->c_str(), __FILE__, __LINE__);
272  return NULL;
273  }
274 
275  project_check(project, flags);
276 
277  if ( verbose & VERB_PROCESS )
279 
280  return project;
281 }
282 
283 long append_project(Bproject* project, Bstring* file_list, Bstring& xsdfile, int flags)
284 {
285  long nmg(0);
286 
287  Bproject* project_append = read_project(file_list, xsdfile, flags);
288 
289  Bfield* field;
290  Bmicrograph* mg;
291 
292  for ( field = project->field; field; field = field->next ) {
293  for ( mg = field->mg; mg; mg = mg->next, nmg++ ) ;
294  if ( project_append && !field->next ) {
295  field->next = project_append->field;
296  project_append->field = NULL;
297  project_kill(project_append);
298  project_append = NULL;
299  }
300  }
301 
302  return nmg;
303 }
304 
305 Bparticle* read_particle(Bstring& filename, Bparticle** partlist, FOMType fom_tag[NFOM])
306 {
307 #if defined(HAVE_XML)
308  return read_particle_xml(filename, partlist, fom_tag);
309 #else
310  return NULL;
311 #endif
312 }
313 
314 
321 int write_project(const char* filename, Bproject* project)
322 {
323  Bstring thefile(filename);
324  return write_project(thefile, project, 0);
325 }
326 
337  int mg_select, int rec_select)
338 {
339  int flags(0);
340  if ( mg_select ) flags |= 2;
341  if ( rec_select ) flags |= 4;
342  return write_project(filename, project, flags);
343 }
344 
359 int write_project(Bstring& filename, Bproject* project, int flags)
360 {
361  int err(0);
362  int mg_select(flags & 2), rec_select(flags & 4);
363 
364  project_resolve_file_access(project, filename, flags);
365 
366  project_check(project, flags & 1);
367 
369 
370  if ( verbose & VERB_PROCESS )
372 
373  if ( project->split == 9 )
374  return write_project_star(filename, project, mg_select, rec_select);
375 
376  if ( filename.empty() )
377  return error_show("No micrograph parameter filename!", __FILE__, __LINE__);
378 
379  Bstring ext = filename.extension();
380 
381  if ( verbose )
382  cout << "Writing parameter file: " << filename << endl;
383 
384  if ( ext.contains("star") ) {
385  err = write_project_star(filename, project, mg_select, rec_select);
386  } else if ( ext.contains("xml") ) {
387  err = write_project_xml(filename, project, mg_select, rec_select);
388  } else if ( ext.contains("emx") ) {
389  err = write_project_emx(filename, project, mg_select, rec_select);
390  } else if ( ext.contains("imod") ) {
391  err = write_project_imod(filename, project);
392  } else {
393  cerr << "Error: Extension \"" << ext << "\" not valid for parameter files!" << endl;
394  cerr << " Parameter file \"" << filename << "\" not written." << endl;
395  err = -1;
396  }
397 
398  if ( err < 0 )
399  error_show(filename.c_str(), __FILE__, __LINE__);
400  else
401  project->filename = filename;
402 
403  return err;
404 }
405 
406 int write_particle(Bstring& filename, Bparticle* part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
407 {
408 #if defined(HAVE_XML)
409  return write_particle_xml(filename, part, euler_flag, omega_flag, fom_tag);
410 #else
411  return 0;
412 #endif
413 }
414 
415 Bstring ppx_filename(Bstring& id, int part_id)
416 {
417  Bstring filename = "ppx/" + id + "_" + Bstring(part_id, "%04d") + ".ppx";
418  return filename;
419 }
420 
421 int ppx_exists(Bparticle* part, int flag)
422 {
423  int exist(0);
424  Bstring filename;
425 
426  if ( part->mg )
427  filename = ppx_filename(part->mg->id, part->id);
428  else if ( part->rec )
429  filename = ppx_filename(part->rec->id, part->id);
430 
431  if ( access(filename.c_str(), R_OK) == 0 )
432  exist = 1;
433 
434  // flag=1 for absent, flag=2 for present
435  if ( flag == exist + 1 )
436  cout << part->sel << tab << filename << endl;
437 
438  return exist;
439 }
440 
441 int ppx_check(Bparticle* part, FOMType fom_tag[NFOM])
442 {
443  Bstring filename;
444 
445  if ( part->mg )
446  filename = ppx_filename(part->mg->id, part->id);
447  else if ( part->rec )
448  filename = ppx_filename(part->rec->id, part->id);
449 
450  if ( access(filename.c_str(), R_OK) )
451  return 0;
452 
453  Bparticle* part_list = NULL;
454 
455  Bparticle* part_nu = read_particle(filename, &part_list, fom_tag);
456 
457  if ( part_nu ) {
458  particle_update(part, part_nu);
459  particle_kill(part_nu);
460  return 1;
461  }
462 
463  return 0;
464 }
465 
467 {
468  FOMType fom_tag[NFOM] = {FOM, FOM_CV};
469 
470  return ppx_check(part, fom_tag);
471 }
472 
474 {
475  long i, j;
476 // Vector3<double> d, ori;
477  double d;
478  Bfield* field;
479  Bmicrograph* mg;
480  Breconstruction* rec;
481  Bparticle* part;
482  Bbadarea* bad;
483  Bstring part_file;
484 
485  if ( verbose & VERB_DEBUG )
486  cout << "DEBUG project_check: " << endl;
487 
488  if ( project->field == NULL && project->rec ) project->select = 1;
489 
490  for ( field=project->field; field; field=field->next ) {
491  i = 1;
492  for ( mg=field->mg; mg; mg=mg->next ) {
493  if ( verbose & VERB_DEBUG )
494  cout << "DEBUG project_check: mg=" << mg->id << endl;
495  if ( mg->next ) {
496  if ( mg->id == mg->next->id ) {
497  mg->id = mg->id + Bstring(i++, "_%03d");
498  if ( verbose )
499  cout << "Resetting micrograph ID: " << mg->id << endl;
500  if ( !mg->next->next ) {
501  mg->next->id = mg->next->id + Bstring(i, "_%03d");
502  if ( verbose )
503  cout << "Resetting micrograph ID: " << mg->next->id << endl;
504  }
505  }
506  }
507  if ( mg->sampling < 1e3 ) mg->sampling *= 1e4;
508  if ( mg->magnification < 1e3 ) mg->magnification *= 1e3;
509  mg->pixel_size[2] = 1;
510  if ( mg->pixel_size[0] < 0.01 || mg->pixel_size[1] < 0.01 ) {
511  mg->pixel_size = Vector3<double>(1,1,1);
512  if ( mg->magnification && mg->sampling ) {
513  mg->pixel_size[0] = mg->sampling/mg->magnification;
514  if ( mg->pixel_size[0] < 0.01 ) mg->pixel_size[0] *= 1e4; // Assume um
515  mg->pixel_size[1] = mg->pixel_size[0];
516  }
517  cerr << "Warning: Resetting pixel size for micrograph " <<
518  mg->id << " to " << mg->pixel_size << endl;
519  }
520  if ( mg->intensity <= 0 ) micrograph_intensity(mg);
521  if ( mg->scale[0] <= 0 ) mg->scale[0] = 1;
522  if ( mg->scale[1] <= 0 ) mg->scale[1] = 1;
523  if ( mg->scale[2] <= 0 ) mg->scale[2] = 1;
524  if ( mg->ctf ) {
525  if ( mg->ctf->volt() < 1e3 ) mg->ctf->volt(1e3*mg->ctf->volt());
526  if ( mg->ctf->Cs() < 1e3 ) mg->ctf->Cs(1e7*mg->ctf->Cs());
527  if ( mg->ctf->defocus_average() < 10 ) mg->ctf->defocus_average(1e4*mg->ctf->defocus_average());
528  if ( mg->ctf->defocus_deviation() < 10 ) mg->ctf->defocus_deviation(1e4*mg->ctf->defocus_deviation());
529  mg->ctf->zero(1);
530  }
531  if ( mg->part ) part_file = mg->part->fpart;
532  for ( part = mg->part; part; part = part->next ) {
533  if ( part->id < 1 )
534  cerr << "Error: Particle has an ID less than 1! (" << mg->id << ")" << endl;
535  part->mg = mg;
536  if ( part_file.length() && part_file != part->fpart ) part_file = 0;
537  if ( part->pixel_size[0] < 0.01 ) part->pixel_size = mg->pixel_size;
538  part->pixel_size[2] = 1;
539  d = (part->ori - mg->box_size/2).length();
540  if ( d > mg->box_size[0]/4 )
541  part->ori = mg->box_size/2;
542  part->ori[2] = 0;
543  }
544  if ( part_file.length() ) {
545  mg->fpart = part_file;
546  for ( part = mg->part; part; part = part->next ) part->fpart = 0;
547  part_file = 0;
548  }
549  for ( j=0, bad = mg->bad; bad; bad = bad->next ) bad->id = --j;
550  }
551  }
552 
553  if ( verbose & VERB_DEBUG )
554  cout << "DEBUG project_check: micrographs=" << project_count_micrographs(project) << endl;
555 
556  i = 1;
557  for ( rec=project->rec; rec; rec=rec->next ) {
558  if ( rec->next ) {
559  if ( rec->id == rec->next->id ) {
560  rec->id = rec->id + Bstring(i++, "_%03d");
561  if ( verbose )
562  cout << "Resetting reconstruction ID: " << rec->id << endl;
563  if ( !rec->next->next ) {
564  rec->next->id = rec->next->id + Bstring(i, "_%03d");
565  if ( verbose )
566  cout << "Resetting reconstruction ID: " << rec->next->id << endl;
567  }
568  }
569  }
570  if ( rec->voxel_size[0] < 0.01 )
571  rec->voxel_size = Vector3<double>(1,1,1);
572  if ( rec->scale[0] <= 0 ) rec->scale[0] = 1;
573  if ( rec->scale[1] <= 0 ) rec->scale[1] = 1;
574  if ( rec->scale[2] <= 0 ) rec->scale[2] = 1;
575  for ( part = rec->part; part; part = part->next ) {
576  if ( part->id < 1 )
577  cerr << "Error: Particle has an ID less than 1! (" << mg->id << ")" << endl;
578  part->rec = rec;
579  if ( part->pixel_size[0] < 0.01 )
580  part->pixel_size = rec->voxel_size;
581  d = (part->ori - rec->box_size/2).length();
582  if ( d > rec->box_size[0]/4 )
583  part->ori = rec->box_size/2;
584  }
585  for ( j=0, bad = rec->bad; bad; bad = bad->next ) bad->id = --j;
586  }
587 
588  if ( verbose & VERB_DEBUG )
589  cout << "DEBUG project_check: reconstructions=" << project_count_reconstructions(project) << endl;
590 
591  field = project->field;
592  if ( ( flags & 1 ) && field ) {
593  if ( project_check_particles(project) < 0 ) bexit(-1);
594  }
595 
597 
598  return 0;
599 }
600 
611 {
612  Bfield* field = NULL;
613  Bmicrograph* mg = NULL;
614  Breconstruction* rec = NULL;
615  Bparticle* part = NULL;
616 
617  Bstring path;
618  if ( project->filename.contains("/") )
619  path = project->filename.pre_rev('/');
620 
621  fn = find_file(fn, path);
622 // if ( verbose & VERB_FULL )
623  cout << "Searching for file " << fn << endl;
624 
625  if ( project->select < 1 ) {
626  for ( field = project->field; field; field = field->next ) {
627  for ( mg = field->mg; mg; mg = mg->next ) {
628  part = mg->part;
629  if ( mg->fpart == fn ) return part;
630  for ( ; part; part = part->next )
631  if ( part->fpart == fn ) return part;
632  }
633  }
634  } else {
635  for ( rec = project->rec; rec; rec = rec->next ) {
636  part = rec->part;
637  if ( rec->fpart == fn ) return part;
638  for ( ; part; part = part->next )
639  if ( part->fpart == fn ) return part;
640  }
641  }
642 
643  if ( verbose )
644  cerr << "Error: File " << fn << " not found!" << endl;
645 
646  return NULL;
647 }
648 
656 {
657  long npart(0);
658  Bfield* field = NULL;
659  Bmicrograph* mg = NULL;
660  Breconstruction* rec = NULL;
661  Bparticle* part = NULL;
662 
663  FOMType fom_tag[NFOM] = {FOM, FOM_CV};
664 
665  if ( verbose ) {
666  cout << "Updating particles from ppx files" << endl;
667  cout << "FOM tags:";
668  for ( int f=0; f<NFOM && fom_tag[f]; ++f )
669  cout << tab << fom_tag[f];
670  cout << endl;
671  }
672 
673  if ( project->select < 1 ) {
674  for ( field = project->field; field; field = field->next )
675  for ( mg = field->mg; mg; mg = mg->next )
676  for ( part = mg->part; part; part = part->next )
677  npart += ppx_check(part, fom_tag);
678  } else {
679  for ( rec = project->rec; rec; rec = rec->next )
680  for ( part = rec->part; part; part = part->next )
681  npart += ppx_check(part, fom_tag);
682  }
683 
684  if ( verbose )
685  cout << "Number of particles updated: " << npart << endl << endl;
686 
687  return 0;
688 }
689 
697 {
698  long npart(0), nexist(0);
699  Bfield* field = NULL;
700  Bmicrograph* mg = NULL;
701  Breconstruction* rec = NULL;
702  Bparticle* part = NULL;
703 
704  if ( verbose ) {
705  if ( flag == 2 )
706  cout << "Existing ppx files" << endl;
707  else if ( flag == 1 )
708  cout << "Absent ppx files" << endl;
709  }
710 
711  if ( project->select < 1 ) {
712  for ( field = project->field; field; field = field->next )
713  for ( mg = field->mg; mg; mg = mg->next )
714  for ( part = mg->part; part; part = part->next, npart++ )
715  nexist += ppx_exists(part, flag);
716  } else {
717  for ( rec = project->rec; rec; rec = rec->next )
718  for ( part = rec->part; part; part = part->next, npart++ )
719  nexist += ppx_exists(part, flag);
720  }
721 
722  if ( verbose ) {
723  cout << "Number of particles: " << npart << endl;
724  cout << "Number of ppx files: " << nexist << endl;
725  cout << "Number of absent ppx files: " << npart - nexist << endl << endl;
726  }
727 
728  return 0;
729 }
730 
731 
743 {
744  long n(1), c, max(0);
745  Bstring fn;
746  Bfield* field;
747  Bmicrograph* mg;
748  Breconstruction* rec;
749  Bparticle* part;
750 
751  if ( project->select < 1 ) {
752  for ( field = project->field; field; field = field->next )
753  for ( mg = field->mg; mg; mg = mg->next )
754  for ( part = mg->part; part; part = part->next )
755  if ( max < part->sel ) max = part->sel;
756  } else {
757  for ( rec = project->rec; rec; rec = rec->next )
758  for ( part = rec->part; part; part = part->next )
759  if ( max < part->sel ) max = part->sel;
760  }
761 
762  if ( verbose )
763  cout << "Splitting into " << max << " sets of particles" << endl;
764 
765  for ( n=1; n<=max; n++ ) {
766  if ( project->select < 1 ) {
767  for ( c=0, field = project->field; field; field = field->next ) {
768  for ( mg = field->mg; mg; mg = mg->next ) {
769  mg->select = 0;
770  for ( part = mg->part; part; part = part->next ) if ( part->sel == n ) {
771  mg->select = 1;
772  c++;
773  }
774  }
775  }
776  for ( rec = project->rec; rec; rec = rec->next )
777  rec->select = 0;
778  } else {
779  for ( field = project->field; field; field = field->next )
780  for ( mg = field->mg; mg; mg = mg->next )
781  mg->select = 0;
782  for ( c=0, rec = project->rec; rec; rec = rec->next ) {
783  rec->select = 0;
784  for ( part = rec->part; part; part = part->next ) if ( part->sel == n ) {
785  rec->select = 1;
786  c++;
787  }
788  }
789  }
790  if ( c ) {
791  fn = filename.pre_rev('.') + Bstring(n, "_%04d.") + filename.post_rev('.');
792  if ( verbose )
793  cout << "Writing " << fn << " with " << c << " particles" << endl;
794  write_project(fn, project, 1, 1);
795  }
796  }
797 
798  return n;
799 }
800 
811 {
812  Bproject* project_temp = project_init();
813  project_temp->comment = project->comment;
814 
815  int n(0);
816  Bfield* field, *field_next;
817  Bstring fn;
818 
819  for ( field = project->field; field; field = field->next ) {
820  field_next = field->next;
821  field->next = NULL;
822  project_temp->field = field;
823  fn = field->id + ".star";
824  write_project(fn, project_temp, 1, 1);
825  field->next = field_next;
826  }
827 
828  return n;
829 }
830 
Bmicrograph::scale
Vector3< double > scale
Definition: mg_processing.h:224
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::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
rwmgXML.h
Reads and writes micrograph XML files.
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
rwmgSerialEM.h
Converts between SerialEM MDOC files and a micrograph parameter file.
ppx_exists
int ppx_exists(Bparticle *part, int flag)
Definition: rwmg.cpp:421
CTFparam::zero
double zero(int i)
Definition: ctf.h:228
Bbadarea::id
int id
Definition: mg_processing.h:145
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bproject::select
int select
Definition: mg_processing.h:342
write_particle
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:406
NFOM
#define NFOM
Definition: mg_processing.h:16
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
Breconstruction::voxel_size
Vector3< double > voxel_size
Definition: mg_processing.h:295
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
project_count_fields
long project_count_fields(Bproject *project)
Counts all the fields in the project structure.
Definition: mg_select.cpp:335
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
project_count_rec_filaments
long project_count_rec_filaments(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:612
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
FOMType
FOMType
Definition: mg_processing.h:38
project_count_reconstructions
long project_count_reconstructions(Bproject *project)
Counts all the reconstructions in the project structure.
Definition: mg_select.cpp:384
read_project
Bproject * read_project(const char *filename, int flags)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
verbose
int verbose
write_particle_xml
int write_particle_xml(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
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
Bstring::empty
bool empty()
Definition: Bstring.h:71
project_display_counts
int project_display_counts(Bproject *project)
Definition: rwmg.cpp:29
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:105
Bmicrograph::sampling
double sampling
Definition: mg_processing.h:214
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
ppx_check
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:441
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
Bfield::id
Bstring id
Definition: mg_processing.h:262
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
length
double length(vector< T > v)
Definition: Vector3.h:530
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:207
Bbadarea
Definition: mg_processing.h:143
project_check_particles
int project_check_particles(Bproject *project)
Checks particle numbers and box sizes.
Definition: mg_img_proc.cpp:604
rwmgIMOD.h
Converts between IMOD files and a micrograph parameter file.
project
Bproject * project
Definition: bshow.cpp:33
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
rwmg.h
Header file for reading and writing micrograph parameters.
append_project
long append_project(Bproject *project, Bstring *file_list, Bstring &xsdfile, int flags)
Definition: rwmg.cpp:283
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:209
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
command_line_time
Bstring command_line_time()
Returns the command line and time in a string.
Definition: utilities.cpp:71
reconstruction_resolve_file_access
int reconstruction_resolve_file_access(Breconstruction *rec, Bstring filename, int flags)
Definition: rwmg.cpp:93
read_particle_xml
Bparticle * read_particle_xml(Bstring &filename, Bparticle **partlist, FOMType fom_tag[NFOM])
command
string command
Definition: utilities.cpp:20
project_count_mg_selected
long project_count_mg_selected(Bproject *project)
Counts all the selected micrographs in the project structure.
Definition: mg_select.cpp:367
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
project_count_mg_part_selected
long project_count_mg_part_selected(Bproject *project)
Counts the number of particles in a project.
Definition: mg_select.cpp:437
ppx_filename
Bstring ppx_filename(Bstring &id, int part_id)
Definition: rwmg.cpp:415
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bmicrograph::magnification
double magnification
Definition: mg_processing.h:213
project_count_rec_selected
long project_count_rec_selected(Bproject *project)
Counts all the selected reconstructions in the project structure.
Definition: mg_select.cpp:399
project_check
int project_check(Bproject *project, int flags=0)
Definition: rwmg.cpp:473
Bproject
Definition: mg_processing.h:336
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:144
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
micrograph_intensity
double micrograph_intensity(Bmicrograph *mg)
Gets the average of a micrograph.
Definition: mg_img_proc.cpp:659
mg_img_proc.h
Header file for image processing from micrograph structures.
CTFparam::volt
double volt()
Definition: ctf.h:87
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:108
read_project_emx
int read_project_emx(Bstring &filename, Bproject *project, Bstring &xsdfile)
Reading micrograph parameters from XML files.
Definition: rwmgEMX.cpp:241
project_update_from_ppx
long project_update_from_ppx(Bproject *project)
Updates a project with ppx files.
Definition: rwmg.cpp:655
Breconstruction::fft
Bstring fft
Definition: mg_processing.h:293
mg_tags.h
All STAR and XML file format tags for micrographs and reconstructions.
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
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
Breconstruction::select
long select
Definition: mg_processing.h:286
write_project_emx
int write_project_emx(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to an EMX file.
Definition: rwmgEMX.cpp:317
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
read_particle
Bparticle * read_particle(Bstring &filename, Bparticle **partlist, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:305
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
project_count_rec_part_selected
long project_count_rec_part_selected(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:523
rwmgEMX.h
Reads and writes micrograph exchange files.
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.
Bstring::next
Bstring * next
Definition: Bstring.h:31
project_resolve_file_access
int project_resolve_file_access(Bproject *project, Bstring filename, int flags)
Definition: rwmg.cpp:118
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_processing.h
Header file for micrograph processing.
Bmicrograph::intensity
double intensity
Definition: mg_processing.h:217
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
find_file
Bstring find_file(Bstring filename, Bstring path, int flag=0)
Searches for a file within or without the given path.
Definition: file_util.cpp:54
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
project_split_write
int project_split_write(Bstring &filename, Bproject *project)
Splits a project into sets of particle selections and write the files.
Definition: rwmg.cpp:742
Bmicrograph::select
long select
Definition: mg_processing.h:204
write_project_imod
int write_project_imod(Bstring &imodfile, Bproject *project)
Creates IMOD parameter files from a project structure.
Definition: rwmgIMOD.cpp:452
Breconstruction::scale
Vector3< double > scale
Definition: mg_processing.h:297
Bmicrograph::fps
Bstring fps
Definition: mg_processing.h:211
Breconstruction::ffil
Bstring ffil
Definition: mg_processing.h:292
Breconstruction::bad
Bbadarea * bad
Definition: mg_processing.h:309
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
read_project_imod
int read_project_imod(Bstring *file_list, Bproject *project, int flag)
Creates a project structure using IMOD parameters.
Definition: rwmgIMOD.cpp:242
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
read_project_serialem
int read_project_serialem(Bstring &filename, Bproject *project, int flag)
Creates a project structure using SerialEM MDOC parameters.
Definition: rwmgSerialEM.cpp:44
field_resolve_file_access
int field_resolve_file_access(Bfield *field, Bmicrograph *mg, Bstring filename, int flags)
Definition: rwmg.cpp:62
Bproject::comment
Bstring comment
Definition: mg_processing.h:339
project_count_mg_filaments
long project_count_mg_filaments(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:564
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:528
project_list_ppx
long project_list_ppx(Bproject *project, int flag)
Lists existing ppx files for a project.
Definition: rwmg.cpp:696
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:244
FOM_CV
@ FOM_CV
Definition: mg_processing.h:42
Breconstruction::fps
Bstring fps
Definition: mg_processing.h:294
project_split_field_write
int project_split_field_write(Bproject *project)
Splits a project into sets of particle selections and write the files.
Definition: rwmg.cpp:810
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
read_project_star
int read_project_star(Bstring &filename, Bproject *project)
Reading micrograph parameters from STAR files.
Definition: rwmgSTAR.cpp:29
particle_update
int particle_update(Bparticle *part, Bparticle *nu_part)
Updates one existing particle with new information.
Definition: mg_processing.cpp:1026
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:106
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
project_find_particle
Bparticle * project_find_particle(Bproject *project, Bstring &fn)
Finds a particle associated with a file name.
Definition: rwmg.cpp:610
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
FOM
@ FOM
Definition: mg_processing.h:40
CTFparam::Cs
double Cs()
Definition: ctf.h:91
Bmicrograph::fft
Bstring fft
Definition: mg_processing.h:210
project_count_rec_filament_nodes
long project_count_rec_filament_nodes(Bproject *project)
Counts the number of filaments in a project.
Definition: mg_select.cpp:633
project_count_rec_particles
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:506
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
project_count_mg_filament_nodes
long project_count_mg_filament_nodes(Bproject *project)
Counts the number of filament nodes in a project.
Definition: mg_select.cpp:587