def toDict(self, key): """ Convert collection into dict indexed by the value of a certain item attribute. If several items have the same value, the result will have a list registered for this key. C{ EXAMPLE: lst.toDict('soln') } C{ -> {soln1:Item, soln3:Item, solnN:Item} } @param key: item attribute @type key: any @return: { info1:dict, info2:dict, info3:[dict, dict].. } @rtype: dict """ result = {} for i in range(len(self)): t.dictAdd(result, self.getValue(i, key), self[i]) return result
def toDict( self, infoKey ): """ Convert list into dict indexed by a certain info-record value. If several Complexes have the same value, the result will have a list registered for this key. EXAMPLE: >>> clst.toDict('soln') -> {1:Complex, 3:Complex, solnN:Complex} @param infoKey: key of info dict in Complexes @type infoKey: str @return: { info1:Complex, info2:Complex, info3:[Complex, Complex].. } @rtype: dict """ result = {} for c in self: t.dictAdd( result, c.info[infoKey], c ) return result
def labelDuplicateAtoms( self ): """ Ensure duplicate atoms are labeled with an alternate code. Atoms that have no duplicates receive alternate code ''. Atoms with one or more duplicates within the same residue receive alternate codes 'A' (first one in list), 'B', and so on. The original alternate code field from the PDB (if any) is deleted. """ import string m = self.model() assert m is not None, 'residue is not attached to any PDBModel' names = m.atoms['name'][self.from_atom : self.to_atom] ## number of occurrences of each atom name counts = [ names.count( n ) for n in names ] if max( counts ) <= 1: return ## nothing to do ## dict with list of positions in which each atom is found positions = {} for i,n in enumerate(names): T.dictAdd( positions, n, i, forceList=True ) ## create new list of alternate codes alt = [] for n, c in zip( names, counts ): pos = positions[ n ] if c == 1: alt.append( '' ) else: alt.append( string.letters[ c - len( pos ) ].upper() ) pos.pop() # remove one, discard m.atoms['alternate'][self.from_atom : self.to_atom] = alt
def labelDuplicateAtoms(self): """ Ensure duplicate atoms are labeled with an alternate code. Atoms that have no duplicates receive alternate code ''. Atoms with one or more duplicates within the same residue receive alternate codes 'A' (first one in list), 'B', and so on. The original alternate code field from the PDB (if any) is deleted. """ import string m = self.model() assert m is not None, 'residue is not attached to any PDBModel' names = m.atoms['name'][self.from_atom:self.to_atom] ## number of occurrences of each atom name counts = [names.count(n) for n in names] if max(counts) <= 1: return ## nothing to do ## dict with list of positions in which each atom is found positions = {} for i, n in enumerate(names): T.dictAdd(positions, n, i, forceList=True) ## create new list of alternate codes alt = [] for n, c in zip(names, counts): pos = positions[n] if c == 1: alt.append('') else: alt.append(string.letters[c - len(pos)].upper()) pos.pop() # remove one, discard m.atoms['alternate'][self.from_atom:self.to_atom] = alt