Package Bio :: Package PDB :: Module Chain
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.Chain

  1  # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package.   
  5   
  6  # Python stuff 
  7  from types import IntType 
  8   
  9  # My Stuff 
 10  from Entity import Entity 
 11   
 12  __doc__="Chain class, used in Structure objects." 
 13   
 14   
15 -class Chain(Entity):
16 - def __init__(self, id):
17 self.level="C" 18 Entity.__init__(self, id)
19 20 # Private methods 21
22 - def _sort(self, r1, r2):
23 """Sort function for residues in a chain 24 25 Residues are first sorted according to their hetatm records. 26 Protein and nucleic acid residues first, hetatm residues next, 27 and waters last. Within each group, the residues are sorted according 28 to their resseq's (sequence identifiers). Finally, residues with the 29 same resseq's are sorted according to icode. 30 31 Arguments: 32 o r1, r2 - Residue objects 33 """ 34 hetflag1, resseq1, icode1=r1.id 35 hetflag2, resseq2, icode2=r2.id 36 if hetflag1!=hetflag2: 37 return cmp(hetflag1[0], hetflag2[0]) 38 elif resseq1!=resseq2: 39 return cmp(resseq1, resseq2) 40 return cmp(icode1, icode2)
41
42 - def _translate_id(self, id):
43 """ 44 A residue id is normally a tuple (hetero flag, sequence identifier, 45 insertion code). Since for most residues the hetero flag and the 46 insertion code are blank (i.e. " "), you can just use the sequence 47 identifier to index a residue in a chain. The _translate_id method 48 translates the sequence identifier to the (" ", sequence identifier, 49 " ") tuple. 50 51 Arguments: 52 o id - int, residue resseq 53 """ 54 if type(id)==IntType: 55 id=(' ', id, ' ') 56 return id
57 58 # Special methods 59
60 - def __getitem__(self, id):
61 """Return the residue with given id. 62 63 The id of a residue is (hetero flag, sequence identifier, insertion code). 64 If id is an int, it is translated to (" ", id, " ") by the _translate_id 65 method. 66 67 Arguments: 68 o id - (string, int, string) or int 69 """ 70 id=self._translate_id(id) 71 return Entity.__getitem__(self, id)
72
73 - def __delitem__(self, id):
74 """ 75 Arguments: 76 o id - (string, int, string) or int 77 """ 78 id=self._translate_id(id) 79 return Entity.__delitem__(self, id)
80
81 - def __repr__(self):
82 return "<Chain id=%s>" % self.get_id()
83 84 # Public methods 85
86 - def get_unpacked_list(self):
87 """Return a list of undisordered residues. 88 89 Some Residue objects hide several disordered residues 90 (DisorderedResidue objects). This method unpacks them, 91 ie. it returns a list of simple Residue objects. 92 """ 93 unpacked_list=[] 94 for residue in self.get_list(): 95 if residue.is_disordered()==2: 96 for dresidue in residue.disordered_get_list(): 97 unpacked_list.append(dresidue) 98 else: 99 unpacked_list.append(residue) 100 return unpacked_list
101
102 - def has_id(self, id):
103 """Return 1 if a residue with given id is present. 104 105 The id of a residue is (hetero flag, sequence identifier, insertion code). 106 If id is an int, it is translated to (" ", id, " ") by the _translate_id 107 method. 108 109 Arguments: 110 o id - (string, int, string) or int 111 """ 112 id=self._translate_id(id) 113 return Entity.has_id(self, id)
114 115 116 # Public 117
118 - def get_atoms(self):
119 for r in self: 120 for a in r: 121 yield a
122