Take a look at the following steps:
- 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')
- 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. ...