| Bsoft 2.0.5 Bernard's software package

bshow_tomo.tcl
Go to the documentation of this file.
1 ##
2 # @file bshow_tomo.tcl
3 #
4 # @brief Procedures to manage tomographic images
5 #
6 # @author Bernard Heymann
7 # @date Created: 20021112
8 # @date Modified: 20180730
9
10 set show_markers 1
11 set show_marker_errors 1
12 set show_marker_labels 1
13 set marker_radius 10
14 set markers_selected []
15 set refop "m"
16 set hires 10
17 set lores 1000
18 set samrat 1
19 set norm_type "Simple"
20 set shift_limit 500
21 set thickness 500
22 set cc_type 0
23
24 ## @brief Dialog box to manage tomographic information
25 #
26
27 proc Tomography { } {
28 # puts "In Tomography"
29 global tool project_item theimg imgtype
30 global helv12 cour12
31 global project_item
32 global tilt_axis marker_radius
33
34 if ![Bimage exists $theimg] {
35 tk_dialog .dialog "No image in memory!" \
36 {Please read in an appropriate image first.} \
37 info 0 {OK}
38 return
39 }
40
41 set c [getImageCanvas $theimg]
42 if ![Bmg exists] {
43 set imgtype "mg"
44 createMgParam
45 setMgParam
46 Bmg set $project_item axis [expr $tilt_axis]
47 Bmg set $project_item marker_radius $marker_radius
48 # puts "Setting tilt axis in the project"
49 } else {
50 set axis [expr [Bmg get $project_item axis]]
51 if { $axis > -1000 } {
52 set tilt_axis $axis
53 # puts "Getting tilt axis from the project"
54 }
55 set r [Bmg get $project_item marker_radius]
56 if $r {
57 set marker_radius $r
58 } else {
59 # set marker_radius 10
60 Bmg set $project_item marker_radius $marker_radius
61 }
62 }
63
64 set field [Bmg get $project_item field]
65 set nmg [Bmg get $project_item number_of_mg]
66 set nrec [Bmg get $project_item number_of_rec]
67
68 # puts "Number of micrographs: $nmg"
69 # puts "Number of reconstructions: $nrec"
70 # puts "Field: $field"
71 # puts "Marker radius: $marker_radius"
72 # puts "Tilt axis: $tilt_axis"
73
74 set w .wtomo
75 if ![winfo exists $w] {
76 toplevel $w
77 menu $w.menuBar -tearoff 0
78 $w.menuBar add cascade -menu $w.menuBar.tomo -label "Tomography" -underline 0
79 menu $w.menuBar.tomo -tearoff 0
80 $w configure -menu $w.menuBar
81 $w.menuBar.tomo add command -label "Help" -underline 0 \
82 -command { showURL "file://$Bsoft/doc/bshow/bshow_tomo.html" }
83 # -command { showHelp bshow_tomo.hlp }
84 $w.menuBar.tomo add command -label "Set tilt angles" \
85 -command { Tilts } -underline 0
86 $w.menuBar.tomo add command -label "Read tilt angles file" \
87 -command { readTlt } -underline 0
88 # $w.menuBar.tomo add command -label "Find markers in all images" \
89 # -command { markerFind -1 } -underline 0
90 $w.menuBar.tomo add command -label "Renumber markers in current image" \
91 -command { markerRenumber } -underline 0
92 $w.menuBar.tomo add command -label "Center markers in current image" \
93 -command { markerCenter } -underline 0
94 $w.menuBar.tomo add command -label "Extract markers" \
95 -command { markerExtract } -underline 0
96 $w.menuBar.tomo add command -label "Show marker table" \
97 -command { markerTable } -underline 0
98 $w.menuBar.tomo add command -label "Delete selected markers" \
99 -command { markerDeleteSelected } -underline 0
100 $w.menuBar.tomo add command -label "Delete selected markers in all images" \
101 -command { markerDeleteSelectedAll } -underline 0
102 $w.menuBar.tomo add command -label "Delete all markers" \
103 -command { markerDeleteAll } -underline 0
104 $w.menuBar.tomo add command -label "Close" \
105 -command { destroy .wtomo } -underline 0
106
107 $w.menuBar add cascade -menu $w.menuBar.tomoflow -label "Workflow" -underline 0
108 menu $w.menuBar.tomoflow -tearoff 0
109 $w configure -menu $w.menuBar
110 # $w.menuBar.tomoflow add command -label "Align and average frames" \
111 # -command { alignAverageFrames } -underline 0
112 $w.menuBar.tomoflow add command -label "Normalize images" \
113 -command { normalizeImages } -underline 0
114 $w.menuBar.tomoflow add command -label "Find markers in current image" \
115 -command { markerFind [.image.scale get] } -underline 0
116 $w.menuBar.tomoflow add command -label "Generate markers from seed" \
117 -command { markerGenerate } -underline 0
118 $w.menuBar.tomoflow add command -label "Find tilt axis" \
119 -command { findTiltAxis } -underline 0
120 $w.menuBar.tomoflow add command -label "Transfer markers to second series" \
121 -command { markerTransfer } -underline 0
122 $w.menuBar.tomoflow add command -label "Track markers" \
123 -command { markerTrack } -underline 0
124 $w.menuBar.tomoflow add command -label "Refine alignment" \
125 -command { markerRefine } -underline 0
126 $w.menuBar.tomoflow add command -label "Calculate and fit power spectra" \
127 -command { tomoPowerSpectra } -underline 0
128 $w.menuBar.tomoflow add command -label "Estimate resolution" \
129 -command { tomoResolution } -underline 0
130 $w.menuBar.tomoflow add command -label "Reconstruct" \
131 -command { tomoReconstruct } -underline 0
132 $w.menuBar.tomoflow add command -label "Denoise" \
133 -command { tomoDenoise } -underline 0
134
135 frame $w.switches
136 checkbutton $w.switches.markers -text "Show markers" -variable show_markers \
137 -command { markerDrawAll }
138 checkbutton $w.switches.errors -text "Show errors" -variable show_marker_errors \
139 -command { markerDrawAll }
140 checkbutton $w.switches.labels -text "Show labels" -variable show_marker_labels \
141 -command { markerDrawAll }
142 pack $w.switches.markers $w.switches.errors $w.switches.labels -side left -ipadx 2 -ipady 5 -pady 5 -padx 1m
143
144 setupEntry $w.tilt_axis "Tilt axis" double $tilt_axis "The general tilt axis angle starting from the x-axis and proceeding counter-clockwise"
145 checkbutton $w.tilt_axis.show -text "Show" -variable show_tilt_axis \
146 -command { drawTiltAxis }
147 bind $w.tilt_axis.e <Return> { setTiltAxis }
148 pack $w.tilt_axis.show -side left -padx 1m
149
150 setupEntry $w.marker_radius "Marker radius" double $marker_radius "The typical radius of fidicial markers in pixels"
151
152 frame $w.marker
153 label $w.marker.tag -text "Markers" -width 16 -anchor w
154 label $w.marker.num -width 10 -text "0" -relief sunken -bd 1 -anchor w
155 button $w.marker.tabbut -text "Marker table" \
156 -relief raised -command "markerTable"
157 pack $w.marker.tag $w.marker.num $w.marker.tabbut -side left -padx 1m
158
159 frame $w.selected
160 label $w.selected.numtag -text "Selected marker" -width 16 -anchor w
161 label $w.selected.num -width 4 -text "" -relief sunken -bd 1 -anchor w
162 label $w.selected.restag -text "Residual" -width 10 -anchor e
163 label $w.selected.res -width 6 -text "" -relief sunken -bd 1 -anchor w
164 label $w.selected.fomtag -text "FOM" -width 5 -anchor e
165 label $w.selected.fom -width 6 -text "" -relief sunken -bd 1 -anchor w
166 button $w.selected.refbut -text "Refine" \
167 -relief raised -command "refineMarker"
168 pack $w.selected.numtag $w.selected.num $w.selected.restag \
169 $w.selected.res $w.selected.fomtag $w.selected.fom \
170 $w.selected.refbut -side left -padx 1m
171
172 frame $w.resid
173 label $w.resid.tag -text "Residual" -width 16 -anchor w
174 label $w.resid.val -width 10 -text "" -relief sunken -bd 1 -anchor w
175 button $w.resid.update -text "Update" \
176 -relief raised -command "updateTomoTable"
177 pack $w.resid.tag $w.resid.val $w.resid.update -side left -padx 1m
178
179 frame $w.fom
180 label $w.fom.label -text "FOM cutoff" -width 16 -anchor w
181 scale $w.fom.scale -orient horizontal -length 300 -from 0 -to 1 \
182 -command { setFOMcutoff } -resolution 0.001
183 pack $w.fom.label $w.fom.scale -side left -padx 1m
184
185 frame $w.field
186 label $w.field.tag -text "Field" -width 16 -anchor w
187 label $w.field.str -width 50 -text $field -relief sunken -bd 1 -anchor w
188 pack $w.field.tag $w.field.str -side left -padx 1m
189
190 setupMicrographButtons $w.neighbor "micrograph"
191
192 label $w.header -font $helv12 -anchor w \
193 -text " Mg Tilt Axis Level OriginX OriginY ScaleX ScaleY Residual"
194
195 frame $w.frame
196 text $w.table -relief sunken -bd 2 -width 70\
197 -yscrollcommand ".wtomo.yscroll set" \
198 -setgrid 1 -highlightthickness 0 -pady 2 -padx 3 -font $cour12
199 scrollbar $w.yscroll -command ".wtomo.table yview" \
200 -highlightthickness 0 -orient vertical
201 grid $w.table -in $w.frame -padx 1 -pady 1 \
202 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
203 grid $w.yscroll -in $w.frame -padx 1 -pady 1 \
204 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
205 grid rowconfig $w.frame 0 -weight 1 -minsize 0
206 grid columnconfig $w.frame 0 -weight 1 -minsize 0
207
208 pack $w.switches $w.tilt_axis $w.marker_radius $w.marker $w.selected \
209 $w.resid $w.fom $w.field $w.neighbor -side top -pady 2 -padx 5 -anchor w
210 pack $w.header -side top -fill x -padx 5
211 pack $w.frame -expand yes -fill both -padx 5 -pady 5
212
213 # puts "Tomo window setup done"
214
215 updateTomoTable
216 updateMarkerParam
217 markerDrawAll
218
219 } else {
220 wm deiconify $w
221 raise $w
222 }
223
224 wm title $w "Tomography"
225 wm iconname $w "Tomography"
226 if { $tool == "marker_group" } {
227 set n [.image.scale get]
228 set mg_item [micrographItem $n]
229 set markers_selected [Bmg marker $mg_item selectrect -10000 -10000 10000 10000]
230 }
231
232 .menuBar.window entryconfigure "Tomography" -state normal
233 bind $c <1> "markerCreateSelect %x %y"
234 bind $c <2> "markerCreateSelect %x %y"
235 bind $c <Shift-1> "markerDelete %x %y"
236 bind $c <Shift-2> "markerDelete %x %y"
237 bind $c <B1-Motion> "markerMove %x %y"
238 bind $c <B2-Motion> "markerMove %x %y"
239 bind $c <ButtonRelease-1> "markerSetSelection %x %y"
240 bind $c <ButtonRelease-2> "markerSetSelection %x %y"
241 bind $w <Return> "Update 0"
242 bind $w <Control-w> { destroy .wtomo }
243 bind $w <Command-w> { destroy .wtomo }
244 bind . <Key-a> "markerAcceptModelLocation"
245 # bind . <Key-i> "invertSelection $c"
246 bind $c <Control-1> "markerSelectAppend %x %y"
247 bind $c <Command-1> "markerSelectAppend %x %y"
248 }
249
250 ## @brief Sets the tilt axis angle
251 #
252
253 proc setTiltAxis { } {
254 global tilt_axis project_item
255 set tilt_axis [.wtomo.tilt_axis.e get]
256 if [Bmg exists] {
257 Bmg set $project_item axis $tilt_axis
258 updateTomoTable
259 }
260 }
261
262 ## @brief Dialog box to set the tilts for a tomographic series
263
264 proc Tilts { } {
265 global helv12
266 global tilt_axis project_item
267 set tilt_axis [.wtomo.tilt_axis.e get]
268 set tilt_step 1
269 set tilt_start -60
270 if [Bmg exists] {
271 set mg_item [micrographItem 0]
272 set tilt_axis [expr [Bmg get $mg_item axis]]
273 set tilt_start [expr [Bmg get $mg_item tilt]]
274 set mg_item [micrographItem 1]
275 set tilt_step [expr [Bmg get $mg_item tilt] - $tilt_start]
276 }
277 set w .wtilt
278 if ![winfo exists $w] {
279 toplevel $w
280
281 setupEntry $w.tilt_step "Tilt step" double $tilt_step "The angular increment between micrographs"
282
283 setupEntry $w.tilt_start "Starting angle" double $tilt_start "The tilt angle of the first micrograph"
284
285 pack $w.tilt_start $w.tilt_step -side top -fill x -pady 2 -padx 15
286
287 frame $w.buttons
288 button $w.buttons.ok -text OK -command "setTilts_and_DestroyWindow .wtilt"
289 button $w.buttons.cancel -text Cancel -command "destroy .wtilt"
290 pack $w.buttons -side bottom -fill x -pady 2m
291 pack $w.buttons.ok $w.buttons.cancel -side left -expand 1
292
293 bind $w <Return> "setTilts_and_DestroyWindow .wtilt"
294 } else {
295 wm deiconify $w
296 raise $w
297 }
298 wm title $w "Tilts"
299 wm iconname $w "Tilts"
300 }
301
302 ## @brief Generates the tilt list for a tomographic series.
303 #
304 # @param w the window to destroy.
305
306 proc setTilts_and_DestroyWindow { w } {
307 global tilt_axis project_item
308 set step [expr [$w.tilt_step.e get]]
309 set start [expr [$w.tilt_start.e get]]
310 destroy $w
311 set nimg [Bmg get $project_item number_of_mg]
312 # puts "Number of micrographs = $nimg"
313 setTiltAxis
314 for {set i 0} {$i < $nimg} {incr i 1} {
315 set tilt [expr $start + $i * $step]
316 set mg_item [micrographItem $i]
317 Bmg set $mg_item tilt $tilt
318 }
319 Bmg update_matrices
320 updateTomoTable
321 }
322
323 ## @brief Reads tilt angles from a rawtlt file
324 #
325
326 proc readTlt { } {
327 global project_item
328 set types {
329 {"tlt files" {.tlt .TLT} }
330 {"rawtlt files" {.rawtlt .RAWTLT} }
331 }
332 set rawtltfile [tk_getOpenFile -filetypes $types]
333 if { [string length $rawtltfile] < 1 } { return}
334 set rawtltID [open $rawtltfile r]
335 set nimg [Bmg get $project_item number_of_mg]
336 set i 0
337 foreach line [split [read $rawtltID] \n] {
338 if { [scan $line "%g" tilt] > 0 } {
339 if { $i < $nimg } {
340 Bmg set $project_item tilt $tilt $i
341 }
342 incr i 1
343 }
344 }
345 close $rawtltID
346 set tilt_axis [.wtomo.tilt_axis.e get]
347 Bmg update_matrices
348 updateTomoTable
349 }
350
351 ## @brief Draws the tilt axis on the canvas
352 #
353
354 proc drawTiltAxis { } {
355 global theimg PI
356 global show_tilt_axis project_item
357 if ![Bmg exists] { return}
358 set c [getImageCanvas $theimg]
359 set wc [getControlWindow $theimg]
360 $c delete tilt_axis
361 if { [$wc.slice.scale get] > 1 } { set show_tilt_axis 0}
362 if { $show_tilt_axis < 1 } { return}
363 set img_num [$wc.image.scale get]
364 set mg_item [micrographItem $img_num]
365 set tax [expr [Bmg get $mg_item axis] * $PI/180.0]
366 set ang [expr [Bmg get $mg_item tilt] * $PI/180.0]
367 # puts "$mg_item $tax $ang"
368 set img_num [$wc.image.scale get]
369 set scale [$wc.scale.scale get]
370 set height [Bimage get $theimg height]
371 set radius [expr $height * $scale / 2]
372 set origin [Bmg get $mg_item origin]
373 set ox [expr [lindex $origin 0] * $scale]
374 set oy [expr ($height - [lindex $origin 1] - 1) * $scale]
375 set ct [expr cos($tax)]
376 set st [expr sin($tax)]
377 set dx [expr $radius*$ct]
378 set dy [expr $radius*$st]
379 set xs [expr $ox - $dx]
380 set ys [expr $oy + $dy]
381 set xe [expr $ox + $dx]
382 set ye [expr $oy - $dy]
383 $c create line $xs $ys $xe $ye -fill LightBlue -dash - -width 1.5 -tags tilt_axis
384 # puts "$tax $xs $ys $xe $ye"
385 # Note that this line points to the tomogram z-axis
386 set vlen [expr 0.1 * $height * $scale * sin($ang)]
387 set xe [expr $ox + $vlen*$st]
388 set ye [expr $oy + $vlen*$ct]
389 $c create line $ox $oy $xe $ye -fill LightBlue -width 1.5 -tags tilt_axis
390 # puts "$vlen $ox $oy $xe $ye"
391 }
392
393 ## @brief Selects a marker
394 #
395 # @param x
396 # @param y Marker position in canvas coordinates.
397
398 proc markerSelect { x y } {
399 if ![winfo exists .wtomo] { return}
400 global theimg project_item
401 global marker_radius markers_selected
402 global px py
403 global mx my
404 set c [getImageCanvas $theimg]
405 set wc [getControlWindow $theimg]
406 set marker_radius [.wtomo.marker_radius.e get]
407 Bmg set $project_item marker_radius $marker_radius
408 # puts $marker_radius
409 set n [$wc.image.scale get]
410 set z [$wc.slice.scale get]
411 set scale [$wc.scale.scale get]
412 set px [expr floor( [$c canvasx $x] / $scale )]
413 set py [expr floor( [$c canvasy $y] / $scale )]
414 set mx [expr int($px)]
415 set my [expr int($py)]
416 set myi [yFlip $my]
417 set mg_item [micrographItem $n]
418 set id [Bmg marker $mg_item select $mx $myi $z]
419 set markers_selected $id
420 set res [Bmg marker $mg_item residual $id]
421 set fom [Bmg marker $mg_item fom $id]
422 .wtomo.selected.num config -text "$id"
423 .wtomo.selected.res config -text "$res"
424 .wtomo.selected.fom config -text "$fom"
425 return $id
426 }
427
428 ## @brief Appends marker at a location to list of selected markers.
429 #
430 # @param x
431 # @param y Cursor position in window coordinates.
432
433 proc markerSelectAppend { x y } {
434 global markers_selected
435 set id [markerSelect $x $y]
436 if { $id < 1 } { return}
437 if { [lsearch $markers_selected $id] < 0 } {
438 lappend markers_selected $id
439 }
440 }
441
442 ## @brief The marker selection is reset and set to within a rectangle.
443 #
444 # @param x
445 # @param y Marker position in canvas coordinates.
446
447 proc markerSetSelection { x y } {
448 global theimg project_item
449 global markers_selected
450 global tool
451 global px py
452 # set markers_selected []
453 if { $tool != "marker_group" } { return}
454 set c [getImageCanvas $theimg]
455 set wc [getControlWindow $theimg]
456 set scale [$wc.scale.scale get]
457 set n [$wc.image.scale get]
458 set x1 $px
459 set y1 [yFlip $py]
460 set x2 [expr [$c canvasx $x] / $scale]
461 set y2 [yFlip [expr [$c canvasx $y] / $scale]]
462 # puts "$x1 $y1 $x2 $y2"
463 set mg_item [micrographItem $n]
464 set markers_selected [Bmg marker $mg_item selectrect $x1 $y1 $x2 $y2]
465 # puts "selected IDS = $markers_selected"
466 markerDrawAll
467 }
468
469 ## @brief Selects or creates a marker
470 #
471 # @param x
472 # @param y Marker position in canvas coordinates.
473
474 proc markerCreateSelect { x y } {
475 if ![winfo exists .wtomo] { return}
476 global theimg project_item
477 global marker_radius markers_selected
478 global tool
479 global px py
480 global mx my
481 set c [getImageCanvas $theimg]
482 set wc [getControlWindow $theimg]
483 set marker_radius [.wtomo.marker_radius.e get]
484 Bmg set $project_item marker_radius $marker_radius
485 # puts $marker_radius
486 set n [$wc.image.scale get]
487 set z [$wc.slice.scale get]
488 set scale [$wc.scale.scale get]
489 set px [expr floor( [$c canvasx $x] / $scale )]
490 set py [expr floor( [$c canvasy $y] / $scale )]
491 set mx [expr int($px)]
492 set my [expr int($py)]
493 set myi [yFlip $my]
494 set mg_item [micrographItem $n]
495 set id [Bmg marker $mg_item select $mx $myi $z]
496 # puts "selected ID = $id"
497 if { $id < 1 } {
498 $c delete selection
499 if { $tool == "marker" } {
500 set id [Bmg marker $mg_item create $mx $myi $z]
501 # puts "created ID = $id"
502 }
503 if { $tool == "marker_group" } {
504 set markers_selected []
505 }
506 }
507 if { $tool == "marker_group" } {
508 if { $id > 0 && [llength $markers_selected] == 0 } {
509 set markers_selected [Bmg marker $mg_item ids 0]
510 }
511 return
512 }
513 if { $id > 0 } {
514 set markers_selected $id
515 # Bmg marker $mg_item snap $id
516 set res [Bmg marker $mg_item residual $id]
517 set fom [Bmg marker $mg_item fom $id]
518 .wtomo.selected.num config -text "$id"
519 .wtomo.selected.res config -text "$res"
520 .wtomo.selected.fom config -text "$fom"
521 }
522 # puts "Selected IDs = $markers_selected"
523 markerDrawAll
524 # Update 0
525 }
526
527 ## @brief Generates markers from a seed.
528 #
529
530 proc markerGenerate { } {
531 global theimg
532 global show_tilt_axis project_item
533 set show_tilt_axis 1
534 Bmg marker $project_item generate
535 updateOrigins
536 Update 0
537 }
538
539 ## @brief Extracts markers from a micrograph.
540 #
541
542 proc markerExtract { } {
543 global filetypes
544 global filename project_item theimg
545 if ![winfo exists .wtomo] { return}
546 set wc [getControlWindow $theimg]
547 set xname [file root [file tail $filename]]
548 set xdir [file dirname $filename]
549 append xname "_marker.pif"
550 set xname [tk_getSaveFile -filetypes $filetypes \
551 -initialfile $xname -initialdir $xdir -defaultextension .pif]
552 if { [string length $xname] < 1 } { return}
553 setMgParam
554 set n [$wc.image.scale get]
555 set mg_item [micrographItem $n]
556 Bmg marker $mg_item extract $xname
557 }
558
559 ## @brief Moves the selected markers
560 #
561 # @param x
562 # @param y Mouse position in canvas coordinates.
563
564 proc markerMove { x y } {
565 if ![winfo exists .wtomo] { return}
566 global theimg
567 global markers_selected project_item
568 global tool
569 global px py
570 set c [getImageCanvas $theimg]
571 set wc [getControlWindow $theimg]
572 set scale [$wc.scale.scale get]
573 set cx [$c canvasx $x]
574 set cy [$c canvasy $y]
575 if { $tool == "marker_group" && [llength $markers_selected] == 0 } {
576 $c delete selection
577 set cpx [expr int($px * $scale)]
578 set cpy [expr int($py * $scale)]
579 $c create rectangle $cpx $cpy $cx $cy -tags selection -outline red
580 return
581 }
582 set n [$wc.image.scale get]
583 set ix [expr $cx / $scale]
584 set iy [expr $cy / $scale]
585 set dx [expr $ix - $px]
586 set dy [expr $py - $iy]
587 set px $ix
588 set py $iy
589 set mg_item [micrographItem $n]
590 foreach id $markers_selected {
591 Bmg marker $mg_item move $id $dx $dy
592 }
593 markerDrawAll
594 }
595
596 ## @brief Draws a marker with an error line and label.
597 #
598 # @param id Marker identifier.
599
600 proc markerDraw { id } {
601 global theimg project_item
602 global show_marker_errors show_marker_labels
603 global marker_color marker2_color marker_select_color error_color error_select_color
604 global marker_radius markers_selected
605 if ![winfo exists .wtomo] { return}
606 set c [getImageCanvas $theimg]
607 set wc [getControlWindow $theimg]
608 set z [$wc.slice.scale get]
609 set n [$wc.image.scale get]
610 set mg_item [micrographItem $n]
611 set locerr [Bmg marker $mg_item location $id]
612 # puts $locerr
613 set selflag [Bmg marker $mg_item getflag $id]
614 # puts $selflag
615 set zr [expr abs([lindex $locerr 2] - $z)]
616 set marker_radius [.wtomo.marker_radius.e get]
617 if { $zr > $marker_radius } { return}
618 set zr2 1
619 if { $zr > 0.1 && $marker_radius > 0 } {
620 set zr2 [expr sqrt(1 - $zr*$zr*1.0/($marker_radius*$marker_radius))]
621 }
622 set scale [$wc.scale.scale get]
623 set x [expr [lindex $locerr 0] * $scale]
624 set y [expr [yFlip [lindex $locerr 1]] * $scale]
625 set radius [expr $marker_radius * $scale * $zr2]
626 set ex [expr $x + [lindex $locerr 3] * $scale]
627 set ey [expr $y - [lindex $locerr 4] * $scale]
628 # puts "$id $locerr"
629 set xmin [expr $x - $radius]
630 set xmax [expr $x + $radius]
631 set ymin [expr $y - $radius]
632 set ymax [expr $y + $radius]
633 if { [lsearch $markers_selected $id] >= 0 } {
634 set markcolorshow $marker_select_color;
635 set errcolorshow $error_select_color;
636 } elseif { $selflag == 2 } {
637 set markcolorshow $marker2_color;
638 set errcolorshow $error_color;
639 } else {
640 set markcolorshow $marker_color;
641 set errcolorshow $error_color;
642 }
643 set idtag [format "m%d" $id]
644 $c create oval $xmin $ymin $xmax $ymax -outline $markcolorshow -width 1 -tags [list marker $idtag]
645 if { $show_marker_errors } {
646 $c create line $x $y $ex $ey -fill $errcolorshow -width 2 -tags [list marker $idtag]
647 }
648 if { $show_marker_labels } {
649 $c create text $xmax $y -text $id -fill $markcolorshow -anchor w -tags [list marker $idtag]
650 }
651 }
652
653 ## @brief Redraws all markers on the canvas
654 #
655
656 proc markerDrawAll {} {
657 global theimg project_item
658 global fom_cutoff
659 global show_markers
660 if ![winfo exists .wtomo] { return}
661 set c [getImageCanvas $theimg]
662 set wc [getControlWindow $theimg]
663 $c delete marker
664 if { $show_markers < 1 } { return}
665 set n [$wc.image.scale get]
666 set mg_item [micrographItem $n]
667 # puts "markerDrawAll $mg_item"
668 set ids [Bmg marker $mg_item ids $fom_cutoff]
669 # puts "fom_cutoff = $fom_cutoff"
670 # puts "IDs = $ids"
671 foreach id $ids {
672 # puts "drawing $id"
673 markerDraw $id
674 }
675 set nsel [Bmg marker $project_item count]
676 .wtomo.marker.num config -text "$nsel"
677 }
678
679 ## @brief Deletes the selected marker.
680 #
681 # @param x
682 # @param y Marker position in canvas coordinates.
683
684 proc markerDelete { x y } {
685 global project_item theimg
686 set wc [getControlWindow $theimg]
687 set n [$wc.image.scale get]
688 set id [markerSelect $x $y]
689 set mg_item [micrographItem $n]
690 if { $id > 0 } {
691 Bmg marker $mg_item delete $id
692 }
693 markerDrawAll
694 }
695
696 ## @brief Deletes the selected marker.
697 #
698 # @param id Marker identifier.
699
700 proc markerDeleteID { id } {
701 global project_item theimg
702 set wc [getControlWindow $theimg]
703 set n [$wc.image.scale get]
704 set mg_item [micrographItem $n]
705 if { $id > 0 } {
706 Bmg marker $mg_item delete $id
707 }
708 markerDrawAll
709 }
710
711 ## @brief Deletes all the selected markers.
712 #
713
714 proc markerDeleteSelected { } {
715 global markers_selected project_item theimg
716 set wc [getControlWindow $theimg]
717 set n [$wc.image.scale get]
718 # puts "IDs = $markers_selected"
719 set mg_item [micrographItem $n]
720 foreach id $markers_selected {
721 Bmg marker $mg_item delete $id
722 }
723 markerDrawAll
724 }
725
726 ## @brief Deletes all the selected markers in all images.
727 #
728
729 proc markerDeleteSelectedAll { } {
730 global markers_selected project_item
731 # puts "IDs = $markers_selected"
732 foreach id $markers_selected {
733 Bmg marker all delete $id
734 }
735 markerDrawAll
736 }
737
738 ## @brief Deletes all markers.
739 #
740
741 proc markerDeleteAll { } {
742 global theimg project_item
743 set c [getImageCanvas $theimg]
744 Bmg marker all delete all
745 $c delete marker
746 .wtomo.marker.num config -text "0"
747 }
748
749 ## @brief Renumbers markers in the current micrograph.
750 #
751
752 proc markerRenumber { } {
753 global project_item theimg
754 set wc [getControlWindow $theimg]
755 set n [$wc.image.scale get]
756 set mg_item [micrographItem $n]
757 Bmg marker $mg_item renumber
758 markerDrawAll
759 }
760
761 ## @brief Centers markers in the current micrograph.
762 #
763
764 proc markerCenter { } {
765 global project_item theimg
766 set wc [getControlWindow $theimg]
767 set n [$wc.image.scale get]
768 set mg_item [micrographItem $n]
769 Bmg marker $mg_item center
770 markerDrawAll
771 }
772
773
774 ## @brief Finds markers in a file.
775 #
776 # @param n Image number.
777
778 proc markerFind { n } {
779 global theimg
780 global marker_radius
781 global fom_cutoff project_item
782 if ![winfo exists .wtomo] { return}
783 set marker_radius [.wtomo.marker_radius.e get]
784 set mg_item [micrographItem $n]
785 set nmark [Bmg marker $mg_item find $marker_radius]
786 if { $nmark < 1 } {
787 tk_messageBox -icon error -type ok -title "Error" -message \
788 "No markers found!"
789 return
790 }
791
792 set max_fom [Bmg marker $mg_item fom_maximum]
793 set fom_cutoff [expr $max_fom / 2]
794 set fom_inc [expr $max_fom/100]
795 set h [Bimage get $theimg height]
796 set maxedge [expr int($h / 4)]
797 markerDrawAll
798
799 if { $nmark } {
800 set w .wtomfom
801 catch {destroy $w}
802 toplevel $w
803 wm title $w "Set the FOM cutoff"
804 wm iconname $w "FOMcut"
805 tkwait visibility $w
806 grab $w
807 frame $w.fom
808 label $w.fom.label -text "Choose a FOM cutoff and close this window before doing anything else" -anchor w
809 scale $w.fom.scale -orient horizontal -length 500 -from 0 -to $max_fom \
810 -command { setFOMcutoff } -resolution $fom_inc
811 label $w.fom.edgelabel -text "Choose an edge width in pixels to exclude markers" -anchor w
812 scale $w.fom.edge -orient horizontal -length 500 -from 0 -to $maxedge \
813 -command { setEdge } -resolution 1
814 button $w.fom.done -text "Done" -relief raised -command { destroy .wtomfom }
815 pack $w.fom.label -side top -fill x
816 pack $w.fom.scale -side top -fill x
817 pack $w.fom.edgelabel -side top -fill x
818 pack $w.fom.edge -side top -fill x
819 pack $w.fom.done -side right
820 $w.fom.scale set $fom_cutoff
821 pack $w.fom -side top -fill x -pady 2
822 tkwait window $w
823 }
824
825 Bmg marker $mg_item delete fom $fom_cutoff
826 Bmg marker $mg_item renumber
827 markerDrawAll
828 set fom_cutoff 0.0
829 }
830
831 proc setEdge { edge } {
832 global project_item theimg
833 set wc [getControlWindow $theimg]
834 set n [$wc.image.scale get]
835 set mg_item [micrographItem $n]
836 Bmg marker $mg_item edge $edge
837 Update 0
838 }
839
840 ## @brief Centers the selected marker.
841 #
842 # @param x
843 # @param y Marker position in canvas coordinates.
844
845 proc markerSnap { x y } {
846 global project_item theimg
847 set wc [getControlWindow $theimg]
848 set n [$wc.image.scale get]
849 set id [markerSelect $x $y]
850 set mg_item [micrographItem $n]
851 if { $id > 0 } {
852 Bmg marker $mg_item snap $id
853 }
854 markerDrawAll
855 }
856
857 ## @brief Updates the residual calculation which also sets all marker residuals.
858 #
859
860 proc updateResidual { } {
861 global project_item
862 if ![winfo exists .wtomo] { return}
863 # puts "Updating residuals"
864 set resid [Bmg marker $project_item residual]
865 .wtomo.resid.val config -text $resid
866 }
867
868 ## @brief Updates the tomographic table from the micrograph parameters in memory.
869 #
870
871 proc updateTomoTable { } {
872 global tilt_axis project_item
873 if ![winfo exists .wtomo] { return}
874 if ![Bmg exists] { return}
875 set act [Bmg get all active]
876 # puts "Updating tomo table with active = $act"
877 set nmg [Bmg get $project_item number_of_mg]
878 if { $nmg < 1 } { return}
879 # puts "Number of micrographs: $nmg"
880 Bmg set all active 0
881 updateResidual
882 set wt 0.0
883 set tax 0.0
884 set table ""
885 for { set i 0} { $i < $nmg } { incr i 1} {
886 set mg_item [micrographItem $i]
887 # puts "Project: $project_item mg: $mg_item"
888 set axis [expr [Bmg get $mg_item axis]]
889 set tilt [expr [Bmg get $mg_item tilt]]
890 set level [expr [Bmg get $mg_item level]]
891 set origin [Bmg get $mg_item origin]
892 set scale [Bmg get $mg_item scale]
893 set ox [lindex $origin 0]
894 set oy [lindex $origin 1]
895 set sx [lindex $scale 0]
896 set sy [lindex $scale 1]
897 set fom [Bmg get $mg_item fom]
898 # puts "$i $tilt $axis $level $ox $oy $sx $sy $fom"
899 append table [format " %3d %6.2f %6.2f %6.2f %6.1f %6.1f %5.3f %5.3f %6.3f\n" $i $tilt $axis $level $ox $oy $sx $sy $fom]
900 if { [expr abs($tilt)] > 2 } {
901 set w1 [expr 1 - exp(-$tilt*$tilt/0.5)]
902 set tax [expr $tax + $axis]
903 set wt [expr $wt + $w1]
904 }
905 }
906 Bmg set all active $act
907 if { $wt } { set tilt_axis [expr $tax / $wt]}
908 .wtomo.tilt_axis.e delete 0 end
909 .wtomo.tilt_axis.e insert 0 $tilt_axis
910 .wtomo.field.str config -text [Bmg get $project_item field]
911 .wtomo.table delete 1.0 end
912 .wtomo.table insert 1.0 $table
913 drawTiltAxis
914 }
915
916 ## @brief Updates marker parameters from the micrograph parameters in memory.
917 #
918
919 proc updateMarkerParam { } {
920 global marker_radius project_item
921 if ![Bmg exists] { return}
922 # puts "Updating marker parameters"
923 updatePixelsize
924 set r [Bmg get $project_item marker_radius]
925 if { $r } {
926 set marker_radius $r
927 }
928 Bmg set $project_item marker_radius $r
929 if [winfo exists .wtomo] {
930 .wtomo.marker_radius.e delete 0 end
931 .wtomo.marker_radius.e insert 0 $marker_radius
932 }
933 }
934
935 ## @brief Sets the selection flag for the selected markers.
936 #
937
938 proc markerSetSelectFlag { } {
939 global markers_selected project_item theimg
940 set wc [getControlWindow $theimg]
941 set n [$wc.image.scale get]
942 set mg_item [micrographItem $n]
943 foreach id $markers_selected {
944 Bmg marker $mg_item setflag $id
945 }
946 updateMarkerTable
947 }
948
949 ## @brief Clears the selection flag for the selected markers.
950 #
951
952 proc markerClearSelectFlag { } {
953 global markers_selected project_item theimg
954 set wc [getControlWindow $theimg]
955 set n [$wc.image.scale get]
956 set mg_item [micrographItem $n]
957 foreach id $markers_selected {
958 Bmg marker $mg_item clearflag $id
959 }
960 updateMarkerTable
961 }
962
963 ## @brief Sets up the window for the marker table and updates it.
964 #
965
966 proc markerTable { } {
967 if ![winfo exists .wtomo] { return}
968 if ![Bmg exists] { return}
969 global cour12 helv12
970 global refop hires lores
971 set w .wmark
972 if ![winfo exists $w] {
973 toplevel $w
974
975 frame $w.frame
976 text $w.table -relief sunken -bd 2 -width 40\
977 -yscrollcommand "$w.yscroll set" \
978 -setgrid 1 -highlightthickness 0 -pady 2 -padx 3 -font $cour12
979 scrollbar $w.yscroll -command "$w.table yview" \
980 -highlightthickness 0 -orient vertical
981 grid $w.table -in $w.frame -padx 1 -pady 1 \
982 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
983 grid $w.yscroll -in $w.frame -padx 1 -pady 1 \
984 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
985 grid rowconfig $w.frame 0 -weight 1 -minsize 0
986 grid columnconfig $w.frame 0 -weight 1 -minsize 0
987
988 label $w.header -font $helv12 -anchor w \
989 -text " Mg Marker Residual FOM Select"
990
991 pack $w.header -side top -fill x -padx 5
992 pack $w.frame -expand yes -fill both -padx 5 -pady 5
993
994 frame $w.butres
995 label $w.butres.label -font $helv12 -anchor w -text Residual -width 8
996 button $w.butres.min -text "|<" -command "markerNextResidual $w min"
997 button $w.butres.lower -text "<" -command "markerNextResidual $w lower"
998 button $w.butres.higher -text ">" -command "markerNextResidual $w higher"
999 button $w.butres.max -text ">|" -command "markerNextResidual $w max"
1000 entry $w.butres.entry -width 10 -validate key -vcmd [list checkType double %P]
1001
1002 frame $w.butfom
1003 label $w.butfom.label -font $helv12 -anchor w -text FOM -width 8
1004 button $w.butfom.min -text "|<" -command "markerNextFOM $w min"
1005 button $w.butfom.lower -text "<" -command "markerNextFOM $w lower"
1006 button $w.butfom.higher -text ">" -command "markerNextFOM $w higher"
1007 button $w.butfom.max -text ">|" -command "markerNextFOM $w max"
1008 entry $w.butfom.entry -width 10 -validate key -vcmd [list checkType double %P]
1009
1010 frame $w.flag
1011 button $w.flag.clear -text "Clear selection" -command "markerClearSelectFlag"
1012 button $w.flag.set -text "Set selection" -command "markerSetSelectFlag"
1013
1014 frame $w.buttons
1015 button $w.buttons.update -text Update -command "updateMarkerTable"
1016 button $w.buttons.close -text Close -command "destroy $w"
1017
1018 pack $w.butres.label $w.butres.min $w.butres.lower \
1019 $w.butres.entry $w.butres.higher $w.butres.max -side left -expand 1
1020 pack $w.butfom.label $w.butfom.min $w.butfom.lower \
1021 $w.butfom.entry $w.butfom.higher $w.butfom.max -side left -expand 1
1022 pack $w.flag.clear $w.flag.set -side left -expand 1
1023 pack $w.buttons.update $w.buttons.close -side left -expand 1
1024
1025 pack $w.buttons -side bottom -fill x -pady 2m
1026 pack $w.flag -side bottom -fill x -pady 2m
1027 pack $w.butfom -side bottom -fill x -pady 2m
1028 pack $w.butres -side bottom -fill x -pady 2m
1029
1030 $w.table tag configure selmark -background #a0b7ce
1031 # bind $w <Return> "doMarkerRefine $w"
1032 } else {
1033 wm deiconify $w
1034 raise $w
1035 }
1036 wm title $w "Marker list"
1037 wm iconname $w "Markers"
1038 updateMarkerTable
1039 }
1040
1041 ## @brief Updates the marker table.
1042 #
1043
1044 proc updateMarkerTable {} {
1045 global markers_selected project_item
1046 if ![winfo exists .wmark] { return}
1047 # puts "Updating tomography table parameters"
1048 updateResidual
1049 set m [Bmg marker $project_item list]
1050 set table ""
1051 foreach {img_num id res fom sel} $m {
1052 append table [format " %4d %4d %7.3f %7.3f %4d\n" $img_num $id $res $fom $sel]
1053 }
1054 .wmark.table delete 1.0 end
1055 .wmark.table insert 1.0 $table
1056 }
1057
1058 ## @brief Centers the viewable canvas on the location in the image.
1059 #
1060 # @param img_num image number.
1061 # @param loc location list.
1062
1063 proc moveCanvasTo { img_num loc } {
1064 global theimg
1065 set c [getImageCanvas $theimg]
1066 set wc [getControlWindow $theimg]
1067 $wc.image.scale set $img_num
1068 set scale [$wc.scale.scale get]
1069 set wd [Bimage get $theimg width]
1070 set ht [Bimage get $theimg height]
1071 set ws [expr [winfo width $c] / (2.0 * $scale)]
1072 set hs [expr [winfo height $c] / (2.0 * $scale)]
1073 set fx [expr ([lindex $loc 0] - $ws) / $wd]
1074 set fy [expr ($ht - [lindex $loc 1] - 1 - $hs) / $ht]
1075 $c xview moveto $fx
1076 $c yview moveto $fy
1077 }
1078
1079 ## @brief Goes to a marker.
1080 #
1081 # @param w dialog window.
1082 # @param id marker identifier
1083 # @param isel offset in table ?
1084 # @param img micrograph index
1085
1086 proc goToMarker { w id isel img } {
1087 global markers_selected project_item
1088 if { $id <= 0 } { return}
1089 set markers_selected $id
1090 set mg_item [micrographItem $img]
1091 set locerr [Bmg marker $mg_item location $id]
1092 moveCanvasTo $img $locerr
1093 $w.butres.entry delete 0 end
1094 $w.butres.entry insert 0 [Bmg marker $mg_item residual $id]
1095 $w.butfom.entry delete 0 end
1096 $w.butfom.entry insert 0 [Bmg marker $mg_item fom $id]
1097 $w.table tag add selmark $isel.0 $isel.end
1098 set isel [expr $isel - 3]
1099 if { $isel < 0 } { set isel 0}
1100 $w.table yview $isel
1101 markerDrawAll
1102 }
1103
1104 ## @brief Goes to the next marker based on its residual.
1105 #
1106 # @param w dialog window.
1107 # @param dir direction: min, lower, higher, max
1108
1109 proc markerNextResidual { w dir } {
1110 global markers_selected
1111 global theimg project_item
1112 set wc [getControlWindow $theimg]
1113 $w.table tag remove selmark 1.0 end
1114 set sgn 1
1115 set n -1
1116 set previd -1
1117 set prevres -1
1118 set ressel -1
1119 if { $dir == "min" || $dir == "higher" } {
1120 set sgn -1
1121 set ressel 1e10
1122 }
1123 if { $dir == "max" } { set prevres 1e10}
1124 if { $dir == "min" || $dir == "max" } {
1125 set markers_selected []
1126 }
1127 if { [llength $markers_selected] > 0 } {
1128 set n [$wc.image.scale get]
1129 set mg_item [micrographItem $n]
1130 set previd [lindex $markers_selected 0]
1131 set prevres [Bmg marker $mg_item residual $previd]
1132 # puts "1. $n $previd $prevres"
1133 }
1134 set m [Bmg marker $project_item list]
1135 set i 0
1136 set isel 0
1137 set img 0
1138 set idsel 0
1139 foreach {img_num id res fom sel} $m {
1140 incr i
1141 if { $sel } {
1142 set dr [expr $sgn * ($ressel - $res)]
1143 set pdr [expr $sgn * ($res - $prevres)]
1144 if { !($img_num == $n && $id == $previd) && $dr < 0 && $pdr < 0 } {
1145 set img $img_num
1146 set idsel $id
1147 set ressel $res
1148 set isel $i
1149 }
1150 }
1151 }
1152 if { $idsel > 0 } {
1153 goToMarker $w $idsel $isel $img
1154 }
1155 # puts "2. $img $idsel $ressel"
1156 }
1157
1158 ## @brief Goes to next marker based on its FOM.
1159 #
1160 # @param w dialog window.
1161 # @param dir direction: min, lower, higher, max
1162
1163 proc markerNextFOM { w dir } {
1164 global markers_selected
1165 global theimg project_item
1166 set wc [getControlWindow $theimg]
1167 $w.table tag remove selmark 1.0 end
1168 set sgn 1
1169 set n -1
1170 set previd -1
1171 set prevfom -1
1172 set fomsel -1
1173 if { $dir == "min" || $dir == "higher" } {
1174 set sgn -1
1175 set fomsel 1e10
1176 }
1177 if { $dir == "max" } { set prevfom 1e10}
1178 if { $dir == "min" || $dir == "max" } {
1179 set markers_selected []
1180 }
1181 if { [llength $markers_selected] > 0 } {
1182 set n [$wc.image.scale get]
1183 set mg_item [micrographItem $n]
1184 set previd [lindex $markers_selected 0]
1185 set prevfom [Bmg marker $mg_item fom $previd]
1186 # puts "1. $n $previd $prevfom"
1187 }
1188 set m [Bmg marker $project_item list]
1189 set i 0
1190 set isel 0
1191 set img 0
1192 set idsel 0
1193 foreach {img_num id res fom sel} $m {
1194 incr i
1195 if { $sel } {
1196 set df [expr $sgn * ($fomsel - $fom)]
1197 set pdf [expr $sgn * ($fom - $prevfom)]
1198 if { !($img_num == $n && $id == $previd) && $df < 0 && $pdf < 0 } {
1199 set img $img_num
1200 set idsel $id
1201 set fomsel $fom
1202 set isel $i
1203 }
1204 }
1205 }
1206 if { $idsel > 0 } {
1207 goToMarker $w $idsel $isel $img
1208 }
1209 # puts "2. $img $idsel $fomsel"
1210 }
1211
1212 ## @brief Accepts the model locations of selected markers.
1213 #
1214
1215 proc markerAcceptModelLocation { } {
1216 global markers_selected
1217 global theimg project_item
1218 if { [llength $markers_selected] < 1 } { return}
1219 set wc [getControlWindow $theimg]
1220 set n [$wc.image.scale get]
1221 set mg_item [micrographItem $n]
1222 foreach id $markers_selected {
1223 Bmg marker $mg_item accept $id
1224 }
1225 markerDrawAll
1226 updateMarkerTable
1227 }
1228
1229 ##### Workflow #####
1230
1231 ## @brief Aligns a series of frames from dose fractionation.
1232 #
1233
1234 proc alignAverageFrames {} {
1235 global paramfile
1236 set w .wframes
1237 if ![winfo exists $w] {
1238 toplevel $w
1239
1240 set newfile [file rootname $paramfile]
1241 append newfile "_aln_avg.star"
1242
1243 frame $w.head
1244 label $w.head.lab -text \
1245 "The frame alignment and averaging will be done using the currently saved parameter file: $paramfile"
1246
1247 setupNewFileEntry $w.file "Output parameter file" $newfile \
1248 "New parameter file written after averaging the frames"
1249
1250 setupEntry $w.refnum "Reference frame" integer 3 "Number of reference frame to use for the initial progressive alignment"
1251
1252 labelframe $w.res -text "Resolution limits"
1253 setupEntry $w.res.hi "High" double 20 "High resolution limit in Å"
1254 setupEntry $w.res.lo "Low" double 1000 "Low resolution limit in Å"
1255 pack $w.res.hi $w.res.lo -side top -expand 1
1256
1257 setupEntry $w.bin "Binning" integer 2 "Binning to speed up alignment"
1258
1259 setupEntry $w.shift "Shift limit" double 20 "Limit to cross-correlation shift allowed"
1260
1261 pack $w.head.lab
1262 pack $w.head $w.file $w.refnum $w.res $w.bin $w.shift \
1263 -side top -fill x -pady 2 -padx 15
1264
1265 frame $w.buttons
1266 button $w.buttons.do -text Do -command "doAlignAverageFrames $w"
1267 button $w.buttons.close -text Close -command "destroy $w"
1268 pack $w.buttons -side bottom -fill x -pady 2m
1269 pack $w.buttons.do $w.buttons.close -side left -expand 1
1270
1271 bind $w <Return> "doAlignAverageFrames $w"
1272 } else {
1273 wm deiconify $w
1274 raise $w
1275 }
1276 wm title $w "AlignFrames"
1277 wm iconname $w "AlignFrames"
1278 }
1279
1280 ## @brief Aligns and averages frames.
1281 #
1282 # @param w dialog window.
1283
1284 proc doAlignAverageFrames { w } {
1285 global env paramfile
1286 set newfile [$w.file.e get]
1287 set refnum [$w.refnum.e get]
1288 set hires [$w.res.hi.e get]
1289 set lores [$w.res.lo.e get]
1290 set bin [$w.bin.e get]
1291 set shift [$w.shift.e get]
1292 setMgParam
1293 if { ![file exists $paramfile] } {
1294 puts "$paramfile not found!"
1295 }
1296 set logfile "[file rootname $newfile].log"
1297 set cmd "$env(BSOFT)/bin/bseries -verb 1 -frames -align $refnum -resol $hires,$lores -shift $shift -bin $bin -out $newfile -average t.pif $paramfile"
1298 executeCommand $cmd $logfile
1299 }
1300
1301 ## @brief Normalizes a series of images based on simple statistics.
1302 #
1303
1304 proc normalizeImages {} {
1305 global paramfile
1306 global norm_type
1307 set w .wnorm
1308 if ![winfo exists $w] {
1309 toplevel $w
1310
1311 set newfile [file rootname $paramfile]
1312 append newfile "_norm.star"
1313
1314 frame $w.head
1315 label $w.head.lab -text \
1316 "The normalization will be done using the currently saved parameter file: $paramfile"
1317
1318 setupNewFileEntry $w.file "Output parameter file" $newfile \
1319 "New parameter file written after normalizing the micrographs"
1320
1321 frame $w.type
1322 label $w.type.l -text "Normalization type"
1323 tk_optionMenu $w.type.v norm_type "Simple" "Gaussian" "Poisson"
1324 pack $w.type.l $w.type.v -side left -ipadx 2
1325
1326 pack $w.head.lab
1327 pack $w.head $w.file $w.type -side top -fill x -pady 2 -padx 15
1328
1329 frame $w.buttons
1330 button $w.buttons.do -text Do -command "doNormalizeImages $w"
1331 button $w.buttons.close -text Close -command "destroy $w"
1332 pack $w.buttons -side bottom -fill x -pady 2m
1333 pack $w.buttons.do $w.buttons.close -side left -expand 1
1334
1335 bind $w <Return> "doFindTiltAxis $w"
1336 } else {
1337 wm deiconify $w
1338 raise $w
1339 }
1340 wm title $w "FindAxis"
1341 wm iconname $w "FindAxis"
1342 }
1343
1344 ## @brief Normalizes images.
1345 #
1346 # @param w dialog window.
1347
1348 proc doNormalizeImages { w } {
1349 global env paramfile
1350 global norm_type
1351 set newfile [$w.file.e get]
1352 setMgParam
1353 if { ![file exists $paramfile] } {
1354 puts "$paramfile not found!"
1355 }
1356 set logfile "[file rootname $newfile].log"
1357 set cmd "$env(BSOFT)/bin/bnorm -v 1 -data float -type $norm_type -out $newfile $paramfile"
1358 executeCommand $cmd $logfile
1359 }
1360
1361 # findTiltAxis
1362 # Locates the tilt axis.
1363 #
1364
1365 proc findTiltAxis { } {
1366 global paramfile
1367 global hires lores
1368 set w .wtax
1369 if ![winfo exists $w] {
1370 toplevel $w
1371
1372 set newfile [file rootname $paramfile]
1373 append newfile "_findaxis.star"
1374
1375 frame $w.head
1376 label $w.head.lab -text \
1377 "The search for the tilt axis angle will use the currently saved parameter file: $paramfile"
1378
1379 setupNewFileEntry $w.file "Output parameter file" $newfile \
1380 "New parameter file written after searching for the tilt axis"
1381
1382 setupEntry $w.tlt "Tilt angle" double 15 "Tilt angle to find tilt axis"
1383
1384 labelframe $w.tax -text "Tilt axis search range"
1385 setupEntry $w.tax.start "Start" double -180 "Starting angle to test for the tilt axis"
1386 setupEntry $w.tax.end "End" double 180 "Ending angle to test for the tilt axis"
1387 setupEntry $w.tax.inc "Increment" double 1 "Angle increment to test for the tilt axis"
1388 pack $w.tax.start $w.tax.end $w.tax.inc -side top -expand 1
1389
1390 labelframe $w.res -text "Resolution limits"
1391 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1392 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1393 pack $w.res.hi $w.res.lo -side top -expand 1
1394
1395 pack $w.head.lab
1396 pack $w.head $w.file $w.tlt $w.tax $w.res -side top -fill x -pady 2 -padx 15
1397
1398 frame $w.buttons
1399 button $w.buttons.do -text Do -command "doFindTiltAxis $w"
1400 button $w.buttons.close -text Close -command "destroy $w"
1401 pack $w.buttons -side bottom -fill x -pady 2m
1402 pack $w.buttons.do $w.buttons.close -side left -expand 1
1403
1404 bind $w <Return> "doFindTiltAxis $w"
1405 } else {
1406 wm deiconify $w
1407 raise $w
1408 }
1409 wm title $w "FindAxis"
1410 wm iconname $w "FindAxis"
1411 }
1412
1413 ## @brief Executes the tilt axis search.
1414 #
1415 # @param w dialog window.
1416
1417 proc doFindTiltAxis { w } {
1418 global env paramfile
1419 global tilt_axis hires lores
1420 set newfile [$w.file.e get]
1421 set tlt [$w.tlt.e get]
1422 set start [$w.tax.start.e get]
1423 set end [$w.tax.end.e get]
1424 set step [$w.tax.inc.e get]
1425 set hires [$w.res.hi.e get]
1426 set lores [$w.res.lo.e get]
1427 setMgParam
1428 if { ![file exists $paramfile] } {
1429 puts "$paramfile not found!"
1430 }
1431 set logfile "[file rootname $newfile].log"
1432 # Bmg findaxis $axis $start $end $step $hires $lores
1433 set cmd "$env(BSOFT)/bin/btrack -verb 1 -findaxis $tlt,$step,$start,$end -resol $hires,$lores -out $newfile $paramfile"
1434 executeCommand $cmd $logfile
1435 }
1436
1437 # markerTransfer
1438 # Transfers markers from one tilt series to a second.
1439 #
1440
1441 proc markerTransfer { } {
1442 global paramfile
1443 global hires lores refine
1444 set w .wtrans
1445 if ![winfo exists $w] {
1446 toplevel $w
1447
1448 labelframe $w.ang -text "Rotation angle search range"
1449 setupEntry $w.ang.start "Start" double -180 "Starting angle to find transfer rotation"
1450 setupEntry $w.ang.end "End" double 180 "Ending angle to find transfer rotation"
1451 setupEntry $w.ang.inc "Increment" double 1 "Angle increment to find transfer rotation"
1452 pack $w.ang.start $w.ang.end $w.ang.inc -side top -expand 1
1453
1454 labelframe $w.res -text "Resolution limits"
1455 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1456 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1457 pack $w.res.hi $w.res.lo -side top -expand 1
1458
1459 setupEntry $w.shift "Shift limit" double 100 "Limit on how much the second image may shift to fit the first"
1460
1461 checkbutton $w.refine -text "Refine markers" -anchor e -variable refine
1462
1463 pack $w.ang $w.res $w.shift $w.refine -side top -fill x -pady 2 -padx 15
1464
1465 frame $w.buttons
1466 button $w.buttons.do -text Do -command "doMarkerTransfer $w"
1467 button $w.buttons.close -text Close -command "destroy $w"
1468 pack $w.buttons -side bottom -fill x -pady 2m
1469 pack $w.buttons.do $w.buttons.close -side left -expand 1
1470
1471 bind $w <Return> "doMarkerTransfer $w"
1472 } else {
1473 wm deiconify $w
1474 raise $w
1475 }
1476 wm title $w "Transfer"
1477 wm iconname $w "Transfer"
1478 }
1479
1480 ## @brief Executes the marker transfer.
1481 #
1482 # @param w dialog window.
1483
1484 proc doMarkerTransfer { w } {
1485 global env paramfile
1486 global tilt_axis hires lores refine
1487 set start [$w.ang.start.e get]
1488 set end [$w.ang.end.e get]
1489 set step [$w.ang.inc.e get]
1490 set hires [$w.res.hi.e get]
1491 set lores [$w.res.lo.e get]
1492 set shift [$w.shift.e get]
1493 setMgParam
1494 if { ![file exists $paramfile] } {
1495 puts "$paramfile not found!"
1496 }
1497 Bmg transfer $start $end $step $hires $lores $shift $refine
1498 updateOrigins
1499 updateTomoTable
1500 markerDrawAll
1501 }
1502
1503 ## @brief Tracks the markers through the tilt series.
1504 #
1505
1506 proc markerTrack { } {
1507 global paramfile
1508 global hires lores recenter cc_type
1509 global shift_limit thickness
1510 checkParamFile
1511 set w .wtrk
1512 if ![winfo exists $w] {
1513 toplevel $w
1514
1515 set newfile [file rootname $paramfile]
1516 append newfile "_trk.star"
1517 set logfile [file rootname $paramfile]
1518 append logfile "_trk.log"
1519
1520 frame $w.head
1521 label $w.head.lab -text \
1522 "Tracking will be done on the currently saved parameter file: $paramfile"
1523 pack $w.head.lab
1524
1525 setupNewFileEntry $w.file "Output parameter file" $newfile \
1526 "New parameter file written after tracking"
1527
1528 setupEntry $w.track "Iterations" integer 5 "Number of iterative tracking cycles"
1529 setupEntry $w.term "Target residual" double 1 \
1530 "The desired residual to terminate before the set number of cycles"
1531
1532 labelframe $w.res -text "Resolution limits"
1533 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1534 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1535 pack $w.res.hi $w.res.lo -side top -expand 1
1536
1537 setupEntry $w.shift "Shift limit" double $shift_limit \
1538 "The maximum number of pixels of shift allowed"
1539 setupEntry $w.thick "Thickness" double $thickness \
1540 "The estimated maximum thickness of the tomogram"
1541 checkbutton $w.cc_type -text "Cross-correlate markers" -anchor e -variable cc_type
1542 checkbutton $w.recenter -text "Recenter" -anchor e -variable recenter
1543
1544 pack $w.head $w.file $w.track $w.term $w.res $w.shift $w.thick \
1545 $w.cc_type $w.recenter -side top -pady 2 -padx 10
1546
1547 frame $w.buttons
1548 button $w.buttons.do -text Do -command "doMarkerTrack $w"
1549 button $w.buttons.close -text Close -command "destroy $w"
1550 pack $w.buttons -side bottom -fill x -pady 2m
1551 pack $w.buttons.do $w.buttons.close -side left -expand 1
1552
1553 bind $w <Return> "doMarkerTrack $w"
1554 } else {
1555 wm deiconify $w
1556 raise $w
1557 }
1558 wm title $w "Track"
1559 wm iconname $w "Track"
1560 }
1561
1562 ## @brief Executes marker tracking.
1563 #
1564 # @param w dialog window.
1565
1566 proc doMarkerTrack { w } {
1567 global env paramfile
1568 global hires lores recenter cc_type
1569 set newfile [$w.file.e get]
1570 set iter [$w.track.e get]
1571 set term [$w.term.e get]
1572 set hires [$w.res.hi.e get]
1573 set lores [$w.res.lo.e get]
1574 set shift [$w.shift.e get]
1575 set thick [$w.thick.e get]
1576 setMgParam
1577 if { ![file exists $paramfile] } {
1578 puts "$paramfile not found!"
1579 }
1580 set cct ""
1581 set rec ""
1582 if { $cc_type } { set cct "-cross"}
1583 if { $recenter } { set rec "-recenter"}
1584 if { $term < 0.1 } { set term 1}
1585 set logfile "[file rootname $newfile].log"
1586 set psfile "[file rootname $newfile].ps"
1587 # puts "logfile = $logfile"
1588 set cmd "$env(BSOFT)/bin/btrack -verb 1 -reset -update -track $iter,$term -resol $hires,$lores -shift $shift -thick $thick $cct $rec -Post $psfile -out $newfile $paramfile"
1589 executeCommand $cmd $logfile
1590 }
1591
1592 ## @brief Refines marker positions and micrograph geometry.
1593 #
1594
1595 proc markerRefine { } {
1596 global helv12
1597 global refop hires lores
1598 set w .wref
1599 if ![winfo exists $w] {
1600 toplevel $w
1601
1602 frame $w.mark
1603 radiobutton $w.mark.m -text "Markers" -variable refop -value "m"
1604 pack $w.mark.m -side left -pady 5
1605
1606 labelframe $w.res -text "Resolution limits"
1607 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1608 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1609 pack $w.res.hi $w.res.lo -side top -expand 1
1610
1611 frame $w.z
1612 radiobutton $w.z.z -text "Z-coordinates" -variable refop -value "z"
1613
1614 frame $w.mg
1615 radiobutton $w.mg.g -text "Micrographs" -variable refop -value "a"
1616 checkbutton $w.mg.v -text "Views" -variable ref_view
1617 checkbutton $w.mg.o -text "Origins" -variable ref_ori
1618 checkbutton $w.mg.s -text "Scales" -variable ref_scale
1619
1620 pack $w.z.z -side left -pady 5
1621 pack $w.mg.g $w.mg.v $w.mg.o $w.mg.s -side left -pady 5
1622 pack $w.mark $w.res $w.z $w.mg -side top -fill x -pady 2 -padx 15
1623
1624 frame $w.buttons
1625 button $w.buttons.do -text Do -command "doMarkerRefine $w"
1626 button $w.buttons.close -text Close -command "destroy $w"
1627 pack $w.buttons -side bottom -fill x -pady 2m
1628 pack $w.buttons.do $w.buttons.close -side left -expand 1
1629
1630 bind $w <Return> "doMarkerRefine $w"
1631 } else {
1632 wm deiconify $w
1633 raise $w
1634 }
1635 wm title $w "Refine"
1636 wm iconname $w "Refine"
1637 }
1638
1639 ## @brief Does a refinement of markers or views.
1640 #
1641 # @param w dialog window.
1642
1643 proc doMarkerRefine { w } {
1644 global refop ref_view ref_ori ref_scale
1645 global hires lores
1646 set hires [$w.res.hi.e get]
1647 set lores [$w.res.lo.e get]
1648 setMgParam
1649 # puts "$refop $ref_view $ref_ori $ref_scale"
1650 if { $refop == "m" } {
1651 Bmg refine $refop $hires $lores
1652 } else {
1653 Bmg refine $refop $ref_view $ref_ori $ref_scale
1654 }
1655 updateOrigins
1656 updateTomoTable
1657 markerDrawAll
1658 }
1659
1660 ## @brief Refines one marker position.
1661 #
1662
1663 proc refineMarker { } {
1664 global markers_selected
1665 global hires lores
1666 set hires 20
1667 set lores 1000
1668 set w .wref
1669 if [winfo exists $w] {
1670 set hires [$w.mark.hientry get]
1671 set lores [$w.mark.loentry get]
1672 }
1673 Bmg refine_one $markers_selected $hires $lores
1674 updateTomoTable
1675 markerDrawAll
1676 }
1677
1678 ## @brief Dialog box for calculating tilt-adjusted power spectra
1679 #
1680
1681 proc tomoPowerSpectra { } {
1682 global paramfile theimg
1683 global volt Cs amp_fac defocus
1684 global tilex tiley tilez
1685 global hires lores
1686 set w .wps
1687 if ![winfo exists $w] {
1688 toplevel $w
1689
1690 set newfile [file rootname $paramfile]
1691 append newfile "_ps.star"
1692
1693 frame $w.head
1694 label $w.head.lab -text \
1695 "The power spectra will be calculated using the currently saved parameter file: $paramfile"
1696 pack $w.head.lab
1697
1698 setupNewFileEntry $w.file "Output parameter file" $newfile \
1699 "New parameter file written after calculating the power spectra"
1700
1701 setupEntry $w.volt "Voltage" double $volt "Acceleration voltage in kV"
1702 setupEntry $w.cs "Cs" double $Cs "Spherical aberration in mm"
1703 setupEntry $w.amp "Amplitude" double $amp_fac "Amplitude contrast as a fraction"
1704 setupEntry $w.def "Defocus" double $defocus "Average defocus in um"
1705
1706 labelframe $w.tiles -text "Tile size:"
1707 setupEntry $w.tiles.x "x" integer $tilex "X-size for tiles to calculate power spectra"
1708 setupEntry $w.tiles.y "y" integer $tiley "Y-size for tiles to calculate power spectra"
1709 pack $w.tiles.x $w.tiles.y -side top -expand 1
1710
1711 labelframe $w.res -text "Resolution limits"
1712 setupEntry $w.res.hi "High" double 8 "High resolution limit in Å"
1713 setupEntry $w.res.lo "Low" double 30 "Low resolution limit in Å"
1714 pack $w.res.hi $w.res.lo -side top -expand 1
1715
1716 labelframe $w.deflim -text "Defocus limits"
1717 setupEntry $w.deflim.lo "Low" double 1.0 "Low defocus limit in µm"
1718 setupEntry $w.deflim.hi "High" double 5.0 "High defocus limit in µm"
1719 pack $w.deflim.lo $w.deflim.hi -side top -expand 1
1720
1721 pack $w.head $w.file $w.volt $w.cs $w.amp $w.def $w.tiles $w.res \
1722 $w.deflim -side top -fill x -pady 2 -padx 15
1723
1724 frame $w.buttons
1725 button $w.buttons.do -text Do -command "doTomoPowerSpectra $w"
1726 button $w.buttons.close -text Close -command "destroy $w"
1727 pack $w.buttons -side bottom -fill x -pady 2m
1728 pack $w.buttons.do $w.buttons.close -side left -expand 1
1729
1730 bind $w <Return> "doTomoResolution $w"
1731 } else {
1732 wm deiconify $w
1733 raise $w
1734 }
1735 wm title $w "Power spectrum"
1736 wm iconname $w "Power spectrum"
1737 }
1738
1739 ## @brief Calculating tilt-adjusted power spectra
1740 #
1741
1742 proc doTomoPowerSpectra { w } {
1743 global env paramfile
1744 global volt Cs amp_fac defocus
1745 global tilex tiley tilez
1746 global hires lores recenter
1747 set newfile [$w.file.e get]
1748 set volt [$w.volt.e get]
1749 set Cs [$w.cs.e get]
1750 set amp_fac [$w.amp.e get]
1751 set defocus [$w.def.e get]
1752 set tilex [$w.tiles.x.e get]
1753 set tiley [$w.tiles.y.e get]
1754 set hires [$w.res.hi.e get]
1755 set lores [$w.res.lo.e get]
1756 set lodef [$w.deflim.lo.e get]
1757 set hidef [$w.deflim.hi.e get]
1758 setMgParam
1759 if { ![file exists $paramfile] } {
1760 puts "$paramfile not found!"
1761 }
1762 set logfile "[file rootname $newfile].log"
1763 set cmd "$env(BSOFT)/bin/bctf -verb 1 -act prepfit -tile $tilex,$tiley,1 -Volt $volt -Cs $Cs -Amp $amp_fac -Defocus $defocus -Range $lodef,$hidef -resol $hires,$lores -fitastig 2 -out $newfile $paramfile"
1764 executeCommand $cmd $logfile
1765 }
1766
1767 ## @brief Estimates the resolution of images in a tilt series.
1768 #
1769
1770 proc tomoResolution { } {
1771 global paramfile theimg
1772 global hires samrat
1773 set w .wres
1774 if ![winfo exists $w] {
1775 toplevel $w
1776
1777 set psfile [file rootname $paramfile]
1778 append psfile "_res.ps"
1779
1780 frame $w.head
1781 label $w.head.lab -text \
1782 "Resolution will be estimated using the currently saved parameter file: $paramfile"
1783 pack $w.head.lab
1784
1785 frame $w.ps
1786 label $w.ps.lab -text "Output Postscript file" -width 20 -anchor w
1787 entry $w.ps.entry -width 40
1788 $w.ps.entry insert 0 $psfile
1789 pack $w.ps.lab $w.ps.entry -side left -pady 5
1790
1791 setupEntry $w.fast "Fast angle" double 10 "Limit images added to each reconstruction"
1792 setupEntry $w.res "High resolution" double $hires "Spatial frequency limit for reconstructions"
1793 setupEntry $w.rat "Sampling ratio" double $samrat "Ratio to average adjacent frequency shells (≥1)"
1794 setupEntry $w.cut "FRC cutoff" double 0.3 "Fourier ring correlation threshold to report resolution"
1795 setupEntry $w.ctf "CTF correction" alnum "none" "Contrast transfer function correction algorithm"
1796
1797 pack $w.head $w.ps $w.fast $w.res $w.rat $w.cut $w.ctf -side top -fill x -pady 2 -padx 15
1798
1799 frame $w.buttons
1800 button $w.buttons.do -text Do -command "doTomoResolution $w"
1801 button $w.buttons.close -text Close -command "destroy $w"
1802 pack $w.buttons -side bottom -fill x -pady 2m
1803 pack $w.buttons.do $w.buttons.close -side left -expand 1
1804
1805 bind $w <Return> "doTomoResolution $w"
1806 } else {
1807 wm deiconify $w
1808 raise $w
1809 }
1810 wm title $w "Resolution"
1811 wm iconname $w "Resolution"
1812 }
1813
1814 ## @brief Executes estimation of the resolution of the tilt series.
1815 #
1816 # @param w dialog window.
1817
1818 proc doTomoResolution { w } {
1819 global env paramfile
1820 global hires samrat
1821 set psfile [$w.ps.entry get]
1822 set fast [$w.fast.e get]
1823 set hires [$w.res.e get]
1824 set samrat [$w.rat.e get]
1825 set cut [$w.cut.e get]
1826 set ctf [$w.ctf.e get]
1827 if { $ctf == "none" } {
1828 set ctf ""
1829 } else {
1830 set ctf "-CTF $ctf"
1831 }
1832 setMgParam
1833 if { ![file exists $paramfile] } {
1834 puts "$paramfile not found!"
1835 }
1836 set logfile "[file rootname $psfile].log"
1837 set cmd "$env(BSOFT)/bin/btomres -verb 1 -fast $fast -resol $hires -ratio $samrat $ctf -cut $cut -Post $psfile $paramfile"
1838 executeCommand $cmd $logfile
1839 }
1840
1841 ## @brief Reconstructs a tomogram.
1842 #
1843
1844 proc tomoReconstruct { } {
1845 global paramfile theimg project_item
1846 global hires lores
1847 set w .wrec
1848 if ![winfo exists $w] {
1849 toplevel $w
1850
1851 set sz [Bmg get $project_item size]
1852 set x [lindex $sz 0]
1853 set y [lindex $sz 1]
1854 set z [expr $x/10]
1855
1856 set recfile [file rootname $paramfile]
1857 append recfile "_rec.pif"
1858 set newfile [file rootname $paramfile]
1859 append newfile "_rec.star"
1860
1861 frame $w.head
1862 label $w.head.lab -text \
1863 "Reconstruction will be done using the currently saved parameter file: $paramfile"
1864
1865 frame $w.rec
1866 label $w.rec.l -text "Output reconstruction" -width 20 -anchor w
1867 entry $w.rec.e -width 40
1868 $w.rec.e insert 0 $recfile
1869 pack $w.rec.l $w.rec.e -side left -pady 5
1870
1871 setupNewFileEntry $w.file "Output parameter file" $newfile \
1872 "New parameter file written after reconstruction"
1873
1874 setupEntry $w.interp "Type" integer 0 "Reconstruction interpolation type: 0=nearest neighbor, 1=weighted, 2=trilinear"
1875
1876 labelframe $w.size -text "Reconstruction size"
1877 setupEntry $w.size.x "x" double $x "Reconstruction x size"
1878 setupEntry $w.size.y "y" double $y "Reconstruction y size"
1879 setupEntry $w.size.z "z" double $z "Reconstruction z size"
1880 pack $w.size.x $w.size.y $w.size.z -side top -expand 1
1881
1882 setupEntry $w.scale "Scale" double 1 "Reconstruction scale"
1883 setupEntry $w.res "High resolution" double $hires "Spatial frequency limit for reconstruction"
1884 setupEntry $w.remark "Marker deletion radius" double 0 "If greater than 0, discs of this radius will be deleted from micrographs"
1885 setupEntry $w.edge "Edge smoothing width" double 3 "If greater than 0, the micrograph edges and extraneous areas will be deleted"
1886 setupEntry $w.ctf "CTF correction" alnum "none" "Contrast transfer function correction algorithm"
1887
1888 pack $w.head.lab
1889 # pack $w.file.lab $w.file.entry $w.file.load -side left -pady 5
1890 pack $w.head $w.rec $w.file $w.interp $w.size $w.scale $w.res $w.remark $w.edge $w.ctf -side top -fill x -pady 2 -padx 15
1891
1892 frame $w.buttons
1893 button $w.buttons.do -text Do -command "doTomoReconstruct $w"
1894 button $w.buttons.close -text Close -command "destroy $w"
1895 pack $w.buttons -side bottom -fill x -pady 2m
1896 pack $w.buttons.do $w.buttons.close -side left -expand 1
1897
1898 bind $w <Return> "doTomoReconstruct $w"
1899 } else {
1900 wm deiconify $w
1901 raise $w
1902 }
1903 wm title $w "Reconstruct"
1904 wm iconname $w "Reconstruct"
1905 }
1906
1907 ## @brief Executes tomogram reconstruction.
1908 #
1909 # @param w dialog window.
1910
1911 proc doTomoReconstruct { w } {
1912 global env paramfile
1913 global hires
1914 set recfile [$w.rec.e get]
1915 set newfile [$w.file.e get]
1916 set interp [$w.interp.e get]
1917 set x [$w.size.x.e get]
1918 set y [$w.size.y.e get]
1919 set z [$w.size.z.e get]
1920 set scale [$w.scale.e get]
1921 set hires [$w.res.e get]
1922 set remark [$w.remark.e get]
1923 set edge [$w.edge.e get]
1924 set ctf [$w.ctf.e get]
1925 set remove ""
1926 if { $remark > 0 } { set remove "-remove $remark"}
1927 set smooth ""
1928 if { $edge > 0 } { set smooth "-edge $edge"}
1929 if { $ctf == "none" } {
1930 set ctf ""
1931 } else {
1932 set ctf "-CTF $ctf"
1933 }
1934 setMgParam
1935 if { ![file exists $paramfile] } {
1936 puts "$paramfile not found!"
1937 }
1938 set logfile "[file rootname $newfile].log"
1939 set cmd "$env(BSOFT)/bin/btomrec -verb 1,tim -interp $interp -size $x,$y,$z -scale $scale -resol $hires $ctf -rescale 0,1 -trans full $remove $smooth -rec $recfile -out $newfile $paramfile"
1940 executeCommand $cmd $logfile
1941 }
1942
1943 ## @brief Denoises a tomogram.
1944 #
1945
1946 proc tomoDenoise { } {
1947 global paramfile theimg project_item
1948 global hires lores
1949 set w .wrec
1950 if ![winfo exists $w] {
1951 toplevel $w
1952
1953 set denfile [file rootname [Bmg get $project_item filename rec]]
1954 # set denfile [file rootname $paramfile]
1955 append denfile "_den.pif"
1956 set newfile [file rootname $paramfile]
1957 append newfile "_den.star"
1958
1959 frame $w.head
1960 label $w.head.lab -text \
1961 "Denoising will be done using the currently saved parameter file: $paramfile"
1962
1963 frame $w.den
1964 label $w.den.l -text "Output denoised map" -width 20 -anchor w
1965 entry $w.den.e -width 40
1966 $w.den.e insert 0 $denfile
1967 pack $w.den.l $w.den.e -side left -pady 5
1968
1969 setupNewFileEntry $w.file "Output parameter file" $newfile \
1970 "New parameter file written after denoising"
1971
1972 setupEntry $w.iter "Iterations" integer 100 "Number of iterative denoising cycles"
1973 setupEntry $w.out "Output frequency" integer 10 "Number of iterations between writing intermediate denoised images"
1974 setupEntry $w.slab "Slab size" integer 100 "Denoising slab size for parallel processing"
1975
1976 pack $w.head.lab
1977 # pack $w.log.lab $w.log.entry -side left -pady 5
1978 pack $w.head $w.den $w.file $w.iter $w.out $w.slab -side top -fill x -pady 2 -padx 15
1979
1980 frame $w.buttons
1981 button $w.buttons.do -text Do -command "doTomoDenoise $w"
1982 button $w.buttons.close -text Close -command "destroy $w"
1983 pack $w.buttons -side bottom -fill x -pady 2m
1984 pack $w.buttons.do $w.buttons.close -side left -expand 1
1985
1986 bind $w <Return> "doTomoDenoise $w"
1987 } else {
1988 wm deiconify $w
1989 raise $w
1990 }
1991 wm title $w "Denoise"
1992 wm iconname $w "Denoise"
1993 }
1994
1995 ## @brief Executes tomogram denoising.
1996 #
1997 # @param w dialog window.
1998
1999 proc doTomoDenoise { w } {
2000 global env paramfile project_item
2001 global hires
2002 set recfile [Bmg get $project_item filename rec]
2003 set denfile [$w.den.e get]
2004 set newfile [$w.file.e get]
2005 set iter [$w.iter.e get]
2006 set out [$w.out.e get]
2007 set slab [$w.slab.e get]
2008 setMgParam
2009 if { ![file exists $paramfile] } {
2010 puts "$paramfile not found!"
2011 }
2012 set logfile "[file rootname $newfile].log"
2013 # set cmd "$env(BSOFT)/bin/bnad -verb 1 -iter $iter -out $out -slab $slab -map $denfile -out $newfile $paramfile"
2014 set cmd "$env(BSOFT)/bin/bnad -verb 1 -iter $iter -out $out -slab $slab $recfile $denfile"
2015 executeCommand $cmd $logfile
2016 }
2017
2018