Exemplo n.º 1
0
def Idiam(diam, **params):
    dim = params["dim"]
    x0 = params.pop("x0")
    params.pop("diamPore")
    Jon = []
    Joff = []
    # TODO bad hack
    if dim==3:
        params.update(h=1.5, Nmax=7e5)
    if dim==2:
        params.update(h=0.75, Nmax=1e5)

    for d in diam:
        # get diffusivity interpolation
        cache_pugh_diffusivity(diamPore=d, **dparams[dim])
        ddata = dict(dparams[dim], name="Dpugh", diamPore=d)

        # current WITHOUT molecule
        setup = pugh.Setup(x0=None, diamPore=d, diffusivity_data=ddata, **params)
        pb, pnps = pugh.solve(setup, visualize=True)
        Jon.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])

        # current WITH molecule
        setup = pugh.Setup(x0=x0, diamPore=d, diffusivity_data=ddata, **params)
        pb, pnps = pugh.solve(setup, visualize=True)
        Joff.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])

    return dict(Jon=Jon, Joff=Joff)
Exemplo n.º 2
0
def cache_pugh_diffusivity(geoname="pugh2", mode="coupled", **params):
    #name = "D%s-%s" % (geoname, mode)
    name = "D%s" % (geoname, )

    if not fields.exists(name, **params):
        if not "cheapest" in params:
            params["cheapest"] = True
        setup = pugh.Setup(x0=None, **params)
        r = setup.geop.rMolecule
        diamPore = setup.geop.diamPore

        if mode == "coupled":
            data_z = diff_profile_z_pugh(diamPore=diamPore)
            data_r = diff_profile_plane(r)
        elif mode == "simple":
            data_z = None
            data_r = diff_profile_plane(r)
        elif mode == "profile":
            data_z = diff_profile_z_pugh(diamPore=diamPore)
            data_r = diff_profile_trivial(r)
        else:
            raise NotImplementedError

        functions = diffusivity_field(setup,
                                      r,
                                      ddata_z=data_z,
                                      ddata_r=data_r,
                                      boundary="dnab",
                                      poreregion="poreregion")
        fields.save_functions(name, params, **functions)
        fields.update()

    return name
Exemplo n.º 3
0
def diff2D(X, **params):
    for x, result in collect_dict(X):
        params["x0"] = x
        setup = pugh.Setup(**params)
        D = diffusivity(setup)
        result.new = dict(D=D)
    return result
Exemplo n.º 4
0
def IVDetail(V, **params):
    params["x0"] = None
    for bV, result in collect_dict(V):
        params["bV"] = bV
        setup = pugh.Setup(**params)
        pb, pnps = pugh.solve(setup)
        result.new = pnps.evaluate(setup.phys.CurrentPNPSDetail)
    return result
Exemplo n.º 5
0
def IrhoDetail(Rho, **params):
    params["x0"] = None
    for rho, result in collect_dict(Rho):
        params["dnaqsdamp"] = rho
        setup = pugh.Setup(**params)
        pb, pnps = pugh.solve(setup, visualize=True)
        result.new = pnps.evaluate(setup.phys.CurrentPNPSDetail)
    return result
Exemplo n.º 6
0
def IV(V, **params):
    params["x0"] = None
    J = []
    for bV in V:
        params["bV"] = bV
        setup = pugh.Setup(**params)
        pb, pnps = pugh.solve(setup)
        J.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])
    return dict(J=J)
Exemplo n.º 7
0
def calculate_diffusivity(X, **params):
    _params = dict(default, **params)
    values = []
    for x0 in X:
        setup = pugh.Setup(x0=x0, **_params)
        setup.physp["bulkbc"] = _params["bulkbc"]
        D = diffusivity(setup)
        values.append(D)
    return dict(D=values)
Exemplo n.º 8
0
def Irho(Rho, **params):
    params["x0"] = None
    bV = params["bV"]
    J = []
    for rho in Rho:
        params["dnaqsdamp"] = rho
        setup = pugh.Setup(**params)
        pb, pnps = pugh.solve(setup, visualize=True)
        J.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])
    cond = [abs(j / bV) for j in J]
    return dict(J=J, cond=cond)
Exemplo n.º 9
0
def D_tensor(X, **params):
    x0 = X[0]
    print
    print
    print "MOLECULE: ", x0
    setup = pugh.Setup(x0=x0, **params)
    nano.plot_sliced(setup.geo)
    #dolfin.plot(setup.geo.subdomains, elevate=-45., key="subdomains")
    #dolfin.plot(setup.geo.subdomains, key="subdomains")
    setup.physp["bulkbc"] = params["bulkbc"]
    D = diffusion.diffusivity_tensor(setup)
    return dict(D=[tolist(D)])
Exemplo n.º 10
0
def cache_pugh_diffusivity_alt(**params):
    "the function above applied to the pugh pore"
    if not fields.exists("Dpugh_alt", **params):
        setup_params = dict(params)
        r = setup_params.pop("r")
        ddata_pore = fields.get_fields("pugh_diff_pore", rMolecule=r)
        ddata_bulk = fields.get_fields("pugh_diff_bulk", rMolecule=r)
        if not "cheapest" in setup_params:
            setup_params["cheapest"] = True
        setup = pugh.Setup(x0=None, **setup_params)
        functions = diffusivity_field_alt(setup, r, ddata_pore, ddata_bulk)
        fields.save_functions("Dpugh_alt", params, **functions)
        fields.update()
Exemplo n.º 11
0
def cache_pugh_diffusivity_old(**params):
    "the function above applied to the pugh pore"
    if not fields.exists("Dpugh", **params):
        setup_params = dict(params)
        r = setup_params.pop("r")
        ddata_z = fields.get_fields("pugh_diff2D", rMolecule=r)
        ddata_r = fields.get_fields("pugh_diff3D", rMolecule=r, bulkbc=True)
        if not "cheapest" in setup_params:
            setup_params["cheapest"] = True
        setup = pugh.Setup(x0=None, **setup_params)
        functions = diffusivity_field(setup, r, ddata_r, ddata_z)
        fields.save_functions("Dpugh", params, **functions)
        fields.update()
Exemplo n.º 12
0
def Idiam(diam, **params):
    dim = params["dim"]
    x0 = params.pop("x0")
    params.pop("diamPore")
    Jon = []
    Joff = []

    for d in diam:
        # get diffusivity interpolation
        cache_pugh_diffusivity(geoname="pugh2", diamPore=d, **dparams[dim])

        # current WITHOUT molecule
        setup = pugh.Setup(x0=None, diamPore=d, **params)
        pb, pnps = pugh.solve(setup, visualize=True)
        Jon.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])

        # current WITH molecule
        setup = pugh.Setup(x0=x0, diamPore=d, **params)
        pb, pnps = pugh.solve(setup, visualize=True)
        Joff.append(pnps.evaluate(setup.phys.CurrentPNPS)["J"])

    return dict(Jon=Jon, Joff=Joff)
Exemplo n.º 13
0
    VVV = dolfin.TensorFunctionSpace(meshp, "CG", 1, shape=(dim, dim))
    D = dolfin.Function(VVV)
    v2d = dolfin.vertex_to_dof_map(VVV)
    Dv = D.vector()
    for k, (i, j) in enumerate(product(i3, i3)):
        Dv[np.ascontiguousarray(v2d[k::dim**2])] = np.ascontiguousarray(Da[:,
                                                                           i,
                                                                           j])

    setup.phys.update(Dp=D, Dm=D)
    #embed()
    return D


# set up domain with protein
ddata = dict(name="Dpugh", r=0.11, dim=2)
setup = pugh.Setup(x0=[0., 0., 10.],
                   dim=2,
                   h=1.,
                   Nmax=1e5,
                   diamPore=6. * np.sqrt(np.pi) / 2.,
                   cheapest=True,
                   diffusivity_data=ddata)
plotter = pugh.Plotter(setup)
pugh.prerefine(setup, True)

print "getting D"
D = set_D_with_protein(setup)
print "plotting"
plotter.plot(D[0, 0], title="Dxx")
dolfin.interactive()
Exemplo n.º 14
0
    Dn = [0., eps] + Dn + [1.]
    Dt = [0., eps] + Dt + [1.]

    fz = interp1d(z, Dz)
    fn = interp1d(x, Dn)
    ft = interp1d(x, Dt)
    import matplotlib.pyplot as plt
    plt.plot(z, fz(z), "s-")
    plt.figure()
    plt.plot(x, fn(x), "s-")
    plt.plot(x, ft(x), "s-")

    # get geometry, prerefine mesh, compute distance function
    setup = pugh.Setup(dim=params.dim,
                       x0=None,
                       h=params.h,
                       Nmax=params.Nmax,
                       cheapest=True)
    pugh.prerefine(setup, visualize=True)
    dist = distance_boundary_from_geo(setup.geo)
    VV = dolfin.VectorFunctionSpace(setup.geo.mesh, "CG", 1)
    normal = dolfin.project(dolfin.grad(dist), VV)
    plotter = pugh.Plotter(setup)
    plotter.plot_vector(normal, "normal")

    #functions, mesh = f.get_functions("pugh_distance", h=h)
    #dist = functions["y"]


    def transformation(n, Dn, Dt):
        D = np.diag([Dn, Dt, Dt]) if len(n) == 3 else np.diag([Dn, Dt])
Exemplo n.º 15
0
             diamDNA=2.5,
             Nmax=1.2e5,
             dim=2,
             r=0.11,
             h=.75,
             cheapest=False,
             Membraneqs=-.5),
        3:
        dict(diamPore=6., Nmax=1e6, dim=3, r=0.11, h=2.0, cheapest=False)
    }

    # obtain diffusivity field and project to x-z plane
    #functions = get_pugh_diffusivity(**dparams[2])
    setup = pugh.Setup(dim=2,
                       h=1.,
                       Nmax=1e5,
                       x0=[0., 0., 0.],
                       diffusivity="Dpugh2")
    setup.prerefine()
    pugh.set_D(setup)
    D3D = setup.phys.Dp[1, 1]
    print D3D([0., 0.])
    #D3D = functions["D"][2]

    D0 = nanopores.D

    def F(x, z):
        if x >= 0:
            return D3D([x, z]) / D0
        else:
            return D3D([-x, z]) / D0
Exemplo n.º 16
0
    while eps > 1e-4:
        print "eps", eps, " ",
        solver.solve()
        u.assign(u + du)
        eps *= epsfact
        epsi.assign(eps)

    return u


if __name__ == "__main__":
    import nanopores.geometries.pughpore as pughpore
    import nanopores.models.pughpore as pugh
    from nanopores import user_param
    setup = pugh.Setup(dim=3, h=2., x0=None, Nmax=6e5, cheapest=True)
    setup.prerefine()
    geo = setup.geo
    #geo = pughpore.get_geo_cyl(lc=1., x0=None)
    y = distance_boundary_from_geo(geo)
    setup.plot(y, title="distance", interactive=True)
    from numpy import linspace
    from matplotlib.pyplot import plot, show
    t = linspace(0., 20., 100)

    def point(t):
        x = [0.] * setup.geop.dim
        x[0] = t
        return x

    plot(t, [y(point(t0)) for t0 in t], ".-")