| Bsoft 2.0.5 Bernard's software package

jpartdif.cpp
Go to the documentation of this file.
1
12 #include "rwmg.h"
13 #include "mg_processing.h"
14 #include "mg_multiple.h"
15 #include "mg_particle_select.h"
16 #include "Matrix.h"
17 #include "utilities.h"
18 #include "options.h"
19 #include "timer.h"
20 #include "Vector3.h"
21 #include "View.h"
22
23 // Declaration of global variables
24 extern int verbose; // Level of output to the screen
25
26 // Usage assistance
27 const char* use[] = {
28 " ",
29 "Usage: jpartdif [options] input1.star input2.star",
30 "-------------------------------------------------",
31 "Calculates the difference in the particle parameters,",
32 "or selects particles based on the fom difference.",
33 " ",
34 "Parameters:",
35 "-verbose 7 Verbosity of output.",
36 "-consolidate Only consolidate particles based on distance.",
37 "-locdiff Calculate the difference in the locations.",
38 "-fomdiff Calculate the difference in the foms.",
39 "-printlocdiff Print the difference in the locations.",
40 "-printanglediff Print the difference in the view angle.",
41 "-printalphadiff Print the difference in the alpha angles.",
42 "-thrlocdiff 10.0 Analyse only particles below threshold (pixels).",
43 "-thranglediff 20.0 Analyse only particles below threshold (degrees).",
44 "-remove Remove all particles with selection number 0.",
45 " ",
46 "Output:",
47 "-output file.star Output parameter file.",
48
49 " ",
50 NULL
51 };
52
53 int main(int argc, char** argv)
54 {
55 // Initializing variables
56 Bstring outfile; // Output parameter file
57 int optind;
58 int consolidate(0);
59 int locdiff(0), fomdiff(0);
60 int printlocdiff(0), printanglediff(0), printalphadiff(0);
61 double anglediffthr(-1), locdiffthr(-1);
62
63 Boption* option = get_option_list(use, argc, argv, optind);
64 Boption* curropt;
65 for ( curropt = option; curropt; curropt = curropt->next ) {
66 if ( curropt->tag == "consolidate" )
67 consolidate = 1;
68 if ( curropt->tag == "locdiff" )
69 locdiff = 1;
70 if ( curropt->tag == "printlocdiff" )
71 printlocdiff = 1;
72 if ( curropt->tag == "printanglediff" )
73 printanglediff = 1;
74 if ( curropt->tag == "printalphadiff" )
75 printalphadiff = 1;
76 if ( curropt->tag == "fomdiff" )
77 fomdiff = 1;
78 if ( curropt->tag == "output" )
79 outfile = curropt->filename();
80 if ( curropt->tag == "thrlocdiff" )
81 if ( ( locdiffthr = curropt->value.real() ) < 0.001 )
82 cerr << "-thrlocdiff: A threshold must be specified!" << endl;
83 if ( curropt->tag == "thranglediff" )
84 if ( ( anglediffthr = curropt->value.real() ) < 0.001 )
85 cerr << "-thranglediff: A threshold must be specified!" << endl;
86
87 }
88
89 option_kill(option);
90
91 double ti = timer_start();
92
93 // Read all the parameter files
94 Bproject* project1 = NULL;
95 Bproject* project2 = NULL;
96 Bproject* project = NULL;
97 Breconstruction* rec1 = NULL;
98 Breconstruction* rec2 = NULL;
99 Bparticle* part1 = NULL;
100 Bparticle* part2 = NULL;
101 Bparticle* part3 = NULL;
102 Bparticle* part = NULL;
103 View view1;
104 View view2;
105 Vector3<double> part1_view;
106 Vector3<double> part2_view;
107
108 double locresid(0), angleresid(0), alpharesid(0), sumlocresid2(0), sumangleresid2(0), sumalpharesid2(0), alpha1, alpha2;
109
110 project1 = read_project(argv[optind++]);
111 project2 = read_project(argv[optind++]);
112 project = project_create(0,1);
113
114 double d, dmin;
115 int closest_part_id(-1), found(0), npart(0);
116
117 if ( consolidate ) {
118 for ( rec1 = project1->rec, rec2=project2->rec ; rec1 && rec2; rec1=rec1->next, rec2=rec2->next ) {
119 for ( part1 = rec1->part; part1 ; part1 = part1->next ) {
120 // find the closest particle (part2) for the current hit (part1)
121 dmin=10000000;
122 for ( part2 = rec2->part; part2 ; part2 = part2->next ) {
123 d = part2->loc.distance(part1->loc);
124 if ( d < dmin ) {
125 dmin = d;
126 closest_part_id = part2->id;
127 }
128 }
129 // check if a particle was assigned to this hit already in the output structure (project)
130 for ( part3 = project->rec->part ; part3 ; part3 = part3->next ) {
131 if ( part3->id == closest_part_id ) {
132 found = 1;
133 }
134 if ( found ) { break ; }
135 }
136 // if the hit corresponds to a new found particle, add to the outputs
137 if ( !found ) {
138 part=particle_add(&project->rec->part, closest_part_id);
139 part->loc = part1->loc;
140 part->ori = part1->ori;
141 part->view = part1->view;
142 part->fom[0] = part1->fom[0];
143 }
144 // if the hit corresponds to a particle that was assigned already, check if this hit is better and then update
145 else {
146 if (part1->fom[0] > part3->fom[0] ) {
147 part3->loc = part1->loc;
148 part3->ori = part1->ori;
149 part3->view = part1->view;
150 part3->fom[0] = part1->fom[0];
151 }
152 }
153 found = 0;
154 }
155 }
156 }
157 else {
158 for ( rec1 = project1->rec, rec2=project2->rec ; rec1 && rec2; rec1=rec1->next, rec2=rec2->next ) {
159 for ( part1 = rec1->part; part1 ; part1 = part1->next ) {
160 // find the same particle in the other file (based on ID)
161 for ( part2 = rec2->part; part2 ; part2 = part2->next ) {
162 if ( part1->id == part2->id ) {
163 part=particle_add(&project->rec->part, part1->id);
164 //default values from particle 1
165 part->loc = part1->loc;
166 part->ori = part1->ori;
167 part->view = part1->view;
168 part->fom[0] = part1->fom[0];
169
170 // calculate differences for selected particles
171
172 if ( part1->sel > 0 ) {
173 if ( locdiff ) { part->loc = part1->loc - part2->loc; }
174 if ( fomdiff ) { part->fom[0] = part1->fom[0] - part2->fom[0]; }
175
176 view1 = View(part1->view[0],part1->view[1],part1->view[2],part1->view.angle());
177 view2 = View(part2->view[0],part2->view[1],part2->view[2],part2->view.angle());
178
179 view1 = view1.backward();
180 view2 = view2.backward();
181
182 locresid = part2->loc.distance(part1->loc);
183
184 part1_view = Vector3<double>(view1[0], view1[1], view1[2]);
185 part2_view = Vector3<double>(view2[0], view2[1], view2[2]);
186
187 angleresid = part1_view.angle(part2_view);
188 angleresid = angleresid *180.0/M_PI;
189
190 //angleresid = view_difference((part1->view).backward(),(part2->view).backward())*180.0/M_PI;
191
192 alpha1 = (view1.angle()*180/M_PI);
193 alpha2 = (view2.angle()*180/M_PI);
194
195
196 // warning C3 symmetry assumed here
197 while ( alpha1 < 0 ) { alpha1 += 120; }
198 while ( alpha2 < 0 ) { alpha2 += 120; }
199
200 while ( alpha1 >= 120 ) { alpha1 -= 120; }
201 while ( alpha2 >= 120 ) { alpha2 -= 120; }
202
203 //while ( alpha1 < 0 ) { alpha1 += 360; }
204 //while ( alpha2 < 0 ) { alpha2 += 360; }
205
206 alpharesid = fabs(alpha1 - alpha2);
207 if ( (120 - fabs(alpha1 - alpha2)) < alpharesid ) { alpharesid = 120 - fabs(alpha1 - alpha2); }
208 //if ( (360 - fabs(alpha1 - alpha2)) < alpharesid ) { alpharesid = 360 - fabs(alpha1 - alpha2); }
209
210 if ( verbose & VERB_PROCESS ) { cout << "Part1 ID: " << part1->id << "\tPart2 ID: " << part2->id << tab << locresid << tab << angleresid << tab << alpharesid << tab << alpha1 << tab << alpha2 << endl; }
211
212 if ( ( locdiffthr < 0 || locresid <= locdiffthr ) && ( anglediffthr < 0 || angleresid <= anglediffthr )) {
213 npart++;
214 sumlocresid2 += locresid * locresid;
215 sumangleresid2 += angleresid * angleresid;
216 sumalpharesid2 += alpharesid * alpharesid;
217 }
218 else {
219 if ( verbose & VERB_PROCESS ) { cout << "Skipping particle " << part1->id << endl; }
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227
228 if ( printlocdiff ) { cout << "Location RMSD\t" << sqrt(sumlocresid2/npart) << "\tParticles: " << npart << endl; }
229 if ( printanglediff ) { cout << "Angle RMSD:\t" << sqrt(sumangleresid2/npart) << "\tParticles: " << npart << endl; }
230 if ( printalphadiff ) { cout << "Alpha RMSD:\t" << sqrt(sumalpharesid2/npart) << "\tParticles: " << npart << endl; }
231
232 if ( verbose & VERB_PROCESS )
233 project_show_selected(project);
234
235 // Write an output parameter file if a name is given
236 if ( outfile.length() ) {
237 project_update_comment(project, argc, argv);
238 write_project(outfile, project, 0, 0);
239 }
240
241 project_kill(project1);
242 project_kill(project2);
243 project_kill(project);
244
245 if ( verbose & VERB_TIME )
246 timer_report(ti);
247
248 bexit(0);
249 }
250
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
Bparticle::id
int id
Definition: mg_processing.h:92
rwmg.h
Header file for reading and writing micrograph parameters.
Bstring::real
double real()
Definition: Bstring.cpp:545
use
const char * use[]
Definition: jpartdif.cpp:27
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
Bparticle::view
View view
Definition: mg_processing.h:101
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
mg_particle_select.h
Select particles.
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Breconstruction
Definition: mg_processing.h:280
Boption::tag
Bstring tag
Definition: options.h:29
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:102
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
Matrix.h
Generalized matrix class.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
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
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
project_show_selected
long project_show_selected(Bproject *project)
Shows the selected particles in a project.
Definition: mg_processing.cpp:2446
mg_multiple.h
Selection of single particle parameters from multiple files for classification.
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bparticle::sel
long sel
Definition: mg_processing.h:103
M_PI
#define M_PI
Definition: utilities.h:59
Boption
A class for a command line input option.
Definition: options.h:26
Vector3::angle
double angle(Vector3< T2 > &v)
Definition: Vector3.h:257
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
View::backward
View backward()
Definition: View.h:115
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
project_create
Bproject * project_create(int nmg, int nrec)
Creates a micrograph processing project parameter structure.
Definition: mg_processing.cpp:47
Boption::next
Boption * next
Definition: options.h:28
Bparticle
Definition: mg_processing.h:89
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
verbose
int verbose
Vector3< double >
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
View::angle
double angle()
Definition: View.h:95
Vector3.h
Class for 3-value vectors.
View
Definition: View.h:26
main
int main(int argc, char **argv)
Definition: jpartdif.cpp:53
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
mg_processing.h
Header file for micrograph processing.
options.h
Header file for option handlers.
View.h
View object.
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
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:333