source: trunk/odf.tcl @ 736

Last change on this file since 736 was 713, checked in by toby, 16 years ago

# on 2003/05/27 16:09:07, toby did:
autoselect 1st phase if none are previously selected
add comments

  • Property rcs:author set to toby
  • Property rcs:date set to 2003/05/27 16:09:07
  • Property rcs:lines set to +12 -1
  • Property rcs:rev set to 1.6
  • Property rcs:state set to Exp
  • Property svn:keywords set to Author Date Revision Id
File size: 13.3 KB
Line 
1# $Id: odf.tcl 713 2009-12-04 23:10:46Z toby $
2
3# Convert a Laue code as used in SPACEGRP to a number, as used in odfchk
4proc LaueCode2number {laueaxis} {
5    switch -exact $laueaxis {
6        1bar {return 1}
7        2/ma -
8        2/mb -
9        2/mc {return 2}
10        mmm  {return 3}
11        4/{return 4}
12        4/mmm {return 5}
13        3barR     {return 6}
14        "3bar mR" {return 7}
15        3bar    {return 8} 
16        3barm1 {return 9}
17        3bar1m  {return 10}
18        6/m    {return 11}
19        6/mmm  {return 12}
20        "m 3"  {return 13}
21        m3m    {return 14}
22        default {return ""}
23    }
24}
25
26# computes a list of ODF (l,m,n) terms for a given spherical harmonic order,
27#   sample symmetry and Laue symmetry
28proc ComputeODFterms {order ISAMSYM laueaxis} {
29
30    set laue [LaueCode2number $laueaxis]
31
32    set odflist {}
33    set ITOT 0
34    for {set I 2} {$I <= $order} {incr I 2} {
35        for {set M -$I} {$M <= $I} {incr M 1} {
36            if {[odfchk $ISAMSYM $I $M]} {
37                for {set N -$I} {$N <= $I} {incr N 1} {
38                    if {[odfchk $laue $I $N]} {
39                        incr ITOT
40                        lappend odflist [list $I $M $N]
41                    }
42                }
43            }
44        }
45    }
46    return $odflist
47}
48
49#PURPOSE: To determine if spherical harmonic term C(l,m) is allowed
50#   in LAUE group
51# based on GSAS FUNCTION ODFCHK(LAUE,L,M)
52proc odfchk {laue l m} {
53
54    set ODFCHK 0
55    if { $l % 2 == 0 && abs($m) <= $l } {
56        if { $laue == 0 } {
57            #Cylindricaly symmetric
58            if { $m == 0 } {set ODFCHK 1}
59        } elseif { $laue == 1 } {
60            #1-bar
61            set ODFCHK 1
62        } elseif { $laue == 2 } {
63            #2/m
64            if { abs($m) % 2 == 0 } {set ODFCHK 1}
65        } elseif { $laue == 3 } {
66            #mmm
67            if { abs($m) % 2 == 0 && $m >= 0 } {set ODFCHK 1}
68        } elseif { $laue == 4 } {
69            #4/m
70            if { abs($m) % 4 == 0 } {set ODFCHK 1}
71        } elseif { $laue == 5 } {
72            #4/mmm
73            if { abs($m) % 4 == 0 && $m >= 0 } {set ODFCHK 1}
74        } elseif { $laue == 6 } {
75            #R-3 R
76            if { abs($m) % 3 == 0 } {set ODFCHK 1}
77        } elseif { $laue == 7 } {
78            #R-3m R
79            if { abs($m) % 3 == 0 && $m >= 0 } {set ODFCHK 1}
80        } elseif { $laue == 8 } {
81            #-3
82            if { abs($m) % 3 == 0 } {set ODFCHK 1}
83        } elseif { $laue == 9 } {
84            #-3m1
85            if { abs($m) % 3 == 0 && $m >= 0 } {set ODFCHK 1}
86        } elseif { $laue == 10 } {
87            #-31m
88            if { abs($m) % 3 == 0 && $m >= 0 } {set ODFCHK 1}
89        } elseif { $laue == 11 } {
90            #6/m
91            if { abs($m) % 6 == 0 } {set ODFCHK 1}
92        } elseif { $laue == 12 } {
93            #6/mmm
94            if { abs($m) % 6 == 0 && $m >= 0 } {set ODFCHK 1}
95        } elseif { $laue == 13 } {
96            #m3
97            if { $m > 0 } {
98                if { $l % 12 == 2 } {
99                    if {$m <= ($l/12) } {set ODFCHK 1}
100                } else {
101                    if {$m <= ($l/12+1) } {set ODFCHK 1}
102                }
103            }
104        } elseif { $laue == 14 } {
105            #m3m
106            if { $m > 0 } {
107                if { $l % 12 == 2 } {
108                    if {$m <= ($l/12) } {set ODFCHK 1}
109                } else {
110                    if {$m <= ($l/12+1) } {set ODFCHK 1}
111                }
112            }
113        }
114    }
115    return $ODFCHK
116}
117
118# called once to make the ODF (spherical harmonics) pane
119# this gets done the first time the pane is selected
120proc MakeODFPane {} {
121    global expgui entryvar entrycmd entrybox
122    if $expgui(haveBW) {
123        pack [TitleFrame $expgui(odfFrame).f1 -bd 4 \
124                -text "Spherical Harmonic (ODF) Preferential Orientation" \
125                -relief groove] -side top -expand yes -fill x -anchor n
126        set expgui(odfFrameTop) [$expgui(odfFrame).f1 getframe]
127    } else {
128        pack [label $expgui(odfFrame).f0 \
129                -text "Spherical Harmonic (ODF) Preferential Orientation"] \
130                -side top -expand yes -fill x -anchor n
131        set expgui(odfFrameTop) [frame $expgui(odfFrame).top]
132        grid $expgui(odfFrameTop) -side top -expand yes -fill x -anchor n
133    }
134
135    grid [frame  $expgui(odfFrameTop).ps] -column 0 -row 0 -sticky w
136    # this is where the buttons will go
137    pack [label $expgui(odfFrameTop).ps.0 -text "No Phases"] -side left
138   
139    grid [label $expgui(odfFrameTop).lA -text " title:" \
140            -fg blue ] -column 1 -row 0 -sticky e
141    grid columnconfig $expgui(odfFrameTop) 1 -weight 1
142    grid [entry $expgui(odfFrameTop).lB -textvariable entryvar(phasename) \
143            -fg blue -width 45] -column 2 -columnspan 10 -row 0 -sticky e
144    grid columnconfigure $expgui(odfFrameTop) 1 -weight 1
145
146    set row 1
147    set angframe [frame $expgui(odfFrameTop).ang]
148    grid $angframe -row 2 -column 0 -columnspan 10
149    grid [label $angframe.l -text "Setting\nangles: "] \
150            -column 0 -row $row
151    foreach col {1 4 7} var {omega chi phi} lbl {w c f} {
152        grid [label $angframe.l$var -text $lbl] \
153                -column $col -row $row -padx 5 -sticky e
154        set font [$angframe.l$var cget -font]
155        $angframe.l$var config -font "Symbol [lrange $font 1 end]"
156        incr col
157        grid [checkbutton $angframe.r$var \
158                -variable entryvar(ODF${var}Ref)] \
159                -column $col -row $row 
160        incr col
161        grid [entry $angframe.e$var \
162                -textvariable entryvar(ODF$var) -width 10] \
163                -column $col -row $row -padx 5
164        set entrybox(ODF$var) $angframe.e$var
165    }
166    grid [label $angframe.lDamp -text "Damping  "] \
167            -column [incr col] -row $row
168    tk_optionMenu $angframe.om entryvar(ODFdampA) 0 1 2 3 4 5 6 7 8 9
169    grid $angframe.om -column [incr col] -row $row
170
171    #
172    set ordframe [frame $expgui(odfFrameTop).ord]
173    grid $ordframe -row 1 -column 0 -columnspan 10
174    set col -1
175    grid [label $ordframe.lo -text "Spherical\nHarmonic Order: "] \
176            -column [incr col] -row $row
177    set ordmenu [tk_optionMenu $ordframe.ord expgui(ODForder) 0]
178    $ordmenu delete 0 end
179    for {set i 0} {$i <= 34} {incr i 2} {
180        $ordmenu insert end radiobutton -variable expgui(ODForder) \
181                -label $i -value $i -command SetODFTerms
182    }
183    $ordframe.ord config -width 3
184    grid $ordframe.ord -column [incr col] -row $row
185
186    grid [label $ordframe.ls -text "Sample\nsymmetry: "] \
187            -column [incr col] -row $row
188    set expgui(ODFsym) {}
189    set expgui(symmenu) [tk_optionMenu $ordframe.sym expgui(ODFsymLbl) \
190            Cylindrical None "Shear (2/m)" "Rolling (mmm)"]
191    grid $ordframe.sym -column [incr col] -row $row
192    for {set i 0} {$i <= [$expgui(symmenu) index end]} {incr i} {
193        $expgui(symmenu) entryconfigure $i -command "SetODFSym $i"
194    }
195    $ordframe.sym config -width 12
196    grid [label $ordframe.lr -text "Refine ODF\ncoefficients"] \
197                -column [incr col] -row $row -padx 5 -sticky e
198    grid [checkbutton $ordframe.r \
199                -variable entryvar(ODFRefcoef)] \
200                -column [incr col] -row $row 
201    grid [label $ordframe.lDamp -text "Damping  "] \
202            -column [incr col] -row $row
203    tk_optionMenu $ordframe.om entryvar(ODFdampC) 0 1 2 3 4 5 6 7 8 9
204    grid $ordframe.om -column [incr col] -row $row
205    if $expgui(haveBW) {
206        pack [TitleFrame $expgui(odfFrame).f2 -bd 4 \
207                -text "Spherical Harmonic Terms: (l,m,n) & coeff's" \
208                -relief groove] -side top -fill both -expand yes -anchor n
209        set canvasfr [$expgui(odfFrame).f2 getframe]
210    } else {
211        set canvasfr [frame $expgui(odfFrame).f3 -bd 4 -relief groove]
212        pack $canvasfr -side top -expand yes -fill both -anchor n
213        grid [label $canvasfr.l \
214                -text "Spherical Harmonic Terms: (l,m,n) & coeff's"] \
215                -sticky news -row 0 -column 0 
216    }
217
218    set expgui(odfFrameCanvas) $canvasfr.canvas
219    set expgui(odfFrameScroll) $canvasfr.scroll
220    grid [canvas $expgui(odfFrameCanvas) \
221            -scrollregion {0 0 5000 500} -width 0 -height 250 \
222            -yscrollcommand "$expgui(odfFrameScroll) set"] \
223            -row 3 -column 0 -sticky ns
224    grid rowconfigure $expgui(odfFrameTop) 3 -weight 1
225    scrollbar $expgui(odfFrameScroll) \
226            -command "$expgui(odfFrameCanvas) yview"
227    frame $expgui(odfFrameCanvas).fr
228    $expgui(odfFrameCanvas) create window 0 0 -anchor nw -window $expgui(odfFrameCanvas).fr
229}
230
231proc SetODFSym {i} {
232    global expgui
233    if {$expgui(ODFsym) == $i} return
234    set expgui(ODFsym) $i
235    set expgui(ODForder) 0
236    SetODFTerms
237}
238
239proc SetODFTerms {} {
240    global expgui
241    if {$expgui(curPhase) == ""} return
242    set curterms [phaseinfo $expgui(curPhase) ODFterms]
243    set laueaxis [GetLaue [phaseinfo $expgui(curPhase) spacegroup]]
244    set newterms [ComputeODFterms $expgui(ODForder) $expgui(ODFsym) $laueaxis]
245    phaseinfo $expgui(curPhase) ODFterms set $newterms
246    phaseinfo $expgui(curPhase) ODForder set $expgui(ODForder)
247    phaseinfo $expgui(curPhase) ODFsym set $expgui(ODFsym)
248    # zero out the new terms
249    for {set i [expr [llength $curterms]+1]} \
250            {$i <= [llength $newterms]} {incr i} {
251        phaseinfo $expgui(curPhase) ODFcoef$i set 0.
252   }
253    incr expgui(changed)
254    SelectODFPhase $expgui(curPhase)
255}
256
257proc DisplayODFPane {} {
258    global expgui expmap
259    eval destroy [winfo children $expgui(odfFrameTop).ps]
260    pack [label $expgui(odfFrameTop).ps.0 -text Phase:] -side left
261    foreach num $expmap(phaselist) type $expmap(phasetype) {
262        pack [button $expgui(odfFrameTop).ps.$num -text $num \
263                -command "SelectODFPhase $num" -padx 1.5m] -side left
264        if {$type > 3} {
265            $expgui(odfFrameTop).ps.$num config -state disabled
266        }
267    }
268    # select the current phase
269    SelectODFPhase $expgui(curPhase)
270}
271
272# select a phase to display & display the ODF terms
273# called when pane is displayed (DisplayODFPane), a phase is selected using the
274# phase buttons or when the number of terms gets changed (SetODFTerms)
275# problem: this seems to be called multiple times -- for reasons that
276#          are unresolved -- but at least it's quick
277proc SelectODFPhase {num} {
278    global entryvar entrycmd entrybox expmap expgui
279    set crsPhase {}
280    # if no phase is selected, select the first phase
281    if {$num == ""} {set num [lindex $expmap(phaselist) 0]}
282    foreach n $expmap(phaselist) type $expmap(phasetype) {
283        if {$n == $num && $type <= 3} {
284            set crsPhase $num
285            catch {$expgui(odfFrameTop).ps.$num config -relief sunken}
286        } else { 
287            catch {$expgui(odfFrameTop).ps.$n config -relief raised}
288        }
289    }
290
291    # disable traces on entryvar until we are ready
292    set entrycmd(trace) 0
293
294    eval destroy [winfo children $expgui(odfFrameCanvas).fr]
295
296    if {$crsPhase == "" || [llength $expmap(phaselist)] == 0} {
297        # blank out the page
298        set expgui(ODFsymLbl) {}
299        set expgui(ODForder) {}
300        foreach var {omega chi phi omegaRef chiRef phiRef \
301                dampC dampA Refcoef} {
302            set entrycmd(ODF$var) {}
303            set entryvar(ODF$var) {}
304        }
305        set entryvar(phasename) {}
306        set entryvar(phasename) {}
307        grid forget $expgui(odfFrameScroll) 
308        set entrycmd(trace) 1
309        return
310    }
311    # phase name
312    set entrycmd(phasename) "phaseinfo $crsPhase name"
313    set entryvar(phasename) [phaseinfo $crsPhase name]
314    # ODFsym   -- sample symmetry (0-3) (*)
315    # prevent SetODFTerms from being run
316    set expgui(curPhase) {}
317    catch {$expgui(symmenu) invoke 0}
318    catch {$expgui(symmenu) invoke [phaseinfo $crsPhase ODFsym]}
319    set expgui(curPhase) $crsPhase
320    # ODForder -- spherical harmonic order (*)
321    set expgui(ODForder) [phaseinfo $expgui(curPhase) ODForder]
322    # ODFomega -- omega oriention angle (*)
323    # ODFchi -- chi oriention angle (*)
324    # ODFphi -- phi oriention angle (*)
325    # ODFomegaRef -- refinement flag for omega (*)
326    # ODFchiRef -- refinement flag for chi (*)
327    # ODFphiRef -- refinement flag for phi (*)
328    # ODFdampA -- damping for angles (*)
329    # ODFdampC -- damping for coefficients (*)
330    # ODFRefcoef -- refinement flag for ODF terms (*)
331    foreach var {omega chi phi omegaRef chiRef phiRef dampC dampA Refcoef} {
332        set entrycmd(ODF$var) "phaseinfo $expgui(curPhase) ODF$var"
333        set entryvar(ODF$var) [eval $entrycmd(ODF$var)]
334        # reset to black
335        catch {$entrybox(ODF$var) config -fg black}
336    }
337    #
338    set row 0
339    set term 0
340    set col 99
341    #     ODFterms -- a list of the {l m n} values for each ODF term (*)
342    #     ODFcoefXXX -- the ODF coefficient for for ODF term XXX (*)
343    set textureindex 1.0
344    foreach lmn [phaseinfo $expgui(curPhase) ODFterms] {
345        # make sure that numbers are separated by spaces
346        regsub -all -- "-" $lmn " -" lmn
347        incr term
348        if {$col > 5} {
349            incr row 2
350            grid rowconfig $expgui(odfFrameCanvas).fr $row \
351                    -minsize 2 -pad 10
352            set col 0
353        }
354        set lbl [eval format (%d,%d,%d) $lmn]
355        grid [label $expgui(odfFrameCanvas).fr.l$term -text $lbl] \
356                -column [incr col] -row $row -sticky s
357#       grid columnconfig $expgui(odfFrameCanvas).fr $col -pad 4
358        grid [entry $expgui(odfFrameCanvas).fr.e$term \
359                -width 10 -textvariable entryvar(ODFcoef$term)] \
360                -column $col -row [expr $row+1]
361        set entrycmd(ODFcoef$term) "phaseinfo $expgui(curPhase) ODFcoef$term"
362        set entryvar(ODFcoef$term) [eval $entrycmd(ODFcoef$term)]
363        set entrybox(ODFcoef$term) $expgui(odfFrameCanvas).fr.e$term
364        grid columnconfig $expgui(odfFrameCanvas).fr $col -pad 12
365        set textureindex [expr {$textureindex + \
366                ($entryvar(ODFcoef$term) * $entryvar(ODFcoef$term)) \
367                / ((2. * [lindex $lmn 0]) + 1.)}]
368    }
369
370    if {$term == 0} {
371        grid [label $expgui(odfFrameCanvas).fr.no -text "no terms" \
372                -anchor center] \
373                -column 0 -row 0 -sticky nsew
374    } else {
375        incr row 2
376        grid [label $expgui(odfFrameCanvas).fr.last \
377                -bd 2 -relief sunken -anchor center \
378                -text "Texture index = [format %.4f $textureindex]" ] \
379                -column 1 -columnspan 6 -row $row -sticky ew
380        grid rowconfig $expgui(odfFrameCanvas).fr $row -pad 12
381    }
382    # resize
383    update 
384    set sizes [grid bbox $expgui(odfFrameCanvas).fr]
385    set maxhgt 220
386    # use the scroll for BIG atom lists
387    if {[lindex $sizes 3] > $maxhgt} {
388        grid $expgui(odfFrameScroll) -sticky ns -column 1 -row 3
389        set height $maxhgt
390    } else {
391        grid forget $expgui(odfFrameScroll) 
392        set height [lindex $sizes 3]
393    }
394    $expgui(odfFrameCanvas) config -scrollregion $sizes \
395            -width [lindex $sizes 2] -height $height
396    set entrycmd(trace) 1
397}
398
399#debug code
400#set expgui(odfFrame) .test
401#catch {destroy $expgui(odfFrame)}
402#toplevel $expgui(odfFrame)
403#MakeODFPane
404#DisplayODFPane
Note: See TracBrowser for help on using the repository browser.