Making a simulation movie with a running plot: Difference between revisions

From OxDNA
Jump to navigation Jump to search
(Making the article more clear. Still a work in progress, but hopefully less so :))
No edit summary
Line 18: Line 18:
#*;<tt>-m</tt>
#*;<tt>-m</tt>
#*:Show oxDNA2 nucleotides, which present major-minor groove asimmetry (just like real DNA), unlike oxDNA1.
#*:Show oxDNA2 nucleotides, which present major-minor groove asimmetry (just like real DNA), unlike oxDNA1.
#*:Several other options can be used. You can see the documentation for <tt>cogli1</tt> by launching it without any other arguments.
#:Several other options can be used. You can see the documentation for <tt>cogli1</tt> by launching it without any other arguments.
# Find a view that you like by moving the configuration around, zooming in, zooming out, etc. See the <tt>cogli1</tt> documentation for details on how to do this. Verify that the view is good for every frame in your trajectory by skimming through it, holding the + button. When you are satisfied that you've found a good view, just press  
# Find a view that you like by moving the configuration around, zooming in, zooming out, etc. See the <tt>cogli1</tt> documentation for details on how to do this. Verify that the view is good for every frame in your trajectory by skimming through it, holding the + button. When you are satisfied that you've found a good view, just press  
#*:<pre>
#:<pre>
#*::u</pre>
#::u</pre>
#: to save the simulation snapshot to a <tt>.cpy</tt> file. An example of a good view for this system is saved in <tt> sample_view.cpy </tt>.
#: to save the simulation snapshot to a <tt>.cpy</tt> file. An example of a good view for this system is saved in <tt> sample_view.cpy </tt>.
#* Now let's export each trajectory frames to <tt>.pov</tt>.
# Now let's export each trajectory frames to <tt>.pov</tt>.
#:<pre>
#:<pre>
#::cogli1 -l view.cpy -t prova.top trajectory.dat</pre>
#::cogli1 -l view.cpy -t prova.top trajectory.dat</pre>
#: where <tt> view.cpy</tt> is the name of your view. This will produce as many <tt>.pov</tt> files as there are simulation snapshots, and each of them will generate a movie frame. You can edit any <tt>.pov</tt> file if you so wish, replace it with one taken from another view, or with something copletely different if you feel like playing Tyler Durden :)
#: where <tt> view.cpy</tt> is the name of your view. This will produce as many <tt>.pov</tt> files as there are simulation snapshots, and each of them will generate a movie frame. You can edit any <tt>.pov</tt> file if you so wish, replace it with one taken from another view, or with something copletely different if you feel like playing Tyler Durden :)
#* Rendering the images in povray can take a long, time, so first we're going to do that with a low resolution to quickly create a preview. Use the command:
# Rendering the images in povray can take a long, time, so first we're going to do that with a low resolution to quickly create a preview. Use the command:
#:<pre>
#:<pre>
#:: povray -D +H600 +W860 *.pov</prev>
#:: povray -D +H600 +W860 *.pov</pre>
#: in order to generate the png images at a low resolution, with 600 pixels of height and 860 of width (i.e. with a format of 16:10). Further decrease the resolution if you want it to run even faster, or change the aspect ration as you please.
#: in order to generate the png images at a low resolution, with 600 pixels of height and 860 of width (i.e. with a format of 16:10). Further decrease the resolution if you want it to run even faster, or change the aspect ration as you please.
# Encode the povray images in a <tt>.avi</tt> movie with the commands
# Encode the povray images in a <tt>.avi</tt> movie with the commands
Line 36: Line 36:
#::mencoder mf://@storyboard.txt -mf w=860:h=600:fps=6:type=png -ovc xvid -xvidencopts bitrate=200 -o preview.avi</pre>
#::mencoder mf://@storyboard.txt -mf w=860:h=600:fps=6:type=png -ovc xvid -xvidencopts bitrate=200 -o preview.avi</pre>
#:Notice that the width and height of the movie should be the same as the one used in the povray command above.
#:Notice that the width and height of the movie should be the same as the one used in the povray command above.
#* Visualise the movie with the editor of choice and verify that everything is fine. Go back to the previous points if you see that something isn't quite right.
# Visualise the movie with the editor of choice and verify that everything is fine. Go back to the previous points if you see that something isn't quite right.
# If you're happy with the view of the movie, you might want to actually use a better resolution. Notice that povray might take a few hours or days to render the scenes depending on your GPU.  
# If you're happy with the view of the movie, you might want to actually use a better resolution. Notice that povray might take a few hours or days to render the scenes depending on your GPU. Notice that if you are going to make a video with a running plot in the top/bottom part of the screen and the simulation movie in the other (i.e. using the <tt>append</tt> below) you'll need to accomodate the resolution for that, so that if e.g. you want to keep the aspect ratio of the video at 16:10 and your plot takes e.g. 20% of the screen you'll want to use a resolution of 1920x1000, so that the plot can be created with a resolution of 1920x200 and the composite frames have a resolution of 1920x1200.
#:Notice that if you are going to make a video with a running plot in the top/bottom part of the screen and the simulation movie in the other (i.e. using the <tt>append</tt> below) you'll need to accomodate the resolution for that, so that if e.g. you want to keep the aspect ratio of the video at 16:10 and your plot takes e.g. 20% of the screen you'll want to use a resolution of 1920x1000, so that the plot can be created with a resolution of 1920x200 and the composite frames have a resolution of 1920x1200.
#:<pre>
#:<pre>
#:: povray -D +A +H1200 +W1920 *.pov</prev>
#:: povray -D +A +H1200 +W1920 *.pov<pre>
#:and then make the video with
#::ls -1v output_*.png > storyboard.txt
#:<pre>ls -1v output_*.png > storyboard.txt
#::mencoder mf://@storyboard.txt -mf w=1920:h=1200:fps=6:type=png -ovc xvid -xvidencopts bitrate=600 -o output.avi</pre>
#::mencoder mf://@storyboard.txt -mf w=1920:h=1200:fps=6:type=png -ovc xvid -xvidencopts bitrate=600 -o output.avi</pre>
# You're video is ready! Enjoy :-D See below how to add a running plot superimposed to the video or above it.
# Your video is ready! Enjoy :-D See below how to add a running plot superimposed to the video or above it.


== Adding a running plot ==
== Adding a running plot ==
Line 64: Line 62:
#* possibly adding some modifiers before plotting, including title, xlabel, ylabel, etc, a grid, etc.
#* possibly adding some modifiers before plotting, including title, xlabel, ylabel, etc, a grid, etc.
#* any other edit you might wish to make
#* any other edit you might wish to make
# After both points above are finished, you can compose the images by either pasting the plots on the simulation snapshots, or appending the images together. This can easily be done with `convert` on linux and cygwin, with either of the following 2 lines: TO SUPERIMPOSE THE PLOT TO THE SIMULATION SNAPSHOT``
# After both points above are finished, you can compose the images by either pasting the plots on the simulation snapshots, or appending the images together. This can easily be done with `convert` on linux and cygwin, with either of the following 2 lines:
<pre>
#:<pre>
for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -composite output_${i}.png; done
#::TO SUPERIMPOSE THE PLOT TO THE SIMULATION SNAPSHOT``
</pre>
#::for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -composite output_${i}.png; done
OR TO APPEND IT ABOVE IT
#::OR TO APPEND IT ABOVE IT
<pre>
#::for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -append output_${i}.png; done</pre>
for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -append output_${i}.png; done
</pre>
swap the order of the plots and the simulations snapshots above to have the plot display below the simulation system instead.
swap the order of the plots and the simulations snapshots above to have the plot display below the simulation system instead.
# Convert the png files into a movie, with <tt>mencoder</tt> or <tt>ffmpeg</tt>, as usual, with:
# Convert the png files into a movie, with <tt>mencoder</tt> or <tt>ffmpeg</tt>, as usual, with:

Revision as of 15:09, 4 November 2016

Page currently under construction

oxDNA simulations can be very informative to look at if presented in the form of a movie. Here we'll see how to make one with cogli1, a lightweight visualisation tool that can draw oxDNA configurations natively. It's so lightweight that can quickly render configurations with thousands of nucleotides, unlike other visualisation tools we've tried in the past.

Making a movie

To make a movie, where's going to load a trajectory in cogli1, choose a view, and then export each frame in the simulation as a trajectory file. Then we'll render them in povray and convert them in a movie with mencoder. Make sure these programs are installed before running this tutorial.

  1. Open the trajectory with cogli1:
    cogli1 --always-centre -I -v -m -t prova.top trajectory.dat
    The only necessary option is -t (though you will want to use -m if you're using the DNA2 interaction), which specifies the topology file. The others are nice for this particular system and for many others, but you might or might not want to use them for the system you're working on. Their use is as follows:
    • -I
      rotate the system to attempt fix its orientation in space. Simulated objects often float freely in solution and can rotate very sharply from a snapshot to the other, so that a movie would be confusing. This tries to copmensate for that. This does fail from time to time, so you might want to double check that everything works fine before rendering the final, hi-quality version of your images.
      -v
      Start the simulation with a centered configuration.
      --always-centre
      Move the system around to keep its center of mass to the centre of the simulation box throughout all the frames
      -m
      Show oxDNA2 nucleotides, which present major-minor groove asimmetry (just like real DNA), unlike oxDNA1.
    Several other options can be used. You can see the documentation for cogli1 by launching it without any other arguments.
  2. Find a view that you like by moving the configuration around, zooming in, zooming out, etc. See the cogli1 documentation for details on how to do this. Verify that the view is good for every frame in your trajectory by skimming through it, holding the + button. When you are satisfied that you've found a good view, just press
    u
    to save the simulation snapshot to a .cpy file. An example of a good view for this system is saved in sample_view.cpy .
  3. Now let's export each trajectory frames to .pov.
    cogli1 -l view.cpy -t prova.top trajectory.dat
    where view.cpy is the name of your view. This will produce as many .pov files as there are simulation snapshots, and each of them will generate a movie frame. You can edit any .pov file if you so wish, replace it with one taken from another view, or with something copletely different if you feel like playing Tyler Durden :)
  4. Rendering the images in povray can take a long, time, so first we're going to do that with a low resolution to quickly create a preview. Use the command:
    povray -D +H600 +W860 *.pov
    in order to generate the png images at a low resolution, with 600 pixels of height and 860 of width (i.e. with a format of 16:10). Further decrease the resolution if you want it to run even faster, or change the aspect ration as you please.
  5. Encode the povray images in a .avi movie with the commands
    ls -1v output_*.png > storyboard.txt
    mencoder mf://@storyboard.txt -mf w=860:h=600:fps=6:type=png -ovc xvid -xvidencopts bitrate=200 -o preview.avi
    Notice that the width and height of the movie should be the same as the one used in the povray command above.
  6. Visualise the movie with the editor of choice and verify that everything is fine. Go back to the previous points if you see that something isn't quite right.
  7. If you're happy with the view of the movie, you might want to actually use a better resolution. Notice that povray might take a few hours or days to render the scenes depending on your GPU. Notice that if you are going to make a video with a running plot in the top/bottom part of the screen and the simulation movie in the other (i.e. using the append below) you'll need to accomodate the resolution for that, so that if e.g. you want to keep the aspect ratio of the video at 16:10 and your plot takes e.g. 20% of the screen you'll want to use a resolution of 1920x1000, so that the plot can be created with a resolution of 1920x200 and the composite frames have a resolution of 1920x1200.
    povray -D +A +H1200 +W1920 *.pov<pre>
    ls -1v output_*.png > storyboard.txt
    mencoder mf://@storyboard.txt -mf w=1920:h=1200:fps=6:type=png -ovc xvid -xvidencopts bitrate=600 -o output.avi
  8. Your video is ready! Enjoy :-D See below how to add a running plot superimposed to the video or above it.

Adding a running plot

Sometimes a system undergoes a structural change that can be seen in the variation of some physical quantity. It's then nice to show the plot updating as the system's configuration evolves. To do that, we still need to create the .png frames as we do in the section above, but

  1. Create the simulation snapshots with cogli1 and povray. This might take a few minutes or a few days depending on the length and resolution of your movie, so you want to start doing this before anything else. Also before producing the final high-quality simulation snapshots you might want to produce a low-quality-quickly-generated preview, by lowering the resolution.
  2. Create the plots of the quantity with gnuplot. This can be done with e.g. the following gnuplot commands ,which should work in gnuplot >=4.6. If you're stuck with an old version of gnuplot that doesn't support for loops, you can use another program to generate a text file that writes the instructions to be performed at every iteration of the loop, and then run the resulting script in gnuplot.
    set term png linewidth 4 font 'arial,28pt' size 3200,600
    set xrange [25e3:25e3*40]
    set yrange [-1.42; -1.24]
    do for [i = 0:39]{ set out 'plot_'.i.'.png'; plot 'energy.dat' every 1000::1000::1000*(i+1) w lp }

notice that several things should be changed here according to your needs, including:

    • the term type (to change the font, resolution, linewidth, etc). The resolution should be compatible with the one of the simulation snapshots
    • the xrange (to make sure that it fits all the points, just barely)
    • the yrange (to make sure that everything fits as needed)
    • the plot command (to change the appearence of the plot, the line-type, how many frames do we have, whether to print the observable only when we have a frame or for all the frames up until a point, etc.).
    • possibly adding some modifiers before plotting, including title, xlabel, ylabel, etc, a grid, etc.
    • any other edit you might wish to make
  1. After both points above are finished, you can compose the images by either pasting the plots on the simulation snapshots, or appending the images together. This can easily be done with `convert` on linux and cygwin, with either of the following 2 lines:
    TO SUPERIMPOSE THE PLOT TO THE SIMULATION SNAPSHOT``
    for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -composite output_${i}.png; done
    OR TO APPEND IT ABOVE IT
    for i in {0..39}; do convert trajectory.dat_${i}_time_*.png plot_${i}.png -append output_${i}.png; done

swap the order of the plots and the simulations snapshots above to have the plot display below the simulation system instead.

  1. Convert the png files into a movie, with mencoder or ffmpeg, as usual, with:
ls -1v output_*.png > storyboard.txt
mencoder mf://@storyboard.txt -mf w=3200:h=2400:fps=6:type=png -ovc xvid -xvidencopts bitrate=200 -o output.avi` where the keys mean:
    • w and h
      respectively the width and hegiht of the movie (in pixels, here 3200 and 2400). This should be the same as the output_*.png files if you don't want the screen to view to be distorted.
      fps
      the number of frames per second (here 6).
      png
      the type of image (here png)
      ovc
      the codec used (here xvid)
      xvidencopts bitrate
      the bitrate, which is an option of the xvid codec (here set to 200)
      o
      the name of the movie file (here output.avi).

An example of this thing is the movie that I'm attaching here sample movie