Знакомство с Pymol

In [7]:
from xmlrpclib import ServerProxy
from IPython.display import Image
cmd = ServerProxy(uri = "http://localhost:8888/RPC2")
In [8]:
import os, sys, time

# PyMOL launching
import __main__

# Tell PyMOL to launch quiet (-q), fullscreen (-e), without internal GUI (-i)
# and without GUI (-c) and with arguments from command line
__main__.pymol_argv = [ 'pymol', '-qei' ]
#__main__.pymol_argv = [ 'pymol', '-cp' ]
#__main__.pymol_argv = [ 'pymol', '-x' ]  

import pymol
 
# Call the function below before using any PyMOL modules.
pymol.finish_launching()
 
from pymol import cmd, stored

Модель 1LMC

Доступ к интерфейсу прикладного программирования PyMOL Python (Application Programming Interface - API) должен осуществляться исключительно через модуль «cmd» (не «_cmd»), т. е. этот модуль реализует интерфейс к командам PyMOL из интерпретатора python. Почти все функции командной строки имеют соответствующий метод API. С помощью «cmd» команды PyMOL вызываются следующим образом:

from pymol import cmd результат = cmd. <имя-команды> (аргумент, ...)

cmd.do (''' ... ''') позволяет запустить все команды, находящиеся в скобках, без дополнительного приписывания «cmd.»

Описание работы команд взято из PyMOLWiki.

  • Gets structure from the PDB and loads it into PyMOL (async 0 is used for scripting in Python API)

    fetch 1lmp, async=0

  • Eleminates water (solvent) from model

    remove solvent

  • Sets the background color

    bg_color white

  • Remove the atom selection from an object (het - heroatoms - NAG, NAD) and creates it as its own object (ligand)

    extract ligands, het

  • Colors atoms with a spectrum of colors based on atomic property (atom count)

    spectrum count, blue_white_yellow

  • Sets the color of an object or an atom selection to a predifined, named color (blue)

    color blue, ligands

  • Renders helices as ribbons with tubular edges

    set cartoon_fancy_helices, 1

  • Creates a new molecule object from a selection

    create bbCA, n. C in /1lmp/A/A

  • Build a backbone made up of only the carbonyl carbon atoms in his structure

    stored.bbC = []
    iterate (bbCA), stored.bbC. append(index)
    for i in stored.bbC:

    bond ("i. %s in bbCA" % str(i), "i. %s in bbCA" % str(i+1))

  • Displays sticks representation of bonds in backbone

    show sticks, bbCA

  • Change the radius for stick

    set stick_radius, 0.15

  • Displays spheres representation of carbonyl carbon atom in backbone

    show spheres, bbCA

  • Changes radius of spheres in the sphere representation

    set sphere_scale, 0.3

  • Colors spheres independently from the rest of the representations

    set sphere_color, white

  • Scales and translates the window and the origin to cover the atom selection (the whole molecule is visible)

    zoom all

  • Sets viewing information for the current scene, including the rotation matrix, position, origin of rotation, clipping planes, and the orthoscopic flag (the output from the Get_View command may then be used by the set_view command to restore the orientation of the scene)

    set_view (\

    0.132083699, -0.399286866, -0.907262564,\
    0.051876582, 0.916810215, -0.395937383,\
    0.989880860, 0.005231251, 0.141808674,\
    0.000000000, 0.000000000, -123.992378235,\
    14.206069946, 50.743125916, 20.377170563,\
    97.756538391, 150.228225708, -20.000000000 )

  • Changes the way PyMOL's internal renderer represents proteins in the final output (normal color and black outline)

    set ray_trace_mode, 1

  • Turns on PyMOL ray traces shadows

    set ray_shadow, 1

  • Defines the number of light sources

    set light_count, 2

  • Set the light to some position (a vector specifying the XYZ location)

    set light, [0, 0, -100]

  • Controls the amount of ambient light

    set ambient, 0

  • Sets the amount of light being emitted from the camera

    set direct, 0.7

  • Controls whether or not specular reflections are shown unrendered, in the GUI

    set specular, 1

  • Sets the shininess of the objects

    set shininess, 5

  • Controls how PyMOL displays specular reflections in the GUI (unrendered)

    set specular_intensity, 0.3

  • Sets reflect controls the amount of light reflection and the effect directional light therefore has on shadows and the general lighting of the scene

    set reflect, 0.2

  • Controls the reflective exponent for the movable light sources

    set reflect_power, 1

  • Controls whether or not a depth cue fog effect is used

    set depth_cue, 1

  • Adjusts the gradient strength of Depth Cue/fog (a low value gives a more generally cloudy image with a gradual introduction of fog; a larger value gives a sharper introduction of fog into the image)

    set fog_start, 0.45

  • Controls the level of antialiasing that pymol does in the ray-tracing routine (higher numbers take longer to ray trace but provide much smoother and better looking images)

    set antialias, 3

  • Creates a ray-traced image of the current frame (make high-resolution photos fit for publication and formal movies)

    ray

  • Writes selected atoms (the whole model) to a file

    save 1lmp.png''')

In [9]:
cmd.do ('''
fetch 1lmp, async=0    
remove solvent    
bg_color white    
extract ligands, het    
spectrum count, blue_white_yellow   
color blue, ligands  
set cartoon_fancy_helices, 1
create bbCA, n. C in /1lmp/A/A 

stored.bbC = [] 
iterate (bbCA), stored.bbC. append(index) 
for i in stored.bbC: 
    bond("i. %s in bbCA" % str(i),  "i. %s in bbCA" % str(i+1))

show sticks, bbCA
set stick_radius, 0.15
show spheres, bbCA
set sphere_scale, 0.3
set sphere_color, white 

zoom all
set_view (\
     0.132083699,   -0.399286866,   -0.907262564,\
     0.051876582,    0.916810215,   -0.395937383,\
     0.989880860,    0.005231251,    0.141808674,\
     0.000055052,   -0.000078812, -123.992927551,\
    14.237404823,   50.392383575,   19.594482422,\
     0.708233833,  247.276199341,  -20.000000000 )

set ray_trace_mode, 1
set ray_shadow, 1
set light_count, 2
set light, [0, 0, -100]
set ambient, 0
set direct, 0.7
set specular, 1
set shininess, 5
set specular_intensity, 0.3
set reflect, 0.2
set reflect_power, 1
set depth_cue, 1
set fog_start, 0.45
set antialias, 3

ray 
save 1lmp.png''')
In [14]:
Image(filename='1lmp.png')
Out[14]:

PyMOL Movie

Модель 1CLL

  • Conceals atom and bond representations for a certain selection or other graphical objects like distances

    hide everything

  • Displays cartoon representation of the object

    show cartoon

  • Aligns the principal components of the atoms in the selection with the XYZ axes

    orient all

  • Sets up a relationship between molecular states and movie frames to control which states are shown in which frame

    mset 1 x300

  • Store and deletes movie keyframes (keyframes store a view, i. e. camera or object position, and optionally the object state and/or a scene

    mview store

  • Sets the viewer to the indicated movie frame

    frame 100

  • Sets the amount of perspective to apply to the scene (the higher the value of field_of_view the more amplified is the effect of the perspective)

    set field_of_view, 60

  • Scales and translates the window and the origin to cover the atom selection (i. is residue identifier)

    zoom i. 22-64

  • Rotate the atomic coordinates of a molecular object according to the object matrix or the axes and angle for the selection and state provided

    rotate z,80

  • Transitions between positions and representations

    mview interpolate

In [11]:
cmd.do('''
fetch 1cll, async=0    
remove solvent  
set opaque_background, off
bg_color white  
spectrum count, yellow_white_blue
set cartoon_fancy_helices, 1
create bbCA, n. C in /1cll/A/A 

show sticks, bbCA
set stick_radius, 0.15
show spheres, bbCA
set sphere_scale, 0.3
set sphere_color, white 

set ray_trace_mode, 1
set ray_shadow, 1
set light_count, 2
set light, [0, 0, -100]
set ambient, 0
set direct, 0.7
set specular, 1
set shininess, 5
set specular_intensity, 0.3
set reflect, 0.2
set reflect_power, 1
set depth_cue, 1
set fog_start, 0.45
set antialias, 3


hide everything
show cartoon
orient all
mset 1 x300
mview store

frame 100
set_view (\
     0.239345193,    0.394345820,   -0.887245953,\
     0.722698808,    0.537888229,    0.434028327,\
     0.648394406,   -0.745094061,   -0.156251863,\
    -0.000164233,   -0.000019472,  -83.616905212,\
     5.847887039,   37.782306671,   14.650521278,\
    35.612285614,  131.625061035,  -20.000000000 )    
set field_of_view, 60
mview store

frame 150
zoom i. 22-64
rotate z,80
mview store

frame 220
zoom i. 100
mview store

mview interpolate
''')
In [12]:
Image(filename='1cll.png')
Out[12]:
In [13]:
from IPython.display import HTML
from base64 import b64encode


video = open('1cll_movie.mp4', 'rb').read()
video_encoded = b64encode(video)
video_tag = '<video controls width="960" height="540" alt = "PyMol Movie" src ="data:video/mp4;base64,{0}" type = "video/mp4">'.format(video_encoded)
HTML(data = video_tag)
Out[13]:

Ссылки