Difference between revisions of "Zero residues"

From PyMOLWiki
Jump to navigation Jump to search
(New page: == OVERVIEW == This script will renumber all the residues such that the first one is numbered 0. This is often helpful when dealing with alignments. == EXAMPLE == <source lang="python"> zero_residues ...)
 
m
Line 15: Line 15:
 
import pymol
 
import pymol
  
def zero_residues(sel1):
+
def zero_residues(sel1,offset=0):
"""
+
        """
PURPOSE: renumbers the residues so that the first one is zero.
+
        PURPOSE: renumbers the residues so that the first one is zero, or offset          .
USAGE: zero_residues protName
+
        USAGE: zero_residues protName   # first residue is 0
EXAMPLE: zero_residues *
+
        USAGE: zero_residues protName, 5 # first residue is 5
EXAMPLE: zero_residues 1ESR
+
        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(sel1)
 
  
# for each name shown
+
        # variable to store the offset
for p in names:
+
        stored.first = None
# get this offset
+
        # get the names of the proteins in the selection
cmd.iterate("first %s and polymer and n. CA" % p,"stored.first=resi")
+
        names = cmd.get_names(sel1)
# don't waste time if we don't have to
+
 
if ( stored.first == 0 ):
+
        # for each name shown
continue;
+
        for p in names:
# reassign the residue numbers
+
                # get this offset
cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % stored.first)
+
                cmd.iterate("first %s and polymer and n. CA" % p,"stored.first=resi")
# update pymol
+
                # don't waste time if we don't have to
cmd.sort()
+
                if ( stored.first == offset ):
 +
                        continue;
 +
                # reassign the residue numbers
 +
                cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % str(int(stored.first)-offset))
 +
                # update pymol
 +
                cmd.sort()
  
 
# let pymol know about the function
 
# let pymol know about the function

Revision as of 14:33, 7 May 2007

OVERVIEW

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

EXAMPLE

zero_residues 1AFK
zero_residues *

INSTALL

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

CODE

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(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 ):
                        continue;
                # reassign the residue numbers
                cmd.alter("%s" % p, "resi=str(int(resi)-%s)" % str(int(stored.first)-offset))
                # update pymol
                cmd.sort()

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