-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoregraphics.tcl
302 lines (271 loc) · 7.8 KB
/
moregraphics.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
##
## Moregraphics
##
## A plugin that allows to create and delete graphics objects that are
## combined from VMD's graphics primitives.
##
## Authors:
## Olaf Lenz <olenz _at_ icp.uni-stuttgart.de>
## Andreas Mezger
##
package provide moregraphics 0.9
namespace eval ::moregraphics:: {
#==========================================================
# NAME : lshift
# PURPOSE : shift list and return first element
# AUTHOR : Richard Booth
# http://www.lehigh.edu/~rvb2
# ---------------------------------------------------------
# ARGUMENTS :
# % inputlist
# List to be shifted.
# RESULTS :
# * Sets inputlist to 2nd to last elements of original inputlist
# * Returns first element in inputlist
# NOTES :
# * useful for command-line arguments and procedure args processing
# EXAMPLE-CALL :
#
# while {[llength $argv] > 0} {
# set arg [lshift argv]
# switch -- $arg {
# -lib {set lib [lshift argv]}
# -show {set show 1}
# default {lappend tests $arg}
# }
# }
#
#==========================================================
proc lshift {inputlist} {
upvar $inputlist argv
set arg [lindex $argv 0]
#set argv [lrange $argv 1 end] ;# below is much faster - lreplace can make use of unshared Tcl_Obj to avoid alloc'ing the result
set argv [lreplace $argv[set argv {}] 0 0]
return $arg
}
# Generates a graphics with a given color that replaces the first
# of gids (if anything is in there)
proc moregraphics {molid color gids args} {
# set the color
graphics $molid color $color
# set the replacement gid
upvar $gids gids2
if { [info exists gids2] && [llength $gids2] } then {
graphics $molid replace [lshift gids2]
}
if { [llength $args] } then {
return [eval "graphics $molid $args"]
}
return ""
}
# delete <options> gids
# delete a list of gids as they are created by the various
# commands below.
#
# Options:
# molid <int> [top]
proc delete args {
set molid "top"
if { [lindex $args 0] == "molid" } then {
lshift args
set molid [lshift args]
}
if { $molid == "top" } then { set molid [ molinfo top ] }
foreach arg $args {
if { [llength $arg] >= 1 } then {
foreach gid $arg {
if { [graphics $molid exists $gid] } then {
graphics $molid delete $gid
}
}
}
}
}
# doublesphere <options>
# generates two slightly shifted spheres
#
# Options:
# molid <int> [top]
# pos <vec> [{0 0 0}]
# dir <vec> [{1 0 0}]
# color1 <colorid> [red]
# color2 <colorid> [blue]
# replace <var> <var>
# radius <float> [1.0]
# shift <float> [0.01]
# res <int> [6]
proc doublesphere args {
set none {}
set molid "top"
set pos {0 0 0}
set dir {1 0 0}
set color1 "red"
set color2 "blue"
set oldvar mg_oldgids
set newvar mg_newgids
set radius 1.0
set shift 0.01
set resolution 6
# Parse options
while {[llength $args] > 0} {
set arg [lshift args]
switch -- $arg {
"molid" { set molid [lshift args] }
"pos" { set pos [lshift args] }
"dir" { set dir [lshift args] }
"color1" { set color1 [lshift args] }
"color2" { set color2 [lshift args] }
"replace" {
set oldvar [lshift args]
set newvar [lshift args]
}
"radius" { set radius [lshift args] }
"shift" { set shift [lshift args] }
"resolution" { set resolution [lshift args] }
default { error "error: doublesphere: unknown option: $arg" }
}
}
if { $molid == "top" } then { set molid [ molinfo top ] }
# compute the positions of the individual spheres
set shiftvec [vecscale [expr 0.5 * $shift] [vecnorm $dir]]
set pos1 [vecadd $pos $shiftvec]
set pos2 [vecadd $pos [vecinvert $shiftvec]]
upvar $oldvar oldgids
upvar $newvar newgids
set gid1 [moregraphics $molid $color1 oldgids \
sphere $pos1 radius $radius \
resolution $resolution]
set gid2 [moregraphics $molid $color2 oldgids \
sphere $pos2 radius $radius \
resolution $resolution]
lappend newgids $gid1 $gid2
return [list $gid1 $gid2]
}
# doublecone <options>
# generates two slightly shifted spheres
#
# Options:
# molid <int> [top]
# pos <vec> [{0 0 0}]
# dir <vec> [{1 0 0}]
# color1 <colorid> [red]
# color2 <colorid> [blue]
# replace <var> <var>
# radius <float> [1.0]
# length <float> [1.0]
# res <int> [6]
proc doublecone args {
set none {}
set molid "top"
set pos {0 0 0}
set dir {1 0 0}
set color1 "red"
set color2 "blue"
set oldvar mg_oldgids
set newvar mg_newgids
set length 1.0
set radius 1.0
set shift 0.01
set resolution 6
# Parse options
while {[llength $args] > 0} {
set arg [lshift args]
switch -- $arg {
"molid" { set molid [lshift args] }
"pos" { set pos [lshift args] }
"dir" { set dir [lshift args] }
"color1" { set color1 [lshift args] }
"color2" { set color2 [lshift args] }
"replace" {
set oldvar [lshift args]
set newvar [lshift args]
}
"radius" { set radius [lshift args] }
"length" { set length [lshift args] }
"resolution" { set resolution [lshift args] }
default { error "error: doublesphere: unknown option: $arg" }
}
}
if { $molid == "top" } then { set molid [ molinfo top ] }
set tipvec [vecscale $length [vecnorm $dir]]
set tip1 [vecadd $pos $tipvec]
set tip2 [vecadd $pos [vecinvert $tipvec]]
upvar $oldvar oldgids
upvar $newvar newgids
set gid1 [moregraphics $molid $color1 oldgids \
cone $pos $tip1 radius $radius \
resolution $resolution]
set gid2 [moregraphics $molid $color2 oldgids \
cone $pos $tip2 radius $radius \
resolution $resolution]
lappend newgids $gid1 $gid2
return [list $gid1 $gid2]
}
# arrow <options>
# generates an arrow
#
# Options:
# molid <int> [top]
# pos <vec> [{0 0 0}]
# dir <vec> [{1 0 0}]
# color1 <colorid> [red]
# color2 <colorid> [blue]
# replace <var> <var>
# radius <float> [0.2]
# coneradius <float> [2.0]
# conelength <float> [0.2]
# resolution <int> [6]
proc arrow args {
set none {}
set molid "top"
set pos {0 0 0}
set dir {1 0 0}
set color1 "red"
set color2 "blue"
set length 1.0
set radius 0.2
set coneradius 2.0
set conelength 0.5
set resolution 6
set oldvar mg_oldgids
set newvar mg_newgids
# Parse options
while {[llength $args] > 0} {
set arg [lshift args]
switch -- $arg {
"molid" { set molid [lshift args] }
"pos" { set pos [lshift args] }
"dir" { set dir [lshift args] }
"color1" { set color1 [lshift args] }
"color2" { set color2 [lshift args] }
"replace" {
set oldvar [lshift args]
set newvar [lshift args]
}
"radius" { set radius [lshift args] }
"coneradius" { set coneradius [lshift args] }
"conelength" { set conelength [lshift args] }
"length" { set length [lshift args] }
"resolution" { set resolution [lshift args] }
default { error "error: arrow: unknown option: $arg" }
}
}
if { $molid == "top" } then { set molid [ molinfo top ] }
set lenvec [vecscale $length [vecnorm $dir]]
set base [vecadd $pos [vecscale -0.5 $lenvec]]
set tip [vecadd $pos [vecscale 0.5 $lenvec]]
set conebase [vecadd $base \
[vecscale [expr 1.0-$conelength] $lenvec]]
upvar $oldvar oldgids
upvar $newvar newgids
set gid1 [moregraphics $molid $color1 oldgids \
cone $conebase $tip radius [expr $coneradius*$radius] \
resolution $resolution]
set gid2 [moregraphics $molid $color2 oldgids \
cylinder $base $conebase radius $radius \
resolution $resolution filled yes]
lappend newgids $gid1 $gid2
return [list $gid1 $gid2]
}
}