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