示例#1
0
def hao_plot_inf(ext_grid):
    fec_system = WLC._make_plot_inf(ext_grid,
                                    WLC.read_haos_data,
                                    base="../../FigData/")
    fec_polypeptide = WLC._make_plot_inf(ext_grid,
                                         WLC.read_hao_polypeptide,
                                         base="../../FigData/")
    return fec_system, fec_polypeptide
示例#2
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
示例#3
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)", "")
示例#4
0
def _debug_plot(to_ret):
    plt.close()
    inf = to_ret.L0_info
    fit_slice = inf.fit_slice
    x, f = to_ret.Separation, to_ret.Force
    # get a grid over all possible forces
    f_grid = np.linspace(min(f), max(f), num=f.size, endpoint=True)
    # get the extension components
    ext_total, ext_components = WLCHao._hao_shift(f_grid, *inf.x0,
                                                  **inf.kw_fit)
    # determine the
    plt.plot(x, f, color='k', alpha=0.3)
    plt.plot(x[fit_slice], f[fit_slice], 'r')
    plt.plot(ext_total, f_grid, 'b--')
    for c in ext_components:
        plt.plot(c, f_grid)
    plt.xlim([min(x), 150e-9])
    plt.axvline(inf.x0[-1])
    plt.show()
示例#5
0
def align_single(d,min_F_N,**kw):
    """
    :param d: FEC to get FJC+WLC fit of
    :param min_F_N: minimum force, in Newtons, for fitting event. helps avoid
     occasional small force events
    :param kw: keywords to use for fitting...
    :return:
    """
    force_N = d.Force
    pred_info = d.info_feather
    max_fit_idx = GF2_event_idx(d,min_F_N)
    # determine the minimum fit index by the maximum of...
    # (1) the surface
    where_above_surface = np.where(force_N >= 0)[0]
    assert where_above_surface.size > 0 , "Never above surface"
    first_time_above_surface = where_above_surface[0]
    assert first_time_above_surface < max_fit_idx , \
        "Couldn't find fitting region"
    # (2) the last event *before* the current, if it exists
    event_idx = pred_info.event_idx
    idx_last_event_before = np.where(event_idx < max_fit_idx)[0]
    start_idx = first_time_above_surface
    if idx_last_event_before.size > 0:
        # then we have an event *before* the final GC helix one.
        # make that the start idx, if it is later (it should be!)
        new_start = event_idx[idx_last_event_before[-1]]
        assert new_start > start_idx , "First event is less than surface?!"
        start_idx = new_start
    # start the fit after any potential adhesions
    fit_start = max(start_idx,pred_info.slice_fit.start)
    fit_slice = slice(fit_start,max_fit_idx,1)
    # slice the object to just the region we want
    obj_slice = d._slice(fit_slice)
    # fit wlc to the f vs x of that slice
    info_fit = WLCHao.hao_fit(obj_slice.Separation,obj_slice.Force,**kw)
    info_fit.fit_slice = fit_slice
    to_ret = ProcessingUtil.AlignedFEC(d,info_fit,feather_info=pred_info)
    return to_ret
示例#6
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"))
示例#7
0
def _offset_L_m():
    return (WLCHao._L0_tail())