Jump to content

WriteSS

From PyMOL Wiki

Overview

[edit]

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

[edit]
  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

[edit]
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

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

output for 1D7P.pdb:

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