A test for MDTraj about calculating interactions within 6 A.
In [1]:
import mdtraj as md
traj = md.load('./material/md.pdb')
top = traj.topology
print traj
print top
In [2]:
# traj.xyz[frame_idx, atom_idx,:]
traj.xyz[0,0]
Out[2]:
In [3]:
cas = top.select('name CA')
print cas
len(cas)
Out[3]:
In [4]:
import numpy as np
cm = np.zeros((401,401))
In [5]:
for f in range(traj.n_frames):
for i, cur_i in enumerate(cas):
cur_ca = traj.xyz[f, cur_i]
for j, com_i in enumerate(cas):
dis = np.sqrt(np.sum((traj.xyz[f,com_i]-cur_ca)**2))
if dis < 6.0:
cm[i][j] = cm[i][j] + 1
In [6]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.imshow(cm, interpolation='nearest', cmap=plt.cm.ocean)
plt.colorbar()
plt.show()
In [9]:
cm
Out[9]:
In [ ]: