Package Bio :: Package PDB :: Module AbstractPropertyMap
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.AbstractPropertyMap

  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  from types import IntType 
  7   
  8  __doc__="Class that maps (chain_id, residue_id) to a residue property" 
  9   
 10   
11 -class AbstractPropertyMap:
12 - def __init__(self, property_dict, property_keys, property_list):
13 self.property_dict=property_dict 14 self.property_keys=property_keys 15 self.property_list=property_list
16
17 - def _translate_id(self, entity_id):
18 return entity_id
19
20 - def __getitem__(self, key):
21 """ 22 Return property for a residue. 23 24 @param chain_id: chain id 25 @type chain_id: char 26 27 @param res_id: residue id 28 @type res_id: int or (char, int, char) 29 30 @return: some residue property 31 @rtype: anything (can be a tuple) 32 """ 33 translated_id=self._translate_id(key) 34 return self.property_dict[translated_id]
35
36 - def __len__(self):
37 """ 38 Return number of residues for which the property is available. 39 40 @return: number of residues 41 @rtype: int 42 """ 43 return len(self.property_dict)
44
45 - def has_key(self, id):
46 """ 47 Return 1 if the map has a property for this residue, 0 otherwise. 48 49 Example: 50 >>> if map.has_key((chain_id, res_id)): 51 >>> res, property=map[(chain_id, res_id)] 52 53 @param chain_id: chain id 54 @type chain_id: char 55 56 @param res_id: residue id 57 @type res_id: char 58 """ 59 translated_id=self._translate_id(id) 60 return self.property_dict.has_key(translated_id)
61
62 - def keys(self):
63 """ 64 Return the list of residues. 65 66 @return: list of residues for which the property was calculated 67 @rtype: [(chain_id, res_id), (chain_id, res_id),...] 68 """ 69 return self.property_keys
70
71 - def __iter__(self):
72 """ 73 Iterate over the (entity, property) list. Handy alternative to 74 the dictionary-like access. 75 76 Example: 77 >>> for (res, property) in iter(map): 78 >>> print res, property 79 80 @return: iterator 81 """ 82 for i in range(0, len(self.property_list)): 83 yield self.property_list[i]
84 85
86 -class AbstractResiduePropertyMap(AbstractPropertyMap):
87 - def __init__(self, property_dict, property_keys, property_list):
88 AbstractPropertyMap.__init__(self, property_dict, property_keys, 89 property_list)
90
91 - def _translate_id(self, ent_id):
92 chain_id, res_id=ent_id 93 if type(res_id)==IntType: 94 ent_id=(chain_id, (' ', res_id, ' ')) 95 return ent_id
96
97 -class AbstractAtomPropertyMap(AbstractPropertyMap):
98 - def __init__(self, property_dict, property_keys, property_list):
99 AbstractPropertyMap.__init__(self, property_dict, property_keys, 100 property_list)
101
102 - def _translate_id(self, ent_id):
103 if len(ent_id)==4: 104 chain_id, res_id, atom_name, icode=ent_id 105 else: 106 chain_id, res_id, atom_name=ent_id 107 icode=None 108 if type(res_id)==IntType: 109 ent_id=(chain_id, (' ', res_id, ' '), atom_name, icode) 110 return ent_id
111