Bsoft  2.1.0
Bernard's software package
jviews.cpp
Go to the documentation of this file.
1 
26 #include "rwstar.h"
27 #include "rwmg.h"
28 #include "utilities.h"
29 #include "options.h"
30 #include "timer.h"
31 #include "mg_processing.h"
32 #include "mg_extract.h"
33 #include "mg_subtomo.h"
34 #include "spline.h"
35 #include "random_numbers.h"
36 
37 #include <fstream>
38 
39 // Declaration of global variables
40 extern int verbose; // Level of output to the screen
41 
52 
53  ofstream fpdb;
54  Matrix3 mat;
55  Vector3<double> shift;
56 
57  fpdb.open(filename.c_str());
58  if ( fpdb.fail() ) return 0;
59 
60  for ( ; part; part = part->next ) {
61 
62  mat = (part->view.backward()).matrix();
63  shift = (part->loc - part->ori) * sampling;
64 
65  for ( int i=0; i<3; i++ )
66  fpdb << fixed << "REMARK 350 BIOMT" << i+1 << setw(4) << part->id
67  << setprecision(6) << setw(10) << mat[i][0]
68  << setw(10) << mat[i][1]
69  << setw(10) << mat[i][2]
70  << setprecision(5) << setw (15) << shift[i] << endl;
71  }
72 
73  fpdb.close();
74 
75  return 1;
76 }
77 
78 int cmm_views(Bstring& filename, Bparticle* part, Vector3<double> sampling,
79  long part_sel, double fom_cutoff, double colorfom_min,
80  double colorfom_max, RGB<double> color, double diameter, double length, double thickness)
81 {
82  ofstream fcmm;
83 
84  fcmm.open(filename.c_str());
85  if ( fcmm.fail() ) return 0;
86 
87  if ( verbose & VERB_PROCESS ) {
88  cout << endl << "Creating a Chimera marker file. Only the first datablock is used." << endl;
89  }
90 
91  Bstring id = filename.base();
92  fcmm << "<marker_set name=\"" << id << "\">" << endl;
93 
94  int n(0);
95  double fom;
96  View view;
97  Vector3<double> loc;
98 
99 // cout << part_sel << tab << fom_cutoff << endl;
100 
101  for ( ; part; part = part->next ) {
102 
103  fom = part->fom[0];
104  view = part->view;
105  view = view.backward();
106  view.normalize();
107  loc = part->loc * sampling;
108 
109 // cout << part->id << tab << part->sel << tab << fom << endl;
110 
111  if ( ((part_sel < 0) && (fom_cutoff < 0 )) || (part->sel == part_sel) || ((fom_cutoff > 0) && (fom >= fom_cutoff)) ) {
112 
113  if ( colorfom_min >= 0 ) {
114  // truncate between min and max
115  if ( fom < colorfom_min ) { fom = colorfom_min; }
116  if ( fom > colorfom_max ) { fom = colorfom_max; }
117 
118  // scale between 0 and 1
119  fom = fom - colorfom_min;
120  fom = fom / (colorfom_max - colorfom_min);
121 
122  // calculate rgb from the fom value
123  color[0] = fom;
124  color[1] = 0;
125  color[2] = 1 - fom;
126  }
127 
128  // put marker at the origin
129  fcmm << "<marker id=\"" << part->id << "99999\" x=\"" << loc[0]
130  << "\" y=\"" << loc[1]
131  << "\" z=\"" << loc[2]
132  << "\" r=\"" << color.r() << "\" g=\"" << color.g() << "\" b=\"" << color.b()
133  << "\" radius=\"" << thickness/2 << "\"/>" << endl;
134 
135  // marker at the end of the current view vector
136  fcmm << "<marker id=\"" << part->id << "\" x=\"" << loc[0] + view[0] * length
137  << "\" y=\"" << loc[1] + view[1] * length
138  << "\" z=\"" << loc[2] + view[2] * length
139  << "\" r=\"" << color.r() << "\" g=\"" << color.g() << "\" b=\"" << color.b()
140  << "\" radius=\"" << diameter/2 << "\"/>" << endl;
141 
142  //link this point to the origin
143  fcmm << "<link id1=\"" << part->id << "\" id2=\"" << part->id
144  << "99999\" r=\"" << color.r() << "\" g=\"" << color.g() << "\" b=\"" << color.b()
145  << "\" radius=\"" << thickness/2 << "\"/>" << endl;
146 
147  n++;
148  }
149 
150  }
151 
152  fcmm << "</marker_set>" << endl;
153 
154  fcmm.close();
155 
156  cout << n << " markers written to " << filename << endl;
157 
158  return n;
159 }
160 
161 // Usage assistance
162 const char* use[] = {
163 " ",
164 "Usage: jviews [options] [input.star]",
165 "------------------------------------",
166 "Creates and modifies particle views.",
167 " ",
168 "Parameters:",
169 "-Even Output evenly distributed views.",
170 "-Asymmetricunit Output all views within asymmetric unit.",
171 "-Grid 10 Output all views within angular distance from a given reference view.",
172 "-Related Output all symmetry related views for a given reference view and symmetry.",
173 "-Radial 75,75,75 Generate a view vector for each particle extending from the given point.",
174 "-Top 200 Assing one of the two top views (up/down) for each particle, depending if the particle is above or below the chosen Z slice.",
175 "-Segment Generate a view vector for each particle extending from the closest point on a line segment (defined as a filament in the input.star).",
176 "-Filament 100,10,5 Generate views covering a filament with a given radius, helical rise & twist (use with option -symmetry)",
177 " and input.star defining the ends of a filament.",
178 "-Random 100 Generate a number of random views.",
179 "-randomizealpha Randomize the angle around view vector (alpha).",
180 "-symmetry C10 Symmetry to use (default: C1 symmetry).",
181 "-recfile 3d.map Associate views with this reconstruction filename.",
182 "-angle 2 Angular sampling stepsize for theta and phi (default: 45 degrees).",
183 "-radius 75 Place particles views at given radius (default 0).",
184 "-shift 5 Shift particles by given amount along the view vectors (default 0).",
185 "-verbose 7 Verbosity of output.",
186 "-reference 0,0.618,1,0 Reference view (dafault: 0,0,1,0)",
187 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
188 "-origin 110,50,44 View origin (default: 0,0,0).",
189 "-discardz 20 Discard views with Z locations further from the Z origin (pixels).",
190 "-select 1 Process only particles with this selection number (default: all).",
191 "-invert Invert views in outputfile.",
192 " ",
193 "Chimera parameters:",
194 "-diameter 5 Chimera marker diameter (default: 2)",
195 "-length 100 Chimera link length (default: 10).",
196 "-thickness 5 Chimera link thickness (default: 2)",
197 "-color 0,0,1 Chimera marker & link color in RGB (default: 1,1,1).",
198 "-fomcolor 0.2,0.3 Chimera marker & link coloring range from blue to red based on particle FOM.",
199 " ",
200 "Output:",
201 "-output output.star Output parameter file",
202 "-cmm output.cmm Output Chimera marker file.",
203 "-pdb output.pdb Output PDB file with BIOMT matrixes.",
204 " ",
205 NULL
206 };
207 
208 int main(int argc, char **argv)
209 {
210  // Initialize variables
211  int mode(0);
212  int set_origin(0);
213  int part_sel(-1);
214  int randomize_alpha(0);
215  int nviews(0);
216  int invert(0);
217  int shift(0);
218  int locz(0);
219  double filament_ang(0);
220  double filament_rise(0);
221  Vector3<double> sampling(1,1,1);
222  Bstring symmetry_string = "C1";
223  double angle(M_PI_4);
224  Bstring outcmm;
225  Bstring outstar;
226  Bstring outpdb;
227  Bstring recfile;
228 
229  double length(10);
230  double angle_limit(0);
231  double diameter(2);
232  double thickness(2);
233  double fom_cutoff(-1);
234  double colorfom_min(-1), colorfom_max(-1);
235  double rad(0);
236  double shiftparticle(0);
237  double discardz(-1);
238  Vector3<double> origin(0,0,0);
239  Vector3<double> vieworigin(0,0,0);
240  Bproject* project = NULL;
241  Breconstruction* rec = NULL;
242  Bparticle* part = NULL;
243  Bparticle* part2 = NULL;
244  Bparticle* part_original = NULL;
245  RGB<double> color(1,1,1);
246  Vector3<double> loc;
247  Vector3<double> loc1;
248  Vector3<double> loc2;
249  View view;
250  View view_inv;
251  View std_view;
252  View ref_view;
253  View* v;
254  Quaternion q1, q2;
255 
256  int i, optind;
257  Boption* option = get_option_list(use, argc, argv, optind);
258  Boption* curropt;
259  for ( curropt = option; curropt; curropt = curropt->next ) {
260 
261  if ( curropt->tag == "Even") { mode = 1; }
262 
263  if ( curropt->tag == "Asymmetricunit") { mode = 1; }
264 
265  if ( curropt->tag == "Related") { mode = 2; }
266  if ( curropt->tag == "symmetry") {
267  symmetry_string = curropt->symmetry_string();
268  }
269  if ( curropt->tag == "Random") {
270  if ( ( nviews = curropt->value.integer() ) < 1 ) {
271  cerr << "-Random: A number of views must be specified!" << endl;
272  bexit(-1);
273  }
274  else {
275  mode = 3;
276  }
277  }
278  if ( curropt->tag == "Radial") {
279  vieworigin = curropt->origin();
280  mode = 4;
281  }
282  if ( curropt->tag == "Grid") {
283  if ( ( angle_limit = curropt->value.real() ) < 0.001 ) {
284  cerr << "-Grid: An angular distance must be specified!" << endl;
285  bexit(-1);
286  }
287  else {
288  angle_limit *= M_PI/180.0;
289  mode = 5;
290  }
291  }
292  if ( curropt->tag == "Filament") {
293  if ( curropt->values(shiftparticle, filament_rise, filament_ang) < 3 ) {
294  cerr << "-Filament: Filament radius, angular spacing and angular raise must be specified!" << endl << endl;
295  bexit(-1);
296  shift = 1;
297  }
298  else {
299  filament_ang *= M_PI/180.0;
300  mode = 6;
301  }
302  }
303  if ( curropt->tag == "Segment") {
304  mode = 7;
305  }
306  if ( curropt->tag == "Top") {
307  if ( ( locz = curropt->value.integer() ) < 0 ) {
308  cerr << "-Top: A value for the Z slice must be specified!" << endl << endl;
309  bexit(-1);
310  }
311  else {
312  mode = 8;
313  }
314  }
315  if ( curropt->tag == "recfile")
316  recfile = curropt->filename();
317  if ( curropt->tag == "radius") {
318  if ( ( rad = curropt->value.real() ) < 1 ) {
319  cerr << "-radius: A value for radius must be specified!" << endl << endl;
320  bexit(-1);
321  }
322  else {
323  if ( rad < 0 ) { rad = 0; }
324  }
325  }
326  if ( curropt->tag == "shift") {
327  if ( ( shiftparticle = curropt->value.real() ) < 0.001 ) {
328  cerr << "-shift: A value for shift must be specified!" << endl << endl;
329  bexit(-1);
330  }
331  else {
332  shift = 1;
333  }
334  }
335  if ( curropt->tag == "sampling")
336  sampling = curropt->scale();
337  if ( curropt->tag == "origin") {
338  origin = curropt->origin();
339  set_origin = 1;
340  }
341  if ( curropt->tag == "reference")
342  ref_view = curropt->view();
343 
344  if ( curropt->tag == "length") {
345  if ( ( length = curropt->value.real() ) < 0.001 ) {
346  cerr << "-length: A value for length must be specified!" << endl << endl;
347  bexit(-1);
348  }
349  }
350  if ( curropt->tag == "angle") {
351  if ( ( angle = curropt->value.real() ) < 0.001 ) {
352  cerr << "-angle: An angular stepsize must be specified!" << endl << endl;
353  bexit(-1);
354  }
355  else {
356  angle *= M_PI/180.0;
357  }
358  }
359  if ( curropt->tag == "diameter") {
360  if ( ( diameter = curropt->value.real() ) < 0.001 ) {
361  cerr << "-diameter: A value for diameter must be specified!" << endl << endl;
362  bexit(-1);
363  }
364  else {
365  if ( diameter < 1 ) { diameter = 1; }
366  }
367  }
368  if ( curropt->tag == "thickness") {
369  if ( ( thickness = curropt->value.real() ) < 0.001 ) {
370  cerr << "-thickness: A value for thickness must be specified!" << endl << endl;
371  bexit(-1);
372  }
373  else {
374  if ( thickness < 1 ) { thickness = 1; }
375  }
376  }
377  if ( curropt->tag == "color") {
378  if ( curropt->values(color[0], color[1], color[2]) < 3 ) {
379  cerr << "-color: Three values for color must be specified!" << endl << endl;
380  bexit(-1);
381  }
382  }
383  if ( curropt->tag == "fomcolor") {
384  if ( curropt->values(colorfom_min, colorfom_max) < 2 ) {
385  cerr << "-fomcolor: Two values for FOM range must be specified!" << endl << endl;
386  bexit(-1);
387  }
388  }
389  if ( curropt->tag == "output")
390  outstar = curropt->filename();
391  if ( curropt->tag == "cmm")
392  outcmm = curropt->filename();
393  if ( curropt->tag == "pdb")
394  outpdb = curropt->filename();
395  if ( curropt->tag == "select") {
396  if ( ( part_sel = curropt->value.integer() ) < 1 ) {
397  cerr << "-select: A selection number must be specified!" << endl << endl;
398  bexit(-1);
399  }
400  }
401  if ( curropt->tag == "fom") {
402  if ( ( fom_cutoff = curropt->value.real() ) < 0.001 ) {
403  cerr << "-fom: A threshold value must be specified!" << endl << endl;
404  bexit(-1);
405  }
406  }
407  if ( curropt->tag == "invert")
408  invert = 1;
409  if ( curropt->tag == "randomizealpha")
410  randomize_alpha = 1;
411  }
412  option_kill(option);
413 
414  double ti = timer_start();
415 
416  // Read a parameter file or create a new project
417  Bstring* file = NULL;
418  if (argv[optind]) {
419  string_add(&file, argv[optind]);
420  if ( file->contains(".star") || file->contains(".STAR") ) {
421  project = read_project(file);
422  }
423  } else {
424  project = project_create(0,1);
425  rec=project->rec;
426  part = particle_add(&rec->part, 1);
427  part->view = std_view;
428  part->ori = origin;
429  part->loc = origin;
430  }
431  string_kill(file);
432 
433  ref_view.normalize();
434 
435  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
436  Matrix3 mat;
437  Matrix3 mat2;
438  Quaternion quat;
439  Quaternion quat_inv;
440  Quaternion quat_ref;
441 
442  // Views withing an asymmetric unit
443  if ( mode == 1 ) {
444 
445  View* allviews;
446 
447  if ( verbose & VERB_PROCESS ) {
448  cout << endl << "Creating all views within asymmetric unit:" << endl;
449  }
450 
451  allviews = asymmetric_unit_views(sym, angle, angle, 1);
452 
453  rec=project->rec;
454  i=1;
455  part_original = rec->part;
456  rec->part = NULL;
457 
458  for ( v=allviews; v; v=v->next ) {
459  view = *v;
460 
461  part = particle_add(&rec->part, i);
462  part->loc = part_original->loc;
463  part->ori = part_original->ori;
464  part->view = view.backward();
465  part->sel = part_original->sel;
466  part->fom[0] = part_original->fom[0];
467  part->fpart = part_original->fpart;
468 
469  i++;
470  }
471  }
472 
473  // All symmetry related views
474  if ( mode == 2 ) {
475 
476  View* allviews;
477 
478  if ( verbose & VERB_PROCESS ) {
479  cout << endl << "Creating all symmetry related views:" << endl;
480  }
481 
482  for ( rec=project->rec; rec; rec=rec->next ) {
483  i=1;
484  part_original= rec->part;
485  rec->part = NULL;
486 
487  for ( part = part_original; part ; part=part->next ) {
488 
489  mat2 = (ref_view.matrix()).transpose();
490 
491  view = part->view;
492  view.normalize();
493 
494  if ( verbose & VERB_PROCESS ) {
495  cout << "Using the reference view: " << view << endl;
496  }
497 
498  allviews = symmetry_get_all_views(sym, view);
499 
500  for ( v=allviews; v; v=v->next ) {
501  mat = (v->matrix()).transpose();
502  mat = mat * mat2;
503  mat = mat.transpose();
504  view = View(mat);
505 
506  part2 = particle_add(&rec->part, i);
507  part2->loc = part->loc;
508  part2->ori = part->ori;
509  part2->view = view;
510  part2->sel = part->sel;
511  part2->fom[0] = part->fom[0];
512  part2->fpart = part->fpart;
513 
514  if ( verbose & VERB_PROCESS ) {
515  cout << tab << view << endl;
516  }
517 
518  i++;
519  }
520  }
521  }
522  }
523 
524  // Random views
525  if ( mode == 3 ) {
526 
527  View* allviews;
528 
529  rec=project->rec;
530  i=1;
531  part_original = rec->part;
532  rec->part = NULL;
533 
534  if ( verbose & VERB_PROCESS ) {
535  cout << endl << "Creating " << nviews << " random views:" << endl;
536  }
537 
538  allviews = random_views(nviews);
539 
540  for ( v=allviews; v; v=v->next ) {
541  view = *v;
542 
543  if ( verbose & VERB_PROCESS ) {
544  cout << view << endl;
545  }
546 
547  part = particle_add(&rec->part, i);
548  part->loc = part_original->loc;
549  part->ori = part_original->ori;
550  part->view = view;
551  part->sel = part_original->sel;
552  part->fom[0] = part_original->fom[0];
553  part->fpart = part_original->fpart;
554 
555  i++;
556  }
557  }
558 
559  // Views extending radially from a given point
560  if ( mode == 4 ) {
561 
562  if ( verbose & VERB_PROCESS ) {
563  cout << endl << "Assigning views extending radially from the given point." << endl;
564  }
565 
566  for ( rec=project->rec; rec; rec=rec->next ) {
567  i=1;
568 
569  for ( part=rec->part; part; part=part->next ) {
570 
571  view = View(part->loc[0] - vieworigin[0], part->loc[1] - vieworigin[1],
572  part->loc[2] - vieworigin[2], 0);
573 
574  view.normalize();
575  view = view.backward();
576 
577  if ( verbose & VERB_PROCESS ) {
578  cout << view << endl;
579  }
580 
581  part->view = view;
582 
583  i++;
584  }
585  }
586  }
587 
588  // Views within specified angular distance
589  if ( mode == 5 ) {
590 
591  View* allviews;
592 
593  if ( verbose & VERB_PROCESS ) {
594  cout << endl << "Creating all views within specified angular distance:" << endl << endl;
595  }
596 
597  for ( rec=project->rec; rec; rec=rec->next ) {
598  i=1;
599  part_original = rec->part;
600  rec->part = NULL;
601 
602  for ( part=part_original; part; part=part->next ) {
603  view = part->view;
604  view.normalize();
605 
606  if ( verbose & VERB_PROCESS ) {
607  cout << "Using the reference view: " << view << endl;
608  }
609 
610  allviews = views_within_limits(view, angle, angle, 1, angle_limit, 0);
611 
612  for ( v=allviews; v; v=v->next ) {
613  view = *v;
614 
615  part2 = particle_add(&rec->part, i);
616  part2->loc = part->loc;
617  part2->ori = part->ori;
618  part2->view = view;
619  part2->sel = part->sel;
620  part2->fom[0] = part->fom[0];
621  part2->fpart = part->fpart;
622 
623  if ( verbose & VERB_PROCESS ) {
624  cout << view << endl;
625  }
626 
627  i++;
628  }
629  }
630  }
631  }
632 
633  // Views for a filamentous object
634  if ( mode == 6 ) {
635 
636  View* allviews;
637  Bfilament fil;
638  Bfilnode node;
639 
640  if ( verbose & VERB_PROCESS ) {
641  cout << endl << "Creating all views for a filamentous object:" << endl;
642  }
643 
644  mat2 = View(0,1,0,0).matrix();
645 
646  for ( rec=project->rec; rec; rec=rec->next ) {
647  i=1;
648  part_original = filaments_to_particles(rec->fil, sampling,
649  Vector3<double>(filament_rise,filament_rise,filament_rise),
650  filament_rise, filament_rise, filament_ang);
651 
652  rec->part = NULL;
653 
654  for ( part=part_original; part; part=part->next ) {
655  allviews = symmetry_get_all_views(sym, part->view);
656 
657  for ( v=allviews; v; v=v->next ) {
658 
659  mat = v->matrix();
660  mat = mat.transpose() * mat2.transpose();
661  mat = mat.transpose();
662  view = View(mat);
663 
664  part2 = particle_add(&rec->part, i);
665  part2->loc = part->loc;
666  part2->ori = part->ori;
667  part2->view = view;
668 
669  if ( verbose & VERB_PROCESS ) { cout << view << endl; }
670  i++;
671  }
672  }
673  }
674 
675  }
676 
677  // Views extending from the closest point on a line segment
678  if ( mode == 7 ) {
679 
680  Bfilnode node;
681  Vector3<double> point1;
682  Vector3<double> point2;
683 
684  for ( rec=project->rec; rec; rec=rec->next ) {
685  i=1;
686 
687  point1 = rec->fil->node->loc;
688  point2 = rec->fil->node->next->loc;
689 
690  if ( verbose & VERB_PROCESS ) {
691  cout << endl << "Assigning views extending from the closest point on a line segment from " << point1 << " to " << point2 << endl;
692  }
693 
694  for ( part=rec->part; part; part=part->next ) {
695 
696  // calculate the closest point on the line segment
697  vieworigin = closest_point_line(part->loc, point1, point2);
698 
699  cout << endl << "Closest point:\t" << vieworigin << endl;
700 
701  view = View(part->loc[0] - vieworigin[0], part->loc[1] - vieworigin[1], part->loc[2] - vieworigin[2], 0);
702 
703  view.normalize();
704  view = view.backward();
705 
706  if ( verbose & VERB_PROCESS ) {
707  cout << view << endl;
708  }
709 
710  part->view = view;
711 
712  i++;
713  }
714  }
715 
716  }
717 
718  // Top views (up / down)
719  if ( mode == 8 ) {
720  for ( rec=project->rec; rec; rec=rec->next ) {
721  for ( part=rec->part; part; part=part->next ) {
722  if ( part->loc[2] < locz ) { part->view = View(0,0,-1,0); }
723  else { part->view = View(0,0,1,0); }
724  }
725  }
726  }
727 
728  // Randomize alpha
729  if ( randomize_alpha ) {
730  double irm = 2.0/get_rand_max();
731  for ( rec=project->rec; rec; rec=rec->next ) {
732  for ( part=rec->part; part; part=part->next ) {
733  if ( verbose & VERB_PROCESS ) {
734  cout << endl << "Original view" << endl;
735  cout << part->view << endl;
736  }
737  part->view = View(part->view[0],part->view[1],part->view[2],M_PI*(random()*irm - 1));
738  if ( verbose & VERB_PROCESS ) {
739  cout << endl << "View with random alpha" << endl;
740  cout << part->view << endl;
741  }
742  }
743  }
744  }
745 
746  // Invert views
747  if ( invert ) {
748  for ( rec=project->rec; rec; rec=rec->next ) {
749  for ( part=rec->part; part; part=part->next ) {
750  if ( verbose & VERB_PROCESS ) {
751  cout << endl << "Original view" << endl;
752  cout << part->view << endl;
753  }
754  part->view = part->view.backward();
755  if ( verbose & VERB_PROCESS ) {
756  cout << endl << "Inverted view" << endl;
757  cout << part->view << endl;
758  }
759  }
760  }
761  }
762 
763  // Shift particles along view vectors to place them one given radius
764  if ( rad > 0 ) {
765  for ( rec=project->rec; rec; rec=rec->next ) {
766  for ( part=rec->part; part; part=part->next ) {
767  view = part->view.backward();
768  view.normalize();
769  origin = part->ori;
770  part->loc = Vector3<double>((origin[0] + rad * view[0]),
771  (origin[1] + rad * view[1]),
772  (origin[2] + rad * view[2]));
773  }
774  }
775  }
776 
777  // Shift particles along view vectors
778  if ( shift > 0 ) {
779  for ( rec=project->rec; rec; rec=rec->next ) {
780  for ( part=rec->part; part; part=part->next ) {
781  view=part->view;
782  view.normalize();
783  view = view.backward();
784  loc = part->loc;
785  part->loc = Vector3<double>((loc[0] + shiftparticle * view[0]),
786  (loc[1] + shiftparticle * view[1]),
787  (loc[2] + shiftparticle * view[2]));
788  }
789  }
790  }
791 
792 
793  // Set origins
794  if ( set_origin == 1 ) {
795  if ( verbose & VERB_PROCESS ) { cout << endl << "Setting particle origins." << endl; }
796  for ( rec=project->rec; rec; rec=rec->next ) {
797  for (part = rec->part; part; part=part->next ) { part->ori = origin; }
798  }
799  }
800 
801  // Dicard particles which have Z locations too far from the central slize
802  if ( discardz > 0 ) {
803  for ( rec=project->rec; rec; rec=rec->next ) {
804  for ( part=rec->part; part; part=part->next ) {
805  view=part->view;
806  origin = part->ori;
807  loc = part->loc;
808  if (loc[2] < (origin[2] - discardz)) {part->sel = 0;}
809  if (loc[2] > (origin[2] + discardz)) {part->sel = 0;}
810  }
811  }
812  }
813 
814  if ( outcmm.length() )
815  if ( !cmm_views(outcmm, project->rec->part, sampling,
816  part_sel, fom_cutoff, colorfom_min,
817  colorfom_max, color, diameter, length, thickness) )
818  cerr << "Cannot open cmm file for writing!" << endl << endl;
819 
820  if ( outpdb.length() )
821  if ( !pdb_matrices_from_particles(project->rec->part, sampling, outpdb) )
822  cerr << "Cannot open PDB file for writing!" << endl << endl;
823 
824  if ( recfile.length() ) {
825  for ( rec=project->rec; rec; rec=rec->next ) {
826  rec->frec = recfile;
827  }
828  }
829 
830  if ( outstar.length() ) {
831  write_project(outstar, project, 0, 0);
832  }
833 
835 
836  if ( verbose & VERB_TIME )
837  timer_report(ti);
838 
839  bexit(0);
840 }
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
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
spline.h
Header file for spline interpolation.
View::next
View * next
Definition: View.h:28
Breconstruction::fil
Bfilament * fil
Definition: mg_processing.h:308
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:442
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Quaternion
Definition: Quaternion.h:25
M_PI_4
#define M_PI_4
Definition: utilities.h:69
Bparticle::view
View view
Definition: mg_processing.h:102
Bfilament
Definition: mg_processing.h:129
main
int main(int argc, char **argv)
Definition: jviews.cpp:208
Bstring
Definition: Bstring.h:29
pdb_matrices_from_particles
int pdb_matrices_from_particles(Bparticle *part, Vector3< double > sampling, Bstring &filename)
Generates PDB file matrices from particle views and locations.
Definition: jviews.cpp:51
Bparticle
Definition: mg_processing.h:90
Matrix3::transpose
Matrix3 transpose() const
Definition: Matrix3.h:268
filaments_to_particles
Bparticle * filaments_to_particles(Bfilament *filaments, Vector3< double > pixel_size, Vector3< long > box_size, double boxing_interval, double rise, double angle)
Converts filaments to sets of particles.
Definition: mg_extract.cpp:1113
Bstring::integer
long integer()
Definition: Bstring.cpp:547
random_views
View * random_views(int nviews)
Calculates a set of random views.
Definition: View.cpp:147
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
random_numbers.h
Header file for functions for creating random images.
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
RGB
Definition: Color.h:24
asymmetric_unit_views
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
Definition: symmetry.cpp:564
View
Definition: View.h:26
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Boption::view
View view()
Definition: options.h:247
length
double length(vector< T > v)
Definition: Vector3.h:530
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bsymmetry
Definition: symmetry.h:38
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
project_create
Bproject * project_create(int nmg, int nrec)
Creates a micrograph processing project parameter structure.
Definition: mg_processing.cpp:48
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
Matrix3
Definition: Matrix3.h:18
rwmg.h
Header file for reading and writing micrograph parameters.
View::backward
View backward()
Definition: View.h:118
cmm_views
int cmm_views(Bstring &filename, Bparticle *part, Vector3< double > sampling, long part_sel, double fom_cutoff, double colorfom_min, double colorfom_max, RGB< double > color, double diameter, double length, double thickness)
Definition: jviews.cpp:78
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
RGB::b
Type b()
Definition: Color.h:47
Boption::value
Bstring value
Definition: options.h:30
timer.h
Utilities for timing functions.
Bfilament::node
Bfilnode * node
Definition: mg_processing.h:133
Bproject
Definition: mg_processing.h:336
Bparticle::sel
long sel
Definition: mg_processing.h:104
View::normalize
double normalize()
Definition: View.h:109
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:233
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
views_within_limits
View * views_within_limits(View theview, double theta_step, double phi_step, double alpha_step, double view_angle_limit, double alpha_angle_limit)
Generates a list of views within an angular distance from the input view.
Definition: View.cpp:207
mg_extract.h
Header file for functions to extract particles from micrographs.
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
Bfilnode::next
Bfilnode * next
Definition: mg_processing.h:117
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:221
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
closest_point_line
Vector3< double > closest_point_line(Vector3< double > point, Vector3< double > endpoint1, Vector3< double > endpoint2)
Calculates the closest point on a line segment from a given point.
Definition: mg_subtomo.cpp:755
mg_processing.h
Header file for micrograph processing.
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
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
Bfilnode::loc
Vector3< double > loc
Definition: mg_processing.h:119
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
Bstring::base
Bstring base()
Definition: Bstring.cpp:516
rwstar.h
A header file for STAR format files.
irm
double irm(1.0L/get_rand_max())
RGB::r
Type r()
Definition: Color.h:45
View::matrix
Matrix3 matrix()
Definition: View.h:153
get_rand_max
long get_rand_max()
Finds the maximum random number for a system.
Definition: random_numbers.cpp:22
Bfilnode
Definition: mg_processing.h:116
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
use
const char * use[]
Definition: jviews.cpp:162
mg_subtomo.h
Header file for functions finding particles (subtomograms) in a tomogram.
verbose
int verbose
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bparticle::id
int id
Definition: mg_processing.h:93
RGB::g
Type g()
Definition: Color.h:46
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284