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