In [27]:
import MDAnalysis
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline

In [28]:
def Rgyr(u):
    """This function will plot Radius of gyration for a give universe (trajectory)
    :input
        universe: A universe with both PSF and DCD Files.
    :return 
        1) matplotlib object for figure. 
        2) array with data. 
    """
    Rgyr = []
    protein = u.select_atoms("protein")
    for ts in u.trajectory:
       Rgyr.append((u.trajectory.time, protein.radius_of_gyration()))
    Rgyr = np.array(Rgyr)

    print Rgyr
    ax = plt.subplot(111)
    ax.plot(Rgyr[:,0], Rgyr[:,1], 'r--', lw=2, label=r"$R_G$")
    ax.set_title("Radius of Gyration")
    ax.set_xlabel("Time (ps)")
    ax.set_ylabel(r"radius of gyration $R_G$ ($\AA$)")
    #ax.figure.savefig("Rgyr.pdf")
    plt.draw()
    return  ax, Rgyr

In [2]:
trj = '50_frame.dcd'
top = './41wl_ff.psf'
u = MDAnalysis.Universe(top, trj)
fig, Rgyrdata = Rgyr(u)
np.savetxt(args.jobname+"-RoG.data", Rgyrdata)
    #print Rgyrdata
fig.figure.savefig(args.jobname+"-RoG.pdf")


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-79efd0199213> in <module>()
      1 trj = '50_frame.dcd'
      2 top = './41wl_ff.psf'
----> 3 u = MDAnalysis.Universe(top, trj)
      4 fig, Rgyrdata = Rgyr(u)
      5 np.savetxt(args.jobname+"-RoG.data", Rgyrdata)

NameError: name 'MDAnalysis' is not defined