def save_fig(params, fieldsname): figname = fieldsname + '_%.1e_%.1e_%.1e_%.1e_%.1e_%.1e' % ( params["avgbind1"], params["avgbind2"], params["avgbind3"], params["P_bind1"], params["P_bind2"], params["P_bind3"]) + str( params["z0"]) data = f.get_fields(fieldsname, **params) t1 = data["t1"] a1 = data["a1"] t2 = data["t2"] a2 = data["a2"] t0 = data["t0"] a0 = data["a0"] print len(t1) print len(t2) lendata = len(t1) + len(t2) for i in range(len(t1)): if math.isnan(a1[i]): print 'a1: NaN %i' % i plt.figure(figsize=(6, 4), dpi=80) plt.plot([3e-6, .7], [0., 0.], linewidth=2, color='lightgreen') plt.plot([1., 1e2], [0., 0.], linewidth=2, color='green') ax = plt.gca() plt.scatter(t1, a1, color='lightgreen', s=8) plt.scatter(t2, a2, color='green', s=8) plt.scatter(t0, a0, marker='o', s=50, facecolors='none', edgecolors='#ff0000') #ax.text(t1[k],a1[k],'%i'%k,fontsize=9) xfmt = FormatStrFormatter('%g') ax.set_xlim([1e-6, 500.]) ax.set_ylim([-2., 25.0]) ax.set_xscale('log') ax.xaxis.set_major_formatter(xfmt) ax.invert_yaxis() ax.set_xlabel(r'$\tau_{off}$ [ms]', fontsize=15) ax.set_ylabel(r'A/I$_0$ [%]', fontsize=15) ax.text(.001, -0.03, 'I', fontsize=15) ax.text(5., -0.03, 'II', fontsize=15) #ax.text(1.,5.,lendata,fontsize=25) plt.tight_layout() nano.savefigs(name=figname, DIR='/home/lv70496/benjamin/plots/') print 'savefig:' print figname
def save_fig(params): figname = 'type_'+str(params["avgbind1"])+'_'+str(params["avgbind2"])+'_'+str(params["P_bind1"])+'_'+str(params["P_bind2"])+'_'+str(params["z0"])+'.eps' data=f.get_fields("rw_2_bind",**params) t1 = np.array([]) t2 = np.array([]) a1 = np.array([]) a2 = np.array([]) T=data["T"] J=data["J"] # print '#data = %i'%len(T) for i in range(len(T)): T_=np.array(T[i])*1e-6 J_=np.array(J[i]) tau_off=np.sum(T_) amp = (2060.-np.inner(J_,T_)/tau_off)/2060.*100 if number: ax.text(tau_off,amp,'%i'%i,fontsize=9) if tau_off<.1: t1=np.append(t1,np.array([tau_off])) a1=np.append(a1,np.array([amp])) else: t2=np.append(t2,np.array([tau_off])) a2=np.append(a2,np.array([amp])) plt.plot([5e-4,.1],[0.,0.],linewidth=2,color='lightgreen') plt.plot([.2,1e2],[0.,0.],linewidth=2,color='green') ax=plt.gca() plt.scatter(t1,a1,color='lightgreen') plt.scatter(t2,a2,color='green') ax.set_xlim([1e-4,500.]) ax.set_ylim([-0.40,4.0]) ax.set_xscale('log') ax.invert_yaxis() ax.set_xlabel(r'$\tau_{off}$ [ms]',fontsize=15) ax.set_ylabel(r'A/I$_0$ [%]',fontsize=15) ax.text(.011,-0.03,'I',fontsize=15) ax.text(5.,-0.03,'II',fontsize=15) plt.tight_layout() nano.savefigs(name=figname,DIR='/home/lv70496/benjamin/plots/')
plt.xlabel(r"$\tau$ off [ms]") #plt.xlim(xmin=0.5) plt.legend(loc="lower right", frameon=False) print "CDF fit:", T plt.figure("data_gammafit_pdf", figsize=(4, 3)) ######### for i in T: T[i].plot_pdf(tt, label=kaformat % kastr[i], std=std, log=log, color=colors[i], linestyle=linestyles[i]) plt.bar(tc, epdf, 0.8 * np.diff(t1), alpha=0.5, label="Experiment") plt.xscale("log") plt.ylabel("Rel. frequency") plt.xlabel(r"$\tau$ off [ms]") #plt.xlim(xmin=0.1) plt.legend(loc="upper right", frameon=False) plt.figure("data_gammafit_error", figsize=(4, 3)) plt.semilogx(ka, error, "o") plt.xlabel(r"$k_a$") plt.ylabel("Fitting error") import folders nanopores.savefigs("rw_cyl", folders.FIGDIR + "/pugh", ending=".pdf")
def save_fig_type(params, fieldsname): plotlin = False # cmap=matplotlib.cm.get_cmap('plasma') data = f.get_fields(fieldsname, **params) figname = fieldsname + '_%.1e_%.1e_%.1e_%.1e' % ( params["avgbind1"], params["avgbind2"], params["P_bind1"], params["P_bind2"]) + str(params["z0"]) t = data["t"] tdata = np.array(t) a = data["a"] ood = data["ood"] lendata = len(t) fac = 1. if max(t) < 1e-2: fac = 1e3 t = [x * 1e3 for x in t] P_bind1 = params["P_bind1"] P_bind2 = params["P_bind2"] avgbind1 = params["avgbind1"] * 1e-6 avgbind2 = params["avgbind2"] * 1e-6 color2 = 'green' color1 = 'lightgreen' color3 = 'red' if plotlin: plt.figure(figsize=(10, 5), dpi=80) else: plt.figure(figsize=(7, 5), dpi=80) if plotlin: gs = gridspec.GridSpec(2, 3, width_ratios=[4, 2, 1], height_ratios=[1, 2.5]) else: gs = gridspec.GridSpec(2, 2, width_ratios=[4, 1], height_ratios=[1, 2.5]) gs.update(wspace=0., hspace=0.) minperc = 0. maxperc = 30. plt1 = plt.subplot(gs[1, 0]) for k in range(lendata): if ood[k] == 0: type1 = plt1.scatter([t[k]], [a[k]], color=color2, s=8) else: type0 = plt1.scatter([t[k]], [a[k]], color=color3, s=8) xfmt = FormatStrFormatter('%g') plt1.set_xlim([.2 * min(t), max(t) * 5.]) plt1.set_ylim([minperc, maxperc]) plt1.set_xscale('log') plt1.xaxis.set_major_formatter(xfmt) plt1.invert_yaxis() plt1.set_ylabel(r'A/I$_0$ [%]', fontsize=15) # plt1.text(.2,23.,str(float(np.where(tdata>0.2)[0].shape[0])/float(tdata.shape[0]))+'='+str(np.where(tdata>0.2)[0].shape[0])+'/'+str(tdata.shape[0]),fontsize=9) if fac == 1.: if P_bind1 != 0.: plt1.text(avgbind1 * .5, 27., 'Long binding', fontsize=9, horizontalalignment='center') k = 0.5 # plt1.add_patch(matplotlib.patches.Rectangle((avgbind1*10**(-k*2),0.),avgbind1*(10**(k)-10**(-k)),maxperc,facecolor=cmap(.7),alpha=.15)) if P_bind2 != 0.: plt1.text(0.002, 27., 'Short binding', fontsize=9, horizontalalignment='center') k = 1.0 # plt1.add_patch(matplotlib.patches.Rectangle((avgbind2*100*10**(-k),0.),avgbind2*(10**(k)-10**(-k)),maxperc,facecolor=cmap(.4),alpha=.15)) # plt1.add_patch(matplotlib.patches.Rectangle((0.01,0.),0.99,maxperc,facecolor=cmap(.4),alpha=.15)) plt1.set_xlabel(r'$\tau_{off}$ [ms]', fontsize=15) #,x=.76) else: plt1.set_xlabel(ur'$\tau_{off}$ [µs]', fontsize=15) #,x=.76) if plotlin: plt2 = plt.subplot(gs[1, 1]) for k in range(lendata): if ood[k] == 0: type1 = plt2.scatter([t[k]], [a[k]], color=color2, s=8) else: type0 = plt2.scatter([t[k]], [a[k]], color=color3, s=8) plt2.invert_yaxis() plt2.set_ylim([maxperc, minperc]) plt2.set_xlim([-2e-2 * max(t), max(t) * (1. + 2e-2)]) plt2.axes.get_yaxis().set_visible(False) plt2.axes.get_xaxis().major.locator.set_params(nbins=6) plt3 = plt.subplot(gs[1, 2]) else: plt3 = plt.subplot(gs[1, 1]) n, bins, patches = plt3.hist(np.array(a), 15, normed=1, orientation='horizontal', color=color1, alpha=.5) plt3.invert_yaxis() plt3.set_xlim([0., max(n) * 1.2]) plt3.set_ylim([maxperc, minperc]) plt3.axes.get_xaxis().set_visible(False) plt3.axes.get_yaxis().set_visible(False) if plotlin: plt4 = plt.subplot(gs[0, 1]) n, bins, patches = plt4.hist(np.array(t), 20, normed=1, color=color1, alpha=.5) plt4.set_xlim([-2e-2 * max(t), max(t) * (1. + 2e-2)]) plt4.axes.get_xaxis().set_visible(False) plt4.axes.get_yaxis().set_visible(False) else: plt4 = plt.subplot(gs[0, 0]) n, bins, patches = plt4.hist(map(lambda x: math.log10(x), np.array(t)), 25, normed=1, color=color1, alpha=.5, align='mid') plt4.set_xlim([math.log10(.2 * min(t)), math.log10(max(t) * 5.)]) plt4.axes.get_xaxis().set_visible(False) plt4.axes.get_yaxis().set_visible(False) plt.legend([type1, type0], ['successful translocation', 'did not translocate'], scatterpoints=4, loc=(.6, 0.50)) plt.tight_layout() nano.savefigs(name=figname, DIR='/home/bstadlbau/plots/', pdf=True) print 'savefig:' print figname
return f([x, z]) else: return f([-x, z]) R, Htop, Hbot = 7, 2, 12 fig, ax = plt.subplots(figsize=(8, 6), num="pot") tr, vertex_values = mesh2triang(mesh) zz = 1000*vertex_values(f) minmax = max(abs(zz)) #plt.triplot(tr) #pc = plt.tripcolor(tr, zz, cmap=cm.bwr) pc = plt.tripcolor(tr, zz, cmap=cm.bwr, vmin=-minmax, vmax=minmax) #pc = plt.pcolor(X, Y, U, cmap=cm.coolwarm_r) #, vmin=0, vmax=1) cb = plt.colorbar(pc) cb.ax.set_ylabel("Electric potential [mV]") #plot_polygon(ax, pugh.polygon(diamPore=6., rmem=13)) plt.xlim(-R, R) plt.ylim(-Hbot, Htop) p = get_pore() plot_polygon(p.protein) plot_polygon(p.membrane) from folders import FIGDIR from nanopores import savefigs savefigs("potential", FIGDIR + "/ahem", (6, 4.5)) #dolfin.plot(v, backend="matplotlib", cmap=cm.viridis) plt.show()
plt.plot(dxx, fplot(cdx_exp, dxx), "-", label="Wei et al.") for i in range(5): plt.plot(dxx, np.ones(len(dxx)) * cdxall_exp[i], "-", color="C0", alpha=0.5) #plt.plot(dxx, fplot(cdx_exp - vdx_exp, dxx), "-", color="C1") #plt.plot(dxx, fplot(cdx_exp + vdx_exp, dxx), "-", color="C1") #plt.fill_between(dxx, fplot(cdx_exp - vdx_exp, dxx), # fplot(cdx_exp + vdx_exp, dxx), alpha=0.5) #plt.plot(dx, fplot(cdx, dx), "o", label="Simulation") plt.plot(dx, fplot(cdx, dx), "o", label="Simulations", color="C1") for i in (0, 1, 2): plt.plot(dx, fplot(cdxall[:, i], dx), "o", color="C1", alpha=0.5) #plt.fill_between(dx, fplot(cdx - cdxstd, dx), fplot(cdx + cdxstd, dx), alpha=0.5) plt.annotate(r"$\delta$=5.5nm", (5.5, cdxall[4, 0] - 1.), xytext=(5.5 - .79, cdxall[4, 0] - 8.), color="C1", arrowprops=dict(arrowstyle="->", color="C1")) plt.xlabel(r"Bond rupture length $\delta$ [nm]") plt.ylabel(r"$\alpha$ [1/V]") plt.legend(loc="upper left", frameon=False) import folders nanopores.savefigs("tau_off2", folders.FIGDIR_HOWORKA + "/wei", ending=".pdf") #nanopores.savefigs("tau_off2", folders.FIGDIR + "/wei", ending=".eps")
# if ood[k]==0: # type1 = plt2.scatter([t[k]],[a[k]],color=color2,s=8) # else: # type0 = plt2.scatter([t[k]],[a[k]],color=color3,s=8) #plt2.invert_yaxis() #plt2.set_ylim([maxperc,minperc]) #plt2.set_xlim([-2e-2*max(t),max(t)*(1.+2e-2)]) #plt2.axes.get_yaxis().set_visible(False) #plt2.axes.get_xaxis().major.locator.set_params(nbins=6) # #plt3=plt.subplot(gs[1,2]) #n, bins, patches = plt3.hist(np.array(a),15,normed=1,orientation='horizontal',color=color1,alpha=.5) #plt3.invert_yaxis() #plt3.set_xlim([0.,max(n)*1.2]) #plt3.set_ylim([maxperc,minperc]) #plt3.axes.get_xaxis().set_visible(False) #plt3.axes.get_yaxis().set_visible(False) # # # #plt4=plt.subplot(gs[0,1]) #n, bins, patches = plt4.hist(np.array(t),20,normed=1,color=color1,alpha=.5) #plt4.set_xlim([-2e-2*max(t),max(t)*(1.+2e-2)]) #plt4.axes.get_xaxis().set_visible(False) #plt4.axes.get_yaxis().set_visible(False) #plt.tight_layout() #plt.show() #plt.savefig('events_both_compare.pdf') nanopores.savefigs("rw/events", FIGDIR, ending=".pdf")
R, Htop, Hbot = 7, 2, 12 fig = plt.figure(figsize=(2.6, 2.15)) ax = plt.axes(xlim=(-R, R), ylim=(-Hbot, Htop)) tr, vertex_values = mesh2triang(mesh) zz = 1000 * vertex_values(f) minmax = max(abs(zz)) #plt.triplot(tr) #pc = plt.tripcolor(tr, zz, cmap=cm.bwr) pc = plt.tripcolor(tr, zz, cmap=cm.bwr, vmin=-minmax, vmax=minmax) #pc = plt.pcolor(X, Y, U, cmap=cm.coolwarm_r) #, vmin=0, vmax=1) cb = plt.colorbar(pc) cb.ax.set_ylabel("Electric potential [mV]") #plot_polygon(ax, pugh.polygon(diamPore=6., rmem=13)) #plt.xlim(-R, R) #plt.ylim(-Hbot, Htop) p = get_pore() plot_polygon(p.protein, lw=.5) plot_polygon(p.membrane, lw=.5) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) from folders import FIGDIR_HOWORKA from nanopores import savefigs savefigs("potential", FIGDIR_HOWORKA + "/ahem", ending=".pdf") #dolfin.plot(v, backend="matplotlib", cmap=cm.viridis) plt.show()
return D3D([-x, z]) / D0 #D = uCross(u=D3D, axis=1, degree=1, dim=2) # obtain 2D mesh where we will evaluate field rx, ry = pugh.pughpore.params["R"], 0.5 * pugh.pughpore.params["H"] rx, ry = 13, 28 Nx, Ny = 201, 401 #mesh2D = RectangleMesh([-R,-H/2.], [R, H/2.], int(4*R), int(2*H)) Y, X = np.mgrid[-ry:ry:Ny * 1j, -rx:rx:Nx * 1j] U = np.zeros((Ny, Nx)) for y in range(Ny): for x in range(Nx): U[y][x] = F(X[y][x], Y[y][x]) fig, ax = plt.subplots(figsize=(6.5, 6.5), num="r0.11") pc = plt.pcolor(X, Y, U, cmap=cm.inferno, vmin=0, vmax=1) plt.colorbar(pc) plot_polygon(ax, pugh.polygon(diamPore=6., rmem=13)) plt.xlim(-13, 13) plt.ylim(-25, 28) #plt.xlabel("x [nm]") #plt.ylabel("z [nm]") fig.axes[1].set_ylabel(r"$D_{zz} / D_0$") #cb = fig.colorbar(CS, cax=cax, extend="both", orientation="vertical", format=formt) import folders nanopores.savefigs("pugh_Dfield_protein", folders.FIGDIR) plt.show()
# with constant D = 0.3*D0 in pore dd = None params = dict(default, diffusivity_data=dd) plt.figure("rD03", figsize=(2.6, 2.)) get_IV(calc, **params) # with 'simple' D interpolation (only analytical near-plane model) dd = ddsimplefine params = dict(default, diffusivity_data=dd) plt.figure("pdDsimple") get_IV(calc, **params) # with analytical r-dependence of D multiplied by z profile dd = ddcoupled params = dict(default, diffusivity_data=dd) plt.figure("pdDcoupled") get_IV(calc, **params) # comparison #plt.figure("finevscoarse") #fine_vs_coarse(False, **default) plt.figure("compareD", figsize=(2.8, 2.1)) #, dpi=300) compare_D_models(calc, **default) plt.figure("compareD_simple", figsize=(1.7, 1.6)) compare_D_models_simple(calc, **default) from nanopores import savefigs savefigs("IV", folders.FIGDIR_HOWORKA + "/ahem", ending=".pdf") #plt.show()
plt.legend(frameon=False) # big plot plt.figure("p0_fit") plt.plot(P2, data2.p0, ".", label="Simulated (N=20000)", zorder=100) PP = np.linspace(0, 1, 500) plt.plot(PP, 1. - np.exp(-a * PP), label="Poisson (a = 0.3)") plt.plot(PP, pmod * (1. - np.exp(-a1 * PP)), label="Mod. Poisson (a = 2.2)") print "pmod", pmod plt.xlabel(r"Binding probability $p$") plt.ylabel(r"$p_0$") #probability of >= 1 binding") plt.gca().add_patch(Rectangle((-0.01, -0.002), 0.07, 0.02, fc="none", ec="k")) plt.legend(frameon=False) import folders nanopores.savefigs("binding_prob", folders.FIGDIR + "/wei", (4, 3)) print "binding prob. inferred from simulations: p = %.6f" % p ap = -np.log(1 - p0) p1 = ap / a print "binding prob. inferred from assumed Poisson distribution: p = %.6f" % p1 # plot mean, std, log of time plt.figure("time_stdmean") mu = np.array(data4.mean_time) sigma = np.array(data4.std_time) log = np.array(data4.mean_log_time) plt.plot(P4, (mu / sigma)**2, "o", label="Simulated (N=100000)") def f(x):
import nanopores import matplotlib.pyplot as plt from mysolve import load_estimators as load figsize = 5 * 0.8, 4 * 0.8 est2D = load("anaPNPS_2D") est3D = load("anaPNPS_3D") fig = plt.figure("refinement", figsize=figsize) est2D["Jvol"].name = r"$|J_h - J|/J$ (2D)" est3D["Jvol"].name = r"$|J_h - J|/J$ (3D)" est2D["Jvol"].plot(rate=-1., fig=False) est3D["Jvol"].plot(rate=-2. / 3, fig=False) ax = plt.gca() ax.lines[1].set_label("") ax.lines[3].set_label("") plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.) from folders import FIGDIR nanopores.savefigs("anaPNPS", FIGDIR)
plt.ylim(300, 985) if rw.success[i]: plt.scatter([t[i0]], [J(z[i0])], s=dotsize, c=stopcolor) scalebar = AnchoredSizeBar(ax.transData, 10, "10ns", 2, pad=0.4, color="#666666", frameon=False, size_vertical=25, fontproperties=fm.FontProperties(size=8) #fontproperties=fontprops ) ax.add_artist(scalebar) plt.xlabel("Time") plt.ylabel("Current") plt.tick_params(axis="both", which='both', left="off", labelleft="off", bottom='off', labelbottom='off') #plt.gcf().tight_layout() nanopores.savefigs("exittime", FIGDIR + "/ahem", ending=".pdf", bbox_inches="tight") plt.show()
if r>=0.25: continue names = {0.152: r"$\rm{K}^{+}$", 0.167: r"$\rm{Cl}^{-}$"} Dmax = max(D) D0 = [d/Dmax for d in D] ax = ax_small ax.plot(Z, D0, ".-", label=names[r]) ax.set_xlabel("z position of molecule [nm]") ax.set_ylabel("D/D0") ax.set_title("rel. diffusivity (2D model)") # coarser calculation for remaining radii for r in [0.5, 1., 1.5]: N = 2e4 data = f.get_fields("pugh_diffusivity2D", rMolecule=r, h=4., Nmax=N) Z, D = zsorted(data, "D") # plot ax = ax_big ax.plot(Z, D, ".-", label="r=%.3f, N=20k" %r) ax.set_xlabel("z position of molecule [nm]") ax.set_ylabel("D/D0") ax.set_title("rel. diffusivity (2D model)") ax_big.legend(bbox_to_anchor=(1.05, 1.), loc="upper left", borderaxespad=0.,) ax_small.legend(bbox_to_anchor=(1.05, 1.), loc="upper left", borderaxespad=0.,) ax_small.legend(loc="lower right") nanopores.savefigs("pugh_diffusivity", folders.FIGDIR) plt.show()
U = np.zeros((Ny, Nx)) for y in range(Ny): for x in range(Nx): U[y][x] = F(X[y][x], Y[y][x]) fig, ax = plt.subplots(figsize=(1.73, 1.9)) #, dpi=300) pc = plt.pcolor(X, Y, U, cmap=plt.get_cmap("bone"), vmin=0, vmax=1) plot_polygon(ax, pughpolygon(diamPore=6., rmem=15), linewidth=0.2) plt.xlim(-15, 15) plt.ylim(-25, 28) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) bbox = ax.get_position() l, b, h = bbox.x0, bbox.y0, bbox.height w = 0.05 cbaxes = fig.add_axes([l - w - 0.07, b, w, h]) cb = plt.colorbar(pc, cax=cbaxes, ax=ax) cbaxes.set_ylabel("Rel. diffusivity") # (r"$D_{zz} / D_0$") cb.set_ticks([0., 1.]) cb.set_ticklabels([0, 1]) cbaxes.yaxis.set_ticks_position('left') cbaxes.yaxis.set_label_position('left') cbaxes.yaxis.labelpad = -3. import os HOME = os.path.expanduser("~") FIGDIR = os.path.join(HOME, "Dropbox", "Paper Howorka", "figures") nanopores.savefigs("pugh/Dfield", FIGDIR) plt.show()
) # one binding fig, ax = plt.subplots(num="bindzones_1", figsize=figsize2) configure_ax(ax) rainbow_text( -11.5, texty, "Long binding".split(), [clong, "k"], ) plot_seq(ax, blong1, clong, 5 * lw) # two bindings fig, ax = plt.subplots(num="bindzones_2", figsize=figsize2) configure_ax(ax) rainbow_text(-13.5, texty + .5 * line, "Long and short".split(), [clong, "k", cshort]) rainbow_text( -6.5, texty - .5 * line, ["binding"], ["k"], ) plot_seq(ax, bshort, cshort, lw2) plot_seq(ax, blong2, clong, lw2) #figdir = nanopores.dirnames.DROPBOX_FIGDIR figdir = nanopores.dirnames.HOME + "/Dropbox/Paper Howorka/figures/" nanopores.savefigs("rw/trace", figdir, ending=".pdf", pad_inches=0)
R = r0 - rMol - eps Z = np.linspace(-R, R, 21) X = [[z,0.,0.] for z in Z] #X = [[0.,0.,0.]] print velocities(X, nproc=7, name="howorka_velo3D_2", **params) do_plot = False redo_plot = False if do_plot: imax = user_params(imax=15)["imax"] if redo_plot: x = [0.2, 0., 0.] #x = [0., 0., 0.] setup = Howorka.Setup(x0=x, **params) f, v, dv = velocity_iteration(setup, imax) nanopores.save_stuff("velocity_iteration", f.tolist(), v.tolist(), dv.tolist()) f, v, dv = nanopores.load_stuff("velocity_iteration") dim = params["dim"] plt.semilogy(range(1, imax+1), 1e12*np.sqrt(np.sum(np.array(f)**2, 1)), "s-", label="net force on molecule") plt.ylabel("force [pN]") plt.xlabel("# iterations") plt.xlim(xmin=1, xmax=imax) plt.xticks(range(1,imax+1)) plt.legend(loc="best") fig = plt.gcf() fig.set_size_inches((4,3)) nanopores.savefigs("howorka_velocity_3D_z0", FIGDIR)
# scale times scale = 1e-6 # microseconds times = [t * 1e-3 / scale for t in times] from matplotlib import pyplot as plt t = linspace(1e-9 / scale, 8e-6 / scale, 500) hist = plt.hist(times, bins=30, color="#aaaaff", linewidth=0.5, weights=[1. / 500.] * len(times), label="BD simulations") pt = pp(t, scale) * integrate_hist(hist) * scale plt.plot(t, pt, "-", color="g", linewidth=3, label="FPT model") plt.legend(loc="upper right", frameon=False) plt.xlabel(u"dwell time [µs]") plt.ylabel(u"rel. frequency") print "integral", integrate_hist(hist), "==", integrate(t, pt) #plt.figure() #plt.hist(data["Fzavg"], bins=30, color="#aaaaff", linewidth=0.5) # #plt.figure() #plt.hist(data["Dzavg"], bins=30, color="#aaaaff", linewidth=0.5) from folders import FIGDIR savefigs("current-nobind-hist", FIGDIR + "/rw")
def Dfit(z, rion=0.11): rpore = dist([0., z]) beta = rion / rpore return 1. / (A + B * np.exp(beta / C) + D * np.exp(beta / E)) def diff_profile_fit(a=-10.3, b=0.05, N=20): Z = np.linspace(a, b, N) return Z, [Dfit(z) for z in Z] z, D = diff_profile_fit(a=-12, b=2, N=100) plt.plot(z, D, "-b", label="Tabulated (infinite cylinder)") data = diff_profile_z_ahem(a=-12, b=2, N=100, **params) z = [x0[2] for x0 in data["x"]] Dz = data["D"] plt.plot(z, Dz, "og", label="Full hydrodynamic model") plt.ylabel("Rel. diffusivity") plt.xlabel("z [nm]") plt.xlim(-10, 0) ax = plt.gca() #ax.yaxis.tick_right() #ax.yaxis.set_label_position("right") plt.legend(loc="upper left", frameon=False) from nanopores import savefigs from folders import FIGDIR savefigs("Dz", FIGDIR + "/ahem", (6, 4.5)) #print results
offset = ScaledTranslation(18, 27, ax.transScale) tform = offset + ax.transLimits + ax.transAxes ell = mpatch.Ellipse((0, 0), 1.8, 10, angle=0.0, transform=tform, fc="None", ec=long_bind_color) ax.add_patch(ell) plt.text(15, 21, "Assumed\n long bindings", color=long_bind_color, horizontalalignment="center") ########## simulations with one binding ########## plt.figure("1bind", figsize=figsize) a, t, ood = fields.get("eventsnew_onlyone_2_", "a", "t", "ood") a, t, success = np.array(a), np.array(t), np.array(ood) == 0 plt.scatter(t[~success], a[~success], **s_fail) plt.scatter(t[success], a[success], **s_success) plt.scatter(t_exp, a_exp, **s_experiment) format_ticks(plt.gca()) ########## simulations with two bindings ########## plt.figure("2bind", figsize=figsize) a, t, ood = fields.get("eventsnew_both_1_", "a", "t", "ood") a, t, success = np.array(a), np.array(t), np.array(ood) == 0 plt.scatter(t[~success], a[~success], **s_fail) plt.scatter(t[success], a[success], **s_success) plt.scatter(t_exp, a_exp, **s_experiment) format_ticks(plt.gca()) figdir = nanopores.dirnames.HOME + "/Dropbox/Paper Howorka/figures/" nanopores.savefigs("rw/events", figdir, ending=".pdf")
label=r"$v_r$ (exact)") plt.plot(z, [x[0] for x in data["v1"]], ".--", color="#0099ff", label=r"$v_r$ (approx.)") plt.xlabel("radial position of molecule [nm]") ## modify plt.ylabel(r"velocity [m/s]") plt.legend(loc="best") #(bbox_to_anchor=(0.5, 1.), loc="upper left") #plt.plot(z, np.abs(np.array(v0)-np.array(v1))) fig = plt.gcf() fig.set_size_inches((4, 3)) plt.figure() plt.plot(z, [x[2] for x in data["v0"]], "v-", color="#009900", label=r"$v_z$ (exact)") plt.plot(z, [x[2] for x in data["v1"]], ".--", color="#99ff00", label=r"$v_z$ (approx.)") plt.xlabel("radial position of molecule [nm]") ## modify plt.ylabel("velocity [m/s]") plt.legend(loc="best") #bbox_to_anchor=(0., 1.), loc="upper left") #plt.plot(z, np.abs(np.array(v0)-np.array(v1))) fig = plt.gcf() fig.set_size_inches((4, 3)) nanopores.savefigs("velo", FIGDIR) #plt.show()
Dzz1 = max(Dzz) xlin = linspace(r + 1e-3, 3., 100) dn = [Dn_plane(t, r, N=20) for t in xlin] dn = [d * Dxx1 / dn[-1] for d in dn] plt.plot(xlin, dn, "-b") dt = [Dt_plane(t, r) for t in xlin] dt = [d * Dzz1 / dt[-1] for d in dt] plt.plot(xlin, dt, "-g") plt.xlim(0., 1.5) plt.xticks([0, 0.5, 1., 1.5]) plt.plot(x, Dxx, "ob", label=r"$D_{xx}$") plt.plot(x, Dyy, "sg", label=r"$D_{yy}$") plt.plot(x, Dzz, ".r", label=r"$D_{zz}$") #plt.plot(x, [D2D]*len(x), "--k", label="2D cyl.") plt.xlabel("x distance from pore wall [nm]") plt.ylabel("Rel. diffusivity") plt.ylim(0, 1) plt.axvline(x=0.11, linestyle="--", color="#666666") plt.annotate("Ion radius", (0.11, 0.94), xytext=(0.25, 0.94 - 0.002), color="#666666", arrowprops=dict(arrowstyle="->", color="#666666")) plt.yticks([i / 10. for i in range(0, 11, 2)]) plt.legend(loc="lower right" ) #bbox_to_anchor=(1.05, 1.), loc="upper left", borderaxespad=0.,) plt.gcf().set_size_inches(3.2, 3.2) nanopores.savefigs("pugh_Dions", FIGDIR) plt.show()
color="red", rwidth=0.9, label="Did not translocate") #total = rw.integrate_hist(hist, cutoff) #tmean = times[times > cutoff].mean() #T = np.logspace(a-3, b, 1000) #fT = np.exp(-T/tmean)*T/tmean #fT *= total/integrate_values(T, fT, cutoff) #plt.plot(T, fT, label="exp. fit, mean = %.2f ms" % (tmean,), # color="dark" + color, **params) #plt.xlim(10**a, 10**b) #fake0 = fake[fake > bins[1]] plt.hist(fake, bins=bins, histtype="step", color="orange", label="Wei et al. 2012") plt.xscale("log") plt.yscale("log") plt.ylabel("Count") plt.xlabel(r"$\tau$ off [s]") plt.ylim(ymin=1., ymax=1e5) plt.legend() #plt.show() import folders nanopores.savefigs("tau_off", folders.FIGDIR + "/wei", (4, 3))
def save_fig_filter(params, fieldsname, i): data = f.get_fields(fieldsname, **params) T_ = data["T"][i].load() J_ = data["J"][i].load() T = np.array([]) J = np.array([]) for k in range(T_.shape[0]): time = T_[k] if time == 1.: T = np.append(T, 1.) J = np.append(J, J_[k]) else: vec = np.ones(int(time)) T = np.append(T, vec) J = np.append(J, J_[k] * vec) T = np.append(T, np.ones(1000000)) J = np.append(J, np.ones(1000000) * J[0]) for k in range(1, T.shape[0]): T[k] += T[k - 1] # T*=1e-9 J *= 1e12 zero = J[0] J -= zero from scipy import signal b, a = signal.bessel(2, 1. / 5. * 1e-3, analog=False) sig_ff = signal.lfilter(b, a, J) amp = data["a"][i] ftime = np.min(np.where(sig_ff > 1e-10)) - 1 ampf = abs(np.sum(sig_ff[:ftime])) / float(ftime) / curr * 100 print 'without filter: %.1f' % amp print 'with filter: %.1f' % ampf tau_off = float(ftime) figname = fieldsname + '_filter_' + '%.8f' % ( tau_off * 1e-6) + '_%04d' % i + '_%.1e_%.1e_%.1e_%.1e' % ( params["avgbind1"], params["avgbind2"], params["P_bind1"], params["P_bind2"]) + str(params["z0"]) af = [ampf] tf = [tau_off] f.save_fields(fieldsname, params, tf5=tf, af5=af) plt.figure(figsize=(6, 4), dpi=80) plt.title('Current signal') ax = plt.gca() if tau_off < 1e3: t = np.linspace(0., tau_off, 3) fac = 1. ax.set_xlabel('time [$ns$]') elif tau_off < 1e6 and tau_off >= 1e3: t = np.linspace(0., tau_off * 1e-3, 3) fac = 1e-3 ax.set_xlabel(r'time [$\mu s$]') else: t = np.linspace(0., tau_off * 1e-6, 3) fac = 1e-6 ax.set_xlabel('time [$ms$]') T = T * fac plt.plot(T, J + zero, color='#000000', label='Original') plt.plot(T, sig_ff + zero, linewidth=2., color='#ff6600', label='Filtered') plt.legend(loc='best') yt = np.linspace(580., 760, 4) ax.set_ylabel(r'A [$pA$]') ax.set_yticks(yt) ax.set_xticks(t) xfmt = FormatStrFormatter('%.1f') ax.xaxis.set_major_formatter(xfmt) ax.set_xlim([-4e-2 * tau_off * fac, (1. + 4e-2) * tau_off * fac]) plt.tight_layout() nano.savefigs(name=figname, DIR='/home/bstadlbau/plots/') print 'savefig: %s' % figname plt.close("all")
calc = True default = dict(geoname="alphahem", dim=2, h=1., Nmax=2e4, rDPore=0.3) # with constant D = 0.3*D0 in pore dd = None params = dict(default, diffusivity_data=dd) plt.figure("rD03") get_IV(calc, **params) # with 'simple' D interpolation (only analytical near-plane model) dd = ddsimplefine params = dict(default, diffusivity_data=dd) plt.figure("pdDsimple") get_IV(calc, **params) # with analytical r-dependence of D multiplied by z profile dd = ddcoupled params = dict(default, diffusivity_data=dd) plt.figure("pdDcoupled") get_IV(calc, **params) # comparison #plt.figure("finevscoarse") #fine_vs_coarse(False, **default) plt.figure("compareD") compare_D_models(calc, **default) from nanopores import savefigs savefigs("IV", folders.FIGDIR + "/ahem", size=(5, 3.7)) #plt.show()