Install moviepy to generate movie from image files
# OSX user: install matplotlib via conda to make it work properly with moviepy# amber.conda install matplotlib
amber.pip install moviepy
amber.conda install freeimage
You know how to use Linux command line. If not, please check basic AMBER tutorial
You know how to open a Jupyter notebook
amber.jupyter notebook notebook.ipynb
# where `notebook.ipynb` is the name of your notebook.
Note: If you did not have amber.{pip, conda}, you can just use pip, conda or jupyter commands
# make sure to change your web browser option to save files as default (vs open file by external program)# NGLView will render each snapshot and save image to your web browser default download location# uncomment all the commands below to render# from time import sleep# # to save time for this tutorial, we make a movie with only 50 frames# for frame in range(0, 50):# # set frame to update coordinates# view.frame = frame# # make sure to let NGL spending enough time to update coordinates# sleep(0.5)# view.download_image(filename='0image{}.png'.format(frame))# # make sure to let NGL spending enough time to render before going to next frame# sleep(2.0)
# In my case, my default download folder is /Users/haichit/Downloads/template='/Users/haichit/Downloads/0image{}.png'# get all (sorted) image filesimagefiles=[template.format(str(i))foriinrange(0,50,2)]
In [ ]:
# make a gif fileframe_per_second=8im=mpy.ImageSequenceClip(imagefiles,fps=frame_per_second)im.write_gif('my_movie.gif',fps=frame_per_second)
In [6]:
# display the gif in this notebookfromIPythonimportdisplaydisplay.HTML("<img src='my_movie.gif'></img>")