How to do it...

Take a look at the following steps:

  1. Let's load our PDB structure with the following code:
import math%load_ext Cythonfrom Bio import PDBrepository = PDB.PDBList()parser = PDB.PDBParser()repository.retrieve_pdb_file('1TUP', pdir='.')p53_1tup = parser.get_structure('P 53', 'pdb1tup.ent')
  1. Here is our pure Python distance function:
def get_distance(atoms):    atoms = list(atoms)    natoms = len(atoms)    for i in range(natoms - 1):        xi, yi, zi = atoms[i].coord        for j in range(i + 1, natoms):            xj, yj, zj = atoms[j].coord            my_dist = math.sqrt((xi - xj)**2 + (yi - yj)**2 + (zi - zj)**2)

This will compute the distance between all of the atoms in the PDB file. We do not care about the result here, just the time cost, so we do not return anything. ...

Get Bioinformatics with Python Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.