| Bsoft 2.0.5 Bernard's software package

bshow_boxes.tcl
Go to the documentation of this file.
1 ##
2 # @file bshow_boxes.tcl
3 #
4 # @brief Procedures to create, move and destroy particle boxes
5 #
6 # @author Bernard Heymann
7 # @date Created: 20010516
8 # @date Modified: 20191017
9
10 set show_boxes 1
11 set show_bad 1
12 set show_box_labels 1
13 set part_sel 1
14 set auto_renum 1
15 set box_color_mode "Uniform"
16 set fom_min 0
17 set fom_max 1
18 set sel_min 0
19 set sel_max 1
20 set box_size "100 100 100"
21 set bad_radius 20
22 set contrast 0
23 set box_selected 0
24 set scale 1
25 set thetemp "thetemp"
26 set peach 0
27
28 ## @brief Dialog box to manipulate particle boxes on the main canvas
29 #
30
31 proc Particles { } {
32 global project_item theimg imgtype
33 global box_size bad_radius box_selected part_sel mg_sel
34
35 if ![Bimage exists $theimg] {
36 tk_dialog .dialog "No image in memory!" \
37 {Please read in an appropriate image first.} \
38 info 0 {OK}
39 return
40 }
41
42 set c [getImageCanvas $theimg]
43 set filename [Bimage get $theimg filename]
44 if ![Bmg exists] {
45 createMgParam
46 setMgParam
47 }
48 # puts "Launching Particles for $c: $project_item"
49 if { [string length $imgtype] < 1 } { set imgtype "mg"}
50 if { [lindex $box_size 0] < 1 } { set box_size "100 100 100"}
51 if { $bad_radius < 1 } { set bad_radius [expr int([lindex $box_size 0] / 4)]}
52 # puts "Box size: $box_size"
53 # puts "Bad radius: $bad_radius"
54
55 set typelabel ""
56 if { $imgtype == "mg" } {
57 set typelabel "micrograph"
58 } elseif { $imgtype == "frame" } {
59 set typelabel "frames"
60 } elseif { $imgtype == "rec" } {
61 set typelabel "reconstruction"
62 } elseif { $imgtype == "part" } {
63 set typelabel "particle"
64 if { $box_selected <= 0 } {
65 set box_selected 1
66 }
67 }
68 # puts "$imgtype: $box_selected"
69
70 set w .wbox
71 if ![winfo exists $w] {
72 if { $imgtype != "mg" && $imgtype != "rec" && $imgtype != "part" && $imgtype != "frame" } {
73 set i [tk_dialog .dialog "No micrograph, reconstruction or particle!" \
74 {Please read in an appropriate image first.} \
75 info 0 {Cancel} {Proceed anyway}]
76 if { $i < 1 } { return}
77 }
78
79 toplevel $w
80
81 menu $w.menuBar -tearoff 0
82 $w.menuBar add cascade -menu $w.menuBar.box -label "Boxes" -underline 0
83 menu $w.menuBar.box -tearoff 0
84 $w configure -menu $w.menuBar
85 $w.menuBar.box add command -label "Help" -underline 0 \
86 -command { showURL "file://$Bsoft/doc/bshow/bshow_part.html" }
87 # -command { showHelp bshow_boxes.hlp }
88 $w.menuBar.box add command -label "Delete all boxes" \
89 -command { boxDeleteAll } -underline 0
90 $w.menuBar.box add command -label "Delete boxes in current image" \
91 -command { boxDeleteCurrent } -underline 0
92 $w.menuBar.box add command -label "Delete unselected boxes" \
93 -command { boxDeleteUnselected } -underline 0
94 $w.menuBar.box add command -label "Renumber particles" \
95 -command { boxRenumber } -underline 0
96 $w.menuBar.box add command -label "Center particles" \
97 -command { boxCenter } -underline 0
98 $w.menuBar.box add command -label "Template picker" \
99 -command { templatePicker } -underline 0
100 $w.menuBar.box add command -label "Variance picker" \
101 -command { variancePicker } -underline 0
102 $w.menuBar.box add command -label "Extract particles from current image" \
103 -command { extractParticles } -underline 0
104 $w.menuBar.box add command -label "Show selected particles" \
105 -command { showSelectedParticles } -underline 0
106 $w.menuBar.box add command -label "Close" \
107 -command { "destroy $w" } -underline 0
108
109 $w.menuBar add cascade -menu $w.menuBar.spaflow -label "Workflow" -underline 0
110 menu $w.menuBar.spaflow -tearoff 0
111 $w configure -menu $w.menuBar
112 $w.menuBar.spaflow add command -label "Extract particles" \
113 -command { extractParticles } -underline 0
114 $w.menuBar.spaflow add command -label "Align particles" \
115 -command { alignParticles } -underline 0
116 $w.menuBar.spaflow add command -label "Refine particles" \
117 -command { refineParticles } -underline 0
118 $w.menuBar.spaflow add command -label "Select particles" \
119 -command { selectParticles } -underline 0
120 $w.menuBar.spaflow add command -label "Reconstruct" \
121 -command { particleReconstruct } -underline 0
122
123 set idx [Bmg get $project_item index_of_mg]
124 set nmg [Bmg get all number_of_mg]
125
126 setupMicrographID $w.mgid
127
128 setupSizeEntry $w.box_size "Box size" integer $box_size "Particle box size in pixels/voxels"
129 setupEntry $w.bad_radius "Bad radius" double $bad_radius "Bad area radius in pixels/voxels"
130
131 frame $w.number
132 label $w.number.tag -text "Particles picked: mg" -width 20 -anchor w
133 label $w.number.num -width 6 -text "0" -relief sunken -bd 1 -anchor w
134 label $w.number.tag2 -text "project" -width 10 -anchor w
135 label $w.number.num2 -width 6 -text "0" -relief sunken -bd 1 -anchor w
136 pack $w.number.tag $w.number.num $w.number.tag2 $w.number.num2 -side left -padx 1m
137
138 frame $w.nbad
139 label $w.nbad.tag -text "Bad regions" -width 20 -anchor w
140 label $w.nbad.num -width 10 -text "0" -relief sunken -bd 1 -anchor w
141 pack $w.nbad.tag $w.nbad.num -side left -padx 1m
142
143 frame $w.sel
144 label $w.sel.tag -text "Current particle" -width 20 -anchor w
145 label $w.sel.id -width 6 -text "0" -relief sunken -bd 1 -anchor w
146 label $w.sel.fom -width 6 -text "0" -relief sunken -bd 1 -anchor w
147 # checkbutton $w.sel.set -text "Selection" -variable part_sel \
148 -command { updatePartSel }
149 tk_optionMenu $w.sel.set part_sel 0 1 2 3 4 5 6 7 8 9 10 \
150 11 12 13 14 15 16 17 18 19 20
151 pack $w.sel.tag $w.sel.id $w.sel.fom $w.sel.set -side left -padx 1m
152
153 frame $w.fom
154 label $w.fom.label -text "FOM" -anchor w
155 scale $w.fom.scale -orient horizontal -length 400 -from 0 -to 1 \
156 -command { setFOMcutoff } -resolution 0.001
157 pack $w.fom.label $w.fom.scale -side top -fill x -padx 1m
158
159 frame $w.switches
160 checkbutton $w.switches.boxes -text "Show boxes" -variable show_boxes \
161 -command { boxesDrawAll }
162 checkbutton $w.switches.labels -text "Show labels" -variable show_box_labels \
163 -command { boxesDrawAll }
164 checkbutton $w.switches.bad -text "Show bad areas" -variable show_bad \
165 -command { boxesDrawAll }
166 pack $w.switches.boxes $w.switches.labels $w.switches.bad \
167 -side left -ipadx 5 -ipady 5 -padx 1m
168
169 frame $w.switches2
170 checkbutton $w.switches2.autorenum -text "Automatic renumbering" -variable auto_renum \
171 -command { boxesDrawAll }
172 # checkbutton $w.switches2.fomcolor -text "Color by FOM" -variable color_by_fom \
173 # -command { boxesDrawAll }
174 tk_optionMenu $w.switches2.color box_color_mode \
175 "Uniform" "FOM" "Selection"
176 pack $w.switches2.autorenum $w.switches2.color \
177 -side left -ipadx 5 -ipady 5 -padx 1m
178
179 setupMicrographButtons $w.neighbor $typelabel
180
181 pack $w.mgid $w.box_size $w.bad_radius $w.number $w.nbad $w.sel $w.fom \
182 $w.switches $w.switches2 $w.neighbor -side top -fill x -pady 2
183
184 updateBoxParam
185 } else {
186 wm deiconify $w
187 raise $w
188 }
189 wm title $w [list "Particles:" $filename]
190 wm iconname $w "Particles"
191 .menuBar.window entryconfigure "Particles" -state normal
192 bind $c <1> "boxCreateSelect %x %y part"
193 bind $c <Shift-1> "boxDelete %x %y"
194 bind $c <Control-1> "boxCreateSelect %x %y bad"
195 bind $c <2> "boxCreateSelect %x %y bad"
196 bind $c <B1-Motion> "boxMove %x %y"
197 bind $c <B2-Motion> "boxMove %x %y"
198 bind $w <Return> "Update 0"
199 bind $w <Control-w> { destroy $w }
200 bind $w <Command-w> { destroy $w }
201 trace add variable part_sel write updatePartSel
202 boxesDrawAll
203 }
204
205 ## @brief Sets the 3 dimensions for a box from the entries.
206 #
207
208 proc setBoxSize { } {
209 set w .wbox
210 if ![winfo exists $w] { return}
211 global theimg project_item
212 global box_size bad_radius
213 # puts "Setting box size for $theimg: $project_item"
214 # set wc [getControlWindow $theimg]
215
216 set box_size_x [$w.box_size.x get]
217 set box_size_y [$w.box_size.y get]
218 set box_size_z [$w.box_size.z get]
219 set box_size "$box_size_x $box_size_y $box_size_z"
220 if { [lindex $box_size 0] < 1 } { set box_size "50 50 50"}
221 set bad_radius [$w.bad_radius.e get]
222 # puts "setBoxSize [$wc.slice.scale cget -to]"
223
224 if { [Bimage get $theimg nslices] < 2 } {
225 set box_size [lreplace $box_size 2 2 1]
226 $w.box_size.z delete 0 end
227 $w.box_size.z insert 0 "1"
228 }
229
230 Bmg set $project_item box_size [lindex $box_size 0] [lindex $box_size 1] [lindex $box_size 2]
231 Bmg set $project_item bad_radius $bad_radius
232 # puts "setBoxSize: $box_size"
233 }
234
235 ## @brief Selects a box or bad area near a clicked location
236 #
237 # @param x
238 # @param y Box position in canvas coordinates.
239
240 proc boxSelect { x y } {
241 if ![winfo exists .wbox] { return}
242 global project_item
243 global box_selected
244 global tool
245 setBoxSize
246 set loc [imageCoordinatesFromCanvas $x $y]
247 set id [Bmg box $project_item select [lindex $loc 0] [lindex $loc 1] [lindex $loc 2]]
248 boxDrawOldNew $id
249 return $id
250 }
251
252 ## @brief Creates or selects a box or bad area near a clicked location
253 #
254 # @param x
255 # @param y Box position in canvas coordinates.
256 # @param t Type: "part"/"bad"
257
258 proc boxCreateSelect { x y t } {
259 if ![winfo exists .wbox] { return}
260 global project_item
261 global box_selected part_sel
262 global tool
263 setBoxSize
264 set loc [imageCoordinatesFromCanvas $x $y]
265 set id [Bmg box $project_item select [lindex $loc 0] [lindex $loc 1] [lindex $loc 2]]
266 # puts "selected ID = $id"
267 if { $id == 0 && $tool == "box" } {
268 set id [Bmg box $project_item create [lindex $loc 0] [lindex $loc 1] [lindex $loc 2] $t $part_sel]
269 # puts "created ID = $id"
270 }
271 boxDrawOldNew $id
272 return $id
273 }
274
275 proc boxDrawOldNew { id } {
276 if ![winfo exists .wbox] { return}
277 global box_selected
278 if { $id != $box_selected } {
279 set tid $box_selected
280 set box_selected $id
281 boxDraw $tid
282 }
283 if { $id != 0 } {
284 boxDraw $id
285 updateBoxSelected
286 updateBoxCounts
287 # puts "selected ID = $id"
288 }
289 }
290
291 ## @brief Moves the selected box or bad area to the new coordinates.
292 #
293 # @param x
294 # @param y Box position in canvas coordinates.
295
296 proc boxMove { x y } {
297 if ![winfo exists .wbox] { return}
298 global project_item theimg
299 global box_selected
300 global px py
301 if { $box_selected == 0 } { return}
302 set c [getImageCanvas $theimg]
303 set wc [getControlWindow $theimg]
304 set scale [$wc.scale.scale get]
305 set ix [expr [$c canvasx $x] / $scale]
306 set iy [expr [$c canvasy $y] / $scale]
307 set dx [expr $ix - $px]
308 set dy [expr $py - $iy]
309 set px $ix
310 set py $iy
311 # puts "Moving $dx $dy"
312 Bmg box $project_item move $box_selected $dx $dy
313 boxesDrawAll
314 }
315
316
317 ## @brief Draws a box or bad area
318 #
319 # Draws a box and circle with the current box size and number
320 # for a selected box, or draws a red circle with the current bad size
321 # for a selected bad area.
322 #
323 # @param id Box or bad area identifier.
324
325 proc boxDraw { id } {
326 global project_item theimg
327 global box_selected box_color_mode
328 global show_box_labels box_color box_select_color bad_color bad_select_color
329 global fom_min fom_max
330 global sel_min sel_max
331 if ![winfo exists .wbox] { return}
332 if { $id == 0 } { return}
333 set c [getImageCanvas $theimg]
334 set wc [getControlWindow $theimg]
335 set n [$wc.image.scale get]
336 set z [$wc.slice.scale get]
337 set mg_item [micrographItem $n]
338 set loc [Bmg box $mg_item location $id]
339 # puts "Location for $mg_item $id: $loc"
340 if { [lindex $loc 0] < 0 } {
341 puts "ID $id not found!"
342 return
343 }
344 set scale [$wc.scale.scale get]
345 set scale_1 [expr $scale - 1]
346 set yi [yFlip [lindex $loc 1]]
347 set xr [expr [lindex $loc 0] * $scale]
348 set yr [expr $yi * $scale]
349 set zr [expr abs([lindex $loc 2] - $z)]
350 if { $id > 0 } {
351 set box_radius_x [expr [.wbox.box_size.x get] * 0.5]
352 set box_radius_y [expr [.wbox.box_size.y get] * 0.5]
353 set box_radius_z [expr [.wbox.box_size.z get] * 0.5]
354 if { $zr > $box_radius_z } { return}
355 set zr2 1
356 if { $box_radius_z > 0 } {
357 set zr [expr $zr*1.0/$box_radius_z]
358 set zr2 [expr sqrt(1 - $zr*$zr)]
359 }
360 # puts "$xr $yr"
361 set box_radius_x [expr $box_radius_x * $scale]
362 set box_radius_y [expr $box_radius_y * $scale]
363 set oval_radius_x [expr $box_radius_x*$zr2]
364 set oval_radius_y [expr $box_radius_y*$zr2]
365 set xmin [expr $xr - $box_radius_x]
366 set xmax [expr $xr + $box_radius_x + $scale_1]
367 set ymin [expr $yr - $box_radius_y]
368 set ymax [expr $yr + $box_radius_y + $scale_1]
369 set cxmin [expr $xr - $oval_radius_x]
370 set cxmax [expr $xr + $oval_radius_x + $scale_1]
371 set cymin [expr $yr - $oval_radius_y]
372 set cymax [expr $yr + $oval_radius_y + $scale_1]
373 set idtag [format "box%d" $id]
374 if { [string compare $box_color_mode "FOM"] == 0 } {
375 set fom [Bmg box $project_item fom $id]
376 set color [spectrum $fom $fom_min $fom_max]
377 } elseif { [string compare $box_color_mode "Selection"] == 0 } {
378 set sel [Bmg box $project_item select $id]
379 set color [spectrum $sel $sel_min $sel_max]
380 } elseif { [lsearch $box_selected $id] >= 0 } {
381 set color $box_select_color;
382 } else {
383 set color $box_color;
384 }
385 $c create rect $xmin $ymin $xmax $ymax -outline $color -width 1 -tags [list box $idtag]
386 $c create oval $cxmin $cymin $cxmax $cymax -outline $color -width 1 -tags [list box $idtag]
387 if { $show_box_labels } {
388 $c create text $xr $yr -text $id -fill $color -tags [list box $idtag]
389 }
390 } elseif { $id < 0 } {
391 set bad_radius [.wbox.bad_radius.e get]
392 if { $zr > $bad_radius } { return}
393 set bad_radius [expr $scale * sqrt($bad_radius*$bad_radius - $zr*$zr)]
394 set xmin [expr $xr - $bad_radius]
395 set xmax [expr $xr + $bad_radius + $scale_1]
396 set ymin [expr $yr - $bad_radius]
397 set ymax [expr $yr + $bad_radius + $scale_1]
398 if { [lsearch $box_selected $id] >= 0 } {
399 set color $bad_select_color;
400 } else {
401 set color $bad_color;
402 }
403 $c create oval $xmin $ymin $xmax $ymax -outline $color -width 1 -tags bad
404 }
405 }
406
407 ## @brief Redraws all boxes and bad circles.
408 #
409
410 proc boxesDrawAll { } {
411 global project_item theimg
412 global imgtype fom_cutoff
413 global show_boxes show_bad
414 set c [getImageCanvas $theimg]
415 # set wc [getControlWindow $theimg]
416 # puts "Drawing boxes for $theimg: $project_item"
417 $c delete box bad
418 if { [string compare $imgtype "mg"] && [string compare $imgtype "rec"] } { return}
419 if ![winfo exists .wbox] { return}
420 setBoxSize
421 updateBoxCounts
422 if { $show_boxes } {
423 # puts "Getting box IDs for cutoff = $fom_cutoff"
424 set ids [Bmg box $project_item ids $fom_cutoff]
425 foreach id $ids {
426 boxDraw $id
427 }
428 }
429 # puts "Boxes drawn"
430 if { $show_bad } {
431 set ids [Bmg box $project_item ids bad]
432 foreach id $ids {
433 boxDraw $id
434 }
435 }
436 # puts "Done"
437 }
438
439
440 ## @brief Deletes the selected box or bad area.
441 #
442 # @param x
443 # @param y Box or bad area position in canvas coordinates.
444
445 proc boxDelete { x y } {
446 if ![winfo exists .wbox] { return}
447 global theimg project_item
448 global boxes_selected
449 global auto_renum
450 set wc [getControlWindow $theimg]
451 set n [$wc.image.scale get]
452 set id [boxSelect $x $y]
453 # puts "ID to be deleted = $id"
454 if { $id != 0 } {
455 Bmg box $project_item delete $id
456 if { $auto_renum } { Bmg box $project_item renumber}
457 }
458 boxesDrawAll
459 }
460
461 ## @brief Deletes all boxes.
462 #
463
464 proc boxDeleteAll { } {
465 global project_item theimg
466 Bmg box $project_item delete all
467 set c [getImageCanvas $theimg]
468 $c delete box bad
469 .wbox.number.num config -text "0"
470 .wbox.nbad.num config -text "0"
471 }
472
473 ## @brief Deletes all boxes in current image.
474 #
475
476 proc boxDeleteCurrent { } {
477 global project_item theimg
478 Bmg box $project_item delete current
479 boxesDrawAll
480 }
481
482 ## @brief Deletes all unselected boxes.
483 #
484
485 proc boxDeleteUnselected { } {
486 global auto_renum fom_cutoff project_item
487 Bmg box $project_item delete fom $fom_cutoff
488 if { $auto_renum } { Bmg box $project_item renumber}
489 boxesDrawAll
490 }
491
492 ## @brief Renumbers boxes.
493 #
494
495 proc boxRenumber { } {
496 global project_item
497 Bmg box $project_item renumber
498 boxesDrawAll
499 }
500
501 ## @brief Centers boxes.
502 #
503
504 proc boxCenter { } {
505 global project_item
506 Bmg box $project_item center
507 boxesDrawAll
508 }
509
510 ## @brief Picks particles by cross-correlation with a template.
511 #
512
513 proc templatePicker { } {
514 if ![winfo exists .wbox] { return}
515 global theimg thetemp
516 global window_scale hires lores
517
518 set w .wtemp
519 if ![winfo exists $w] {
520 toplevel $w
521
522 set m $w.menu
523 menu $m -tearoff 0
524 $m add cascade -menu $m.file -label "File" -underline 0
525 menu $m.file -tearoff 0
526 $w configure -menu $m
527 $m.file add command -label "Open ..." -command { readTemplate } \
528 -underline 0 -accelerator "Ctrl-o"
529 $m.file add command -label "Save ..." -command { saveTemplate } \
530 -underline 0 -accelerator "Ctrl-S"
531
532 frame $w.frame -relief ridge -borderwidth 2 -bg black
533
534 wm minsize $w 200 200
535 set c $w.frame.c
536 canvas $c -width 200 -height 200 \
537 -relief sunken -borderwidth 2 \
538 -xscrollcommand "$w.frame.hscroll set" \
539 -yscrollcommand "$w.frame.vscroll set"
540 scrollbar $w.frame.vscroll -orient vertical -command "$c yview"
541 scrollbar $w.frame.hscroll -orient horizontal -command "$c xview"
542
543 grid $c -in $w.frame \
544 -row 0 -column 0 -rowspan 1 -columnspan 1 -sticky news
545 grid $w.frame.vscroll \
546 -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news
547 grid $w.frame.hscroll \
548 -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news
549 # grid $c -in $w.frame -sticky nw -padx 2 -pady 2
550 grid rowconfig $w.frame 0 -weight 1 -minsize 0
551 grid columnconfig $w.frame 0 -weight 1 -minsize 0
552
553 image create photo $thetemp
554 $c create image 0 0 -image $thetemp -anchor nw -tags template
555
556 frame $w.scale
557 label $w.scale.label -text "Scale" -width 6 -anchor w
558 scale $w.scale.scale -orient horizontal -from 0.1 -to 10 \
559 -command { setTemplateScale } -resolution 0.1
560 pack $w.scale.label -side left
561 pack $w.scale.scale -side bottom -fill x
562 $w.scale.scale set $window_scale
563
564 labelframe $w.res -text "Resolution limits"
565 setupEntry $w.res.hi "High" double $hires "High resolution limit"
566 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
567 pack $w.res.hi $w.res.lo -side top -expand 1
568
569 labelframe $w.fomcut -text "FOM range"
570 setupEntry $w.fomcut.min "Minimum" double 0 \
571 "The minimum FOM cutoff to select picked particles\nIf it is zero, an automatic cutoff will be calculated"
572 setupEntry $w.fomcut.max "Maximum" double 1e30 \
573 "The maximum FOM cutoff to select picked particles"
574 pack $w.fomcut.min $w.fomcut.max -side top -expand 1
575
576 setupEntry $w.excld "Exclusion distance" double 0 "Minimum distance between picked particles"
577 setupEntry $w.bin "Binning" integer 1 "Binning the image to accelerate picking"
578
579 frame $w.buttons
580 button $w.buttons.update -text Update -command "updateBoxTemplate $w" -relief raised
581 button $w.buttons.pick -text Pick -command "doTemplatePicker $w" -relief raised
582 button $w.buttons.cancel -text Close -command " destroy $w " -relief raised
583 pack $w.buttons.update $w.buttons.pick $w.buttons.cancel -side left -expand 1
584
585 pack $w.frame $w.scale $w.res $w.fomcut $w.excld $w.bin $w.buttons -side top -fill both -expand yes
586
587 wm title $w "Template Picker"
588 wm iconname $w "Template"
589 } else {
590 wm deiconify $w
591 raise $w
592 }
593
594 setTemplateScale 1
595 updateBoxTemplate $w
596
597 bind $w <Control-w> { destroy $w }
598 bind $w <Command-w> { destroy $w }
599 }
600
601 proc setTemplateScale { scale } {
602 global thetemp
603 # global window_width window_height window_scale
604 set w .wtemp
605 if ![winfo exists $w] { return}
606 if ![Bimage exists thetemp] { return}
607 set c $w.frame.c
608 set width [Bimage get $thetemp width]
609 set height [Bimage get $thetemp height]
610 set size "0 0 [expr $width * $scale] [expr $height * $scale]"
611 $c configure -scrollregion $size
612 # $c configure -width $window_width -height $window_height -scrollregion $size
613 # puts "set scale to $scale"
614
615 set oz [expr [Bimage get $thetemp nslices] / 2]
616
617 # Bimage template $thetemp 0 $oz $scale 1
618 Bimage template $thetemp $oz $scale
619 }
620
621 proc readTemplate { } {
622 global imgdir thetemp
623 global filetypes
624 set w .wtemp
625 if ![winfo exists $w] { return}
626 set currdir $imgdir
627 if { [string length $currdir] < 2 } { set currdir [pwd]}
628 set new_filename [tk_getOpenFile -title "Open image file" \
629 -filetypes $filetypes -initialdir $currdir]
630 if { [string length $new_filename] < 1 } { return}
631 if { [catch { set nimages [Bimage open $thetemp $new_filename 0]} err] } {
632 bgerror $err
633 return
634 }
635 set oz [expr [Bimage get $thetemp nslices] / 2]
636 set scale [$w.scale.scale get]
637 # Bimage template $thetemp 0 $oz 1 1
638 Bimage template $thetemp $oz $scale
639 }
640
641 proc saveTemplate { } {
642 global imgdir thetemp
643 global filetypes filename
644 set currdir $imgdir
645 if { [string length $currdir] < 2 } { set currdir [pwd]}
646 set new_filename [tk_getSaveFile -filetypes $filetypes \
647 -initialfile [file tail $filename] -initialdir $currdir \
648 -defaultextension .pif]
649 if { [string length $new_filename] < 1 } { return}
650 Bimage set $thetemp pixel_size [.pixel_size.entry get]
651 Bimage save $thetemp $new_filename
652 writeSettingsFile
653 }
654
655 ## @brief Updates and shows the particle template.
656 #
657 # @param w the window.
658
659 proc updateBoxTemplate { w } {
660 if ![winfo exists .wbox] { return}
661 global theimg thetemp
662
663 set wc [getControlWindow $theimg]
664 set img_num [$wc.image.scale get]
665 set mg_item [micrographItem $img_num]
666
667 Bmg box $mg_item template
668
669 if ![winfo exists $w] {
670 templatePicker
671 }
672
673 # set z [$wc.slice.scale get]
674 if { [Bimage exists $thetemp] } {
675 set oz [expr [Bimage get $thetemp nslices] / 2]
676 set scale [$w.scale.scale get]
677 # Bimage template $thetemp 0 $oz $scale 1
678 Bimage template $thetemp $oz $scale
679 }
680 }
681
682 ## @brief Picks particles using cross-correlation.
683 #
684 # @param w the window.
685
686 proc doTemplatePicker { w } {
687 global project_item theimg
688 global hires lores fom_cutoff
689
690 set wc [getControlWindow $theimg]
691 set img_num [$wc.image.scale get]
692 set mg_item [micrographItem $img_num]
693
694 set hires [$w.res.hi.e get]
695 set lores [$w.res.lo.e get]
696 set fom_cutoff [$w.fomcut.min.e get]
697 set fommax [$w.fomcut.max.e get]
698 set excld [$w.excld.e get]
699 set bin [$w.bin.e get]
700
701 Bmg box $mg_item pickcc $hires $lores $fom_cutoff $fommax $excld $bin
702
703 updateBoxParam
704 boxesDrawAll
705 }
706
707 ## @brief Picks particles from a variance map.
708 #
709
710 proc variancePicker { } {
711 if ![winfo exists .wbox] { return}
712 global theimg thetemp
713
714 set w .wvar
715 if ![winfo exists $w] {
716 toplevel $w
717
718 setupEntry $w.avg "Average kernel" integer 21 "The edge size of the averaging kernel"
719 setupEntry $w.var "Variance kernel" integer 301 "The edge size of the variance kernel"
720 setupEntry $w.excld "Exclusion distance" double 100 "Minimum distance between picked particles"
721 setupEntry $w.bin "Binning" integer 1 "Binning the image to accelerate picking"
722 # setupEntry $w.nsig "Relative to sigma" double 5 "Number of standard deviations from the average in the variance map"
723 setupEntry $w.fmin "Minimum cutoff" double 0.1 "Minimum to accept in the variance map"
724 setupEntry $w.fmax "Maximum cutoff" double 0.2 "Maximum to accept in the variance map"
725
726 frame $w.buttons
727 button $w.buttons.pick -text Pick -command "doVariancePicker $w" -relief raised
728 button $w.buttons.cancel -text Close -command " destroy $w " -relief raised
729 pack $w.buttons.pick $w.buttons.cancel -side left -expand 1
730
731 pack $w.avg $w.var $w.excld $w.bin $w.fmin $w.fmax $w.buttons -side top -fill both -expand yes
732
733 wm title $w "Variance Picker"
734 wm iconname $w "Variance"
735 } else {
736 wm deiconify $w
737 raise $w
738 }
739
740 bind $w <Control-w> { destroy $w }
741 bind $w <Command-w> { destroy $w }
742 }
743
744 ## @brief Picks particles using variance map.
745 #
746 # @param w the window.
747
748 proc doVariancePicker { w } {
749 global project_item theimg
750
751 set wc [getControlWindow $theimg]
752 set img_num [$wc.image.scale get]
753 set mg_item [micrographItem $img_num]
754
755 set avg [$w.avg.e get]
756 set var [$w.var.e get]
757 set excld [$w.excld.e get]
758 set bin [$w.bin.e get]
759 # set nsig [$w.nsig.e get]
760 set fmin [$w.fmin.e get]
761 set fmax [$w.fmax.e get]
762
763 Bmg box $mg_item pickvar $avg $var $excld $bin $fmin $fmax
764
765 updateBoxParam
766 boxesDrawAll
767 }
768
769 proc updatePartSel args {
770 global project_item
771 global box_selected part_sel
772 # puts "Particle $box_selected: $part_sel"
773 Bmg box $project_item select $box_selected $part_sel
774 # boxesDrawAll
775 }
776
777 ## @brief Updates box and bad area parameters.
778 #
779
780 proc updateBoxParam { } {
781 global theimg imgtype
782 global project_item
783 global box_size bad_radius
784 global fom_min fom_max
785 global sel_min sel_max
786 set w .wbox
787 if ![winfo exists $w] { return}
788 if { $imgtype != "mg" && $imgtype != "rec" && $imgtype != "part" && $imgtype != "frame" } { return}
789 # puts "Updating box parameters for $theimg: $project_item"
790 if ![Bmg exists] {
791 createMgParam
792 setBoxSize
793 }
794 set idx [Bmg get $project_item index_of_mg]
795 # puts "$project_item $idx"
796 updatePixelsize
797 set temp_size [Bmg get $project_item box_size]
798 if { [lindex $temp_size 0] > 0 && [lindex $temp_size 1] > 0 } {
799 set box_size $temp_size
800 }
801 if { [Bmg get $project_item bad_radius] > 0 } {
802 set bad_radius [Bmg get $project_item bad_radius]
803 }
804 set filename [Bmg get $project_item filename $imgtype]
805 wm title $w [list "Particles:" $filename]
806 $w.mgid.str config -text "$project_item"
807 $w.mgid.idx config -text "$idx"
808 $w.box_size.x delete 0 end
809 $w.box_size.x insert 0 [lindex $box_size 0]
810 $w.box_size.y delete 0 end
811 $w.box_size.y insert 0 [lindex $box_size 1]
812 $w.box_size.z delete 0 end
813 $w.box_size.z insert 0 [lindex $box_size 2]
814 $w.bad_radius.e delete 0 end
815 $w.bad_radius.e insert 0 $bad_radius
816 updateBoxCounts
817 updateBoxSelected
818 set fom_min [Bmg box all fom_min]
819 set fom_max [Bmg box all fom_max]
820 set sel_min [Bmg box all select_min]
821 set sel_max [Bmg box all select_max]
822 }
823
824 ## @brief Updates box and bad area counts.
825 #
826
827 proc updateBoxCounts { } {
828 global project_item
829 global fom_max
830 if ![winfo exists .wbox] { return}
831 # puts "Updating box counts for $project_item"
832 set nbox [Bmg box $project_item count]
833 set nbad [Bmg box $project_item count bad]
834 set nboxall [Bmg box all count]
835 set w .wbox
836 if [winfo exists $w] {
837 $w.number.num config -text "$nbox"
838 $w.number.num2 config -text "$nboxall"
839 $w.nbad.num config -text "$nbad"
840 set fom_max [Bmg box $project_item fom_max]
841 if { $fom_max < 0.001 } { set fom_max 0.001}
842 set sres 0.00001
843 if { $fom_max > 0.005 } {
844 set sres 0.0001
845 } elseif { $fom_max > 0.05 } {
846 set sres 0.001
847 } elseif { $fom_max > 0.5 } {
848 set sres 0.01
849 }
850 $w.fom.scale config -to $fom_max -tickinterval [expr $fom_max / 5] -resolution $sres
851 }
852 }
853
854 ## @brief Updates selected box and bad area counts.
855 #
856
857 proc updateBoxSelected { } {
858 global theimg imgtype project_item
859 global box_selected part_sel
860 set w .wbox
861 if ![winfo exists $w] { return}
862 set wc [getControlWindow $theimg]
863 if { $imgtype == "part" } {
864 set box_selected [expr [$wc.image.scale get] + 1]
865 }
866 if { $box_selected > 0 } {
867 $w.sel.id config -text "$box_selected"
868 set fom [Bmg box $project_item fom $box_selected]
869 $w.sel.fom config -text "$fom"
870 set sel [Bmg box $project_item select $box_selected]
871 if { $sel >= 0 } {
872 set part_sel $sel
873 }
874 }
875 # puts "$box_selected $part_sel"
876 }
877
878 ## @brief Extracts particles from the current set of box coordinates.
879 #
880
881 proc extractParticles { } {
882 global project_item theimg
883 global scale
884
885 if { [Bmg box $project_item count] < 1 } {
886 tk_messageBox -icon error -type ok -title "Error" -message \
887 "No particles picked!"
888 return
889 }
890
891 set w .wpext
892 catch {destroy $w}
893 toplevel $w
894 wm title $w "Extracting particles"
895 wm iconname $w "ExtPart"
896
897 label $w.msg -wraplength 4i -justify left \
898 -text {Select parameters for particle extraction}
899
900 frame $w.panel
901
902 frame $w.panel.fill
903 label $w.panel.fill.tag -text "Fill value" -width 12 -anchor w
904 radiobutton $w.panel.fill.avg -text "Average" -variable filltype -value 1
905 radiobutton $w.panel.fill.back -text "Background" -variable filltype -value 2
906 radiobutton $w.panel.fill.val -text "Value" -variable filltype -value 0
907 entry $w.panel.fill.entry -width 10 -relief sunken \
908 -validate key -vcmd { string is double %P }
909 $w.panel.fill.entry insert 0 [Bimage get $theimg background]
910 # $w.panel.fill.entry insert 0 0
911
912 setupEntry $w.panel.scale "Scale" double $scale "Particle extraction scale relative to the micrograph sampling"
913
914 frame $w.panel.mask_width
915 label $w.panel.mask_width.tag -text "Filament mask width" -width 50 -anchor w
916 entry $w.panel.mask_width.entry -width 10 -relief sunken \
917 -validate key -vcmd { string is double %P }
918 $w.panel.mask_width.entry insert 0 "0"
919
920 frame $w.panel.path
921 label $w.panel.path.tag -text "Particle path" -width 10 -anchor w
922 entry $w.panel.path.entry -width 50 -relief sunken
923 $w.panel.path.entry insert 0 ""
924
925 frame $w.check
926 # checkbutton $w.check.oddbutton -text "Odd size" -width 20 -anchor w -variable odd
927 checkbutton $w.check.backbutton -text "Correct background" -width 20 -anchor w -variable back
928 checkbutton $w.check.normbutton -text "Normalize" -width 14 -anchor w -variable norm
929 checkbutton $w.check.splitbutton -text "Individual output files" \
930 -width 20 -anchor w -variable part_split
931
932 frame $w.buttons
933 button $w.buttons.ok -text OK -command "doExtractParticles $w"
934 button $w.buttons.cancel -text Cancel -command "destroy $w"
935
936 pack $w.msg -side top -padx 5 -pady 5
937
938 pack $w.panel.fill.tag $w.panel.fill.avg $w.panel.fill.back $w.panel.fill.val \
939 $w.panel.fill.entry -side left -fill both -expand true
940 pack $w.panel.mask_width.tag $w.panel.mask_width.entry -side left -padx 5 -pady 5
941 pack $w.panel.path.tag $w.panel.path.entry -side left -padx 5 -pady 5
942 pack $w.panel.fill $w.panel.scale $w.panel.mask_width $w.panel.path -side top
943 pack $w.panel -side top -fill both
944
945 pack $w.check.backbutton $w.check.normbutton $w.check.splitbutton -side left -pady 5 -padx 2
946 pack $w.check -side top -pady 2m
947
948 pack $w.buttons.ok $w.buttons.cancel -side left -padx 5
949 pack $w.buttons -side bottom -pady 2m
950
951 bind $w <Return> "doExtractParticles $w"
952 }
953
954 ## @brief Extracts particles from the current set of box coordinates.
955 #
956 # @param w Dialog window.
957
958 proc doExtractParticles { w } {
959 global filetypes project_item
960 global filename imgdir paramdir
961 global scale filltype
962 global back norm part_split
963 set xdir $paramdir
964 if { [string length $xdir] < 2 } { set xdir $imgdir}
965 if { [string length $xdir] < 2 } { set xdir [pwd]}
966 set xname [file root [file tail $filename]]
967 append xname "_part.pif"
968 set xname [tk_getSaveFile -filetypes $filetypes \
969 -initialfile $xname -initialdir $xdir -defaultextension .pif]
970 if { [string length $xname] < 1 } { return}
971 # puts "Extract from $filename to $xname"
972 set xname [relativePath [pwd] $xname]
973 set scale [$w.panel.scale.e get]
974 set pathname [$w.panel.path.entry get]
975 set mask_width [$w.panel.mask_width.entry get]
976 set fill [$w.panel.fill.entry get]
977 Bmg set $project_item pixel_size [.pixel_size.entry get]
978 setMgParam
979 Bmg box $project_item extract $xname $scale $back $norm $filltype $fill $mask_width $part_split $pathname
980 destroy $w
981 }
982
983 ## @brief Aligns particles by projection matching to a reference.
984 #
985
986 proc alignParticles { } {
987 global paramfile
988 global hires lores
989 global angle annmin annmax shift_limit
990 global peach
991 checkParamFile
992 set w .wspa
993 if ![winfo exists $w] {
994 toplevel $w
995
996 set angle 3
997 set shift_limit 10
998 set annmin 1
999 set annmax 100
1000
1001 set newfile [file rootname $paramfile]
1002 append newfile "_aln.star"
1003 set logfile [file rootname $paramfile]
1004 append logfile "_aln.log"
1005
1006 frame $w.head
1007 label $w.head.lab -text \
1008 "Aligning will be done on the currently saved parameter file: $paramfile"
1009 pack $w.head.lab
1010
1011 setupNewFileEntry $w.file "Output parameter file" $newfile \
1012 "New parameter file written after alignment"
1013
1014 setupScrollEntry $w.ref "Reference map" "" "Template or reference map to align to"
1015
1016 setupEntry $w.sym "Symmetry" alnum "C1" "Point group symmetry"
1017
1018 labelframe $w.res -text "Resolution limits"
1019 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1020 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1021 pack $w.res.hi $w.res.lo -side top -expand 1
1022
1023 setupEntry $w.ang "Angular step" double $angle \
1024 "The grid search step intervals in degrees"
1025 setupEntry $w.shift "Shift limit" double $shift_limit \
1026 "The maximum number of pixels of shift allowed"
1027
1028 labelframe $w.ann -text "Annuli"
1029 setupEntry $w.ann.min "Minimum" double $annmin \
1030 "The innermost annulus to include"
1031 setupEntry $w.ann.max "Maximum" double $annmax \
1032 "The outermost annulus to include"
1033 pack $w.ann.min $w.ann.max -side top -expand 1
1034
1035 checkbutton $w.peach -text "Peach" -variable peach
1036 # radiobutton $w.peach -text "Peach" -variable peach -value 0
1037
1038 pack $w.head $w.file $w.ref $w.sym $w.res $w.ang $w.shift $w.ann \
1039 $w.peach -side top -pady 2 -padx 10
1040
1041 frame $w.buttons
1042 button $w.buttons.do -text Do -command "doAlignParticles $w"
1043 button $w.buttons.close -text Close -command "destroy $w"
1044 pack $w.buttons -side bottom -fill x -pady 2m
1045 pack $w.buttons.do $w.buttons.close -side left -expand 1
1046
1047 bind $w <Return> "doAlignParticles $w"
1048 } else {
1049 wm deiconify $w
1050 raise $w
1051 }
1052 wm title $w "Align"
1053 wm iconname $w "Align"
1054 }
1055
1056 ## @brief Executes marker tracking.
1057 #
1058 # @param w dialog window.
1059
1060 proc doAlignParticles { w } {
1061 global env paramfile
1062 global hires lores
1063 global peach
1064 set newfile [$w.file.e get]
1065 set ref [$w.ref.e get]
1066 set sym [$w.sym.e get]
1067 set hires [$w.res.hi.e get]
1068 set lores [$w.res.lo.e get]
1069 set angle [$w.ang.e get]
1070 set shift [$w.shift.e get]
1071 set annmin [$w.ann.min.e get]
1072 set annmax [$w.ann.max.e get]
1073 setMgParam
1074 if { ![file exists $paramfile] } {
1075 puts "$paramfile not found!"
1076 }
1077 set logfile "[file rootname $newfile].log"
1078 # set psfile "[file rootname $newfile].ps"
1079 # puts "logfile = $logfile"
1080 if { $peach } {
1081 set cmd "psubmit /stachraid/bin/bomrun4 -mode ccc -CTF -sym $sym -resol $hires,$lores -ang $angle -shift $shift -ann $annmin,$annmax -ref $ref $paramfile -ss"
1082 } else {
1083 set cmd "$env(BSOFT)/bin/borient -verb 1 -mode ccc -CTF -sym $sym -resol $hires,$lores -ang $angle -shift $shift -ann $annmin,$annmax -ref $ref -out $newfile $paramfile"
1084 executeCommand $cmd $logfile
1085 }
1086 }
1087
1088 ## @brief Refines particle orientations by central section matching to a reference.
1089 #
1090
1091 proc refineParticles { } {
1092 global paramfile
1093 global hires lores
1094 global angini angacc stpini stpacc def mag
1095 checkParamFile
1096 set w .wspa
1097 if ![winfo exists $w] {
1098 toplevel $w
1099
1100 set angini 3
1101 set angacc 0.5
1102 set stpini 4
1103 set stpacc 0.5
1104 set def 0.0
1105 set mag 0.0
1106
1107 set newfile [file rootname $paramfile]
1108 append newfile "_aln.star"
1109 set logfile [file rootname $paramfile]
1110 append logfile "_aln.log"
1111
1112 frame $w.head
1113 label $w.head.lab -text \
1114 "Aligning will be done on the currently saved parameter file: $paramfile"
1115 pack $w.head.lab
1116
1117 setupNewFileEntry $w.file "Output parameter file" $newfile \
1118 "New parameter file written after alignment"
1119
1120 setupScrollEntry $w.ref "Reference map" "" "Template or reference map to align to"
1121
1122 labelframe $w.grd -text "Angular grid search"
1123 setupEntry $w.grd.ini "Initial angle" double $angini "Initial angluar step size in degrees"
1124 setupEntry $w.grd.acc "Angular accuracy" double $angacc "Target angular accuracy in degrees"
1125 pack $w.grd.ini $w.grd.acc -side top -expand 1
1126
1127 labelframe $w.stp -text "Translational search"
1128 setupEntry $w.stp.ini "Initial step" double $stpini "Initial translational step size in pixels"
1129 setupEntry $w.stp.acc "Translational accuracy" double $stpacc "Target translational accuracy in pixels"
1130 pack $w.stp.ini $w.stp.acc -side top -expand 1
1131
1132 labelframe $w.res -text "Resolution limits"
1133 setupEntry $w.res.hi "High" double $hires "High resolution limit"
1134 setupEntry $w.res.lo "Low" double $lores "Low resolution limit"
1135 pack $w.res.hi $w.res.lo -side top -expand 1
1136
1137 setupEntry $w.def "Defocus refinement" double $def \
1138 "Defocus step size to refine defocus in micrometer"
1139 setupEntry $w.mag "Magnification refinement" double $mag \
1140 "The maximum number of pixels of shift allowed"
1141
1142 pack $w.head $w.file $w.ref $w.grd $w.stp $w.res $w.def $w.mag \
1143 -side top -pady 2 -padx 10
1144
1145 frame $w.buttons
1146 button $w.buttons.do -text Do -command "doRefineParticles $w"
1147 button $w.buttons.close -text Close -command "destroy $w"
1148 pack $w.buttons -side bottom -fill x -pady 2m
1149 pack $w.buttons.do $w.buttons.close -side left -expand 1
1150
1151 bind $w <Return> "doRefineParticles $w"
1152 } else {
1153 wm deiconify $w
1154 raise $w
1155 }
1156 wm title $w "Refine"
1157 wm iconname $w "Refine"
1158 }
1159
1160 ## @brief Executes particle orientation refinement.
1161 #
1162 # @param w dialog window.
1163
1164 proc doRefineParticles { w } {
1165 global env paramfile
1166 global hires lores
1167 global angini angacc stpini stpacc def mag
1168 set newfile [$w.file.e get]
1169 set ref [$w.ref.e get]
1170 set angini [$w.grd.ini.e get]
1171 set angacc [$w.grd.acc.e get]
1172 set stpini [$w.stp.ini.e get]
1173 set stpacc [$w.stp.acc.e get]
1174 set hires [$w.res.hi.e get]
1175 set lores [$w.res.lo.e get]
1176 set def [$w.def.e get]
1177 set mag [$w.mag.e get]
1178 setMgParam
1179 if { ![file exists $paramfile] } {
1180 puts "$paramfile not found!"
1181 }
1182 set opt "-grid $angini,$angacc "
1183 if { $stpacc } { append opt "-step $stpini,$stpacc "}
1184 append opt "-resol $hires,$lores "
1185 if { $def } { append opt "-defocus $def "}
1186 if { $mag } { append opt "-magnif $mag "}
1187
1188 set logfile "[file rootname $newfile].log"
1189 # set psfile "[file rootname $newfile].ps"
1190 # puts "logfile = $logfile"
1191 set cmd "$env(BSOFT)/bin/brefine -verb 1 $opt -ref $ref -out $newfile $paramfile"
1192 executeCommand $cmd $logfile
1193 }
1194
1195 ## @brief Selects particles after an alignment run.
1196 #
1197
1198 proc selectParticles { } {
1199 global paramfile theimg project_item
1200 global selall fom_check cv_check top_check ran_check defadj
1201 showSelectedParticles
1202 set w .wspasel
1203 if ![winfo exists $w] {
1204 toplevel $w
1205
1206 set newfile [file rootname $paramfile]
1207 append newfile "_sel.star"
1208
1209 frame $w.head
1210 label $w.head.lab -text \
1211 "Particle seletion will be done using the currently saved parameter file: $paramfile"
1212
1213 setupNewFileEntry $w.file "Output parameter file" $newfile \
1214 "New parameter file written after selection"
1215
1216 checkbutton $w.all -text "Select all" -variable selall
1217 setupCheckEntry $w.fom "FOM" list fom fom_check "Selection based on the figure-of-merit"
1218 setupCheckEntry $w.cv "CV" list cv cv_check "Selection based on cross-validation"
1219 setupCheckEntry $w.top "Top" list top top_check "Selection based on the top scorers"
1220 checkbutton $w.defadj -text "Adjust for defocus" -variable defadj
1221 setupCheckEntry $w.ran "Random" list ran ran_check "Random selection"
1222
1223 pack $w.head.lab
1224 pack $w.head $w.file $w.all $w.fom $w.cv $w.top $w.defadj $w.ran -side top -pady 2 -padx 15
1225
1226 frame $w.buttons
1227 button $w.buttons.do -text Do -command "doSelectParticles $w"
1228 button $w.buttons.reset -text Reset -command "showSelectedParticles"
1229 button $w.buttons.close -text Close -command "destroy $w"
1230 pack $w.buttons -side bottom -fill x -pady 2m
1231 pack $w.buttons.do $w.buttons.reset $w.buttons.close -side left -expand 1
1232
1233 bind $w <Return> "doSelectParticles $w"
1234 } else {
1235 wm deiconify $w
1236 raise $w
1237 }
1238 wm title $w "Select"
1239 wm iconname $w "Select"
1240 }
1241
1242 ## @brief Shows the current particle selection.
1243 #
1244
1245 proc showSelectedParticles { } {
1246 global env paramfile
1247 set logfile "[file rootname $paramfile].log"
1248 set cmd "$env(BSOFT)/bin/bpartsel -verb 7 $paramfile"
1249 executeCommand $cmd $logfile
1250 }
1251
1252 ## @brief Executes particle selection.
1253 #
1254 # @param w dialog window.
1255
1256 proc doSelectParticles { w } {
1257 global env paramfile
1258 global selall fom_check cv_check top_check ran_check defadj
1259 set newfile [$w.file.e get]
1260 set fom [$w.fom.e get]
1261 set cv [$w.cv.e get]
1262 set top [$w.top.e get]
1263 set ran [$w.ran.e get]
1264 setMgParam
1265 if { ![file exists $paramfile] } {
1266 puts "$paramfile not found!"
1267 }
1268 set ad ""
1269 if { $defadj } { set ad ",1"}
1270 set opt ""
1271 if { $selall } { append opt "-all "}
1272 if { $fom_check } { append opt "-fom $fom$ad "}
1273 if { $cv_check } { append opt " -cv $cv$ad "}
1274 if { $top_check } { append opt "-top $top$ad "}
1275 if { $ran_check } { append opt "-random $ran "}
1276 set logfile "[file rootname $newfile].log"
1277 set cmd "$env(BSOFT)/bin/bpartsel -verb 7 $opt -out $newfile $paramfile"
1278 executeCommand $cmd $logfile
1279 }
1280
1281 ## @brief Reconstructs a single particle.
1282 #
1283
1284 proc particleReconstruct { } {
1285 global paramfile theimg project_item
1286 global hires lores
1287 set w .wsparec
1288 if ![winfo exists $w] {
1289 toplevel $w
1290
1291 set sz [Bmg get $project_item box_size]
1292 set x [lindex $sz 0]
1293 set y [lindex $sz 1]
1294 set z [lindex $sz 0]
1295
1296 set recfile [file rootname $paramfile]
1297 append recfile "_rec.pif"
1298 set newfile [file rootname $paramfile]
1299 append newfile "_rec.star"
1300
1301 frame $w.head
1302 label $w.head.lab -text \
1303 "Reconstruction will be done using the currently saved parameter file: $paramfile"
1304
1305 frame $w.rec
1306 label $w.rec.l -text "Output reconstruction" -width 20 -anchor w
1307 entry $w.rec.e -width 40
1308 $w.rec.e insert 0 $recfile
1309 pack $w.rec.l $w.rec.e -side left -pady 5
1310
1311 setupNewFileEntry $w.file "Output parameter file" $newfile \
1312 "New parameter file written after reconstruction"
1313
1314 setupEntry $w.cls "Classes" alnum "all" "Classes of particles to select for reconstruction"
1315
1316 setupEntry $w.interp "Type" integer 0 "Reconstruction interpolation type: 0=nearest neighbor, 1=weighted, 2=trilinear"
1317
1318 labelframe $w.size -text "Reconstruction size"
1319 setupEntry $w.size.x "x" double $x "Reconstruction x size"
1320 setupEntry $w.size.y "y" double $y "Reconstruction y size"
1321 setupEntry $w.size.z "z" double $z "Reconstruction z size"
1322 pack $w.size.x $w.size.y $w.size.z -side top -expand 1
1323
1324 setupEntry $w.scale "Scale" double 1 "Reconstruction scale"
1325 setupEntry $w.res "High resolution" double $hires "Spatial frequency limit for reconstruction"
1326 setupEntry $w.ctf "CTF correction" alnum "flip" "Contrast transfer function correction algorithm"
1327 setupEntry $w.sym "Symmetry" alnum "C1" "Point group symmetry"
1328
1329 pack $w.head.lab
1330 pack $w.head $w.rec $w.file $w.cls $w.interp $w.size $w.scale $w.res $w.ctf $w.sym -side top -fill x -pady 2 -padx 15
1331
1332 frame $w.buttons
1333 button $w.buttons.do -text Do -command "doReconstruct $w"
1334 button $w.buttons.close -text Close -command "destroy $w"
1335 pack $w.buttons -side bottom -fill x -pady 2m
1336 pack $w.buttons.do $w.buttons.close -side left -expand 1
1337
1338 bind $w <Return> "doReconstruct $w"
1339 } else {
1340 wm deiconify $w
1341 raise $w
1342 }
1343 wm title $w "Reconstruct"
1344 wm iconname $w "Reconstruct"
1345 }
1346
1347 ## @brief Executes tomogram reconstruction.
1348 #
1349 # @param w dialog window.
1350
1351 proc doReconstruct { w } {
1352 global env paramfile
1353 global hires
1354 set recfile [$w.rec.e get]
1355 set newfile [$w.file.e get]
1356 set cls [$w.cls.e get]
1357 set interp [$w.interp.e get]
1358 set x [$w.size.x.e get]
1359 set y [$w.size.y.e get]
1360 set z [$w.size.z.e get]
1361 set scale [$w.scale.e get]
1362 set hires [$w.res.e get]
1363 set ctf [$w.ctf.e get]
1364 set sym [$w.sym.e get]
1365 if { $ctf == "none" } {
1366 set ctf ""
1367 } else {
1368 set ctf "-CTF $ctf"
1369 }
1370 setMgParam
1371 if { ![file exists $paramfile] } {
1372 puts "$paramfile not found!"
1373 }
1374 set logfile "[file rootname $newfile].log"
1375 set cmd "$env(BSOFT)/bin/breconstruct -verb 1,tim -classes $cls -interp $interp -size $x,$y,$z -scale $scale -resol $hires $ctf -sym $sym -rescale 0,1 -full -half -rec $recfile -out $newfile $paramfile"
1376 executeCommand $cmd $logfile
1377 }
1378