Zero residues

From PyMOLWiki
Revision as of 13:10, 12 May 2009 by Warren (talk | contribs) (→‎CODE)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


This script will renumber all the residues such that the first one is numbered 0. This is often helpful when dealing with alignments.

Ordering from Sequence End

If you want to change numbering based off the last residue's number in the sequence, just replace first in the code with last.


zero_residues 1AFK
zero_residues *

# make the first residue's number, 30.
zero_residues 1AFK, 30


Copy the source code below, to "" and then simply run the file. The command, "zero_residues" will now be defined and can be used as in the examples above.


import pymol

def zero_residues(sel1,offset=0):
        PURPOSE: renumbers the residues so that the first one is zero, or offset           .
        USAGE: zero_residues protName    # first residue is 0
        USAGE: zero_residues protName, 5 # first residue is 5
        EXAMPLE: zero_residues *
        offset = int(offset)

        # variable to store the offset
        stored.first = None
        # get the names of the proteins in the selection
        names = cmd.get_names(selection=sel1)

        # for each name shown
        for p in names:
                # get this offset
                cmd.iterate("first %s and polymer and n. CA" % p,"stored.first=resi")
                # don't waste time if we don't have to
                if ( stored.first == offset ):
                # reassign the residue numbers
                cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % str(int(stored.first)-offset))
                # update pymol

# let pymol know about the function
cmd.extend("zero_residues", zero_residues)