| Bsoft 2.0.5 Bernard's software package

emgrand.cpp
Go to the documentation of this file.
1
9 #include "mg_random.h"
10 #include "rwmg.h"
11 #include "symmetry.h"
12 #include "utilities.h"
13 #include "timer.h"
14 #include "options.h"
15
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
20 // Usage assistance
21 const char* use[] = {
22 " ",
23 "Usage: emgrand [options] input.star [input.star]",
24 "------------------------------------------------",
25 "Randomizes particle parameters.",
26 " ",
27 "Actions:",
28 "-randomviews Replace views with random orientations.",
29 "-helical Replace views with random orientations for a helix.",
30 "-symmetry C5 Replace views with random symmetry-related orientations.",
31 "-origins 1.4 Introduce random errors into origins with this standard deviation (pixels).",
32 "-views 3.1 Introduce random errors into views with this standard deviation (degrees).",
33 "-defocus 0.3 Introduce random errors into defocus with this standard deviation (um).",
34 "-magnification 0.1 Introduce random errors into magnifications with this standard deviation (fraction).",
35 "-setasu C5 Set the views to the asymmetric unit (must agree with -symmetry if used).",
36 " ",
37 "Parameters:",
38 "-verbose 7 Verbosity of output.",
39 " ",
40 "Output:",
41 "-output file.star Output parameter file name.",
42 " ",
43 NULL
44 };
45
46
47 int main(int argc, char **argv)
48 {
49 // Initialize optional variables
50 double randomorigins(0); // Standard deviation for origin errors (angstrom)
51 double randomviews(0); // Standard deviation for view errors (degrees)
52 double randomdefocus(0); // Standard deviation for defocus errors (angstrom)
53 double randommag(0); // Standard deviation for magnification errors (fraction)
54 Bstring outfile; // Output parameter file
55 Bsymmetry* sym = NULL; // No symmetry specified
56 int random(0); // Flag to generate random views
57 int helical(0); // Flag to generate random helical views
58 int randsym(0); // Flag to generate random symmetry-related views
59 int asu(0); // Flag to change views to ASU
60
61 int optind;
62 Boption* option = get_option_list(use, argc, argv, optind);
63 Boption* curropt;
64 for ( curropt = option; curropt; curropt = curropt->next ) {
65 if ( curropt->tag == "randomviews" )
66 random = 1;
67 if ( curropt->tag == "helical" )
68 helical = 1;
69 if ( curropt->tag == "symmetry" ) {
70 sym = curropt->symmetry();
71 randsym = 1;
72 }
73 if ( curropt->tag == "origins" ) {
74 if ( ( randomorigins = curropt->value.real() ) < 0.00001 )
75 cerr << "-origins: A standard deviation must be specified!" << endl;
76 else if ( randomorigins < 0 ) randomorigins = 0;
77 }
78 if ( curropt->tag == "views" ) {
79 if ( ( randomviews = curropt->value.real() ) < 0.00001 )
80 cerr << "-views: A standard deviation must be specified!" << endl;
81 else {
82 randomviews *= M_PI/180.0; // Assume degrees
83 if ( randomviews < 0 ) randomviews = 0;
84 }
85 }
86 if ( curropt->tag == "defocus" ) {
87 if ( ( randomdefocus = curropt->value.real() ) < 0.00001 )
88 cerr << "-defocus: A standard deviation must be specified!" << endl;
89 else {
90 if ( randomdefocus < 100 ) randomdefocus *= 1e4; // Assume um
91 if ( randomdefocus < 0 ) randomdefocus = 0;
92 }
93 }
94 if ( curropt->tag == "magnification" ) {
95 if ( ( randommag = curropt->value.real() ) < 0.00001 )
96 cerr << "-magnification: A standard deviation must be specified!" << endl;
97 else
98 if ( randommag < 0 ) randommag = 0;
99 }
100 if ( curropt->tag == "setasu" ) {
101 sym = curropt->symmetry();
102 asu = 1;
103 }
104 if ( curropt->tag == "output" )
105 outfile = curropt->filename();
106 }
107 option_kill(option);
108
109 double ti = timer_start();
110
111 // Read parameter file(s)
112 Bstring* file_list = NULL;
113 while ( optind < argc ) string_add(&file_list, argv[optind++]);
114 if ( !file_list ) {
115 cerr << "Error: No parameter files specified!" << endl;
116 bexit(-1);
117 }
118
119 Bproject* project = read_project(file_list);
120 if ( project == NULL ) {
121 cerr << "Error: No input file read!" << endl;
122 bexit(-1);
123 }
124
125 if ( random )
126 project_random_views(project);
127
128 if ( helical )
129 project_random_helical_views(project);
130
131 if ( sym && randsym )
132 project_random_symmetry_related_views(project, sym);
133
134 if ( randomorigins )
135 project_random_origins(project, randomorigins);
136
137 if ( randomviews )
138 project_random_views(project, randomviews);
139
140 if ( randomdefocus )
141 project_random_defocus(project, randomdefocus);
142
143 if ( randommag )
144 project_random_magnification(project, randommag);
145
146 if ( sym && asu )
147 project_set_particle_asu_views(project, sym);
148
149 // Output parameters
150 if ( project && outfile.length() ) {
151 project_update_comment(project, argc, argv);
152 write_project(outfile, project, 0, 0);
153 }
154
155 // Memory cleanup
156 project_kill(project);
157 kill_symmetry(sym);
158
159 if ( verbose & VERB_TIME )
160 timer_report(ti);
161
162 bexit(0);
163 }
164
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
rwmg.h
Header file for reading and writing micrograph parameters.
Bstring::real
double real()
Definition: Bstring.cpp:545
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
project_set_particle_asu_views
int project_set_particle_asu_views(Bproject *project, Bstring &symmetry_asu)
Sets particle views within the asymmetric unit.
Definition: mg_processing.cpp:3792
project_random_helical_views
int project_random_helical_views(Bproject *project)
Replace the original particle orientations by random side views for a helix.
Definition: mg_random.cpp:179
symmetry.h
Header file for general symmetry functions.
utilities.h
Header file for general utilities.
mg_random.h
Header file for applying some randomization to parameters.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
project_random_symmetry_related_views
int project_random_symmetry_related_views(Bproject *project, Bsymmetry *sym)
Replaces the original orientations by symmetry-related views.
Definition: mg_random.cpp:362
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
verbose
int verbose
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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
Boption::filename
Bstring filename()
Definition: options.h:85
main
int main(int argc, char **argv)
Definition: emgrand.cpp:47
timer.h
Utilities for timing functions.
project_random_origins
int project_random_origins(Bproject *project, double std)
Introduces random errors into particle origins.
Definition: mg_random.cpp:73
M_PI
#define M_PI
Definition: utilities.h:59
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
project_random_views
int project_random_views(Bproject *project)
Replace the original particle orientations by random views.
Definition: mg_random.cpp:130
Bsymmetry
Definition: symmetry.h:38
project_random_defocus
int project_random_defocus(Bproject *project, double std)
Introduces random errors into micrograph defocus averages.
Definition: mg_random.cpp:28
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
project_random_magnification
int project_random_magnification(Bproject *project, double std)
Introduces random errors into particle magnifications.
Definition: mg_random.cpp:313
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
options.h
Header file for option handlers.
project_update_comment
int project_update_comment(Bproject *project, int n, char **strings)
Puts a set of strings and time in the main comment of a project.
Definition: rwmg.cpp:468
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bproject
Definition: mg_processing.h:333
use
const char * use[]
Definition: emgrand.cpp:21