rendered in VMD using Tachyon

Script for easily extracting the view matrix in VMD

I have been using VMD increasingly more since I discovered how powerful the included tachyon engines are in VMD for rendering. But since I started learning VMD I have been struggling with copying my work flow from PyMol to VMD. Especially my old routine where I always made pml scripts for all movie and images I made with PyMol, has been hard to transfer to VMD.


Tachyon rendered image  made in VMD using a script.

As far as I can tell, you have to get 4 different view matrices out of VMD, to be able to reconstruct the view you see on screen in the display window:





I get the individual matrices by writing the following command in the TkConsole in VMD, after I have found the view I want:

molinfo top get center_matrix

Of course you need to swap the “center_matrix” part with what ever matrix you want. For the center_matrix the TkConsole should give you something like this back:

{{1 0 0 2.37329} {0 1 0 8.44672} {0 0 1 13.1514} {0 0 0 1}}

Then you have to add the following command to you script:

 molinfo top set {center_matrix} {{{1 0 0 2.37329} {0 1 0 8.44672} {0 0 1 13.1514} {0 0 0 1}}}

This you have to do for all the matrices and as far as I can tel you have to do it for all the molecules you want to show in your render, so if you have a model + map you have to do it for both molecules (mol-ID 0 and 1), like this:

 molinfo 0 set {center_matrix} {{{1 0 0 2.37329} {0 1 0 8.44672} {0 0 1 13.1514} {0 0 0 1}}}

molinfo 1 set {center_matrix} {{{1 0 0 2.37329} {0 1 0 8.44672} {0 0 1 13.1514} {0 0 0 1}}}

This gets very annoying to do every time you want to change the view even a tiny bit, so I made myself a .tcl script which writes out the four matrices with the correct context to a file called view_matrices.log . The output from that file can be directly  inserted into your script, however you will need to change the “top”  part to what ever molecule you want it to act o, if not the top molecule. The same goes if you have multiple molecules, then you need to add the commands twice, one for each mol-ID.

To run the script, copy/paste the below lines into a new file, say get_view.tcl and save the file in your working directory. Then within VMD, after you have loaded your structure and picked the view you want, you need to go to the  TkConsole and type:

play get_view.tcl

and then you should find a file in your working directory called view_matrices.log, containing the above mentioned matrices ready to be inserted into your movie/image script.


set file [ open “view_matrices.log” w]
set c [molinfo top get center_matrix]
set s [molinfo top get scale_matrix]
set r [molinfo top get rotate_matrix]
set g [molinfo top get global_matrix]
puts $file “molinfo top set {center_matrix} {$c}”
puts $file “molinfo top set {scale_matrix} {$s}”
puts $file “molinfo top set {rotate_matrix} {$r}”
puts $file “molinfo top set {global_matrix} {$g}”
close $file

Leave a Reply

Your email address will not be published. Required fields are marked *