def pdbContact(pdb,all=False): """ Generate array of all atom-atom distances in a pdb file. Defaults to only look at CA atoms """ pdb = other.getPolymerAtoms(pdb) pdb = other.removeRotamers(pdb) # Remove non-CA atoms if not all: pdb = [l for l in pdb if l[13:15] == "CA"] coord = [[float(l[30+8*i:38+8*i]) for i in range(3)] for l in pdb] dist = geometry.calcDistances(coord) return dist
def pdbSeq(pdb,use_atoms=False): """ Parse the SEQRES entries in a pdb file. If this fails, use the ATOM entries. Return dictionary of sequences keyed to chain and type of sequence used. """ # Try using SEQRES seq = [l for l in pdb if l[0:6] == "SEQRES"] if len(seq) != 0 and not use_atoms: seq_type = "SEQRES" chain_dict = dict([(l[11],[]) for l in seq]) for c in chain_dict.keys(): chain_seq = [l[19:70].split() for l in seq if l[11] == c] for x in chain_seq: chain_dict[c].extend(x) # Otherwise, use ATOM else: # Check to see if there are multiple models. If there are, only look # at the first model. models = [i for i, l in enumerate(pdb) if l.startswith("MODEL")] if len(models) > 1: pdb = pdb[models[0]:models[1]] seq_type = "ATOM " atoms = other.getPolymerAtoms(pdb) #atoms = other.removeRotamers(atoms) atoms = [l for l in atoms if l[13:15] == "CA"] atoms = other.removeRotamers(atoms)#this second call removes alternate residues, which may not be interleaved. Actually, the first call could be removed. chain_dict = dict([(l[21],[]) for l in atoms]) for c in chain_dict.keys(): chain_dict[c] = [l[17:20] for l in atoms if l[21] == c] return chain_dict, seq_type