Difference between revisions of "WriteSS"

From PyMOLWiki
Jump to: navigation, search
m
 
Line 11: Line 11:
 
== The Code ==
 
== The Code ==
 
<source lang="python">
 
<source lang="python">
import os;
+
import os
import os.path;
+
import os.path
import glob;
+
import glob
import string;
 
  
 
from pymol import cmd
 
from pymol import cmd
Line 23: Line 22:
  
 
for file in files:
 
for file in files:
         pdbName = string.split(os.path.basename(file), ".")[0]
+
         pdbName = os.path.basename(file).split(".")[0]
 
         cmd.load(file, pdbName)
 
         cmd.load(file, pdbName)
 
         outFile = open(pdbName + '.ss', 'wb')
 
         outFile = open(pdbName + '.ss', 'wb')

Latest revision as of 03:14, 27 November 2009

Overview

This script will write the secondary structural elements for each PDB file in some specified directory, for each alpha carbon in the protein, to an output text file. Residues without secondary structure definition will get a "." in the string.

This is untested code and has little chance of working for anyone but me. Although, it does work for me.

Instructions

  1. Copy the code to your machine
  2. Find FIXME in the code below and change "files" to either a glob like the one already there (for a whole directory) or a list with one element (for just one file).
  3. change the output filename. By default it's PDBCODE.ss.

The Code

import os
import os.path
import glob

from pymol import cmd
from pymol import stored
from pymol import selector

files = glob.glob("/tmp/thy_model/*.pdb")

for file in files:
        pdbName = os.path.basename(file).split(".")[0]
        cmd.load(file, pdbName)
        outFile = open(pdbName + '.ss', 'wb')
        stored.ss = ""
        cmd.iterate( '(n. CA)', 'stored.ss = stored.ss + ("%1s"%ss)')
        for c in stored.ss:
                if c  == " ":
                        outFile.write('.')
                else:
                        outFile.write(c)
        cmd.delete(pdbName)
        outFile.close()

Example

python ss.pym  # my directory has 1d7p.pdb in it

output for 1D7P.pdb:

...............HHH.......SSS..SSSHHHHH..................................................................SS..SS..................................................