1 ''' PDBAnalyzer script by destine, 2005-05-25
   2 '''
   3 import unittest, os, glob
   4 from cStringIO import StringIO
   5 from Bio.PDB import *
   6 
   7 class PDBAnalyzer:
   8     def __init__(self, name, input_file):
   9         # first make a PDB parser object
  10         self.pdb_parser = PDBParser(PERMISSIVE=1)
  11 
  12         # get the structure, call it name
  13         self.structure = self.pdb_parser.get_structure(name, input_file)
  14 
  15     def getChains(self, model_index):
  16         return self.structure.get_list()[model_index]
  17 
  18     def getChain(self, model_index, chain_index):
  19         chains = self.getChains( model_index )
  20         return chains.get_list()[chain_index]
  21 
  22     def getAtomsCoordInChain(self, model_index, chain_index):
  23         chain = self.getChain( model_index, chain_index)
  24         coords = []
  25         for residue in chain.get_list():
  26             #print residue.get_list()
  27             for atom in residue.get_list():
  28                 if atom.name == 'CA':
  29                     coords.append(atom.coord)
  30         return coords
  31 
  32 class TestPDBAnalyzer(unittest.TestCase):
  33     def setUp(self):
  34         input_file = '1C3W.pdb'
  35         self.pa = PDBAnalyzer("test",input_file)
  36 
  37     def testPolypeptidesUsingC2N(self):
  38         ppb = PPBuilder()
  39         ppp = ppb.build_peptides(self.pa.structure, 1)
  40         self.assertEquals(2,len(ppp))
  41 
  42     def testAtomsCoordInChain(self):
  43         coords = self.pa.getAtomsCoordInChain(0,0)
  44         self.assertEquals(222, len(coords))
  45 
  46 if __name__ == '__main__':
  47     unittest.main()
web biohackers.net