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