1 | |
---|
2 | set ::rb_loader(cartesian) RB_Cartesian_Load |
---|
3 | set ::rb_descriptor(cartesian) "Cartesian coordinates from text file" |
---|
4 | |
---|
5 | |
---|
6 | proc RB_Cartesian_Load {args} { |
---|
7 | |
---|
8 | destroy .cartesian |
---|
9 | toplevel .cartesian |
---|
10 | set cart .cartesian |
---|
11 | |
---|
12 | |
---|
13 | pack [frame $cart.con -bd 2 -relief groove] -side top |
---|
14 | pack [frame $cart.display -bd 2 -relief groove] -side top -expand 1 -fill both |
---|
15 | pack [frame $cart.save -bd 2 -relief groove] -side bottom |
---|
16 | wm title $cart "Load rigid body information from cartesian coordinate file" |
---|
17 | wm geometry $cart 600x600+10+10 |
---|
18 | set ::rb_file_load "" |
---|
19 | set ::rb_cartfile "" |
---|
20 | set filelist "" |
---|
21 | set files [glob -nocomplain [file join $::expgui(scriptdir) *.cart]] |
---|
22 | foreach file $files { |
---|
23 | lappend ::rb_cartfile [lindex [string map {"/" " "} $file] end] |
---|
24 | } |
---|
25 | # puts $::rb_cartfile |
---|
26 | set ::rb_file_load [lindex $::rb_cartfile 0] |
---|
27 | # grid [label $cart.con.lbl -text "Choose Z-Matrix file to load"] -row 1 -column 0 |
---|
28 | # eval tk_optionMenu $cart.con.file ::rb_file_load $::rb_cartfile |
---|
29 | # grid $cart.con.file -row 1 -column 1 |
---|
30 | |
---|
31 | grid [button $cart.con.but -text "Load Coordinates from File" -width 22 -command "RB_cart $cart.display"] -row 2 -column 1 |
---|
32 | grid [button $cart.save.but2 -text "Save Cartesian \n Coordinates" -width 15 -command "RB_cart_Build"] -row 2 -column 1 -padx 5 |
---|
33 | $cart.save.but2 config -state disable |
---|
34 | grid [button $cart.save.but3 -text "Abort" -width 15 -command "destroy .cartesian"] -row 2 -column 3 -padx 5 -sticky ns |
---|
35 | } |
---|
36 | |
---|
37 | proc RB_cart {location args} { |
---|
38 | catch {unset array ::tline} |
---|
39 | set ::rb_file_load [tk_getOpenFile -parent .cartesian -filetypes { |
---|
40 | {"Cartesian input" .cart} {"All files" *}}] |
---|
41 | if {[string trim $::rb_file_load] == ""} return |
---|
42 | set fh [open $::rb_file_load r] |
---|
43 | set ::rb_linenum 0 |
---|
44 | while {[gets $fh line] >= 0} { |
---|
45 | set line [string trim $line] |
---|
46 | if {$line == ""} continue |
---|
47 | # puts "blankcheck = $blankcheck\ntemp = $temp" |
---|
48 | # set temp [string trim $line " "] |
---|
49 | # if {$blankcheck != "0" && $blankcheck != "-1"} |
---|
50 | # if {$blankcheck != ""} { |
---|
51 | incr ::rb_linenum |
---|
52 | set ::tline($::rb_linenum) [string map {, " "} $line] |
---|
53 | puts "::tline($::rb_linenum) = $::tline($::rb_linenum) " |
---|
54 | # } |
---|
55 | |
---|
56 | |
---|
57 | } |
---|
58 | RB_cart_Display $location |
---|
59 | .cartesian.save.but2 config -state normal |
---|
60 | |
---|
61 | } |
---|
62 | |
---|
63 | proc RB_cart_Display {location args} { |
---|
64 | |
---|
65 | eval destroy [winfo children $location] |
---|
66 | foreach {top main side lbl} [MakeScrollTable $location] {} |
---|
67 | set col [llength $::tline(1)] |
---|
68 | grid [label $top.col -justify center -text "Ignore \n line"] -row 0 -column 0 |
---|
69 | set ::rb_cart_col(1) "label" |
---|
70 | set ::rb_cart_col(2) "X" |
---|
71 | set ::rb_cart_col(3) "Y" |
---|
72 | set ::rb_cart_col(4) "Z" |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | set ::rb_colnum 0 |
---|
77 | for {set linenum 1} {$linenum <= $::rb_linenum} {incr linenum} { |
---|
78 | for {set colnum 0} {$colnum <= [expr [llength $::tline($linenum)] -1]} {incr colnum} { |
---|
79 | grid [label $main.cart$::rb_colnum -text [lindex $::tline($linenum) $colnum] -width 8] -padx 5 -row $linenum -column [expr $colnum + 1] |
---|
80 | set ::rb_dummy_atom($linenum) 0 |
---|
81 | grid [checkbutton $main.d$::rb_colnum -variable ::rb_dummy_atom($linenum)] -row $linenum -column 0 |
---|
82 | incr ::rb_colnum |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | for {set z 1} {$z <= $::rb_colnum} {incr z} { |
---|
87 | if {$z > 4} {set ::rb_cart_col($z) "Ignore"} |
---|
88 | |
---|
89 | |
---|
90 | set menu [tk_optionMenu $top.$z ::rb_cart_col($z) atom X Y Z Ignore] |
---|
91 | $menu entryconfig 1 -command "RB_cart_restraint $z" |
---|
92 | $menu entryconfig 2 -command "RB_cart_restraint $z" |
---|
93 | $menu entryconfig 3 -command "RB_cart_restraint $z" |
---|
94 | grid $top.$z -row 0 -column $z |
---|
95 | $top.$z config -width 8 |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | ResizeScrollTable $location |
---|
100 | } |
---|
101 | |
---|
102 | proc RB_cart_restraint {col args} { |
---|
103 | |
---|
104 | set fixcoord $::rb_cart_col($col) |
---|
105 | puts "column $col coordinate changed to $fixcoord" |
---|
106 | for {set z 1} {$z <= $::rb_colnum} {incr z} { |
---|
107 | if {$z != $col} { |
---|
108 | if {$::rb_cart_col($z) == $fixcoord} {puts "col $z needs to be changed"} |
---|
109 | if {$::rb_cart_col($z) == $fixcoord} {set ::rb_cart_col($z) "Ignore"} |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | proc RB_cart_Build {} { |
---|
116 | |
---|
117 | set bodytyp [expr [llength [RigidBodyList]] + 1] |
---|
118 | set ::rb_num 1 |
---|
119 | set ::rb_matrix_num($bodytyp) 1 |
---|
120 | set sitenum $::rb_linenum |
---|
121 | set temp $::rb_linenum |
---|
122 | set colnum [llength $::tline(1)] |
---|
123 | |
---|
124 | for {set z 1} {$z <= $::rb_colnum} {incr z} { |
---|
125 | if {$::rb_cart_col($z) == "x" || $::rb_cart_col($z) == "X"} {set ::rb_x_coord [expr $z - 1]} |
---|
126 | if {$::rb_cart_col($z) == "y" || $::rb_cart_col($z) == "Y"} {set ::rb_y_coord [expr $z - 1]} |
---|
127 | if {$::rb_cart_col($z) == "z" || $::rb_cart_col($z) == "Z"} {set ::rb_z_coord [expr $z - 1]} |
---|
128 | } |
---|
129 | # puts "x = $::rb_x_coord" |
---|
130 | # puts "y = $::rb_y_coord" |
---|
131 | # puts "z = $::rb_z_coord" |
---|
132 | |
---|
133 | set x 1 |
---|
134 | |
---|
135 | catch {array unset ::rb_x $bodytyp,1,*} |
---|
136 | catch {array unset ::rb_y $bodytyp,1,*} |
---|
137 | catch {array unset ::rb_z $bodytyp,1,*} |
---|
138 | |
---|
139 | |
---|
140 | for {set coordnum 1} {$coordnum <= $sitenum} {incr coordnum} { |
---|
141 | if {$::rb_dummy_atom($coordnum) != 1} { |
---|
142 | # puts $::tline($coordnum) |
---|
143 | set ::rb_x($bodytyp,1,$x) [lindex $::tline($coordnum) $::rb_x_coord] |
---|
144 | set ::rb_y($bodytyp,1,$x) [lindex $::tline($coordnum) $::rb_y_coord] |
---|
145 | set ::rb_z($bodytyp,1,$x) [lindex $::tline($coordnum) $::rb_z_coord] |
---|
146 | # puts "line = $::tline($coordnum)" |
---|
147 | # puts "coors = $::rb_x($bodytyp,1,$coordnum) $::rb_y($bodytyp,1,$coordnum) $::rb_z($bodytyp,1,$coordnum)" |
---|
148 | incr x |
---|
149 | } else { |
---|
150 | set temp [expr $temp -1] |
---|
151 | } |
---|
152 | |
---|
153 | } |
---|
154 | |
---|
155 | set ::rb_coord_num($bodytyp,1) $temp |
---|
156 | |
---|
157 | |
---|
158 | #$::rb_notebook raise [$::rb_notebook page 0] |
---|
159 | # set pane [$::rb_notebook getframe rb_body0] |
---|
160 | # set con2 $pane.con2 |
---|
161 | |
---|
162 | #RB_Create_Cart $bodytyp $con2 |
---|
163 | destroy .cartesian |
---|
164 | NewBodyTypeWindow |
---|
165 | } |
---|
166 | |
---|