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

In [4]:
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 [7]:
trj = '50_frame.dcd'
top = './41wl_ff.psf'
u = MDAnalysis.Universe(top, trj)
fig, Rgyrdata = Rgyr(u)
#np.savetxt("SimAnaRep-RoG.data", Rgyrdata)
#fig.figure.savefig("SimAnaRep-RoG.pdf")


[[  0.          14.45947817]
 [  0.04888821  14.56343943]
 [  0.09777642  14.66004709]
 [  0.14666463  14.5950319 ]
 [  0.19555284  14.65924899]
 [  0.24444105  14.52109577]
 [  0.29332926  14.52496548]
 [  0.34221747  14.74254526]
 [  0.39110568  14.74876355]
 [  0.43999389  14.52289098]
 [  0.4888821   14.52560928]
 [  0.53777031  14.4352187 ]
 [  0.58665852  14.53671809]
 [  0.63554673  14.43235824]
 [  0.68443494  14.46688002]
 [  0.73332315  14.4705191 ]
 [  0.78221136  14.41274683]
 [  0.83109957  14.43789711]
 [  0.87998778  14.38424011]
 [  0.92887599  14.41613229]
 [  0.9777642   14.56441881]
 [  1.02665241  14.5337207 ]
 [  1.07554062  14.41597997]
 [  1.12442883  14.40583184]
 [  1.17331704  14.45525257]
 [  1.22220525  14.46460474]
 [  1.27109346  14.46638457]
 [  1.31998167  14.40691409]
 [  1.36886988  14.52930841]
 [  1.41775809  14.54878399]
 [  1.4666463   14.48549566]
 [  1.51553451  14.49806385]
 [  1.56442272  14.50785088]
 [  1.61331093  14.50795497]
 [  1.66219914  14.54129607]
 [  1.71108735  14.38962131]
 [  1.75997556  14.51879453]
 [  1.80886377  14.51302802]
 [  1.85775198  14.59042283]
 [  1.90664019  14.50376336]
 [  1.9555284   14.45130122]
 [  2.00441661  14.5705463 ]
 [  2.05330482  14.66729859]
 [  2.10219303  14.51986238]
 [  2.15108124  14.54526494]
 [  2.19996945  14.4653264 ]
 [  2.24885766  14.46804386]
 [  2.29774587  14.5561452 ]
 [  2.34663408  14.39166516]
 [  2.39552229  14.48221981]]