source: trunk/odf.tcl @ 282

Last change on this file since 282 was 235, checked in by toby, 13 years ago

# on 2000/07/20 22:03:39, toby did:
Spherical Harmonic implementation

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