基本命令(也可使用鼠标操作,但不如命令来得简单)
pwd # show current directory
dir # list file in the current directory
cd directory #change directory
load xxx #注意要打上扩展名,例如1LMK.pdb,否则会errorc
reat name, (selection) #name=object to creat, selection=atom to include in the new object,非常实用的功能
Manipulating object:
show representation, (selection)
hide representation, (selection)
#the available representations are: (前面是个人比较常用的)lines, spheres, ribbon, cartoon, sticks, surface, /// mesh, dots, labels, extent
例如: stick mol1 & resi 100 # mol1为显示在pymol右边的分子名称
Turn an object on and off:(这个直接用鼠标就ok了)
enable/disable, object-name #turn on/off all representation
Basic atom selections:
name
resn
resi
chain
elem
Selection algebra:就是怎么选择
交集是and、&,例如 1LDK and chain A and i. 1-103
并集是or/|,补集是not/!
Change your point of view:
zoom, (selection) #fit the selection to screen
orient, (selection) #align molecular axisc
enter, (selection) # size not changed
turn axis, angle #rotate camera
move axis, distance #translate camera
Align (个人认为最重要的功能):
align (source), (target) #the source object will be moved and rotated to fit the target object
例如: align (prot1 and chain A), (prot2 and chain B) 按整条链叠合
align mol1 & resi N1, mol2 & resi N2 按某一个残基叠合
align mol1 & resi N1-N2 & name n+ca+c+o,mol2 & resi N3-N4 & name n+ca+c+o 按某段残基的主链进行叠合
在align的过程中会产生一个root mean square deviation (RMSD),这个值可在一定程度上衡量alignment的效果。
Set control (可以通过这个命令来调整所有参数的值,可惜没有什么详细的介绍)
例如 set sphere_scale, 0.5, (n. Fe) #decrease Fe atom size to 0.5
set bg_rgb, [1,1,1] #set background as white
set ribbon_sampling, 1
Measurement (又一个十分重要的功能,可以真正挖掘结构的意义)
dist #测量两个原子之间的距离,ctrl+右键选择第一个原子,ctrl+中键选择第二个原子,然后测量dist。
angel # 测三个原子之间的夹角, ctrl+中键选择第三个原子,然后测量angle
dihedral #测量四个原子之间的二面角
Launching PyMOL
File for startup commands
Linux:
Whenever PyMol starts, a '.pymolrc' file containing commands is run. All you need to do is create ".pymolrc" and place it in your home directory. Alternatively, you can instead create ".pymolrc.py" which contains actual Python code instead of just PyMOL commands.
Windows:
On Windows, use 'pymolrc', 'pymolrc.py' or 'pymolrc.pym'.
Warren DeLano
Launching PyMOL from an external program
If PYMOL_PATH, LD_LIBRARY_PATH, and TCL_LIBRARY are correctly defined, then you can launch PyMOL from an external Python program as shown inexamples/devel/start_pymol.py.
NOTE: This approach is not recommended, since the PyMOL launching process is subject to change without warning. The recommended approach is to just use PyMOL as your python interpreter:
pymol -r
pymol -qcr
Warren DeLano
Running PyMOL in batch mode
To perform PyMOL commands from stdin (file, pipe) without opening an OpenGL window, try:
pymol -qc
Suppressing PyMOL output
Just type:
feedback disable,all,actions
feedback disable,all,results
-From Python:
cmd.feedback("disable","all","actions")
cmd.feedback("disable","all","results")
Will suppress most of PyMOL's normal chatter.
Launching Python programs
Running a Python script from PyMOL, usually the command:
run script.py
Is enough. Of course, the file script.py needs to be in the working directory.
For more detailed examples, see the commands to launch Python scripts when starting PyMOL. Asynchronous means, that a new Python thread is started:
pymol example.py # synchronous, in PyMOL module
pymol -r example.py # synchronous in __main__ module
pymol -l example.py # asychronous in a new module
You can also launch python programs from within PyMOL with the commands:
run example.py # synchronous in pymol module
run example.py,main # synchronous in __main__ module
spawn example.py # asychronous in a new module
spawn example.py,global # asychronous in the PyMOL module
spawn example.py,main # asychronous in the __main__ module
Displaying biochemical Properties
Selecting secondary structures
Examples:
select helix, (ss h)
select sheet, (ss s)
select loop, (ss l+'')
Color by atom type from a script
The "util" module contains a number of functions that color the atoms according to type, with different colors for the C atoms. For instance,
util.cbay three
in a .pml script will color object "three" by atom type, with the carbon atoms in yellow ("color by atom yellow").
Other functions from ../modules/pymol/util.py are cbag, cbac, cbas, cbap, cbak, cbaw and cbab (grey (carbon), cyan, salmon, purple, pink, white (hydrogen) and slate).
Lieven Buts
Displaying double bonds
You can try going into lines mode and turning on the valence display:
hide
show lines
set valence, 0.1
a higher value for valence spreads things out more. I don't know of a way to get the dotted notation.
Michael George Lerner
Calculating dihedral angles
The get_dihedral function requires four single-atom selections to work:
get_dihedral prot1///9/C, prot1///10/N, prot1///10/CA, prot1///10/C
Adding hydrogen bonds
Regarding H-bonds. There isn't a built-in function yet, but you can show H-bonds between two objects using atom selections so long as hydrogens are present in both molecules. If you don't have hydrogens, you can use h_add on the proteins or provide ligands with valence information and then use h_add.
Two examples are below. For clarity, they draw dashes between the heavy atoms and hide the hydrogens.
EXAMPLE 1: Show hydrogen bonds between protein and docked ligands
EXAMPLE 2: Show hydrogen bonds between two proteins
There is also a script drawing nice hydrogen bonds fromGareth Stockwell
Warren DeLano
Assign color by B-factor
Robert Campbell has a color_b.py python script on hisPyMOL web page that you can use.
it has a number of options including the selection and two types of colouring schemes (rainbow versus a blue-magenta-red gradient) and two types of binning of the colours (equal number of atoms in each colour or equal spacing of colours along the B-factor range).
See http://biophysics.med.jhmi.edu/rlc/work/pymol to download. There is a script 'data2bfacor' to display arbitrary data assigned to atoms as well.
Robert L. Campbell
Polar surface area
For a solvent accessible PSA approximation:
set dot_density, 3
remove hydro
remove solvent
show dots
set dot_solvent, on
get_area elem N+O
get_area elem C+S
get_area all
For molecular PSA approximation
set dot_density, 3
remove hydro
remove solvent
set dot_solvent, off
get_area elem N+O
get_area elem C+S
get_area all
Showing dots isn't mandatory, but it's a good idea to confirm that you're getting the value for the atom dot surface you think you're using.
Please realize that the resulting numbers are only approximate, reflecting the sum of partial surface areas for all the dots you see. To increase accuracy, set dot_density to 4, but be prepared to wait...
Warren DeLano
Display solvent accessible surface
Using the surface display mode, PyMOL doesn't show the solvent accessible surface, rather it shows the solvent/protein contact surface. The solvent accessible surface area is usually defined as the surface traced out by the center of a water sphere, having a radius of about 1.4 angstroms, rolled over the protein atoms. The contact surface is the surface traced out by the vdw surfaces of the water atoms when in contact with the protein.
PyMOL can only show solvent accessible surfaces using the dot or sphere representations:
for dots:
show dots
set dot_mode,1
set dot_density,3
for spheres:
alter all,vdw=vdw+1.4
show spheres
Kaushik Raha
Displaying the C-Alpha trace of proteins
hide
show ribbon
set ribbon_sampling,1
And if your model only contains CA atoms, you'll also need to issue:
set ribbon_trace,1
Warren DeLano
Displaying the Phosphate backbone of nucleic acids
Should you ever want to show the phosphate trace of a nucleic acid molecule:
def p_trace(selection="(all)"):
s = str(selection)
cmd.hide('lines',"("+s+")")
cmd.hide('spheres',"("+s+")")
cmd.hide('sticks',"("+s+")")
cmd.hide('ribbon',"("+s+")")
cmd.show('cartoon',"("+s+")")
cmd.set('cartoon_sampling',1,"("+s+")")
cmd.set('cartoon_tube_radius',0.5,"("+s+")")
cmd.extend('p_trace',p_trace)
and then:
p_trace (selection)
Luca Jovine
Align proteins with CA fit
If the proteins have significant homology, then you can use the align command:
align prot1////ca,prot2
which will perform a sequence alignment of prot1 against prot2, and then an optimizing fit using the CA positions. I'm not sure if the help text for align got into 0.82, but the next version will definitely have it.
Coloring molecules
Coloring secondary structures
Examples:
color red, ss h
color yellow, ss s
color green, ss l+''
When "the colour bleeds from the ends of helices and sheets into loops," try setting cartoon_discrete_colors to 'on' (or 1).
set cartoon_discrete_colors, 1
or from the the "Cartoon" menu of the external GUI find "Discrete Colors" as the last item in the menu.
Robert Campbell
Color by atom type from a script
The "util" module contains a number of functions that color the atoms according to type, with different colors for the C atoms. For instance,
util.cbay three
in a .pml script will color object "three" by atom type, with the carbon atoms in yellow ("color by atom yellow").
Other functions from ../modules/pymol/util.py are cbag, cbac, cbas, cbap, cbak, cbaw and cbab (grey (carbon), cyan, salmon, purple, pink, white (hydrogen) and slate).
Lieven Buts
Use CMYK-safe Colors
Some RGB triplets do have equivalents in CMYK space, and as a result, a figure that looks great on a screen can come out with unpredictable colors when printed.
Most applications do a good job with RGB-to-CMYK conversions for photos, but do not do such a good job with graphics that use pure primary colors. For example, reds are generally OK, but pure blues and greens do not translate very well.
Here are some RGB values that are within the CMYK gamut (i.e. are "CMYK-safe"). In general, colors in PyMOL can be assigned manually:
set_color green= [0.00 , 0.53 , 0.22]
Note that there are default atom colors such as "carbon", "nitrogen", "oxygen", "hydrogen", "sulfur", etc. which should also be redefined:
set_color carbon= [0.00 , 0.53 , 0.22]
Here's still another URL. Although the list of colors is not extensive, you can see colors:CMYK-safe RGB colors
Gil Prive, Dave Fahrney and Warren DeLano
Assign color by B-factor
Robert Campbell has a color_b.py python script on hisPyMOL web page that you can use.
it has a number of options including the selection and two types of colouring schemes (rainbow versus a blue-magenta-red gradient) and two types of binning of the colours (equal number of atoms in each colour or equal spacing of colours along the B-factor range).
See http://biophysics.med.jhmi.edu/rlc/work/pymol to download. There are other scripts there as well.
Robert L. Campbell
Creating a Color bar
To show a vertical/horizontal color bar indiacting the b-factor variation, use the scriptpseudobar.pml on the structurepseudobar.pdb, or do the following:
1. Create a pdb-file which contains CA positions only, whereas the numbers correspond to your wanted increments of colors. Be sure that CA's are separated by a contant value, say 5 Angstroem.
2. Load this new pseudobar-pdb file into PyMOL, make bonds between increment 1 and increment 2 [increment 2 and increment 3 and so on...], define/assign a smooth color for each increment (copy colors definition from automatically created colors made by b-factor script) and show the b-factor bar as lines (or sticks).
Bartholomeus Kuettner
Coloring insides and outsides of helices differently
Q: does anyone know how to color the inside of helices a different color than the outsides?
A:
set cartoon_highlight_color, red
Warren L. DeLano
Coloring all objects differently
Q: Is there a simple way to colour each object currently loaded, with a different colour?
A: There is a script color_obj.py that does the job.
The script is also available at
http://www.ebi.ac.uk/~gareth/misc
USAGE
color_obj(rainbow=0)
This function colours each object currently in the PyMOL heirarchy
with a different colour. Colours used are either the 22 named
colours used by PyMOL (in which case the 23rd object, if it exists,
gets the same colour as the first), or are the colours of the rainbow
Gareth Stockwell
List the color of atoms
To retrieve the color for a residue as identified in an expression, you can either iterate over a selection from the PyMOL command line
iterate all, print color
Alternatively, this can be done from a Python script.
Rendering molecules
Displaying in ball-and-stick mode
Q: I've tried several settings and commands but cannot figure out how to make a simple ball-and-stick representation of a molecule. Can it be done in Pymol?
A: Yes, but it is non-obvious:
hide lines
show sticks
show spheres
set stick_radius=0.1
set sphere_scale=0.25
You can change the two numbers above to fit preferences.
Warren DeLano
Adjusting width of cartoon
Try varying the following.
For strands:
cartoon_rect_length
cartoon_rect_width
For helices:
cartoon_oval_length
cartoon_oval_width
or for "fancy" helices:
cartoon_dumbell_length
cartoon_dumbell_width
cartoon_dumbell_radius (radius of cylinder at edge of helix ribbon)
In each case "length" refers to what some might call the width and "width" refers to what some might call the thickness.
Robert Campbell
Calculating a partial surface
There is a, until now, undocumented way to calculate a surface for only a part of an object without creating a new one:
flag ignore, not A/49-63/, set
delete indicate
show surface
If the surface was already computed, then you'll also need to issue the command:
rebuild
Warren DeLano
Displaying surface inside a molecule
As far as I can tell, setting ambient to zero alone doesn't quite do the job, since some triangles still get lit by the light source.
The best combination I can find is:
set ambient=0
set direct=0.7
set reflect=0.0
set backface_cull=0
Which gives no shadows and only a few artifacts.
As an alternative, you might just consider showing the inside of the surface directly...that will create less visual artifacts, and so long as ambient and direct are sufficiently low, it will look reasonable in "ray".
util.ray_shadows("heavy")
set two_sided_lighting=1
set backface_cull=0
Warren DeLano
Displaying all states of a multiple model/NMR structure
Just go to the movies menue and click 'show all states'.
Jules Jacobsen
Displaying dashed lines between two atoms
I think the following commands will do what you want:
select a, ///A/501/02
select b, ///B/229/N
distance d, a, b
This will give you a dashed line object d which is labelled with the distance between the two atoms 'a' and 'b' - you can get rid of the label using
hide labels, d
btw, if you want to ray-trace the image, I find the dashes come out a bit fat - so I tend to use
set dash_gap, 0.5
set dash_radius, 0.1
before the 'ray' command.
Gareth Stockwell
· Adjusting size of selection indicators
Adjusting size of selection indicators
Try:
set selection_width, 6
set selection_width, 7
Warren L. DeLano
Adjusting ray trace-image size
The pymol ray tracer can generate an image of any size.
ray height,width
Example:
ray 3000,2400
png filename.png
For more options, try 'help ray'
Evan Stein and Ben Cornett
Ray tracing maps
For better quality maps with a white background.
set ray_trace_fog,0
set ray_shadows,0
set antialias,1
ray 1600,1200
png img.png
(it will take quite a while...)
Then open img.png using an external image viewer. It should be high enough resolution to print nicely.
Warren DeLano
Nive PovRay settings
I typically use the make_pov.py script and "run" it from pymol once to load the function, and then I do "make_pov('povray.inp')" to create the povray.inp file.
Then I edit that file to insert some lines like:
fog {
distance 10
fog_type 2
fog_alt 10.
fog_offset -160.
up <0.,1.,.4>
colour rgbt<1.0, 1.0, 1.0, 0.1>
turbulence 0.8
}
In this case I'm not really doing depth-cueing but adding fog at the lower background edge (there were two planes defining the background and a surface below the molecule) rising up towards the front upper edge of the scene.
"fog_type 2" means a "rising fog" along the "up" vector. fog_type 1 is a constant fog. To get pure depth cueing, you would want "up" to be along the <0., 0., 1.> vector (I think!). You'll need to play around with the distance and fog_offset parameters.
You wouldn't necessarily want the "turbulence" parameter in there either.
Check out "Atmospheric Effects" in the povray documentation for many more details:http://www.povray.org/documentation/view/201/
Robert Campbell
Making stereo pairs
Try:
ray angle=-3
png image1.png
ray angle=3
png image2.png
This is superior to using the "turn" command because it also rotates the light source. That way shadows will look right.
To make even more beautiful stereo images, use a program like Illustrator or Canvas to add the stereo/depth cued labels. This is a little tricky to describe, but I'll give it my best shot. Place the two images side by side with their centers separated by 6.0 - 6.5 cm, and aligned horizontally. Now add all your labels on the LEFT figure. select all of your labels and duplicate them. Move the duplicated labels to the RIGHT side. For clarity sake let's assume we have 3 labels on the LEFT side (a,b, and c -- we will call then aL and aR for the left and right labels, respectively). Place aL near a recognizable feature of the LEFT figure that you are trying to label. Now horizontilly align aR with aL. Now using only the L/R arrow keys move the aR label until the identical portion of the actual label (let's say the lower right hand tip of the 'a') is vertically aligned with the identical portion of your model (let's say where the C alpha-C beta bond leaves the ribbon backbone) on both the LEFT and RIGHT images. Repeat these steps for each pair of labels. This is a nice method for adding stereo labels because it does not require looking at your computer screen in wall-eyed stereo for 2 hours in order to get proper placement of labels.
By assuring that the labels are positioned in the LEFT and RIGHT images at positions that are identical with respect to the part of the model that is being labeled you automatically are also placing them so they are at the proper depth when the figure is finally viewed in stereo.
Scott Classen and Warren DeLano
Meaning of the get_view output
Of the 18 numbers in the output array,
0-8 is the 3x3 rotation matrix,
9-11 is the camera location,
12-14 is the origin of rotation,
15-16 are the clipping distances,
and 17 is the orthoscopic flag.
Robert Campbell, Paolo Martel and Warren
Viewing direction vectors
Create a python script (I call it axes.py):
# axes.py
from pymol.cgo import *
from pymol import cmd
from pymol.vfont import plain
# create the axes object, draw axes with cylinders coloured red, green,
#blue for X, Y and Z
obj = [
CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0.,
CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0.,
CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0,
]
# add labels to axes object (requires pymol version 0.8 or greater, I
# believe
cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
# then we load it into PyMOL
cmd.load_cgo(obj,'axes')
Then you just need to do "run axes.py" from the pymol command line.
You can modify the "3" in the above description of the text labels to change the size of the labels. If you are running a version of pymol older the 0.8, then you cannot add the text (that's why I included colour coding of the axes). You can also use just lines instead of cylinders if you wish:
obj = [
BEGIN, LINES,
COLOR, 1.0, 0.0, 0.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 10.0, 0.0, 0.0,
COLOR, 0.0, 1.0, 0.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 0.0, 10.0, 0.0,
COLOR, 0.0, 0.0, 1.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 0.0, 0.0, 10.0,
END,
]
would work as well to define the axes object.
Ray-traceable labels
You can use the cgo text (line or cylinder versions) as I mentioned in my reply about drawing the xyz axes, but be warned that the labels rotate with your molecule, so getting them oriented perpendicular to the view may be a pain (unless there is something I've missed).
Warren's example from a previous reply of his (cgotext.py):
# draw text using cgo
from pymol import cmd
from pymol.cgo import *
from pymol.vfont import plain
cgo = []
axes = [[2.0,0.0,0.0],[0.0,2.0,0.0],[0.0,0.0,2.0]]
pos = [0.0,0.0,0.0]
wire_text(cgo,plain,pos,'Hello World',axes)
pos = [0.0,-3.0,0.0]
cyl_text(cgo,plain,pos,'Hello Universe',0.10,axes=axes)
cmd.set("cgo_line_radius",0.03)
cmd.load_cgo(cgo,'txt')
cmd.zoom("all",2.0)
Robert Campbell
CGO label orientation
You could use the cmd.rotate andcmd.translate to position the labels, but it is likely to be somewhat painful. If I'm not mistaken, the rotation will always be about and axis through the origin and so you may need to translate the label into the correct position.
Thus if you have your label in an object called 'text', you could do,
cmd.rotate(axis='x',angle=20.,object='text')
and repeat this with different angles, until you get the orientation correct. Then use:
cmd.translate(vector='[1.,2.,3.]',object='text')
(using the appropriate vector, of course!) to position the label.
Not ideal, but if it is sufficiently important, it can be done!
Modeling with PyMOL
Saving with transformed coordinates
Here is a simple script that saves the molecule with coordinates from the current orientation.
(invoke it with 'run save_transformed.py' and type the new save_transformed.py command thereafter).
Paulo Martel
Translate or rotate individual objects
There is a "translate" function similar to "rotate", the docs for these don't exist yet, because the implementation isn't finished. However, feel free to use them in the following forms:
translate vector,object-name,state
(vector needs to be something like [x,y,z])
translate [1,0,0],pept
rotate axis,angle,object-name,state
(axis can be either the letter x,y,z or a 3D vector [x,y,z])
rotate x,90,pept
rotate [1,1,1],10,pept
Warren DeLano
Moving one segment relative to the rest
This means moving two parts of one object into different directions. The easiest way to do this is to split the objects and then use the rotate command.
EXAMPLE: split.pml
Warren DeLano
Split states to objects
There is also a new command in the 0.95 series:
split_states object-name
which will spread a PDB "biological unit" (or any multi-state object -- including SD files) over a series of independent objects. This makes it possible to interact with such objects more naturally than with "all_states = 1".
Warren DeLano
Altering secondary structures:
Examples:
alter A/10:34/, ss='H'
alter A/35:40/, ss='L'
alter A/41:60/, ss='S'
Altering van der Waals radii
Example:
alter (elem Fe),vdw=1.8
rebuild
(The value for Fe is wrecked in PyMOL at the moment, so running the above line might be a good idea).
Warren DeLano
Altering atom coordinates
Example:
alter_state 1,(pdb1cse),x=x-10.0
The latter section can contain formulae involving at least the xyz coordinates, lots of constants and the (+-*/) operators.
Deleting bonds
Select the bond using Ctrl-right-click, then either
unbond pk1,pk2
or hit Ctrl-D.
Warren DeLano
Converting D- to L- amino acids
The inversion function was changed in version 0.95 to take advantage of multiple picked atoms. To invert a center, Ctrl-middle-click to pick the center atom as pk1 and two stationary atoms as pk2 and pk3. Then type Ctrl-E to invert.
Warren DeLano
Adding disulfide bonds
You can use the "bond" command to attach them:
bond 24/sg,26/sg
bond 56/sg,99/sg
unpick
(unpick will hide the bond baton which gets displayed.)
Additionally, the residue names can be changed for bonded cysteines:
alter cys/,name='CYX'
or for specific residues
alter 24+26+56+99/,name='CYX'
Warren DeLano
Adding hydrogen bonds
Regarding H-bonds. There isn't a built-in function yet, but you can show H-bonds between two objects using atom selections so long as hydrogens are present in both molecules. If you don't have hydrogens, you can use h_add on the proteins or provide ligands with valence information and then use h_add.
Two examples are below. For clarity, they draw dashes between the heavy atoms and hide the hydrogens.
EXAMPLE 1: Show hydrogen bonds between protein and docked ligands
EXAMPLE 2: Show hydrogen bonds between two proteins
There is also a script drawing nice hydrogen bonds fromGareth Stockwell
Warren DeLano
Protonating ligands
If your ligands come in with valid valencies and formal charges, PyMOL's h_add command can protonate ligands. (NOTE that there is a minor technical hiccup with SD-files which are loaded by default as immutable "discrete" objects.) Suffice it to say that in order to make changes to the chemical structure, an object must be loaded with the "discrete" flag set to zero.
Unfortunately, much of the molecular editing stuff remains to be documented. Here's an example sequence, but I'm not sure it will help to much...as indicated in the manual, this is immature functionality with some major gaps. Attach in particular is very limited...
# show valences
set valence=0.05
# load cysteine fragment
fragment cys
# remove hydrogens
remove (hydro)
# edit gamma S
edit cys////sg
# add hydrogen
attach H,1,1
# add planer, trivalent nitrogen onto C terminus
edit cys////C
attach N,3,3
# edit that nitrogen
edit (elem N and neighbor cys////C)
# attach a tetrahedral methyl (note random position)
attach C,4,4
# here's an example of adding a whole residue from the library
edit cys////N
editor.attach_amino_acid("pk1","ace")
# now restore missing hydrogens (note that the names are off...)
h_add
Warren DeLano
Superposition of two molecules
Using pair_fit requires that you specify a set of paired atoms in each structure. Fortunately, you no longer have to specify each pair separately, so long as the ordering is the same in each selection (almost always true).
pair_fit ( trna10 and resid 10:15 and name P ), ( ref4 and resid 10:15 and
name P )
Another example:
pair_fit prot1///11-26/CA, prot2///34-49/CA
would superimpose prot1 on prot2 using C-alphas from residues 11-26 in prot1 and 34-49 in prot2.
Movies with PyMOL
Encoding video files
Assuming you have created a lot of .png files and would like to encode a .mpeg, .avi or other video format, a number of solutions are known:
·mencoder "mf://*.png" -mf type=png:fps=18 -ovc lavc -o output.avi
·
·Another good program for converting images into movies of different formats isVideoMach : http://gromada.com/VideoMach.html
·
·
·
·TMPGEnc from http://www.tmpgenc.net/ is very fast, easy to use, and produces very nice ouput (MPEG-2). Unfortunately, it does not handle images larger than 720 x 576 pixels.
·
·
·
·The latest Adobe Premiere recipe:
· Microsoft's MPEG4 V2, 960x720 @ 30 fps, which PowerPoint automatically
·treats as full-screen (due it's wacky metrics).
·
·Using this codec, a recent 24-second movie consumed only 4.5 MB of space,
·but looks much better than a 640x480 Cinepak-based movie with a file size of
·around ~40 MB. It definitely pays to use the latest technology
·
·
·
·A freeware jiffy to convert png files to an animation isimgcon,
·which proved to be very useful:http://www.fmrib.ox.ac.uk/~yongyue/imgcondl.html
·
·
Advanced PyMOL features
Meaning of the get_view output
Of the 18 numbers in the output array,
0-8 is the 3x3 rotation matrix,
9-11 is the camera location,
12-14 is the origin of rotation,
15-16 are the clipping distances,
and 17 is the orthoscopic flag.
Robert Campbell, Paolo Martel and Warren
Altering atom coordinates
Example:
alter_state 1,(pdb1cse),x=x-10.0
The latter section can contain formulae involving at least the xyz coordinates, lots of constants and the (+-*/) operators.
Translate or rotate individual objects
There is a "translate" function similar to "rotate", the docs for these don't exist yet, because the implementation isn't finished. However, feel free to use them in the following forms:
translate vector,object-name,state
vector needs to be something like [x,y,z]
translate [1,0,0],pept
rotate axis,angle,object-name,state
axis can be either the letter x,y,z or a 3D vector [x,y,z]
rotate x,90,pept
rotate [1,1,1],10,pept
Warren DeLano
Moving one segment relative to the rest
This means moving two parts of one object into different directions. The easiest way to do this is to split the objects and then use the rotate command.
EXAMPLE: split.pml
Warren DeLano
What is in a selection?
Atom selections aren't directly exposed to Python, but you can have PyMOL build a Python list containing whatever information you need:
Using PyMOL commands:
list=[]
iterate (name ca),list.append((resi,resn))
print list
[('ASP', '1'), ('CYS', '2'), ('ALA', '3'), ('TRP', '4'), ('HIS', '5'), ('LEU',
'6'), ('GLY', '7'), ('GLU', '8'), ('LEU', '9'), ('VAL', '10'), ('TRP', '11'),
('CYS', '12'), ('THR', '13')]
or using a Python script (in PyMOL):
from pymol import cmd,stored
stored.list=[]
cmd.iterate("(name ca)","stored.list.append((resi,resn))")
print stored.list
[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
LEU'), ('7', 'GLY'), ('8', 'GLU'), ('9', 'LEU'), ('10', 'VAL'), ('11', 'TRP'),
('12', 'CYS'), ('13', 'THR')]
Warren DeLano
How does the Density Wizard work?
The answer:
· Load a map
· Load a model structure
· Activate the Density Wizard
· Control-middle click to pick any atom in the model to get the map drawn about it. Each of the blue rows in the Wizard is a pop-up menu. You can select multiple or different maps to be displayed at different levels as you traverse the model.
Warren DeLano
What the heck is molecular sculpting?
Molecular sculpting works like a real-time energy minimizer, except that it isn't minimizing the energy. Instead, its just trying to return local atomic geometries (bonds, angles, chirality, planarity) to the configuration the molecules possess when they were first loaded into PyMOL.
To actually use this feature:
You can adjust the radius and cushion using the blue pop-up menus.
Right now I'm not sure the sculpting feature is more than entertainment, but my expectation is that it will become part of PyMOL's crystallographic model building system in the future.
Warren DeLano
Align proteins with CA fit
If the proteins have significant homology, then you can use the align command:
align prot1////ca,prot2
which will perform a sequence alignment of prot1 against prot2, and then an optimizing fit using the CA positions. I'm not sure if the help text for align got into 0.82, but the next version will definitely have it.
Python scripting
Launching Python programs
1. Running a Python script from PyMOL, usually the command:
run script.py
Is enough. Of course, the file script.py needs to be in the working directory.
You can also launch Python scripts when starting PyMOL. Asynchronous means, that a new Python thread is started:
pymol example.py # synchronous, in PyMOL module
pymol -r example.py # synchronous in __main__ module
pymol -l example.py # asychronous in a new module
You can also launch python programs from within PyMOL with the commands:
run example.py # synchronous in pymol module
run example.py,main # synchronous in __main__ module
spawn example.py # asychronous in a new module
spawn example.py,global # asychronous in the PyMOL module
spawn example.py,main # asychronous in the __main__ module
2. Running PyMOL from a Python script requires two commands:
import pymol
pymol.finish_launching()
Using the PyMOL commandline
Are you aware that the PyMOL command line is also a Python command line? You can just use PyMOL interactively in that fashion.
PyMOL>print 1+1
2
PyMOL>from random import random
PyMOL>print random()
0.739460642143
The only major difference is that the default namespace for PyMOL is "pymol" not "__main__"
PyMOL>print __name__
pymol
Warren DeLano
What is in a selection?
Atom selections aren't directly exposed to Python, but you can have PyMOL build a Python list containing whatever information you need:
Using PyMOL commands:
list=[]
iterate (name ca),list.append((resi,resn))
print list
[('ASP', '1'), ('CYS', '2'), ('ALA', '3'), ('TRP', '4'), ('HIS', '5'), ('LEU',
'6'), ('GLY', '7'), ('GLU', '8'), ('LEU', '9'), ('VAL', '10'), ('TRP', '11'),
('CYS', '12'), ('THR', '13')]
or using a Python script (in PyMOL):
from pymol import cmd,stored
stored.list=[]
cmd.iterate("(name ca)","stored.list.append((resi,resn))")
print stored.list
[('1', 'ASP'), ('2', 'CYS'), ('3', 'ALA'), ('4', 'TRP'), ('5', 'HIS'), ('6', '
LEU'), ('7', 'GLY'), ('8', 'GLU'), ('9', 'LEU'), ('10', 'VAL'), ('11', 'TRP'),
('12', 'CYS'), ('13', 'THR')]
Warren DeLano
Does a selection exist?
The function below will return true if the selection is defined.
from pymol import cmd
from types import *
def sele_exists(sele):
sess = cmd.get_session()
for i in sess["names"]:
if type(i) is ListType:
if sele==i[0]:
return 1
return 0
Igor Pechersky
Get coordinates from Python
The actual C-langauge arrays aren't exposed, but there are at least three different ways you can modify coordinates from within Python:
· You can get a python object which contains the molecular information, modify the coordinates in that object, load the modified molecule into PyMOL, update the modified coordinates to the original model, and then delete the modified object. (Example in a python script)
· Another approach is the "alter_state" function, which can perform the same transformation in a single PyMOL command statement:
alter_state 1,pept,(x,y)=(-y,x)
Likewise sub-selections can be transformed as well:
alter_state 1,(pept and name ca),(x,y,z)=(x+5,y,z)
· A third approach is to use alter_state with the global "stored" object:Example in a Python script) Approaches 2 gives the best performance, approach 3 gives more flexibility, and approach 1 gives you a reusable and fully modifiable Python object.
Warren DeLano
Create objects from PDB strings
I thought I'd post this example, just in case anyone else cares about this:
delete all
cmd.read_pdbstr("""HEADER CREATED BY CONVERTPROSPECT 27-JAN-02 2tnf \
REMARK 1 \
ATOM 1 N PRO A 9 1.895 67.213 -38.182 1.00 0.00 N \
ATOM 2 CA PRO A 9 1.703 68.680 -38.402 1.00 0.00 C \
....
ATOM 1153 C GLY A 157 6.927 59.108 -38.901 1.00 6.00 C \
ATOM 1154 O GLY A 157 6.700 59.292 -37.676 1.00 6.00 O \
TER 1155 GLY A 157 \
MASTER \
END \
""","2tnfa")
hide all
show cartoon
color grey
....
Reece Hart
Measure distances from Python
Use Python (and the run command with .py files).
from pymol import cmd
f=open('dist.txt','w')
dst=cmd.distance('tmp','mol1///25/ha','mol1///26/ha')
f.write("%8.3f\n"%dst)
f.close()
You could measure the whole protein this way by putting a loop around the distance command:
from pymol import cmd
f=open('dist.txt','w')
atom = cmd.get_model("mol1////ha").atom
for i in range(len(atom)-1):
sele1 = 'mol1///%s/HA'%atom[i].resi
sele2 = 'mol1///%s/HA'%atom[i+1].resi
dst=cmd.distance('tmp',sele1,sele2)
f.write("%14s %14s %8.3f\n"%(sele1,sele2,dst))
f.close()
The output "dist.txt" would then look like:
mol1///4/HA mol1///5/HA 4.748
mol1///5/HA mol1///6/HA 4.828
mol1///6/HA mol1///7/HA 4.861
mol1///7/HA mol1///8/HA 4.784
mol1///8/HA mol1///9/HA 4.936
mol1///9/HA mol1///10/HA 4.833
mol1///10/HA mol1///11/HA 4.933
mol1///11/HA mol1///12/HA 4.813
Warren DeLano
Coloring all objects differently
Q: Is there a simple way to colour each object currently loaded, with a different colour (in the same way that you can colour each chain in a molecule differently)? This would be really useful in visualising a set of superposed structures.
A: There is a script color_obj.py that does the job.
The script is also available at
http://www.ebi.ac.uk/~gareth/misc
USAGE
color_obj(rainbow=0)
This function colours each object currently in the PyMOL heirarchy
with a different colour. Colours used are either the 22 named
colours used by PyMOL (in which case the 23rd object, if it exists,
gets the same colour as the first), or are the colours of the rainbow
Gareth Stockwell
List the color of atoms
To retrieve the color for a residue as identified in an expression, you can either iterate over a selection from the PyMOL command line
iterate all, print color
Alternatively, this can be done from aPython script.
import pymol
pymol.color_list = []
cmd.iterate('all', 'pymol.color_list.append(color)')
print pymol.color_list
Warren DeLano
List secondary structures
Secondary structures (both predefined and those calculated with the 'dss' command) can be exported as a long string ('HHHHLLLLSSS') with the following script:
import pymol
pymol.stored_ss = []
cmd.iterate('all', 'pymol.stored_ss.append(string.ljust(ss,1))')
print string.join(pymol.stored_ss)
Warren DeLano
Process key events from shell
The following scripts turns the view 30 deg around the y-axis, each time you press the enter key in the python shell (the original shell you started pymol from), just as an example:
#use "spawn spawn_demo.py, local" to invoke this python script from
within pymol
wait=""
i=0
while i < 12 and wait!="x":
cmd.turn("y", 30)
print "Press enter key to continue or x + enter to terminate"
wait=raw_input()
i=i+1
print "Done"
Markus Meier
Alter key bindings
It's not GUI, but you could simply bind a function key such as F1 to a command:
cmd.set_key('F1',lambda :cmd.show('sticks'))
Warren DeLano
Viewing direction vectors
Create a python script (I call it axes.py):
# axes.py
from pymol.cgo import *
from pymol import cmd
from pymol.vfont import plain
# create the axes object, draw axes with cylinders coloured red, green,
#blue for X, Y and Z
obj = [
CYLINDER, 0., 0., 0., 10., 0., 0., 0.2, 1.0, 1.0, 1.0, 1.0, 0.0, 0.,
CYLINDER, 0., 0., 0., 0., 10., 0., 0.2, 1.0, 1.0, 1.0, 0., 1.0, 0.,
CYLINDER, 0., 0., 0., 0., 0., 10., 0.2, 1.0, 1.0, 1.0, 0., 0.0, 1.0,
]
# add labels to axes object (requires pymol version 0.8 or greater, I
# believe
cyl_text(obj,plain,[-5.,-5.,-1],'Origin',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[10.,0.,0.],'X',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[0.,10.,0.],'Y',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
cyl_text(obj,plain,[0.,0.,10.],'Z',0.20,axes=[[3,0,0],[0,3,0],[0,0,3]])
# then we load it into PyMOL
cmd.load_cgo(obj,'axes')
Then you just need to do "run axes.py" from the pymol command line.
You can modify the "3" in the above description of the text labels to change the size of the labels. If you are running a version of pymol older the 0.8, then you cannot add the text (that's why I included colour coding of the axes). You can also use just lines instead of cylinders if you wish:
obj = [
BEGIN, LINES,
COLOR, 1.0, 0.0, 0.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 10.0, 0.0, 0.0,
COLOR, 0.0, 1.0, 0.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 0.0, 10.0, 0.0,
COLOR, 0.0, 0.0, 1.0,
VERTEX, 0.0, 0.0, 0.0, VERTEX, 0.0, 0.0, 10.0,
END,
]
would work as well to define the axes object.
Ray-traceable labels
You can use the cgo text (line or cylinder versions) as I mentioned in my reply about drawing the xyz axes, but be warned that the labels rotate with your molecule, so getting them oriented perpendicular to the view may be a pain (unless there is something I've missed).
Warren's example from a previous reply of his (cgotext.py):
# draw text using cgo
from pymol import cmd
from pymol.cgo import *
from pymol.vfont import plain
cgo = []
axes = [[2.0,0.0,0.0],[0.0,2.0,0.0],[0.0,0.0,2.0]]
pos = [0.0,0.0,0.0]
wire_text(cgo,plain,pos,'Hello World',axes)
pos = [0.0,-3.0,0.0]
cyl_text(cgo,plain,pos,'Hello Universe',0.10,axes=axes)
cmd.set("cgo_line_radius",0.03)
cmd.load_cgo(cgo,'txt')
cmd.zoom("all",2.0)
Robert Campbell
CGO label orientation
You could use the cmd.rotate andcmd.translate to position the labels, but it is likely to be somewhat painful. If I'm not mistaken, the rotation will always be about and axis through the origin and so you may need to translate the label into the correct position.
Thus if you have your label in an object called 'text', you could do,
cmd.rotate(axis='x',angle=20.,object='text')
and repeat this with different angles, until you get the orientation correct. Then use:
cmd.translate(vector='[1.,2.,3.]',object='text')
(using the appropriate vector, of course!) to position the label.
Not ideal, but if it is sufficiently important, it can be done!
Robert Campbell
3D marks on atoms
Here's a script graph.py which can be used to put marks on the positions of every atom in a selection. There are several types of marks included now, e.g. cube, rhombic dodecahedron, tetrahedron, plus and star. Using a matrix operator these can be extended a bit, to 2D counterparts for example, or to elongated or rotated shapes. I should still include some documentation but in brief the usage is as follows:
graph selection = '(all)', shape = 'plus' | 'sphere' | 'star' | 'tetrahedron' | 'dodecahedron', size = 1, r = 0.10, rgb1 = [1,0,0], rgb2 = [0,0,1], mtx = [[1,0,0],[0,1,0],[0,0,1]], name = "graph"
Selection should be obvious, as is shape. Size is a relative indicator for the size, though at present I haven't fixed things such that a size 1 tetrahedron matches a size 1 dodecahedron. r is the radius of the lines. rgb1 and rgb2 are the start and end color for each line. mtx is the matrix operator, which works on the original shape centered around the origin (before translation to the point of the atom from the selection).
Tserk Wassenaar
Save and load objects
There is a convenient format: ".pkl", that works like PDB, but is a Pickled copy of the PyMOL Model Class. The main advantage this has over .pdb is that it saves and restores extra properties such as secondary structure code, atom types, van der waals radii, formal and partial charges, etc.
load myprot.pdb
dss
show cartoon
alter 100-110/, ss='H'
alter 65-67,ss='L'
save myprot.pkl
... quit program, complete your PhD, take a vacation, and come back...
load myprot.pkl
show cartoon
will work.
".pkl" has the additional advantage of being a simple molecular object useful in straight Python, outside of PyMOL. All you need to do is have a copy of PyMOL's "chempy" module available in your PYTHONPATH
from chempy import io
model = io.pkl.fromFile("myprot.pkl")
for atom in model.atom:
print atom.name
Warren DeLano
Building ChemPy models
This is a snap. Just "run" the following Python program from within PyMOL.
from chempy.models import Indexed
from chempy import Bond, Atom
from whrandom import random
from pymol import cmd
model = Indexed()
# create some atoms
for a in range(1,11):
at = Atom()
at.name = "X%02d"%a
at.coord = [random()*5,random()*5,random()*5]
model.atom.append(at)
# now create some bonds
for a in range(1,10):
bd = Bond()
bd.index = [a-1,a] # zero-based indices!
model.bond.append(bd)
# now load and label
cmd.load_model(model,"example")
cmd.label("example","name")
本文引用地址:http://blog.sciencenet.cn/blog-355217-279196.html