-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcpyrep.tcl
222 lines (167 loc) · 5.37 KB
/
cpyrep.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
## Copies/saves/restores representations without
## having to deal with the save state stuff
global molreps; ## Array for storing representations
proc save_rep {index {mollist all}} {
## Saves representations to an array
global molreps
## Clear reps stored in the index slot
foreach {key rep} [array get molreps [list $index*]] {
unset molreps($key)
}
if {$mollist == "all"} {
set mollist [molinfo list]
}
set j 0;
foreach mol $mollist {
set numreps [molinfo $mol get numreps]
for {set i 0} {$i < $numreps} {incr i} {
set rep [molinfo $mol get "{rep $i} {selection $i} {color $i} {material $i}"]
lappend rep [mol showperiodic $mol $i]
lappend rep [mol numperiodic $mol $i]
lappend rep [mol showrep $mol $i]
lappend rep [mol selupdate $i $mol]
lappend rep [mol colupdate $i $mol]
lappend rep [mol scaleminmax $mol $i]
lappend rep [mol smoothrep $mol $i]
lappend rep [mol drawframes $mol $i]
set molreps([list $index $j $i $numreps]) $rep
set rep {}
}
incr j
}
}
proc restore_rep {index index2 {mollist all} {clear 1}} {
global molreps
if {$mollist == "all"} {
set mollist [molinfo list]
}
## First clear all the existing representations
if {$clear} {
foreach mol $mollist {
set numreps [molinfo $mol get numreps]
for {set i 0} {$i < $numreps} {incr i} {
mol delrep 0 $mol
}
}
}
## Restore representation to mol(s)
foreach mol $mollist {
set j 0
foreach key [lsort -integer -increasing -index 2 [array names molreps [list $index $index2*]]] {
lassign $key aindex bindex i numreps
if {$j >= $numreps} {break}
lassign $molreps($key) r s c m pbc numpbc on selupd colupd colminmax smooth framespec
eval "mol representation $r"
eval "mol color $c"
eval "mol selection {$s}"
eval "mol material $m"
eval "mol addrep $mol"
if {[string length $pbc]} {
eval "mol showperiodic $mol $i $pbc"
eval "mol numperiodic $mol $i $numpbc"
}
eval "mol selupdate $i $mol $selupd"
eval "mol colupdate $i $mol $colupd"
eval "mol scaleminmax $mol $i $colminmax"
eval "mol smoothrep $mol $i $smooth"
eval "mol drawframes $mol $i {$framespec}"
if { !$on } {
eval "mol showrep $mol $i 0"
}
incr j;
}
}
}
proc restore_rep_all_2_all {index {mollist all}} {
global molreps
if {$mollist == "all"} {
set mollist [molinfo list]
}
## First clear all the existing representations
foreach mol $mollist {
set numreps [molinfo $mol get numreps]
for {set i 0} {$i < $numreps} {incr i} {
mol delrep 0 $mol
}
}
## Restore representation to mol(s)
set k 0
foreach mol $mollist {
set j 0
foreach key [lsort -integer -increasing -index 2 [array names molreps [list $index $k*]]] {
lassign $key aindex bindex i numreps
if {$j >= $numreps} {break}
lassign $molreps($key) r s c m pbc numpbc on selupd colupd colminmax smooth framespec
eval "mol representation $r"
eval "mol color $c"
eval "mol selection {$s}"
eval "mol material $m"
eval "mol addrep $mol"
if {[string length $pbc]} {
eval "mol showperiodic $mol $i $pbc"
eval "mol numperiodic $mol $i $numpbc"
}
eval "mol selupdate $i $mol $selupd"
eval "mol colupdate $i $mol $colupd"
eval "mol scaleminmax $mol $i $colminmax"
eval "mol smoothrep $mol $i $smooth"
eval "mol drawframes $mol $i {$framespec}"
if { !$on } {
eval "mol showrep $mol $i 0"
}
incr j
}
incr k
}
}
## Duplicate a particular representation
proc dup_rep {{index last} {mol top}} {
## Get the number of representations
set numreps [molinfo $mol get numreps]
if {$index == "last"} {
set index [expr {$numreps - 1}]
}
if {$mol == "top"} {
set mol [molinfo top]
}
set rep [molinfo $mol get "{rep $index} {selection $index} {color $index} {material $index}"]
lappend rep [mol showperiodic $mol $index]
lappend rep [mol numperiodic $mol $index]
lappend rep [mol showrep $mol $index]
lappend rep [mol selupdate $index $mol]
lappend rep [mol colupdate $index $mol]
lappend rep [mol scaleminmax $mol $index]
lappend rep [mol smoothrep $mol $index]
lappend rep [mol drawframes $mol $index]
lassign $rep r s c m pbc numpbc on selupd colupd colminmax smooth framespec
eval "mol representation $r"
eval "mol color $c"
eval "mol selection {$s}"
eval "mol material $m"
eval "mol addrep $mol"
if {[string length $pbc]} {
eval "mol showperiodic $mol $numreps $pbc"
eval "mol numperiodic $mol $numreps $numpbc"
}
eval "mol selupdate $numreps $mol $selupd"
eval "mol colupdate $numreps $mol $colupd"
eval "mol scaleminmax $mol $numreps $colminmax"
eval "mol smoothrep $mol $numreps $smooth"
eval "mol drawframes $mol $numreps {$framespec}"
if { !$on } {
eval "mol showrep $mol $numreps 0"
}
}
proc write_rep {fname {index *}} {
## Write representation array to a file
global molreps
set outFile [open $fname w]
puts $outFile [list array set molreps [array get molreps [list $index*]]]
close $outFile
}
proc read_rep {fname} {
## Restore representation array from file
global molreps
array unset molreps
source $fname
}