In [1]:
from __future__ import print_function
from collections import defaultdict
import sys
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
from Bio import PDB
In [2]:
repository = PDB.PDBList()
parser = PDB.PDBParser()
repository.retrieve_pdb_file('1TUP', pdir='.')
p53_1tup = parser.get_structure('P 53', 'pdb1tup.ent')
In [3]:
atom_cnt = defaultdict(int)
atom_chain = defaultdict(int)
atom_res_types = defaultdict(int)
for atom in p53_1tup.get_atoms():
my_residue = atom.parent
my_chain = my_residue.parent
atom_chain[my_chain.id] += 1
if my_residue.resname != 'HOH':
atom_cnt[atom.element] += 1
atom_res_types[my_residue.resname] += 1
print(dict(atom_res_types))
print(dict(atom_chain))
print(dict(atom_cnt))
In [5]:
res_types = defaultdict(int)
res_per_chain = defaultdict(int)
for residue in p53_1tup.get_residues():
res_types[residue.resname] += 1
res_per_chain[residue.parent.id] +=1
print(dict(res_types))
print(dict(res_per_chain))
In [6]:
def get_bounds(my_atoms):
my_min = [sys.maxint] * 3
my_max = [-sys.maxint] * 3
for atom in my_atoms:
for i, coord in enumerate(atom.coord):
if coord < my_min[i]:
my_min[i] = coord
if coord > my_max[i]:
my_max[i] = coord
return my_min, my_max
In [7]:
chain_bounds = {}
for chain in p53_1tup.get_chains():
print(chain.id, get_bounds(chain.get_atoms()))
chain_bounds[chain.id] = get_bounds(chain.get_atoms())
print(get_bounds(p53_1tup.get_atoms()))
In [8]:
#matplotlib 3d plot
fig = plt.figure(figsize=(16, 9))
ax3d = fig.add_subplot(111, projection='3d')
ax_xy = fig.add_subplot(331)
ax_xy.set_title('X/Y')
ax_xz = fig.add_subplot(334)
ax_xz.set_title('X/Z')
ax_zy = fig.add_subplot(337)
ax_zy.set_title('Z/Y')
color = {'A': 'r', 'B': 'g', 'C': 'b', 'E': '0.5', 'F': '0.75'}
zx, zy, zz = [], [], []
for chain in p53_1tup.get_chains():
xs, ys, zs = [], [], []
for residue in chain.get_residues():
ref_atom = next(residue.get_iterator())
x, y, z = ref_atom.coord
if ref_atom.element == 'ZN':
zx.append(x)
zy.append(y)
zz.append(z)
continue
xs.append(x)
ys.append(y)
zs.append(z)
ax3d.scatter(xs, ys, zs, color=color[chain.id])
ax_xy.scatter(xs, ys, marker='.', color=color[chain.id])
ax_xz.scatter(xs, zs, marker='.', color=color[chain.id])
ax_zy.scatter(zs, ys, marker='.', color=color[chain.id])
ax3d.set_xlabel('X')
ax3d.set_ylabel('Y')
ax3d.set_zlabel('Z')
ax3d.scatter(zx, zy, zz, color='k', marker='v', s=300)
ax_xy.scatter(zx, zy, color='k', marker='v', s=80)
ax_xz.scatter(zx, zz, color='k', marker='v', s=80)
ax_zy.scatter(zz, zy, color='k', marker='v', s=80)
for ax in [ax_xy, ax_xz, ax_zy]:
ax.get_yaxis().set_visible(False)
ax.get_xaxis().set_visible(False)
In [ ]: