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(): """ <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
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
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")
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")
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))
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")
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")
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))
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")
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))
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)
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")
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")
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)