source: branches/sandbox/atomcons.tcl @ 1143

Last change on this file since 1143 was 999, checked in by toby, 15 years ago

Add Distance Rest to Constraints (sandbox)

  • Property svn:keywords set to Author Date Revision Id
File size: 25.7 KB
Line 
1# $Revision: 999 $ $Date: 2010-09-08 22:04:39 +0000 (Wed, 08 Sep 2010) $
2# initial constraint sort mode
3set expcons(sortmode) num
4# size of constraint box
5set expcons(height) 300
6
7# this is used once to create the constraint page
8proc MakeConstraintsPane {} {
9    global expgui expcons expmap
10    # create the notebook
11    grid [NoteBook $expgui(consFrame).n -bd 2 -side bottom] -sticky news
12    source [file join $expgui(scriptdir) profcons.tcl]
13    source [file join $expgui(scriptdir) distrest.tcl]
14}
15
16# this is used to update the contents of the constraint page when displayed
17proc DisplayConstraintsPane {} {
18    global expgui expcons expmap
19    # create pages for each of the constraint "subpages"
20    catch {$expgui(consFrame).n delete atomic}
21    catch {$expgui(consFrame).n delete macro}
22    catch {$expgui(consFrame).n delete profile}
23    catch {$expgui(consFrame).n delete distrest}
24    set atom normal
25    set mm disabled
26    if {[llength $expmap(phasetype)] == 0} {
27        set atom disabled
28    } elseif {[lindex $expmap(phasetype) 0] == 4} {
29        set mm normal
30        if {[llength $expmap(phasetype)] == 1} {
31            set atom disabled
32        }
33    }
34    set expcons(atommaster) [\
35            $expgui(consFrame).n insert end atomic -text "Atom Constraints" \
36            -state $atom \
37            -createcmd "MakeAtomsConstraintsPane" \
38            -raisecmd "DisplayAtomConstraints"]
39    set expcons(mmatommaster) [\
40            $expgui(consFrame).n insert end macro -text Macromol \
41            -state $mm \
42            -createcmd "MakeAtomsConstraintsPane mm" \
43            -raisecmd "DisplayAtomConstraints mm"]
44    # profile constraints page
45    set expcons(profilemaster) [\
46            $expgui(consFrame).n  insert end profile -text "Profile Constraints" \
47            -createcmd "MakeProfileConstraintsPane" \
48            -raisecmd "DisplayProfileConstraints"]   
49    set expcons(distmaster) [\
50            $expgui(consFrame).n insert end distrest -text "Distance Restraints" \
51            -state $atom \
52            -createcmd "" \
53            -raisecmd "DisplayDistanceRestraints"]
54 
55    set page [$expgui(consFrame).n raise]
56    # open the atom constraints page if no page is open
57    if {$page == ""} {
58        foreach page [$expgui(consFrame).n pages] {
59            # loop to the first non-disabled page
60            if {[$expgui(consFrame).n itemcget $page -state] == "normal"} {
61                $expgui(consFrame).n raise $page
62                return
63            }
64        }
65    } else {
66        set pageupdate [$expgui(consFrame).n itemcget $page -raisecmd]
67        catch $pageupdate
68    }
69}
70
71# fill the atom/mm constraints pane
72proc MakeAtomsConstraintsPane {"mode {}"} {
73    global expgui expcons
74    if {$mode == "mm"} {
75        set frm mmatommaster
76    } else {
77        set frm atommaster
78    }
79
80    grid [button $expcons($frm).new -text "New Constraint" \
81            -command "EditAtomConstraint new [list $mode]"] \
82            -column 0 -sticky sw -row 1
83    grid [button $expcons($frm).del -text "Delete" \
84            -command "DeleteAtomConstraints [list $mode]"] \
85            -column 1 -sticky se -row 1
86    grid [canvas $expcons($frm).canvas \
87            -scrollregion {0 0 5000 500} -width 0 -height 250 \
88            -yscrollcommand "$expcons($frm).scroll set"] \
89            -column 0 -row 0 -columnspan 2 -sticky nsew
90    grid columnconfigure $expcons($frm) 0 -weight 1
91    grid rowconfigure $expcons($frm) 0 -weight 1
92    grid rowconfigure $expcons($frm) 1 -pad 5
93    scrollbar $expcons($frm).scroll \
94            -command "$expcons($frm).canvas yview"
95}
96
97
98# this is called to display the constraints on atomic/mm parameters
99proc DisplayAtomConstraints {"mode {}"} {
100    global expgui expcons expmap
101    if {$mode == "mm"} {
102        set frm mmatommaster
103    } else {
104        set frm atommaster
105    }
106    catch {destroy $expcons($frm).canvas.fr}
107    set top [frame $expcons($frm).canvas.fr]
108    $expcons($frm).canvas create window 0 0 -anchor nw -window $top
109
110    # get a list of constraints
111    set expcons(lastconstr) 0
112    set expcons(clist) {}
113    set i 0
114    catch {unset varlist}
115    while {[set clist [constrinfo atom get [incr i]]] != -1} {
116        set clist [lsort -index 1 $clist]
117        if {$expcons(sortmode) == "num"} {
118            set sortvar $i
119        } elseif {$expcons(sortmode) == "var"} {
120            set sortvar [lindex [lindex $clist 0] 2]
121        } elseif {$expcons(sortmode) == "atom"} {
122            set sortvar [lindex [lindex $clist 0] 1]
123            if {$sortvar == "ALL"} {set sortvar 0}
124        } elseif {$expcons(sortmode) == "phase"} {
125            set sortvar [lindex [lindex $clist 0] 0]
126        }
127        # tabulate a list where each phase-atom-var is referenced
128        foreach item $clist {
129            set phase [lindex $item 0]
130            set atom [lindex $item 1]
131            if {$atom == "ALL"} {set atom $expmap(atomlist_$phase)}
132            foreach a $atom {
133                set key [lindex $item 2]_${phase}_${a}
134                lappend varlist($key) $i
135            }
136        }
137        lappend expcons(clist) [list $sortvar $i $clist]
138    }
139    # were any variables referenced more than once?
140   
141    set problems {}
142    foreach key [array names varlist] {
143        if {[llength $varlist($key)] > 1} {
144            append problems " $varlist($key)"
145        }
146    }
147    # column headings
148    set row 0
149    set col -1
150    if {$mode == "mm"} {
151        set head {# "" "" \
152                "" Atom(s) Variable Multiplier \
153                "" Atom(s) Variable Multiplier \
154                "" Delete}
155    } else {
156        set head {# "" Phase \
157                "" Atom(s) Variable Multiplier \
158                "" Atom(s) Variable Multiplier \
159                "" Delete}
160    }
161    foreach lbl $head {
162        incr col
163        if {$lbl != ""} {
164            grid [label $top.t$col -text $lbl] -column $col -row $row
165        }
166    }
167    # make some column headings into buttons
168    foreach col {0 2 4 5} val {num phase atom var} {
169        catch {
170            $top.t$col config -relief raised -bd 2
171            bind $top.t$col <1> \
172                    "set expcons(sortmode) $val; DisplayAtomConstraints [list $mode]"
173        }
174    }
175    # extra column spacing
176    foreach col {1 2 4 5 6 8 9 10} { 
177        grid columnconfig $top $col -pad 6
178    }
179    set i 0
180    if {$expcons(sortmode) == "var"} {
181        set sortlist [lsort -index 0 -ascii $expcons(clist)]
182    } else {
183        set sortlist [lsort -index 0 -integer $expcons(clist)]
184    }
185    foreach item $sortlist {
186        set clist [lindex $item 2]
187        set num [lindex $item 1]
188        incr i
189        # row separator
190        grid [frame $top.sp$row -bd 8 -bg white] \
191                -columnspan 20 -column 0 -row [incr row] -sticky nsew
192        grid rowconfig $top $row -minsize 2 -pad 2
193        set startrow [incr row]
194        catch {unset atomlist}
195        # make a list of unique phase #, variables & multipliers
196        foreach item $clist {
197            set key [lindex $item 0]_[lindex $item 2]_[lindex $item 3]
198            lappend atomlist($key) [lindex $item 1]
199        }
200        set phprev 0
201        incr row -1
202        set col 1
203        foreach key [lsort [array names atomlist]] {
204            regexp {(.*)_(.*)_(.*)} $key dummy phase var mult
205            if {$phase != $phprev} {
206                set col 1
207                if {$phprev!= 0} {
208                    grid [frame $top.sp$row -bg white] \
209                            -columnspan 14 -column 2 \
210                            -row [incr row] -sticky nsew
211                    grid rowconfig $top $row -minsize 1
212                }
213                if {$mode == "mm"} {
214                    incr col
215                    incr row
216                } else {
217                    grid [label $top.c${col}$row -text $phase] \
218                            -column [incr col] -row [incr row]
219                }
220                set phprev $phase
221            }
222            incr col
223            if {$col > 8} {
224                incr row
225                set col 3
226            }
227            grid [label $top.c${col}$row \
228                    -justify left \
229                    -text [CompressList $atomlist($key) 20]] \
230                    -column [incr col] -row $row -sticky w
231            grid [label $top.c${col}$row -text $var] \
232                    -column [incr col] -row $row
233            set vallbl $top.c${col}$row
234            grid [label $vallbl -text "x $mult"] \
235                        -column [incr col] -row $row
236            if {$mult < 0} {
237                $vallbl config -bg beige
238            }
239        }
240        grid [button $top.but$row -text "edit" \
241                -command "EditAtomConstraint $num [list $mode]"] \
242                -column 1 -row $startrow \
243                -rowspan [expr 1 + $row - $startrow]
244        set expcons(delete$num) 0
245        grid [checkbutton $top.del$row  \
246                -variable expcons(delete$num)] \
247                -column 12 -row $startrow \
248                -rowspan [expr 1 + $row - $startrow]
249        if {[lsearch $problems $num] == -1} {
250            grid [label $top.l$i -text $num] \
251                    -column 0 -row $startrow \
252                    -rowspan [expr 1 + $row - $startrow]
253        } else {
254            grid [label $top.l$i -text $num -fg red] \
255                    -column 0 -row $startrow \
256                    -rowspan [expr 1 + $row - $startrow]
257        }
258        set expcons(lastconstr) \
259                [expr $expcons(lastconstr) > $num ? \
260                $expcons(lastconstr) : $num ]
261    }
262    # row separator
263    grid [frame $top.sp$row -bd 8 -bg white] \
264            -columnspan 16 -column 0 -row [incr row] -sticky nsew
265    grid rowconfig $top $row -minsize 2 -pad 2
266    # column separators
267    foreach col {3 7 11} {
268        grid [frame $top.vs${col}$row -bd 8 -bg white] \
269                -column $col -row 0 -rowspan $row -sticky nsew
270        grid columnconfig $top $col -minsize 2 -pad 2
271    }
272    # resize the canvas & scrollbar
273    update idletasks
274    set sizes [grid bbox $top]
275    $expcons($frm).canvas config -scrollregion $sizes
276    set hgt [lindex $sizes 3]
277    # set the maximum height for the canvas from the frame
278    set maxheight [expr \
279            [winfo height [winfo parent $expgui(consFrame)]] - 130]
280
281    # use the scroll for BIG constraint lists
282    if {$hgt > $maxheight} {
283        grid $expcons($frm).scroll -sticky ns -column 2 -row 0
284    }
285    $expcons($frm).canvas config \
286            -height $maxheight \
287            -width [lindex $sizes 2]
288    $expgui(consFrame).n compute_size
289    # report constraint errors
290    set msg {}
291    foreach key [lsort [array names varlist]] {
292        if {[llength $varlist($key)] > 1} {
293            regexp {(.*)_(.*)_(.*)} $key dummy var phase atom
294            append msg "   $var for atom $atom (phase $phase) is in"
295            append msg " constraints [CompressList $varlist($key) 40]\n"
296        }
297    }
298    $expgui(consFrame).n compute_size
299    update idletasks
300    if {$msg != ""} {
301        set msg "Error: an atomic parameter can appear in only one constraint. Here is a list of parameters that are referenced in more than one constraint:\n\n$msg"
302        MyMessageBox -icon error -message $msg \
303                -helplink "expgui6.html AtomConstraintsError" \
304                -parent [winfo toplevel $expgui(consFrame)] 
305    }
306}
307
308# this is called to delete an atomic constraint
309proc DeleteAtomConstraints {mode} {
310    global expcons expgui
311    # get the constraints to delete
312    set dellist {}
313    for {set i 1} {$i <= $expcons(lastconstr)} {incr i} {
314        if $expcons(delete$i) {lappend dellist $i}
315    }
316    # nothing to delete?
317    if {$dellist == ""} return
318    if {[MyMessageBox -message \
319            "Do you want to delete constraint(s) [CompressList $dellist]?" \
320            -parent [winfo toplevel $expcons(atommaster)] \
321            -type {No Delete} -default no] == "no"} return
322    foreach num [lsort -decreasing -integer $dellist] {
323        constrinfo atom delete $num
324        RecordMacroEntry "constrinfo atom delete $num" 0
325        incr expgui(changed)
326    }
327    RecordMacroEntry "incr expgui(changed)" 0
328    DisplayAtomConstraints $mode
329}
330
331# called to edit a single constraint set
332proc EditAtomConstraint {num mode} {
333    global expcons expmap expgui
334
335    set top {.editcons}
336    catch {toplevel $top}
337
338    if {$mode == "mm"} {pleasewait "making window..."}
339
340    bind $top <Key-F1> "MakeWWWHelp expgui6.html EditAtomConstraints"
341    eval destroy [grid slaves $top]
342    if {$num == "new"} {
343        wm title $top "New Constraint"
344        set clist {}
345        grid [label $top.top -text "Editing new constraint"] \
346            -column 0 -row 0 -columnspan 4
347
348    } else {
349        wm title $top "Constraint #$num"
350        set clist [constrinfo atom get $num]
351        grid [label $top.top -text "Editing constraint #$num"] \
352            -column 0 -row 0 -columnspan 4
353    }
354    # column headings
355    grid [canvas $top.canvas \
356            -scrollregion {0 0 5000 500} -width 100 -height 50 \
357            -xscrollcommand "$top.scroll set"] \
358            -column 0 -row 1 -columnspan 4 -sticky nsew
359    grid columnconfigure $top 3 -weight 1
360    grid rowconfigure $top 1 -weight 1
361    catch {destroy $top.scroll}
362    scrollbar $top.scroll -orient horizontal \
363            -command "$top.canvas xview"
364    #    grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4
365    # create a scrollable frame inside the canvas
366    set cfr [frame $top.canvas.fr -class Coord]
367    $top.canvas create window 0 0 -anchor nw  -window $cfr
368
369    grid [button $top.add -text "New Column" \
370            -command "NewAtomConstraintColumn $top $cfr $num [list $mode]"] \
371            -column 0 -row 3  -columnspan 2 -sticky ew
372    grid [button $top.done -text "Save" \
373            -command "SaveAtomConstraint $num $top [list $mode]"] \
374            -column 0 -row 4 -sticky ns
375    grid [button $top.quit -text "Cancel\nChanges" \
376            -command "CancelEditConstraint $top $num"]  -column 1 -row 4
377    grid [button $top.help -text Help -bg yellow \
378            -command "MakeWWWHelp expgui6.html EditAtomConstraints"] \
379            -column 2 -row 3 -columnspan 99 -rowspan 2 -sticky e
380
381    set col 0
382    set row 1
383    if {$mode == "mm"} {
384        set head {Atom(s) Variable Multiplier} 
385        incr row 2
386    } else {
387        set head {Phase Atom(s) Variable Multiplier} 
388    }
389    foreach lbl $head { 
390        # row separator
391        grid [frame $cfr.spc$row -bd 8 -bg white] \
392                -columnspan 60 -column 0 -row [incr row] -sticky nsew
393        grid rowconfig $cfr $row -minsize 2 -pad 2
394        if {$lbl == ""} {
395            incr row
396        } else {
397            grid [label $cfr.t$row -text $lbl] -column $col -row [incr row]
398        }
399    }
400    # row separator
401    grid [frame $cfr.spc$row -bd 8 -bg white] \
402            -columnspan 60 -column 0 -row [incr row] -sticky nsew
403    grid rowconfig $cfr $row -minsize 2 -pad 2
404    # make a list of unique phase #, variables & multipliers
405    catch {unset atomlist}
406    foreach item $clist {
407        if {$item == -1} break
408        set key [lindex $item 0]_[lindex $item 2]_[lindex $item 3]
409        lappend atomlist($key) [lindex $item 1]
410    }
411    set ic 0
412    foreach key [lsort [array names atomlist]] {
413        incr ic
414        regexp {(.*)_(.*)_(.*)} $key dummy phase var mult
415    }
416    # delete traces on expcons(var1)
417    foreach v [ trace vinfo expcons(var1)] {
418        eval trace vdelete expcons(var1) $v
419    }
420    # fill the listbox & set the vars
421    set ic 0
422    foreach key [lsort [array names atomlist]] {
423        incr ic
424        regexp {(.*)_(.*)_(.*)} $key dummy phase var mult
425        # delete traces on expcons(phase$ic)
426        foreach v [ trace vinfo expcons(phase$ic)] {
427            eval trace vdelete expcons(phase$ic) $v
428        }
429        MakeAtomConstraintColumn $cfr $ic $col $num $mode
430        incr col 3
431        # set the various variables
432        set expcons(phase$ic) $phase
433        set expcons(mult$ic) $mult
434        set expcons(var$ic) $var
435        FillAtomsConstraintList $ic $atomlist($key)
436        trace variable expcons(phase$ic) w "FillAtomsConstraintList $ic {}"
437    }
438    if {$num == "new"} {NewAtomConstraintColumn $top $cfr $num $mode}
439    trace variable expcons(var1) w SetVarConstraintMenu
440    SetVarConstraintMenu
441    # resize the canvas & scrollbar
442    update idletasks
443    set sizes [grid bbox $cfr]
444    $top.canvas config -scrollregion $sizes
445    set width [lindex $sizes 2]
446    # use the scroll for BIG constraints
447    if {$width > 600} {
448        set width 600
449        grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4
450    }
451    $top.canvas config -height [lindex $sizes 3] -width $width
452    # force the window to stay on top
453    if {$mode == "mm"} {donewait}
454    putontop $top
455    tkwait window $top
456    afterputontop
457}
458
459# called when the "Cancel Changes" button is pressed
460proc CancelEditConstraint {top num} {
461    global expcons
462    if {$expcons(var1) == ""} {destroy $top; return}
463    if {$num == "new"} {destroy $top; return}
464    set ans [MyMessageBox -type "{Abandon Changes} {Continue Edit}" \
465            -parent [winfo toplevel $top] -default "abandon changes" \
466            -helplink "expguierr.html AbandonEditConstraints" \
467            -icon warning -message  \
468            {Do you want to lose any changes made to this constraint?}]
469    if {$ans == "abandon changes"} {destroy $top}
470}
471
472# called to make each column in the atom parameter dialog
473proc MakeAtomConstraintColumn {cfr ic col num mode} {
474    global expmap expcons expgui
475    set row 1
476    # make column separator
477    incr col 2
478    grid [frame $cfr.sp$col -bd 8 -bg white] \
479            -rowspan 9 -column $col -row $row -sticky nsew
480    grid columnconfig $cfr $col -minsize 2 -pad 2
481
482    # there should be more than one phase
483    if {[lindex $expmap(phasetype) 0] == 4} {
484        set list [lrange $expmap(phaselist) 1 end]
485    } else {
486        set list $expmap(phaselist)
487    }
488    if {$mode != "mm"} {
489        eval tk_optionMenu $cfr.phase$ic expcons(phase$ic) $list
490        grid $cfr.phase$ic -column [incr col] -row [incr row 2] -columnspan 2
491    } else {
492        incr col
493        incr row 2
494    }
495    # make the listbox
496    set expcons(atomlistbox$ic) $cfr.lb$ic
497    if {$mode == "mm"} {
498        set wid 21
499    } else {
500        set wid 12
501    }
502    grid [listbox $cfr.lb$ic -height 10 -width $wid \
503            -exportselection 0 -selectmode extended \
504            -yscrollcommand " $cfr.sb$ic set"] \
505            -column $col -row [incr row 2] -sticky nse
506    bind $expcons(atomlistbox$ic) <Button-3> \
507            "$expcons(atomlistbox$ic) selection set 0 end"
508    grid [scrollbar $cfr.sb$ic -command "$cfr.lb$ic yview"] \
509            -column [expr 1+$col] -row $row -sticky wns
510    if {$mode == "mm" && $num == "new"} {
511        set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \
512                FRA X Y Z UIS XYZU]
513        $expcons(varmenu$ic) insert 5 separator
514    } elseif {$mode == "mm"} {
515        set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \
516                FRA X Y Z UIS]
517    } elseif {$num == "new"} {
518        set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \
519                FRAC X Y Z UISO U11 U22 U33 U12 U23 U13 MX MY MZ XYZU Uxx XYZU+-F]
520        $expcons(varmenu$ic) insert 14 separator
521    } else {
522        set expcons(varmenu$ic) [tk_optionMenu $cfr.var$ic expcons(var$ic) \
523                FRAC X Y Z UISO U11 U22 U33 U12 U23 U13 MX MY MZ]
524    }
525    grid $cfr.var$ic -column $col -row [incr row 2] -columnspan 2
526    grid [entry $cfr.c${col}$ic -width 10 \
527            -textvariable expcons(mult$ic)] \
528            -column $col -row [incr row 2] -columnspan 2
529}
530
531# called when the "New column" button is pressed to add a new constraint
532proc NewAtomConstraintColumn {top cfr num mode} {
533    global expcons expmap expgui
534    set col -3
535    set row 1
536    for {set ic 1} {$ic < 500} {incr ic} {
537        incr col 3
538        if [winfo exists $cfr.lb$ic] continue
539        # delete traces on expcons(phase$ic)
540        foreach v [ trace vinfo expcons(phase$ic)] {
541            eval trace vdelete expcons(phase$ic) $v
542        }
543        MakeAtomConstraintColumn $cfr $ic $col $num $mode
544        # set the various variables to initial values
545        set expcons(atmlst$ic) {}
546        if {$mode == "mm"} {
547            set expcons(phase$ic) 1
548            FillAtomsConstraintList $ic {}
549        } elseif {[lindex $expmap(phasetype) 0] != 4 \
550                && [llength $expmap(phaselist)] == 1} {
551            set expcons(phase$ic) $expmap(phaselist)
552            FillAtomsConstraintList $ic {}
553        } elseif {[lindex $expmap(phasetype) 0] == 4 \
554                && [llength $expmap(phaselist)] == 2} {
555            set expcons(phase$ic) [lindex $expmap(phaselist) 1]
556            FillAtomsConstraintList $ic {}
557        } else {
558            set expcons(phase$ic) {}
559        }
560        set expcons(var$ic) {}
561        set expcons(mult$ic) 1.0
562        trace variable expcons(phase$ic) w "FillAtomsConstraintList $ic {}"
563        break
564    }
565    # set the allowed constraints
566    SetVarConstraintMenu
567    # resize the canvas & scrollbar
568    update idletasks
569    set sizes [grid bbox $cfr]
570    $top.canvas config -scrollregion $sizes
571    set width [lindex $sizes 2]
572    # use the scroll for BIG constraints
573    if {$width > 600} {
574        set width 600
575        grid $top.scroll -sticky ew -column 0 -row 2 -columnspan 4
576    }
577    $top.canvas config -height [lindex $sizes 3] -width $width
578}
579
580# called when the leftmost constraint variable is changed, so that
581# only allowed constraints are offered to the user.
582proc SetVarConstraintMenu {args} {
583    global expcons
584    set maxvar [$expcons(varmenu1) index end]
585    set allowed {}
586    switch $expcons(var1) {
587        FRAC {set allowed FRAC}
588        FRA {set allowed FRA}
589        X -
590        Y -
591        Z {set allowed "X Y Z"}
592        XYZU {set allowed XYZU}
593        UISO {set allowed UISO}
594        UIS {set allowed UIS}
595        XYZU+-F {set allowed XYZU+-F}
596        U11 -
597        U22 -
598        U33 -
599        U12 -
600        U23 -
601        U13 {set allowed "U11 U22 U33 U12 U23 U13"}
602        Uxx {set allowed Uxx}
603        MX -
604        MY -
605        MZ {set allowed "MX MY MZ"}
606    }
607    for {set ic 2} {$ic < 500} {incr ic} {
608        if [catch {set expcons(varmenu$ic)}] break
609        if [winfo exists $expcons(varmenu$ic)] {
610            # if only one variable choice is allowed select it,
611            # if not and the current value is not allowed, blank it out
612            if {[llength $allowed] == 1} {
613                set expcons(var$ic) $allowed
614            } elseif {[lsearch $allowed $expcons(var$ic)] == -1} {
615                set expcons(var$ic) {}
616            }
617            set num 0
618            for {set num 0} {$num <= $maxvar} {incr num} {
619                # ignore error on separators
620                catch {
621                    set var [$expcons(varmenu$ic) entrycget $num -label]
622                    if {[lsearch $allowed $var] == -1} {
623                        $expcons(varmenu$ic) entryconfigure $num \
624                                -state disabled
625                    } else {
626                        $expcons(varmenu$ic) entryconfigure $num \
627                                -state normal
628                    }
629                }
630            }
631        } else {
632            break
633        }
634    }
635}
636
637# called to load the parameter values into the atom parameter dialog
638proc FillAtomsConstraintList {ic atomselectlist args} {
639    global expcons expgui expmap
640    # fill the atoms box
641    set phase $expcons(phase$ic)
642    if {[lindex $expmap(phasetype) [expr {$phase -1}]] == 4} {
643        set cmd mmatominfo
644        set mm 1
645    } else {
646        set cmd atominfo
647        set mm 0
648    }   
649    $expcons(atomlistbox$ic) delete 0 end
650    set atmlst {}
651    if  {$expgui(asorttype) == "type"} {
652        # sort on atom type
653        foreach atom $expmap(atomlist_$phase) {
654            lappend atmlst "$atom [$cmd $phase $atom type]"
655        }
656        set atmlst [lsort -ascii -index 1 $atmlst]
657    } elseif {$expgui(asorttype) == "number"} {
658        # sort on atom number
659        foreach atom $expmap(atomlist_$phase) {
660            lappend atmlst "$atom $atom $phase"
661        }
662        set atmlst [lsort -integer -index 1 $atmlst]
663    } elseif {$expgui(asorttype) == "x"} {
664        # sort on x
665        foreach atom $expmap(atomlist_$phase) {
666            lappend atmlst "$atom [$cmd $phase $atom x]"
667        }
668        set atmlst [lsort -real -index 1 $atmlst]
669    } elseif {$expgui(asorttype) == "y"} {
670        # sort on y
671        foreach atom $expmap(atomlist_$phase) {
672            lappend atmlst "$atom [$cmd $phase $atom y]"
673        }
674        set atmlst [lsort -real -index 1 $atmlst]
675    } elseif {$expgui(asorttype) == "z"} {
676        # sort on z
677        foreach atom $expmap(atomlist_$phase) {
678            lappend atmlst "$atom [$cmd $phase $atom z]"
679        }
680        set atmlst [lsort -real -index 1 $atmlst]
681    } else {
682        # error "Bad expgui(asorttype) = $expgui(asorttype)"
683        # other -- ignore and sort on atom number
684        foreach atom $expmap(atomlist_$phase) {
685            lappend atmlst "$atom $atom $phase"
686        }
687        set atmlst [lsort -integer -index 1 $atmlst]
688
689    }
690    # make a list of atoms in the box
691    set expcons(atmlst$ic) {}
692    foreach tuple $atmlst {
693        set atom [lindex $tuple 0]
694        lappend expcons(atmlst$ic) $atom
695        if {$mm} {
696            $expcons(atomlistbox$ic) insert end [\
697                    format "%-6s%-3s%-2s%3d%4d %-6s" \
698                    [$cmd $phase $atom label] \
699                    [$cmd $phase $atom residue] \
700                    [$cmd $phase $atom group] \
701                    [$cmd $phase $atom resnum] \
702                    $atom \
703                    [$cmd $phase $atom type]]
704        } else {
705            $expcons(atomlistbox$ic) insert end [format "%-6s%3d %-6s" \
706                    [$cmd $phase $atom label] \
707                    $atom \
708                    [$cmd $phase $atom type]]
709        }
710        # select the atom if appropriate
711        if {[lsearch $atomselectlist $atom] != -1} {
712            $expcons(atomlistbox$ic) selection set end
713        }
714    }
715    if {$atomselectlist == "ALL"} {
716        $expcons(atomlistbox$ic) selection set 0 end
717    }
718}
719
720# this is called to change an atomic constraint
721proc SaveAtomConstraint {num top mode} {
722    global expcons expgui
723    # special variables XYZU & Uxx should only occur with num == "new"
724    # then add new constraints
725    if {$expcons(var1) == ""} {
726        MyMessageBox -message \
727            "No variables were selected to constrain" \
728            -parent [winfo toplevel $expcons(atommaster)] \
729            -type {Fix} -default fix -icon error
730        return
731    }
732    set varlist {{}}
733    if {$expcons(var1) == "XYZU+-F"} {set varlist "X Y Z UISO FRAC"}
734    if {$expcons(var1) == "XYZU"} {
735        if {$mode == "mm"} {
736            set varlist "X Y Z UIS"
737        } else {
738            set varlist "X Y Z UISO"
739        }
740    }
741    if {$expcons(var1) == "Uxx"} {set varlist "U11 U22 U33 U12 U23 U13"}
742    set atomlist {}
743    foreach var $varlist {
744        set clist {}
745        for {set ic 1} {$ic < 500} {incr ic} {
746            if [catch {set expcons(varmenu$ic)}] break
747            if [winfo exists $expcons(varmenu$ic)] {
748                set phase $expcons(phase$ic)
749                if {$var == ""} {
750                    set v $expcons(var$ic)
751                } else {
752                    set v $var
753                }
754                if  {$expcons(var1) == "XYZU+-F"} {
755                    set mult 1
756                } else {
757                    set mult $expcons(mult$ic)
758                }
759                set atomlist {}
760                foreach indx [$expcons(atomlistbox$ic) curselection] {
761                    lappend atomlist [lindex $expcons(atmlst$ic) $indx]
762                }
763                if {[llength $atomlist] == [llength $expcons(atmlst$ic)] \
764                        && $v == "UISO"} {
765                    set atomlist ALL
766                } else {
767                    set atomlist [lsort -integer $atomlist]
768                }
769                # ignore this column if phase is invalid or there are no atoms
770                if {![catch {expr $phase}] && \
771                        [llength $atomlist] > 0 && \
772                        $v != ""} {
773                    # error if mult is invalid
774                    if [catch {expr $mult}] {
775                        MyMessageBox -message \
776                                "Multiplier value \"$mult\" in column $ic is invalid" \
777                                -parent [winfo toplevel $expcons(atommaster)] \
778                                -type {Fix} -default fix -icon error
779                        return
780                    }
781                    foreach atom $atomlist {
782                        if  {$expcons(var1) == "XYZU+-F" && \
783                                $var == "FRAC"} {
784                            set mult [expr -1*$mult]
785                        }
786                        lappend clist [list $phase $atom $v $mult]
787                    }
788                }
789            }
790        }
791        if {$atomlist == ""} {
792            MyMessageBox -message \
793                "No atoms were selected to constrain" \
794                -parent [winfo toplevel $expcons(atommaster)] \
795                -type {Fix} -default fix -icon error
796            return
797        }
798        # maximum number of parameters in a constraint is 500
799        if {[llength $clist] > 500} {
800            MyMessageBox -message \
801                    "There are [llength $clist] parameters in this constraint, but only 500 are allowed in an atom constraint." \
802                    -parent [winfo toplevel $expcons(atommaster)] \
803                    -helplink "expgui6.html AtomConstraintsMax" \
804                    -type {Fix} -default fix -icon error
805            return
806        }
807        if {$expcons(var1) == "XYZU+-F" && [llength $atomlist] != 2} {
808            MyMessageBox -message \
809                    "Exactly 2 atoms must be linked with the XYZU+-F option" \
810                    -parent [winfo toplevel $expcons(atommaster)] \
811                    -helplink "expgui6.html XYZUF" \
812                    -type {Fix} -default fix -icon error
813            return
814        }
815        if {$num == "new"} {
816            constrinfo atom add {} $clist
817            RecordMacroEntry "constrinfo atom add {} [list $clist]" 0
818        } elseif {$clist != ""} {
819            constrinfo atom set $num $clist
820            RecordMacroEntry "constrinfo atom set $num [list $clist]" 0
821        } else {
822            constrinfo atom delete $num
823            RecordMacroEntry "constrinfo atom delete $num" 0
824        }
825        incr expgui(changed)
826        RecordMacroEntry "incr expgui(changed)" 0
827    }
828    destroy $top
829    DisplayAtomConstraints $mode
830}
Note: See TracBrowser for help on using the repository browser.