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