示例#1
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    input_dir = "../../../Data/FECs180307/"
    out_dir = "./"
    force = True
    q_interp, energy_list_arr, q_offset_nm,n_fecs = \
        CheckpointUtilities.getCheckpoint("./cache.pkl",read_data,
                                          force,input_dir)
    G_no_peg = FigureUtil.read_non_peg_landscape()
    #_giant_debugging_plot(out_dir, energy_list_arr)
    base = out_dir + "FigureS6_LandscapeComparison"
    kw_name_arr = [
        [dict(add_annotations=True), base],
        [dict(add_annotations=False), base + "_0"],
        [dict(add_annotations=False, limit_plot=1), base + "_1"],
    ]
    for kw, name in kw_name_arr:
        fig = PlotUtilities.figure(figsize=(3, 3))
        make_comparison_plot(q_interp, energy_list_arr, G_no_peg, **kw)
        base = name
        PlotUtilities.save_twice(fig, base + ".jpeg", base + ".svg")
示例#2
0
def run():
    input_dir = "../../../../Data/FECs180307/"
    out_dir = "./"
    q_offset_nm = 100
    q_interp, energy_list_arr, _ = FigureUtil.\
        _read_energy_list_and_q_interp(input_dir, q_offset=q_offset_nm,
                                       min_fecs=9)
    # read in some example data
    base_dir_BR = input_dir + "BR+Retinal/"
    names_BR = ["/BR+Retinal/3000nms/170503FEC/landscape_"]
    PEG600 = FigureUtil._read_samples(base_dir_BR,names_BR)[0]
    # read in the FECs
    fecs = FigureUtil._snapsnot(PEG600.base_dir,
                                step=Pipeline.Step.REDUCED).fec_list
    args_mean = (energy_list_arr, q_interp)
    mean_A = mean_A_jarzynski(*args_mean)
    mean_G = mean_G_iwt(*args_mean)
    mean_F_from_dot = mean_A_dot_iwt(*args_mean)[0]
    ex = fecs[0]
    q = q_interp * 1e-9
    # xxx offset q and z... probably a little off!
    z = ex.ZFunc(ex) + q[0]
    k = ex.SpringConstant
    beta = ex.Beta
    A = mean_A[0]
    G = mean_G[0]
    n_iters = 5000
    force =True
    kw_lr = dict(G0=G, A=A, q=q, z=z, k=k, beta=beta,n_iters=n_iters)
    lr = CheckpointUtilities.getCheckpoint("./lr_deconv.pkl",
                                           _deconvoled_lr,force,**kw_lr)
    diff_kT = np.array(lr.mean_diffs) * beta
    min_idx = np.argmin(diff_kT)
    idx_search = np.logspace(start=3,stop=np.floor(np.log2(min_idx)),
                             endpoint=True,num=10,base=2)
    idx_to_use = [int(i) for i in idx_search]
    # fit a spline to the converged G to get the mean restoring force
    fig = PlotUtilities.figure((4,6))
    xlim = [min(q_interp)-5, max(q_interp)]
    fmt_kw = dict(xlim=xlim,ylim=[None,None])
    ax1 = plt.subplot(3,1,1)
    plt.plot(diff_kT)
    plt.axvline(min_idx)
    FigureUtil._plot_fmt(ax1,is_bottom=True,xlabel="iter #",
                         ylabel="diff G (kT)",xlim=[None,None],ylim=[None,None])
    ax2 = plt.subplot(3,1,2)
    plt.plot(q_interp,lr._G0_initial_lr.G0_kT,color='b',linewidth=3)
    plt.plot(q_interp,lr.G0_kT,color='r',linewidth=3)
    FigureUtil._plot_fmt(ax2,is_bottom=False,ylabel="G (kT)",**fmt_kw)
    ax1 = plt.subplot(3,1,3)
    FigureUtil._plot_fec_list(fecs, xlim, ylim=[None,None])
    for i in idx_to_use:
        _plot_f_at_iter_idx(lr, i)
    _plot_f_at_iter_idx(lr, 0,label="F from G0",linewidth=4)
    plt.plot(q_interp,mean_F_from_dot*1e12,label="F from A_z_dot",linewidth=2)
    # also plot the force we expect from the original A_z_dot
    FigureUtil._plot_fmt(ax1,is_bottom=True,xlim=xlim,ylim=[None,None])
    PlotUtilities.legend()
    PlotUtilities.savefig(fig,"FigureS_A_z.png")
    pass
示例#3
0
def _G0_plot(plot_dir, data_sliced, landscape, fmt):
    # XXX why is this necessary?? screwing up absolute values
    previous_JCP = FigureUtil.read_non_peg_landscape(base="../../FigData/")
    offset_s = np.mean([d.Separation[0] for d in data_sliced])
    G_hao = landscape.G0_kcal_per_mol
    idx_zero = np.where(landscape.q_nm <= 100)
    G_hao = G_hao - landscape.G0_kcal_per_mol[0]
    G_JCP = previous_JCP.G0_kcal_per_mol - previous_JCP.G0_kcal_per_mol[0] + 50
    offset_jcp_nm = min(previous_JCP.q_nm)
    landscape_offset_nm = min(landscape.q_nm)
    q_JCP_nm = previous_JCP.q_nm - offset_jcp_nm + 5
    q_Hao_nm = landscape.q_nm - landscape_offset_nm
    fig = FigureUtil._fig_single(y=6)
    xlim, ylim = FigureUtil._limits(data_sliced)
    ax1 = plt.subplot(2, 1, 1)
    FigureUtil._plot_fec_list(data_sliced, **fmt)
    FigureUtil._plot_fmt(ax1, **fmt)
    ax2 = plt.subplot(2, 1, 2)
    plt.plot(q_Hao_nm, G_hao, label="Aligned, IWT")
    plt.plot(q_JCP_nm, G_JCP, 'r--', label="JCP landscape")
    FigureUtil._plot_fmt(ax2,
                         ylabel="G (kcal/mol)",
                         is_bottom=True,
                         xlim=xlim,
                         ylim=[None, None])
    PlotUtilities.legend(ax=ax2, handlelength=2)
    ax2.set_xlim(fmt['xlim'])
    PlotUtilities.savefig(fig, plot_dir + "FigureSX_LandscapeComparison.png")
示例#4
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    base_dir = RetinalUtil._landscape_base()
    step = Pipeline.Step.POLISH
    in_dir = Pipeline._cache_dir(base=base_dir, enum=Pipeline.Step.REDUCED)
    out_dir = Pipeline._cache_dir(base=base_dir, enum=step)
    force = True
    limit = None
    functor = lambda: generate_landscape(in_dir)
    energy_obj = CheckpointUtilities.\
        getCheckpoint(filePath=out_dir + "energy.pkl",
                      orCall=functor,force=force)
    data = CheckpointUtilities.lazy_multi_load(in_dir)
    # also load all the data
    fig = PlotUtilities.figure((3, 6))
    PlotUtil.plot_landscapes(data, energy_obj)
    PlotUtilities.savefig(fig, out_dir + "out_G.png")
    pass
示例#5
0
def make_aligned_plot(base_dir, step, data, xlim=None, post="", **kw):
    plot_subdir = Pipeline._plot_subdir(base_dir, step)
    f_x = lambda x: x.Separation
    xlim_tmp, ylim = nm_and_pN_limits(data, f_x)
    xlim = [xlim[0], 200] if xlim is None else xlim
    name_func = FEC_Util.fec_name_func
    for i, d in enumerate(data):
        f = PlotUtilities.figure()
        _aligned_plot(d, f_x, xlim, ylim, i=i, **kw)
        PlotUtilities.savefig(f, plot_subdir + name_func(0, d) + post + ".png")
示例#6
0
def polish_plot(ax1,ax2,d_unpolish,d_polish,xlim,ylim,f_x,plot_components_1,i):
    plt.sca(ax1)
    kw_plot = dict(f_x=f_x,xlim=xlim,ylim=ylim,use_shift=True,i=i)
    ProcessingUtil._aligned_plot(d_unpolish, plot_components=plot_components_1,
                                 **kw_plot)
    PlotUtilities.xlabel("")
    PlotUtilities.no_x_label(ax1)
    plt.sca(ax2)
    ProcessingUtil._aligned_plot(d_polish, plot_components=False,
                                 **kw_plot)
示例#7
0
def _make_algned_plot(alignment, label):
    fig = PlotUtilities.figure((3, 4))
    gs = gridspec.GridSpec(3, 2)
    # make the 'standard' alignment plots
    axes = _heatmap_alignment(gs, alignment, 0)
    _ensemble_alignment(gs, alignment, 1)
    out_name = "./FigureS_Alignment_{:s}.png".format(label)
    PlotUtilities.title(label, ax=axes[0])
    PlotUtilities.savefig(fig,
                          out_name,
                          subplots_adjust=dict(hspace=0.12, wspace=0.02))
示例#8
0
def _feather_plot(data,plot_subdir,f_x = lambda x: x.Separation,
                  xlim=[-20, 150]):
    _, ylim = ProcessingUtil.nm_and_pN_limits(data, f_x=f_x)
    for i,d in enumerate(data):
        fig = PlotUtilities.figure()
        ProcessingUtil.plot_single_fec(d, f_x, xlim, ylim, markevery=1,
                                       i=i)
        x = f_x(d) * 1e9
        for i in d.info_feather.event_idx:
            plt.axvline(x[i])
        name = FEC_Util.fec_name_func(0,d)
        PlotUtilities.savefig(fig,plot_subdir + name + ".png")
示例#9
0
def _ensemble_alignment(gs, alignment, col_idx):
    xlim, ylim = FigureUtil._limits(alignment._all_fecs)
    common_kw = dict(xlim=xlim, ylim=ylim)
    kw_fmt = dict(color=False, is_left=(col_idx == 0), **common_kw)
    ax1 = plt.subplot(gs[0, col_idx])
    FigureUtil._plot_fec_list(alignment.zeroed.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax1, **kw_fmt)
    ax2 = plt.subplot(gs[1, col_idx])
    FigureUtil._plot_fec_list(alignment.polished.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax2, **kw_fmt)
    PlotUtilities.no_x_label(ax=ax2)
    ax3 = plt.subplot(gs[2, col_idx])
    FigureUtil._plot_fec_list(alignment.blacklisted.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax3, is_bottom=True, **kw_fmt)
示例#10
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    model, descr = WLC.Hao_PEGModel, "Hao_Parameters",
    fig = PlotUtilities.figure((4, 6))
    plot_inf = WLC._make_plot_inf(ext_grid=np.linspace(0, 30, num=3000),
                                  read_functor=WLC.read_haos_data,
                                  base="../../FigData/")
    make_model_plot(plot_inf=plot_inf, title=descr)
    PlotUtilities.savefig(fig, "PEG_{:s}.png".format(descr))
    # make sure what we have matches Hao.
    fig = PlotUtilities.figure((2.5, 4))
    make_comparison_plot()
    plt.xlim([0, 35])
    plt.ylim([0, 300])
    PlotUtilities.legend(frameon=True)
    PlotUtilities.savefig(fig, "out_compare.png")
    pass
def _fec_demo_plot(energy_list, out_dir):
    fecs = []
    energies = []
    N = len(energy_list)
    for e in energy_list:
        data = RetinalUtil.read_fecs(e)
        fecs.append(data)
        energies.append(e)
    n_cols = N
    fig = PlotUtilities.figure((n_cols * 1, 6))
    FigureUtil.data_plot(fecs, energies, xlim=[-20, 100])
    PlotUtilities.savefig(fig,
                          out_dir + "energies.png",
                          subplots_adjust=dict(hspace=0.02, wspace=0.04))
def _energy_plot(energy_list, out_dir):
    # interpolate all the energies to the same grid
    energies_plot = [e._iwt_obj for e in energy_list]
    q_interp, splines = RetinalUtil.interpolating_G0(energies_plot)
    # get an average/stdev of energy
    fig = PlotUtilities.figure((7, 7))
    ax = plt.subplot(1, 1, 1)
    PlotUtil.plot_mean_landscape(q_interp, splines, ax=ax)
    min_x_show_nm = int(np.floor(min(q_interp) - 2))
    max_x_show_nm = min_x_show_nm + 20

    plt.xlim([min_x_show_nm, max_x_show_nm])
    plt.xticks([i for i in range(min_x_show_nm, max_x_show_nm)])
    ax.xaxis.set_ticks_position('both')
    ax.grid(True)
    PlotUtilities.savefig(fig, out_dir + "avg.png")
示例#13
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
示例#14
0
def _giant_debugging_plot(out_dir, energy_list_arr):
    fig = PlotUtilities.figure((8, 12))
    gs = gridspec.GridSpec(nrows=2, ncols=1, hspace=0.15)
    n_cols = max([len(list_v) for list_v in energy_list_arr])
    for i, energy_list in enumerate(energy_list_arr):
        fecs = []
        energies = []
        for e in energy_list:
            data = RetinalUtil.read_fecs(e)
            fecs.append(data)
            energies.append(e)
        gs_tmp = gridspec.GridSpecFromSubplotSpec(nrows=3,
                                                  ncols=n_cols,
                                                  subplot_spec=gs[i])
        FigureUtil.data_plot(fecs, energies, gs1=gs_tmp, xlim=[-20, 100])
    PlotUtilities.savefig(fig,
                          out_dir + "FigureS_Mega_Debug.png",
                          subplots_adjust=dict(hspace=0.02, wspace=0.04))
示例#15
0
def data_plot(fecs, energies, gs1=None, xlim=[None, None]):
    n_cols = len(energies)
    n_rows = 2
    all_ax = []
    if gs1 is None:
        gs1 = gridspec.GridSpec(n_rows + 1, n_cols)
    for i, (data, e) in enumerate(zip(fecs, energies)):
        axs_tmp = [plt.subplot(gs1[j, i]) for j in range(n_rows)]
        ax1, ax2 = axs_tmp
        PlotUtil.plot_landscapes(data, e, ax1=ax1, ax2=ax2)
        # every axis after the first gets more of the decoaration chopped...
        all_ax.append(axs_tmp)
        # XXX should really put this into the meta class...
        plt.sca(ax1)
        tmp_str = e.file_name
        match = re.search(
            r"""
                          ([\w+-]+Retinal)/([\d\w]+)/([\d\w]+)/
                          """, tmp_str, re.IGNORECASE | re.VERBOSE)
        assert match is not None
        groups = match.groups()
        BR, velocity, title = groups
        vel_label = velocity.replace("nms", "")
        title_label = title.replace("FEC", "")
        title = "{:s}, v={:s}\n {:s}".format(BR, vel_label, title_label)
        PlotUtilities.title(title, fontsize=5)
        for a in axs_tmp:
            a.set_xlim(xlim)
    fix_axes(all_ax)
    xlim = all_ax[0][0].get_xlim()
    # just get the IWT
    energies_plot = [e._iwt_obj for e in energies]
    q_interp, splines = RetinalUtil.interpolating_G0(energies_plot)
    # get an average/stdev of energy
    ax = plt.subplot(gs1[-1, 0])
    mean_energy, std_energy = PlotUtil.plot_mean_landscape(q_interp,
                                                           splines,
                                                           ax=ax)
    max_q_nm = RetinalUtil.q_GF_nm_plot()
    q_at_max_energy,_,_ =  \
        PlotUtil.plot_delta_GF(q_interp,mean_energy,std_energy,
                               max_q_nm=max_q_nm)
    plt.axvspan(q_at_max_energy, max(xlim), color='k', alpha=0.3)
    ax.set_xlim(xlim)
示例#16
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))
示例#17
0
def _plot_comparison(plot_dir, heatmap_jcp, iwt_obj, data_sliced_plot):
    fmt = dict(xlim=[-20, 55], ylim=[-20, 150])
    _G0_plot(plot_dir, data_sliced_plot, iwt_obj, fmt=fmt)
    fig = FigureUtil._fig_single(y=6)
    ax1 = plt.subplot(2, 1, 1)
    extent = heatmap_jcp._extent_nm_and_pN(offset_x_nm=0)
    plt.imshow(heatmap_jcp.heatmap,
               origin='lower',
               aspect='auto',
               extent=extent,
               cmap=plt.cm.afmhot)
    FigureUtil._plot_fmt(is_bottom=False, ax=ax1, **fmt)
    PlotUtilities.title("Top: JCP.\n Bottom: New data, - PEG3400")
    ax2 = plt.subplot(2, 1, 2)
    FEC_Plot.heat_map_fec(data_sliced_plot,
                          use_colorbar=False,
                          num_bins=(150, 75),
                          separation_max=fmt['xlim'][1])
    FigureUtil._plot_fmt(is_bottom=True, ax=ax2, **fmt)
    out_name = plot_dir + "FigureSX_jcp_fec_comparison.png"
    PlotUtilities.savefig(fig, out_name, tight=True)
示例#18
0
def _heatmap_alignment(gs, alignment, col_idx):
    xlim, ylim = FigureUtil._limits(alignment._all_fecs)
    max_x = xlim[1]
    bin_step_nm = 1
    bin_step_pN = 5
    bins_x = np.arange(xlim[0], xlim[1] + bin_step_nm, step=bin_step_nm)
    bins_y = np.arange(ylim[0], ylim[1] + bin_step_pN, step=bin_step_pN)
    common_kw = dict(separation_max=max_x,
                     use_colorbar=False,
                     title="",
                     bins=(bins_x, bins_y))
    ax1 = plt.subplot(gs[0, col_idx])
    FEC_Plot.heat_map_fec(alignment.zeroed.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax1, xlim, ylim, color=True)
    ax2 = plt.subplot(gs[1, col_idx])
    FEC_Plot.heat_map_fec(alignment.polished.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax2, xlim, ylim, color=True)
    title_kw = dict(color='b', y=0.95, loc='left', fontsize=6)
    downarrow = "$\Downarrow$"
    title_sub = downarrow + " Subtract $X_{\mathbf{PEG3400}}(F)$ + " + \
                "$L_{\mathbf{0,C-term}}$"
    PlotUtilities.title(title_sub, **title_kw)
    PlotUtilities.no_x_label(ax=ax2)
    ax3 = plt.subplot(gs[2, col_idx])
    FEC_Plot.heat_map_fec(alignment.blacklisted.fec_list, **common_kw)
    FigureUtil._plot_fmt(ax3, xlim, ylim, is_bottom=True, color=True)
    PlotUtilities.title(downarrow + " Remove poorly-fit FECs", **title_kw)
    return [ax1, ax2, ax3]
示例#19
0
def fix_axes(ax_list):
    # loop through all the axes and toss them.
    xlims = get_ranges(ax_list, get_x=True)
    ylims = get_ranges(ax_list, get_x=False)
    for i, axs in enumerate(ax_list):
        for j, ax in enumerate(axs):
            if (i > 0):
                # columns after the first lose their labels
                PlotUtilities.no_y_label(ax)
                PlotUtilities.ylabel("", ax=ax)
            ax.set_ylim(ylims[j])
            if (j != 0):
                PlotUtilities.no_x_label(ax)
                PlotUtilities.xlabel("", ax=ax)
示例#20
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")
示例#21
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")
示例#22
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)", "")
示例#23
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)", "")
示例#24
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)
示例#25
0
def _make_plots(galleries_labels):
    alignments = [
        FigureUtil._alignment_pipeline(gallery_tmp[0])
        for gallery_tmp in galleries_labels
    ]
    for i, (_, label) in enumerate(galleries_labels):
        # make the standard aligning plot
        alignment = alignments[i]
        _make_algned_plot(alignment, label)
    # plot the final curves on the same plot
    xlim, ylim = FigureUtil._limits(alignment._all_fecs)
    colors = ['rebeccapurple', 'g']
    fig = PlotUtilities.figure((5, 3))
    gs = gridspec.GridSpec(2, 2)
    # reverse everything, so PEG600 is on top
    galleries_labels = galleries_labels[::-1]
    alignments = alignments[::-1]
    for i, (_, l) in enumerate(galleries_labels):
        ax = plt.subplot(gs[i, 0])
        a = alignments[i]
        FigureUtil._plot_fec_list(a.blacklisted.fec_list,
                                  xlim,
                                  ylim,
                                  label=l,
                                  color=colors[i])
        if (i == 0):
            PlotUtilities.no_x_label(ax)
            PlotUtilities.xlabel("", ax=ax)
    # plot them both on the last column
    plt.subplot(gs[:, 1])
    kw = [dict(), dict(linewidth=0.6)]
    for i, (_, l) in enumerate(galleries_labels):
        a = alignments[i]
        FigureUtil._plot_fec_list(a.blacklisted.fec_list,
                                  xlim,
                                  ylim,
                                  label=l,
                                  color=colors[i],
                                  **kw[i])
    PlotUtilities.savefig(fig, "FigureS_3400vs600.png")
示例#26
0
def _make_work_plot(fec_list,x_arr,works_kcal,gs,col,color,title):
    # get the interpolated work
    x_interp, mean_W, std_W = _mean_work(x_arr, works_kcal)
    # use Davids function
    shift_david_nm_plot = 10
    L0_david = 11e-9
    max_david = L0_david * 0.95
    x_david = np.linspace(0,max_david,num=100)
    style_david = dict(color='b',linestyle='--',label="David")
    legend_kw = dict(handlelength=1.5,handletextpad=0.3,fontsize=6)
    david_F = _f_david(kbT=4.1e-21, L0=L0_david, Lp=0.4e-9, x=x_david)
    david_W = _single_work(x=x_david,f=david_F)
    x_david_plot = x_david * 1e9 - shift_david_nm_plot
    W_david_plot = david_W * kcal_per_mol_per_J()
    f_david_plot = david_F * 1e12
    is_left = (col == 0)
    fmt_kw = dict(is_left=is_left)
    label_work = "$W$ (kcal/mol)"
    # interpolate each work onto a grid
    xlim, ylim, ylim_work = xlim_ylim()
    fudge_work = max(std_W)
    ax1 = plt.subplot(gs[0,col])
    FigureUtil._plot_fec_list(fec_list,xlim,ylim)
    plt.plot(x_david_plot,f_david_plot,**style_david)
    if is_left:
        PlotUtilities.legend(**legend_kw)
    FigureUtil._plot_fmt(ax1, xlim, ylim,**fmt_kw)
    PlotUtilities.title(title,color=color)
    ax2 = plt.subplot(gs[1,col])
    for x,w in zip(x_arr,works_kcal):
        plt.plot(x * 1e9,w,linewidth=0.75)
    FigureUtil._plot_fmt(ax2, xlim, ylim_work,ylabel=label_work,**fmt_kw)
    ax3 = plt.subplot(gs[2,col])
    _plot_mean_works(x_interp, mean_W, std_W, color, title)
    style_lower_david = dict(**style_david)
    if (not is_left):
        style_lower_david['label'] = None
    plt.plot(x_david_plot,W_david_plot,'b--',zorder=5,**style_lower_david)
    PlotUtilities.legend(**legend_kw)
    FigureUtil._plot_fmt(ax3, xlim, ylim_work,is_bottom=True,
                         ylabel=label_work,**fmt_kw)
示例#27
0
def _plot_fmt(ax,
              xlim,
              ylim,
              is_bottom=False,
              color=False,
              is_left=True,
              ylabel="$F$ (pN)",
              xlabel="Extension (nm)"):
    PlotUtilities.tickAxisFont(ax=ax)
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
    PlotUtilities.title("", ax=ax)
    PlotUtilities.ylabel(ylabel, ax=ax)
    PlotUtilities.xlabel(xlabel, ax=ax)
    if (not is_bottom):
        PlotUtilities.no_x_label(ax=ax)
        PlotUtilities.xlabel("", ax=ax)
    if (not is_left):
        PlotUtilities.no_y_label(ax=ax)
        PlotUtilities.ylabel("", ax=ax)
    if color:
        color_kw = dict(ax=ax, color='w', label_color='k')
        PlotUtilities.color_x(**color_kw)
        PlotUtilities.color_y(**color_kw)
示例#28
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    default_base = "../../../Data/170321FEC/"
    base_dir = Pipeline._base_dir_from_cmd(default=default_base)
    step = Pipeline.Step.POLISH
    in_dir = Pipeline._cache_dir(base=base_dir, enum=Pipeline.Step.ALIGNED)
    out_dir = Pipeline._cache_dir(base=base_dir,enum=step)
    plot_dir = Pipeline._plot_subdir(base=base_dir, enum=step)
    force = True
    limit = None
    functor = lambda : polish_data(in_dir)
    data =CheckpointUtilities.multi_load(cache_dir=out_dir,load_func=functor,
                                         force=force,
                                         limit=limit,
                                         name_func=FEC_Util.fec_name_func)
    sizes = [d.Force.size for d in data]
    min_s = min(sizes)
    sliced_data = [d._slice(slice(0,min_s,1)) for d in data]
    for d in sliced_data:
        d.Offset = d.ZSnsr[0]
        d.Extension = d.Separation
        d.kT = 4.1e-21
    data_wham = UtilWHAM.to_wham_input(objs=sliced_data, n_ext_bins=75)
    data_wham.z = np.array([d.ZSnsr for d in sliced_data])
    obj_wham = WeightedHistogram.wham(data_wham)
    data_unpolished = CheckpointUtilities.lazy_multi_load(in_dir)
    f_x_zsnsr = lambda x: x.ZSnsr
    xlim = [-40,150]
    ProcessingUtil.heatmap_ensemble_plot(data,out_name=plot_dir + "heatmap.png",
                                         xlim=xlim)
    ProcessingUtil.heatmap_ensemble_plot(data,f_x=f_x_zsnsr,
                                         out_name=plot_dir + "heatmap_Z.png",
                                         kw_map=dict(x_func=f_x_zsnsr),
                                         xlim=xlim)
    # plot each individual
    f_x = lambda x_tmp : x_tmp.Separation
    plot_subdir = Pipeline._plot_subdir(base_dir, step)
    name_func = FEC_Util.fec_name_func
    _, ylim = ProcessingUtil.nm_and_pN_limits(data,f_x)
    for i,(d_unpolish,d_polish) in enumerate(zip(data_unpolished,data)):
        kw_plot = dict(d_unpolish=d_unpolish,
                       d_polish=d_polish,
                       xlim=xlim,ylim=ylim,i=i)
        fig = PlotUtilities.figure((6,6))
        # make the Separation column
        ax1,ax2 = plt.subplot(2,2,1), plt.subplot(2,2,3)
        polish_plot(ax1, ax2, f_x = lambda x: x.Separation,
                    plot_components_1=True,**kw_plot)
        # make the ZSnsr column
        ax3,ax4 = plt.subplot(2,2,2), plt.subplot(2,2,4)
        polish_plot(ax3, ax4, f_x = lambda x: x.ZSnsr,plot_components_1=False,
                    **kw_plot)
        PlotUtilities.xlabel("Stage Position (nm)", ax=ax4)
        for a in [ax3,ax4]:
            PlotUtilities.no_y_label(ax=a)
            PlotUtilities.ylabel("",ax=a)
        name = plot_subdir + name_func(0, d_polish) + ".png"
        PlotUtilities.savefig(fig,name)
示例#29
0
def _fig_single(y=3.3):
    return PlotUtilities.figure((3.3, y))
示例#30
0
def _fig_double(y=3.3):
    return PlotUtilities.figure((7, y))