[BioPython] vector distance

Peter Cock p.j.a.cock at googlemail.com
Fri Feb 6 10:51:29 UTC 2009


On Thu, Feb 5, 2009 at 6:19 PM, Bala subramanian
<bala.biophysics at gmail.com> wrote:
> Dear Friends,
>
> Can someone please tell me if it is possible to calculate the vector
> distance between two atoms using Bio.PDB. Given two pdb files, i want to
> calculate the vector distance between the Calpha atoms in the two pdb files.
> Someone kindly enlighten me how can i do it.

Have you ever worked with Numeric or NumPy before?  That would be very
helpful for you.

Given two residue objects, this worked on Biopython 1.48 or older
(using Numeric):

import Numeric
def calc_residue_dist(residue_one, residue_two) :
    """Returns the C-alpha distance between two residues"""
    diff_vector  = residue_one["CA"].coord - residue_two["CA"].coord
    return Numeric.sqrt(Numeric.sum(diff_vector * diff_vector))

Now that Biopython 1.49+ is using NumPy instead of Numeric, you'd
probably want to do this instead:

import numpy
def calc_residue_dist(residue_one, residue_two) :
    """Returns the C-alpha distance between two residues"""
    diff_vector  = residue_one["CA"].coord - residue_two["CA"].coord
    return numpy.sqrt(numpy.sum(diff_vector * diff_vector))

See http://www.warwick.ac.uk/go/peter_cock/python/protein_contact_map/
for more information.

Peter



More information about the Biopython mailing list