def build_geometry(mesh_path, file_format="xml", scale=1.): scale = float(scale) if file_format == "xml": mesh = meshio.loadMesh(mesh_path)[0] elif file_format == "msh": mesh = meshio.importGmsh(mesh_path + ".msh", scale)[0] elif file_format == "inp": mesh = meshio.importAbaqus(mesh_path + ".inp", scale)[0] else: raise TypeError("File format " + str(file_format) + " not available: choose among xml, msh, inp") cyto = sgeom.TmComp('cyto', mesh, range(mesh.ntets)) (zmin_tris, zmin_vset, zmax_tris, zmax_vset) = zminmax_tris(mesh) memb_tris = list(mesh.getSurfTris()) for tri in zmin_tris: memb_tris.remove(tri) for tri in zmax_tris: memb_tris.remove(tri) memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto) membrane = sgeom.Memb('membrane', mesh, [memb]) mesh.addROI('v_zmin', sgeom.ELEM_VERTEX, zmin_vset) mesh.addROI('v_zmin_sample', sgeom.ELEM_VERTEX, radial_extrema(mesh, zmin_vset)) mesh.addROI('v_zmax_sample', sgeom.ELEM_VERTEX, radial_extrema(mesh, zmax_vset)) return mesh
def build_geometry(mesh_path): mesh = meshio.loadMesh(mesh_path)[0] cyto = sgeom.TmComp('cyto', mesh, range(mesh.ntets)) (zmin_tris,zmin_vset,zmax_tris,zmax_vset) = zminmax_tris(mesh) memb_tris = list(mesh.getSurfTris()) for tri in zmin_tris: memb_tris.remove(tri) for tri in zmax_tris: memb_tris.remove(tri) memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto) membrane = sgeom.Memb('membrane', mesh, [memb] ) #mesh.addROI('v_zmin',sgeom.ELEM_VERTEX,ROIset(zmin_vset)) #mesh.addROI('v_zmin_sample',sgeom.ELEM_VERTEX,ROIset(radial_extrema(mesh,zmin_vset))) #mesh.addROI('v_zmax_sample',sgeom.ELEM_VERTEX,ROIset(radial_extrema(mesh,zmax_vset))) mesh.addROI('v_zmin',sgeom.ELEM_VERTEX,zmin_vset) mesh.addROI('v_zmin_sample',sgeom.ELEM_VERTEX,radial_extrema(mesh,zmin_vset)) mesh.addROI('v_zmax_sample',sgeom.ELEM_VERTEX,radial_extrema(mesh,zmax_vset)) return mesh
def setUp(self): mdl = smodel.Model() S1 = smodel.Spec('S1', mdl) vsys = smodel.Volsys('vsys', mdl) ssys = smodel.Surfsys('ssys', mdl) smodel.Reac('R01', vsys, lhs=[S1], rhs=[S1], kcst=1) smodel.SReac('SR01', ssys, slhs=[S1], srhs=[S1], kcst=1) vrange = [-200.0e-3, 50e-3, 1e-3] vrate = lambda v: 2.0 Chan1 = smodel.Chan('Chan1', mdl) chanop = smodel.ChanState('chanop', mdl, Chan1) chancl = smodel.ChanState('chancl', mdl, Chan1) smodel.VDepSReac('VDSR01', ssys, slhs=[chancl], srhs=[chanop], k=vrate, vrange=vrange) smodel.VDepSReac('VDSR02', ssys, srhs=[chancl], slhs=[chanop], k=vrate, vrange=vrange) Chan1_Ohm_I = smodel.OhmicCurr('Chan1_Ohm_I', ssys, chanstate=chanop, g=20e-12, erev=-77e-3) if __name__ == "__main__": self.mesh = meshio.importAbaqus('meshes/test.inp', 1e-7)[0] else: self.mesh = meshio.importAbaqus( 'missing_solver_methods_test/meshes/test.inp', 1e-7)[0] comp1 = sgeom.TmComp('comp1', self.mesh, range(self.mesh.countTets())) comp1.addVolsys('vsys') patch1 = sgeom.TmPatch('patch1', self.mesh, self.mesh.getSurfTris(), comp1) patch1.addSurfsys('ssys') self.c1ROIInds = range(10) self.p1ROIInds = range(5) self.mesh.addROI('comp1ROI', sgeom.ELEM_TET, self.c1ROIInds) self.mesh.addROI('patch1ROI', sgeom.ELEM_TRI, self.p1ROIInds) membrane = sgeom.Memb('membrane', self.mesh, [patch1], opt_method=1) rng = srng.create('mt19937', 512) rng.initialize(1234) self.sim = ssolver.Tetexact(mdl, self.mesh, rng, True) self.sim.setEfieldDT(1e-4) self.sim.reset()
assert (len(submemb_tets_surftris.values()) == len(submemb_tets)) ########## Create a membrane as a surface mesh # Stochastic sim: memb_stoch = sgeom.TmPatch('memb_stoch', mesh_stoch, memb_tris, cyto_stoch) memb_stoch.addSurfsys('ssys_stoch') # Determinsitic sim: memb_det = sgeom.TmPatch('memb_det', mesh_det, memb_tris, cyto_det) memb_det.addSurfsys('ssys_det') # For EField calculation print "Creating membrane.." membrane = sgeom.Memb('membrane', mesh_stoch, [memb_stoch]) print "Membrane created." # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SIMULATION # # # # # # # # # # # # # # # # # # # # # # r = srng.create_mt19937(512) r.initialize(7) r_dummy = srng.create_mt19937(512) r_dummy.initialize(7) print "Creating Tet exact solver" #Creating two solvers sim_stoch = ssolver.Tetexact(mdl_stoch, mesh_stoch, r, True)
for j in range(4): in_tris.add(tritemp[j]) memb_tris = out_tris.intersection(in_tris) memb_tris = list(memb_tris) print len(memb_tris), " surface triangles." ########## Create a membrane as a surface mesh memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto) memb.addSurfsys('ssys') print "Area: ", memb.getArea() print "Creating membrane.." membrane = sgeom.Memb('membrane', mesh, [memb]) print "Membrane created." # # # # # # # # # # # # # # # # # # # # # # # # SIMULATION # # # # # # # # # # # # # # # # # # # # # # r = srng.create_mt19937(512) r.initialize(7) sim = ssolver.Tetexact(mdl, mesh, r, True) print "Resetting simulation object.." sim.reset() print "Injecting molecules.." sim.setTemp(TEMPERATURE + 273.15)
ER_memb_tris, icomp=ER_comp, ocomp=cyto_comp) memb_surf = stetmesh.TmPatch('memb_surf', mesh, NotAzTris, icomp=cyto_comp, ocomp=None) # AZ_surf = stetmesh.TmPatch('AZ_surf', mesh, az_tris, icomp = cyto_comp) # $-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$----- # Create the patch and associate with surface system 'ssys' patch = stetmesh.TmPatch('patch', mesh, NotCaSensTris, icomp=cyto_comp) # Create the membrane across which the potential will be solved membrane = stetmesh.Memb('membrane', mesh, [patch], opt_method=1) # $-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$----- # add volume systems (with all their reactions and diff rules) to compartments: cyto_comp.addVolsys('vsys0') ER_comp.addVolsys('vsys1') memb_surf.addSurfsys('surfsys0') ER_surf.addSurfsys('surfsys2') # $-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$----- patch.addSurfsys('ssys') # $-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$-----$----- # Reactions involving SERCA: # # SERCA species: # SERCA_X0Ca = smodel.Spec('SERCA_X0Ca', model) # SERCA_X1Ca = smodel.Spec('SERCA_X1Ca', model)
tritemp = mesh_stoch.getTetTriNeighb(Comp_tetIDs[i][j]) for tri in tritemp: if tri in memb_tris: Compborder_triIDs[i].append(tri) Compborder_tri_areas[i] = Compborder_tri_areas[i] + mesh_stoch.getTriArea(tri) break ########## Create a membrane as a surface mesh # Stochastic sim: memb_stoch = sgeom.TmPatch('memb_stoch', mesh_stoch, memb_tris, cyto_stoch) memb_stoch.addSurfsys('ssys_stoch') # For EField calculation print "Creating membrane.." membrane = sgeom.Memb('membrane', mesh_stoch, [memb_stoch], opt_file_name = './meshes/'+meshfile_ab+"_optimalidx") print "Membrane created." # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SIMULATION # # # # # # # # # # # # # # # # # # # # # # r = srng.create_mt19937(512) r.initialize(int(time.time()%1000)) # Random-number generator r_dummy = srng.create_mt19937(512) r_dummy.initialize(int(time.time()%1000)) print "Creating tetexact solver..." sim_stoch = ssolver.Tetexact(mdl_stoch, mesh_stoch, r, True) print "Creating WM solver"
for p in pot_pos: # Axis is aligned with z-axis pot_tet[i] = mesh.findTetByPoint([0.0, 0.0, pot_pos[i]]) i = i + 1 # # # # # # # # # # # # # # # GEOMETRY OBJECTS # # # # # # # # # # # # # # # # # # Create cytosol compartment cyto = sgeom.TmComp('cyto', mesh, range(mesh.ntets)) # Create the patch and associate with surface system 'ssys' patch = sgeom.TmPatch('patch', mesh, memb_tris, cyto) patch.addSurfsys('ssys') # Create the membrane across which the potential will be solved membrane = sgeom.Memb('membrane', mesh, [patch], opt_method=1) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Create the random number generator r = srng.create('mt19937', 512) r.initialize(int(time.time() % 10000)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # SIMULATION # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Create solver object using SuperLU EField solver sim = mpi_solver.TetOpSplit(mdl, mesh, r, mpi_solver.EF_DV_SLUSYS, tet_hosts, tri_hosts)
assert (n_minzverts > 0) memb_tris = list(mesh.getSurfTris()) # Doing this now, so will inject into first little z section for t in minztris: memb_tris.remove(t) for t in maxztris: memb_tris.remove(t) # Create the membrane with the tris removed at faces memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto) memb.addSurfsys('ssys') membrane = sgeom.Memb('membrane', mesh, [memb], opt_method=2, search_percent=100.0) # Set the single-channel conductance: g_leak_sc = L_G_tot / len(memb_tris) OC_L = smodel.OhmicCurr('OC_L', ssys, chanstate=Leak, erev=leak_rev, g=g_leak_sc) # Create the solver objects sim = ssolver.TetODE(mdl, mesh, calcMembPot=True) sim.setTolerances(1.0e-6, 1e-6) surfarea_mesh = sim.getPatchArea('memb')
def test_efield_vc(): mesh = make_tri_prism(3, 10, 1.0) interior = sgeom.TmComp('interior', mesh, range(mesh.ntets)) model = smodel.Model() # need at minimum one species sA = smodel.Spec('A', model) patch = sgeom.TmPatch('patch', mesh, mesh.getSurfTris(), interior) memb = sgeom.Memb('membrane', mesh, [patch], opt_method=1) rng = srng.create('r123', 512) sim = ssolver.Tetexact(model, mesh, rng, True) EF_dt = 1e-6 # 1 microsecond sim.reset() sim.setEfieldDT(EF_dt) # initialise potential of mesh vertices to 0V sim.setMembPotential('membrane', 0) # membrane capacitance sim.setMembCapac('membrane', 0) # volume resistivity sim.setMembVolRes('membrane', 1) # 1 ohm·m # clamp top and bottom of prism vtop = set( (vi for tri in mesh.getROIData('top') for vi in mesh.getTri(tri))) vbottom = set( (vi for tri in mesh.getROIData('bottom') for vi in mesh.getTri(tri))) for v in vtop: sim.setVertV(v, 10.0) sim.setVertVClamped(v, True) for v in vbottom: sim.setVertV(v, 0.0) sim.setVertVClamped(v, True) # get means across all horizontal slices slices = dict((int(mo.group(1)), mesh.getROIData(s)) for s in mesh.getAllROINames() for mo in [re.search('slice(\d+)', s)] if mo) slice_keys = list(slices.keys()) slice_keys.sort() N = 10 result = np.zeros((N, 1 + len(slice_keys))) for k in range(N): result[k, 0] = k sim.advance(EF_dt) j = 1 for s in slice_keys: nv = 0 sumv = 0.0 for vi in slices[s]: nv += 1 sumv += sim.getVertV(vi) result[k, j] = sumv / nv j += 1 for i in np.arange(1.0, 12.0): for j in result[1:, int(i)]: assert (abs(j - (i - 1)) < 1e-10)
def test_rallpack3(): print("Rallpack 3 with TetODE") #meshfile ='axon_cube_L1000um_D866m_600tets' meshfile = 'axon_cube_L1000um_D866m_1135tets' #meshfile = 'axon_cube_L1000um_D866nm_1978tets' # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Potassium conductance, Siemens/m^2 K_G = 360 # Sodium conductance, Siemens/m^2 Na_G = 1200 # Leak conductance, Siemens/m^2 L_G = 0.25 # Potassium reversal potential, V K_rev = -77e-3 # Sodium reversal potential, V Na_rev = 50e-3 # Leak reveral potential, V leak_rev = -65.0e-3 # Potassium channel density K_ro = 18.0e12 # Sodium channel density Na_ro = 60.0e12 # Total leak conductance for ideal cylinder: surfarea_cyl = 1.0 * np.pi * 1000 * 1e-12 L_G_tot = L_G * surfarea_cyl # A table of potassium density factors at -65mV, found in getpops. n0, n1, n2, n3, n4 K_FACS = [0.216750577045, 0.40366011853, 0.281904943772, \ 0.0874997924409, 0.0101845682113 ] # A table of sodium density factors. m0h1, m1h1, m2h1, m3h1, m0h0, m1h0, m2h0, m3h0 NA_FACS = [0.343079175644, 0.0575250437508, 0.00321512825945, 5.98988373918e-05, \ 0.506380603793, 0.0849062503811, 0.00474548939393, 8.84099403236e-05] # Ohm.m Ra = 1.0 # # # # # # # # # # # # # # # # SIMULATION CONTROLS # # # # # # # # # # # # # # # The simulation dt (seconds); for TetODE this is equivalent to EField dt SIM_DT = 5.0e-6 # Sim end time (seconds) SIM_END = 0.1 # The number of sim 'time points'; * SIM_DT = sim end time SIM_NTPNTS = int(SIM_END / SIM_DT) + 1 # The current injection in amps Iinj = 0.1e-9 # # # # # # # # # # # # # DATA COLLECTION # # # # # # # # # # # # # # # # # # # record potential at the two extremes along (z) axis POT_POS = np.array([0.0, 1.0e-03]) POT_N = len(POT_POS) # Length of the mesh, in m LENGTH = 1000.0e-6 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # mdl = smodel.Model() ssys = smodel.Surfsys('ssys', mdl) # K channel K = smodel.Chan('K', mdl) K_n0 = smodel.ChanState('K_n0', mdl, K) K_n1 = smodel.ChanState('K_n1', mdl, K) K_n2 = smodel.ChanState('K_n2', mdl, K) K_n3 = smodel.ChanState('K_n3', mdl, K) K_n4 = smodel.ChanState('K_n4', mdl, K) # Na channel Na = smodel.Chan('Na', mdl) Na_m0h1 = smodel.ChanState('Na_m0h1', mdl, Na) Na_m1h1 = smodel.ChanState('Na_m1h1', mdl, Na) Na_m2h1 = smodel.ChanState('Na_m2h1', mdl, Na) Na_m3h1 = smodel.ChanState('Na_m3h1', mdl, Na) Na_m0h0 = smodel.ChanState('Na_m0h0', mdl, Na) Na_m1h0 = smodel.ChanState('Na_m1h0', mdl, Na) Na_m2h0 = smodel.ChanState('Na_m2h0', mdl, Na) Na_m3h0 = smodel.ChanState('Na_m3h0', mdl, Na) # Leak L = smodel.Chan('L', mdl) Leak = smodel.ChanState('Leak', mdl, L) # Gating kinetics _a_m = lambda mV: ((((0.1 * (25 - (mV + 65.)) / (np.exp( (25 - (mV + 65.)) / 10.) - 1))))) _b_m = lambda mV: ((((4. * np.exp(-((mV + 65.) / 18.)))))) _a_h = lambda mV: ((((0.07 * np.exp((-(mV + 65.) / 20.)))))) _b_h = lambda mV: ((((1. / (np.exp((30 - (mV + 65.)) / 10.) + 1))))) _a_n = lambda mV: ((((0.01 * (10 - (mV + 65.)) / (np.exp( (10 - (mV + 65.)) / 10.) - 1))))) _b_n = lambda mV: ((((0.125 * np.exp(-(mV + 65.) / 80.))))) Kn0n1 = smodel.VDepSReac('Kn0n1', ssys, slhs=[K_n0], srhs=[K_n1], k=lambda V: 1.0e3 * 4. * _a_n(V * 1.0e3)) Kn1n2 = smodel.VDepSReac('Kn1n2', ssys, slhs=[K_n1], srhs=[K_n2], k=lambda V: 1.0e3 * 3. * _a_n(V * 1.0e3)) Kn2n3 = smodel.VDepSReac('Kn2n3', ssys, slhs=[K_n2], srhs=[K_n3], k=lambda V: 1.0e3 * 2. * _a_n(V * 1.0e3)) Kn3n4 = smodel.VDepSReac('Kn3n4', ssys, slhs=[K_n3], srhs=[K_n4], k=lambda V: 1.0e3 * 1. * _a_n(V * 1.0e3)) Kn4n3 = smodel.VDepSReac('Kn4n3', ssys, slhs=[K_n4], srhs=[K_n3], k=lambda V: 1.0e3 * 4. * _b_n(V * 1.0e3)) Kn3n2 = smodel.VDepSReac('Kn3n2', ssys, slhs=[K_n3], srhs=[K_n2], k=lambda V: 1.0e3 * 3. * _b_n(V * 1.0e3)) Kn2n1 = smodel.VDepSReac('Kn2n1', ssys, slhs=[K_n2], srhs=[K_n1], k=lambda V: 1.0e3 * 2. * _b_n(V * 1.0e3)) Kn1n0 = smodel.VDepSReac('Kn1n0', ssys, slhs=[K_n1], srhs=[K_n0], k=lambda V: 1.0e3 * 1. * _b_n(V * 1.0e3)) Na_m0h1_m1h1 = smodel.VDepSReac('Na_m0h1_m1h1', ssys, slhs=[Na_m0h1], srhs=[Na_m1h1], k=lambda V: 1.0e3 * 3. * _a_m(V * 1.0e3)) Na_m1h1_m2h1 = smodel.VDepSReac('Na_m1h1_m2h1', ssys, slhs=[Na_m1h1], srhs=[Na_m2h1], k=lambda V: 1.0e3 * 2. * _a_m(V * 1.0e3)) Na_m2h1_m3h1 = smodel.VDepSReac('Na_m2h1_m3h1', ssys, slhs=[Na_m2h1], srhs=[Na_m3h1], k=lambda V: 1.0e3 * 1. * _a_m(V * 1.0e3)) Na_m3h1_m2h1 = smodel.VDepSReac('Na_m3h1_m2h1', ssys, slhs=[Na_m3h1], srhs=[Na_m2h1], k=lambda V: 1.0e3 * 3. * _b_m(V * 1.0e3)) Na_m2h1_m1h1 = smodel.VDepSReac('Na_m2h1_m1h1', ssys, slhs=[Na_m2h1], srhs=[Na_m1h1], k=lambda V: 1.0e3 * 2. * _b_m(V * 1.0e3)) Na_m1h1_m0h1 = smodel.VDepSReac('Na_m1h1_m0h1', ssys, slhs=[Na_m1h1], srhs=[Na_m0h1], k=lambda V: 1.0e3 * 1. * _b_m(V * 1.0e3)) Na_m0h0_m1h0 = smodel.VDepSReac('Na_m0h0_m1h0', ssys, slhs=[Na_m0h0], srhs=[Na_m1h0], k=lambda V: 1.0e3 * 3. * _a_m(V * 1.0e3)) Na_m1h0_m2h0 = smodel.VDepSReac('Na_m1h0_m2h0', ssys, slhs=[Na_m1h0], srhs=[Na_m2h0], k=lambda V: 1.0e3 * 2. * _a_m(V * 1.0e3)) Na_m2h0_m3h0 = smodel.VDepSReac('Na_m2h0_m3h0', ssys, slhs=[Na_m2h0], srhs=[Na_m3h0], k=lambda V: 1.0e3 * 1. * _a_m(V * 1.0e3)) Na_m3h0_m2h0 = smodel.VDepSReac('Na_m3h0_m2h0', ssys, slhs=[Na_m3h0], srhs=[Na_m2h0], k=lambda V: 1.0e3 * 3. * _b_m(V * 1.0e3)) Na_m2h0_m1h0 = smodel.VDepSReac('Na_m2h0_m1h0', ssys, slhs=[Na_m2h0], srhs=[Na_m1h0], k=lambda V: 1.0e3 * 2. * _b_m(V * 1.0e3)) Na_m1h0_m0h0 = smodel.VDepSReac('Na_m1h0_m0h0', ssys, slhs=[Na_m1h0], srhs=[Na_m0h0], k=lambda V: 1.0e3 * 1. * _b_m(V * 1.0e3)) Na_m0h1_m0h0 = smodel.VDepSReac('Na_m0h1_m0h0', ssys, slhs=[Na_m0h1], srhs=[Na_m0h0], k=lambda V: 1.0e3 * _a_h(V * 1.0e3)) Na_m1h1_m1h0 = smodel.VDepSReac('Na_m1h1_m1h0', ssys, slhs=[Na_m1h1], srhs=[Na_m1h0], k=lambda V: 1.0e3 * _a_h(V * 1.0e3)) Na_m2h1_m2h0 = smodel.VDepSReac('Na_m2h1_m2h0', ssys, slhs=[Na_m2h1], srhs=[Na_m2h0], k=lambda V: 1.0e3 * _a_h(V * 1.0e3)) Na_m3h1_m3h0 = smodel.VDepSReac('Na_m3h1_m3h0', ssys, slhs=[Na_m3h1], srhs=[Na_m3h0], k=lambda V: 1.0e3 * _a_h(V * 1.0e3)) Na_m0h0_m0h1 = smodel.VDepSReac('Na_m0h0_m0h1', ssys, slhs=[Na_m0h0], srhs=[Na_m0h1], k=lambda V: 1.0e3 * _b_h(V * 1.0e3)) Na_m1h0_m1h1 = smodel.VDepSReac('Na_m1h0_m1h1', ssys, slhs=[Na_m1h0], srhs=[Na_m1h1], k=lambda V: 1.0e3 * _b_h(V * 1.0e3)) Na_m2h0_m2h1 = smodel.VDepSReac('Na_m2h0_m2h1', ssys, slhs=[Na_m2h0], srhs=[Na_m2h1], k=lambda V: 1.0e3 * _b_h(V * 1.0e3)) Na_m3h0_m3h1 = smodel.VDepSReac('Na_m3h0_m3h1', ssys, slhs=[Na_m3h0], srhs=[Na_m3h1], k=lambda V: 1.0e3 * _b_h(V * 1.0e3)) OC_K = smodel.OhmicCurr('OC_K', ssys, chanstate=K_n4, erev=K_rev, g=K_G / K_ro) OC_Na = smodel.OhmicCurr('OC_Na', ssys, chanstate=Na_m3h0, erev=Na_rev, g=Na_G / Na_ro) # Mesh geometry mesh = meshio.loadMesh('validation_efield/meshes/' + meshfile)[0] cyto = sgeom.TmComp('cyto', mesh, range(mesh.ntets)) # The tetrahedrons from which to record potential POT_TET = np.zeros(POT_N, dtype='uint') i = 0 for p in POT_POS: # Assuming axiz aligned with z-axis POT_TET[i] = mesh.findTetByPoint([0.0, 0.0, POT_POS[i]]) i = i + 1 # Find the tets connected to the bottom face # First find all the tets with ONE face on a boundary boundtets = [] #store the 0to3 index of the surface triangle for each of these boundary tets bt_srftriidx = [] for i in range(mesh.ntets): tettemp = mesh.getTetTetNeighb(i) if (tettemp[0] == -1 or tettemp[1] == -1 or tettemp[2] == -1 or tettemp[3] == -1): boundtets.append(i) templist = [] if (tettemp[0] == -1): templist.append(0) if (tettemp[1] == -1): templist.append(1) if (tettemp[2] == -1): templist.append(2) if (tettemp[3] == -1): templist.append(3) bt_srftriidx.append(templist) assert (boundtets.__len__() == bt_srftriidx.__len__()) # Find the tets on the z=0 and z=1000um boundaries, and the triangles minztets = [] minztris = [] maxztris = [] minzverts = set([]) boundminz = mesh.getBoundMin()[2] + LENGTH / mesh.ntets boundmaxz = mesh.getBoundMax()[2] - LENGTH / mesh.ntets for i in range(boundtets.__len__()): # get the boundary triangle for btriidx in bt_srftriidx[i]: zminboundtri = True tribidx = mesh.getTetTriNeighb(boundtets[i])[btriidx] tritemp = mesh.getTri(tribidx) trizs = [0.0, 0.0, 0.0] trizs[0] = mesh.getVertex(tritemp[0])[2] trizs[1] = mesh.getVertex(tritemp[1])[2] trizs[2] = mesh.getVertex(tritemp[2])[2] for j in range(3): if (trizs[j] > boundminz): zminboundtri = False if (zminboundtri): minztets.append(boundtets[i]) minztris.append(tribidx) minzverts.add(tritemp[0]) minzverts.add(tritemp[1]) minzverts.add(tritemp[2]) continue zmaxboundtri = True for j in range(3): if (trizs[j] < boundmaxz): zmaxboundtri = False if (zmaxboundtri): maxztris.append(tribidx) n_minztris = len(minztris) assert (n_minztris > 0) minzverts = list(minzverts) n_minzverts = len(minzverts) assert (n_minzverts > 0) memb_tris = list(mesh.getSurfTris()) # Doing this now, so will inject into first little z section for t in minztris: memb_tris.remove(t) for t in maxztris: memb_tris.remove(t) # Create the membrane with the tris removed at faces memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto) memb.addSurfsys('ssys') membrane = sgeom.Memb('membrane', mesh, [memb], opt_method=2, search_percent=100.0) # Set the single-channel conductance: g_leak_sc = L_G_tot / len(memb_tris) OC_L = smodel.OhmicCurr('OC_L', ssys, chanstate=Leak, erev=leak_rev, g=g_leak_sc) # Create the solver objects sim = ssolver.TetODE(mdl, mesh, calcMembPot=True) sim.setTolerances(1.0e-6, 1e-6) surfarea_mesh = sim.getPatchArea('memb') surfarea_cyl = 1.0 * np.pi * 1000 * 1e-12 corr_fac_area = surfarea_mesh / surfarea_cyl vol_cyl = np.pi * 0.5 * 0.5 * 1000 * 1e-18 vol_mesh = sim.getCompVol('cyto') corr_fac_vol = vol_mesh / vol_cyl RES_POT = np.zeros((SIM_NTPNTS, POT_N)) for t in memb_tris: sim.setTriCount(t, 'Leak', 1) sim.setPatchCount('memb', 'Na_m0h1', (Na_ro * surfarea_cyl * NA_FACS[0])) sim.setPatchCount('memb', 'Na_m1h1', (Na_ro * surfarea_cyl * NA_FACS[1])) sim.setPatchCount('memb', 'Na_m2h1', (Na_ro * surfarea_cyl * NA_FACS[2])) sim.setPatchCount('memb', 'Na_m3h1', (Na_ro * surfarea_cyl * NA_FACS[3])) sim.setPatchCount('memb', 'Na_m0h0', (Na_ro * surfarea_cyl * NA_FACS[4])) sim.setPatchCount('memb', 'Na_m1h0', (Na_ro * surfarea_cyl * NA_FACS[5])) sim.setPatchCount('memb', 'Na_m2h0', (Na_ro * surfarea_cyl * NA_FACS[6])) sim.setPatchCount('memb', 'Na_m3h0', (Na_ro * surfarea_cyl * NA_FACS[7])) sim.setPatchCount('memb', 'K_n0', (K_ro * surfarea_cyl * K_FACS[0])) sim.setPatchCount('memb', 'K_n1', (K_ro * surfarea_cyl * K_FACS[1])) sim.setPatchCount('memb', 'K_n2', (K_ro * surfarea_cyl * K_FACS[2])) sim.setPatchCount('memb', 'K_n3', (K_ro * surfarea_cyl * K_FACS[3])) sim.setPatchCount('memb', 'K_n4', (K_ro * surfarea_cyl * K_FACS[4])) sim.setMembPotential('membrane', -65e-3) sim.setMembVolRes('membrane', Ra * corr_fac_vol) sim.setMembCapac('membrane', 0.01 / corr_fac_area) for v in minzverts: sim.setVertIClamp(v, Iinj / n_minzverts) for l in range(SIM_NTPNTS): sim.run(SIM_DT * l) for p in range(POT_N): RES_POT[l, p] = sim.getTetV(int(POT_TET[p])) * 1.0e3 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Benchmark # At 0um- the end of the mesh ifile_benchmark_x0 = open( 'validation_efield/data/rallpack3_benchmark/rallpack3_0_0.001dt_1000seg', 'r') # At 1000um- the end of the mesh ifile_benchmark_x1000 = open( 'validation_efield/data/rallpack3_benchmark/rallpack3_1000_0.001dt_1000seg', 'r') tpnt_benchmark = [] v_benchmark_x0 = [] v_benchmark_x1000 = [] lines_benchmark_x0 = ifile_benchmark_x0.readlines()[2:] # Read in mv and ms for line_benchmark_x0 in lines_benchmark_x0: nums = line_benchmark_x0.split() tpnt_benchmark.append(float(nums[0])) v_benchmark_x0.append(float(nums[1])) lines_benchmark_x1000 = ifile_benchmark_x1000.readlines()[2:] for line_benchmark_x1000 in lines_benchmark_x1000: nums = line_benchmark_x1000.split() v_benchmark_x1000.append(float(nums[1])) # Get rid of the last point which seems to be missing from STEPS v_benchmark_x0 = v_benchmark_x0[:-1] tpnt_benchmark = tpnt_benchmark[:-1] v_benchmark_x1000 = v_benchmark_x1000[:-1] rms0 = stats(v_benchmark_x0, RES_POT[:, 0]) assert (rms0 < 0.15) rms1000 = stats(v_benchmark_x1000, RES_POT[:, 1]) assert (rms1000 < 1.1)