In [4]:
conda install -c schrodinger pymol
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/MacOS/anaconda3

  added / updated specs:
    - pymol


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    apbs-1.5                   |       h1de35cc_3         258 KB  schrodinger
    conda-4.10.0               |   py36h79c6626_1         3.0 MB  conda-forge
    freemol-1.158              |             py_2           6 KB  schrodinger
    glew-2.0.0                 |                0         542 KB  schrodinger
    libopenblas-0.3.13         |       h7ddc91c_0         4.7 MB
    mengine-1                  |       h1de35cc_1         292 KB  schrodinger
    mpeg_encode-1              |       h1de35cc_1         103 KB  schrodinger
    mtz2ccp4_px-1.0            |       hdc02c5d_3         533 KB  schrodinger
    openssl-1.1.1k             |       h0d85af4_0         1.9 MB  conda-forge
    pdb2pqr-2.1.2+pymol        |             py_0         236 KB  schrodinger
    pmw-2.0.1+3                |             py_3          60 KB  schrodinger
    pymol-2.3.5                |   py36h95b93ae_0         8.1 MB  schrodinger
    rigimol-1.3                |                2         530 KB  schrodinger
    ------------------------------------------------------------
                                           Total:        20.2 MB

The following NEW packages will be INSTALLED:

  apbs               schrodinger/osx-64::apbs-1.5-h1de35cc_3
  freemol            schrodinger/noarch::freemol-1.158-py_2
  glew               schrodinger/osx-64::glew-2.0.0-0
  libopenblas        pkgs/main/osx-64::libopenblas-0.3.13-h7ddc91c_0
  mengine            schrodinger/osx-64::mengine-1-h1de35cc_1
  mpeg_encode        schrodinger/osx-64::mpeg_encode-1-h1de35cc_1
  mtz2ccp4_px        schrodinger/osx-64::mtz2ccp4_px-1.0-hdc02c5d_3
  pdb2pqr            schrodinger/noarch::pdb2pqr-2.1.2+pymol-py_0
  pmw                schrodinger/noarch::pmw-2.0.1+3-py_3
  pymol              schrodinger/osx-64::pymol-2.3.5-py36h95b93ae_0
  rigimol            schrodinger/osx-64::rigimol-1.3-2

The following packages will be UPDATED:

  conda                                4.9.2-py36h79c6626_0 --> 4.10.0-py36h79c6626_1
  openssl                                 1.1.1j-hbcf498f_0 --> 1.1.1k-h0d85af4_0



Downloading and Extracting Packages
freemol-1.158        | 6 KB      | ##################################### | 100% 
mtz2ccp4_px-1.0      | 533 KB    | ##################################### | 100% 
pmw-2.0.1+3          | 60 KB     | ##################################### | 100% 
conda-4.10.0         | 3.0 MB    | ##################################### | 100% 
pdb2pqr-2.1.2+pymol  | 236 KB    | ##################################### | 100% 
pymol-2.3.5          | 8.1 MB    | ##################################### | 100% 
mpeg_encode-1        | 103 KB    | ##################################### | 100% 
glew-2.0.0           | 542 KB    | ##################################### | 100% 
apbs-1.5             | 258 KB    | ##################################### | 100% 
rigimol-1.3          | 530 KB    | ##################################### | 100% 
openssl-1.1.1k       | 1.9 MB    | ##################################### | 100% 
mengine-1            | 292 KB    | ##################################### | 100% 
libopenblas-0.3.13   | 4.7 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Note: you may need to restart the kernel to use updated packages.

Допустим, pymol установила.

In [55]:
import numpy as np
from IPython.display import Image

Теперь запустим в pymol простой скрипт из задания и получим картинку.

In [69]:
import __main__
__main__.pymol_argv = [ 'pymol', '-c' ]
import pymol
pymol.finish_launching()
from pymol import cmd,stored

cmd.do('''
fetch 1cll, async=0
as lines, n. C+O+N+CA
zoom i. 4+5
mset 1 x1000
mview store''')

cmd.png('/tmp/1.png')
Image(filename='/tmp/1.png')
Out[69]:

Сделаем итерацию по остаткам.

In [70]:
stored.r = [] 
cmd.iterate('1cll and n. CA','stored.r.append(resi)')

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.5,0.75])
    print([1,1,colors[k]])
    cmd.set('cartoon_color','col%d' % k ,'resi %d' % int(i))
cmd.show_as('cartoon','all')
[1, 1, 1.0]
[1, 1, 0.9966887417218543]
[1, 1, 0.9933774834437086]
[1, 1, 0.9900662251655629]
[1, 1, 0.9867549668874173]
[1, 1, 0.9834437086092715]
[1, 1, 0.9801324503311258]
[1, 1, 0.9768211920529801]
[1, 1, 0.9735099337748344]
[1, 1, 0.9701986754966887]
[1, 1, 0.9668874172185431]
[1, 1, 0.9635761589403974]
[1, 1, 0.9602649006622517]
[1, 1, 0.956953642384106]
[1, 1, 0.9536423841059603]
[1, 1, 0.9503311258278145]
[1, 1, 0.9470198675496688]
[1, 1, 0.9437086092715232]
[1, 1, 0.9403973509933775]
[1, 1, 0.9370860927152318]
[1, 1, 0.9337748344370861]
[1, 1, 0.9304635761589404]
[1, 1, 0.9271523178807947]
[1, 1, 0.923841059602649]
[1, 1, 0.9205298013245033]
[1, 1, 0.9172185430463576]
[1, 1, 0.9139072847682119]
[1, 1, 0.9105960264900662]
[1, 1, 0.9072847682119205]
[1, 1, 0.9039735099337748]
[1, 1, 0.9006622516556292]
[1, 1, 0.8973509933774835]
[1, 1, 0.8940397350993378]
[1, 1, 0.890728476821192]
[1, 1, 0.8874172185430463]
[1, 1, 0.8841059602649006]
[1, 1, 0.880794701986755]
[1, 1, 0.8774834437086093]
[1, 1, 0.8741721854304636]
[1, 1, 0.8708609271523179]
[1, 1, 0.8675496688741722]
[1, 1, 0.8642384105960265]
[1, 1, 0.8609271523178808]
[1, 1, 0.8576158940397351]
[1, 1, 0.8543046357615894]
[1, 1, 0.8509933774834437]
[1, 1, 0.847682119205298]
[1, 1, 0.8443708609271523]
[1, 1, 0.8410596026490066]
[1, 1, 0.8377483443708609]
[1, 1, 0.8344370860927153]
[1, 1, 0.8311258278145696]
[1, 1, 0.8278145695364238]
[1, 1, 0.8245033112582781]
[1, 1, 0.8211920529801324]
[1, 1, 0.8178807947019868]
[1, 1, 0.814569536423841]
[1, 1, 0.8112582781456954]
[1, 1, 0.8079470198675497]
[1, 1, 0.804635761589404]
[1, 1, 0.8013245033112583]
[1, 1, 0.7980132450331126]
[1, 1, 0.794701986754967]
[1, 1, 0.7913907284768211]
[1, 1, 0.7880794701986755]
[1, 1, 0.7847682119205298]
[1, 1, 0.7814569536423841]
[1, 1, 0.7781456953642384]
[1, 1, 0.7748344370860927]
[1, 1, 0.7715231788079471]
[1, 1, 0.7682119205298014]
[1, 1, 0.7649006622516556]
[1, 1, 0.7615894039735099]
[1, 1, 0.7582781456953642]
[1, 1, 0.7549668874172185]
[1, 1, 0.7516556291390728]
[1, 1, 0.7483443708609272]
[1, 1, 0.7450331125827814]
[1, 1, 0.7417218543046358]
[1, 1, 0.7384105960264901]
[1, 1, 0.7350993377483444]
[1, 1, 0.7317880794701987]
[1, 1, 0.7284768211920529]
[1, 1, 0.7251655629139073]
[1, 1, 0.7218543046357616]
[1, 1, 0.7185430463576159]
[1, 1, 0.7152317880794702]
[1, 1, 0.7119205298013245]
[1, 1, 0.7086092715231789]
[1, 1, 0.705298013245033]
[1, 1, 0.7019867549668874]
[1, 1, 0.6986754966887417]
[1, 1, 0.695364238410596]
[1, 1, 0.6920529801324503]
[1, 1, 0.6887417218543046]
[1, 1, 0.685430463576159]
[1, 1, 0.6821192052980132]
[1, 1, 0.6788079470198676]
[1, 1, 0.6754966887417219]
[1, 1, 0.6721854304635762]
[1, 1, 0.6688741721854304]
[1, 1, 0.6655629139072847]
[1, 1, 0.6622516556291391]
[1, 1, 0.6589403973509933]
[1, 1, 0.6556291390728477]
[1, 1, 0.652317880794702]
[1, 1, 0.6490066225165563]
[1, 1, 0.6456953642384107]
[1, 1, 0.6423841059602649]
[1, 1, 0.6390728476821192]
[1, 1, 0.6357615894039735]
[1, 1, 0.6324503311258278]
[1, 1, 0.6291390728476821]
[1, 1, 0.6258278145695364]
[1, 1, 0.6225165562913908]
[1, 1, 0.619205298013245]
[1, 1, 0.6158940397350994]
[1, 1, 0.6125827814569537]
[1, 1, 0.609271523178808]
[1, 1, 0.6059602649006622]
[1, 1, 0.6026490066225165]
[1, 1, 0.5993377483443709]
[1, 1, 0.5960264900662251]
[1, 1, 0.5927152317880795]
[1, 1, 0.5894039735099338]
[1, 1, 0.5860927152317881]
[1, 1, 0.5827814569536424]
[1, 1, 0.5794701986754967]
[1, 1, 0.576158940397351]
[1, 1, 0.5728476821192052]
[1, 1, 0.5695364238410596]
[1, 1, 0.5662251655629139]
[1, 1, 0.5629139072847682]
[1, 1, 0.5596026490066226]
[1, 1, 0.5562913907284768]
[1, 1, 0.5529801324503312]
[1, 1, 0.5496688741721854]
[1, 1, 0.5463576158940397]
[1, 1, 0.543046357615894]
[1, 1, 0.5397350993377483]
[1, 1, 0.5364238410596027]
[1, 1, 0.5331125827814569]
[1, 1, 0.5298013245033113]
[1, 1, 0.5264900662251656]
[1, 1, 0.5231788079470199]
[1, 1, 0.5198675496688742]
[1, 1, 0.5165562913907285]
[1, 1, 0.5132450331125828]
[1, 1, 0.509933774834437]
[1, 1, 0.5066225165562914]
[1, 1, 0.5033112582781457]
[1, 1, 0.5]
In [71]:
cmd.png('/tmp/2.png')
Image(filename='/tmp/2.png')
Out[71]:

Сделаем мультик. Недосказанность кода преодолена, но собрать gif у меня не получилось.

In [72]:
for i in range(len(stored.r)):
    cmd.frame((10*i)+1)
    cmd.zoom( 'n. CA and i. %d+%d' % (i,i+7))
    cmd.mview('store')