-
Notifications
You must be signed in to change notification settings - Fork 91
/
diameter.py
33 lines (28 loc) · 1.02 KB
/
diameter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Calculation of protein diameter
===============================
This script calculates the diameter of a protein
defined as the maximum pairwise atom distance.
"""
# Code source: Patrick Kunzmann
# License: BSD 3 clause
from tempfile import gettempdir
import numpy as np
import biotite.structure as struc
import biotite.structure.io as strucio
import biotite.database.rcsb as rcsb
def get_diameter(pdb_id):
file_name = rcsb.fetch(pdb_id, "mmtf", gettempdir())
atom_array = strucio.load_structure(file_name)
# Remove all non-amino acids
atom_array = atom_array[struc.filter_amino_acids(atom_array)]
coord = atom_array.coord
# Calculate all pairwise difference vectors
diff = coord[:, np.newaxis, :] - coord[np.newaxis, :, :]
# Calculate absolute of difference vectors -> square distances
sq_dist = np.sum(diff*diff, axis=-1)
# Maximum distance is diameter
diameter = np.sqrt(np.max(sq_dist))
return diameter
# Example application
print("Diameter of 1QAW:", get_diameter("1QAW"), "Angstrom")