Exemplo n.º 1
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]
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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.º 5
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")
Exemplo n.º 6
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")
Exemplo 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)", "")
Exemplo n.º 8
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.º 9
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)
Exemplo n.º 10
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"))