1 | |
---|
2 | |
---|
3 | |
---|
4 | # code for distance restraints (soft constraints) |
---|
5 | proc DisplayDistanceRestraints {} { |
---|
6 | global expcons |
---|
7 | eval destroy [winfo children $expcons(distmaster)] |
---|
8 | |
---|
9 | set leftfr $expcons(distmaster).f1 |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | grid [frame $leftfr -bd 2 -relief groove] -column 0 -row 0 \ |
---|
14 | -sticky nsew |
---|
15 | grid [frame $expcons(distmaster).f2 -bd 2 -relief groove] -column 1 -row 0 \ |
---|
16 | -sticky nsew |
---|
17 | grid rowconfigure $expcons(distmaster) 0 -weight 1 |
---|
18 | grid columnconfigure $expcons(distmaster) 1 -weight 1 |
---|
19 | |
---|
20 | |
---|
21 | # Pick Phase to be Evaluated ********************************************** |
---|
22 | label $leftfr.phlabel -text Phase |
---|
23 | set ::sr_phaselist $::expmap(phaselist) |
---|
24 | eval tk_optionMenu $leftfr.phase sr_entryvar(softphase) $::sr_phaselist |
---|
25 | grid $leftfr.phlabel -column 0 -row 0 |
---|
26 | grid $leftfr.phase -column 1 -row 0 |
---|
27 | #************************************************************************** |
---|
28 | |
---|
29 | grid [label $leftfr.lweight -text "Restraint Weight"] -column 0 -row 2 -sticky sw |
---|
30 | grid [entry $leftfr.weight -width 8 -textvariable entryvar(distrestweight)] -column 1 -row 2 -sticky sw |
---|
31 | set ::entrycmd(distrestweight) "SoftConst weight" |
---|
32 | set ::entrycmd(trace) 0 |
---|
33 | set ::entryvar(distrestweight) [SoftConst weight] |
---|
34 | set ::entrycmd(trace) 1 |
---|
35 | grid [button $leftfr.edit -text "Edit Distance Restraints" -command SR_TEST] -column 0 -row 3 \ |
---|
36 | -sticky sw -columnspan 2 |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | #package require Tk |
---|
42 | #source c:/gsas/expgui/readexp.tcl |
---|
43 | #source c:/gsas/expgui/gsascmds.tcl |
---|
44 | |
---|
45 | #********************************************************************************************* |
---|
46 | #Read Disangle File and Create Bond List (sr_all_bonds)************************************************************************** |
---|
47 | #********************************************************************************************* |
---|
48 | proc SR_Read_Distances {filename} { |
---|
49 | catch {unset ::sr_bond_distance} |
---|
50 | catch {unset ::sr_lookuplist1} |
---|
51 | catch {unset ::sr_lookuplist2} |
---|
52 | set ::sr_all_bonds "" |
---|
53 | if {[file exists $filename]} { |
---|
54 | puts "$filename from [pwd] is opened" |
---|
55 | set fh [open $filename r] |
---|
56 | # puts $fh |
---|
57 | } else { |
---|
58 | puts "$filename not found in directory [pwd]" |
---|
59 | } |
---|
60 | set ::sr_bond_totals -1 |
---|
61 | while {[gets $fh line] >= 0} { |
---|
62 | if {[lindex $line 2] == 0} { |
---|
63 | incr ::sr_bond_totals |
---|
64 | set ::sr_bond_distance($::sr_bond_totals) $line |
---|
65 | #puts "$::sr_bond_distance($::sr_bond_totals)" |
---|
66 | } |
---|
67 | } |
---|
68 | set natoms [phaseinfo 1 natoms] |
---|
69 | #puts "there are $natoms atoms in the file" |
---|
70 | #puts "$::sr_bond_totals bond distances have been read from the file" |
---|
71 | close $fh |
---|
72 | |
---|
73 | #create initial parameter for implimentation of soft restraints |
---|
74 | catch (unset initsoftpar) |
---|
75 | set x 0 |
---|
76 | |
---|
77 | #set ::sr_all_bonds "" |
---|
78 | while {$x < $::sr_bond_totals} { |
---|
79 | |
---|
80 | #phase number (0) |
---|
81 | set initsoftpar($x) [lindex $::sr_bond_distance($x) 1] |
---|
82 | |
---|
83 | #atom number 1 (1) |
---|
84 | lappend initsoftpar($x) [lindex $::sr_bond_distance($x) 5] |
---|
85 | |
---|
86 | #atom number 2 (2) |
---|
87 | lappend initsoftpar($x) [lindex $::sr_bond_distance($x) 6] |
---|
88 | |
---|
89 | #extract symmetry information (3, 4) |
---|
90 | set temp [lindex $::sr_bond_distance($x) 7] |
---|
91 | lappend initsoftpar($x) [expr abs($temp) % 100 * abs($temp) / $temp] |
---|
92 | lappend initsoftpar($x) [expr abs($temp)/100] |
---|
93 | |
---|
94 | #extract unit cell translations (5, 6, 7) |
---|
95 | lappend initsoftpar($x) [expr [string index [lindex $::sr_bond_distance($x) 8] 0] - 5] |
---|
96 | lappend initsoftpar($x) [expr [string index [lindex $::sr_bond_distance($x) 8] 1] - 5] |
---|
97 | lappend initsoftpar($x) [expr [string index [lindex $::sr_bond_distance($x) 8] 2] - 5] |
---|
98 | |
---|
99 | #create bond ID code |
---|
100 | set t2 [string map {" " ""} [set t1 $initsoftpar($x)]] |
---|
101 | set ::sr_restraintdist($t2) "" |
---|
102 | set ::sr_restraintesd($t2) "" |
---|
103 | |
---|
104 | #extract bond distance |
---|
105 | lappend initsoftpar($x) [lindex $::sr_bond_distance($x) 3] |
---|
106 | |
---|
107 | #extract atom type and labels |
---|
108 | set num1 [lindex $::sr_bond_distance($x) 5] |
---|
109 | set num2 [lindex $::sr_bond_distance($x) 6] |
---|
110 | set type1 [atominfo 1 [lindex $::sr_bond_distance($x) 5] type] |
---|
111 | set type1 [lindex [split $type1 {+-}] 0] |
---|
112 | set type2 [atominfo 1 [lindex $::sr_bond_distance($x) 6] type] |
---|
113 | set type2 [lindex [split $type2 {+-}] 0] |
---|
114 | lappend initsoftpar($x) $type1 |
---|
115 | lappend initsoftpar($x) $type2 |
---|
116 | |
---|
117 | lappend initsoftpar($x) [atominfo 1 [lindex $::sr_bond_distance($x) 5] label] |
---|
118 | lappend initsoftpar($x) [atominfo 1 [lindex $::sr_bond_distance($x) 6] label] |
---|
119 | |
---|
120 | #puts "$initsoftpar($x)" |
---|
121 | #set atom types into array |
---|
122 | lappend ::sr_lookuplist1($type1) $x |
---|
123 | lappend ::sr_lookuplist2($type2) $x |
---|
124 | |
---|
125 | #add bond code to list element |
---|
126 | lappend initsoftpar($x) $t2 |
---|
127 | |
---|
128 | #create master list of bonds |
---|
129 | lappend ::sr_all_bonds $initsoftpar($x) |
---|
130 | |
---|
131 | incr x |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | #****************************************************************************************** |
---|
136 | #Make Scroll Table Procedure with Scrollbar to left **************************************** |
---|
137 | #****************************************************************************************** |
---|
138 | # creates a table that is scrollable in both x and y, use ResizeScrollTable |
---|
139 | # to set sizes after gridding the boxes |
---|
140 | proc SR_Make_Scroll_Table {box} { |
---|
141 | grid [label $box.0] -column 0 -row 0 |
---|
142 | grid [set tbox [canvas $box.top \ |
---|
143 | -scrollregion {0 0 10 10} \ |
---|
144 | -xscrollcommand "sync2boxesX $box.top $box.can $box.scroll" \ |
---|
145 | -width 10 -height 10]] \ |
---|
146 | -sticky sew -row 0 -column 1 |
---|
147 | grid [set sbox [canvas $box.side \ |
---|
148 | -scrollregion {0 0 10 10} \ |
---|
149 | -yscrollcommand "sync2boxesY $box.side $box.can $box.yscroll" \ |
---|
150 | -width 10 -height 10]] \ |
---|
151 | -sticky nes -row 1 -column 0 |
---|
152 | grid [set bbox [canvas $box.can \ |
---|
153 | -scrollregion {0 0 10 10} \ |
---|
154 | -yscrollcommand "sync2boxesY $box.can $box.side $box.yscroll" \ |
---|
155 | -xscrollcommand "sync2boxesX $box.can $box.top $box.scroll" \ |
---|
156 | -width 200 -height 200 -bg lightgrey]] \ |
---|
157 | -sticky news -row 1 -column 1 |
---|
158 | grid [set sxbox [scrollbar $box.scroll -orient horizontal \ |
---|
159 | -command "move2boxesX \" $box.can $box.top \" "]] \ |
---|
160 | -sticky ew -row 2 -column 1 |
---|
161 | grid [set sybox [scrollbar $box.yscroll \ |
---|
162 | -command "move2boxesY \" $box.can $box.side \" "]] \ |
---|
163 | -sticky ns -row 1 -column 0 |
---|
164 | frame $tbox.f -bd 0 |
---|
165 | $tbox create window 0 0 -anchor nw -window $tbox.f |
---|
166 | frame $bbox.f -bd 2 |
---|
167 | $bbox create window 0 0 -anchor nw -window $bbox.f |
---|
168 | frame $sbox.f -bd 2 -relief raised |
---|
169 | $sbox create window 0 0 -anchor nw -window $sbox.f |
---|
170 | grid columnconfig $box 1 -weight 1 |
---|
171 | grid rowconfig $box 1 -weight 1 |
---|
172 | return [list $tbox.f $bbox.f $sbox.f $box.0] |
---|
173 | } |
---|
174 | |
---|
175 | #************************************************************************************** |
---|
176 | #SR_Resize_Scroll_Table Procedure ********************************************************* |
---|
177 | #************************************************************************************** |
---|
178 | proc SR_Resize_Scroll_Table {box} { |
---|
179 | update idletasks |
---|
180 | for {set i 0} {$i < [lindex [grid size $box.can.f] 0]} {incr i} { |
---|
181 | set x1 [lindex [grid bbox $box.can.f $i 0] 2] |
---|
182 | set x2 [lindex [grid bbox $box.top.f $i 0] 2] |
---|
183 | if {$x2 > $x1} {set x1 $x2} |
---|
184 | grid columnconfigure $box.top.f $i -minsize $x1 |
---|
185 | grid columnconfigure $box.can.f $i -minsize $x1 |
---|
186 | } |
---|
187 | for {set i 0} {$i < [lindex [grid size $box.can.f] 1]} {incr i} { |
---|
188 | set x1 [lindex [grid bbox $box.can.f 0 $i] 3] |
---|
189 | set x2 [lindex [grid bbox $box.side.f 0 $i] 3] |
---|
190 | if {$x2 > $x1} {set x1 $x2} |
---|
191 | grid rowconfigure $box.can.f $i -minsize $x1 |
---|
192 | grid rowconfigure $box.side.f $i -minsize $x1 |
---|
193 | } |
---|
194 | update idletasks |
---|
195 | set sizes [grid bbox $box.can.f] |
---|
196 | $box.can config -scrollregion $sizes |
---|
197 | $box.side config -scrollregion $sizes |
---|
198 | $box.top config -scrollregion $sizes |
---|
199 | $box.top config -height [lindex [grid bbox $box.top.f] 3] |
---|
200 | $box.side config -width [lindex [grid bbox $box.side.f] 2] |
---|
201 | } |
---|
202 | |
---|
203 | #************************************************************************************** |
---|
204 | # Procedure to sort soft restraints --------------------------------------------- |
---|
205 | #************************************************************************************** |
---|
206 | proc SR_Sort {whichbutton main} { |
---|
207 | # reset all button labels |
---|
208 | $::sr_top.alabel1 config -text "Atom 1" |
---|
209 | $::sr_top.alabel2 config -text "Atom 2" |
---|
210 | $::sr_top.dlabel1 config -text "Distance" |
---|
211 | |
---|
212 | if {$whichbutton == "atom1"} { |
---|
213 | if {$::sr_atom1_button == 1} { |
---|
214 | set ::sr_prsort [lsort -integer -decreasing -index 1 $::sr_all_bonds] |
---|
215 | $::sr_top.alabel1 config -text "Atom 1 \u2193" |
---|
216 | } else { |
---|
217 | set ::sr_prsort [lsort -integer -increasing -index 1 $::sr_all_bonds] |
---|
218 | $::sr_top.alabel1 config -text "Atom 1 \u2191" |
---|
219 | } |
---|
220 | set x [expr $::sr_atom1_button * -1] |
---|
221 | set ::sr_atom1_button $x |
---|
222 | #puts $::sr_atom1_button |
---|
223 | } elseif {$whichbutton == "atom2"} { |
---|
224 | if {$::sr_atom2_button == 1} { |
---|
225 | set ::sr_prsort [lsort -integer -decreasing -index 2 $::sr_all_bonds] |
---|
226 | $::sr_top.alabel2 config -text "Atom 2 \u2193" |
---|
227 | } else { |
---|
228 | set ::sr_prsort [lsort -integer -increasing -index 2 $::sr_all_bonds] |
---|
229 | $::sr_top.alabel2 config -text "Atom 2 \u2191" |
---|
230 | } |
---|
231 | set x [expr $::sr_atom2_button * -1] |
---|
232 | set ::sr_atom2_button $x |
---|
233 | } else { |
---|
234 | if {$::sr_distance_button == 1} { |
---|
235 | puts "distance" |
---|
236 | set ::sr_prsort [lsort -increasing -index 8 $::sr_all_bonds] |
---|
237 | $::sr_top.dlabel1 config -text "Distance \u2193" |
---|
238 | } else { |
---|
239 | set ::sr_prsort [lsort -decreasing -index 8 $::sr_all_bonds] |
---|
240 | $::sr_top.dlabel1 config -text "Distance \u2191" |
---|
241 | } |
---|
242 | set x [expr $::sr_distance_button * -1] |
---|
243 | set ::sr_distance_button $x |
---|
244 | } |
---|
245 | SR_Fill_Display $main |
---|
246 | |
---|
247 | } |
---|
248 | #********************************************************************************* |
---|
249 | #Procedure to set up soft display ************************************************ |
---|
250 | #********************************************************************************* |
---|
251 | |
---|
252 | proc SR_Display {args} { |
---|
253 | #global rprint |
---|
254 | destroy .mainrestraintbox.sr_rvaluebox |
---|
255 | set ::sr_rb .mainrestraintbox.sr_rvaluebox |
---|
256 | frame $::sr_rb |
---|
257 | pack $::sr_rb -side top -fill both -expand 1 |
---|
258 | |
---|
259 | foreach {::sr_top main side lbl} [MakeScrollTable $::sr_rb] {} |
---|
260 | set ::contraintmainbox $main |
---|
261 | |
---|
262 | button $::sr_top.alabel1 -text "Atom 1 " -command "SR_Sort atom1 $main" |
---|
263 | button $::sr_top.alabel2 -text "Atom 2 " -command "SR_Sort atom2 $main" |
---|
264 | button $::sr_top.dlabel1 -text "Distance " -command "SR_Sort distance $main" |
---|
265 | |
---|
266 | grid $::sr_top.alabel1 -column 1 -row 2 |
---|
267 | grid $::sr_top.alabel2 -column 2 -row 2 |
---|
268 | grid $::sr_top.dlabel1 -column 3 -row 2 |
---|
269 | |
---|
270 | label $::sr_top.rlabel1 -text "Restraint" |
---|
271 | label $::sr_top.rlabel2 -text "esd" |
---|
272 | button $::sr_top.rcon1 -text "Check All" -width 10 -command { |
---|
273 | set ::sr_checkall 1 |
---|
274 | SR_Set_All_Check_Buttons |
---|
275 | grid forget $::sr_top.rcon1 |
---|
276 | grid $::sr_top.rcon2 -column 6 -row 2 -padx 5 |
---|
277 | } |
---|
278 | |
---|
279 | button $::sr_top.rcon2 -text "Clear All" -width 10 -command { |
---|
280 | set ::sr_checkall 0 |
---|
281 | SR_Set_All_Check_Buttons |
---|
282 | grid forget $::sr_top.rcon2 |
---|
283 | grid $::sr_top.rcon1 -column 6 -row 2 -padx 5 |
---|
284 | } |
---|
285 | |
---|
286 | grid $::sr_top.rlabel1 -column 4 -row 2 -padx 20 |
---|
287 | grid $::sr_top.rlabel2 -column 5 -row 2 -padx 20 |
---|
288 | grid $::sr_top.rcon1 -column 6 -row 2 -padx 5 |
---|
289 | |
---|
290 | SR_Sort atom1 $main |
---|
291 | SR_Fill_Display $main |
---|
292 | } |
---|
293 | |
---|
294 | #***************************************************************************************** |
---|
295 | #Procedure to fill in sorted Restraint and esd data ************************************** |
---|
296 | #***************************************************************************************** |
---|
297 | proc SR_Fill_Display {main args} { |
---|
298 | eval destroy [winfo children $main] |
---|
299 | set choice $::sr_entryvar(choicenum) |
---|
300 | set atomreq1 $::sr_entryvar(softatom1) |
---|
301 | set atomreq2 $::sr_entryvar(softatom2) |
---|
302 | set phasereq $::sr_entryvar(softphase) |
---|
303 | |
---|
304 | set len [llength $::sr_prsort] |
---|
305 | set rownum 0 |
---|
306 | for {set i 0} {$i <= $len} {incr i} { |
---|
307 | set rprint [lindex $::sr_prsort $i] |
---|
308 | set atomid1 [lindex $rprint 9] |
---|
309 | set atomid2 [lindex $rprint 10] |
---|
310 | if {$::sr_entryvar(softphase) == [lindex $rprint 0]} { |
---|
311 | if {[string trim $::sr_dminvalue] == ""} {set Dmin 0} else {set Dmin $::sr_dminvalue} |
---|
312 | if {[string trim $::sr_dmaxvalue] == ""} {set Dmax 1000} else {set Dmax $::sr_dmaxvalue} |
---|
313 | if {[lindex $rprint 8] >= $Dmin && [lindex $rprint 8] <= $Dmax} { |
---|
314 | if {$atomreq1 == "" || $atomreq1 == "all" || $atomreq1 == $atomid1} { |
---|
315 | if {$atomreq2 == "" || $atomreq2 == "all" || $atomreq2 == $atomid2} { |
---|
316 | if {$choice == 0 || ($choice == 1 && [string trim $::sr_restraintdist([lindex $rprint 13])] != "") \ |
---|
317 | || ($choice == 2 && [string trim $::sr_restraintdist([lindex $rprint 13])] == "") } { |
---|
318 | label $main.ratom1$i -text [lindex $rprint 11] -justify center -anchor center |
---|
319 | label $main.ratom2$i -text [lindex $rprint 12] -justify center -anchor center |
---|
320 | label $main.rdistance$i -text [lindex $rprint 8] -justify center -anchor center |
---|
321 | entry $main.restraint$i -width 8 -textvariable ::sr_restraintdist([lindex $rprint 13]) -takefocus 1 |
---|
322 | bind $main.restraint$i <KeyRelease> {SR_Validate_Soft %W distance} |
---|
323 | entry $main.restesd$i -width 8 -textvariable ::sr_restraintesd([lindex $rprint 13]) -takefocus 1 |
---|
324 | bind $main.restesd$i <KeyRelease> {SR_Validate_Soft %W esd} |
---|
325 | checkbutton $main.sr_crestraint$i -variable ::sr_crestraint([lindex $rprint 13]) |
---|
326 | incr rownum |
---|
327 | grid $main.ratom1$i -column 1 -row $rownum |
---|
328 | grid $main.ratom2$i -column 2 -row $rownum |
---|
329 | grid $main.rdistance$i -column 3 -row $rownum |
---|
330 | grid $main.restraint$i -column 4 -row $rownum |
---|
331 | grid $main.restesd$i -column 5 -row $rownum |
---|
332 | grid $main.sr_crestraint$i -column 6 -row $rownum |
---|
333 | $main.ratom1$i conf -width 8 |
---|
334 | $main.ratom2$i conf -width 8 |
---|
335 | $main.rdistance$i conf -width 8 |
---|
336 | bind $main.restraint$i <ButtonPress> {SR_Set_Rval %W} |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | bind $::sr_rb <Configure> {ResizeScrollTable $::sr_rb} |
---|
345 | } |
---|
346 | #**************************************************************************** |
---|
347 | #Procedure for updating sr_rvalue and sr_resd Boxes ******************************* |
---|
348 | #**************************************************************************** |
---|
349 | proc SR_Set_Rval {window} { |
---|
350 | set ::sr_rvalue [$window get] |
---|
351 | set ::sr_resd [[regsub ".f.restraint" $window ".f.restesd"] get] |
---|
352 | } |
---|
353 | |
---|
354 | #**************************************************************************** |
---|
355 | #Error Checking Procedures for Entry Boxes ********************************** |
---|
356 | #**************************************************************************** |
---|
357 | |
---|
358 | proc SR_Validate_Num {val1} { |
---|
359 | # is it a valid number? |
---|
360 | if {[string trim $val1] != ""} { |
---|
361 | expr $val1 |
---|
362 | if {$val1 < 0} {error} |
---|
363 | } |
---|
364 | } |
---|
365 | |
---|
366 | proc SR_Validate_Soft {win type} { |
---|
367 | set val [$win get] |
---|
368 | if {[catch { |
---|
369 | SR_Validate_Num $val |
---|
370 | }]} { |
---|
371 | # error on validation |
---|
372 | $win config -fg red |
---|
373 | $::srcb3.rbutton3 config -bg red -text "Invalid Restraints" |
---|
374 | set ::sr_error 1 |
---|
375 | } else { |
---|
376 | # valid value |
---|
377 | $win config -fg black |
---|
378 | $::srcb3.rbutton3 config -bg green -text "Save Restraints to EXP File" |
---|
379 | set ::sr_error 0 |
---|
380 | } |
---|
381 | } |
---|
382 | |
---|
383 | #************************************************************************************** |
---|
384 | #Procedure to load current restraints, flag presetraints and build restraint only list |
---|
385 | #************************************************************************************** |
---|
386 | proc SR_Load_Restraints {args} { |
---|
387 | set temp_res [SoftConst restraintlist] |
---|
388 | set lenr [llength $temp_res] |
---|
389 | set ::sr_restraints_only "" |
---|
390 | |
---|
391 | #for {set i 0} {$i < $lenr} {incr i} { |
---|
392 | # set temp_res1 [lindex $temp_res $i] |
---|
393 | #} |
---|
394 | foreach temp_res1 $temp_res { |
---|
395 | set t1 "[lindex $temp_res1 0] [lindex $temp_res1 1] [lindex $temp_res1 2] \ |
---|
396 | [lindex $temp_res1 3] [lindex $temp_res1 4] [lindex $temp_res1 5] \ |
---|
397 | [lindex $temp_res1 6] [lindex $temp_res1 7]" |
---|
398 | set t2 [string map {" " ""} $t1] |
---|
399 | set ::sr_restraintdist($t2) [lindex $temp_res1 8] |
---|
400 | set ::sr_restraintesd($t2) [lindex $temp_res1 9] |
---|
401 | } |
---|
402 | |
---|
403 | #set ::sr_restraints_only "" |
---|
404 | |
---|
405 | for {set j 0} {$j < $::sr_bond_totals} {incr j} { |
---|
406 | set temp_dist [lindex $::sr_all_bonds $j] |
---|
407 | if {$::sr_restraintdist([lindex $temp_dist 13]) != ""} { |
---|
408 | lappend ::sr_restraints_only $temp_dist |
---|
409 | } |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | |
---|
414 | #************************************************************************* |
---|
415 | #write soft restraints to file ******************************************* |
---|
416 | #************************************************************************* |
---|
417 | proc SR_Write_Restraints { } { |
---|
418 | if {$::sr_error == 0} { |
---|
419 | # set ::sr_write "" |
---|
420 | set len [llength $::sr_all_bonds] |
---|
421 | for {set i 0} {$i <= [expr $len-1]} {incr i} { |
---|
422 | set temp [lindex $::sr_all_bonds $i] |
---|
423 | if {[string trim $::sr_restraintdist([lindex $temp 13])] != ""} { |
---|
424 | set softrest "[lindex $temp 0] [lindex $temp 1] \ |
---|
425 | [lindex $temp 2] [lindex $temp 3] [lindex $temp 4] \ |
---|
426 | [lindex $temp 5] [lindex $temp 6] [lindex $temp 7]\ |
---|
427 | $::sr_restraintdist([lindex $temp 13])\ |
---|
428 | $::sr_restraintesd([lindex $temp 13])" |
---|
429 | lappend sr_write $softrest |
---|
430 | } |
---|
431 | } |
---|
432 | # put the entire restraint list back into the .EXP file |
---|
433 | SoftConst restraintlist set $sr_write |
---|
434 | # indicate a change to the .EXP file |
---|
435 | incr ::expgui(changed) |
---|
436 | # close the window and return access to main window |
---|
437 | destroy .mainrestraintbox |
---|
438 | afterputontop |
---|
439 | } else { |
---|
440 | bell |
---|
441 | #puts "invalid restaint / esd. Save aborted" |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | #********************************************************************************* |
---|
446 | #Procedure to update restraints ************************************************* |
---|
447 | #********************************************************************************* |
---|
448 | |
---|
449 | proc SR_Update_Restraints {args} { |
---|
450 | foreach i [array names ::sr_crestraint] { |
---|
451 | if {$::sr_crestraint($i) == 1} { |
---|
452 | #puts "::sr_restraintdist($i) $::sr_rvalue" |
---|
453 | set ::sr_restraintdist($i) $::sr_rvalue |
---|
454 | set ::sr_restraintesd($i) $::sr_resd |
---|
455 | } |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | #******************************************************************************* |
---|
460 | #Procedure to delete restraints ************************************************ |
---|
461 | #******************************************************************************* |
---|
462 | |
---|
463 | proc SR_Delete_Restraints {args} { |
---|
464 | foreach i [array names ::sr_crestraint] { |
---|
465 | if {$::sr_crestraint($i) == 1} { |
---|
466 | set ::sr_restraintdist($i) "" |
---|
467 | set ::sr_restraintesd($i) "" |
---|
468 | } |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | #********************************************************************************* |
---|
473 | #set flag for restraint update *************************************************** |
---|
474 | #********************************************************************************* |
---|
475 | proc SR_Set_All_Check_Buttons { } { |
---|
476 | # loop over all widgets in main frame |
---|
477 | foreach w [winfo children $::contraintmainbox] { |
---|
478 | # pick out checkboxes which have crest |
---|
479 | if {[string first crest $w] != -1} { |
---|
480 | $w deselect |
---|
481 | if {$::sr_checkall} { |
---|
482 | $w invoke |
---|
483 | } |
---|
484 | } |
---|
485 | } |
---|
486 | } |
---|
487 | |
---|
488 | #********************************************************************************* |
---|
489 | #Main Program Begin*************************************************************** |
---|
490 | #********************************************************************************* |
---|
491 | proc SR_Main_Editor {args} { |
---|
492 | |
---|
493 | catch {destroy .mainrestraintbox} |
---|
494 | set mrb .mainrestraintbox |
---|
495 | toplevel $mrb |
---|
496 | #pack $mrb -side top |
---|
497 | wm title $mrb "Soft Restraint Control Panel" |
---|
498 | #wm geometry $mrb 415x500+10+10 |
---|
499 | #wm geometry $mrb {} |
---|
500 | set srcb1 $mrb.srconbox1 |
---|
501 | set srcb2 $mrb.srconbox2 |
---|
502 | set ::srcb3 $mrb.srconbox3 |
---|
503 | frame $srcb1 -bd 2 -relief groove -pady 5 |
---|
504 | frame $srcb2 -bd 2 -relief groove -pady 5 |
---|
505 | frame $::srcb3 -bd 2 -relief groove -pady 5 |
---|
506 | pack $srcb1 -side top -anchor w -fill x |
---|
507 | pack $srcb2 -side top -anchor w -fill x |
---|
508 | pack $::srcb3 -side bottom -anchor w -fill x |
---|
509 | |
---|
510 | label $srcb1.atomlabel1 -text "Atom Type 1" |
---|
511 | label $srcb1.atomlabel2 -text "Atom Type 2" |
---|
512 | label $srcb1.dminlabel -text "Dmin" |
---|
513 | label $srcb1.dmaxlabel -text "Dmax" |
---|
514 | label $srcb2.restlabel -text "Restraint Value" -width 16 -anchor w |
---|
515 | label $srcb2.restlabelesd -text "esd" |
---|
516 | eval tk_optionMenu $srcb1.atom1 ::sr_entryvar(softatom1) "[lsort [array names ::sr_lookuplist1]] all" |
---|
517 | eval tk_optionMenu $srcb1.atom2 ::sr_entryvar(softatom2) "[lsort [array names ::sr_lookuplist2]] all" |
---|
518 | |
---|
519 | |
---|
520 | entry $srcb1.sr_dminvalue -width 8 -textvariable ::sr_dminvalue -takefocus 1 |
---|
521 | entry $srcb1.sr_dmaxvalue -width 8 -textvariable ::sr_dmaxvalue -takefocus 1 |
---|
522 | entry $srcb2.sr_rvalue -width 8 -textvariable ::sr_rvalue -takefocus 1 |
---|
523 | entry $srcb2.sr_resd -width 8 -textvariable ::sr_resd -takefocus 1 |
---|
524 | |
---|
525 | bind $srcb1.sr_dminvalue <KeyRelease> {SR_Validate_Soft %W dmin} |
---|
526 | bind $srcb1.sr_dmaxvalue <KeyRelease> {SR_Validate_Soft %W dmax} |
---|
527 | bind $srcb2.sr_rvalue <KeyRelease> {SR_Validate_Soft %W sr_rvalue} |
---|
528 | bind $srcb2.sr_resd <KeyRelease> {SR_Validate_Soft %W sr_resd} |
---|
529 | |
---|
530 | button $srcb1.recalc -text "Filter" -bd 6 -command {SR_Display} |
---|
531 | button $srcb2.rbutton1 -text "check update" -command {SR_Update_Restraints} |
---|
532 | button $srcb2.rbutton2 -text "check remove" -command {SR_Delete_Restraints} |
---|
533 | button $::srcb3.rbutton3 -text "Save Restraints to EXP File" -bd 6 -bg green -command {SR_Write_Restraints} |
---|
534 | button $::srcb3.rbutton4 -text "Cancel" -command {destroy .mainrestraintbox; afterputontop} |
---|
535 | |
---|
536 | grid $srcb1.atomlabel1 -column 1 -row 0 |
---|
537 | grid $srcb1.atom1 -column 2 -row 0 |
---|
538 | $srcb1.atom1 conf -width 2 |
---|
539 | grid $srcb1.atomlabel2 -column 1 -row 1 |
---|
540 | grid $srcb1.atom2 -column 2 -row 1 |
---|
541 | $srcb1.atom2 conf -width 2 |
---|
542 | grid $srcb1.recalc -column 4 -row 2 -padx 5 |
---|
543 | $srcb1.recalc conf -width 7 |
---|
544 | |
---|
545 | grid $srcb1.dminlabel -column 3 -row 0 |
---|
546 | grid $srcb1.sr_dminvalue -column 4 -row 0 |
---|
547 | grid $srcb1.dmaxlabel -column 3 -row 1 |
---|
548 | grid $srcb1.sr_dmaxvalue -column 4 -row 1 |
---|
549 | |
---|
550 | |
---|
551 | set choice {"Show All Bonds" "Restrained Bonds" "Unrestrained Bonds"} |
---|
552 | set ::sr_entryvar(choice) "Show All Bonds" |
---|
553 | |
---|
554 | set m1 [eval tk_optionMenu $srcb1.rcon3 sr_entryvar(choice) $choice] |
---|
555 | # set up a variable to track menu choices by number. Do this by adding a command |
---|
556 | # to each item in the option menu |
---|
557 | foreach i {0 1 2} { |
---|
558 | $m1 entryconfig $i -command "set ::sr_entryvar(choicenum) $i" |
---|
559 | } |
---|
560 | grid $srcb1.rcon3 -column 1 -row 2 -padx 5 |
---|
561 | $srcb1.rcon3 config -width 23 |
---|
562 | grid configure $srcb1.rcon3 -columnspan 2 |
---|
563 | |
---|
564 | grid $srcb2.restlabel -column 0 -row 3 -sticky w |
---|
565 | grid $srcb2.sr_rvalue -column 1 -row 3 |
---|
566 | grid $srcb2.restlabelesd -column 2 -row 3 |
---|
567 | grid $srcb2.sr_resd -column 3 -row 3 |
---|
568 | grid $srcb2.rbutton1 -column 4 -row 3 -padx 5 |
---|
569 | grid $srcb2.rbutton2 -column 5 -row 3 -padx 5 |
---|
570 | |
---|
571 | grid $::srcb3.rbutton3 -column 0 -row 0 |
---|
572 | grid $::srcb3.rbutton4 -column 0 -row 1 -pady 5 |
---|
573 | |
---|
574 | |
---|
575 | |
---|
576 | SR_Display |
---|
577 | |
---|
578 | foreach item [trace vinfo ::sr_entryvar(softatom1)] { |
---|
579 | eval trace vdelete ::sr_entryvar(softatom1) $item |
---|
580 | } |
---|
581 | trace variable ::sr_entryvar(softatom1) w SR_Display |
---|
582 | |
---|
583 | foreach item [trace vinfo ::sr_entryvar(softatom2)] { |
---|
584 | eval trace vdelete ::sr_entryvar(softatom2) $item |
---|
585 | } |
---|
586 | trace variable ::sr_entryvar(softatom2) w SR_Display |
---|
587 | |
---|
588 | foreach item [trace vinfo ::sr_entryvar(choicenum)] { |
---|
589 | eval trace vdelete ::sr_entryvar(choicenum) $item |
---|
590 | } |
---|
591 | trace variable ::sr_entryvar(choicenum) w SR_Display |
---|
592 | |
---|
593 | foreach item [trace vinfo ::sr_entryvar(softphase)] { |
---|
594 | eval trace vdelete ::sr_entryvar(softphase) $item |
---|
595 | } |
---|
596 | trace variable ::sr_entryvar(softphase) w SR_Display |
---|
597 | putontop $mrb |
---|
598 | |
---|
599 | #list of global variables and procedures |
---|
600 | #::sr_bond_distance |
---|
601 | #::sr_lookuplist1 |
---|
602 | #::sr_lookuplist2 |
---|
603 | #::sr_bond_totals |
---|
604 | #::sr_rb |
---|
605 | #::sr_top |
---|
606 | #::sr_checkall |
---|
607 | #::sr_entryvar(choicenum) |
---|
608 | #::sr_entryvar(softatom1) |
---|
609 | #::sr_entryvar(softatom2) |
---|
610 | #::sr_entryvar(softphase) |
---|
611 | #::sr_dminvalue |
---|
612 | #::sr_dmaxvalue |
---|
613 | #::sr_restraintdist |
---|
614 | #::sr_restraintesd |
---|
615 | #::sr_rvalue |
---|
616 | #::sr_resd |
---|
617 | #::srcb4.rbutton3 |
---|
618 | #::sr_crestraint |
---|
619 | #::sr_phaselist |
---|
620 | #::sr_restraints_only |
---|
621 | #::sr_prsort |
---|
622 | #::sr_all_bonds |
---|
623 | |
---|
624 | #SR_Read_Distances |
---|
625 | #SR_Make_ScrollTable |
---|
626 | #SR_Resize_Scroll_Table |
---|
627 | #SR_Display |
---|
628 | #SR_Set_Rval |
---|
629 | #SR_Validate_Num |
---|
630 | #SR_Load_Restraints |
---|
631 | #SR_Write_Restraints |
---|
632 | #SR_Update_Restraints |
---|
633 | #SR_Delete_Restraints |
---|
634 | #SR_Set_All_Check_Buttons |
---|
635 | #SR_Build |
---|
636 | |
---|
637 | } |
---|
638 | #************************************************************************ |
---|
639 | #Procedure to Initialize variables *************************************** |
---|
640 | #************************************************************************* |
---|
641 | proc SR_Initialize {} { |
---|
642 | set ::sr_atom1_button 1 |
---|
643 | set ::sr_atom2_button 1 |
---|
644 | set ::sr_distance_button 1 |
---|
645 | set ::sr_entryvar(choicenum) 0 |
---|
646 | set ::sr_entryvar(softphase) "1" |
---|
647 | set ::sr_entryvar(softatom1) "all" |
---|
648 | set ::sr_entryvar(softatom2) "all" |
---|
649 | set ::sr_phaselist $::expmap(phaselist) |
---|
650 | set ::sr_error 0 |
---|
651 | set ::sr_restraints_only "" |
---|
652 | set ::sr_all_bonds "" |
---|
653 | set ::sr_prsort $::sr_all_bonds |
---|
654 | } |
---|
655 | |
---|
656 | |
---|
657 | |
---|
658 | #expload TEST3.EXP |
---|
659 | #mapexp |
---|
660 | SR_Initialize |
---|
661 | #SR_Read_Distances test2.disagl |
---|
662 | #SR_Load_Restraints |
---|
663 | #SR_Main_Editor |
---|
664 | #SR_Load_Restraints |
---|
665 | |
---|
666 | proc SR_TEST {} { |
---|
667 | SR_Read_Distances test2.disagl |
---|
668 | SR_Load_Restraints |
---|
669 | SR_Main_Editor |
---|
670 | } |
---|
671 | |
---|
672 | #*********************************************************************** |
---|
673 | #Build Hard List of Restraints ***************************************** |
---|
674 | #*********************************************************************** |
---|
675 | proc SR_Hard_List {args} { |
---|
676 | |
---|
677 | destroy .sr_hardbox |
---|
678 | set ::sr_hb .sr_hardbox |
---|
679 | frame $::sr_hb |
---|
680 | pack $::sr_hb -side top -fill both -expand 1 |
---|
681 | |
---|
682 | foreach {::sr_hard main side lbl} [MakeScrollTable $::sr_hb] {} |
---|
683 | set ::contraintmainbox $main |
---|
684 | |
---|
685 | |
---|
686 | set resnum [llength $::sr_restraints_only] |
---|
687 | puts $resnum |
---|
688 | |
---|
689 | |
---|
690 | |
---|
691 | } |
---|
692 | |
---|
693 | |
---|
694 | |
---|
695 | |
---|
696 | |
---|
697 | |
---|
698 | |
---|
699 | |
---|
700 | |
---|
701 | |
---|
702 | |
---|
703 | |
---|
704 | |
---|
705 | |
---|
706 | |
---|
707 | |
---|