import nanopores.models.pughpore as pughm from nanopores.tools import fields import nanopores import folders nanopores.add_params(h=1.) functions, mesh = fields.get_functions("pugh_distance", h=h) y = functions["y"] pughm.Plotter().plot(y, title="distance", interactive=True)
# iv curve or other stuff for Howorka where geometry can be reused import numpy import nanopores import matplotlib.pyplot as plt from nanopores.models import Howorka from matplotlib2tikz import save as tikz_save nanopores.add_params(**Howorka.PARAMS) nanopores.add_params( bV=numpy.linspace(-0.1, 0.1, 11), dnaqsdamp=[0.2, 0.35, 0.5], bulkcon=300, plot="bV", nproc=4, ) print PARAMS geo_params = dict(z0=None, rMolecule=rMolecule, Rx=Rx, Ry=Ry) geo, phys = Howorka.setup2D(**geo_params) mesh = geo.mesh def run(**phys_params): params = geo_params.copy() params.update(phys_params) geo, phys = Howorka.setup2D(mesh=mesh, **params) pb, pnps = Howorka.solve2D(geo, phys, **params) return dict(J=pnps.get_functional("Javgctr")) #result, stamp = nanopores.iterate_in_parallel(run, iterkeys=[plot], **PARAMS)
import nanopores, dolfin, numpy, os from nanopores.tools.functions1D import Geometry1D from nanopores.physics.convdiff import ConvectionDiffusion, ConvectionDiffusionSteady from nanopores.models import Howorka from nanopores import Interval import matplotlib.pyplot as plt import matplotlib.ticker as ticker import force_profiles from collections import defaultdict from functools import partial nanopores.add_params( savefig=False, steady=False, log=True, levels=1, t=1e-8, steps=100, # timesteps per level for logarithmic time plot ) # create 1D version of pore geometry a, b = -1000., 1000. N = 10000 domain = Interval(a, b) h = 0.5 * Howorka.params_geo.l0 # half pore length pore = Interval(-h, h) bulkfluidtop = Interval(h, b) domain.addsubdomains( #fluid = domain, pore=pore,
"""do stuff on top of PNPS solve, like convecting analyte concentration with force field. TODO: also plot duplicate left half""" import numpy, dolfin, os from matplotlib import pyplot import matplotlib.tri as mtri import matplotlib import nanopores from nanopores.models import Howorka from nanopores.physics.convdiff import ConvectionDiffusion nanopores.add_params( log = True, save = False, video = False, levels = 7, steps = 100, # timesteps per level for logarithmic time plot **Howorka.PARAMS) PARAMS.pop("z0") # video directories TMPDIR = "/tmp/video/" VIDDIR = os.path.expanduser("~") + "/presentations/nanopores/" if video: if not os.path.exists(TMPDIR): os.makedirs(TMPDIR) else: for f in os.listdir(TMPDIR): os.remove(TMPDIR + f)
import os import nanopores import matplotlib.pyplot as plt from mysolve import load_estimators as load nanopores.add_params(est="F") F = "err ref" if est == "ref" else est DIR = os.path.expanduser("~") + "/papers/pnps-numerics/figures/" for dim in "3D", "2D": estimators = load("adap%s" % dim) estimators_cheap = load("adap%scheap" % dim) estimators_unif = load("adap%suniform" % dim) for est in estimators, estimators_cheap, estimators_unif: est["Fabs"] = nanopores.Estimator("Fabs") est["Fabs"].pairs = [ (N, abs(drag) + abs(el)) for (N, drag), (N1, el) in zip(est["Fdrag"].pairs, est["Fel"].pairs) ] estimators[F].name = "adaptive" estimators_cheap[F].name = "adaptive (cheap)" estimators_unif[F].name = "uniform" rate = -2. / float(dim[0]) estimators[F].plot() estimators_cheap[F].plot(fig=False) estimators_unif[F].plot(fig=False, rate=rate)
""" TODO: -) understand no boundary condition -) validate understanding with analytical solution """ import nanopores, dolfin, os from nanopores.physics.simplepnps import SimpleNernstPlanckProblem import matplotlib.pyplot as plt import matplotlib.ticker as ticker import force_profiles from collections import defaultdict nanopores.add_params(savefig=False) class DiffusionProblem1D(SimpleNernstPlanckProblem): method = SimpleNernstPlanckProblem.method method["iterative"] = False @staticmethod def initial_u(V, c0): u = dolfin.Function(V) u.interpolate(dolfin.Constant(c0)) return u @staticmethod def forms(V, geo, phys, F): dx = geo.dx() grad = phys.grad kT = dolfin.Constant(phys.kT) D = dolfin.Constant(Dtarget(phys.rTarget))
# -*- coding: utf-8 -*- """ Created on Mon Oct 24 11:42:54 2016 @author: gregor """ import os import dolfin import nanopores.geometries.pughpore as pugh import nanopores nanopores.add_params( z=0., r=1., ) print os.getpid() geo = pugh.get_geo_cyl(x0=[1., 1., z], rMolecule=r) #rMolecule=0.15) dolfin.plot(geo.subdomains) dolfin.plot(geo.boundaries) dolfin.interactive()
"""save/load/modify PNPS force field.""" import numpy, dolfin import nanopores from nanopores.models import Howorka nanopores.add_params(Howorka, z0 = None, bV = 0., dnaqsdamp = 0.5, save = False, ) # save and load implicit force field FNAME = "howorka2D_implicit" def save_force_field(**params): F, Fel, Fdrag = Howorka.F_field_implicit(**params) mesh = Howorka.geo.mesh nanopores.save_functions(FNAME, mesh, meta=params, F=F, Fel=Fel, Fdrag=Fdrag) if save: save_force_field(**PARAMS) exit() def load_force_field(): forces, mesh, params = nanopores.load_vector_functions(FNAME) #mesh = forces["F"].function_space().mesh() return forces["F"], forces["Fel"], forces["Fdrag"], mesh, params # get forces and accompanying function spaces F, Fel, Fdrag, mesh, params = load_force_field()
import itertools, numpy import nanopores import HoworkaSimple as H nanopores.add_params( bVstep=0.025, tol=1e-2, h=.5, ) bVs = [-.01, -.02, -.05, -.1, -.2, -.5, -1., -2.] qs = [0.1, 0.25, 0.5, 1., 2.] params = itertools.product(bVs, qs) M, N = len(bVs), len(qs) geo, _ = H.setup2D(z0=None, h=h) solve = (lambda phys: H.solve2D_fixedpoint(geo, phys, imax=20, tol=tol), lambda phys: H.solve2D_fixedpoint_bVscheme( geo, phys, imax=20, bVstep=bVstep, tol=tol), lambda phys: H.solve2D_fixedpoint_bVscheme( geo, phys, imax=100, bVstep=bVstep, tol=tol), lambda phys: H.solve2D_hybrid(geo, phys, imax=10, tol=tol), lambda phys: H.solve2D_hybrid_PB(geo, phys, imax=10, tol=tol)) data = tuple(numpy.zeros([M, N], dtype=bool) for k in range(5)) #for bV, dnaqs in params: for i in range(M): for j in range(N): phys = H.phys2D(geo, bV=bVs[i], dnaqsdamp=qs[j]) for k in range(5): data[k][i, j] = solve[k](phys)
"create 2D point set for Howorka model where force shall be evaluated." import numpy as np from itertools import product import math import matplotlib.pyplot as plt import nanopores gauss = np.polynomial.legendre.leggauss nanopores.add_params( h = 0.5, hout = 1., Ry = 10., Rx = 3., ) def points(h, hout, r0, r, l0, Rx, Ry): # effective pore radius for molecule R = r0 - r # get scaled 1D gauss quadrature nodes # for x grid inside pore # this has h = h/2 to resolve the thin region k = int(math.ceil(R/h*2.)) x, w = gauss(2*k + 1) x = R*x[k:] # get uniform y grid inside pore m = int(math.ceil(2.*l0/h)) y = np.linspace(-l0-r+h/2, l0+r-h/2, m) # list of (x,y) values in pore
"plot 1D force/PMF profiles for 2D Howorka pore and save" import os, numpy, dolfin, Howorka from nanopores import kB, T, add_params, save_dict, saveplots, showplots from matplotlib.pyplot import figure, plot, legend, show, title, xlabel, ylabel, savefig add_params( himp=.2, hexp=.5, Nimp=1e5, Nexp=2e4, Qmol=-1., Nz=2, ) # get force from explicit molecule def F_explicit(*lspace): for z0 in numpy.linspace(*lspace): geo, phys = Howorka.setup2D(z0=z0, h=hexp, Qmol=Qmol) dolfin.plot(geo.boundaries, key="b", title="boundaries") pb, pnps = Howorka.solve2D(geo, phys, Nmax=Nexp, cheapest=True) yield pnps.zforces() # get force from implicit molecule def F_implicit(*lspace): geo, phys = Howorka.setup2D(z0=None, h=himp, Qmol=Qmol) pb, pnps = Howorka.solve2D(geo, phys, Nmax=Nimp, cheapest=True) (v, cp, cm, u, p) = pnps.solutions() F, Fel, Fdrag = phys.Forces(v, u)
"""run diffusion equation to determine selectivity""" import numpy, dolfin from matplotlib import pyplot import nanopores from nanopores.physics.convdiff import ConvectionDiffusion nanopores.add_params( log = True, levels = 1, t = 1e-0, steps = 100, # timesteps per level for logarithmic time plot ) # import force field, mesh etc. from forcefield import geo, phys, Fel, Fdrag, params # initial condition #N = 10. # number of molecules to diffuse #r = 50. # radius of spherical region where molecules start [nm] #Vol = dolfin.pi*4./3.*r**3 # volume of region [nm**3] #c0 = N/Vol # concentration [1/nm**3] #x0 = numpy.array([0., z0]) # position of region #u0f = lambda x: (c0 if sum((x-x0)**2) < r**2 else 0.) # function # concentration in 1/nm**3 (Burns et al.) c0 = 2*50.*(phys.mol*phys.nm**3) # 50 mM = 50*mol/m**3 (50*6e23*1e-27 = 3e-2) u0 = geo.pwconst("c0", dict(bulkfluidtop = c0, default=0.)) # total concentration
"calculate 2D implicit forcefield; clever save/continue depending on params." from nanopores.models import Howorka from nanopores.tools import fields import nanopores nanopores.add_params( rMolecule=0.5, Qmol=-1., h=1., Nmax=2e4, ) params = dict( bV=0., dnaqsdamp=0.5, rMolecule=rMolecule, Qmol=Qmol, bulkcon=3e2, Nmax=Nmax, h=h, Rx=12., Ry=12., ) # save and load implicit force field NAME = "force2Dimp" def save_forcefield_implicit(**params): F, Fel, Fdrag = Howorka.F_field_implicit(**params) mesh = Howorka.geo.mesh
import dolfin from itertools import product import nanopores from nanopores.tools import fields from nanopores.models import Howorka import forcefield2D #from plot_forcefield import porestreamlines import matplotlib.pyplot as plt import matplotlib.tri as mtri import matplotlib.delaunay as dln import matplotlib.ticker import matplotlib.patches as patches import colormaps as cm nanopores.add_params(eps=0.1, ) def porestreamlines(polygon=None, rx=10., ry=10., Nx=100, Ny=100, maxvalue=None, **fields): "streamlines plot of vector field around nanopore" # interpolate on regular mesh symmetric w.r.t. center axis #mesh2D = nanopores.RectangleMesh([-rx-0.1,-ry-0.1], [rx+0.1,ry+0.1], Nx, Ny) #fields2 = nanopores.convert2D(mesh2D, *(fields.values()))
"calculate force on given points; clever save/continue depending on params." from nanopores.models import Howorka from nanopores.tools import fields from nanopores import add_params add_params( rMolecule=0.5, Qmol=-1., dnaqsdamp=0.5, ) params = dict( bV=0., dnaqsdamp=dnaqsdamp, rMolecule=rMolecule, Qmol=Qmol, bulkcon=3e2, ) solver_params = dict( params, Rx=8., h3D=8., h=1., lcpore=0.1, Nmax3D=2.5e4, # UMFPACK: max. ca. 3e4 Nmax=1e4, stokesLU=True, ) fields.update()
import numpy, dolfin, nanopores from dolfin import * from nanopores.geometries.finfet import finfet from nanopores import showplots, saveplots, add_params from collocation import dopants add_params( Ndop = 4, h = 1., maxorder = 2, ) def solve(geo, dops): tic() t = dolfin.Timer("phys") phys = nanopores.Physics("finfet", geo, dopants=dops, vD=None, vG=None, vS=None) phys.add_dopants t.stop() dolfin.plot(geo.submesh("source"), key="dop", title="dopants in source") t = dolfin.Timer("init") pde = nanopores.NonstandardPB(geo, phys) pde.tolnewton = 1e-8 pde.newtondamp = 1. t.stop() t = dolfin.Timer("solve") pde.solve() t.stop() u = pde.solution
Ncol = A.shape[1] Ndop = A.shape[0] / 3 dops = [] for i, a in enumerate(A.T): dops.append([None] * Ndop) for j in range(Ndop): dops[i][j] = list(a[3 * j:3 * j + 3]) if isinstance(weights, float): weights = [[weights]] return dops, list(weights[0]) # test if __name__ == "__main__": from nanopores import add_params add_params( N=4, order=2, ) dops, weights = dopants(N, order) for i, sample in enumerate(dops): print "Sample # %d:" % i for j, dop in enumerate(sample): print " dopant #%d: %s" % (j, dop) print "Weights:" print weights