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