| 1 | #!/usr/bin/tclsh
 | 
|---|
| 2 | #
 | 
|---|
| 3 | # This scripts parsed a tecplot style file of triangles and produces one
 | 
|---|
| 4 | # frame for each found triangle to be used in animation of the tesselation
 | 
|---|
| 5 | # including the rolling sphere via VMD's graphics interface.
 | 
|---|
| 6 | #
 | 
|---|
| 7 | # Use as follows:
 | 
|---|
| 8 | # surfacing <filename>          # to start
 | 
|---|
| 9 | # surfacing_off                 # to end
 | 
|---|
| 10 | 
 | 
|---|
| 11 | # fname is the filename of the tecplot .dat file
 | 
|---|
| 12 | proc surfacing { fname } {
 | 
|---|
| 13 |         global nodes
 | 
|---|
| 14 |         global Triangles
 | 
|---|
| 15 |         global tcount
 | 
|---|
| 16 |         # open file
 | 
|---|
| 17 |         set file [open $fname r]
 | 
|---|
| 18 |         gets $file title
 | 
|---|
| 19 |         gets $file variables
 | 
|---|
| 20 |         gets $file zone
 | 
|---|
| 21 |         # parse nodes
 | 
|---|
| 22 |         set ncount 1
 | 
|---|
| 23 |         gets $file line
 | 
|---|
| 24 |         while { $line != {} } {
 | 
|---|
| 25 |                 set nodes($ncount) $line
 | 
|---|
| 26 |                 incr ncount
 | 
|---|
| 27 |                 gets $file line
 | 
|---|
| 28 |         }
 | 
|---|
| 29 |         set ncount [ expr $ncount -1 ]
 | 
|---|
| 30 |         puts "There are $ncount nodes."
 | 
|---|
| 31 |         # there's a blank line in between
 | 
|---|
| 32 |         # parse triangles
 | 
|---|
| 33 |         set tcount 0
 | 
|---|
| 34 |         gets $file line
 | 
|---|
| 35 |         while { $line != {} } {
 | 
|---|
| 36 |                 set Triangles($tcount) [ split $line " "]
 | 
|---|
| 37 |                 incr tcount
 | 
|---|
| 38 |                 gets $file line
 | 
|---|
| 39 |         }
 | 
|---|
| 40 |         puts "There are $tcount triangles."
 | 
|---|
| 41 |         
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         # avoid some 'animate dup' bug
 | 
|---|
| 44 |         set molid [molinfo top]
 | 
|---|
| 45 |         if {$tcount < 2} {
 | 
|---|
| 46 |                 error "tcount should be greater than 2."
 | 
|---|
| 47 |         }
 | 
|---|
| 48 |         # make tcount-1 copies of current frame
 | 
|---|
| 49 |         for {set i 0} {$i <$tcount} {incr i} {
 | 
|---|
| 50 |                 animate dup frame 0 $molid
 | 
|---|
| 51 |         }
 | 
|---|
| 52 |         animate goto 0
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         global vmd_frame
 | 
|---|
| 55 |         trace variable vmd_frame([molinfo top]) w update_current_surface
 | 
|---|
| 56 |         display update
 | 
|---|
| 57 |         return
 | 
|---|
| 58 | }       
 | 
|---|
| 59 | 
 | 
|---|
| 60 | proc update_current_surface {name index op} { 
 | 
|---|
| 61 |         draw delete all
 | 
|---|
| 62 |         global nodes
 | 
|---|
| 63 |         global Triangles
 | 
|---|
| 64 |         set count 0
 | 
|---|
| 65 |         set frame [molinfo $index get frame]
 | 
|---|
| 66 |         while { [expr $count+1] < $frame } {
 | 
|---|
| 67 |                 draw color red
 | 
|---|
| 68 |                 draw material Transparent
 | 
|---|
| 69 |                 set first [ lrange $nodes([ lindex $Triangles($count) 0 ]) 0 2 ]
 | 
|---|
| 70 |                 set second [ lrange $nodes([ lindex $Triangles($count) 1 ]) 0 2 ]
 | 
|---|
| 71 |                 set third [ lrange $nodes([ lindex $Triangles($count) 2 ]) 0 2 ]
 | 
|---|
| 72 |                 draw triangle $first $second $third
 | 
|---|
| 73 |                 incr count
 | 
|---|
| 74 |         }
 | 
|---|
| 75 |         if { [expr $count+1] <= $frame } {
 | 
|---|
| 76 |                 draw color green
 | 
|---|
| 77 |                 draw material Opaque
 | 
|---|
| 78 |                 puts "Last triangle is [lindex $Triangles($count) 0] [lindex $Triangles($count) 1] [lindex $Triangles($count) 2]"
 | 
|---|
| 79 |                 set first [ lrange $nodes([ lindex $Triangles($count) 0 ]) 0 2 ]
 | 
|---|
| 80 |                 set second [ lrange $nodes([ lindex $Triangles($count) 1 ]) 0 2 ]
 | 
|---|
| 81 |                 set third [ lrange $nodes([ lindex $Triangles($count) 2 ]) 0 2 ]
 | 
|---|
| 82 |                 draw triangle $first $second $third
 | 
|---|
| 83 |         }
 | 
|---|
| 84 |         #enumerate_atoms 0
 | 
|---|
| 85 |         
 | 
|---|
| 86 |         return
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | proc surfacing_off {} {
 | 
|---|
| 90 |         global vmd_frame
 | 
|---|
| 91 |         global tcount
 | 
|---|
| 92 |         trace vdelete vmd_frame([molinfo top]) w update_current_surface
 | 
|---|
| 93 |         draw delete all
 | 
|---|
| 94 |         animate delete beg 1 end $tcount skip 0 [molinfo top]
 | 
|---|
| 95 |         return
 | 
|---|
| 96 | }
 | 
|---|
| 97 | 
 | 
|---|