Bsoft  2.1.0
Bernard's software package
bdual.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_tomography.h"
13 #include "mg_tomo_track.h"
14 #include "ps_marker.h"
15 #include "utilities.h"
16 #include "options.h"
17 #include "timer.h"
18 
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21 
22 
23 // Usage assistance
24 const char* use[] = {
25 " ",
26 "Usage: bdual [options] input1.star [input2.star]",
27 "------------------------------------------------",
28 "Handles dual tomographic tilt series of micrographs.",
29 "Expects exactly two input parameter files corresponding to the two tilt series.",
30 "Outputs only the second series to a parameter file.",
31 " ",
32 "Actions:",
33 "-seed 1.3,-95,75 Transfers seed markers from first to second series,",
34 " using the angular increment to test for rotation angle,",
35 " within the angular limits (default -180,180).",
36 "-refine Refines markers from the second series after transfer.",
37 "-transform Calculates the correct micrograph transformations for the 2nd series.",
38 "-deselect 5-9,33 Deselect markers by id from all micrographs and models.",
39 "-zcompare Compare Z coordinates of the first and second series.",
40 " ",
41 "Parameters:",
42 "-verbose 7 Verbosity of output.",
43 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
44 "-resolution 900,300 High and low resolution limits for cross-correlation (default 0.1,1000 angstrom).",
45 "-shiftlimit 155.5 Limit on micrograph shift search in pixels (default 20% of micrograph width).",
46 " ",
47 "Output:",
48 "-output file.star Output parameter file for 2nd series.",
49 "-Postscript out.ps Postscript output with Z coordinate error plots.",
50 "-bild out.bld BILD output with fitted marker models.",
51 " ",
52 NULL
53 };
54 
55 
56 int main(int argc, char** argv)
57 {
58  // Initializing variables
59  double rot_start(-180), rot_end(180); // Rotation search limits
60  double rot_step(0); // Rotation search step size for seed transfer
61  int refine(0); // Flag to refine seed markers
62  int transform(0); // Flag to transform micrograph parameters
63  Bstring deselect; // String specifying markers to deselect
64  int zcompare(0); // Flag to enable Z compare option
65  Vector3<double> sam; // Units for the three axes (A/pixel)
66  double hi_res(0), lo_res(1000); // Default resolution range
67  double shift_limit(-1); // Micrograph shift search limit
68  Bstring paramfile; // Output parameter file
69  Bstring psfile; // Output postscript file
70  Bstring bildfile; // Output bild file
71 
72  int optind;
73  Boption* option = get_option_list(use, argc, argv, optind);
74  Boption* curropt;
75  for ( curropt = option; curropt; curropt = curropt->next ) {
76  if ( curropt->tag == "seed" ) {
77  if ( curropt->values(rot_step, rot_start, rot_end) < 1 )
78  cerr << "-rotation: A rotation angle step size must be specified." << endl;
79  else {
80  rot_step *= M_PI/180.0;
81  rot_start *= M_PI/180.0;
82  rot_end *= M_PI/180.0;
83  }
84  }
85  if ( curropt->tag == "refine" ) refine = 1;
86  if ( curropt->tag == "transform" ) transform = 1;
87  if ( curropt->tag == "deselect" ) deselect = curropt->value;
88  if ( curropt->tag == "zcompare" ) zcompare = 1 ;
89  if ( curropt->tag == "sampling" )
90  sam = curropt->scale();
91  if ( curropt->tag == "resolution" ) {
92  if ( curropt->values(hi_res, lo_res) < 1 )
93  cerr << "-resolution: Resolution limits must be specified." << endl;
94  else if ( hi_res > lo_res )
95  swap(hi_res, lo_res);
96  }
97  if ( curropt->tag == "shiftlimit" )
98  if ( ( shift_limit = curropt->value.real() ) < 1 )
99  cerr << "-shiftlimit: A shift limit in pixels must be specified." << endl;
100  if ( curropt->tag == "output" )
101  paramfile = curropt->filename();
102  if ( curropt->tag == "Postscript" )
103  psfile = curropt->filename();
104  if ( curropt->tag == "bild" )
105  bildfile = curropt->filename();
106  }
107  option_kill(option);
108 
109  double ti = timer_start();
110 
111  // Read all the parameter files
112  Bstring* file_list = NULL;
113  if ( optind < argc ) string_add(&file_list, argv[optind++]);
114  if ( optind < argc ) string_add(&file_list, argv[optind++]);
115  if ( !file_list ) {
116  cerr << "Error: No parameter files specified!" << endl;
117  bexit(-1);
118  }
119 
120  Bproject* project = read_project(file_list);
121  if ( !project || !project->field || !project->field->mg ) {
122  cerr << "Error: No first tilt series!" << endl;
123  bexit(-1);
124  }
125 
126  if ( !project->field->next ) {
127  cerr << "Error: Two tilt series (fields) must be specified!" << endl;
128  bexit(-1);
129  }
130 
132 
133  if ( deselect.length() )
135 
136  if ( project->field->mg->origin[0] < 1 || project->field->mg->origin[1] < 1 )
138 
139  if ( sam[0] > 0 )
141 
142  if ( rot_step > 0 ) {
143  project_transfer_seed(project, rot_start, rot_end, rot_step, hi_res, lo_res, shift_limit);
144  project->field->select = 0;
145  if ( refine )
146  project_refine_markers(project, hi_res, lo_res);
147  project->field->select = 1;
148  }
149 
150  if ( transform )
152 
153  if ( bildfile.length() )
155 
156  if ( zcompare )
158 
159  if ( psfile.length() )
160  ps_dual_zcompare(psfile, project);
161 
162 // project_tomo_errors(project2);
163 
164 // if ( transform )
165 // project_merge_rec_markers(project);
166 
167 // if ( project->rec ) project_tomo_residuals(project, 1);
168 
169  if ( paramfile.length() )
170  write_project(paramfile, project, 1, 1);
171 
173 
174  if ( verbose & VERB_TIME )
175  timer_report(ti);
176 
177  bexit(0);
178 }
179 
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
ps_marker.h
Header file for postscript tools dealing with Bmarkers.
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:310
project_transfer_seed
int project_transfer_seed(Bproject *project, double rot_start, double rot_end, double rot_step, double hi_res, double lo_res, double shift_limit)
Transfers the seed markers from the first to the second project.
Definition: mg_tomo_track.cpp:1421
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
main
int main(int argc, char **argv)
Definition: bdual.cpp:56
Bstring
Definition: Bstring.h:29
ps_dual_zcompare
int ps_dual_zcompare(Bstring &filename, Bproject *project)
Generates a PostScript file that displays X by X, Y by Y, and Z by Z plots for diagnostic purposes.
Definition: ps_marker.cpp:424
Bproject::field
Bfield * field
Definition: mg_processing.h:346
project_sort_markers_by_id
int project_sort_markers_by_id(Bproject *project)
Sorts markers for each micrograph by ID number.
Definition: mg_tomography.cpp:844
project_set_nominal_mg_origins
int project_set_nominal_mg_origins(Bproject *project)
Sets micrograph origins to the centers of the micrographs.
Definition: mg_img_proc.cpp:770
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
marker_sets_to_bild
int marker_sets_to_bild(Bstring &filename, Bmarker *mark1, Bmarker *mark2)
Generates a bild file with the two marker sets.
Definition: marker.cpp:1287
mg_tomo_track.h
Functions to track fiducial markers in a tomographic series of images.
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
use
const char * use[]
Definition: bdual.cpp:24
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
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
project_dual_zcompare
double project_dual_zcompare(Bproject *project)
Lists two sets of Z coordinates for comparison.
Definition: mg_tomo_track.cpp:1644
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Boption::value
Bstring value
Definition: options.h:30
project_transform_dual
int project_transform_dual(Bproject *project)
Calculates the transformation of the second tilt series to fit the first.
Definition: mg_tomo_track.cpp:1544
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
mg_img_proc.h
Header file for image processing from micrograph structures.
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
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
Bfield::select
long select
Definition: mg_processing.h:265
Bfield::next
Bfield * next
Definition: mg_processing.h:261
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
mg_processing.h
Header file for micrograph processing.
project_refine_markers
int project_refine_markers(Bproject *project, double hi_res, double lo_res)
Refines marker positions in a tomographic series.
Definition: mg_tomo_track.cpp:685
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
verbose
int verbose
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
mg_tomography.h
Header file for single particle image processing in Bsoft.
project_deselect_markers
long project_deselect_markers(Bproject *project, Bstring &deselect_list)
Deletes selected markers in a project hierarchy.
Definition: mg_tomography.cpp:1603
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284