Ejemplo n.º 1
0
def plot_mean_landscape(q_interp, splines, ax=None,color='c',label=None,
                        fill_between=True):
    """
    :param q_interp: where to interpolate the splines
    :param splines: LstSqUnivariateSpline objects
    :param ax:  which axis to add to
    :return:
    """
    mean_energy, std_energy = _mean_and_stdev_landcapes(splines,q_interp)
    ax = plt.subplot(1, 1, 1) if (ax is None) else ax
    plt.subplot(ax)
    plt.plot(q_interp, mean_energy, color=color,label=label)
    if fill_between:
        plt.fill_between(q_interp, mean_energy - std_energy,
                         mean_energy + std_energy,
                         color=color, alpha=0.2)
    PlotUtilities.lazyLabel("q (nm)", "$\Delta G_0$ (kcal/mol)", "")
    return mean_energy, std_energy
Ejemplo n.º 2
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    n = 1000
    pts = np.linspace(-1,1,num=n)
    f = lambda x: -1 * x**2 - 0.5 * x + 3 * x**3 + 10 * x**4 + \
        np.sin(2 * np.pi * x * 3) * 0.5 / (1+abs(x/3))
    f_pts = f(pts)
    max_f = max(f(pts))
    f_pts /= max_f
    brute_sample_n = 15
    dict_brute = dict(markersize=3)
    brute_pts = pts[::int(n/brute_sample_n)]
    brute_f_pts = f(brute_pts) / max_f
    # get the 'zoom in' region
    best_idx = np.argmin(brute_f_pts)
    pts_zoom = np.linspace(brute_pts[best_idx-1],brute_pts[best_idx+1],
                            num=10,endpoint=True)
    f_zoom = f(pts_zoom) / max_f
    fig = PlotUtilities.figure((3,4))
    ax1 = plt.subplot(2,1,1)
    plt.plot(pts,f_pts)
    plt.plot(brute_pts,brute_f_pts,'ro',**dict_brute)
    PlotUtilities.lazyLabel("","Error","")
    PlotUtilities.no_x_label(ax1)
    ax2 = plt.subplot(2,1,2)
    plt.plot(pts,f_pts)
    xmin, xmax = min(pts_zoom),max(pts_zoom)
    ymin, ymax = min(f_zoom),max(f_zoom)
    y_range = ymax-ymin
    plt.xlim(xmin,xmax)
    plt.ylim(ymin - y_range * 0.1,ymax + y_range * 0.1)
    plt.axvline(pts_zoom[np.argmin(f_zoom)],label="Found\nmin",
                color='g',linestyle='--')
    Annotations.zoom_effect01(ax1, ax2, xmin, xmax)
    PlotUtilities.lazyLabel("X (au)","Error","")
    PlotUtilities.savefig(fig,"./out.png")
Ejemplo n.º 3
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    base_dir = "../../../../Data/FECs180307/"
    read_f = FigureUtil.read_sample_landscapes
    gallery = CheckpointUtilities.getCheckpoint("./caches.pkl",
                                                read_f,False,base_dir)
    lab_plot = [ ["BR-PEG3400",gallery.PEG3400],
                 ["BO-PEG3400",gallery.BO_PEG3400] ]
    fig = PlotUtilities.figure(figsize=(4,6))
    gs = gridspec.GridSpec(ncols=1,nrows=2,height_ratios=[3,1])
    gs_pipeline= gridspec.GridSpecFromSubplotSpec(ncols=2,nrows=3,hspace=0.03,
                                                  subplot_spec=gs[0,:])
    colors = ['r','rebeccapurple']
    xlim,_,ylm_W = xlim_ylim()

    mean_works_info = []
    for i,(label,to_use) in enumerate(lab_plot):
        pipeline = FigureUtil._alignment_pipeline(to_use)
        fecs = pipeline.blacklisted.fec_list
        # calculate all the works
        x_arr = [f.Separation for f in fecs]
        f_arr = [f.Force for f in fecs]
        works = _calculate_work(x_arr,f_arr)
        works_kcal = np.array(works) * kcal_per_mol_per_J()
        c = colors[i]
        _make_work_plot(fecs, x_arr, works_kcal,gs_pipeline,col=i,color=c,
                         title=label)
        x_interp, mean_W, std_W= _mean_work(x_arr,works_kcal)
        plt.subplot(gs[-1, :])
        _plot_mean_works(x_interp, mean_W, std_W, color=c, title=label)
        plt.xlim(xlim)
        plt.ylim(ylm_W)
        PlotUtilities.lazyLabel("Extension (nm)" , "$W$ (kcal/mol)","",
                                useLegend=False)
    PlotUtilities.savefig(fig, "FigureS_Work.png".format(label))
Ejemplo n.º 4
0
def _make_plots(pre_str,W_of_interest,beta,fit_info,ext_list,work_list):
    work_all = np.array(work_list)
    Ws_kT = W_of_interest * beta
    min_W_kT, max_W_kT = min(Ws_kT), max(Ws_kT)
    x_final = fit_info.x_final
    kw_common = fit_info.kw_common
    eq_5_B_REM = palassini_2011_eq_5(fit_info)
    range_W_kT = (max_W_kT - min_W_kT)
    model_W = np.linspace(min_W_kT - range_W_kT, max_W_kT + range_W_kT, num=50)
    model_P_not_norm = unnormalized_prob(model_W, *x_final, **kw_common)
    model_P = model_P_not_norm / trapz(x=model_W, y=model_P_not_norm)
    fig = PlotUtilities.figure()
    plt.hist(Ws_kT, normed=True)
    plt.plot(model_W, model_P,label="Model")
    title = "Bias = {:.2f} kT".format(eq_5_B_REM)
    PlotUtilities.lazyLabel("W (kT)","$N$",title)
    PlotUtilities.savefig(fig,pre_str + "outhist.png")
    fig = PlotUtilities.figure()
    for e,w in zip(ext_list,work_all):
        plt.plot(e,w * beta)
    PlotUtilities.lazyLabel("Ext (m)","W (kT)","")
    PlotUtilities.savefig(fig,pre_str + "out.png")
Ejemplo n.º 5
0
def make_comparison_plot():
    plot_inf = WLC.peg_contribution(model_f=WLC.Hao_PEGModel)
    ext_grid = plot_inf.q
    plot_info_hao, plot_inf_hao_polypeptide = hao_plot_inf(ext_grid)
    # plot all of Hao's data
    label_hao_total = "Hao's FJC+WLC"
    plt.plot(plot_info_hao.q, plot_info_hao.f, 'k-', label=label_hao_total)
    wlc_color = 'b'
    # plot Hao's polypeptide model
    plt.plot(*WLC.read_hao_polypeptide(base="../../FigData/"),
             color=wlc_color,
             marker='o',
             linestyle='None',
             markersize=4,
             label="Hao's WLC")
    plt.plot(ext_grid, plot_inf.f, color='r', label="My model")
    labels = ["My FJC", "My WLC"]
    colors = ['darkgoldenrod', wlc_color]
    for q, l, c in zip(plot_inf.qs, labels, colors):
        plt.plot(q, plot_inf.f, label=l, color=c)
    plt.xlim([0, 50])
    plt.ylim([0, 400])
    PlotUtilities.lazyLabel("Extension (nm)", "Force (pN)", "")
Ejemplo n.º 6
0
def plot_landscapes(data,energy_obj,ax1=None,ax2=None):
    if ax1 is None:
        ax1 = plt.subplot(3,1,1)
    if ax2 is None:
        ax2 = plt.subplot(3,1,2)
    energy_obj = RetinalUtil.valid_landscape(energy_obj)
    q = energy_obj.q
    q_nm = q * 1e9
    xlim_nm = [min(q_nm), max(q_nm)]
    G0_plot = energy_obj.G0_kcal_per_mol
    spline_G0 = RetinalUtil.spline_fit(q=q, G0=energy_obj.G0)
    to_kcal_per_mol = Conversions.kcal_per_mol_per_J()
    plt.sca(ax1)
    for d in data:
        plt.plot(d.Separation * 1e9, d.Force * 1e12, markevery=50)
    plt.xlim(xlim_nm)
    PlotUtilities.lazyLabel("", "$F$ (pN)", "")
    PlotUtilities.no_x_label(ax=ax1)
    plt.sca(ax2)
    plt.plot(q_nm, G0_plot)
    plt.plot(q_nm, spline_G0(q) * to_kcal_per_mol, 'r--')
    PlotUtilities.lazyLabel("", "$\Delta G_\mathrm{0}$\n(kcal/mol)", "")
    PlotUtilities.no_x_label(ax=ax2)
    plt.xlim(xlim_nm)
Ejemplo n.º 7
0
def make_model_plot(plot_inf, title):
    gs = gridspec.GridSpec(nrows=2, ncols=1)
    gs_ext = gridspec.GridSpecFromSubplotSpec(nrows=2,
                                              ncols=1,
                                              subplot_spec=gs[0],
                                              width_ratios=[1],
                                              height_ratios=[2, 1],
                                              hspace=0.02,
                                              wspace=0.02)
    ax1 = plt.subplot(gs_ext[0])
    print("For {:s}...".format(title))
    for k, v in plot_inf.kw.items():
        print("{:s}={:.5g}".format(k, v))
    labels = ["PEG", "Unfolded\npeptide"]
    color_final = 'k'
    colors = ['b', 'r']
    for q, l, c in zip(plot_inf.qs, labels, colors):
        plt.plot(q, plot_inf.f, label=l, color=c)
    plt.plot(plot_inf.q, plot_inf.f, label="Both", color=color_final)
    PlotUtilities.lazyLabel("",
                            "$F$ (pN)",
                            title,
                            legend_kwargs=dict(frameon=True))
    PlotUtilities.no_x_label(ax1)
    W_str = "$W_{\mathbf{PEG}}" if len(labels) == 1 else \
        "$W_{\mathbf{PEG+POLY}}$"
    plt.subplot(gs_ext[1])
    plt.plot(plot_inf.q, plot_inf.w, color=color_final)
    PlotUtilities.lazyLabel("Extension (nm)", W_str + "\n(kcal/mol)", "")
    plt.subplot(gs[1])
    plt.plot(plot_inf.f, plot_inf.w, color=color_final)
    colors = ['m', 'g']
    for i, f_tmp in enumerate([149, 249]):
        W_int = plot_inf.W_at_f(f_tmp)
        label = "{:d} kcal/mol at {:d} pN".format(W_int, f_tmp)
        plt.axhline(W_int, label=label, color=colors[i], linestyle='--')
    xlabel = "$F$ (pN) [! not extension !]"
    PlotUtilities.lazyLabel(xlabel, W_str + "\n(kcal/mol)", "")
Ejemplo n.º 8
0
def make_retinal_subplot(gs,
                         energy_list_arr,
                         shifts,
                         skip_arrow=True,
                         limit_plot=None):
    q_interp_nm = energy_list_arr[0].q_nm
    means = [e.G0_kcal_per_mol for e in energy_list_arr]
    # fit a second order polynomial and subtract from each point
    q_fit_nm_relative = 7
    max_fit_idx = \
        np.argmin(np.abs((q_interp_nm - q_interp_nm[0]) - q_fit_nm_relative))
    fits = []
    fit_pred_arr = []
    for m in means:
        fit = np.polyfit(x=q_interp_nm[:max_fit_idx], y=m[:max_fit_idx], deg=2)
        fits.append(fit)
        fit_pred = np.polyval(fit, x=q_interp_nm)
        fit_pred_arr.append(fit_pred)
    stdevs = [e.G_err_kcal for e in energy_list_arr]
    ax1 = plt.subplot(gs[0])
    common_error = dict(capsize=0)
    style_dicts = [
        dict(color=FigureUtil.color_BR(), label=r"with retinal"),
        dict(color=FigureUtil.color_BO(), label=r"w/o  retinal")
    ]
    markers = ['v', 'x']
    deltas, deltas_std = [], []
    delta_styles = [
        dict(color=style_dicts[i]['color'],
             markersize=5,
             linestyle='None',
             marker=markers[i],
             **common_error) for i in range(len(energy_list_arr))
    ]
    xlim = [None, 27]
    ylim = [-25, 450]
    q_arr = []
    round_energy = -1
    max_q_nm = max(q_interp_nm)
    # add the 'shifted' energies
    for i, (mean,
            stdev) in enumerate(zip(means[:limit_plot], stdevs[:limit_plot])):
        tmp_style = style_dicts[i]
        style_fit = dict(**tmp_style)
        style_fit['linestyle'] = '--'
        style_fit['label'] = None
        corrected = mean - fit_pred_arr[i]
        plt.plot(q_interp_nm, mean, **tmp_style)
        plt.fill_between(x=q_interp_nm,
                         y1=mean - stdev,
                         y2=mean + stdev,
                         color=tmp_style['color'],
                         linewidth=0,
                         alpha=0.3)
        energy_error = np.mean(stdev)
        max_idx = -1
        q_at_max_energy = q_interp_nm[max_idx]
        max_energy_mean = corrected[max_idx]
        # for the error, use the mean error over all interpolation
        max_energy_std = energy_error
        deltas.append(max_energy_mean)
        deltas_std.append(max_energy_std)
        q_arr.append(q_at_max_energy)
    plt.xlim(xlim)
    plt.ylim(ylim)
    PlotUtilities.lazyLabel("Extension (nm)", "$\mathbf{\Delta}G$ (kcal/mol)",
                            "")
    leg = PlotUtilities.legend(loc='lower right')
    colors_leg = [s['color'] for s in style_dicts]
    PlotUtilities.color_legend_items(leg, colors=colors_leg[:limit_plot])
    return ax1, means, stdevs