Crystallography‎ > ‎Molecular graphics‎ > ‎Pymol‎ > ‎


Selecting water molecules nearby a chain or residue

select active_water, ( (resi XX and name YY and chain Z) around 3.5) and (resn HOH)

The above command select any water molecules that is/are around 3.5A of the YY atom of resi XX in chain Z

Selecting water molecules mediating H-bonds at the interface between two protein chains

First select the water molecules that are within a certain distance (3.5Å?) from the two chains independently as follows:

select interface1, [residues...]
select waters_at_interface1, interface1 around XX and resn HOH
save file1.pdb, waters_at_interface1

select interface2, [residues...]
select waters_at_interface2, interface2 around XX and resn HOH
save file2.pdb, waters_at_interface2

Then paste the selections (file1.pdb and file2.pdb) in a file called myselections.pml , and create a file called intersect containing the following:


# definition of the files that will be compared

# removal of previous comparison file from current dir
rm $common

while read line
  # adjusts the line in file1 to avoid different atom identifier
  grepme=$(awk -F 'HOH' '{print $2}')
  # searches for the line of $file1 in $file2 and exports the results to $common
  grep "$grepme" $file2 >> $common
done < "$file1"

Now run a bash script like this:

pymol -c myselections.pml

The output file common.pdb will contain those water molecules that contact (within the XX distance chosen above) both chains at the same time.
Really a neat script, full credit to F.Forneris (personal communication).

Selecting secondary structure

select helix, (ss h)
select sheet, (ss s)
select loop, (ss l+'')

Single-word selectors


Simplest selection-expressions are single-word selectors. These selectors do not take identifiers; they are complete by themselves. Many single-word selectors have short forms to save on typing. Some short forms must be followed by a period and a space, in order to delimit the word. Short forms and long forms have the same effect.

 description single word short form
All atoms currently loadedall
No atoms (empty selection)    nonenone 
All hydrogen atoms currently loadedhydro h. 
All atoms loaded from PDB HETATM recordshetatm het 
All atoms in enabled objects
with at least one visible representation

All atoms with defined coordinates in the current state (used in creating movies)



PyMOL> color blue, all
PyMOL> color blue, *
PyMOL> hide hydro Representations of all hydrogen atoms are hidden
PyMOL> hide h.
PyMOL> show spheres, hetatom All the atoms defined as HETATOMS
PyMOL> show spheres, het All the atoms defined as HET are represented as spheres

Other selection modes

- To select all residues of a certain type automatically, like all arginines or all lysines + arginines in a chain:

select all_arg_lys, resn arn+lys

select resnam arg
select chain A and (resnam lys or resnam arg)

- To select (by residue) all the atoms around 10 angstroms from a certain atom (let's say resi 120):

select near_ten, resi 120 around 10

- To select a specific residue number on a specific chain ID:

select xxxA, resi xxx and chain A

- To select residue from different chains:

select (resi 367 and chain c)


(resi 366-379 and chain a)

- To select a particular atom from a ligand use:

select [ligand name and/or chain] and n. [atom name]


- If the ligand is chain c and you want to select the atom named C21 in the pdb file:

select c. c & n. c21

or the ligand has a residue name like "BME" or something similar:

select r. bme & n. c21

- To select all c_alpha of all Cys residues:

select c_alphas, cys/ca

- To select all histidines that lie within 6 angstroms from each other, you need to iterate through the histidines:

# select C-alpha atoms in all HIS residues as our query set
select c_alphas, his/ca
# create a selection to hold the resulting atom set
select result, none
# iterate through each query atom (each expanded to a residue) 
# selecting all nearby HIS residues as we go into the result
while cmd.pop("tmp", "c_alphas"): \"result", "result or byres (his/ near_to 6 of byres tmp)")
# then display the resulting selection
enable result

Write out selection

Let's say we select (by residue) all the atoms around 10 angstroms from a certain atom (let's say resi 120)
select near_ten, resi 120 around 10
And now we would like to write the residue id's of this selection to an external file.
We need to "iterate" by using:
ndx.write("[ MyIndex ]\n")
iterate selection, ndx.write("%d\n" % ID)