def run(): """ <Description> Args: param1: This is the first param. Returns: This is a description of what is returned. """ base_input_processing = RetinalUtil._processing_base() base_dir = RetinalUtil._landscape_base() step = Pipeline.Step.MANUAL in_dir = Pipeline._cache_dir(base=base_input_processing, enum=Pipeline.Step.POLISH) out_dir = Pipeline._cache_dir(base=base_dir,enum=step) data_input = CheckpointUtilities.lazy_multi_load(in_dir) force = True functor = lambda : ProcessingUtil.\ _filter_by_bl(data_input,base_input_processing) data = CheckpointUtilities.multi_load(cache_dir=out_dir,load_func=functor, force=force, name_func=FEC_Util.fec_name_func) # plot each individual ProcessingUtil.plot_data(base_dir,step,data,xlim=[-50,150]) plot_subdir = Pipeline._plot_subdir(base_dir, step) out_name = plot_subdir + "heatmap.png" ProcessingUtil.heatmap_ensemble_plot(data, out_name=out_name)
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.SANITIZED in_dir = Pipeline._cache_dir(base=base_dir, enum=Pipeline.Step.MANUAL) out_dir = Pipeline._cache_dir(base=base_dir, enum=step) force = True limit = None min_sep = RetinalUtil.min_sep_landscape() max_sep = min_sep + 100e-9 functor = lambda: slice_data(in_dir, min_sep=min_sep, max_sep=max_sep) data = CheckpointUtilities.multi_load(cache_dir=out_dir, load_func=functor, force=force, limit=limit, name_func=FEC_Util.fec_name_func) plot_dir = Pipeline._plot_subdir(base=base_dir, enum=step) ProcessingUtil.heatmap_ensemble_plot(data, out_name=plot_dir + "heatmap.png", xlim=[-20, max_sep * 1e9]) # plot each individual ProcessingUtil.plot_data(base_dir, step, data)
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(): """ <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.REDUCED in_dir = Pipeline._cache_dir(base=base_dir, enum=Pipeline.Step.SANITIZED) out_dir = Pipeline._cache_dir(base=base_dir, enum=step) force = True limit = None functor = lambda: to_iwt(in_dir) data = CheckpointUtilities.multi_load(cache_dir=out_dir, load_func=functor, force=force, limit=limit, name_func=FEC_Util.fec_name_func) ProcessingUtil.plot_data(base_dir, step, data, xlim=[-50, 150]) plot_subdir = Pipeline._plot_subdir(base_dir, step) out_name = plot_subdir + "heatmap.png" ProcessingUtil.heatmap_ensemble_plot(data, out_name=out_name)
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 run(): """ <Description> Args: param1: This is the first param. Returns: This is a description of what is returned. """ input_dir = "../../../Data/FECs180307/" out_dir = "./" force = True q_interp, energy_list_arr, q_offset_nm,n_fecs = \ CheckpointUtilities.getCheckpoint("./cache.pkl",read_data, force,input_dir) G_no_peg = FigureUtil.read_non_peg_landscape() #_giant_debugging_plot(out_dir, energy_list_arr) base = out_dir + "FigureS6_LandscapeComparison" kw_name_arr = [ [dict(add_annotations=True), base], [dict(add_annotations=False), base + "_0"], [dict(add_annotations=False, limit_plot=1), base + "_1"], ] for kw, name in kw_name_arr: fig = PlotUtilities.figure(figsize=(3, 3)) make_comparison_plot(q_interp, energy_list_arr, G_no_peg, **kw) base = name PlotUtilities.save_twice(fig, base + ".jpeg", base + ".svg")
def read_dir(base_dir,enum): in_dir = Pipeline._cache_dir(base=base_dir, enum=enum) dir_exists = os.path.exists(in_dir) if (dir_exists and \ len(GenUtilities.getAllFiles(in_dir, ext=".pkl")) > 0): data = CheckpointUtilities.lazy_multi_load(in_dir) else: data = [] return data
def slice_data(in_dir, min_sep=40e-9, max_sep=140e-9): data = CheckpointUtilities.lazy_multi_load(in_dir) for d in data: try: _, _, to_ret = RetinalUtil._slice_single(d, min_sep, max_ext_m=max_sep) except AssertionError as e: print(e) print("Couldn't use {:s} in {:s}".format(d.Meta.Name, in_dir)) continue yield to_ret
def read_energy_lists(subdirs): """ :param subdirs: which directories to look in (e.g. BR+Retinal/) :return: list, elements are all the landscapes in the subdirs """ energy_list_arr = [] # get all the energy objects for base in subdirs: in_dir = Pipeline._cache_dir(base=base, enum=Pipeline.Step.CORRECTED) in_file = in_dir + "energy.pkl" e = CheckpointUtilities.lazy_load(in_file) energy_list_arr.append(e) return energy_list_arr
def _cache_individual(d, out_dir, f, force, *args, **kw): """ :param d: fec, or something that can be applied to FEC_Util.fec_name_func :param out_dir: where the pkl fie should live :param f: function to call :param force: if we should force re-caching :param args: to f :param kw: to f :return: cache or new function run """ name = out_dir + FEC_Util.fec_name_func(0, d) + ".pkl" data = CheckpointUtilities.getCheckpoint(name, f, force, *args, **kw) return data
def generate_landscape(in_dir): data = CheckpointUtilities.lazy_multi_load(in_dir) data_wham = UtilWHAM.to_wham_input(data) energy_wham = WeightedHistogram.wham(fwd_input=data_wham) f_iwt = InverseWeierstrass.free_energy_inverse_weierstrass iwt_obj = f_iwt(unfolding=data) # offset the IWT so that it matches the offset of WHAM... iwt_obj.q -= iwt_obj.q[0] offset_q = energy_wham.q[0] iwt_obj.q += offset_q iwt_obj._z += offset_q to_ret = RetinalUtil.DualLandscape(wham_obj=energy_wham, iwt_obj=iwt_obj, other_helices=[]) return to_ret
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, True, base_dir) galleries_labels = [[gallery.PEG600, "PEG600"], [gallery.PEG3400, "PEG3400"]] _make_plots(galleries_labels)
def read_in_energy(base_dir): """ :param base_dir: where the landscape lives; should be a series of FECs of about the same spring constant (e.g. /BR+Retinal/300/170321FEC/) :return: RetinalUtil.EnergyWithMeta """ landscape_base = _landscape_dir(base_dir) cache_tmp = \ Pipeline._cache_dir(base=landscape_base, enum=Pipeline.Step.POLISH) file_load = cache_tmp + "energy.pkl" energy_obj = CheckpointUtilities.lazy_load(file_load) obj = EnergyWithMeta(file_load,landscape_base, energy_obj) # read in the data, determine how many curves there are data_tmp = read_fecs(obj) n_data = len(data_tmp) obj.set_n_fecs(n_data) return obj
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 run(): """ <Description> Args: param1: This is the first param. Returns: This is a description of what is returned. """ base_dir_analysis = RetinalUtil._analysis_base() out_dir = Pipeline._cache_dir(base=base_dir_analysis, enum=Pipeline.Step.CORRECTED) force = True GenUtilities.ensureDirExists(out_dir) energy_list = CheckpointUtilities.getCheckpoint(out_dir + \ "energy.pkl", get_energy_list,force, base_dir_analysis) _fec_demo_plot(energy_list, out_dir)
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.READ cache_dir = Pipeline._cache_dir(base=base_dir, enum=step) force = True limit = None functor = lambda: read_all_data(base_dir) data = CheckpointUtilities.multi_load(cache_dir=cache_dir, load_func=functor, force=force, limit=limit, name_func=FEC_Util.fec_name_func) ProcessingUtil.plot_data(base_dir, step, data, markevery=100)
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)
def polish_data(base_dir): all_data = CheckpointUtilities.lazy_multi_load(base_dir) for d in all_data: to_ret = _polish_single(d) yield to_ret
def bias_fit_info(cache_file,W_of_interest,beta): fit_info = CheckpointUtilities.getCheckpoint(cache_file,fit_W_dist,True, W_of_interest,beta) return fit_info
def align_data(base_dir,out_dir,n_pool,**kw): all_data = CheckpointUtilities.lazy_multi_load(base_dir) input_v = [ [d,out_dir,kw] for d in all_data] to_ret = ProcessingUtil._multiproc(func, input_v, n_pool) to_ret = [r for r in to_ret if r is not None] return to_ret
def filter_data(base_dir, out_dir, force, t_filter, f_decimate): all_data = CheckpointUtilities.lazy_multi_load(base_dir) input_v = [[d, out_dir, force, t_filter, f_decimate] for d in all_data] to_ret = ProcessingUtil._multiproc(func, input_v, n_pool=3) return to_ret
def to_iwt(in_dir): data = CheckpointUtilities.lazy_multi_load(in_dir) # make sure they all have the same velocity for i in RetinalUtil._convert_to_iwt(data, in_dir): yield i
def align_data(base_dir,out_dir,n_pool,**kw): all_data = CheckpointUtilities.lazy_multi_load(base_dir) return _multi_align(out_dir,kw,all_data,n_pool)
def _snapsnot(base_dir, step): corrected_dir = Pipeline._cache_dir(base=base_dir, enum=step) data = CheckpointUtilities.lazy_multi_load(corrected_dir) return SnapshotFEC(step, data)
def make_plot(dir_in, out_name): dir_aligned = dir_in + "cache_8_aligned/" dir_polished = dir_in + "cache_10_polish/" data_unaligned = CheckpointUtilities.lazy_multi_load(dir_aligned) data_polished = CheckpointUtilities.lazy_multi_load(dir_polished) data_unaligned = ProcessingUtil._filter_by_bl(data_unaligned, dir_in) data_polished = ProcessingUtil._filter_by_bl(data_polished, dir_in) # scootch the data over slightly for d in data_polished: d.Separation -= 20e-9 to_x = lambda _x: _x * 1e9 to_y = lambda _y: _y * 1e12 xlim = [-10, 100] ylim = [-20, 350] plt.close() fig = PlotUtilities.figure(figsize=(3.5, 4.5)) kw_plot = dict(linewidth=0.75) ax1 = plt.subplot(2, 2, 1) for d in data_unaligned: plt.plot(to_x(d.Separation), to_y(d.Force), **kw_plot) ax2 = plt.subplot(2, 2, 2) for d in data_polished: plt.plot(to_x(d.Separation), to_y(d.Force), **kw_plot) for a in [ax1, ax2]: a.set_ylim(ylim) a.set_xlim(xlim) PlotUtilities.lazyLabel("Extension (nm)", "$F$ (pN)", "", ax=a) PlotUtilities.ylabel("", ax=ax2) height_pN = 100 min_y, max_y, delta_y = Scalebar.offsets_zero_tick( limits=ylim, range_scalebar=height_pN) kw_scale = dict(offset_x=0.7, offset_y=max_y, x_kwargs=dict(width=20, unit="nm"), y_kwargs=dict(height=height_pN, unit="pN")) for a in [ax1, ax2]: Scalebar.crossed_x_and_y_relative(ax=a, **kw_scale) PlotUtilities.no_y_label(ax=a) PlotUtilities.no_x_label(ax=a) PlotUtilities.x_label_on_top(ax=a) num = 200 bins_x = np.linspace(xlim[0], xlim[-1], endpoint=True, num=num) bins_y = np.linspace(ylim[0], ylim[-1], endpoint=True, num=num) kw = dict(color='w', use_colorbar=False, bins=(bins_x, bins_y), title="") kw_scale_heat = dict(**kw_scale) line_kw_def = dict(color='w', linewidth=2) font_x, font_y = Scalebar.font_kwargs_modified(x_kwargs=dict(color='w'), y_kwargs=dict(color='w')) kw_scale_heat['x_kwargs']['line_kwargs'] = line_kw_def kw_scale_heat['x_kwargs']['font_kwargs'] = font_x kw_scale_heat['y_kwargs']['line_kwargs'] = line_kw_def kw_scale_heat['y_kwargs']['font_kwargs'] = font_y ax3 = plt.subplot(2, 2, 3) Plotting.formatted_heatmap(data=data_unaligned, **kw) Scalebar.crossed_x_and_y_relative(ax=ax3, **kw_scale_heat) ax4 = plt.subplot(2, 2, 4) Plotting.formatted_heatmap(data=data_polished, **kw) Scalebar.crossed_x_and_y_relative(ax=ax4, **kw_scale_heat) for a in [ax3, ax4]: PlotUtilities.no_y_label(ax=a) PlotUtilities.no_x_label(ax=a) a.set_xlim(xlim) a.set_ylim(ylim) PlotUtilities.xlabel("", ax=a) PlotUtilities.ylabel("", ax=ax4) PlotUtilities.ylabel("$F$ (pN)", ax=ax3) PlotUtilities.savefig(fig, out_name) pass