Difference between revisions of "PDB Web Services Script"

From PyMOLWiki
Jump to navigation Jump to search
(New page: == Overview == A short snippet of code utilizing the new PDB Web Services. == The Code == <source lang="python"> import pymol from pymol import stored, cmd import SOAPpy import string # ...)
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
 
A short snippet of code utilizing the new PDB Web Services.
 
A short snippet of code utilizing the new PDB Web Services.
 +
 +
Notes:
 +
# See [http://www.rcsb.org/robohelp/webservices/summary.htm PDB Web Services]
 +
# You need [http://pywebsvcs.sourceforge.net/ SOAP for Python] installed
 +
# The sequence of a chain fetched from the PDB does not always equal the sequence of a chain fetched from the PDB Web Services.  I believe the PDB Web Services has the complete biological chain, not just what's in the structure.
 +
# The offset is a hack; it uses a trick in PyMOL and may not be robust at all.  Use at your own caution.
  
 
== The Code ==
 
== The Code ==
Line 7: Line 13:
 
from pymol import stored, cmd
 
from pymol import stored, cmd
 
import SOAPpy
 
import SOAPpy
import string
 
  
 
# define a mapping from three letters to one
 
# define a mapping from three letters to one
Line 24: Line 29:
  
 
# open up the PDB web services and make a connection
 
# open up the PDB web services and make a connection
stored.pyMOLSeq = string.join( stored.pyMOLSeq, '' )
+
stored.pyMOLSeq = ''.join( stored.pyMOLSeq )
 
server = SOAPpy.SOAPProxy("http://www.pdb.org/pdb/services/pdbws")
 
server = SOAPpy.SOAPProxy("http://www.pdb.org/pdb/services/pdbws")
  
 
# fetch the secondary structure assignment from the PDB &
 
# fetch the secondary structure assignment from the PDB &
 
# split it up into an array of characters
 
# split it up into an array of characters
stored.ss = [ x for x in server.getKabschSander("1foo", "A") ]
+
stored.ss = list( server.getKabschSander("1foo", "A") )
  
 
# get the sequence
 
# get the sequence
 
pdbSeq = server.getSequenceForStructureAndChain("1foo", "A")
 
pdbSeq = server.getSequenceForStructureAndChain("1foo", "A")
offset = string.find( pdbSeq, stored.pyMOLSeq )
+
# danger: hackishly foolish, but worked for 1foo.
 +
offset = pdbSeq.find( stored.pyMOLSeq )
  
 
# make the assignment in PyMOL
 
# make the assignment in PyMOL
 
cmd.alter( "1foo and c. A and n. CA and i. " + str(offset) + "-", "ss=stored.ss.pop(0)" )
 
cmd.alter( "1foo and c. A and n. CA and i. " + str(offset) + "-", "ss=stored.ss.pop(0)" )
 +
 +
# show as cartoons
 +
cmd.as("cartoon")
 
</source>
 
</source>
 +
 +
[[Category:Script_Library]]
 +
[[Category:UI_Scripts]]

Latest revision as of 06:22, 26 January 2010

Overview

A short snippet of code utilizing the new PDB Web Services.

Notes:

  1. See PDB Web Services
  2. You need SOAP for Python installed
  3. The sequence of a chain fetched from the PDB does not always equal the sequence of a chain fetched from the PDB Web Services. I believe the PDB Web Services has the complete biological chain, not just what's in the structure.
  4. The offset is a hack; it uses a trick in PyMOL and may not be robust at all. Use at your own caution.

The Code

import pymol
from pymol import stored, cmd
import SOAPpy

# define a mapping from three letters to one
# Thanks to whomever posted this on the PyMOLWiki:
#   http://www.pymolwiki.org/index.php/Label
one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \
'ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y',    \
'ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A',    \
'GLY':'G', 'PRO':'P', 'CYS':'C'}

# fetch some molecule; yes, 1foo exists in the PDB
cmd.fetch("1foo", async=0)
# get the sequence from PyMOL
stored.pyMOLSeq = []
cmd.iterate( "1foo and c. A and n. CA" , "stored.pyMOLSeq.append( one_letter[resn] )" )

# open up the PDB web services and make a connection
stored.pyMOLSeq = ''.join( stored.pyMOLSeq )
server = SOAPpy.SOAPProxy("http://www.pdb.org/pdb/services/pdbws")

# fetch the secondary structure assignment from the PDB &
# split it up into an array of characters
stored.ss = list( server.getKabschSander("1foo", "A") )

# get the sequence
pdbSeq = server.getSequenceForStructureAndChain("1foo", "A")
# danger: hackishly foolish, but worked for 1foo.
offset = pdbSeq.find( stored.pyMOLSeq )

# make the assignment in PyMOL
cmd.alter( "1foo and c. A and n. CA and i. " + str(offset) + "-", "ss=stored.ss.pop(0)" )

# show as cartoons
cmd.as("cartoon")