166 "Usage: mg2imod [options] input.mrc input.xf input.tlt input.fid input.xyz",
167 "-------------------------------------------------------------------------",
168 "Converts between IMOD files and a micrograph parameter file.",
171 "-topif Flag to convert the image file to multi-image PIF (default not).",
174 "-verbose 7 Verbosity of output.",
175 "-sampling 1.5 Sampling (A/pixel).",
178 "-output file.star Output micrograph parameter file.",
179 "-imod file.xf Output IMOD parameter files.",
185 int main(
int argc,
char** argv)
196 for ( curropt = option; curropt; curropt = curropt->
next ) {
197 if ( curropt->
tag ==
"topif" ) flag = 1;
198 if ( curropt->
tag ==
"sampling" )
199 if ( ( sampling = curropt->
value.
real() ) < 0.1 )
200 cerr <<
"-sampling: A pixel size must be specified" << endl;
201 if ( curropt->
tag ==
"output" )
203 if ( curropt->
tag ==
"imod" )
214 while ( optind < argc )
string_add(&file_list, argv[optind++]);
216 cerr <<
"Error: No parameter files specified!" << endl;
230 if ( project == NULL ) {
231 cerr <<
"Error: No project generated!" << endl;
235 if ( sampling > 0.1 )
259 ifstream fprm(filename.
c_str());
261 cerr <<
"Error: A text file specifying 2D transformations must be given!" << endl;
266 cout <<
"Reading 2D transformations from " << filename << endl;
268 for ( mg = project->
field->
mg; mg; mg = mg->
next ) {
269 fprm >> a[0] >> a[1] >> a[2] >> a[3] >> dx >> dy;
270 mg->
tilt_axis = (atan2(-a[0], a[1]) + atan2(-a[3], -a[2]))/2.0;
271 mg->
origin[0] -= a[0]*dx + a[2]*dy;
272 mg->
origin[1] -= a[1]*dx + a[3]*dy;
286 ifstream fprm(filename.
c_str());
288 cerr <<
"Error: A text file specifying tilt angles must be given!" << endl;
293 cout <<
"Reading tilt angles from " << filename << endl;
295 for ( mg = project->
field->
mg; mg; mg = mg->
next ) {
308 int mark_id(0), first(1);
313 ifstream fprm(filename.
c_str());
315 cerr <<
"Error: A text file specifying the 3D marker model must be given!" << endl;
319 fprm >> mark_id >> x >> y >> z >> dum >> dum;
320 while ( fprm >> word ) {
321 if ( word ==
"Pix:" ) fprm >> rec->
voxel_size;
322 if ( word ==
"Dim:" )
break;
328 cout <<
"Getting reconstruction parameters from " << filename << endl;
330 cout <<
"Getting reconstruction parameters from " << rec->
frec << endl;
336 cout << setprecision(3) <<
"Voxel size = " << rec->
voxel_size <<
" Origin = " << rec->
origin << endl;
338 while ( !fprm.eof() ) {
339 if ( first ) first = 0;
340 else fprm >> mark_id >> x >> y >> z >> dum >> dum;
341 if ( fprm.fail() )
break;
349 cout << mark_id <<
tab << x <<
tab << y <<
tab << z << endl;
362 ifstream fprm(filename.
c_str());
364 cerr <<
"Error: A binary IMOD file specifying the fiducial markers must be given!" << endl;
369 cout <<
"Reading markers from " << filename << endl;
379 fprm.read((
char *)tag, 4);
380 if ( fprm.fail() )
return -2;
382 fprm.read((
char *)tag, 4);
383 if ( fprm.fail() )
return -2;
387 if ( fprm.fail() )
return -2;
389 swapbytes((
unsigned char *) &imod->objsize, 4);
392 cout <<
"number of objects = " << imod->objsize << endl;
394 fprm.read((
char *)tag, 4);
395 if ( fprm.fail() )
return -2;
398 if ( fprm.fail() )
return -2;
400 swapbytes((
unsigned char *) &objt->contsize, 4);
403 cout <<
"number of contours = " << objt->contsize << endl;
405 for ( i=0; i<objt->contsize; i++ ) {
406 fprm.read((
char *)tag, 4);
407 if ( fprm.fail() )
return -2;
410 if ( fprm.fail() )
return -2;
412 swapbytes((
unsigned char *) &cont->psize, 4);
415 cout <<
"number of points = " << cont->psize << endl;
417 psize = 3*cont->psize*
sizeof(float);
418 point =
new float[3*cont->psize];
420 fprm.read((
char *)point, psize);
421 if ( fprm.fail() )
return -2;
423 swapbytes(psize, (
unsigned char *) point, 4);
425 for ( j=0, mg = project->
field->
mg; mg; mg = mg->
next, j+=3 ) {
431 cout << mg->
id << tab << mark->
id << tab << mark->
loc << endl;
470 if ( file_list->
empty() ) {
471 cerr <<
"No filenames given to create a project!" << endl;
480 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
484 base = imgfile.
base();
487 cerr <<
"Error: Image file " << imgfile <<
" not read!" << endl;
488 error_show(
"project_from_IMOD", __FILE__, __LINE__);
491 if ( p->
sizeZ() > 1 ) {
496 imgfile = base +
".pif";
506 cerr <<
"Error: No image file provided!" << endl;
507 error_show(
"project_from_IMOD", __FILE__, __LINE__);
518 for ( n=0; n<p->
images(); n++ ) {
519 mg_id = base +
Bstring(n+1,
"_%03d");
521 if ( !field->
mg ) field->
mg = mg;
529 cout <<
"Creating field " << field->
id <<
", micrograph " << mg->
id << endl;
530 cout <<
"Pixel size = " << mg->
pixel_size <<
" Origin = " << mg->
origin << endl;
537 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
546 rec->
frec = base +
".rec";
593 ofstream fprm(paramfile.
c_str());
595 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
600 cout <<
"Writing 2D transformations to " << paramfile << endl;
604 for ( mg = project->
field->
mg; mg; mg = mg->
next ) {
611 fprm << setprecision(7) << setw(12) << a[0]
615 << setprecision(3) << setw(12) << a[0]*d.
x() + a[1]*d.
y()
616 << setw(12) << a[2]*d.
x() + a[3]*d.
y() << endl;
622 paramfile = imodfile.
base() +
".tlt";
629 fprm.open(paramfile.
c_str());
631 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
636 cout <<
"Writing tilt angles to " << paramfile << endl;
645 if ( rec && rec->
mark ) {
646 paramfile = imodfile.
base() +
"fid.xyz";
653 fprm.open(paramfile.
c_str());
655 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
660 cout <<
"Writing the 3D marker model to " << paramfile << endl;
672 for ( mark = rec->
mark; mark; mark = mark->
next ) {
673 fprm << setw(4) << mark->
id 674 << setprecision(2) << setw(10) << mark->
loc.
x() + rec->
origin.
x()
676 << setw(10) << mark->
loc.
z()
677 << setw(7) << 1 << setw(5) << mark->
id;
678 if ( mark == rec->
mark )
679 fprm <<
" Pix: " << setprecision(5) << setw(11) << rec->
voxel_size 680 <<
" Dim: " << setprecision(0) << setw(6) << 2*rec->
origin.
x()
681 << setw(6) << 2*rec->
origin.
y();
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Header file for reading and writing micrograph parameters.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Header file for general utilities.
Bimage * read_img(Bstring filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for image processing from micrograph structures.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
int write_img(Bstring filename, Bimage *p)
General driver function to write multiple image formats.
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Utilities for timing functions.
int read_imod_tlt(Bstring &filename, Bproject *project)
General image parameter class.
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
bool contains(const Bstring &s)
Header file for generalized linked list functions.
Bproject * project_from_IMOD(Bstring *file_list, int flag)
Creates a project structure using IMOD parameters.
A class for a command line input option.
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
int read_imod_fid(Bstring &filename, Bproject *project)
Header file for single particle image processing in Bsoft.
Vector3< long > size() const
void swapbytes(unsigned char *v, size_t n)
Swaps bytes.
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
int project_kill(Bproject *project)
Frees a whole project.
int project_set_pixel_size(Bproject *project, double pixel_size)
Sets the pixel size for all the micrographs.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Vector3< double > micrograph_get_nominal_origin(Bmicrograph *mg)
Gets the nominal origin for a micrograph.
int read_imod_xf(Bstring &filename, Bproject *project)
int option_kill(Boption *option)
Deallocates a linked list of option structures.
int read_imod_xyz(Bstring &filename, Breconstruction *rec)
Header file for micrograph processing.
Header file for 2D and 3D image I/O.
Header file for option handlers.
int main(int argc, char **argv)
int project_update_comment(Bproject *project, int n, char **strings)
Puts a set of strings and time in the main comment of a project.
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
int bexit(int value)
Exit function for cleanup and debugging.
double timer_start()
Starts timer and prints the time.
ostream & tab(ostream &out)
int string_kill(Bstring *list)
Kills a string linked list.
int write_IMOD_parameters(Bstring &imodfile, Bproject *project)
Creates IMOD parameter files from a project structure.