def gen_geom(): # import the tetrahedral mesh mesh = meshio.importAbaqus('astrocyte.inp', 1e-6)[0] # create a compartment comprising all mesh tetrahedrons ntets = mesh.countTets() # create cytosolic compartment cyto = stetmesh.TmComp('cyto', mesh, range(ntets)) # add volume system to cytosol cyto.addVolsys('vsys') # create ER compartment er = stetmesh.Comp('er', mesh) # Assign volume to ER er.setVol(0.00314e-19) # add volume system to ER cyto.addVolsys('er_vsys') # Define surfaces # "cylinder_mesh.txt" describes Cyto & ER surfaces to import input = open("cylinder_mesh.txt", 'r') ASTRO_TRIS = pickle.load(input) ER_TRIS = pickle.load(input) input.close() # create the patch for ER membrane er_patch = stetmesh.TmPatch('er_patch', mesh, ER_TRIS, cyto) er_patch.addSurfsys('ssys') # create the patch for astrocyte plasma membrane cyto_patch = stetmesh.TmPatch('cyto_patch', mesh, ASTRO_TRIS, icomp=cyto) cyto_patch.addSurfsys('mb_surf') # return geometry container object return mesh, ASTRO_TRIS, ER_TRIS
def setUp(self): self.model = smodel.Model() A = smodel.Spec('A', self.model) surfsys = smodel.Surfsys('ssys', self.model) D_a = smodel.Diff('D_a', surfsys, A) self.DCST = 0.2e-9 D_a.setDcst(self.DCST) self.mesh = meshio.importAbaqus2("directional_dcst_test/mesh_tet.inp", "directional_dcst_test/mesh_tri.inp", 1e-6, "directional_dcst_test/mesh_conf")[0] boundary_tris = self.mesh.getROIData("boundary") v1_tets = self.mesh.getROIData("v1_tets") comp1 = sgeom.TmComp("comp1", self.mesh, v1_tets) patch1 = sgeom.TmPatch("patch", self.mesh, boundary_tris, comp1) patch1.addSurfsys("ssys") self.neigh_tris = self.mesh.getROIData("neigh_tri") self.focus_tri = self.mesh.getROIData("focus_tri")[0] self.rng = srng.create('r123', 512) self.rng.initialize(1000) self.solver = solv.Tetexact(self.model, self.mesh, self.rng)
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 setUp(self): self.model = smodel.Model() self.vsys1 = smodel.Volsys('vsys1', self.model) self.ssys1 = smodel.Surfsys('ssys1', self.model) if __name__ == "__main__": self.mesh = meshio.loadMesh('meshes/cyl_len10_diam1')[0] else: self.mesh = meshio.loadMesh( 'getROIArea_bugfix_test/meshes/cyl_len10_diam1')[0] ntets = self.mesh.countTets() comp1Tets, comp2Tets = [], [] comp1Tris, comp2Tris = set(), set() for i in range(ntets): if self.mesh.getTetBarycenter(i)[0] > 0: comp1Tets.append(i) comp1Tris |= set(self.mesh.getTetTriNeighb(i)) else: comp2Tets.append(i) comp2Tris |= set(self.mesh.getTetTriNeighb(i)) patch1Tris = list(comp1Tris & comp2Tris) self.comp1 = sgeom.TmComp('comp1', self.mesh, comp1Tets) self.comp2 = sgeom.TmComp('comp2', self.mesh, comp2Tets) self.comp1.addVolsys('vsys1') self.comp2.addVolsys('vsys1') self.patch1 = sgeom.TmPatch('patch1', self.mesh, patch1Tris, self.comp1, self.comp2) self.patch1.addSurfsys('ssys1') self.ROI1 = self.mesh.addROI('ROI1', sgeom.ELEM_TRI, patch1Tris)
def setUp(self): mdl = smodel.Model() S1 = smodel.Spec('S1', mdl) ssys = smodel.Surfsys('ssys', mdl) smodel.SReac('SR01', ssys, slhs=[S1], srhs=[S1], kcst=1) if __name__ == "__main__": mesh = meshio.importAbaqus('meshes/test.inp', 1e-7)[0] else: mesh = meshio.importAbaqus( 'tetODE_setPatchSReacK_bugfix_test/meshes/test.inp', 1e-7)[0] comp1 = sgeom.TmComp('comp1', mesh, range(mesh.countTets())) patch1 = sgeom.TmPatch('patch1', mesh, mesh.getSurfTris(), comp1) patch1.addSurfsys('ssys') rng = srng.create('mt19937', 512) rng.initialize(1234) self.sim = ssolver.TetODE(mdl, mesh, rng) self.sim.setTolerances(1.0e-3, 1.0e-3)
def setUp(self): DCST = 0.08e-10 self.model = smodel.Model() A = smodel.Spec('A', self.model) self.vsys = smodel.Volsys('vsys', self.model) self.ssys = smodel.Surfsys('ssys', self.model) self.diff = smodel.Diff("diff", self.vsys, A, DCST) self.sdiff = smodel.Diff("diff", self.ssys, A, DCST) if __name__ == "__main__": self.mesh = meshio.importAbaqus('meshes/test_mesh.inp', 1e-7)[0] else: self.mesh = meshio.importAbaqus( 'parallel_std_string_bugfix_test/meshes/test_mesh.inp', 1e-7)[0] self.tmcomp = sgeom.TmComp('comp', self.mesh, range(self.mesh.ntets)) self.tmcomp.addVolsys('vsys') self.surf_tris = self.mesh.getSurfTris() self.tmpatch = sgeom.TmPatch('patch', self.mesh, self.surf_tris, icomp=self.tmcomp) self.tmpatch.addSurfsys('ssys') self.rng = srng.create('r123', 512) self.rng.initialize(1000) tet_hosts = gd.binTetsByAxis(self.mesh, steps.mpi.nhosts) tri_hosts = gd.partitionTris(self.mesh, tet_hosts, self.surf_tris) self.solver = solv.TetOpSplit(self.model, self.mesh, self.rng, solv.EF_NONE, tet_hosts, tri_hosts) self.solver.reset()
def setUp(self): DCST = 0.08e-10 self.model = smodel.Model() A = smodel.Spec('A', self.model) self.vsys = smodel.Volsys('vsys', self.model) self.ssys = smodel.Surfsys('ssys', self.model) self.diff = smodel.Diff("diff", self.vsys, A, DCST) self.sdiff = smodel.Diff("diff", self.ssys, A, DCST) if __name__ == "__main__": self.mesh = meshio.importAbaqus('meshes/test_mesh.inp', 1e-7)[0] else: self.mesh = meshio.importAbaqus( 'parallel_diff_sel_test/meshes/test_mesh.inp', 1e-7)[0] self.tmcomp = sgeom.TmComp('comp', self.mesh, range(self.mesh.ntets)) self.tmcomp.addVolsys('vsys') self.surf_tris = self.mesh.getSurfTris() self.tmpatch = sgeom.TmPatch('patch', self.mesh, self.surf_tris, icomp=self.tmcomp) self.tmpatch.addSurfsys('ssys') self.rng = srng.create('r123', 512) self.rng.initialize(1000)
def setUp(self): self.model = smodel.Model() A = smodel.Spec("A", self.model) B = smodel.Spec("B", self.model) C = smodel.Spec("C", self.model) D = smodel.Spec("D", self.model) E = smodel.Spec("E", self.model) self.vsys1 = smodel.Volsys('vsys1', self.model) self.vsys2 = smodel.Volsys('vsys2', self.model) self.ssys1 = smodel.Surfsys('ssys1', self.model) self.reac1 = smodel.Reac('reac1', self.vsys1, lhs = [A], rhs = [A], kcst = 1e5) self.reac2 = smodel.Reac('reac2', self.vsys2, lhs = [E], rhs = [E], kcst = 1e4) self.sreac = smodel.SReac('sreac', self.ssys1, slhs = [B], srhs = [B], kcst = 1e3) if __name__ == "__main__": self.mesh = meshio.loadMesh('meshes/cyl_len10_diam1')[0] else: self.mesh = meshio.loadMesh('getROIArea_bugfix_test/meshes/cyl_len10_diam1')[0] ntets = self.mesh.countTets() comp1Tets, comp2Tets = [], [] comp1Tris, comp2Tris = set(), set() for i in range(ntets): if self.mesh.getTetBarycenter(i)[0] > 0: comp1Tets.append(i) comp1Tris |= set(self.mesh.getTetTriNeighb(i)) else: comp2Tets.append(i) comp2Tris |= set(self.mesh.getTetTriNeighb(i)) patch1Tris = list(comp1Tris & comp2Tris) self.comp1 = sgeom.TmComp('comp1', self.mesh, comp1Tets) self.comp2 = sgeom.TmComp('comp2', self.mesh, comp2Tets) self.comp1.addVolsys('vsys1') self.comp2.addVolsys('vsys2') self.patch1 = sgeom.TmPatch('patch1', self.mesh, patch1Tris, self.comp1, self.comp2) self.patch1.addSurfsys('ssys1') self.ROI1 = self.mesh.addROI('ROI1', sgeom.ELEM_TET, comp1Tets) self.ROI2 = self.mesh.addROI('ROI2', sgeom.ELEM_TET, comp2Tets) self.ROI3 = self.mesh.addROI('ROI3', sgeom.ELEM_TRI, patch1Tris) self.rng = srng.create('r123', 512) self.rng.initialize(1000) tet_hosts = gd.linearPartition(self.mesh, [steps.mpi.nhosts, 1, 1]) tri_hosts = gd.partitionTris(self.mesh, tet_hosts, patch1Tris) self.solver = solv.TetOpSplit(self.model, self.mesh, self.rng, solv.EF_NONE, tet_hosts, tri_hosts)
def gen_geom(): mesh = smeshio.loadMesh('validation_rd/meshes/' + MESHFILE)[0] ntets = mesh.countTets() comp = stetmesh.TmComp('cyto', mesh, range(ntets)) alltris = mesh.getSurfTris() patch_tris = [] for t in alltris: baryc = mesh.getTriBarycenter(t) rad = np.sqrt(np.power(baryc[0], 2) + np.power(baryc[1], 2)) # By checking the cubit mesh the outer tris fall in the following bound if rad > 0.000009955 and rad < 0.00001001: patch_tris.append(t) patch = stetmesh.TmPatch('patch', mesh, patch_tris, icomp=comp) patch.addSurfsys('ssys') area = 0 for t in patch_tris: area += mesh.getTriArea(t) inject_tris = [] for p in patch_tris: # X should be maximum (10) for the inject region if mesh.getTriBarycenter(p)[0] > 9.999e-6: inject_tris.append(p) patch_tris_n = len(patch_tris) # Now find the distances along the edge for all tris tridists = np.zeros(patch_tris_n) triareas = np.zeros(patch_tris_n) for i in range(patch_tris_n): baryc = mesh.getTriBarycenter(patch_tris[i]) rad = np.sqrt(np.power(baryc[0], 2) + np.power(baryc[1], 2)) theta = np.arctan2(baryc[1], baryc[0]) tridists[i] = (theta * rad * 1e6) triareas[i] = mesh.getTriArea(patch_tris[i]) # Triangles will be separated into those to the 'high' side (positive y) with positive L # and those on the low side (negative y) with negative L return mesh, patch_tris, patch_tris_n, inject_tris, tridists, triareas
def gen_geom(): mesh = smeshio.loadMesh('meshes/coin_10r_1h_13861')[0] ntets = mesh.countTets() comp = stetmesh.TmComp('cyto', mesh, range(ntets)) alltris = mesh.getSurfTris() # Sort patch triangles as those of positive z patch_tris = [] for t in alltris: vert0, vert1, vert2 = mesh.getTri(t) if (mesh.getVertex(vert0)[2] > 0.0 \ and mesh.getVertex(vert1)[2] > 0.0 \ and mesh.getVertex(vert2)[2] > 0.0): patch_tris.append(t) # Create the patch patch = stetmesh.TmPatch('patch', mesh, patch_tris, icomp=comp) patch.addSurfsys('ssys') patch_tris_n = len(patch_tris) trirads = pylab.zeros(patch_tris_n) triareas = pylab.zeros(patch_tris_n) # Find the central tri ctetidx = mesh.findTetByPoint([0.0, 0.0, 0.5e-6]) ctet_trineighbs = mesh.getTetTriNeighb(ctetidx) ctri_idx = -1 for t in ctet_trineighbs: if t in patch_tris: ctri_idx = t # Now find the distance of the centre of each tri to the central tri cbaryc = mesh.getTriBarycenter(ctri_idx) for i in range(patch_tris_n): baryc = mesh.getTriBarycenter(patch_tris[i]) r2 = math.pow((baryc[0]-cbaryc[0]),2) + \ math.pow((baryc[1]-cbaryc[1]),2) + \ math.pow((baryc[2]-cbaryc[2]),2) r = math.sqrt(r2) # Convert to microns trirads[i] = r * 1.0e6 triareas[i] = mesh.getTriArea(patch_tris[i]) * 1.0e12 return mesh, patch_tris, patch_tris_n, ctri_idx, trirads, triareas
def boundTrisAsPatch(mesh, patch_name, icomp=None, ocomp=None, scale=1e-6): """ Create a patch in the STEPS Tetmesh object using triangles bound in selected volumes. Parameters: * mesh Associated Tetmesh object created in STEPS * comp_name Name of the compartment * scale LENGTH scale from the CUBIT gemoetry to real geometry. e.g. a radius of 10 in CUBIT to a radius of 1 micron in STEPS, scale is 1e-7. By default the scale is 1e-6, i.e. 1 unit in CUBIT equals 1 micron in STEPS. Return: steps.geom.TmComp object """ steps_ids = getTrisBoundInSelectedVols(mesh, scale) patch = sgeom.TmPatch(patch_name, mesh, steps_ids, icomp, ocomp) return patch
def SelectedTrisAsPatch(mesh, tri_proxy, patch_name, icomp=None, ocomp=None): """ Create a patch in the STEPS Tetmesh object using selected triangles. Parameters: * mesh Associated Tetmesh object created in STEPS * tri_proxy Triangle element proxy generated by STEPS mesh importing function * patch_name Name of the patch * icomp Inner TmComp compartment object (not name), None by default * ocomp Outer TmComp compartment object (not name), None by default Return: steps.geom.TmPatch object """ steps_ids = getSelectedTris(tri_proxy)[0] patch = sgeom.TmPatch(patch_name, mesh, steps_ids, icomp, ocomp) return patch
def gen_geom(): mesh = smeshio.loadMesh('validation_rd/meshes/' + MESHFILE)[0] ctetidx = mesh.findTetByPoint([0.0, 0.0, 0.5e-6]) ntets = mesh.countTets() comp = stetmesh.TmComp('cyto', mesh, range(ntets)) alltris = mesh.getSurfTris() patch_tris = [] for t in alltris: vert0, vert1, vert2 = mesh.getTri(t) if (mesh.getVertex(vert0)[2] > 0.0 and mesh.getVertex(vert1)[2] > 0.0 and mesh.getVertex(vert2)[2] > 0.0): patch_tris.append(t) patch_tris_n = len(patch_tris) patch = stetmesh.TmPatch('patch', mesh, patch_tris, icomp=comp) patch.addSurfsys('ssys') trirads = numpy.zeros(patch_tris_n) triareas = numpy.zeros(patch_tris_n) # TRy to find the central tri ctet_trineighbs = mesh.getTetTriNeighb(ctetidx) ctri_idx = -1 for t in ctet_trineighbs: if t in patch_tris: ctri_idx = t # Now find the distance of the center of the tets to the center of the center tet (at 0,0,0) cbaryc = mesh.getTriBarycenter(ctri_idx) for i in range(patch_tris_n): baryc = mesh.getTriBarycenter(patch_tris[i]) r2 = math.pow((baryc[0] - cbaryc[0]), 2) + math.pow( (baryc[1] - cbaryc[1]), 2) + math.pow((baryc[2] - cbaryc[2]), 2) r = math.sqrt(r2) # Conver to microns trirads[i] = r * 1.0e6 triareas[i] = mesh.getTriArea(patch_tris[i]) return mesh, patch_tris, patch_tris_n, ctri_idx, trirads, triareas
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 run_sim(): # Set up and run the simulations once, before the tests # analyze the results. ##################### First order irreversible ######################### global KCST_foi, N_foi, tolerance_foi KCST_foi = 5 # The reaction constant N_foi = 50 # Can set count or conc NITER_foi = 100000 # The number of iterations # Tolerance for the comparison: # In test runs, with good code, < 1% will fail with a 1.5% tolerance tolerance_foi = 2.0 / 100 ####################### First order reversible ######################### global KCST_f_for, KCST_b_for, COUNT_for, tolerance_for KCST_f_for = 10.0 # The reaction constant KCST_b_for = 2.0 COUNT_for = 100000 # Can set count or conc NITER_for = 10 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 1% tolerance_for = 1.0 / 100 ####################### Second order irreversible A2 ################### global KCST_soA2, CONCA_soA2, tolerance_soA2 KCST_soA2 = 10.0e6 # The reaction constant CONCA_soA2 = 10.0e-6 NITER_soA2 = 1000 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 2% tolerance_soA2 = 3.0 / 100 ####################### Second order irreversible AA ################### global KCST_soAA, CONCA_soAA, CONCB_soAA, tolerance_soAA KCST_soAA = 5.0e6 # The reaction constant CONCA_soAA = 20.0e-6 CONCB_soAA = CONCA_soAA NITER_soAA = 1000 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 1% tolerance_soAA = 2.0 / 100 ####################### Second order irreversible AB ################### global KCST_soAB, CONCA_soAB, CONCB_soAB, tolerance_soAB KCST_soAB = 5.0e6 # The reaction constant CONCA_soAB = 1.0e-6 n_soAB = 2 CONCB_soAB = CONCA_soAB / n_soAB NITER_soAB = 1000 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 1% tolerance_soAB = 1.0 / 100 ####################### Third order irreversible A3 ################### global KCST_toA3, CONCA_toA3, tolerance_toA3 KCST_toA3 = 1.0e12 # The reaction constant CONCA_toA3 = 10.0e-6 NITER_toA3 = 1000 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 1% tolerance_toA3 = 3.0 / 100 ####################### Third order irreversible A2B ################### global KCST_toA2B, CONCA_toA2B, CONCB_toA2B, tolerance_toA2B KCST_toA2B = 0.1e12 # The reaction constant CONCA_toA2B = 30.0e-6 CONCB_toA2B = 20.0e-6 NITER_toA2B = 1000 # The number of iterations # In test runs, with good code, <0.1% will fail with a tolerance of 1% tolerance_toA2B = 1.0 / 100 ####################### Second order irreversible 2D ################### global COUNTA_so2d, COUNTB_so2d, CCST_so2d, tolerance_so2d COUNTA_so2d = 100.0 n_so2d = 2.0 COUNTB_so2d = COUNTA_so2d / n_so2d KCST_so2d = 10.0e10 # The reaction constant AREA_so2d = 10.0e-12 NITER_so2d = 1000 # The number of iterations # In tests fewer than 0.1% fail with tolerance of 2% tolerance_so2d = 1.0 / 100 ############################ Common parameters ######################## global VOL DT = 0.1 # Sampling time-step INT = 1.1 # Sim endtime NITER_max = 100000 ######################################################################## mdl = smod.Model() volsys = smod.Volsys('vsys', mdl) surfsys = smod.Surfsys('ssys', mdl) # First order irreversible A_foi = smod.Spec('A_foi', mdl) A_foi_diff = smod.Diff('A_foi_diff', volsys, A_foi, 0.01e-12) R1_foi = smod.Reac('R1_foi', volsys, lhs=[A_foi], rhs=[], kcst=KCST_foi) # First order reversible A_for = smod.Spec('A_for', mdl) B_for = smod.Spec('B_for', mdl) A_for_diff = smod.Diff('A_for_diff', volsys, A_for, 0.01e-12) B_for_diff = smod.Diff('B_for_diff', volsys, B_for, 0.01e-12) R1_for = smod.Reac('R1_for', volsys, lhs=[A_for], rhs=[B_for], kcst=KCST_f_for) R2_for = smod.Reac('R2_for', volsys, lhs=[B_for], rhs=[A_for], kcst=KCST_b_for) # Second order irreversible A2 A_soA2 = smod.Spec('A_soA2', mdl) C_soA2 = smod.Spec('C_soA2', mdl) A_soA2_diff = smod.Diff('A_soA2_diff', volsys, A_soA2, 1e-12) R1_soA2 = smod.Reac('R1_soA2', volsys, lhs=[A_soA2, A_soA2], rhs=[C_soA2], kcst=KCST_soA2) # Second order irreversible AA A_soAA = smod.Spec('A_soAA', mdl) B_soAA = smod.Spec('B_soAA', mdl) C_soAA = smod.Spec('C_soAA', mdl) A_soAA_diff = smod.Diff('A_soAA_diff', volsys, A_soAA, 0.2e-12) B_soAA_diff = smod.Diff('B_soAA_diff', volsys, B_soAA, 0.2e-12) R1_soAA = smod.Reac('R1_soAA', volsys, lhs=[A_soAA, B_soAA], rhs=[C_soAA], kcst=KCST_soAA) # Second order irreversible AB A_soAB = smod.Spec('A_soAB', mdl) B_soAB = smod.Spec('B_soAB', mdl) C_soAB = smod.Spec('C_soAB', mdl) A_soAB_diff = smod.Diff('A_soAB_diff', volsys, A_soAB, 0.1e-12) B_soAB_diff = smod.Diff('B_soAB_diff', volsys, B_soAB, 0.1e-12) R1_soAB = smod.Reac('R1_soAB', volsys, lhs=[A_soAB, B_soAB], rhs=[C_soAB], kcst=KCST_soAB) # Third order irreversible A3 A_toA3 = smod.Spec('A_toA3', mdl) C_toA3 = smod.Spec('C_toA3', mdl) A_soA3_diff = smod.Diff('A_soA3_diff', volsys, A_toA3, 0.2e-12) R1_toA3 = smod.Reac('R1_toA3', volsys, lhs=[A_toA3, A_toA3, A_toA3], rhs=[C_toA3], kcst=KCST_toA3) # Third order irreversible A2B A_toA2B = smod.Spec('A_toA2B', mdl) B_toA2B = smod.Spec('B_toA2B', mdl) C_toA2B = smod.Spec('C_toA2B', mdl) A_soA2B_diff = smod.Diff('A_soA2B_diff', volsys, A_toA2B, 0.1e-12) B_soA2B_diff = smod.Diff('B_soA2B_diff', volsys, B_toA2B, 0.1e-12) R1_toA3 = smod.Reac('R1_toA2B', volsys, lhs=[A_toA2B, A_toA2B, B_toA2B], rhs=[C_toA2B], kcst=KCST_toA2B) # Second order irreversible 2D A_so2d = smod.Spec('A_so2d', mdl) B_so2d = smod.Spec('B_so2d', mdl) C_so2d = smod.Spec('C_so2d', mdl) A_so2d_diff = smod.Diff('A_so2d_diff', surfsys, A_so2d, 1.0e-12) B_so2d_diff = smod.Diff('B_so2d_diff', surfsys, B_so2d, 1.0e-12) SR1_so2d = smod.SReac('SR1_so2d', surfsys, slhs=[A_so2d, B_so2d], srhs=[C_so2d], kcst=KCST_so2d) mesh = smeshio.importAbaqus('validation_rd/meshes/sphere_rad1_37tets.inp', 1e-6)[0] VOL = mesh.getMeshVolume() comp1 = sgeom.TmComp('comp1', mesh, range(mesh.ntets)) comp1.addVolsys('vsys') patch1 = sgeom.TmPatch('patch1', mesh, mesh.getSurfTris(), comp1) patch1.addSurfsys('ssys') CCST_so2d = KCST_so2d / (6.02214179e23 * patch1.getArea()) rng = srng.create('r123', 512) rng.initialize(1000) sim = ssolv.Tetexact(mdl, mesh, rng) sim.reset() global tpnts, ntpnts tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res_m_foi = numpy.zeros([NITER_foi, ntpnts, 1]) res_std1_foi = numpy.zeros([ntpnts, 1]) res_std2_foi = numpy.zeros([ntpnts, 1]) res_m_for = numpy.zeros([NITER_for, ntpnts, 2]) res_m_soA2 = numpy.zeros([NITER_soA2, ntpnts, 2]) res_m_soAA = numpy.zeros([NITER_soAA, ntpnts, 3]) res_m_soAB = numpy.zeros([NITER_soAB, ntpnts, 3]) res_m_toA3 = numpy.zeros([NITER_toA3, ntpnts, 2]) res_m_toA2B = numpy.zeros([NITER_toA2B, ntpnts, 3]) res_m_so2d = numpy.zeros([NITER_so2d, ntpnts, 3]) for i in range(0, NITER_max): sim.reset() if i < NITER_foi: sim.setCompCount('comp1', 'A_foi', N_foi) if i < NITER_for: sim.setCompCount('comp1', 'A_for', COUNT_for) sim.setCompCount('comp1', 'B_for', 0.0) if i < NITER_soA2: sim.setCompConc('comp1', 'A_soA2', CONCA_soA2) if i < NITER_soAA: sim.setCompConc('comp1', 'A_soAA', CONCA_soAA) sim.setCompConc('comp1', 'B_soAA', CONCB_soAA) if i < NITER_soAB: sim.setCompConc('comp1', 'A_soAB', CONCA_soAB) sim.setCompConc('comp1', 'B_soAB', CONCB_soAB) if i < NITER_toA3: sim.setCompConc('comp1', 'A_toA3', CONCA_toA3) if i < NITER_toA2B: sim.setCompConc('comp1', 'A_toA2B', CONCA_toA2B) sim.setCompConc('comp1', 'B_toA2B', CONCB_toA2B) if i < NITER_so2d: sim.setPatchCount('patch1', 'A_so2d', COUNTA_so2d) sim.setPatchCount('patch1', 'B_so2d', COUNTB_so2d) for t in range(0, ntpnts): sim.run(tpnts[t]) if i < NITER_foi: res_m_foi[i, t, 0] = sim.getCompCount('comp1', 'A_foi') if i < NITER_for: res_m_for[i, t, 0] = sim.getCompConc('comp1', 'A_for') * 1e6 res_m_for[i, t, 1] = sim.getCompConc('comp1', 'B_for') * 1e6 if i < NITER_soA2: res_m_soA2[i, t, 0] = sim.getCompConc('comp1', 'A_soA2') if i < NITER_soAA: res_m_soAA[i, t, 0] = sim.getCompConc('comp1', 'A_soAA') res_m_soAA[i, t, 1] = sim.getCompConc('comp1', 'B_soAA') if i < NITER_soAB: res_m_soAB[i, t, 0] = sim.getCompConc('comp1', 'A_soAB') res_m_soAB[i, t, 1] = sim.getCompConc('comp1', 'B_soAB') if i < NITER_toA3: res_m_toA3[i, t, 0] = sim.getCompConc('comp1', 'A_toA3') if i < NITER_toA2B: res_m_toA2B[i, t, 0] = sim.getCompConc('comp1', 'A_toA2B') res_m_toA2B[i, t, 1] = sim.getCompConc('comp1', 'B_toA2B') res_m_toA2B[i, t, 2] = sim.getCompConc('comp1', 'C_toA2B') if i < NITER_so2d: res_m_so2d[i, t, 0] = sim.getPatchCount('patch1', 'A_so2d') res_m_so2d[i, t, 1] = sim.getPatchCount('patch1', 'B_so2d') global mean_res_foi, std_res_foi mean_res_foi = numpy.mean(res_m_foi, 0) std_res_foi = numpy.std(res_m_foi, 0) global mean_res_for mean_res_for = numpy.mean(res_m_for, 0) global mean_res_soA2 mean_res_soA2 = numpy.mean(res_m_soA2, 0) global mean_res_soAA mean_res_soAA = numpy.mean(res_m_soAA, 0) global mean_res_soAB mean_res_soAB = numpy.mean(res_m_soAB, 0) global mean_res_toA3 mean_res_toA3 = numpy.mean(res_m_toA3, 0) global mean_res_toA2B mean_res_toA2B = numpy.mean(res_m_toA2B, 0) global mean_res_so2d mean_res_so2d = numpy.mean(res_m_so2d, 0) global ran_sim ran_sim = True
def setUp(self): KCST = 1e6 DCST = 0.08e-12 self.model = smodel.Model() A = smodel.Spec('A', self.model) B = smodel.Spec('B', self.model) C = smodel.Spec('C', self.model) D = smodel.Spec('D', self.model) E = smodel.Spec('E', self.model) F = smodel.Spec('F', self.model) self.ssys1 = smodel.Surfsys('ssys1', self.model) self.ssys2 = smodel.Surfsys('ssys2', self.model) self.sreac1 = smodel.SReac('sreac1', self.ssys1, slhs=[A, B], srhs=[C], kcst=KCST) self.sreac2 = smodel.SReac('sreac2', self.ssys2, slhs=[D, E], srhs=[F], kcst=KCST) self.geom = sgeom.Geom() self.comp = sgeom.Comp('comp', self.geom, 1e-18) self.patch1 = sgeom.Patch('patch1', self.geom, self.comp, None, 1e-12) self.patch1.addSurfsys('ssys1') self.patch2 = sgeom.Patch('patch2', self.geom, self.comp, None, 1e-12) self.patch2.addSurfsys('ssys2') if __name__ == "__main__": self.mesh = meshio.importAbaqus('meshes/brick_40_4_4_1400tets.inp', 1e-6)[0] else: self.mesh = meshio.importAbaqus( 'multi_sys_test/meshes/brick_40_4_4_1400tets.inp', 1e-6)[0] comp1_tets = [] comp2_tets = [] for t in range(self.mesh.ntets): cord = self.mesh.getTetBarycenter(t) if cord[0] < 0.0: comp1_tets.append(t) else: comp2_tets.append(t) self.tmcomp = sgeom.TmComp('comp', self.mesh, range(self.mesh.ntets)) surf_tris = self.mesh.getSurfTris() patch_tris1 = [] patch_tris2 = [] for tri in surf_tris: tet_neighs = self.mesh.getTriTetNeighb(tri) for tet in tet_neighs: if tet in comp1_tets: patch_tris1.append(tri) break elif tet in comp2_tets: patch_tris2.append(tri) break self.tmpatch1 = sgeom.TmPatch('patch1', self.mesh, patch_tris1, self.tmcomp) self.tmpatch1.addSurfsys('ssys1') self.tmpatch2 = sgeom.TmPatch('patch2', self.mesh, patch_tris2, self.tmcomp) self.tmpatch2.addSurfsys('ssys2') self.rng = srng.create('r123', 512) self.rng.initialize(1000)
def loadMesh(pathname): """ Load a mesh in STEPS from the XML (and ASCII) file. This will work with just the XML file, but this is akin to creating the mesh in STEPS from scratch and really negates the use of storing the mesh infomation at all. For maximum benefit the XML file should be accompanied by the ASCII file, which contains all the internal information. PARAMETERS: * pathname: the root of the path where the file(s) are stored. e.g. with 'meshes/spine1' this function will look for files /meshes/spine1.xml and /meshes/spine1.txt RETURNS: A tuple (mesh, comps, patches) * mesh The STEPS Tetmesh object (steps.geom.Tetmesh) * comps A list of any compartment objects (steps.geom.TmComp) from XML file * patches A list of any patches objects (steps.geom.TmPatch) from XML file """ # Try to open the XML file. An error will be thrown if it doesn't exist xmlfile = open(pathname+'.xml', 'r') # Try to open the text file. A warning will be shown and a flag set if it doesn't exist havetxt = True try : textfile = open(pathname+'.txt', 'r') except: havetxt = False if (havetxt == False) : print("WARNING: text file not found. Will construct mesh from information in XML file only.") # Perform a basic check to see if we have the expected kind of file which has not been altered. info = xmlfile.readline() if(xmlfile.readline().rstrip() != '<tetmesh>'): print('XML file is not a recognised STEPS mesh file') return # Collect basic node information and perform some checks on the data read from XML file nodeinfo = xmlfile.readline().strip() assert(nodeinfo.__len__() > 17) assert(nodeinfo[-2:] == '">') nnodes = int(nodeinfo[15:-2]) if (havetxt): assert (nnodes == int(textfile.readline())) nodes_out = [0.0]*(nnodes*3) for i in range(nnodes): idxtemp = xmlfile.readline().strip() assert(int(idxtemp[13:-2]) == i) coordtemp = xmlfile.readline().strip() assert(coordtemp[:8] == '<coords>' and coordtemp[-9:] == '</coords>') coordtemp = coordtemp[8:-9].split(', ') nodes_out[i*3], nodes_out[(i*3)+1], nodes_out[(i*3)+2] = float(coordtemp[0]), float(coordtemp[1]), float(coordtemp[2]) assert(xmlfile.readline().strip() == '</node>') assert(xmlfile.readline().strip() == '</nodes>') # Now read triangle information from xml file and text file if we have it triinfo = xmlfile.readline().strip() assert(triinfo.__len__() > 21) assert(triinfo[-2:] == '">') ntris = int(triinfo[19:-2]) if (havetxt) : textfile.readline() assert (ntris == int(textfile.readline())) tris_out = [0]*(ntris*3) # numpy.zeros(ntris*3, dtype = 'int') if (havetxt) : triareas_out = [0.0]*ntris # numpy.zeros(ntris) trinorms_out = [0.0]*(ntris*3) # numpy.zeros(ntris*3) tritetns_out = [0]*(ntris*2) # numpy.zeros(ntris*2, dtype = 'int') for i in range(ntris): idxtemp = xmlfile.readline().strip() assert(int(idxtemp[12:-2]) == i) nodetemp = xmlfile.readline().strip() assert (nodetemp[:7] == '<nodes>' and nodetemp[-8:] == '</nodes>') nodetemp = nodetemp[7:-8].split(', ') tris_out[i*3], tris_out[(i*3)+1], tris_out[(i*3)+2] = int(nodetemp[0]), int(nodetemp[1]), int(nodetemp[2]) assert(xmlfile.readline().strip() == '</tri>') # Now read the text file, if it exists, and get the extra information if (havetxt): line = textfile.readline().rstrip().split(" ") assert(line.__len__() == 6) triareas_out[i], trinorms_out[i*3], trinorms_out[(i*3)+1], trinorms_out[(i*3)+2] = float(line[0]), float(line[1]), float(line[2]), float(line[3]) tritetns_out[i*2], tritetns_out[(i*2)+1] = int(line[4]), int(line[5]) assert(xmlfile.readline().strip() == '</triangles>') # Now read tet information from xml file and text file if we have it tetinfo = xmlfile.readline().strip() assert(tetinfo.__len__() > 24) assert(tetinfo[-2:] == '">') ntets = int(tetinfo[22:-2]) if (havetxt) : textfile.readline() assert(ntets == int(textfile.readline())) tets_out = [0]*(ntets*4) # numpy.zeros(ntets*4, dtype = 'int') if (havetxt): tetvols_out = [0.0]*ntets # numpy.zeros(ntets) tetbarycs_out = [0.0]*(ntets*3) # numpy.zeros(ntets*3) tettrins_out = [0]*(ntets*4) # numpy.zeros(ntets*4, dtype = 'int') tettetns_out = [0]*(ntets*4) # numpy.zeros(ntets*4, dtype = 'int') for i in range(ntets): idxtemp = xmlfile.readline().strip() assert(int(idxtemp[12:-2]) == i) nodetemp = xmlfile.readline().strip() assert (nodetemp[:7] == '<nodes>' and nodetemp[-8:] == '</nodes>') nodetemp = nodetemp[7:-8].split(', ') tets_out[i*4], tets_out[(i*4)+1], tets_out[(i*4)+2], tets_out[(i*4)+3] = int(nodetemp[0]), int(nodetemp[1]), int(nodetemp[2]), int(nodetemp[3]) assert(xmlfile.readline().strip() == '</tet>') # Read the text file if we have it and get further information if (havetxt): line = textfile.readline().rstrip().split(" ") assert (line.__len__() == 12) tetvols_out[i], tetbarycs_out[i*3], tetbarycs_out[(i*3)+1], tetbarycs_out[(i*3)+2] = float(line[0]), float(line[1]), float(line[2]), float(line[3]) tettrins_out[i*4], tettrins_out[(i*4)+1], tettrins_out[(i*4)+2], tettrins_out[(i*4)+3] = int(line[4]), int(line[5]), int(line[6]), int(line[7]) tettetns_out[i*4], tettetns_out[(i*4)+1], tettetns_out[(i*4)+2], tettetns_out[(i*4)+3] = int(line[8]), int(line[9]), int(line[10]), int(line[11]) assert(xmlfile.readline().strip() == '</tetrahedrons>') # We have all the information now. Time to make the Tetmesh object. New constructor keeps the order, which is: # nodes, tris, tri areas, tri normals, tri tet neighbours, tets, tet volumes, tet barycenters, tet tri neighbs, tet tet neighbs. mesh = stetmesh.Tetmesh(nodes_out, tris_out, triareas_out, trinorms_out, tritetns_out, tets_out, tetvols_out, tetbarycs_out, tettrins_out, tettetns_out) # Now fetch any comp and patch information from XML file compinfo = xmlfile.readline().strip() assert(compinfo.__len__() > 24) assert(compinfo[-2:] == '">') ncomps = int(compinfo[22:-2]) comps_out = [] for i in range(ncomps): idxtemp = xmlfile.readline().strip() assert(int(idxtemp[13:-2]) == i) idtemp = xmlfile.readline().strip() assert(idtemp[:4] == '<id>' and idtemp[-5:] == '</id>') idtemp = idtemp[4:-5] volsystemp = xmlfile.readline().strip() assert(volsystemp[:8] == '<volsys>' and volsystemp[-9:] == '</volsys>') volsystemp = volsystemp[8:-9].split(',') if (volsystemp[0] == '') : volsystemp = [] tettemp = xmlfile.readline().strip() assert(tettemp[:6] == '<tets>' and tettemp[-7:] == '</tets>') tettemp = tettemp[6:-7].split(',') nctets = tettemp.__len__() ctets = [0]*nctets # numpy.zeros(nctets, dtype = 'int') for ct in range(nctets): ctets[ct] = int(tettemp[ct]) c_out = stetmesh.TmComp(idtemp, mesh, ctets) for v in volsystemp: c_out.addVolsys(v) comps_out.append(c_out) assert(xmlfile.readline().strip() == '</comp>') assert(xmlfile.readline().strip() == '</compartments>') # Retrieve patch info patchinfo = xmlfile.readline().strip() assert(patchinfo.__len__() > 19) assert(patchinfo[-2:] == '">') npatches = int(patchinfo[17:-2]) patches_out = [] for i in range(npatches): idxtemp = xmlfile.readline().strip() assert(int(idxtemp[14:-2]) == i) idtemp = xmlfile.readline().strip() assert(idtemp[:4] == '<id>' and idtemp[-5:] == '</id>') idtemp = idtemp[4:-5] surfsystemp = xmlfile.readline().strip() assert(surfsystemp[:9] == '<surfsys>' and surfsystemp[-10:] == '</surfsys>') surfsystemp = surfsystemp[9:-10].split(',') if (surfsystemp[0] == '') : surfsystemp = [] icomptemp = xmlfile.readline().strip() assert(icomptemp[:7] == '<icomp>' and icomptemp[-8:] == '</icomp>') icomptemp = icomptemp[7:-8] ocomptemp = xmlfile.readline().strip() assert(ocomptemp[:7] == '<ocomp>' and ocomptemp[-8:] == '</ocomp>') ocomptemp = ocomptemp[7:-8] tritemp = xmlfile.readline().strip() assert(tritemp[:6] == '<tris>' and tritemp[-7:] == '</tris>') tritemp = tritemp[6:-7].split(',') nptris = tritemp.__len__() ptris = [0]*nptris # numpy.zeros(nptris, dtype='int') for pt in range(nptris): ptris[pt] = int(tritemp[pt]) if (ocomptemp != 'null'): p_out = stetmesh.TmPatch(idtemp, mesh, ptris, mesh.getComp(icomptemp), mesh.getComp(ocomptemp)) else : p_out = stetmesh.TmPatch(idtemp, mesh, ptris, mesh.getComp(icomptemp)) for s in surfsystemp: p_out.addSurfsys(s) patches_out.append(p_out) assert(xmlfile.readline().strip() == '</patch>') assert(xmlfile.readline().strip() == '</patches>') return (mesh,comps_out,patches_out)
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()
model = smodel.Model() A = smodel.Spec('A', model) surfsys = smodel.Surfsys('ssys', model) D_a = smodel.Diff('D_a', surfsys, A) DCST = 0.2e-9 D_a.setDcst(DCST) mesh = meshio.importAbaqus2("mesh_tet.inp", "mesh_tri.inp", 1e-6, "mesh_conf")[0] boundary_tris = mesh.getROIData("boundary") v1_tets = mesh.getROIData("v1_tets") comp1 = sgeom.TmComp("comp1", mesh, v1_tets) patch1 = sgeom.TmPatch("patch", mesh, boundary_tris, comp1) patch1.addSurfsys("ssys") neigh_tris = mesh.getROIData("neigh_tri") focus_tri = mesh.getROIData("focus_tri")[0] rng = srng.create('mt19937', 512) rng.initialize(int(time.time() % 4294967295)) solver = solv.Tetexact(model, mesh, rng) print "Set dcst from focus_tri to all neighbor tris to 0..." for tri in neigh_tris: solver.setTriDiffD(focus_tri, "D_a", 0, tri) print solver.getTriDiffD(focus_tri, "D_a", tri) solver.setTriCount(focus_tri, "A", 10)
submemb_tets_surftris = dict() for m in submemb_tets: tris = mesh_stoch.getTetTriNeighb(m) for t in tris: if t in memb_tris: submemb_tets_surftris[m] = t break 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)
pot_tet = numpy.zeros(pot_n, dtype='uint') i = 0 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 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
and mesh.getVertex(vert2)[2] > 0.0): if mesh.getTriBarycenter(t)[0] > 0.0: patchA_tris.append(t) bar = mesh.getTriBars(t) patchA_bars.add(bar[0]) patchA_bars.add(bar[1]) patchA_bars.add(bar[2]) else: patchB_tris.append(t) bar = mesh.getTriBars(t) patchB_bars.add(bar[0]) patchB_bars.add(bar[1]) patchB_bars.add(bar[2]) # Create the patch patchA = stetmesh.TmPatch('patchA', mesh, patchA_tris, icomp = comp) patchA.addSurfsys('ssys') patchB = stetmesh.TmPatch('patchB', mesh, patchB_tris, icomp = comp) patchB.addSurfsys('ssys') # Find the set of bars that connect the two patches as the intersecting bars barsDB = patchA_bars.intersection(patchB_bars) barsDB=list(barsDB) # Create the surface diffusion boundary diffb = stetmesh.SDiffBoundary('sdiffb', mesh, barsDB, [patchA, patchB]) # Find the central tri ctetidx = mesh.findTetByPoint([0.0, 0.0, 0.5e-6]) ctet_trineighbs = mesh.getTetTriNeighb(ctetidx) ctri_idx=-1
def setUp(self): self.DCST = 0.08e-12 self.model = smodel.Model() A = smodel.Spec('A', self.model) X = smodel.Spec('X', self.model) self.ssys1 = smodel.Surfsys('ssys1', self.model) self.ssys2 = smodel.Surfsys('ssys2', self.model) self.sreac = smodel.SReac('sreac', self.ssys1, slhs = [A], srhs = [A], kcst = 1e5) self.diff1 = smodel.Diff('diffX1', self.ssys1, X, self.DCST) self.diff2 = smodel.Diff('diffX2', self.ssys2, X, self.DCST) if __name__ == "__main__": self.mesh = meshio.loadMesh('meshes/coin_10r_1h_13861')[0] else: self.mesh = meshio.loadMesh('sdiff_bugfix_test/meshes/coin_10r_1h_13861')[0] ntets = self.mesh.countTets() self.comp = sgeom.TmComp('cyto', self.mesh, range(ntets)) alltris = self.mesh.getSurfTris() patchA_tris = [] patchB_tris = [] patchA_bars = set() patchB_bars = set() for t in alltris: vert0, vert1, vert2 = self.mesh.getTri(t) if (self.mesh.getVertex(vert0)[2] > 0.0 \ and self.mesh.getVertex(vert1)[2] > 0.0 \ and self.mesh.getVertex(vert2)[2] > 0.0): if self.mesh.getTriBarycenter(t)[0] > 0.0: patchA_tris.append(t) bar = self.mesh.getTriBars(t) patchA_bars.add(bar[0]) patchA_bars.add(bar[1]) patchA_bars.add(bar[2]) else: patchB_tris.append(t) bar = self.mesh.getTriBars(t) patchB_bars.add(bar[0]) patchB_bars.add(bar[1]) patchB_bars.add(bar[2]) self.patchA = sgeom.TmPatch('patchA', self.mesh, patchA_tris, icomp = self.comp) self.patchA.addSurfsys('ssys1') self.patchB = sgeom.TmPatch('patchB', self.mesh, patchB_tris, icomp = self.comp) self.patchB.addSurfsys('ssys2') # Find the set of bars that connect the two patches as the intersecting bars barsDB = patchA_bars.intersection(patchB_bars) barsDB=list(barsDB) # Create the surface diffusion boundary self.diffb = sgeom.SDiffBoundary('sdiffb', self.mesh, barsDB, [self.patchA, self.patchB]) ctetidx = self.mesh.findTetByPoint([0.0, 0.0, 0.5e-6]) ctet_trineighbs = self.mesh.getTetTriNeighb(ctetidx) self.ctri_idx=-1 for t in ctet_trineighbs: if t in patchA_tris+patchB_tris: self.ctri_idx = t self.rng = srng.create('r123', 512) self.rng.initialize(1000) self.solver = solv.Tetexact(self.model, self.mesh, self.rng)
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)
for j in range(4): out_tris.add(tritemp[j]) in_tris = set() for i in inner_tets: tritemp = mesh.getTetTriNeighb(i) 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)
DCST) # name, where, what, how fast # diff_Ca_sens = smodel.Diff('diff_Ca_sens', surfsys2, Ca_sens, DCST) # name, where, what, how fast # define compartments: cyto_comp = stetmesh.TmComp('cyto_comp', mesh, CS_tet_IDs) ER_comp = stetmesh.TmComp('ER_comp', mesh, ER_tet_IDs) # get surf tris in comps: CS_memb_tris = meshctrl.findSurfTrisInComp(mesh, cyto_comp) ER_memb_tris = meshctrl.findOverlapTris(mesh, CS_tet_IDs, ER_tet_IDs) # patches: ER_surf = stetmesh.TmPatch('ER_surf', mesh, 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)
Compborder_tri_areas = [0.0]*len(Length) for i in range(len(Length)): Compborder_triIDs[i]=[] for j in range(len(Comp_tetIDs[i])): 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))
def __init__(self, x): if x.INT_DOMAIN == []: DOMAIN_NAMES = [x.CYT_NAME, x.PSD_NAME] else: DOMAIN_NAMES = [x.CYT_NAME, x.SER_NAME, x.PSD_NAME] print x.GeoFileName print x.scale print DOMAIN_NAMES print 'importAbaqus ... \n' mesh, nodeproxy, tetproxy, triproxy = smeshio.importAbaqus( x.GeoFileName, x.scale, DOMAIN_NAMES) print 'OK\n' print 'Load Head, Neck, and Dend IDs\n' Head_ID = np.loadtxt(x.HeadIDFileName) - 1 Neck_ID = np.loadtxt(x.NeckIDFileName) - 1 Dend_ID = np.loadtxt(x.DendIDFileName) - 1 Head_ID = Head_ID.astype(np.int) Neck_ID = Neck_ID.astype(np.int) Dend_ID = Dend_ID.astype(np.int) print 'OK\n' ntets = mesh.ntets tet_groups = tetproxy.blocksToGroups() Cyt_tets = tet_groups[x.CYT_NAME] nCyt_tets = len(Cyt_tets) if x.INT_DOMAIN != []: SER_tets = tet_groups[x.SER_NAME] nSER_tets = len(SER_tets) print 'nGol_tets: ', nSER_tets tri_groups = triproxy.blocksToGroups() tri_PSD = tri_groups[x.PSD_NAME] tri_nPSD = len(tri_PSD) ### ### Volume system ### Annotation of geometry ### Cytosol = sgeom.TmComp('Cytosol', mesh, Cyt_tets) Cytosol.addVolsys('vsys_Cyt') # Golgi = sgeom.TmComp('Golgi', mesh, Gol_tets) # Golgi.addVolsys('vsys_Gol') #### #### Surface & PSD mesh preparation #### ## Obtain IDs of neighboring triangles from cytosolic tetrahedrons tri_S = set(mesh.getSurfTris()) if x.INT_DOMAIN != []: tri_SER = set() for i in SER_tets: tri = mesh.getTetTriNeighb(i) tri_SER.add(tri[0]) tri_SER.add(tri[1]) tri_SER.add(tri[2]) tri_SER.add(tri[3]) tri_S.difference(tri_SER) ### ### tri_S_PSD = tri_S.intersection(tri_PSD) tri_Head = set() for i in Head_ID: tri = mesh.getTetTriNeighb(i) tri_Head.add(tri[0]) tri_Head.add(tri[1]) tri_Head.add(tri[2]) tri_Head.add(tri[3]) tri_Neck = set() for i in Neck_ID: tri = mesh.getTetTriNeighb(i) tri_Neck.add(tri[0]) tri_Neck.add(tri[1]) tri_Neck.add(tri[2]) tri_Neck.add(tri[3]) tri_Dend = set() for i in Dend_ID: tri = mesh.getTetTriNeighb(i) tri_Dend.add(tri[0]) tri_Dend.add(tri[1]) tri_Dend.add(tri[2]) tri_Dend.add(tri[3]) tri_S_Head = tri_S.intersection(tri_Head) tri_S_Neck = tri_S.intersection(tri_Neck) tri_S_Dend = tri_S.intersection(tri_Dend) tri_S_Head_PSD = tri_S_Head.intersection(tri_PSD) tri_S_Neck_PSD = tri_S_Neck.intersection(tri_PSD) tri_S_Head_noPSD = tri_S_Head.difference(tri_PSD) tri_S_Neck_noPSD = tri_S_Neck.difference(tri_PSD) ## ## Make list from set ## tri_S = list(tri_S) tri_S_Dend = list(tri_S_Dend) tri_S_Head_PSD = list(tri_S_Head_PSD) tri_S_Neck_PSD = list(tri_S_Neck_PSD) tri_S_Head_noPSD = list(tri_S_Head_noPSD) tri_S_Neck_noPSD = list(tri_S_Neck_noPSD) ## ## Surface system ## Annotation of geometry ## p_Dend = sgeom.TmPatch('Dend', mesh, tri_S_Dend, icomp=Cytosol) p_Head_PSD = sgeom.TmPatch('Head_PSD', mesh, tri_S_Head_PSD, icomp=Cytosol) p_Neck_PSD = sgeom.TmPatch('Neck_PSD', mesh, tri_S_Neck_PSD, icomp=Cytosol) p_Head_noPSD = sgeom.TmPatch('Head_noPSD', mesh, tri_S_Head_noPSD, icomp=Cytosol) p_Neck_noPSD = sgeom.TmPatch('Neck_noPSD', mesh, tri_S_Neck_noPSD, icomp=Cytosol) p_Dend.addSurfsys('ssys') p_Head_PSD.addSurfsys('ssys') p_Neck_PSD.addSurfsys('ssys') p_Head_noPSD.addSurfsys('ssys') p_Neck_noPSD.addSurfsys('ssys') self.mesh = mesh self.ntets = ntets self.Cyt_tets = Cyt_tets self.nCyt_tets = nCyt_tets self.Cytosol = Cytosol self.tri_S = tri_S self.tri_S_Dend = tri_S_Dend self.tri_S_Head_PSD = tri_S_Head_PSD self.tri_S_Neck_PSD = tri_S_Neck_PSD self.tri_S_Head_noPSD = tri_S_Head_noPSD self.tri_S_Neck_noPSD = tri_S_Neck_noPSD self.p_Dend = p_Dend self.p_Head_PSD = p_Head_PSD self.p_Neck_PSD = p_Neck_PSD self.p_Head_noPSD = p_Head_noPSD self.p_Neck_noPSD = p_Neck_noPSD ## ## SER surf mesh ## if x.INT_DOMAIN != []: tris_Cyt = set() for i in range(nCyt_tets): tris = mesh.getTetTriNeighb(Cyt_tets[i]) tris_Cyt.add(tris[0]) tris_Cyt.add(tris[1]) tris_Cyt.add(tris[2]) tris_Cyt.add(tris[3]) tris_SER = set() for i in range(nSER_tets): tris = mesh.getTetTriNeighb(SER_tets[i]) tris_SER.add(tris[0]) tris_SER.add(tris[1]) tris_SER.add(tris[2]) tris_SER.add(tris[3]) tris_S_SER = tris_Cyt.intersection(tris_SER) self.tris_S_SER = list(tris_S_SER) else: self.tris_S_SER = [] ## ## Obtain IDs for fluxes ## mesh.addROI('Head_ROI', sgeom.ELEM_TET, Head_ID) mesh.addROI('Neck_ROI', sgeom.ELEM_TET, Neck_ID) mesh.addROI('Dend_ROI', sgeom.ELEM_TET, Dend_ID) print 'tri_S : ', len(tri_S) print 'tri_S_Head_PSD : ', len(tri_S_Head_PSD) print 'tri_S_Neck_PSD : ', len(tri_S_Neck_PSD) print 'tri_S_Head_noPSD : ', len(tri_S_Head_noPSD) print 'tri_S_Neck_noPSD : ', len(tri_S_Neck_noPSD) print 'tri_S_Dend : ', len(tri_S_Dend) tmp = len(tri_S_Head_PSD + tri_S_Neck_PSD + tri_S_Dend + tri_S_Neck_noPSD + tri_S_Head_noPSD) print 'Head_PSD + Neck_PSD + Dend + Neck_noPSD + Head_noPSD: ', tmp # print mesh.getSurfSys() print 'Gend_geom has been finished!\n'
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)