Example #1
0
def plotpmf1D(xvst,xlabel="",ylabel="Free energy (k$_B$T)",bins=50,saveas=None,display=True,label=""):
    """Plot 1D pmf"""
    if not display:
        import matplotlib
        matplotlib.use("Agg")
    import matplotlib.pyplot as plt
    mid_bin,Fdata =  pmfutil.pmf1D(xvst,bins=bins) 
    plt.plot(mid_bin,Fdata,lw=2,label=label)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    if saveas is not None:
        plt.savefig(saveas) 
    if display:
        plt.show()
Example #2
0
def TS_probabilities(Tdirs,coordfile,contact_args):
    """ Calculate the TS contact probabilities along some reaction coordinate

    Parameters
    ----------

    Tdirs : list
        List of directory names to collect reaction coordinate file from

    coordfile : str
        Name of file containing reaction coordinate.

    contact_args : object
        Object containing the 

    """

    T = Tdirs[0].split("_")[0]
    coordname = coordfile.split(".")[0]
    if not os.path.exists("%s_profile/state_bounds.txt" % coordname):
        # Determine state bounds from 1D profile
        print "calculating state bounds"
        coordvst = np.concatenate([np.loadtxt("%s/%s" % (x,coordfile)) for x in Tdirs ])
        if not os.path.exists("%s_profile" % coordname):
            os.mkdir("%s_profile" % coordname)
        os.chdir("%s_profile" % coordname)
        mid_bin, Fdata = pmfutil.pmf1D(coordvst,bins=40)
        xinterp, F = pmfutil.interpolate_profile(mid_bin,Fdata)
        minidx, maxidx = pmfutil.extrema_from_profile(xinterp,F)
        min_bounds, max_bounds = pmfutil.state_bounds_from_profile(xinterp,F)
        min_labels, max_labels = pmfutil.assign_state_labels(min_bounds,max_bounds)
        pmfutil.save_state_bounds(T,min_bounds,max_bounds,min_labels,max_labels)
        os.chdir("..")
        with open("%s_profile/%s_state_bounds.txt" % (coordname,T),"r") as fin:
            state_bins = np.array([ [float(x.split()[1]),float(x.split()[2])] 
                for x in fin.readlines() if x.split()[0].startswith("TS")])
    else:
        # Load state bounds
        with open("%s_profile/state_bounds.txt" % coordname,"r") as fin:
            state_bins = np.array([ [float(x.split()[1]),float(x.split()[2])] 
                for x in fin.readlines() if x.split()[0].startswith("TS")])

    # Calculate the contact probability in TS
    print "calculating TS"
    contact_args.bins = state_bins
    bin_edges, qi_vs_Q = simulation.calc.binned_contacts.calculate_binned_contacts_vs_q(contact_args)
    TS = qi_vs_Q[0,:]
    return TS
Example #3
0
def plotpmf1D(xvst,
              xlabel="",
              ylabel="Free energy (k$_B$T)",
              bins=50,
              saveas=None,
              display=True,
              label=""):
    """Plot 1D pmf"""
    if not display:
        import matplotlib
        matplotlib.use("Agg")
    import matplotlib.pyplot as plt
    mid_bin, Fdata = pmfutil.pmf1D(xvst, bins=bins)
    plt.plot(mid_bin, Fdata, lw=2, label=label)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    if saveas is not None:
        plt.savefig(saveas)
    if display:
        plt.show()
Example #4
0
    parser.add_argument('--saveas', type=str, help='Optional. Filename to save plot.')
    args = parser.parse_args()

    filename = args.data 
    coord_name = filename.split(".")[0]
    n_bins = args.n_bins
    title = args.title
    saveas = args.saveas

    if filename.endswith("npy"):
        coord = np.load(filename)
    else:
        coord = np.loadtxt(filename)
    if filename == "Q.dat":
        coord += np.random.normal(size=coord.shape[0])

    mid_bin, Fdata = pmfutil.pmf1D(coord,bins=n_bins)
    #xinterp, F = pmfutil.interpolate_profile(mid_bin,Fdata)

    # Plot profile from data and interpolant 
    #plt.plot(xinterp,F(xinterp),lw=2,color='b',label="data")
    plt.plot(mid_bin,Fdata,marker='o',color='b',label="fit")
    plt.legend()
    plt.xlabel("%s" % coord_name,fontsize=16)
    plt.ylabel("F(%s) (k$_B$T)" % coord_name,fontsize=16)
    plt.title(title)

    if saveas is not None:
        plt.savefig(saveas)
    plt.show()
Example #5
0
        print T[i]
        qtanh_files = [ "{}/{}".format(os.path.dirname(x),coordfile) for x in trajfiles[i] ]
        qtanh_files_exist = [ os.path.exists(x) for x in qtanh_files ]
        # this should work except I am experiencing a strange NaN error.
        if np.all(qtanh_files_exist) and not recalculate:  
            qtanh = [ np.load(x) for x in qtanh_files ]
        else:
            qtanh = []
            for n in range(len(trajfiles[i])):
                traj = trajfiles[i][n]
                qtanh_temp = np.array(qtanhsum_obs.map(md.load(traj, top=topfile)))
                np.save(os.path.dirname(traj) + "/" + coordfile, qtanh_temp)
                qtanh.append(qtanh_temp)

        # calculate free energy profile and state definitions
        mid_bin, Fdata = pmfutil.pmf1D(np.concatenate(qtanh), bins=40)
        #plt.plot(mid_bin, Fdata, label=str(T[i]))

        if not os.path.exists(coordname + "_profile"):
            os.mkdir(coordname + "_profile")
        os.chdir(coordname + "_profile")
        np.savetxt("T_{}_mid_bin.dat".format(T[i]), mid_bin)
        np.savetxt("T_{}_F.dat".format(T[i]), Fdata)

        xinterp, F = pmfutil.interpolate_profile(mid_bin, Fdata)
        minidx, maxidx = pmfutil.extrema_from_profile(xinterp, F)

        F_fit = F(xinterp)
        with open("T_{}_stab.dat".format(T[i]), "w") as fout:
            fout.write(str(F_fit[minidx[1]] - F_fit[minidx[0]]))
         
Example #6
0
                        help='Optional. Filename to save plot.')
    args = parser.parse_args()

    filename = args.data
    coord_name = filename.split(".")[0]
    n_bins = args.n_bins
    title = args.title
    saveas = args.saveas

    if filename.endswith("npy"):
        coord = np.load(filename)
    else:
        coord = np.loadtxt(filename)
    if filename == "Q.dat":
        coord += np.random.normal(size=coord.shape[0])

    mid_bin, Fdata = pmfutil.pmf1D(coord, bins=n_bins)
    #xinterp, F = pmfutil.interpolate_profile(mid_bin,Fdata)

    # Plot profile from data and interpolant
    #plt.plot(xinterp,F(xinterp),lw=2,color='b',label="data")
    plt.plot(mid_bin, Fdata, marker='o', color='b', label="fit")
    plt.legend()
    plt.xlabel("%s" % coord_name, fontsize=16)
    plt.ylabel("F(%s) (k$_B$T)" % coord_name, fontsize=16)
    plt.title(title)

    if saveas is not None:
        plt.savefig(saveas)
    plt.show()