In [1]:
from xmlrpclib import ServerProxy
import __main__
__main__.pymol_argv = [ 'pymol', '-c' ]
# __main__.pymol_argv = [ 'pymol', '-x' ]
import pymol
pymol.finish_launching()
from pymol import cmd,stored
 Detected 4 CPU cores.  Enabled multithreaded rendering.
In [2]:
cmd.do('''
fetch 1cll, async=0
as lines, n. C+O+N+CA
zoom i. 4+5
mset 1 x1000
mview store''')
In [3]:
for i in range(100):
    cmd.frame((10*i)+1)
    cmd.zoom( 'n. CA and i. %d+%d' % (i,i+7))
    cmd.mview('store')    
In [4]:
v = cmd.get_view()
cmd.set_view(v)
In [5]:
stored.r = [] 
cmd.iterate('1cll and n. CA','stored.r.append(int(resi))')
Out[5]:
152
In [6]:
import numpy as np
length = len(stored.r)
colors = np.linspace(1,0.5, length)
for k,i in enumerate(stored.r):
    cmd.set_color('col%d' %k, [colors[k], 0, 1])
    cmd.set('cartoon_color','col%d' % k ,'resi %d' % i)
cmd.show_as('cartoon','all');

Сохранение изображения

In [7]:
cmd.zoom()
cmd.png(filename='/media/sf_jupyter_core/molsim/pymol.png',width='10cm',dpi=300,ray=1)

Отображение видео

In [8]:
import io
import base64
from IPython.display import HTML

video = io.open('movie.mp4', 'r+b').read()
encoded = base64.b64encode(video)
HTML(data='''<video alt="test" controls>
                <source src="data:video/mp4;base64,{0}" type="video/mp4" />
             </video>'''.format(encoded.decode('ascii')))
Out[8]: