Bsoft  2.1.0
Bernard's software package
tcltk_bmg.cpp
Go to the documentation of this file.
1 
9 // Tk must be included before anything else to remedy symbol conflicts
10 #include <tk.h>
11 
12 //#include "tcltk_bmg.h"
13 #include "tcltk_bbox.h"
14 #include "tcltk_bfil.h"
15 #include "tcltk_bhelix.h"
16 #include "tcltk_bxtal.h"
17 #include "tcltk_bmarker.h"
18 #include "mg_processing.h"
19 #include "mg_multiple.h"
20 #include "mg_img_proc.h"
21 #include "mg_select.h"
22 #include "mg_ctf.h"
23 #include "mg_ctf_fit.h"
24 #include "mg_tomography.h"
25 #include "mg_tags.h"
26 #include "rwmg.h"
27 #include "rwimg.h"
28 #include "scatter.h"
29 #include "linked_list.h"
30 #include "timer.h"
31 #include "utilities.h"
32 
33 #include <sys/stat.h>
34 
35 // Declaration of global variables
36 extern int verbose; // Level of output to the screen
37 extern Bproject* project;
38 extern Bimage* imglist;
39 
40 // Internal function prototypes
41 Tcl_Obj* do_get(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
42 int do_set(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
43 Tcl_Obj* do_rps(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
44 Tcl_Obj* do_lambda(int objc, Tcl_Obj *CONST objv[]);
45 Tcl_Obj* do_ctf_fit(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
46 Tcl_Obj* do_mg_sort(Bproject* project, int objc, Tcl_Obj *CONST objv[]);
47 
138 int project_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
139 {
140 // verbose = 967;
141 
142  Tcl_ResetResult(interp);
143 
144  if ( objc < 2 ) {
145  Tcl_AppendResult(interp, "wrong # args", (char *)NULL);
146  return TCL_ERROR;
147  }
148 
149  Bstring action = Tcl_GetStringFromObj(objv[1], NULL);
150  if ( verbose & VERB_DEBUG )
151  cout << "DEBUG BmgCmd: Action: " << action << " (" << action.length() << ")" << endl;
152 
153  Tcl_Obj* returnObj = Tcl_NewObj();
154 
155  char string[128] = " ";
156  Tcl_SetStringObj(returnObj, string, 1);
157 
158 // int nmg(1), nrec(0);
159 // int type(1);
160  Bstring imgtype("mg");
161  Bstring filename;
162  Bstring* files = NULL;
163  Bfield* field = NULL;
164  Bmicrograph* mg = NULL;
165  Breconstruction* rec = NULL;
166  Bparticle* part = NULL;
167 
168  time_t ti = time(NULL);
169 
170 // if ( project ) cout << "Flag active = %d\n", project->select);
171 
172  if ( action == "create" ) {
173  if ( objc > 2 ) filename = Tcl_GetStringFromObj(objv[2], NULL);
174  if ( objc > 3 ) imgtype = Tcl_GetStringFromObj(objv[3], NULL);
175  if ( imglist ) {
177  } else {
178 // string_add(&files, filename);
179 // project = project_create_from_images(files, imgtype);
180  project = project_create_from_images(&filename, imgtype);
181 // string_kill(files);
182  }
183  } else if ( action == "exists" ) {
184  if ( project ) Tcl_SetIntObj(returnObj, 1);
185  else Tcl_SetIntObj(returnObj, 0);
186  } else if ( action == "read" ) {
187  if ( objc < 2 ) {
188  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
189  return TCL_ERROR;
190  }
191  filename = Tcl_GetStringFromObj(objv[2], NULL);
192  if ( verbose & VERB_DEBUG )
193  cout << "DEBUG BmgCmd: File name: " << filename << " (" << filename.length() << ")" << endl;
194  if ( project ) project_kill(project);
195  project = read_project(filename);
196  if ( project->field ) {
197  mg = project->field->mg; // Only use the first micrograph
198  Tcl_SetStringObj(returnObj, mg->id.c_str(), mg->id.length());
199  }
200 // cout << "nrec=" << project_count_reconstructions(project) << endl;
201  } else if ( action == "add" ) {
202  if ( objc < 2 ) {
203  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
204  return TCL_ERROR;
205  }
206  filename = Tcl_GetStringFromObj(objv[2], NULL);
207  if ( verbose & VERB_DEBUG )
208  cout << "DEBUG BmgCmd: File name: " << filename << " (" << filename.length() << ")" << endl;
209  files = filename.split();
210  project_multi_add(project, files, 0);
211  string_kill(files);
212  if ( project->field ) {
213  mg = project->field->mg; // Only use the first micrograph
214  Tcl_SetStringObj(returnObj, (char *)mg->id.c_str(), mg->id.length());
215  }
216  } else if ( action == "write" ) {
217  if ( objc < 2 ) {
218  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
219  return TCL_ERROR;
220  }
221 // cout << "nrec=" << project_count_reconstructions(project) << endl;
222  filename = Tcl_GetStringFromObj(objv[2], NULL);
223  if ( verbose & VERB_DEBUG )
224  cout << "DEBUG BmgCmd: File name: " << filename << " (" << filename.length() << ")" << endl;
225  if ( !project ) {
226  Tcl_AppendResult(interp, "No project in memory!", (char *)NULL);
227  return TCL_ERROR;
228  }
229  project->comment += "\n# Written from Bshow\n# " + Bstring(asctime(localtime(&ti))) + "\n";
230  write_project(filename, project);
231  } else if ( action == "kill" ) {
233  project = NULL;
234  } else if ( action == "ids" ) {
235  for ( field = project->field; field; field = field->next ) {
236  snprintf(string, 128, "Field-of-view %s %ld ", field->id.c_str(), field->select);
237  Tcl_AppendToObj(returnObj, string, strlen(string));
238  for ( mg = field->mg; mg; mg = mg->next ) {
239  snprintf(string, 128, "Micrograph %s %ld ", mg->id.c_str(), mg->select);
240  Tcl_AppendToObj(returnObj, string, strlen(string));
241  for ( part = mg->part; part; part = part->next ) {
242  snprintf(string, 128, "Particle %d %ld ", part->id, part->sel);
243  Tcl_AppendToObj(returnObj, string, strlen(string));
244  }
245  }
246  }
247  for ( rec = project->rec; rec; rec = rec->next ) {
248  snprintf(string, 128, "Reconstruction %s %ld ", rec->id.c_str(), rec->select);
249  Tcl_AppendToObj(returnObj, string, strlen(string));
250  for ( part = rec->part; part; part = part->next ) {
251  snprintf(string, 128, "Particle %d %ld ", part->id, part->sel);
252  Tcl_AppendToObj(returnObj, string, strlen(string));
253  }
254  }
255 // } else if ( action == "item" ) {
256 // returnObj = do_item(project, objc, objv);
257  } else if ( action == "get" ) {
258  returnObj = do_get(project, objc, objv);
259  } else if ( action == "set" ) {
260  do_set(project, objc, objv);
261  } else if ( action == "image_type" ) {
262  imgtype = Tcl_GetStringFromObj(objv[2], NULL);
263  imgtype = image_type(imgtype);
264  Tcl_SetStringObj(returnObj, (char *)imgtype.c_str(), imgtype.length());
265  } else if ( action == "rps" ) {
266  returnObj = do_rps(project, objc, objv);
267  } else if ( action == "ctf_fit" ) {
268  returnObj = do_ctf_fit(project, objc, objv);
269  } else if ( action == "sort" ) {
270  returnObj = do_mg_sort(project, objc, objv);
271  } else if ( action == "update_matrices" ) {
274  } else if ( action == "thickness" ) {
275  returnObj = do_tomo_thickness(project, objc, objv);
276  } else if ( action == "lambda" ) {
277  returnObj = do_lambda(objc, objv);
278  } else if ( action == "transfer" ) {
279  do_tomo_transfer_seed(project, objc, objv);
280  } else if ( action == "findaxis" ) {
281  do_tomo_findaxis(project, objc, objv);
282  } else if ( action == "track" ) {
283  do_tomo_track(project, objc, objv);
284  } else if ( action == "refine" ) {
285  do_tomo_refine(project, objc, objv);
286  } else if ( action == "refine_one" ) {
287  do_tomo_refine_one(project, objc, objv);
288  } else if ( action == "box" ) {
289  returnObj = do_box(project, objc, objv);
290  } else if ( action == "filament" ) {
291  returnObj = do_filament(project, objc, objv);
292  } else if ( action == "node" ) {
293  returnObj = do_node(project, objc, objv);
294  } else if ( action == "layerline" ) {
295  returnObj = do_layerline(project, objc, objv);
296  } else if ( action == "spot" ) {
297  returnObj = do_spot(project, objc, objv);
298  } else if ( action == "marker" ) {
299  returnObj = do_marker(project, objc, objv);
300  } else {
301  cerr << "Error: Action " << action << " not recognized!" << endl;
302  }
303 
304  Tcl_SetObjResult(interp, returnObj);
305 
306  return TCL_OK;
307 }
308 
309 
311 {
312  Bstring bstr;
313  Bstring* strlist = NULL;
314 
315  Bfield* field = NULL;
316  Bmicrograph* mg = NULL;
317  Bparticle* part = NULL;
318  Breconstruction* rec = NULL;
319 
320  if ( verbose & VERB_DEBUG )
321  cout << "DEBUG get_all_file_names: Getting all file names" << endl;
322 
323  for ( field = project->field; field; field = field->next ) {
324  mg = field->mg;
325  if ( mg && mg->next && mg->fmg.length() && mg->fmg == mg->next->fmg ) {
326  bstr = mg->fmg + ":mg:Field:" + field->id + " ";
327  string_add(&strlist, bstr);
328  } else {
329  for ( mg = field->mg; mg; mg = mg->next ) {
330  if ( mg->fmg.length() ) {
331  bstr = mg->fmg + ":mg:Micrograph:" + mg->id + " ";
332  string_add(&strlist, bstr);
333  }
334  if ( mg->fframe.length() ) {
335  bstr = mg->fframe + ":frame:Micrograph:" + mg->id + " ";
336  string_add(&strlist, bstr);
337  }
338  }
339  }
340  if ( mg && mg->next && mg->fps.length() && mg->fps == mg->next->fps ) {
341  bstr = mg->fps + ":ps:Field:" + field->id + " ";
342  string_add(&strlist, bstr);
343  } else {
344  for ( mg = field->mg; mg; mg = mg->next ) {
345  if ( mg->fps.length() ) {
346  bstr = mg->fps + ":ps:Micrograph:" + mg->id + " ";
347  string_add(&strlist, bstr);
348  }
349  }
350  }
351  for ( mg = field->mg; mg; mg = mg->next ) {
352  if ( mg->fpart.length() ) {
353  bstr = mg->fpart + ":part:Micrograph:" + mg->id + " ";
354  string_add(&strlist, bstr);
355  } else for ( part = mg->part; part; part = part->next ) {
356  if ( part->fpart.length() ) {
357  bstr = part->fpart + ":part:Micrograph:" + mg->id + " ";
358  string_add(&strlist, bstr);
359  }
360  }
361  if ( mg->ffil.length() ) {
362  bstr = mg->ffil + ":fil:Micrograph:" + mg->id + " ";
363  string_add(&strlist, bstr);
364  }
365  if ( mg->fft.length() ) {
366  bstr = mg->fft + ":ft:Micrograph:" + mg->id + " ";
367  string_add(&strlist, bstr);
368  }
369  }
370  }
371 
372  for ( rec = project->rec; rec ; rec = rec->next ) {
373  if ( rec->frec.length() ) {
374  bstr = rec->frec + ":rec:Reconstruction:" + rec->id + " ";
375  string_add(&strlist, bstr);
376  }
377  if ( rec->fpart.length() ) {
378  bstr = rec->fpart + ":part:Reconstruction:" + rec->id + " ";
379  string_add(&strlist, bstr);
380  } else for ( part = rec->part; part; part = part->next ) {
381  if ( part->fpart.length() ) {
382  bstr = part->fpart + ":part:Reconstruction:" + rec->id + " ";
383  string_add(&strlist, bstr);
384  }
385  }
386  if ( rec->ffil.length() ) {
387  bstr = rec->ffil + ":fil:Reconstruction:" + rec->id + " ";
388  string_add(&strlist, bstr);
389  }
390  if ( rec->fps.length() ) {
391  bstr = rec->fps + ":ps:Reconstruction:" + rec->id + " ";
392  string_add(&strlist, bstr);
393  }
394  if ( rec->fft.length() ) {
395  bstr = rec->fft + ":ft:Reconstruction:" + rec->id + " ";
396  string_add(&strlist, bstr);
397  }
398  }
399 
400  for ( part = project->class_avg; part; part = part->next ) {
401  if ( part->fpart.length() && part->fpart != bstr ) {
402  bstr = part->fpart + ":part:Class:1 ";
403  string_add(&strlist, bstr);
404  bstr = part->fpart;
405  }
406  }
407 
408  if ( verbose & VERB_DEBUG )
409  cout << "DEBUG get_all_file_names: Last file name: " << bstr << endl;
410 
411  bstr = string_catenate(strlist);
412 
413  string_kill(strlist);
414 
415  if ( verbose & VERB_DEBUG )
416  cout << "DEBUG get_all_file_names: Catenation done" << endl;
417 
418  return bstr;
419 }
420 
422 {
423  Bstring bstr;
424  Bstring* strlist = NULL;
425 
426  Bfield* field = NULL;
427  Bmicrograph* mg = NULL;
428  Bparticle* part = NULL;
429  Breconstruction* rec = NULL;
430 
431  if ( verbose & VERB_DEBUG )
432  cout << "DEBUG get_all_file_names: Getting all file names" << endl;
433 
434  for ( field = project->field; field; field = field->next ) {
435  mg = field->mg;
436  if ( mg && mg->next && mg->fmg.length() && mg->fmg == mg->next->fmg ) {
437  if ( imgtype == "mg" ) {
438  bstr = mg->fmg + ":mg:Field:" + field->id + " ";
439  string_add(&strlist, bstr);
440  }
441  } else {
442  for ( mg = field->mg; mg; mg = mg->next ) {
443  if ( mg->fmg.length() ) {
444  if ( imgtype == "mg" ) {
445  bstr = mg->fmg + ":mg:Micrograph:" + mg->id + " ";
446  string_add(&strlist, bstr);
447  }
448  }
449  if ( mg->fframe.length() ) {
450  if ( imgtype == "frame" ) {
451  bstr = mg->fframe + ":frame:Micrograph:" + mg->id + " ";
452  string_add(&strlist, bstr);
453  }
454  }
455  }
456  }
457  if ( mg && mg->next && mg->fps.length() && mg->fps == mg->next->fps ) {
458  if ( imgtype == "ps" ) {
459  bstr = mg->fps + ":ps:Field:" + field->id + " ";
460  string_add(&strlist, bstr);
461  }
462  } else {
463  for ( mg = field->mg; mg; mg = mg->next ) {
464  if ( mg->fps.length() ) {
465  if ( imgtype == "ps" ) {
466  bstr = mg->fps + ":ps:Micrograph:" + mg->id + " ";
467  string_add(&strlist, bstr);
468  }
469  }
470  }
471  }
472  for ( mg = field->mg; mg; mg = mg->next ) {
473  if ( mg->fpart.length() ) {
474  if ( imgtype == "part" ) {
475  bstr = mg->fpart + ":part:Micrograph:" + mg->id + " ";
476  string_add(&strlist, bstr);
477  }
478  } else for ( part = mg->part; part; part = part->next ) {
479  if ( part->fpart.length() ) {
480  if ( imgtype == "part" ) {
481  bstr = part->fpart + ":part:Micrograph:" + mg->id + " ";
482  string_add(&strlist, bstr);
483  }
484  }
485  }
486  if ( mg->ffil.length() ) {
487  if ( imgtype == "fil" ) {
488  bstr = mg->ffil + ":fil:Micrograph:" + mg->id + " ";
489  string_add(&strlist, bstr);
490  }
491  }
492  if ( mg->fft.length() ) {
493  if ( imgtype == "ft" ) {
494  bstr = mg->fft + ":ft:Micrograph:" + mg->id + " ";
495  string_add(&strlist, bstr);
496  }
497  }
498  }
499  }
500 
501  for ( rec = project->rec; rec ; rec = rec->next ) {
502  if ( rec->frec.length() ) {
503  if ( imgtype == "rec" ) {
504  bstr = rec->frec + ":rec:Reconstruction:" + rec->id + " ";
505  string_add(&strlist, bstr);
506  }
507  }
508  if ( rec->fpart.length() ) {
509  if ( imgtype == "part" ) {
510  bstr = rec->fpart + ":part:Reconstruction:" + rec->id + " ";
511  string_add(&strlist, bstr);
512  }
513  } else for ( part = rec->part; part; part = part->next ) {
514  if ( part->fpart.length() ) {
515  if ( imgtype == "part" ) {
516  bstr = part->fpart + ":part:Reconstruction:" + rec->id + " ";
517  string_add(&strlist, bstr);
518  }
519  }
520  }
521  if ( rec->ffil.length() ) {
522  if ( imgtype == "fil" ) {
523  bstr = rec->ffil + ":fil:Reconstruction:" + rec->id + " ";
524  string_add(&strlist, bstr);
525  }
526  }
527  if ( rec->fps.length() ) {
528  if ( imgtype == "ps" ) {
529  bstr = rec->fps + ":ps:Reconstruction:" + rec->id + " ";
530  string_add(&strlist, bstr);
531  }
532  }
533  if ( rec->fft.length() ) {
534  if ( imgtype == "ft" ) {
535  bstr = rec->fft + ":ft:Reconstruction:" + rec->id + " ";
536  string_add(&strlist, bstr);
537  }
538  }
539  }
540 
541  for ( part = project->class_avg; part; part = part->next ) {
542  if ( part->fpart.length() && part->fpart != bstr ) {
543  if ( imgtype == "part" ) {
544  bstr = part->fpart + ":part:Class:1 ";
545  string_add(&strlist, bstr);
546  }
547  }
548  }
549 
550  if ( verbose & VERB_DEBUG )
551  cout << "DEBUG get_all_file_names: Last file name: " << bstr << endl;
552 
553  bstr = string_catenate(strlist);
554 
555  string_kill(strlist);
556 
557  if ( verbose & VERB_DEBUG )
558  cout << "DEBUG get_all_file_names: Catenation done" << endl;
559 
560  return bstr;
561 }
562 
563 Tcl_Obj* part_select(Bparticle* part, int objc, Tcl_Obj *CONST objv[])
564 {
565  Tcl_Obj* returnObj = Tcl_NewObj();
566 
567  int id(0), sel(-1);
568 
569  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
570  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &sel);
571 
572  if ( id > 0 ) {
573  for ( ; part && part->id != id; part = part->next ) ;
574  if ( part ) {
575  if ( sel >= 0 ) part->sel = sel;
576  else sel = part->sel;
577  }
578  }
579 
580  Tcl_SetIntObj(returnObj, sel);
581 
582  return returnObj;
583 }
584 
585 Tcl_Obj* part_fom(Bparticle* part, int objc, Tcl_Obj *CONST objv[])
586 {
587  Tcl_Obj* returnObj = Tcl_NewObj();
588 
589  int id(0), fom_index(0);
590  char string[MAXLINELEN] = "";
591 
592  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &id);
593  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &fom_index);
594 
595  if ( id > 0 ) {
596  for ( ; part && part->id != id; part = part->next ) ;
597  if ( part ) {
598  snprintf(string, MAXLINELEN, "%f", part->fom[fom_index]);
599  Tcl_SetStringObj(returnObj, string, strlen(string));
600  }
601  }
602 
603 // cout << "fom for " << id << ": " << string << endl;
604 
605  return returnObj;
606 }
607 
608 
609 Tcl_Obj* do_get(Bproject* project, int objc, Tcl_Obj *CONST objv[])
610 {
611  Tcl_Obj* returnObj = Tcl_NewObj();
612 
613  int i, n(-1), mgi(0), nmg(0), nrec(0), npart(0), err(0);
614  char string[MAXLINELEN] = "";
615  Bstring bstr, imgtype, filename;
616 // Vector3<double> sam(1,1,1);
617  Vector3<int> size;
618  View v;
619  Bfield* field = NULL;
620  Bmicrograph* mg = NULL;
621  Bparticle* part = NULL;
622  Breconstruction* rec = NULL;
623 
624  Bstring item = Tcl_GetStringFromObj(objv[2], NULL);
625 
626  Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
627 
628  Bstring id = item.post(':');
629  id = id.remove(' ');
630  item = item.pre(':');
631 
632  if ( verbose & VERB_DEBUG ) {
633  cout << "DEBUG do_get: Item: " << item << " (" << item.length() << ")" << endl;
634  cout << "DEBUG do_get: ID: " << id << " (" << id.length() << ")" << endl;
635  cout << "DEBUG do_get: Property: " << property << " (" << property.length() << ")" << endl;
636  }
637 
638 // verbose = 512;
639 // cout << "id = \"" << id << "\"" << endl;
640 
641  if ( item.contains("all" ) ) {
642  field = project->field;
643  if ( field ) mg = field->mg;
644  rec = project->rec;
647  } else if ( item.contains("Field") ) {
648  for ( field = project->field; field && field->id != id; field = field->next ) ;
649 // if ( !field ) field = project->field;
650  if ( !field ) err++;
651  } else if ( item.contains("Micrograph") ) {
652  for ( field = project->field; field; field = field->next ) {
653  for ( mg = field->mg; mg && mg->id != id; mg = mg->next) mgi++;
654  if ( mg ) break;
655  }
656  if ( !mg ) err++;
657  } else if ( item.contains("Reconstruction") ) {
658  project->select = 1;
659  for ( rec = project->rec; rec && rec->id != id; rec = rec->next ) ;
660  if ( !rec ) err++;
661  } else if ( item.contains("Class") ) {
662  part = project->class_avg;
663  } else {
664  cerr << "Error in do_get: item \"" << item << "\" not supported! (property: " << property << ")" << endl;
665  return returnObj;
666  }
667 
668  if ( err ) cerr << "Error in do_get: " << item << " not found! (property: " << property << ")" << endl;
669 
670 
671  if ( !project || property.empty() ) {
672  Tcl_SetIntObj(returnObj, 0);
673  } else if ( property == "active" ) {
674  Tcl_SetIntObj(returnObj, project->select);
675  } else if ( property == "id" ) {
676  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &n);
677  if ( project->select && rec ) {
678  Tcl_SetStringObj(returnObj, (char *)rec->id.c_str(), rec->id.length());
679  } else if ( mg ) {
680  if ( !mg ) {
681  cerr << "Error: No micrograph specified!" << endl;
682  mg = field->mg;
683  }
684  if ( mg )
685  Tcl_SetStringObj(returnObj, (char *)mg->id.c_str(), mg->id.length());
686  } else if ( field ) {
687  if ( n >= 0 ) {
688  for ( i=0, mg = field->mg; mg && i != n; mg = mg->next, i++ ) ;
689  if ( !mg ) {
690  cerr << "Error: No micrograph specified!" << endl;
691  mg = field->mg;
692  }
693  Tcl_SetStringObj(returnObj, (char *)mg->id.c_str(), mg->id.length());
694  } else {
695  Tcl_SetStringObj(returnObj, (char *)field->id.c_str(), field->id.length());
696  }
697  }
698  } else if ( property == "id_from_index" ) {
699  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &n);
700  if ( project->select ) {
701  for ( i=1, rec = project->rec; rec; rec = rec->next, ++i )
702  if ( i == n ) break;
703  Tcl_SetStringObj(returnObj, (char *)rec->id.c_str(), rec->id.length());
704  } else {
705  for ( i=1, field = project->field; field; field = field->next ) {
706  for ( mg = field->mg; mg; mg = mg->next, ++i )
707  if ( i == n) break;
708  if ( mg ) break;
709  }
710  Tcl_SetStringObj(returnObj, (char *)mg->id.c_str(), mg->id.length());
711  }
712  } else if ( property == "img_num" ) {
713  if ( mg ) n = mg->img_num;
714  else n = 0;
715  Tcl_SetIntObj(returnObj, n);
716  } else if ( property == "field" ) {
717  if ( !field ) field = project->field;
718  if ( field )
719  Tcl_SetStringObj(returnObj, (char *)field->id.c_str(), field->id.length());
720  } else if ( property == "number_of_item" ) {
721  if ( project->select ) {
722  if ( part ) n = project_count_rec_particles(project);
723  else n = nrec;
724  if ( !n ) n = project_count_reconstructions(project);
725  } else if ( field ) {
726  if ( part ) n = project_count_mg_particles(project);
727  else n = nmg;
728  if ( !n ) for ( n=0, mg = field->mg; mg; mg = mg->next) n++;
729  }
730  Tcl_SetIntObj(returnObj, n);
731 // cout << "Number of items = " << n << endl;
732  } else if ( property == "number_of_mg" ) {
733  if ( !nmg && field ) for ( nmg=0, mg = field->mg; mg; mg = mg->next) nmg++;
734  Tcl_SetIntObj(returnObj, nmg);
735 // cout << "Number of micrographs = " << nmg << endl;
736  } else if ( property == "number_of_rec" ) {
737  for ( nrec=0, rec = project->rec; rec; rec = rec->next ) nrec++;
738  Tcl_SetIntObj(returnObj, nrec);
739  } else if ( property == "number_of_part" ) {
740  if ( !part ) {
741  if ( mg ) part = mg->part;
742  if ( rec ) part = rec->part;
743  }
744  for ( npart=0; part; part = part->next ) npart++;
745  Tcl_SetIntObj(returnObj, npart);
746  } else if ( property == "index_of_item" ) {
747  if ( rec ) {
748  for ( i=0, rec = project->rec; rec && rec->id != id; rec = rec->next ) i++;
749  } else {
750  for ( i=0, field = project->field; field; field = field->next ) {
751  for ( mg = field->mg; mg && mg->id != id; mg = mg->next) i++;
752  if ( mg ) break;
753  }
754  }
755  Tcl_SetIntObj(returnObj, ++i);
756  } else if ( property == "image_filenames" ) {
757  if ( objc > 4 ) {
758  imgtype = Tcl_GetStringFromObj(objv[4], NULL);
759  bstr = get_all_file_names(project, imgtype);
760  } else {
761  bstr = get_all_file_names(project);
762  }
763  Tcl_AppendToObj(returnObj, bstr.c_str(), bstr.length());
764  } else if ( property == "filename" ) {
765  imgtype = Tcl_GetStringFromObj(objv[4], NULL);
766  if ( mg ) {
767 // cout << "Get: id=" << mg->id << " file=" << mg->fps << " imgtype=" << imgtype << endl;
768  if ( imgtype == "mg" )
769  Tcl_SetStringObj(returnObj, (char *)mg->fmg.c_str(), mg->fmg.length());
770  else if ( imgtype == "frame" )
771  Tcl_SetStringObj(returnObj, (char *)mg->fframe.c_str(), mg->fframe.length());
772  else if ( imgtype == "part" )
773  Tcl_SetStringObj(returnObj, (char *)mg->fpart.c_str(), mg->fpart.length());
774  else if ( imgtype == "fil" )
775  Tcl_SetStringObj(returnObj, (char *)mg->ffil.c_str(), mg->ffil.length());
776  else if ( imgtype == "ft" )
777  Tcl_SetStringObj(returnObj, (char *)mg->fft.c_str(), mg->fft.length());
778  else if ( imgtype == "ps" )
779  Tcl_SetStringObj(returnObj, (char *)mg->fps.c_str(), mg->fps.length());
780  } else if ( rec ) {
781  if ( imgtype == "rec" )
782  Tcl_SetStringObj(returnObj, (char *)rec->frec.c_str(), rec->frec.length());
783  else if ( imgtype == "part" )
784  Tcl_SetStringObj(returnObj, (char *)rec->fpart.c_str(), rec->fpart.length());
785  else if ( imgtype == "fil" )
786  Tcl_SetStringObj(returnObj, (char *)rec->ffil.c_str(), rec->ffil.length());
787  else if ( imgtype == "ft" )
788  Tcl_SetStringObj(returnObj, (char *)rec->fft.c_str(), rec->fft.length());
789  else if ( imgtype == "ps" )
790  Tcl_SetStringObj(returnObj, (char *)rec->fps.c_str(), rec->fps.length());
791  } else if ( part ) {
792  if ( imgtype == "part" )
793  Tcl_SetStringObj(returnObj, (char *)part->fpart.c_str(), part->fpart.length());
794  }
795  imgtype = 0;
796  } else if ( property == "select" ) {
797  if ( project->select && rec ) {
798  Tcl_SetIntObj(returnObj, rec->select);
799  } else if ( mg ) {
800  Tcl_SetIntObj(returnObj, mg->select);
801  } else if ( field ) {
802  Tcl_SetIntObj(returnObj, field->select);
803  } else if ( part ) {
804  returnObj = part_select(part, objc, objv);
805  } else {
806  Tcl_SetIntObj(returnObj, 0);
807  }
808  } else if ( property == "fom" ) {
809  if ( project->select && rec ) {
810  Tcl_SetDoubleObj(returnObj, rec->fom);
811  } else if ( mg ) {
812  Tcl_SetDoubleObj(returnObj, mg->fom);
813  } else if ( part ) {
814  returnObj = part_fom(part, objc, objv);
815 // Tcl_SetDoubleObj(returnObj, part->fom[0]);
816  } else {
817  Tcl_SetDoubleObj(returnObj, 0);
818  }
819 /* } else if ( property == "pixel_size" ) {
820  if ( objc > 4 ) imgtype = Tcl_GetStringFromObj(objv[4], NULL);
821  if ( field && !mg ) mg = field->mg;
822  if ( part ) sam = part->pixel_size;
823  else if ( imgtype == "part" ) {
824  if ( project->select && rec && rec->part )
825  sam = rec->part->pixel_size;
826  else if ( mg && mg->part )
827  sam = mg->part->pixel_size;
828  } else if ( mg ) {
829  sam = mg->pixel_size;
830  } else if ( rec ) {
831  sam = rec->voxel_size;
832  }
833  snprintf(string, MAXLINELEN, "%g %g %g ", sam[0], sam[1], sam[2]);
834  Tcl_AppendToObj(returnObj, string, strlen(string));*/
835  } else if ( property == "pixel_size" ) {
836  if ( project->select && rec ) {
837  snprintf(string, 128, "%g %g %g ", rec->voxel_size[0], rec->voxel_size[1], rec->voxel_size[2]);
838  Tcl_AppendToObj(returnObj, string, strlen(string));
839  } else if ( mg ) {
840  snprintf(string, 128, "%g %g %g ", mg->pixel_size[0], mg->pixel_size[1], mg->pixel_size[2]);
841  Tcl_AppendToObj(returnObj, string, strlen(string));
842  } else if ( field ) {
843  for ( mg = field->mg; mg; mg = mg->next ) {
844  snprintf(string, 128, "%g %g %g ", mg->pixel_size[0], mg->pixel_size[1], mg->pixel_size[2]);
845  Tcl_AppendToObj(returnObj, string, strlen(string));
846  }
847  } else if ( part ) {
848  for ( part = project->class_avg; part; part = part->next ) {
849  snprintf(string, 128, "%g %g %g ", part->pixel_size[0], part->pixel_size[1], part->pixel_size[2]);
850  Tcl_AppendToObj(returnObj, string, strlen(string));
851  }
852  }
853  } else if ( property == "part_pixel_size" ) {
854  if ( !part ) {
855  if ( mg ) part = mg->part;
856  else if ( rec ) part = rec->part;
857  }
858  if ( part ) {
859  if ( objc > 4 ) filename = Tcl_GetStringFromObj(objv[4], NULL);
860  if ( filename.length() < 1 || ( mg && filename == mg->fpart ) ||
861  ( rec && filename == rec->fpart ) ) {
862  for ( ; part; part = part->next ) {
863  snprintf(string, 128, "%g %g %g ", part->pixel_size[0], part->pixel_size[1], part->pixel_size[2]);
864  Tcl_AppendToObj(returnObj, string, strlen(string));
865  }
866  } else {
867  for ( ; part; part = part->next ) if ( filename == part->fpart ) {
868  snprintf(string, 128, "%g %g %g ", part->pixel_size[0], part->pixel_size[1], part->pixel_size[2]);
869  Tcl_AppendToObj(returnObj, string, strlen(string));
870  break;
871  }
872  }
873  }
874  } else if ( property == "size" ) {
875  if ( !mg && field ) mg = field->mg;
876  if ( mg ) {
877  size = micrograph_get_size(mg);
878  snprintf(string, 128, "%d %d %d ", size[0], size[1], size[2]);
879  Tcl_AppendToObj(returnObj, string, strlen(string));
880  }
881  } else if ( property == "origin" ) {
882  if ( project->select && rec ) {
883  snprintf(string, 128, "%g %g %g ", rec->origin[0], rec->origin[1], rec->origin[2]);
884  Tcl_AppendToObj(returnObj, string, strlen(string));
885  } else if ( mg ) {
886  snprintf(string, 128, "%g %g %g ", mg->origin[0], mg->origin[1], mg->origin[2]);
887  Tcl_AppendToObj(returnObj, string, strlen(string));
888  } else if ( field ) {
889  for ( mg = field->mg; mg; mg = mg->next ) {
890  snprintf(string, 128, "%g %g %g ", mg->origin[0], mg->origin[1], mg->origin[2]);
891  Tcl_AppendToObj(returnObj, string, strlen(string));
892  }
893  } else if ( part ) {
894  for ( part = project->class_avg; part; part = part->next ) {
895  snprintf(string, 128, "%g %g %g ", part->ori[0], part->ori[1], part->ori[2]);
896  Tcl_AppendToObj(returnObj, string, strlen(string));
897  }
898  }
899  } else if ( property == "part_origin" ) {
900  if ( !part ) {
901  if ( mg ) part = mg->part;
902  else if ( rec ) part = rec->part;
903  }
904  if ( part ) {
905  if ( objc > 4 ) filename = Tcl_GetStringFromObj(objv[4], NULL);
906  if ( filename.length() < 1 || ( mg && filename == mg->fpart ) ||
907  ( rec && filename == rec->fpart ) ) {
908  for ( ; part; part = part->next ) {
909  snprintf(string, 128, "%g %g %g ", part->ori[0], part->ori[1], part->ori[2]);
910  Tcl_AppendToObj(returnObj, string, strlen(string));
911  }
912  } else {
913  for ( ; part; part = part->next ) if ( filename == part->fpart ) {
914  snprintf(string, 128, "%g %g %g ", part->ori[0], part->ori[1], part->ori[2]);
915  Tcl_AppendToObj(returnObj, string, strlen(string));
916  break;
917  }
918  }
919  }
920  } else if ( property == "scale" ) {
921  if ( project->select && rec ) {
922  snprintf(string, 128, "%g %g %g ", rec->scale[0], rec->scale[1], rec->scale[2]);
923  Tcl_AppendToObj(returnObj, string, strlen(string));
924  } else if ( mg ) {
925  snprintf(string, 128, "%g %g %g ", mg->scale[0], mg->scale[1], mg->scale[2]);
926  Tcl_AppendToObj(returnObj, string, strlen(string));
927  } else if ( field ) {
928  for ( mg = field->mg; mg; mg = mg->next ) {
929  snprintf(string, 128, "%g %g %g ", mg->scale[0], mg->scale[1], mg->scale[2]);
930  Tcl_AppendToObj(returnObj, string, strlen(string));
931  }
932  }
933  } else if ( property == "dose" ) {
934  if ( !mg ) mg = field->mg;
935  if ( mg ) {
936  Tcl_SetDoubleObj(returnObj, mg->dose);
937  } else {
938  if ( mg->intensity < 0.01 ) micrograph_intensity(mg);
939  Tcl_SetDoubleObj(returnObj, mg->intensity);
940  }
941  } else if ( property == "intensity" ) {
942  if ( !mg ) mg = field->mg;
943  if ( mg ) {
944  if ( mg->intensity < 0.01 ) micrograph_intensity(mg);
945  Tcl_SetDoubleObj(returnObj, mg->intensity);
946  } else {
947  Tcl_SetDoubleObj(returnObj, 0.0);
948  }
949  } else if ( property == "defocus_deviation" ) {
950  if ( project->select && rec ) {
951  if ( !rec->ctf ) rec->ctf = new CTFparam;
952  Tcl_SetDoubleObj(returnObj, rec->ctf->defocus_deviation());
953  } else if ( mg ) {
954  if ( !mg->ctf ) mg->ctf = new CTFparam;
955  Tcl_SetDoubleObj(returnObj, mg->ctf->defocus_deviation());
956  }
957  } else if ( property == "defocus" ) {
958  if ( project->select && rec ) {
959  if ( !rec->ctf ) rec->ctf = new CTFparam;
960  Tcl_SetDoubleObj(returnObj, rec->ctf->defocus_average());
961  } else if ( mg ) {
962  if ( !mg->ctf ) mg->ctf = new CTFparam;
963  Tcl_SetDoubleObj(returnObj, mg->ctf->defocus_average());
964 // cout << "Micrograph: " << mg->id << " defocus=" << mg->ctf->defocus_average() << endl;
965  }
966  } else if ( property == "astigmatism_angle" ) {
967  if ( project->select && rec ) {
968  if ( !rec->ctf ) rec->ctf = new CTFparam;
969  Tcl_SetDoubleObj(returnObj, rec->ctf->astigmatism_angle()*180/M_PI);
970  } else if ( mg ) {
971  if ( !mg->ctf ) mg->ctf = new CTFparam;
972  Tcl_SetDoubleObj(returnObj, mg->ctf->astigmatism_angle()*180/M_PI);
973  }
974  } else if ( property == "volt" ) {
975  if ( project->select && rec ) {
976  if ( !rec->ctf ) rec->ctf = new CTFparam;
977  Tcl_SetDoubleObj(returnObj, rec->ctf->volt());
978  } else if ( mg ) {
979  if ( !mg->ctf ) mg->ctf = new CTFparam;
980  Tcl_SetDoubleObj(returnObj, mg->ctf->volt());
981  }
982  } else if ( property == "Cs" ) {
983  if ( project->select && rec ) {
984  if ( !rec->ctf ) rec->ctf = new CTFparam;
985  Tcl_SetDoubleObj(returnObj, rec->ctf->Cs());
986  } else if ( mg ) {
987  if ( !mg->ctf ) mg->ctf = new CTFparam;
988  Tcl_SetDoubleObj(returnObj, mg->ctf->Cs());
989  }
990  } else if ( property == "amp_fac" ) {
991  if ( project->select && rec ) {
992  if ( !rec->ctf ) rec->ctf = new CTFparam;
993  Tcl_SetDoubleObj(returnObj, sin(rec->ctf->amp_shift()));
994  } else if ( mg ) {
995  if ( !mg->ctf ) mg->ctf = new CTFparam;
996  Tcl_SetDoubleObj(returnObj, sin(mg->ctf->amp_shift()));
997  }
998  } else if ( property == "focal_length" ) {
999  if ( project->select && rec ) {
1000  if ( !rec->ctf ) rec->ctf = new CTFparam;
1001  Tcl_SetDoubleObj(returnObj, rec->ctf->focal_length());
1002  } else if ( mg ) {
1003  if ( !mg->ctf ) mg->ctf = new CTFparam;
1004  Tcl_SetDoubleObj(returnObj, mg->ctf->focal_length());
1005  }
1006  } else if ( property == "aperture" ) {
1007  if ( project->select && rec ) {
1008  if ( !rec->ctf ) rec->ctf = new CTFparam;
1009  Tcl_SetDoubleObj(returnObj, rec->ctf->objective_aperture());
1010  } else if ( mg ) {
1011  if ( !mg->ctf ) mg->ctf = new CTFparam;
1012  Tcl_SetDoubleObj(returnObj, mg->ctf->objective_aperture());
1013  }
1014  } else if ( property == "slit_width" ) {
1015  if ( project->select && rec ) {
1016  if ( !rec->ctf ) rec->ctf = new CTFparam;
1017  Tcl_SetDoubleObj(returnObj, rec->ctf->slit_width());
1018  } else if ( mg ) {
1019  if ( !mg->ctf ) mg->ctf = new CTFparam;
1020  Tcl_SetDoubleObj(returnObj, mg->ctf->slit_width());
1021  }
1022  } else if ( property == "baseline" ) {
1023  if ( project->select && rec ) {
1024  if ( !rec->ctf ) rec->ctf = new CTFparam;
1025  bstr = rec->ctf->baseline_equation();
1026  Tcl_SetStringObj(returnObj, bstr.c_str(), bstr.length());
1027  } else if ( mg ) {
1028  if ( !mg->ctf ) mg->ctf = new CTFparam;
1029  bstr = mg->ctf->baseline_equation();
1030  Tcl_SetStringObj(returnObj, bstr.c_str(), bstr.length());
1031  }
1032  } else if ( property == "baseline_type" ) {
1033  if ( project->select && rec ) {
1034  if ( !rec->ctf ) rec->ctf = new CTFparam;
1035  Tcl_SetIntObj(returnObj, rec->ctf->baseline_type());
1036  } else if ( mg ) {
1037  if ( !mg->ctf ) mg->ctf = new CTFparam;
1038  Tcl_SetIntObj(returnObj, mg->ctf->baseline_type());
1039  }
1040  } else if ( property == "envelope" ) {
1041  if ( project->select && rec ) {
1042  if ( !rec->ctf ) rec->ctf = new CTFparam;
1043  bstr = rec->ctf->envelope_equation();
1044  Tcl_SetStringObj(returnObj, bstr.c_str(), bstr.length());
1045  } else if ( mg ) {
1046  if ( !mg->ctf ) mg->ctf = new CTFparam;
1047  bstr = mg->ctf->envelope_equation();
1048  Tcl_SetStringObj(returnObj, bstr.c_str(), bstr.length());
1049  }
1050  } else if ( property == "envelope_type" ) {
1051  if ( project->select && rec ) {
1052  if ( !rec->ctf ) rec->ctf = new CTFparam;
1053  Tcl_SetIntObj(returnObj, rec->ctf->envelope_type());
1054  } else if ( mg ) {
1055  if ( !mg->ctf ) mg->ctf = new CTFparam;
1056  Tcl_SetIntObj(returnObj, mg->ctf->envelope_type());
1057  }
1058  } else if ( property == "zero" ) {
1059  if ( project->select && rec ) {
1060  if ( rec->ctf )
1061  Tcl_SetDoubleObj(returnObj, rec->ctf->zero(1));
1062  } else if ( mg ) {
1063  if ( mg->ctf )
1064  Tcl_SetDoubleObj(returnObj, mg->ctf->zero(1));
1065  }
1066  } else if ( property == "view" ) {
1067  if ( mg ) v = View(mg->matrix);
1068  else if ( rec ) v = rec->view;
1069  snprintf(string, 128, "%g %g %g %g ", v[0], v[1], v[2], v.angle());
1070  Tcl_AppendToObj(returnObj, string, strlen(string));
1071  } else if ( property == "axis" ) {
1072  if ( !mg && field ) mg = field->mg;
1073  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->tilt_axis*180.0/M_PI);
1074  else Tcl_SetDoubleObj(returnObj, 0);
1075  } else if ( property == "tilt" ) {
1076  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->tilt_angle*180.0/M_PI);
1077  else Tcl_SetDoubleObj(returnObj, 0);
1078  } else if ( property == "level" ) {
1079  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->level_angle*180.0/M_PI);
1080  else Tcl_SetDoubleObj(returnObj, 0);
1081  } else if ( property == "unitcell" ) {
1082  if ( mg )
1083  snprintf(string, 128, "%g %g %g %g ", mg->hvec[0], mg->hvec[1], mg->kvec[0], mg->kvec[1]);
1084  Tcl_AppendToObj(returnObj, string, strlen(string));
1085  } else if ( property == "helix_axis" ) {
1086  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->helix_axis*180.0/M_PI);
1087  else Tcl_SetDoubleObj(returnObj, 0.0);
1088  } else if ( property == "helix_rise" ) {
1089  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->helix_rise);
1090  else Tcl_SetDoubleObj(returnObj, 0.0);
1091  } else if ( property == "helix_angle" ) {
1092  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->helix_angle*180.0/M_PI);
1093  else Tcl_SetDoubleObj(returnObj, 0.0);
1094  } else if ( property == "helix_radius" ) {
1095  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->helix_radius);
1096  else Tcl_SetDoubleObj(returnObj, 0.0);
1097  } else if ( property == "box_size" ) {
1098  if ( project->select && rec ) snprintf(string, 128, "%ld %ld %ld", rec->box_size[0], rec->box_size[1], rec->box_size[2]);
1099  else {
1100  if ( !mg ) mg = field->mg;
1101  if ( mg ) snprintf(string, 128, "%ld %ld %ld", mg->box_size[0], mg->box_size[1], mg->box_size[2]);
1102  }
1103  Tcl_SetStringObj(returnObj, string, strlen(string));
1104  } else if ( property == "bad_radius" ) {
1105  if ( project->select && rec ) Tcl_SetDoubleObj(returnObj, rec->bad_radius);
1106  else {
1107  if ( !mg ) mg = field->mg;
1108  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->bad_radius);
1109  }
1110  } else if ( property == "filament_width" ) {
1111  if ( project->select && rec ) Tcl_SetDoubleObj(returnObj, rec->filament_width);
1112  else {
1113  if ( !mg ) mg = field->mg;
1114  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->filament_width);
1115  }
1116  } else if ( property == "filament_node_radius" ) {
1117  if ( project->select && rec ) Tcl_SetDoubleObj(returnObj, rec->fil_node_radius);
1118  else {
1119  if ( !mg ) mg = field->mg;
1120  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->fil_node_radius);
1121  }
1122  } else if ( property == "sf_radius" ) {
1123  if ( project->select && rec ) Tcl_SetDoubleObj(returnObj, rec->sf_radius);
1124  else {
1125  if ( !mg ) mg = field->mg;
1126  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->sf_radius);
1127  }
1128  } else if ( property == "marker_radius" ) {
1129  if ( part ) Tcl_SetDoubleObj(returnObj, 0.0);
1130  else if ( project->select && rec ) Tcl_SetDoubleObj(returnObj, rec->mark_radius);
1131  else {
1132  if ( !mg && field ) mg = field->mg;
1133  if ( mg ) Tcl_SetDoubleObj(returnObj, mg->mark_radius);
1134  }
1135  } else {
1136  cerr << "Error in do_get: Property " << property << " not recognized!" << endl;
1137  }
1138 
1139  return returnObj;
1140 }
1141 
1142 
1143 int do_set(Bproject* project, int objc, Tcl_Obj *CONST objv[])
1144 {
1145  if ( !project )
1146  return error_show("Error: No project defined!\n", __FILE__, __LINE__);
1147 
1148  int update(0);
1149 
1150  int i, n(-1), err(0);
1151  double value;
1152  Vector3<int> box;
1153  Vector3<double> origin, sam(1,1,1), scale;
1154 
1155  Bstring name, imgtype;
1156  Bfield* field = NULL;
1157  Bmicrograph* mg = NULL;
1158  Breconstruction* rec = NULL;
1159  Bparticle* part = NULL;
1160 
1161  Bstring item = Tcl_GetStringFromObj(objv[2], NULL);
1162 
1163  Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
1164 
1165  Bstring id = item.post(':');
1166  id = id.remove(' ');
1167  item = item.pre(':');
1168 
1169  if ( verbose & VERB_DEBUG ) {
1170  cout << "DEBUG do_set: Item: " << item << " (" << item.length() << ")" << endl;
1171  cout << "DEBUG do_set: ID: " << id << " (" << id.length() << ")" << endl;
1172  cout << "DEBUG do_set: Property: " << property << " (" << property.length() << ")" << endl;
1173  }
1174 
1175  if ( item.contains("all" ) ) {
1176  } else if ( property == "id" ) {
1177  if ( item.contains("Field") ) {
1178  field = project->field;
1179  } else if ( item.contains("Micrograph") ) {
1180  field = project->field;
1181  if ( field ) mg = field->mg;
1182  } else if ( item.contains("Reconstruction") ) {
1183  project->select = 1;
1184  rec = project->rec;
1185  } else err++;
1186  } else if ( item.contains("Field") ) {
1187  for ( field = project->field; field && field->id != id; field = field->next ) ;
1188  if ( !field ) err++;
1189 // cout << "field id = " << project->field->id << endl;
1190  } else if ( item.contains("Micrograph") ) {
1191  for ( field = project->field; field; field = field->next ) {
1192  for ( mg = field->mg; mg && mg->id != id; mg = mg->next) ;
1193  if ( mg ) break;
1194  }
1195  if ( !mg ) err++;
1196 // cout << "set mg id: " << mg->id << endl;
1197  } else if ( item.contains("Reconstruction") ) {
1198  for ( rec = project->rec; rec && rec->id != id; rec = rec->next ) ;
1199  if ( !rec ) rec = project->rec;
1200  if ( !rec ) err++;
1201  } else if ( item.contains("Class") ) {
1202  part = project->class_avg;
1203  } else {
1204  cerr << "Error in do_set: item \"" << item << "\" not supported! (property: " << property << ")" << endl;
1205  return update;
1206  }
1207 
1208  if ( err ) cerr << "Error in do_set: " << item << " not found! (property: " << property << ")" << endl;
1209 
1210  if ( !project || property.empty() || objc < 4 ) {
1211  return update;
1212  } else if ( property == "active" ) {
1213  Tcl_GetIntFromObj(NULL, objv[4], &project->select);
1214  if ( project->select && !project->rec ) rec = reconstruction_add(&project->rec, id);
1215  } else if ( property == "id" ) {
1216  id = Tcl_GetStringFromObj(objv[4], NULL);
1217 // cout << "Setting item " << item << " to id " << id << endl;
1218  if ( project->select ) {
1219  if ( rec ) {
1220  rec->id = id;
1221  } else {
1222  rec = project->rec;
1223  if ( !rec->next ) rec->id = id;
1224  else for ( n=0, rec = project->rec; rec; rec = rec->next, n++ ) {
1225  rec->id = id + Bstring(n, "_%03d");
1226  }
1227  }
1228  } else if ( !mg && field ) {
1229  field->id = id;
1230  } else if ( mg ) {
1231  mg = field->mg;
1232  if ( !mg->next ) mg->id = id;
1233  else for ( n=0, mg = field->mg; mg; mg = mg->next, n++ ) {
1234  mg->id = id + Bstring(n, "_%03d");
1235  }
1236  }
1237  } else if ( property == "filename" ) {
1238  name = Tcl_GetStringFromObj(objv[4], NULL);
1239  imgtype = Tcl_GetStringFromObj(objv[5], NULL);
1240 // cout << "filename=" << name << " imgtype=" << imgtype << endl;
1241  if ( mg ) {
1242 // cout << "Set: id=" << id << " file=" << name << " imgtype=" << imgtype << endl;
1243  if ( imgtype == "mg" ) mg->fmg = name;
1244  else if ( imgtype == "frame" ) mg->fframe = name;
1245  else if ( imgtype == "part" ) mg->fpart = name;
1246  else if ( imgtype == "fil" ) mg->ffil = name;
1247  else if ( imgtype == "ft" ) mg->fft = name;
1248  else if ( imgtype == "ps" ) mg->fps = name;
1249  } else if ( field ) {
1250  if ( imgtype == "mg" ) {
1251  for ( i=0, mg = field->mg; mg; mg = mg->next, i++ ) {
1252  mg->fmg = name;
1253  mg->img_num = i;
1254  }
1255  } else if ( imgtype == "ps" ) {
1256  for ( mg = field->mg; mg; mg = mg->next )
1257  mg->fps = name;
1258  }
1259  } else if ( rec ) {
1260  if ( imgtype == "rec" ) rec->frec = name;
1261  else if ( imgtype == "part" ) rec->fpart = name;
1262  else if ( imgtype == "fil" ) rec->ffil = name;
1263  else if ( imgtype == "ft" ) rec->fft = name;
1264  else if ( imgtype == "ps" ) rec->fps = name;
1265  } else if ( part ) {
1266  if ( imgtype == "part" ) part->fpart = name;
1267  if ( part == project->class_avg )
1268  for ( ; part; part = part->next ) part->fpart = name;
1269  }
1270  imgtype = 0;
1271  name = 0;
1272  } else if ( property == "select" ) {
1273  Tcl_GetIntFromObj(NULL, objv[4], &i);
1274  if ( project->select && rec ) rec->select = i;
1275  else if ( mg ) mg->select = i;
1276  else if ( field ) field->select = i;
1277  else if ( part ) part->sel = i;
1278  } else if ( property == "pixel_size" ) {
1279 // cout << objc << endl;
1280  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &sam[0]);
1281  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &sam[1]);
1282  if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &sam[2]);
1283 // cout << "pixel size = " << sam << endl;
1284  if ( project->select && rec )
1285  rec->voxel_size = sam;
1286  else if ( mg )
1287  mg->pixel_size = sam;
1288  else if ( field ) for ( mg = field->mg; mg; mg = mg->next )
1289  mg->pixel_size = sam;
1290  } else if ( property == "origin" ) {
1291  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1292  origin[0] = value;
1293  Tcl_GetDoubleFromObj(NULL, objv[5], &value);
1294  origin[1] = value;
1295  Tcl_GetDoubleFromObj(NULL, objv[6], &value);
1296  origin[2] = value;
1297  if ( project->select && rec ) rec->origin = origin;
1298  else if ( mg ) mg->origin = origin;
1299  else if ( field ) for ( mg = field->mg; mg; mg = mg->next ) mg->origin = origin;
1300  } else if ( property == "scale" ) {
1301  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1302  scale[0] = value;
1303  Tcl_GetDoubleFromObj(NULL, objv[5], &value);
1304  scale[1] = value;
1305  Tcl_GetDoubleFromObj(NULL, objv[6], &value);
1306  scale[2] = value;
1307  if ( project->select && rec ) rec->scale = scale;
1308  else if ( mg ) mg->scale = scale;
1309  else if ( field ) for ( mg = field->mg; mg; mg = mg->next ) mg->scale = scale;
1310  } else if ( property == "dose" ) {
1311  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1312  if ( item.contains("all" ) )
1313  project_set_dose(project, value);
1314  else if ( mg )
1315  mg->dose = value;
1316  else if ( field ) for ( mg = field->mg; mg; mg = mg->next )
1317  mg->dose = value;
1318  } else if ( property == "defocus_deviation" ) {
1319  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1320  if ( project->select && rec ) {
1321  if ( !rec->ctf ) rec->ctf = new CTFparam;
1322  rec->ctf->defocus_deviation(value);
1323  } else if ( mg ) {
1324  if ( !mg->ctf ) mg->ctf = new CTFparam;
1325  mg->ctf->defocus_deviation(value);
1326  }
1327  } else if ( property == "defocus" ) {
1328  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1329  if ( project->select && rec ) {
1330  if ( !rec->ctf ) rec->ctf = new CTFparam;
1331  rec->ctf->defocus_average(value);
1332  } else if ( mg ) {
1333  if ( !mg->ctf ) mg->ctf = new CTFparam;
1334  mg->ctf->defocus_average(value);
1335  }
1336  } else if ( property == "astigmatism_angle" ) {
1337  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1338  value *= M_PI/180.0;
1339  if ( project->select && rec ) {
1340  if ( !rec->ctf ) rec->ctf = new CTFparam;
1341  rec->ctf->astigmatism_angle(value);
1342  } else if ( mg ) {
1343  if ( !mg->ctf ) mg->ctf = new CTFparam;
1344  mg->ctf->astigmatism_angle(value);
1345  }
1346  } else if ( property == "volt" ) {
1347  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1348  project_set_volts(project, value);
1349  } else if ( property == "Cs" ) {
1350  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1351  project_set_Cs(project, value);
1352  } else if ( property == "amp_fac" ) {
1353  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1354  project_set_amp_shift(project, asin(value));
1355  } else if ( property == "focal_length" ) {
1356  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1358  } else if ( property == "aperture" ) {
1359  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1360  project_set_aperture(project, value);
1361  } else if ( property == "slit_width" ) {
1362  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1364  } else if ( property == "baseline_type" ) {
1365  if ( project->select && rec ) {
1366  if ( !rec->ctf ) rec->ctf = new CTFparam;
1367  Tcl_GetIntFromObj(NULL, objv[4], &i);
1368  rec->ctf->baseline_type(i);
1369  } else if ( mg ) {
1370  if ( !mg->ctf ) mg->ctf = new CTFparam;
1371  Tcl_GetIntFromObj(NULL, objv[4], &i);
1372  mg->ctf->baseline_type(i);
1373 // cout << "Micrograph: " << mg->id << " baseline_type: " << mg->ctf->baseline_type() << endl;
1374  }
1375  } else if ( property == "baseline" ) {
1376  if ( project->select && rec ) {
1377  if ( !rec->ctf ) rec->ctf = new CTFparam;
1378  rec->ctf->parse_baseline_equation(Tcl_GetStringFromObj(objv[4], NULL));
1379  } else if ( mg ) {
1380  if ( !mg->ctf ) mg->ctf = new CTFparam;
1381  mg->ctf->parse_baseline_equation(Tcl_GetStringFromObj(objv[4], NULL));
1382  }
1383  } else if ( property == "envelope_type" ) {
1384  if ( project->select && rec ) {
1385  if ( !rec->ctf ) rec->ctf = new CTFparam;
1386  Tcl_GetIntFromObj(NULL, objv[4], &i);
1387  rec->ctf->envelope_type(i);
1388  } else if ( mg ) {
1389  if ( !mg->ctf ) mg->ctf = new CTFparam;
1390  Tcl_GetIntFromObj(NULL, objv[4], &i);
1391  mg->ctf->envelope_type(i);
1392 // cout << "Micrograph: " << mg->id << " envelope_type: " << mg->ctf->envelope_type() << endl;
1393  }
1394  } else if ( property == "envelope" ) {
1395  if ( project->select && rec ) {
1396  if ( !rec->ctf ) rec->ctf = new CTFparam;
1397  rec->ctf->parse_envelope_equation(Tcl_GetStringFromObj(objv[4], NULL));
1398  } else if ( mg ) {
1399  if ( !mg->ctf ) mg->ctf = new CTFparam;
1400  mg->ctf->parse_envelope_equation(Tcl_GetStringFromObj(objv[4], NULL));
1401  }
1402  } else if ( property == "axis" ) {
1403  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1404  value *= M_PI/180.0;
1405  if ( field ) {
1406  if ( objc > 5 ) {
1407  Tcl_GetIntFromObj(NULL, objv[5], &n);
1408  for ( i=0, mg = field->mg; mg && i<n; mg = mg->next, i++ ) ;
1409  if ( mg ) mg->tilt_axis = value;
1410  } else {
1411  for ( mg = field->mg; mg; mg = mg->next ) mg->tilt_axis = value;
1412  }
1413  } else if ( mg ) {
1414  mg->tilt_axis = value;
1415  }
1416  } else if ( property == "tilt" ) {
1417  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1418  value *= M_PI/180.0;
1419 // cout << "Trying to set tilt angle for item " << item << " to " << value*180/M_PI << endl;
1420  if ( !mg && field ) {
1421  Tcl_GetIntFromObj(NULL, objv[5], &n);
1422  for ( i=0, mg = field->mg; mg && i<n; mg = mg->next, i++ ) ;
1423 // cout << "Trying to set tilt angle for mg " << n << " to " << value*180/M_PI << endl;
1424  }
1425 // if ( mg ) cout << "Set tilt for mg " << n << " to " << value*180/M_PI << endl;
1426  if ( mg ) mg->tilt_angle = value;
1427  } else if ( property == "level" ) {
1428  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1429  value *= M_PI/180.0;
1430  if ( !mg && field ) {
1431  Tcl_GetIntFromObj(NULL, objv[5], &n);
1432  for ( i=0, mg = field->mg; mg && i<n; mg = mg->next, i++ ) ;
1433  }
1434  if ( mg ) mg->level_angle = value;
1435  } else if ( property == "unitcell" ) {
1436  if ( mg ) {
1437  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1438  mg->hvec[0] = value;
1439  Tcl_GetDoubleFromObj(NULL, objv[5], &value);
1440  mg->hvec[1] = value;
1441  Tcl_GetDoubleFromObj(NULL, objv[6], &value);
1442  mg->kvec[0] = value;
1443  Tcl_GetDoubleFromObj(NULL, objv[7], &value);
1444  mg->kvec[1] = value;
1445  }
1446  } else if ( property == "helix_axis" ) {
1447  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1448  if ( mg ) mg->helix_axis = value*M_PI/180.0;
1449  } else if ( property == "helix_rise" ) {
1450  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1451  if ( mg ) mg->helix_rise = value;
1452  } else if ( property == "helix_angle" ) {
1453  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1454  if ( mg ) mg->helix_angle = value*M_PI/180.0;
1455  } else if ( property == "helix_radius" ) {
1456  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1457  if ( mg ) mg->helix_radius = value;
1458  } else if ( property == "box_size" ) {
1459  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &box[0]);
1460  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &box[1]);
1461  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &box[2]);
1463 /* if ( project->select && project->rec ) {
1464  for ( rec = project->rec; rec; rec = rec->next ) rec->box_size = box;
1465  } else if ( mg ) {
1466  box[2] = 1;
1467  mg->box_size = box;
1468  } else if ( field ) {
1469  box[2] = 1;
1470  for ( mg = field->mg; mg; mg = mg->next )
1471  mg->box_size = box;
1472  }*/
1473  } else if ( property == "bad_radius" ) {
1474  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1475  if ( project->select && rec )
1476  for ( rec=project->rec; rec; rec=rec->next ) rec->bad_radius = value;
1477  else if ( mg ) mg->bad_radius = value;
1478  else if ( field )
1479  for ( mg = field->mg; mg; mg = mg->next ) mg->bad_radius = value;
1480  } else if ( property == "filament_width" ) {
1481  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1482  if ( project->select && rec )
1483  for ( rec=project->rec; rec; rec=rec->next ) rec->filament_width = value;
1484  else if ( mg ) mg->filament_width = value;
1485  else if ( field )
1486  for ( mg = field->mg; mg; mg = mg->next ) mg->filament_width = value;
1487  } else if ( property == "filament_node_radius" ) {
1488  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1489  if ( project->select && rec )
1490  for ( rec=project->rec; rec; rec=rec->next ) rec->fil_node_radius = value;
1491  else if ( mg ) mg->fil_node_radius = value;
1492  else if ( field )
1493  for ( mg = field->mg; mg; mg = mg->next ) mg->fil_node_radius = value;
1494  } else if ( property == "sf_radius" ) {
1495  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1496  if ( project->select && rec )
1497  for ( rec=project->rec; rec; rec=rec->next ) rec->sf_radius = value;
1498  else if ( mg ) mg->sf_radius = value;
1499  else if ( field )
1500  for ( mg = field->mg; mg; mg = mg->next ) mg->sf_radius = value;
1501  } else if ( property == "marker_radius" ) {
1502  Tcl_GetDoubleFromObj(NULL, objv[4], &value);
1503  if ( project->select && rec )
1504  for ( rec=project->rec; rec; rec=rec->next ) rec->mark_radius = value;
1505  else if ( mg ) mg->mark_radius = value;
1506  else if ( field )
1507  for ( mg = field->mg; mg; mg = mg->next ) mg->mark_radius = value;
1508  } else {
1509  cerr << "Error in do_set: Property " << property << " not recognized!" << endl;
1510  }
1511 
1512  return update;
1513 }
1514 
1515 Tcl_Obj* do_rps(Bproject* project, int objc, Tcl_Obj *CONST objv[])
1516 {
1517  Tcl_Obj* returnObj = Tcl_NewObj();
1518 
1519  int err(0);
1520  long img_num(0);
1521  Bfield* field = NULL;
1522  Bmicrograph* mg = NULL;
1523  Breconstruction* rec = NULL;
1524  CTFparam* em_ctf = NULL;
1525  Bimage* p = NULL;
1526  Bstring filename, filename2;
1527 
1528  Bstring item = Tcl_GetStringFromObj(objv[2], NULL);
1529  if ( verbose & VERB_DEBUG )
1530  cout << "DEBUG do_rps: Item: " << item << " (" << item.length() << ")" << endl;
1531 
1532  Bstring id = item.post(':');
1533  id = id.remove(' ');
1534  item = item.pre(':');
1535 
1536  if ( verbose & VERB_DEBUG ) {
1537  cout << "DEBUG do_rps: Item: " << item << " (" << item.length() << ")" << endl;
1538  cout << "DEBUG do_rps: ID: " << id << " (" << id.length() << ")" << endl;
1539  }
1540 
1541  if ( item.contains("Micrograph") ) {
1542  for ( field = project->field; field; field = field->next ) {
1543  for ( mg = field->mg; mg && mg->id != id; mg = mg->next) ;
1544  if ( mg ) break;
1545  }
1546  if ( !mg ) err++;
1547  else {
1548  img_num = mg->img_num;
1549  if ( !mg->ctf ) mg->ctf = new CTFparam;
1550  em_ctf = mg->ctf;
1551  filename = mg->fps;
1552  if ( filename.contains("/") ) filename = filename.post_rev('/');
1553  for ( p = imglist; p; p = p->next ) {
1554  filename2 = p->file_name();
1555  if ( filename2.contains(filename) ) break;
1556  }
1557  if ( p ) p->sampling(mg->pixel_size);
1558  else err++;
1559  }
1560  } else if ( item.contains("Reconstruction") ) {
1561  for ( rec = project->rec; rec && rec->id != id; rec = rec->next ) ;
1562  if ( !rec ) err++;
1563  else {
1564  if ( !rec->ctf ) rec->ctf = new CTFparam;
1565  em_ctf = rec->ctf;
1566  filename = rec->fps;
1567  if ( filename.contains("/") ) filename = filename.post_rev('/');
1568  for ( p = imglist; p; p = p->next ) {
1569  filename2 = p->file_name();
1570  if ( filename2.contains(filename) ) break;
1571  }
1572  if ( p ) p->sampling(rec->voxel_size);
1573  else err++;
1574  }
1575  } else {
1576  cerr << "Error in do_rps: item \"" << item << "\" not supported!" << endl;
1577  return returnObj;
1578  }
1579 
1580  if ( !p ) {
1581  cerr << "Warning in do_rps: No image! " << endl;
1582  return returnObj;
1583  }
1584 
1585  if ( img_num >= p->images() ) img_num = 0;
1586 
1587  if ( verbose & VERB_DEBUG ) {
1588  cout << "DEBUG do_rps: image id = " << p->identifier() << endl;
1589  cout << "DEBUG do_rps: image = " << p->file_name() << tab << img_num << endl;
1590  }
1591 
1592  if ( em_ctf->defocus_average() <= 1 ||
1593  em_ctf->defocus_average() >= 2e5 )
1594  em_ctf->defocus_average(2e4);
1595 
1596 /* if ( objc > 3 ) {
1597  Tcl_GetDoubleFromObj(NULL, objv[3], &defocus_avg);
1598  em_ctf->defocus_average(defocus_avg);
1599  }
1600 
1601  if ( objc > 4 ) {
1602  Tcl_GetDoubleFromObj(NULL, objv[4], &defocus_dev);
1603  em_ctf->defocus_deviation(defocus_dev);
1604  }
1605 
1606  if ( objc > 5 ) {
1607  Tcl_GetDoubleFromObj(NULL, objv[5], &astigmatism_angle);
1608  em_ctf->astigmatism_angle(astigmatism_angle);
1609  }
1610 */
1611  char string[128];
1612  Bimage* prps = img_ctf_radial_average(p, img_num, *em_ctf);
1613 
1614  if ( !prps ) {
1615  snprintf(string, 128, "Warning: Radial average failed!");
1616  Tcl_AppendToObj(returnObj, string, strlen(string));
1617  return returnObj;
1618  }
1619 
1620  if ( prps->sizeX() < 1 ) {
1621  snprintf(string, 128, "Warning: Radial average has zero values!");
1622  Tcl_AppendToObj(returnObj, string, strlen(string));
1623  return returnObj;
1624  }
1625 
1626  long i;
1627 
1628  double wri = img_water_ring_index(prps);
1629 
1630  for ( i=0; i<prps->sizeX(); i++ ) {
1631  if ( !isfinite((*prps)[i]) ) {
1632  cerr << "Warning in do_rps: Point " << i << " is a NaN!" << endl;
1633  Tcl_AppendToObj(returnObj, string, strlen(string));
1634  return returnObj;
1635  }
1636  snprintf(string, 128, " %g", (*prps)[i]);
1637  Tcl_AppendToObj(returnObj, string, strlen(string));
1638 // cout << i << tab << (*prps)[i] << endl;
1639  }
1640 
1641  delete prps;
1642 
1643  snprintf(string, 128, " %g", wri);
1644  Tcl_AppendToObj(returnObj, string, strlen(string));
1645 
1646  if ( verbose & VERB_DEBUG )
1647  cout << "DEBUG do_rps: done" << endl;
1648 
1649  return returnObj;
1650 }
1651 
1652 Tcl_Obj* do_lambda(int objc, Tcl_Obj *CONST objv[])
1653 {
1654  Tcl_Obj* returnObj = Tcl_NewObj();
1655 
1656  double v(0), lambda(0);
1657  CTFparam ctf;
1658  if ( objc > 2 ) Tcl_GetDoubleFromObj(NULL, objv[2], &v);
1659  ctf.volt(v);
1660  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &v);
1661  ctf.focal_length(v);
1662  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &v);
1663  ctf.objective_aperture(v);
1664  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &v);
1665  ctf.slit_width(v);
1666 
1667  Bstring atompropfile;
1668  Batomtype* atompar = get_atom_properties(atompropfile);
1669 
1670  if ( !atompar ) {
1671  cerr << "Error: No atom parameter file read!" << endl;
1672  return returnObj;
1673  }
1674 
1675  lambda = ice_lambda(atompar, ctf);
1676 
1677  Tcl_SetDoubleObj(returnObj, lambda);
1678 
1679  return returnObj;
1680 }
1681 
1682 Tcl_Obj* do_ctf_fit(Bproject* project, int objc, Tcl_Obj *CONST objv[])
1683 {
1684  Tcl_Obj* returnObj = Tcl_NewObj();
1685 
1686  int err(0);
1687  int level(0); // 0=quick, 1=baseline, 2=defocus, 3=astigmatism
1688  long img_num(0);
1689  double lores(1e10), hires(0.1);
1690  double def_start(1e3), def_end(2e5), def_inc(1e3);
1691  Bfield* field = NULL;
1692  Bmicrograph* mg = NULL;
1693  Breconstruction* rec = NULL;
1694  CTFparam* em_ctf = NULL;
1695  Bimage* p = NULL;
1696  Bstring filename, filename2;
1697 
1698  Bstring item = Tcl_GetStringFromObj(objv[2], NULL);
1699  if ( verbose & VERB_DEBUG )
1700  cout << "DEBUG do_ctf_fit: Item: " << item << " (" << item.length() << ")" << endl;
1701 
1702  Bstring id = item.post(':');
1703  id = id.remove(' ');
1704  item = item.pre(':');
1705 
1706 // cout << "id = " << id << endl;
1707 
1708  if ( item.contains("Micrograph") ) {
1709  for ( field = project->field; field; field = field->next ) {
1710  for ( mg = field->mg; mg && mg->id != id; mg = mg->next) ;
1711  if ( mg ) break;
1712  }
1713  if ( !mg ) err++;
1714  else {
1715  img_num = mg->img_num;
1716  if ( !mg->ctf ) mg->ctf = new CTFparam;
1717  em_ctf = mg->ctf;
1718  filename = mg->fps;
1719  if ( filename.contains("/") ) filename = filename.post_rev('/');
1720  for ( p = imglist; p; p = p->next ) {
1721  filename2 = p->file_name();
1722  if ( filename2.contains(filename) ) break;
1723  }
1724  if ( p ) p->sampling(mg->pixel_size);
1725  else err++;
1726  }
1727  } else if ( item.contains("Reconstruction") ) {
1728  for ( rec = project->rec; rec && rec->id != id; rec = rec->next ) ;
1729  if ( !rec ) err++;
1730  else {
1731  if ( !rec->ctf ) rec->ctf = new CTFparam;
1732  em_ctf = rec->ctf;
1733  filename = rec->fps;
1734  if ( filename.contains("/") ) filename = filename.post_rev('/');
1735  for ( p = imglist; p; p = p->next ) {
1736  filename2 = p->file_name();
1737  if ( filename2.contains(filename) ) break;
1738  }
1739  if ( p ) p->sampling(rec->voxel_size);
1740  else err++;
1741  }
1742  } else {
1743  cerr << "Error in do_ctf_fit: item \"" << item << "\" not supported!" << endl;
1744  return returnObj;
1745  }
1746 
1747  if ( !p ) {
1748  cerr << "Warning in do_ctf_fit: No image! " << endl;
1749  return returnObj;
1750  }
1751 
1752  if ( img_num >= p->images() ) img_num = 0;
1753 
1754  if ( verbose & VERB_DEBUG )
1755  cout << "DEBUG do_rps: image id = " << p->identifier() << endl;
1756 
1757  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &level);
1758  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &lores);
1759  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &hires);
1760  if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &def_start);
1761  if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &def_end);
1762  if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &def_inc);
1763 
1764  if ( level == 0 || em_ctf->defocus_average() == 0 ) {
1765  em_ctf->defocus_deviation(0);
1766  em_ctf->astigmatism_angle(0);
1767  img_ctf_find_defocus(p, img_num, *em_ctf, lores, hires, def_start, def_end, def_inc);
1768  img_ctf_fit_baseline(p, img_num, *em_ctf, lores, hires);
1769  img_ctf_fit_envelope(p, img_num, *em_ctf, lores, hires);
1770  }
1771 
1772  if ( level == 1 )
1773  img_ctf_fit_baseline(p, img_num, *em_ctf, lores, hires);
1774 
1775  if ( level == 2 )
1776  img_ctf_fit_envelope(p, img_num, *em_ctf, lores, hires);
1777 
1778  if ( level == 3 )
1779  img_ctf_find_defocus(p, img_num, *em_ctf, lores, hires,
1780  em_ctf->defocus_average()/1.2, em_ctf->defocus_average()*1.2,
1781  em_ctf->defocus_average()*0.2);
1782 
1783  if ( level == 4 )
1784  img_ctf_fit_astigmatism(p, img_num, *em_ctf, lores, hires);
1785 
1786  double wri = img_water_ring_index(p, img_num, *em_ctf);
1787  if ( mg ) mg->wri = wri;
1788 
1789  Bstring base_eq = em_ctf->baseline_equation();
1790  Bstring env_eq = em_ctf->envelope_equation();
1791 
1792 // cout << base_eq << endl;
1793 
1794  char string[MAXLINELEN] = "";
1795  if ( base_eq.length() )
1796  snprintf(string, MAXLINELEN, "\"%s\" \"%s\" %g %g %g %g", base_eq.c_str(), env_eq.c_str(),
1797  em_ctf->defocus_average(), em_ctf->defocus_deviation(), em_ctf->astigmatism_angle()*180.0/M_PI, wri);
1798 
1799  Tcl_SetStringObj(returnObj, string, strlen(string));
1800 
1801  return returnObj;
1802 }
1803 
1804 Tcl_Obj* do_mg_sort(Bproject* project, int objc, Tcl_Obj *CONST objv[])
1805 {
1806  Tcl_Obj* returnObj = Tcl_NewObj();
1807  char string[MAXLINELEN] = "";
1808  Bstring mg_sort, tag;
1809 
1810  if ( objc > 3 ) mg_sort = Tcl_GetStringFromObj(objv[3], NULL);
1811  if ( mg_sort == "Defocus" ) tag = CTF_DEF_AVG;
1812  if ( mg_sort == "Water ring" ) tag = MICROGRAPH_WATER_RING;
1813  if ( mg_sort == "Particles" ) tag = PARTICLE;
1814  if ( mg_sort == "Intensity" ) {
1816  tag = MICROGRAPH_INTENSITY;
1817  }
1818 
1819  vector<pair<Bmicrograph*,double>> mgv = project_mg_sort(project, tag);
1820 
1821  if ( mgv.size() < 1 ) return returnObj;
1822 
1823  for ( auto it = mgv.begin(); it != mgv.end(); ++it ) {
1824  sprintf(string, "%s %20.16f ", it->first->id.c_str(), it->second);
1825  Tcl_AppendToObj(returnObj, string, strlen(string));
1826  }
1827 
1828  return returnObj;
1829 }
1830 
do_set
int do_set(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:1143
Bmicrograph::helix_rise
double helix_rise
Definition: mg_processing.h:230
Bmicrograph::scale
Vector3< double > scale
Definition: mg_processing.h:224
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:415
project_mg_tilt_to_matrix
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
Definition: mg_tomography.cpp:2177
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
MAXLINELEN
#define MAXLINELEN
Definition: utilities.h:45
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
do_tomo_thickness
Tcl_Obj * do_tomo_thickness(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:68
project_set_aperture
int project_set_aperture(Bproject *project, double aperture)
Sets the objective aperture of all the micrographs.
Definition: mg_ctf.cpp:1695
Bmicrograph::filament_width
double filament_width
Definition: mg_processing.h:234
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
verbose
int verbose
tcltk_bfil.h
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:473
CTFparam::zero
double zero(int i)
Definition: ctf.h:228
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
do_get
Tcl_Obj * do_get(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:609
Bproject::select
int select
Definition: mg_processing.h:342
img_ctf_fit_astigmatism
double img_ctf_fit_astigmatism(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires)
Fits the astigmatism with a given defocus, baseline and envelope.
Definition: mg_ctf_fit.cpp:566
Bstring
Definition: Bstring.h:29
project_set_dose
int project_set_dose(Bproject *project, double dose)
Sets the electron dose of all the micrographs.
Definition: mg_processing.cpp:2099
Bimage::next
Bimage * next
Definition: Bimage.h:179
Breconstruction::voxel_size
Vector3< double > voxel_size
Definition: mg_processing.h:295
Bparticle
Definition: mg_processing.h:90
do_box
Tcl_Obj * do_box(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bbox.cpp:115
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
CTFparam::objective_aperture
double objective_aperture()
Definition: ctf.h:102
Breconstruction::ctf
CTFparam * ctf
Definition: mg_processing.h:306
Breconstruction::filament_width
double filament_width
Definition: mg_processing.h:300
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:236
Breconstruction::fom
double fom
Definition: mg_processing.h:305
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
CTFparam::astigmatism_angle
double astigmatism_angle()
Definition: ctf.h:110
project_count_reconstructions
long project_count_reconstructions(Bproject *project)
Counts all the reconstructions in the project structure.
Definition: mg_select.cpp:384
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:220
Vector3< int >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
do_tomo_refine_one
int do_tomo_refine_one(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:216
do_rps
Tcl_Obj * do_rps(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:1515
Bmicrograph::helix_axis
double helix_axis
Definition: mg_processing.h:229
Breconstruction::sf_radius
double sf_radius
Definition: mg_processing.h:303
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
mg_select.h
Header file for micrograph processing.
Bmicrograph::helix_radius
double helix_radius
Definition: mg_processing.h:232
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Batomtype
Definition: rwatomprop.h:19
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
project_set_volts
int project_set_volts(Bproject *project, double volts)
Sets the acceleration voltage of all the micrographs.
Definition: mg_ctf.cpp:1579
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bfield::id
Bstring id
Definition: mg_processing.h:262
View
Definition: View.h:26
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
get_all_file_names
Bstring get_all_file_names(Bproject *project)
Definition: tcltk_bmg.cpp:310
Bstring::post
Bstring post(char c)
Definition: Bstring.cpp:402
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:304
get_atom_properties
Batomtype * get_atom_properties(Bstring &filename)
Reading atomic properties from parameter files.
Definition: rwatomprop.cpp:47
Bfield
Definition: mg_processing.h:260
project_processing
int project_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Implements the "Bmg" command in Tcl/Tk to access micrograph parameter files through Bsoft.
Definition: tcltk_bmg.cpp:138
micrograph_get_size
Vector3< long > micrograph_get_size(Bmicrograph *mg)
Gets the size of a micrograph.
Definition: mg_img_proc.cpp:712
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:207
project_mg_avg_intensities
int project_mg_avg_intensities(Bproject *project)
Retrieves the average micrograph intensities.
Definition: mg_img_proc.cpp:689
imglist
Bimage * imglist
Definition: bshow.cpp:32
PARTICLE
#define PARTICLE
Definition: mg_tags.h:181
img_ctf_find_defocus
double img_ctf_find_defocus(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires, double def_start=1e3, double def_end=2e5, double def_inc=1e3)
Searches for the defocus based on correlation.
Definition: mg_ctf_fit.cpp:400
do_layerline
Tcl_Obj * do_layerline(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bhelix.cpp:71
Bmicrograph::dose
double dose
Definition: mg_processing.h:216
CTFparam::parse_baseline_equation
int parse_baseline_equation(Bstring base_eq)
Extracts the coefficients from the baseline string.
Definition: ctf.cpp:244
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:296
do_tomo_track
int do_tomo_track(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:154
Bimage::images
long images()
Definition: Bimage.h:504
string_catenate
Bstring string_catenate(Bstring *list)
Catenates a string linked list into one string.
Definition: Bstring.cpp:747
rwmg.h
Header file for reading and writing micrograph parameters.
scatter.h
Functions for calculating electron scattering profiles.
CTF_DEF_AVG
#define CTF_DEF_AVG
Definition: mg_tags.h:172
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:209
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
Bstring::pre
Bstring pre(char c)
Definition: Bstring.cpp:389
Bmicrograph::level_angle
double level_angle
Definition: mg_processing.h:221
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Bmicrograph::hvec
Vector3< double > hvec
Definition: mg_processing.h:226
do_node
Tcl_Obj * do_node(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bfil.cpp:534
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
project_create_from_images
Bproject * project_create_from_images(Bstring *file_list, Bstring type)
Creates a project structure using image file names.
Definition: mg_img_proc.cpp:230
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:219
do_marker
Tcl_Obj * do_marker(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:279
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
CTFparam::envelope_equation
Bstring envelope_equation()
Generates an envelope equation string from 4 coefficients.
Definition: ctf.cpp:211
Bproject
Definition: mg_processing.h:336
do_mg_sort
Tcl_Obj * do_mg_sort(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:1804
CTFparam::parse_envelope_equation
int parse_envelope_equation(Bstring env_eq)
Extracts the coefficients from the envelope string.
Definition: ctf.cpp:289
Bmicrograph::kvec
Vector3< double > kvec
Definition: mg_processing.h:227
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:563
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
project_multi_add
int project_multi_add(Bproject *project, Bstring *file_list, int fom_index)
Merges multiple projects with an existing one.
Definition: mg_multiple.cpp:207
micrograph_intensity
double micrograph_intensity(Bmicrograph *mg)
Gets the average of a micrograph.
Definition: mg_img_proc.cpp:659
mg_img_proc.h
Header file for image processing from micrograph structures.
CTFparam::volt
double volt()
Definition: ctf.h:87
CTFparam::defocus_deviation
double defocus_deviation()
Definition: ctf.h:108
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:238
do_lambda
Tcl_Obj * do_lambda(int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:1652
do_ctf_fit
Tcl_Obj * do_ctf_fit(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:1682
tcltk_bhelix.h
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
Breconstruction::fft
Bstring fft
Definition: mg_processing.h:293
project
Bproject * project
Definition: bshow.cpp:33
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
mg_tags.h
All STAR and XML file format tags for micrographs and reconstructions.
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
CTFparam::slit_width
double slit_width()
Definition: ctf.h:104
Breconstruction::fil_node_radius
double fil_node_radius
Definition: mg_processing.h:301
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
do_filament
Tcl_Obj * do_filament(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bfil.cpp:77
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
img_water_ring_index
double img_water_ring_index(Bimage *p, long img_num, CTFparam &em_ctf)
Calculates the water ring index from a power spectrum.
Definition: mg_ctf_fit.cpp:660
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
Breconstruction::select
long select
Definition: mg_processing.h:286
isfinite
bool isfinite(complex< T > &value)
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:225
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:348
Bfield::select
long select
Definition: mg_processing.h:265
do_spot
Tcl_Obj * do_spot(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bxtal.cpp:68
do_tomo_findaxis
int do_tomo_findaxis(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:131
project_set_particle_box_size
int project_set_particle_box_size(Bproject *project, Vector3< long > box_size)
Sets particle box size to the given value.
Definition: mg_processing.cpp:2284
CTFparam
Definition: ctf.h:28
img_ctf_fit_envelope
double img_ctf_fit_envelope(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires)
Fits only the envelope for a given CTF.
Definition: mg_ctf_fit.cpp:341
Bmicrograph::fom
double fom
Definition: mg_processing.h:239
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
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
image_type
Bstring image_type(Bstring type)
Converts an image type string to a standard form.
Definition: mg_img_proc.cpp:38
CTFparam::envelope_type
long envelope_type()
Definition: ctf.h:119
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
tcltk_bmarker.h
A shared object to manage markers in micrograph parameter files in TCL/Tk.
mg_processing.h
Header file for micrograph processing.
Bmicrograph::intensity
double intensity
Definition: mg_processing.h:217
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
Breconstruction::bad_radius
double bad_radius
Definition: mg_processing.h:302
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
linked_list.h
Header file for generalized linked list functions.
Bmicrograph::select
long select
Definition: mg_processing.h:204
do_tomo_transfer_seed
int do_tomo_transfer_seed(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:102
Bstring::split
Bstring * split()
Definition: Bstring.cpp:605
Breconstruction::scale
Vector3< double > scale
Definition: mg_processing.h:297
Bmicrograph::helix_angle
double helix_angle
Definition: mg_processing.h:231
Bmicrograph::fps
Bstring fps
Definition: mg_processing.h:211
Breconstruction::ffil
Bstring ffil
Definition: mg_processing.h:292
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
project_set_amp_shift
int project_set_amp_shift(Bproject *project, double amp_shift)
Sets the amplitude contribution of all the micrographs.
Definition: mg_ctf.cpp:1638
Bmicrograph::wri
double wri
Definition: mg_processing.h:218
project_create_from_image
Bproject * project_create_from_image(Bimage *p, Bstring type)
Creates a project structure using image file names.
Definition: mg_img_proc.cpp:69
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
project_mg_sort
vector< pair< Bmicrograph *, double > > project_mg_sort(Bproject *project, Bstring tag)
Sorts the micrographs by a selected parameter.
Definition: mg_select.cpp:1631
CTFparam::focal_length
double focal_length()
Definition: ctf.h:89
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
CTFparam::amp_shift
double amp_shift()
Definition: ctf.h:99
mg_ctf_fit.h
Header file for CTF (contrast transfer function) functions.
Bmicrograph::fil_node_radius
double fil_node_radius
Definition: mg_processing.h:235
mg_multiple.h
Selection of single particle parameters from multiple files for classification.
Bproject::comment
Bstring comment
Definition: mg_processing.h:339
tcltk_bxtal.h
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
MICROGRAPH_INTENSITY
#define MICROGRAPH_INTENSITY
Definition: mg_tags.h:87
part_fom
Tcl_Obj * part_fom(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:585
ice_lambda
double ice_lambda(Batomtype *atompar, CTFparam &ctf)
Calculates the average lambda proportionality parameter for vitreous ice.
Definition: scatter.cpp:501
do_tomo_refine
int do_tomo_refine(Bproject *project, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmarker.cpp:179
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:398
Breconstruction::fps
Bstring fps
Definition: mg_processing.h:294
Bimage::identifier
void identifier(Bstring s)
Definition: Bimage.h:231
CTFparam::baseline_equation
Bstring baseline_equation()
Generates a baseline equation string from 4 to 10 coefficients.
Definition: ctf.cpp:167
level
size_t level(0)
img_ctf_radial_average
Bimage * img_ctf_radial_average(Bimage *p, long n, CTFparam &em_ctf)
Calculates the power spectrum radial average corrected for astigmatism.
Definition: mg_ctf_fit.cpp:46
View::angle
double angle()
Definition: View.h:98
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
tcltk_bbox.h
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
project_set_slit_width
int project_set_slit_width(Bproject *project, double slit)
Sets the energy filter slit width of all the micrographs.
Definition: mg_ctf.cpp:1724
Bmicrograph::sf_radius
double sf_radius
Definition: mg_processing.h:237
Bparticle::id
int id
Definition: mg_processing.h:93
project_set_focal_length
int project_set_focal_length(Bproject *project, double focal_length)
Sets the focal length of all the micrographs.
Definition: mg_ctf.cpp:1666
img_ctf_fit_baseline
double img_ctf_fit_baseline(Bimage *p, long n, CTFparam &em_ctf, double lores, double hires)
Fits only the baseline for a given CTF.
Definition: mg_ctf_fit.cpp:308
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_select.cpp:350
CTFparam::Cs
double Cs()
Definition: ctf.h:91
MICROGRAPH_WATER_RING
#define MICROGRAPH_WATER_RING
Definition: mg_tags.h:88
Bmicrograph::fft
Bstring fft
Definition: mg_processing.h:210
mg_tomography.h
Header file for single particle image processing in Bsoft.
CTFparam::baseline_type
long baseline_type()
Definition: ctf.h:112
project_count_rec_particles
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:506
Breconstruction::view
View view
Definition: mg_processing.h:298
project_set_Cs
int project_set_Cs(Bproject *project, double Cs)
Sets the spherical aberation constant of all the micrographs.
Definition: mg_ctf.cpp:1609
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284