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