Exemple #1
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 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
Exemple #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")
Exemple #4
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)
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