Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def make_comparison_plot(q_interp,
                         energy_list_arr,
                         G_no_peg,
                         add_annotations,
                         limit_plot=None):
    landscpes_with_error = \
        FigureUtil._get_error_landscapes(q_interp, energy_list_arr)
    # get the extension grid we wnt...
    ext_grid = np.linspace(0, 25, num=100)
    # read in Hao's energy landscape
    fec_system = WLC._make_plot_inf(ext_grid, WLC.read_haos_data)
    shifts = [fec_system.W_at_f(f) for f in [249, 149]]
    gs = gridspec.GridSpec(nrows=1, ncols=1)
    ax1, means, stdevs = \
        make_retinal_subplot(gs,landscpes_with_error,shifts,
                             limit_plot=limit_plot)
    # get the with-retinal max
    ax1 = plt.subplot(gs[0])
    # get the max of the last point (the retinal energy landscape is greater)
    offsets = [l.G0_kcal_per_mol[-1] for l in landscpes_with_error]
    q_no_PEG_start = max(q_interp)
    q_nm_no_PEG = G_no_peg.q_nm + q_no_PEG_start
    G_err_kcal_no_PEG = G_no_peg.G_err_kcal
    for i, G_offset in enumerate(offsets[:limit_plot]):
        G_kcal = G_no_peg.G0_kcal_per_mol + G_offset
        mean_err = np.mean(G_err_kcal_no_PEG)
        idx_errorbar = q_nm_no_PEG.size // 2
        common_style = dict(color='grey', linewidth=1.5)
        ax1.plot(q_nm_no_PEG, G_kcal, linestyle='--', **common_style)
        if (i != 0):
            continue
        ax1.errorbar(q_nm_no_PEG[idx_errorbar],
                     G_kcal[idx_errorbar],
                     yerr=mean_err,
                     marker=None,
                     markersize=0,
                     capsize=3,
                     **common_style)
    axes = [ax1]
    ylim = [None,
            np.max(offsets) + max(G_no_peg.G0_kcal_per_mol) + \
            G_err_kcal_no_PEG[-1]*4]
    for a in axes:
        a.set_ylim(ylim)
        a.set_xlim([None, max(q_nm_no_PEG)])
    # add in the scale bar
    ax = axes[0]
    xlim = ax.get_xlim()
    ylim = ax.get_ylim()
    y_range = (ylim[1] - ylim[0])
    range_scale_kcal = np.round(y_range / 3, -2)
    x_range_scalebar_nm = 20
    min_offset, _, rel_delta = Scalebar. \
        offsets_zero_tick(limits=ylim,range_scalebar=range_scale_kcal)
    min_offset_x, _, rel_delta_x= Scalebar. \
        offsets_zero_tick(limits=xlim,range_scalebar=x_range_scalebar_nm)
    offset_x = 0.25
    offset_y = min_offset + 1 * rel_delta
    common_kw = dict(add_minor=True)
    scalebar_kw = dict(offset_x=offset_x,
                       offset_y=offset_y,
                       ax=ax,
                       x_on_top=True,
                       y_on_right=False,
                       x_kwargs=dict(width=x_range_scalebar_nm,
                                     unit="nm",
                                     **common_kw),
                       y_kwargs=dict(height=range_scale_kcal,
                                     unit="kcal/mol",
                                     **common_kw))
    PlotUtilities.no_x_label(ax=ax)
    PlotUtilities.no_y_label(ax=ax)
    Scalebar.crossed_x_and_y_relative(**scalebar_kw)
    # add the helical boxes
    offset_boxes_nm = -25
    FigureUtil.add_helical_boxes(ax=ax1,
                                 ymax_box=0.97,
                                 box_height=0.07,
                                 constant_offset=offset_boxes_nm,
                                 clip_on=True)
    delta_delta_G_total = np.abs(np.diff(offsets))[0]
    delta_delta_G_linker = np.abs(np.diff(shifts))[0]
    if add_annotations:
        str_text = " $\mathbf{\Delta\Delta}G_{\mathbf{Total}}$"
        min_o = min(offsets)
        xy = q_no_PEG_start, min_o
        xy_end = q_no_PEG_start, min_o + delta_delta_G_total
        labelled_arrow(ax1, str_text, xy, xy_end)
        str_dd = " $\mathbf{\Delta\Delta}G_{\mathbf{Linker}}$"
        xlim = plt.xlim()
        x_range = (xlim[1] - xlim[0])
        x0 = np.mean(xlim) + x_range * 0.05
        y0 = min_o
        y1 = min_o + delta_delta_G_linker
        xy2 = x0, y0
        xy_end2 = x0, y1
        labelled_arrow(ax1,
                       str_dd,
                       xy2,
                       xy_end2,
                       color_arrow='r',
                       y_text_fudge=0.0)
    # # save out the data
    preamble = "FigureS6"
    X = np.array([delta_delta_G_total, delta_delta_G_linker]).reshape((1, -1))
    np.savetxt(fname=preamble + "_ddG.csv",
               X=X,
               fmt=["%.1f", "%.1f"],
               delimiter=",",
               header="ddG_total (kcal/mol), ddG_linker (kcal/mol)")
    # save out the landscapes
    x_y_yerr_name = [[q_interp, landscpes_with_error[0], preamble + "_BR"],
                     [q_interp, landscpes_with_error[1], preamble + "_BO"]]
    for x, l, name in x_y_yerr_name:
        y = l.G0_kcal_per_mol
        yerr = l.G_err_kcal
        Record.save_csv(
            dict(x=x,
                 y=[y, yerr],
                 save_name=name,
                 x_name="q",
                 x_units="nm",
                 y_name=["Energy", "Energy Error"],
                 y_units="kcal/mol"))
    # save out the remainder of the BO
    G_kcal_PEG_tmp = G_no_peg.G0_kcal_per_mol + max(offsets)
    Record.save_csv(
        dict(x=q_nm_no_PEG,
             y=[G_kcal_PEG_tmp, G_err_kcal_no_PEG],
             save_name=preamble + "_JCP_no_PEG",
             x_name="q",
             x_units="nm",
             y_name=["Energy", "Energy Error"],
             y_units="kcal/mol"))