2

Using a typical pdb file, I am able to calculate the distance between two atoms in a structure using a method similar to that presented in the Biopython documentation. Shown here:

from Bio import PDB
parser = PDB.PDBParser()

pdb1 ='./4twu.pdb' 
structure = parser.get_structure("4twu", pdb1) 
model = structure[0] 
chain = model['A'] 
residue1 = chain[1] 
residue2 = chain[2]
atom1 = residue1['CA'] 
atom2 = residue2['CA'] 

distance = atom1-atom2 

print(distance)

Is there a method within Biopython to calculate the distance from an atom to a fixed point with xyz coordinates? If not Biopython, what would be the best method to solve this problem? Thanks.

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
MunKee
  • 23
  • 1
  • 4

1 Answers1

0

Your atom1 object stores the coordinates in the coord attribute (it's a NumPy array), e.g.

>>> print(atom1.coord)
[ 26.26600075  25.41300011   2.84200001]

If you want to calculate the distance to another point in space you need to define it in a similar format.

import numpy
x = 1
y = 1
y = 1
v = numpy.array((x, y, z), dtype=float)

and you can then calculate the distance with NumPy.

distance = numpy.linalg.norm(atom1.coord - v)
Community
  • 1
  • 1
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
  • Works perfectly. Thanks Ashafix. – MunKee May 07 '16 at 10:16
  • 1
    Yes. This is basically what the Atom objects are doing for you via the subtraction in your question, ``__sub__`` is defined in the atom class as taking the norm of the difference in the coordinate vectors. – Peter Cock May 09 '16 at 08:51