Difference between revisions of "Creating Movies"
(→Encoding to a movie) |
AngelHerraez (talk | contribs) (another example of loop; also GIF file export; animGIF and AVI formats) |
||
Line 35: | Line 35: | ||
Save this text in a file, for example 'movieloop.jmol'. | Save this text in a file, for example 'movieloop.jmol'. | ||
+ | |||
+ | == Alternative example == | ||
+ | This uses the same principles, slightly different (though equivalent) code and is set for the rotation of the model in a single frame. In addition, it exports to <code>gif</code> format (only available in recent 11.7 versions) for later making an animated <code>gif</code> file outside Jmol: | ||
+ | |||
+ | <pre> | ||
+ | load whatever_file.mol | ||
+ | color background [xD2DFEF] | ||
+ | /* | ||
+ | add any other rendering commands | ||
+ | */ | ||
+ | for (var i=0; i<36; i=i+1) | ||
+ | write image 200 200 @{"movie" + ("0000" + i)[-3][0] + ".gif"} | ||
+ | /* 200 and 200 are width and height */ | ||
+ | rotate axisangle {1 1 0} 10 | ||
+ | /* axis is defined by X Y Z lengths between braces; this one is at 45 degrees | ||
+ | and 10 (degrees) is angle of rotation, so the 36-loop gives a full turn | ||
+ | */ | ||
+ | end for | ||
+ | </pre> | ||
= Viewstate = | = Viewstate = | ||
− | Now you still need to create a viewstate. To do this, load the system coordinates you are interested in, rotate and change background colors until the picture looks as you want it. This can be saved into a file with the command: | + | Now you still need to create a viewstate for the initial display. To do this, load the system coordinates you are interested in, rotate and change background colors until the picture looks as you want it. This can be saved into a file with the command: |
<pre> | <pre> | ||
Line 44: | Line 63: | ||
</pre> | </pre> | ||
− | A state file | + | A state file looks something like this (only some of the important parts are shown): |
<pre> | <pre> | ||
... | ... | ||
Line 59: | Line 78: | ||
= Creating a playable movie = | = Creating a playable movie = | ||
+ | * Linux console: | ||
To create the animation, make a file with first the viewstate and then the loop, for example by: | To create the animation, make a file with first the viewstate and then the loop, for example by: | ||
<pre> | <pre> | ||
Line 64: | Line 84: | ||
jmol movie.jmol | jmol movie.jmol | ||
+ | </pre> | ||
+ | |||
+ | * Jmol console (any OS): | ||
+ | Start Jmol, open the script console, and type: | ||
+ | <pre> | ||
+ | script moviestate.jmol | ||
+ | script movieloop.jmol | ||
</pre> | </pre> | ||
Line 70: | Line 97: | ||
== Encoding to the mpeg format == | == Encoding to the mpeg format == | ||
− | The most straightforward way to encode to mpeg2 is "convert". This will create huge files and the needed mpeg2encode might not always be installed. | + | The most straightforward way to encode to <code>mpeg2</code> in Linux systems is "convert". This will create huge files and the needed <code>mpeg2encode</code> might not always be installed. |
<pre> | <pre> | ||
− | |||
convert *.jpg movie.gif | convert *.jpg movie.gif | ||
convert *.jpg movie.mpg | convert *.jpg movie.mpg | ||
</pre> | </pre> | ||
− | Alternatively, encode to smaller mpeg4 files with | + | Alternatively, encode to smaller <code>mpeg4</code> files with <code>mencoder</code>, which comes along with <code>mplayer</code>. |
<pre> | <pre> | ||
Line 91: | Line 117: | ||
Fine tune the speed/length of the animation by varying the -fps (frames per second) option. | Fine tune the speed/length of the animation by varying the -fps (frames per second) option. | ||
+ | |||
+ | == Encoding to animated gif format == | ||
+ | You will need a third-party software for this. Load into it the full set of <code>gif</code> files generated by Jmol (<code>gif</code> format is only available in recent 11.7 versions of Jmol), choose the time step and the loop options and save into animated <code>gif</code>. These files will be viewable directly in any web browser. | ||
+ | |||
+ | == Encoding to avi format == | ||
+ | Some programas will be able to read multiple <code>gif</code>, <code>png</code> or <code>jpg</code> files and produce an <code>avi</code> video file. Be aware that the file size will likely be large; that's where the <code>mpeg</code> alternatives may be useful. |
Revision as of 12:23, 7 November 2008
- A list of Jmol / JSmol Tutorials written by users.
- Using the mouse (English · Español · Français · Japanese).
- Scripting quickstart: rendering options · selecting atoms.
- How to create surfaces and isosurfaces, including cavities, pockets and tunnels.
- Displaying shapes, polyhedra, orbitals, dipoles, distances, forces and vibrations.
- Creating movies.
- Customizing Jmol: macros · menus.
- Web pages without writing code by using the Jmol "Export to Web" function.
An animation is just a sequence of images, so all one needs is Jmol to create a batch file of images. There is currently no menu option to do this, but a small bit of scripting can do the trick. It is possible to get the movie output from either one frame at several angles or from a series of frames.
Contents
Output Loop Script
The main part of the script is given here: based on a mail from Bob Hanson on the mailing list. If you want to rotate a single molecule, you need to uncomment the respective 'rotate' commands. If you want to loop over the timeframes in your coordinate file, you only need to change the 'nFrames' variable to the amount of frames you are currently using (this is given in the title of the main Jmol window). You might also want to change the width and height parameters to create a bigger or smaller animation.
name = "./frame0000.jpg"; nFrames = 125; nDegrees = 1; thisFrame = 0; width = 640; height = 480; set zoomLarge false; message loop; thisFrame = thisFrame + 1; fileName = name.replace("0000","" + ("0000" + thisFrame)[-4][0]); #rotate x @nDegrees; # use these options if you want to rotate the molecule #rotate y @nDegrees; #rotate z @nDegrees; frame next; # only use this if you have a multiframe file. refresh; write image @width @height @fileName; if (thisFrame < nFrames);goto loop;endif; background black;
Save this text in a file, for example 'movieloop.jmol'.
Alternative example
This uses the same principles, slightly different (though equivalent) code and is set for the rotation of the model in a single frame. In addition, it exports to gif
format (only available in recent 11.7 versions) for later making an animated gif
file outside Jmol:
load whatever_file.mol color background [xD2DFEF] /* add any other rendering commands */ for (var i=0; i<36; i=i+1) write image 200 200 @{"movie" + ("0000" + i)[-3][0] + ".gif"} /* 200 and 200 are width and height */ rotate axisangle {1 1 0} 10 /* axis is defined by X Y Z lengths between braces; this one is at 45 degrees and 10 (degrees) is angle of rotation, so the 36-loop gives a full turn */ end for
Viewstate
Now you still need to create a viewstate for the initial display. To do this, load the system coordinates you are interested in, rotate and change background colors until the picture looks as you want it. This can be saved into a file with the command:
write state "moviestate.jmol"
A state file looks something like this (only some of the important parts are shown):
... load "CoCr_125frames.XYZ"; # This part is essential! ... cameraDepth = 3.0; center {6.424099 3.137966 4.133584}; moveto /* time, axisAngle */ 0.0 { -704 -672 -228 173.73} /* zoom, translation */ 62.1 2 0.0 0.06 /* center, rotationRadius */ {6.424099 3.137966 4.133584} 9.94055;; slab 100;depth 0; ...
Creating a playable movie
- Linux console:
To create the animation, make a file with first the viewstate and then the loop, for example by:
cat moviestate.jmol movieloop.jmol > movie.jmol jmol movie.jmol
- Jmol console (any OS):
Start Jmol, open the script console, and type:
script moviestate.jmol script movieloop.jmol
Jmol will start, and show you the animation, while it is writing the output files.
Encoding to the mpeg format
The most straightforward way to encode to mpeg2
in Linux systems is "convert". This will create huge files and the needed mpeg2encode
might not always be installed.
convert *.jpg movie.gif convert *.jpg movie.mpg
Alternatively, encode to smaller mpeg4
files with mencoder
, which comes along with mplayer
.
mencoder "mf://*.jpg" -o movie.mpg -ovc lavc -fps 8
Many options and codecs are available, the default settings often create images that are too grainy due to the high image compression. Some testing by Mario Valle at CSCS gave optimal mencoder options for a movie of atomistic simulations. To have it run on default Windows installations (e.g. for use in Powerpoint), also use the msmpeg4v2 codec with autoaspect. The optimal combination of mencoder options then becomes:
mencoder "mf://*.jpg" -o movie.mpg -ovc lavc -lavcopts vcodec=msmpeg4v2:autoaspect:vbitrate=2160000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 -fps 8
Fine tune the speed/length of the animation by varying the -fps (frames per second) option.
Encoding to animated gif format
You will need a third-party software for this. Load into it the full set of gif
files generated by Jmol (gif
format is only available in recent 11.7 versions of Jmol), choose the time step and the loop options and save into animated gif
. These files will be viewable directly in any web browser.
Encoding to avi format
Some programas will be able to read multiple gif
, png
or jpg
files and produce an avi
video file. Be aware that the file size will likely be large; that's where the mpeg
alternatives may be useful.