Wiki‎ > ‎

VMD View Change Rendering Tutorial

posted Mar 11, 2011, 3:33 PM by Dong Xu   [ updated Sep 10, 2016, 10:08 AM ]
VMD 1.8 (or later)

For this tutorial we will be using View Change Render 1.1 by Barry Isralewitz
http://www.ks.uiuc.edu/Research/vmd/script_library/scripts/view_change_render/

Make sure you remember where you save both this script and the “view_change_render.tcl” script linked in the file because we will be editing these during the tutorial.


Windows: you must have VideoMach 2.7.2 (or later) or another similar program
http://www.gromada.com/VideoMach.html

Linix / Unix: Make sure you have "ffmpeg" in your command path

When making “animated GIF” movies you need to have “ImageMagick” in your command path

How to control movie time length

ffmpeg -r 10 -b 3000k -i YourImagesName.%04d.tga YourMoviesName.mp4

since we make the frame rate of the video 10 frames every second, it makes it very easy to know the length of the video you will create.

for instance if I write:
move_vp_render 2 1 560 /home/lab/usr/cwilcock/Test2 test 240;

I know that 240 frames will be made, which will be exactly 24 seconds. so moving my video along with the sound I can easily tell where I need to make changes to make my videos more interesting.

Procedures:

Step 1: Going over the functions

After verifying all the required software is downloaded, locate the “view_change_render” and “view_change_render.tcl”  files mentioned in “required software”.

The first script goes through how view_change_render operates and all of its functions (we will review each of these in detail)

The second script “view_change_render.tcl” which has the functions we will be using in this tutorial.

Functions:

save_vp
     this function is used to save any view point we want  in VMD so that we can use it later.

retrieve_vp    this function is used to move to any view point that we have saved using save_vp.

move_vp    this is a very useful function that will move us from any viewpoint to another using the morph function.

move_vp_render     this is the most important function we will use, this will use the move_vp function to move from one view point to another and will render images for every frame in between.

write_vps     this function is used to save any viewpoint we’ve made and write them to a file we can use later.

Please note that I highly suggest using this function about every 10 minutes you are working. This is fast and efficient as well as saves all of your work so far. So if VMD accidentally closes or you forget to save right before you exit you will still have something to work with.

It is also possible to write over a previous file so you don’t need to make a new one each time you save, this means you can save as often as you would like to keep your view points(For information on this please go to “Examples:” ). Its good to keep a few files for your view points in case you ever need them.

source        this function is used to get view points we have saved from other sessions.

For instructions on how to use each of these functions go to the “Examples” section located at the end.

Step 2: Modifying the scripts

We are now going to edit our “view_change_render.tcl” script so it’s easier to use for making our movies.

Locate the “view_change_render.tcl” script and open it. This script will give some examples on using the functions inside along with providing all the code.

Next we want to locate the “move_vp” function, this can be done either by scrolling or by pressing “Ctrl + f” and using the search function.

Next we are going to find the code where you’re computer renders the images, this can be done by either scrolling or using the search function to find “render snapshot”

you should be looking at some code that looks like this:

render snapshot [file join $::VCR::dirName $::VCR::filePrefixName.$frametext.rgb]
puts "Rendering frame [file join $::VCR::dirName $::VCR::filePrefixName.$frametext.rgb]"

This code tell your computer what type of file you want your images rendered as. The “view_change_render.tcl” has .rgb as default, but since we will normally be using TachyonInternal or .tga files it will be a lot easier to change it here instead of manually later.

In order to change how the files are rendered just change the .rgb extension into what ever file type you want, I believe that .tga gives the best image quality so I use that.

The end code should look like this:

render snapshot [file join $::VCR::dirName $::VCR::filePrefixName.$frametext.tga]
puts "Rendering frame [file join $::VCR::dirName $::VCR::filePrefixName.$frametext.tga]"

with a .tga extension instead of a .rgb

Step 3: Using the scripts

So now that we’ve done steps 1 and 2 you should roughly know what each function does and you should have a modified “view_change_render.tcl” script so that we render .tga files instead of .rgb

Next we will be using these function to make something.

Setting Up:

Locate and open “VMD” on your system.
This should open into 3 different windows: your “VMD Main”, “VMD Display”, and “VMD command prompt.

I find that using the TK console makes this easier on the Linix / Unix Systems since it is easier to copy and redo tasks.

To open the TK console go to your “VMD Main” window and look at the top.
At the top search for “Extensions” towards the right of the window. click on “Extensions” to open a scroll down menu, at the bottom of the menu select “TK Console” and your TK console will open.

The Script:

Now before we do anything we need VMD to recognize our “view_change_render.tcl” script.
This can be done by either sourcing the file, or by opening “view_change_render.tcl” and copying all of the content to your “TK Console” I usually do the second option since I’m not as used to using sourcing.

Your VMD should now be able to run the functions in the script.

Step 4: Get a different view on thing

Now we are going to use the functions to make a movie.

from your “VMD Main” window load a molecule or .pdb file that you want to make a movie of.

now that the molecule is loaded go ahead and go to “Display” and “Representation” in your “VMD Main” window so that you can change how the molecule looks for better presentation.

After you are finished changing how the file looks we will start using the functions discussed above.

save_vp :

The first thing we need to do is use the “save_vp” function to save our view points.

Just start saving view points and getting cool displays wherever you want, for now we are just getting used to the controls, to save your view points you will type the following in your “TK Console”:
save_vp (x) ; save_vp 1 . . . save_vp 2 . . . save_vp 90
where (x) is any number from 1 through 10000.
the view points don’t need to be in order but you need to remember where each view point is saved to, so its easier to just go in order from 1 up.

after you save several view points we get to play around with them a bit.

retrieve_vp :

the next function we will use is a lot like the first one “retrieve_vp”. we use this function to go back to any view point we’ve saved. its used by type the following in your “TK Console”:
retrieve_vp (x); retrieve_vp 1 . . . retrieve_vp 2 . . . retrieve_vp 90
where like above (x) can be any number from 1 to 10000 as long as you can remember it.

retrieve_vp makes it very easy to see each view point we will use in our movies.

move_vp:

This is one of the most important functions we will be using since it gives you a preview of what the movie will look like when we will be done.

how “move_vp” works is it goes from one of our view points to the next by using morph, and then display the view changing at what ever speed you would like.

to use “move_vp” in your “TK Console” you’ll type:
move_vp x y (z) (“String”); move_vp 1 3 , move_vp 2 5 200 , move_vp 9 4 600 smooth

where x is your starting frame, y is your ending frame, z is how many frames/screens you want to see in between the two view points(if not specified it defaults to 50), and (“String”) specifies whether you want it smooth or jerky(default is smooth).

the 'smooth' option accelerates and decelerates the transformation
the 'sharp' / ’jerky’ option gives constant velocity

it may take a few attempts until you figure out exactly how this works, but for now it makes a short display of moving from one view point to another.

(make a note that move_vp only moves from one view point too another, it does not go to any of the view points in between, for example move_vp 1 5 will take you from view point 1 to view point 5 but it ignores view points 2,3, and 4 since they were not specified. so If you wanted to go from 1 to 2 to 3 etc you would need to type move_vp 1 2; move_vp 2 3; move_vp 3 4 etc until you got to the frame you wanted.)

For now just mess around with move_vp until you get a hang of how the function works.

Step 5: Making a Movie

Now that we went over the major functions excluding “move_vp_render” which I’ll cover soon, we are going to start making a movie. (pause for cheering)

In order to make our movie we have to first learn how the “ffmpeg” and the “move_vp_render” functions work, along with their syntax.

Since “ffmpeg” first needs images to work we’ll start with “move_vp_render”

How “move_vp_render” works is by using the “move_vp” function and taking snapshots of the molecule each specified frame as it goes from one view point to another.

the syntax of “move_vp_render” is very similar to the normal “move_vp” syntax with a few key differences however.

for “move_vp” we go from one view point to another while specifying how many frames we want to be in the middle.
“move_vp 1 2 300”  move from view point 1 to 2 with 300 frames in between.

The same is true for “move_vp_render” however this new function has a few new variables in between.
“move_vp_render 1 2 1 (“x”) (“y”) 25”

how this reads is move from view point 1 to 2 (now here’s a big difference) start the images with 1 (I’ll explain this in a second) save them to directory “x” (put in what directory to save them to) name the files “y” (what should the images be called) and finally how many snapshots to take in between 25.

If this image was taken in “move_vp_render” it would be named as “y.0001.tga” and in directory “x” it would also make the snapshots “y.0002.tga through y.0025.tga”
So if I wanted to take 10 images between view points 1 and 2, save them to my_documents and name them “tester.0101.tga through tester.0110.tga” I would write it like this:

“move_vp_render 1 2 101 My_Documents tester 10”

The 1 and 2 tell the computer which viewpoints to use, 10 is how many snapshots I want, 101 is what number I want to start at when I’m saving my image, (we change this value a lot if we’re take images by using more than one “move_vp_render”) and finally I want to save it to “My_Documents” with the name “tester”.

It may take some practice to get used to “move_vp_render” but its very easy to use once you get accustomed to it.

After using “move_vp_render” to get our files, we can now make our movie using “ffmpeg”.

to use “ffmpeg” first you set your directory to where you saved your images with “move_vp_render” this can be done through using “cd (desired directory)”.

After your directory is set we use ffmpeg, the syntax is like this:

“ffmpeg -r 10 -b 3000k -i YourImagesName.%04d.tga YourMoviesName.mp4”

This will take all .tga images named “YourImagesName” with a number at the end and then turn them into a movie called “YourMoviesName.mp4”

After running this function we turn all the images we’ve made and turn them into a movie.

For some more useful functions using “ffmpeg” try here:
http://howto-pages.org/ffmpeg/

I have found it to be helpful on a lot of questions I had.

This concludes the Tutorial, if there are any questions feel free to e-mail me at
cameron_dana@hotmail.com
I will try my best to respond promptly


Examples:

This sections is to help give some examples on using each function in case you are still having trouble.

save_vp    “save_vp #” the # can be any number from 1 - 10000 and save that number to             that specific view point, these saved view points dissapear each session unless             you write and source them before you end and when you start.

save_vp 1; save_vp 2; save_vp 3; save_vp 18

retrieve_vp    “retrieve_vp #” takes any view point you have saved using “save_vp” and then             puts your VMD camera into that exact position.

retrieve_vp 1; retrieve_vp 2; retrieve_vp 3; retrieve_vp 18

move_vp    “move_vp #1 #2 #3” moves from view point #1 to #2 and displays #3 amount of             frames in between.

        move_vp 1 2 100; move_vp 2 3 500; move_vp 3 18 150; move_vp 18 2 87

move_vp_render    “move_vp_render #1 #2 #N “string location” “string name” #3” moves from             view point #1 to #2 and renders #3 amount of frames in between, saves                 them to path “string location” with the names

(“string name”.#N.tga”   through   “string name”.(#N + #3).tga)

move_vp_render 1 2 1 /Images test 100 ;

move_vp_render 2 18 101 /Images test 100

write_vps    “write_vps (“string name”.tcl)” saves all your current view points to the file

(“string name”.tcl) so that you can use it later.

write_vps rna_strand_views.tcl;

write_vps september1st2011.tcl (for date progress);

write_vps session1.tcl;

write_vps fun_views.tcl

To save over a file that already there just type the command over, like this:

write_vps fun_views.tcl;

(do some stuff)

write_vps fun_views.tcl

this will just overwrite your older file so that you can easily save as you go,

Caution: Since this overwrites it can be very useful while you are working but be careful             not to accidentally save over some files you don’t mean to.

try to use an “_” instead of a “(space)” when you’re naming your files because a         lot of functions will misread the space as separation and then misinterpret your         code.

source    “source (“string name”.tcl)” this will read the view points you saved from before so         that you can use them again during this session.

source rna_strand_views.tcl;

source september1st2011.tcl;

source session1.tcl;

source fun_views.tcl
Comments