30 "Usage: mg2imod [options] input.mrc input.xf input.tlt input.xyz",
31 "---------------------------------------------------------------",
32 "Converts between IMOD files and a micrograph parameter file.",
35 "-topif Flag to convert the image file to multi-image PIF (default not).",
38 "-verbose 7 Verbosity of output.",
39 "-sampling 1.5 Sampling (A/pixel).",
42 "-output file.star Output micrograph parameter file.",
43 "-imod file.xf Output IMOD parameter files.",
49 int main(
int argc,
char** argv)
60 for ( curropt = option; curropt; curropt = curropt->next ) {
61 if ( strcmp(curropt->tag,
"topif") == 0 ) flag = 1;
62 if ( strcmp(curropt->tag,
"sampling") == 0 )
63 if ( sscanf(curropt->value,
"%f", &sampling) < 1 )
64 cerr <<
"-sampling: A pixel size must be specified" << endl;
65 if ( strcmp(curropt->tag,
"output") == 0 )
66 outfile = get_option_filename(curropt->value);
67 if ( strcmp(curropt->tag,
"imod") == 0 )
68 imodfile = get_option_filename(curropt->value);
78 while ( optind < argc )
string_add(&file_list, argv[optind++]);
80 cerr <<
"Error: No parameter files specified!" << endl;
94 if ( project == NULL ) {
95 cerr <<
"Error: No project generated!" << endl;
145 if ( file_list->
empty() ) {
146 cerr <<
"No filenames given to create a project!" << endl;
155 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
159 base = imgfile.
base();
160 if ( ext.
contains(
"st") ) imgfile +=
":mrc";
163 cerr <<
"Error: Image file " << imgfile <<
" not read!" << endl;
164 error_show(
"project_from_IMOD", __FILE__, __LINE__);
173 imgfile = base +
".pif";
181 cerr <<
"Error: No image file provided!" << endl;
182 error_show(
"project_from_IMOD", __FILE__, __LINE__);
187 Bstring mg_id, rec_id, rec_name;
194 for ( n=0; n<p->
images(); n++ ) {
195 mg_id = base +
Bstring(n+1,
"_%03d");
197 if ( !field->
mg ) field->
mg = mg;
204 cout <<
"Creating field \"" << field->
id <<
"\", micrograph \"" << mg->
id <<
"\"" << endl;
210 char aline[100], *aptr;
213 double a[4], dx, dy, ta;
215 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
218 if ( ( fd = fopen(thisfile->
c_str(),
"r") ) == NULL ) {
219 cerr <<
"Error: A text file specifying 2D transformations must be given!" << endl;
223 cout <<
"Reading 2D transformations from \"" << *thisfile <<
"\"" << endl;
224 for ( mg = field->
mg; mg; mg = mg->
next ) {
225 fscanf(fd,
"%lf %lf %lf %lf %lf %lf", &a[0], &a[1], &a[2], &a[3], &dx, &dy);
226 mg->
tilt_axis = (atan2(-a[0], a[1]) + atan2(-a[3], -a[2]))/2.0;
227 mg->
origin[0] -= a[0]*dx + a[2]*dy;
228 mg->
origin[1] -= a[1]*dx + a[3]*dy;
232 if ( ( fd = fopen(thisfile->
c_str(),
"r") ) == NULL ) {
233 cerr <<
"Error: A text file specifying tilt angles must be given!" << endl;
237 cout <<
"Reading tilt angles from \"" << *thisfile <<
"\"" << endl;
238 for ( mg = field->
mg; mg; mg = mg->
next ) {
239 fscanf(fd,
"%lf", &ta);
244 if ( ( fd = fopen(thisfile->
c_str(),
"r") ) == NULL ) {
245 cerr <<
"Error: A text file specifying the 3D marker model must be given!" << endl;
249 cout <<
"Reading the 3D marker model from \"" << *thisfile <<
"\"" << endl;
252 rec_name = base +
".rec";
253 if ( access(rec_name.
c_str(), R_OK) ) {
254 fgets(aline, 100, fd);
255 aptr = strstr(aline,
"Pix");
260 rec->
frec = rec_name;
267 while ( fgets(aline, 100, fd) ) {
268 if ( sscanf(aline,
"%d %f %f %f %d %d", &mark_id, &x, &y, &z, &dum, &dum) > 5 ) {
319 if ( ( fd = fopen(paramfile.
c_str(),
"w") ) == NULL ) {
320 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
325 cout <<
"Writing 2D transformations to \"" << paramfile <<
"\"" << endl;
329 for ( mg = project->
field->
mg; mg; mg = mg->
next ) {
334 fprintf(fd,
"%12.7lf%12.7lf%12.7lf%12.7lf%12.3lf%12.3lf\n", a[0], a[1],
335 a[2], a[3], a[0]*d.
x() + a[1]*d.
y(), a[2]*d.
x() + a[3]*d.
y());
340 paramfile = imodfile.
base() +
".tlt";
342 if ( ( fd = fopen(paramfile.
c_str(),
"w") ) == NULL ) {
343 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
348 cout <<
"Writing tilt angles to \"" << paramfile <<
"\"" << endl;
355 if ( rec && rec->
mark ) {
356 paramfile = imodfile.
base() +
"fid.xyz";
358 if ( ( fd = fopen(paramfile.
c_str(),
"w") ) == NULL ) {
359 error_show(
"write_IMOD_parameters", __FILE__, __LINE__);
364 cout <<
"Writing the 3D marker model to \"" << paramfile <<
"\"" << endl;
366 for ( mark = rec->
mark; mark; mark = mark->
next ) {
367 fprintf(fd,
"%4d%10.2f%10.2f%10.2f %6d %4d", mark->
id,
369 if ( mark == rec->
mark )
370 fprintf(fd,
" Pix: %11.5f Dim: %5.0f %5.0f\n",
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.
int main(int argc, char **argv)
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.
Bproject * project_from_IMOD(Bstring *file_list, int flag)
Creates a project structure using IMOD parameters.
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.
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
Header file for single particle image processing in Bsoft.
Vector3< long > size() const
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.
int write_IMOD_parameters(Bstring &imodfile, Bproject *project)
Creates IMOD parameter files from a project structure.
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 option_kill(Boption *option)
Deallocates a linked list of option structures.
Header file for micrograph processing.
Header file for 2D and 3D image I/O.
Header file for option handlers.
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.
int string_kill(Bstring *list)
Kills a string linked list.