[BioPython] PDBparser and NMR pdb file

K. Arun karbak at gmail.com
Tue Jan 4 15:32:10 EST 2005


On Thu, 16 Dec 2004 18:41:03 +0100, Edoardo Saccenti
<saccenti at cerm.unifi.it> wrote:

> does anyboy know if is possible to handle PDB files
> of structures obteined via NMR spectrometry?
> E.G. obtein models of various conformers in a file?

I wrote some quick and dirty code to do this a while ago - I'm sure
the Bio.PDB module code can be used more effectively than it is below.

-arun

## --
#!/usr/bin/env python

"""
extract-model.py :
Script to spit out arbitrary models from a PDB NMR structure.
Note that only the MODEL, ATOM, TER, and ENDMDL lines are
retained. All header detail is stripped. The lines are printed to
stdout, and will need to be redirected to an appropriate file.

Usage:
extract-model.py PDB-ID PDB-filename model-no-to-extract

K. Arun <karbak at cmu.edu>


"""

import sys, string, re, os
from Bio.PDB.PDBParser import PDBParser

pdb_id = sys.argv[1]
pdb_filename = sys.argv[2]
model_reqd = sys.argv[3]

model_pat = re.compile('^MODEL\s+' + model_reqd + '\s+')
endmdl_pat = re.compile('^ENDMDL')

p = PDBParser( PERMISSIVE = 1 )

structure = p.get_structure(pdb_id, pdb_filename)
no_of_models = len(structure.get_list())

if int(model_reqd) > (no_of_models - 1):
    print "This stucture only has", (no_of_models - 1), "models.",
    print "You've asked for model", str(model_reqd) + "."
    sys.exit(-1)
else:
    try:
        f = open(pdb_filename, 'r')
    except IOError:
        print "Can't open file."
        sys.exit(-1)

    in_model = 0
    notdone = 1
    
    while notdone:
        l = f.readline()
        
        if model_pat.match(l):
            in_model = 1

        while in_model:
            print l.rstrip()
            l = f.readline()
            if endmdl_pat.match(l):
                print l.rstrip()
                in_model = 0
                notdone = 0

##--


More information about the BioPython mailing list