Figure 7 - ENM performances

We fetch nine PDB from the protein data bank and calculate the time it takes to calculate the ENM and the C2-C2 fluctuations


In [24]:
# import barnaba
import barnaba.enm as enm
import time
import numpy as np

times=[]
n_beads_AA=[]
n_res=[]
for fname in flist:
    t0=time.time()
    enm_tmp=enm.Enm(fname,cutoff=0.7,sele_atoms="AA",sparse=True)
    t1=time.time()-t0
    fluc,rl=enm_tmp.c2_fluctuations()
    t2=time.time()-t0-t1
    n_beads_AA.append(enm_tmp.n_beads)
    n_res.append(len(rl))
    times.append([t1,t2])
t_AA_sparse=np.array(times)


/Users/sandrobottaro/anaconda/lib/python2.7/site-packages/mdtraj/formats/pdb/pdbfile.py:196: UserWarning: Unlikely unit cell vectors detected in PDB file likely resulting from a dummy CRYST1 record. Discarding unit cell vectors.
  warnings.warn('Unlikely unit cell vectors detected in PDB file likely '
# Read  (2570, 3) coordinates
# Using sparse matrix diagonalization
# Read  (3817, 3) coordinates
# Using sparse matrix diagonalization
# Read  (3809, 3) coordinates
# Using sparse matrix diagonalization
# Read  (1608, 3) coordinates
# Using sparse matrix diagonalization
# Read  (6383, 3) coordinates
# Using sparse matrix diagonalization
# Read  (5837, 3) coordinates
# Using sparse matrix diagonalization
# Read  (4996, 3) coordinates
# Using sparse matrix diagonalization
# Read  (739, 3) coordinates
# Using sparse matrix diagonalization
# Read  (800, 3) coordinates
# Using sparse matrix diagonalization

In [9]:
import matplotlib.pyplot as plt
import seaborn as sns

plt.plot(n_beads_AA,t_AA_sparse[:,0],marker='o',ls='',label='Diagonalization')
plt.plot(n_beads_AA,t_AA_sparse[:,1],marker='o',ls='',label='Dist. fluc. calculation')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()
plt.yscale('log')



In [10]:
plt.plot(n_res,t_AA_sparse[:,0],marker='o',ls='',label='Diagonalization')
plt.plot(n_res,t_AA_sparse[:,1],marker='o',ls='',label='Dist. fluc. calculation')
plt.ylabel('execution time (s)')
plt.xlabel('N. res')
plt.legend()
plt.yscale('log')



In [12]:
times=[]
n_beads_AA=[]
for fname in flist:
    t0=time.time()
    enm_tmp=enm.Enm(fname,cutoff=0.7,sele_atoms="AA",sparse=False)
    t1=time.time()-t0
    fluc,rl=enm_tmp.c2_fluctuations()
    t2=time.time()-t0-t1
    n_beads_AA.append(enm_tmp.n_beads)
    times.append([t1,t2])
t_AA_vanilla=np.array(times)


/Users/sandrobottaro/anaconda/lib/python2.7/site-packages/mdtraj/formats/pdb/pdbfile.py:196: UserWarning: Unlikely unit cell vectors detected in PDB file likely resulting from a dummy CRYST1 record. Discarding unit cell vectors.
  warnings.warn('Unlikely unit cell vectors detected in PDB file likely '
# Read  (2570, 3) coordinates
# Read  (3817, 3) coordinates
# Read  (3809, 3) coordinates
# Read  (1608, 3) coordinates
# Read  (6383, 3) coordinates
# Read  (5837, 3) coordinates
# Read  (4996, 3) coordinates
# Read  (739, 3) coordinates
# Read  (800, 3) coordinates

In [13]:
plt.figure(figsize=(12,4))
plt.subplot2grid((1,2),(0,0))
plt.title('Diagonalization only')
plt.plot(n_beads_AA,t_AA_sparse[:,0],marker='o',ls='',label='Sparse',c='r')
plt.plot(n_beads_AA,t_AA_vanilla[:,0],marker='o',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()
plt.yscale('log')

plt.subplot2grid((1,2),(0,1))
plt.title('Total')
plt.plot(n_beads_AA,np.sum(t_AA_sparse,axis=1),marker='s',ls='',label='Sparse',c='r')
plt.plot(n_beads_AA,np.sum(t_AA_vanilla,axis=1),marker='s',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()

plt.yscale('log')



In [14]:
plt.figure(figsize=(12,4))
plt.subplot2grid((1,2),(0,0))
plt.title('Diagonalization only')
plt.plot(n_res,t_AA_sparse[:,0],marker='o',ls='',label='Sparse',c='r')
plt.plot(n_res,t_AA_vanilla[:,0],marker='o',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. res')
plt.legend()
plt.yscale('log')

plt.subplot2grid((1,2),(0,1))
plt.title('Total')
plt.plot(n_res,np.sum(t_AA_sparse,axis=1),marker='s',ls='',label='Sparse',c='r')
plt.plot(n_res,np.sum(t_AA_vanilla,axis=1),marker='s',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. res')
plt.legend()

plt.yscale('log')


SBP model


In [16]:
times=[]
n_beads_SBP=[]
for fname in flist:
    t0=time.time()
    enm_tmp=enm.Enm(fname,sparse=True,cutoff=1.0)
    t1=time.time()-t0
    fluc,rl=enm_tmp.c2_fluctuations()
    t2=time.time()-t0-t1
    n_beads_SBP.append(enm_tmp.n_beads)
    times.append([t1,t2])
t_SBP_sparse=np.array(times)


/Users/sandrobottaro/anaconda/lib/python2.7/site-packages/mdtraj/formats/pdb/pdbfile.py:196: UserWarning: Unlikely unit cell vectors detected in PDB file likely resulting from a dummy CRYST1 record. Discarding unit cell vectors.
  warnings.warn('Unlikely unit cell vectors detected in PDB file likely '
# Read  (360, 3) coordinates
# Using sparse matrix diagonalization
WARNING: there are 7 null modes.             Normally there should be only 6 corresponding to rotational and translational invariance.            This can lead to unpredictable results.
# Read  (480, 3) coordinates
# Using sparse matrix diagonalization
# Read  (525, 3) coordinates
# Using sparse matrix diagonalization
# Read  (213, 3) coordinates
# Using sparse matrix diagonalization
# Read  (888, 3) coordinates
# Using sparse matrix diagonalization
# Read  (810, 3) coordinates
# Using sparse matrix diagonalization
# Read  (697, 3) coordinates
# Using sparse matrix diagonalization
# Read  (82, 3) coordinates
# Using sparse matrix diagonalization
# Read  (98, 3) coordinates
# Using sparse matrix diagonalization

In [17]:
plt.plot(n_beads_SBP,t_SBP_sparse[:,0],marker='o',ls='',label='Diagonalization')
plt.plot(n_beads_SBP,t_SBP_sparse[:,1],marker='o',ls='',label='Dist. fluc. calculation')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()
plt.yscale('log')



In [18]:
times=[]
n_beads_SBP=[]
for fname in flist:
    t0=time.time()
    enm_tmp=enm.Enm(fname,sparse=False,cutoff=1.0)
    t1=time.time()-t0
    fluc,rl=enm_tmp.c2_fluctuations()
    t2=time.time()-t0-t1
    n_beads_SBP.append(enm_tmp.n_beads)
    times.append([t1,t2])
t_SBP_vanilla=np.array(times)


/Users/sandrobottaro/anaconda/lib/python2.7/site-packages/mdtraj/formats/pdb/pdbfile.py:196: UserWarning: Unlikely unit cell vectors detected in PDB file likely resulting from a dummy CRYST1 record. Discarding unit cell vectors.
  warnings.warn('Unlikely unit cell vectors detected in PDB file likely '
# Read  (360, 3) coordinates
WARNING: there are 7 null modes.             Normally there should be only 6 corresponding to rotational and translational invariance.            This can lead to unpredictable results.
# Read  (480, 3) coordinates
# Read  (525, 3) coordinates
# Read  (213, 3) coordinates
# Read  (888, 3) coordinates
# Read  (810, 3) coordinates
# Read  (697, 3) coordinates
# Read  (82, 3) coordinates
# Read  (98, 3) coordinates

In [19]:
plt.figure(figsize=(12,4))
plt.subplot2grid((1,2),(0,0))
plt.title('Diagonalization only')
plt.plot(n_beads_SBP,t_SBP_sparse[:,0],marker='o',ls='',label='Sparse',c='r')
plt.plot(n_beads_SBP,t_SBP_vanilla[:,0],marker='o',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()
plt.yscale('log')

plt.subplot2grid((1,2),(0,1))
plt.title('Total')
plt.plot(n_beads_SBP,np.sum(t_SBP_sparse,axis=1),marker='s',ls='',label='Sparse',c='r')
plt.plot(n_beads_SBP,np.sum(t_SBP_vanilla,axis=1),marker='s',ls='',label='Vanilla',c='b')
plt.ylabel('execution time (s)')
plt.xlabel('N. beads')
plt.legend()
plt.yscale('log')


Save all results on disk


In [20]:
fout=open('performances.dat','w')
fout.write('# PDB | n_beads_AA | n_beads_SBP | n_res | \
t_AA_sprs diag | t_AA_sprs fluc | t_AA_vnll diag | t_AA_vnll fluc | \
t_SBP_sprs diag | t_SBP_sprs fluc | t_SBP_vnll diag | t_SBP_vnll fluc \n')
for i,finname in enumerate(flist):
    pdb=finname.split(".")[0]
    fout.write("%s %d %d %d %e %e %e %e %e %e %e %e \n" % \
               (pdb,n_beads_AA[i],n_beads_SBP[i],n_res[i],\
                t_AA_sparse[i,0],t_AA_sparse[i,1],t_AA_vanilla[i,0],t_AA_vanilla[i,1],\
                t_SBP_sparse[i,0],t_SBP_sparse[i,1],t_SBP_vanilla[i,0],t_SBP_vanilla[i,1]))
fout.close()

Final plot


In [21]:
plt.figure(figsize=(12,4))
plt.subplot2grid((1,2),(0,0))
plt.subplots_adjust(wspace=0)
plt.title('Diagonalization only')
plt.plot(n_res,t_SBP_sparse[:,0],marker='^',ls='',label='Sparse',c='r',ms=8,markeredgecolor='k')
plt.plot(n_res,t_SBP_vanilla[:,0],marker='^',ls='',label='Vanilla',c='gold',ms=8,markeredgecolor='k')
#plt.legend()
plt.plot(n_res,t_AA_sparse[:,0],marker='o',ls='',label='Sparse',c='r',ms=8,markeredgecolor='k')
plt.plot(n_res,t_AA_vanilla[:,0],marker='o',ls='',label='Vanilla',c='gold',ms=8,markeredgecolor='k')
plt.ylabel('execution time (s)')
plt.xlabel('N. res')
#plt.legend()
plt.yscale('log')
plt.xscale('log')
plt.ylim(0.01,2000)

ax=plt.subplot2grid((1,2),(0,1))
plt.title('Total')
ax.plot(n_res,np.sum(t_AA_sparse,axis=1),marker='o',ls='',label='Sparse',c='r',ms=8,markeredgecolor='k')
ax.plot(n_res,np.sum(t_AA_vanilla,axis=1),marker='o',ls='',label='Dense',c='gold',ms=8,markeredgecolor='k')
plt.legend()
ax.plot(n_res,np.sum(t_SBP_sparse,axis=1),marker='^',ls='',label='Sparse',c='r',ms=8,markeredgecolor='k')
ax.plot(n_res,np.sum(t_SBP_vanilla,axis=1),marker='^',ls='',label='Dense',c='gold',ms=8,markeredgecolor='k')
ax.yaxis.tick_right()
plt.xlabel('N. res')
#plt.legend()
plt.ylim(0.01,2000)

plt.yscale('log')
plt.xscale('log')
plt.savefig('ENM-performance.pdf',bbox_inches="tight")