|
#!/usr/bin/env tclsh |
|
## Transparent 360 Rotation Gif in VMD |
|
## EML 13 Sept 2021 |
|
## |
|
## Modify the `SPECIFY USER VARIABLES` section below! |
|
## Run with `source rotate-gif.tcl` in VMD command line |
|
|
|
## Tell the program to expect variables |
|
variable basename |
|
variable basefilename |
|
variable mybasefilename |
|
variable imgsavedir |
|
|
|
### !!! SPECIFY USER VARIABLES !!! |
|
|
|
## Base for output file name (i.e., use `test` to later create `test.gif`) |
|
set basename "test" |
|
|
|
## Save directory -- either use a string or `[pwd]` for current working dir |
|
## Note: if not using the `[pwd]` or `/tmp`, you'll need a `povray.conf` file |
|
#set imgsavedir "/full/path/to/save/dir" |
|
set imgsavedir [pwd] |
|
## Number of degrees to rotate by (integer!) |
|
set rotateby "5" |
|
|
|
## Total number of degrees to rotate by (integer!) |
|
set fullrotate "360" |
|
|
|
### !!! END USER VARIABLES !!! |
|
|
|
#--------------------------------------# |
|
#-- Advanced User Modification Below --# |
|
#--------------------------------------# |
|
|
|
## Set the file path using basename and imgsavedir |
|
set mybasefilename [format "%s/$basename" $imgsavedir] |
|
|
|
## Use a white background and turn off depthcueing for transparency to render! |
|
color Display Background white |
|
display depthcue off |
|
|
|
## Rotation loop: rotate from 0-X degrees by X degree(s) each time |
|
## Note: change both the increment (`incr i 1`) AND rotation `rotate y by 1` |
|
## for different amounts |
|
## Get full rotation distance (counter at 1 so images start naming at 1) |
|
set myfullrotate [expr {$fullrotate + 1}] |
|
for {set i 1} {$i < $myfullrotate} {incr i $rotateby} { |
|
puts {} |
|
puts "Starting to process Frame $i" |
|
rotate y by $rotateby |
|
set basefilename [format "%s/$basename.%04d.pov" $imgsavedir $i ] |
|
## Set the render command |
|
render POV3 $basefilename povray +W%w +H%h -I%s -O%s.png -D +X +A +FN +UA |
|
} |
|
|
|
## Other render options |
|
## -------------------- |
|
## +W: width `+W%w` uses the current window width |
|
## +H: height. `+H%h` uses the current window height |
|
## +I: the name of the POV file to use. You may need the `.pov` |
|
## extension in $basefilename. |
|
## +O: the name of the final image. If you specify the `.pov` above, it'll |
|
## be something like `.pov.png`. |
|
## -D: switches off the graphics display while being rendered. Using `+D` |
|
## instead means the display will be on! |
|
## +X: make rendering killable |
|
## +FT: write targa file (with `+O%s.tga`) |
|
## +FN: write PNG file (with `+O%s.png`) |
|
## +FJ: write JPG file (with `+O%s.jpg`) |
|
## +FB: write Bitmap file (with `+O%s.bmp`) |
|
## +FP: write PPM format (with `+O%s.ppm`) |
|
## +UA: use background transparency. To use this, save as filetype that |
|
## supports transparency, like PNG. |
|
## The VMD background must be white for this option!!! |
|
## Note: If you need super-high-res images, use `+W%w0 +H%h0` (it WILL be slow |
|
## but very beautiful) |
|
## Note: XXXX is the $basename |
|
## |
|
## TGA -- not transparent |
|
## render POV3 XXXX povray +W%w +H%h -I%s -O%s.tga -D +X +A +FT |
|
## |
|
## JPG -- not transparent |
|
## render POV3 XXXX povray +W%w +H%h -I%s -O%s.jpg -D +X +A +FJ |
|
## |
|
## PNG Format -- yes transparent |
|
## render POV3 XXXX povray +W%w +H%h -I%s -O%s.png -D +X +A +FN +UA |
|
## -------------------- |
|
|
|
## Print to VMD Terminal |
|
puts {} |
|
puts "Starting GIF conversion with ImageMagick. I'll update you when I'm done." |
|
|
|
## Run ImageMagick's convert outside of VMD |
|
## Options: |
|
## -delay: time in 1/100s of a second. |
|
## -layers: |
|
## -dispose: what to do with the previous animation. |
|
## `previous` gets rid of the prior frame! |
|
## Note: This option must be given before the frames are read in. |
|
## -loop: how many times to replay the gif. `0` replays infinitely |
|
::ExecTool::exec convert -delay 4 -layers optimize -dispose previous -loop 0 \ |
|
$mybasefilename.*.png $mybasefilename.gif |
|
|
|
puts {} |
|
puts "Conversion attempt finished!" |
|
puts "If you ran into issues, try running the command alone in a Terminal." |
|
puts " convert -delay 4 -layers optimize -dispose previous -loop 0 $mybasefilename.*.png $mybasefilename.gif" |
|
puts {} |
|
puts "Note1: I don't delete the intermediate files. I trust you can." |
|
puts {} |
|
puts "Note2: On Linux, it may look like there's 1 frozen frame." |
|
puts "Check this by opening the GIF in an internet browser!" |
|
puts {} |