from xmlrpclib import ServerProxy
from IPython.display import Image
cmd = ServerProxy(uri = "http://localhost:8888/RPC2")
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
Доступ к интерфейсу прикладного программирования PyMOL Python (Application Programming Interface - API) должен осуществляться исключительно через модуль «cmd» (не «_cmd»), т. е. этот модуль реализует интерфейс к командам PyMOL из интерпретатора python. Почти все функции командной строки имеют соответствующий метод API. С помощью «cmd» команды PyMOL вызываются следующим образом:
from pymol import cmd результат = cmd. <имя-команды> (аргумент, ...)
cmd.do (''' ... ''') позволяет запустить все команды, находящиеся в скобках, без дополнительного приписывания «cmd.»
Описание работы команд взято из PyMOLWiki.
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
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))
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.000000000, 0.000000000, -123.992378235,\
14.206069946, 50.743125916, 20.377170563,\
97.756538391, 150.228225708, -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
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
set fog_start, 0.45
set antialias, 3
ray
save 1lmp.png''')
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''')
Image(filename='1lmp.png')
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
mset 1 x300
mview store
frame 100
set field_of_view, 60
zoom i. 22-64
rotate z,80
mview interpolate
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
''')
Image(filename='1cll.png')
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)
Визуализация: PyMOLWiki
Анимация: MovieSchool
Логические операторы и алгебра выбора: Selection Algebra