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 __delitem__(self, id):
70 """ 71 Arguments: 72 o id - (string, int, string) or int 73 """ 74 id=self._translate_id(id) 75 return Entity.__delitem__(self, id)
76
77 - def __repr__(self):
78 return "<Chain id=%s>" % self.get_id()
79 80 # Public methods 81
82 - def get_unpacked_list(self):
83 """Return a list of undisordered residues. 84 85 Some Residue objects hide several disordered residues 86 (DisorderedResidue objects). This method unpacks them, 87 ie. it returns a list of simple Residue objects. 88 """ 89 unpacked_list=[] 90 for residue in self.get_list(): 91 if residue.is_disordered()==2: 92 for dresidue in residue.disordered_get_list(): 93 unpacked_list.append(dresidue) 94 else: 95 unpacked_list.append(residue) 96 return unpacked_list
97
98 - def has_id(self, id):
99 """Return 1 if a residue with given id is present. 100 101 The id of a residue is (hetero flag, sequence identifier, insertion code). 102 If id is an int, it is translated to (" ", id, " ") by the _translate_id 103 method. 104 105 Arguments: 106 o id - (string, int, string) or int 107 """ 108 id=self._translate_id(id) 109 return Entity.has_id(self, id)
110 111 112 # Public 113
114 - def get_atoms(self):
115 for r in self: 116 for a in r: 117 yield a
118