def setUp(self): self.model = smodel.Model() A = smodel.Spec('A', self.model) volsys = smodel.Volsys('vsys', self.model) D_a = smodel.Diff('D_a', volsys, 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") v2_tets = self.mesh.getROIData("v2_tets") comp1 = sgeom.TmComp("comp1", self.mesh, v1_tets) comp2 = sgeom.TmComp("comp2", self.mesh, v2_tets) comp1.addVolsys("vsys") comp2.addVolsys("vsys") db = sgeom.DiffBoundary("boundary", self.mesh, boundary_tris) self.rng = srng.create('r123', 512) self.rng.initialize(1000) self.solver = solv.Tetexact(self.model, self.mesh, self.rng)
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) 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 setup_module(): global rng, NITER, DT, INT, CONC, DCST, SAMPLE, MESHFILE, tolerance global tetidxs, tetrads rng = srng.create('r123', 512) rng.initialize(1000) # The max unsigned long NITER = 10 DT = 0.01 INT = 0.05 CONC = 50.0e-6 # the number of initial molecules DCST = 0.1e-9 SAMPLE = 12033 MESHFILE = 'cyl_diam0_4__len10_12Ktets' # <1% fail with a tolerance of 5% tolerance = 5.0 / 100 # create the array of tet indices to be found at random tetidxs = numpy.zeros(SAMPLE, dtype='int') # further create the array of tet barycentre distance to centre tetrads = numpy.zeros(SAMPLE)
def setup_module(): global rng, NITER, DT, INT rng = srng.create('r123', 512) rng.initialize(1000) # The max unsigned long NITER = 10 DT = 0.01 INT = 0.11 global NINJECT, DCST, tolerance, SAMPLE, MESHFILE, tetidxs, tetrads # The number of initial molecules: NINJECT = 10000 DCST = 0.2e-9 # In tests, with good code, <1% fail with a tolerance of 5% tolerance = 5.0 / 100 # The number of tets to sample at random: SAMPLE = 1060 MESHFILE = 'cyl_diam2__len10_1060tets' # create the array of tet indices to be found at random tetidxs = numpy.zeros(SAMPLE, dtype='int') # further create the array of tet barycentre distance to centre tetrads = numpy.zeros(SAMPLE)
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): # model setup mdl = smodel.Model() spc = smodel.Spec('A', mdl) vsys = smodel.Volsys('A', mdl) diff = smodel.Diff('diff_A', vsys, spc) diff.setDcst(0.0) # mesh vertCoos = [0.0, 0.0, 0.0, \ 1.0e-6, 0.0, 0.0, \ 0.0, 1.0e-6, 0.0, \ 0.0, 0.0, 1.0e-6, \ 1.0e-6, 1.0e-6, 1.0e-6 ] vertIds = [0, 1, 2, 3, \ 1, 2, 3, 4 ] # geom setup msh = sgeom.Tetmesh(vertCoos, vertIds) ntets = msh.countTets() comp = sgeom.TmComp('comp', msh, range(ntets)) comp.addVolsys('A') # init sim rng = srng.create('mt19937', 512) rng.initialize(2903) tet_hosts = sgd.linearPartition(msh, [1, 1, smpi.nhosts]) self.sim = spsolver.TetOpSplit(mdl, msh, rng, spsolver.EF_NONE, tet_hosts)
def setUp(self): self.model = smodel.Model() A = smodel.Spec('A', self.model) volsys = smodel.Volsys('vsys', self.model) D_a = smodel.Diff('D_a', volsys, 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] comp = sgeom.TmComp("comp", self.mesh, range(self.mesh.ntets)) comp.addVolsys("vsys") self.rng = srng.create('r123', 512) self.rng.initialize(1000) self.solver = solv.Tetexact(self.model, self.mesh, self.rng) boundary_tris = self.mesh.getROIData("boundary") boundary_tets1 = self.mesh.getROIData("boundary_tets_1") boundary_tets2 = self.mesh.getROIData("boundary_tets_2") self.pairing = {} for tri in boundary_tris: neigh_tets = self.mesh.getTriTetNeighb(tri) if neigh_tets[0] in boundary_tets1: self.pairing[tri] = (neigh_tets[0], neigh_tets[1]) else: self.pairing[tri] = (neigh_tets[1], neigh_tets[0])
def runSBMLmod(sbmlFile, time_end, time_dt, iter_n = 1, solver = 'Wmdirect', specs_plot = {}, vol_units = 1.0e-3, vol_def = False): iSbml = ssbml.Interface(sbmlFile, volunits_def = vol_units, volume_def = vol_def) mdl = iSbml.getModel() mesh = iSbml.getGeom() comp_specs = {} if not specs_plot: got_sp = False else: got_sp = True for comp in mesh.getAllComps(): comp_specs[comp.getID()] = [] volsys_strings = comp.getVolsys() for vsys_str in volsys_strings: vsys = mdl.getVolsys(vsys_str) specs = vsys.getAllSpecs() for spec in specs: comp_specs[comp.getID()].append(spec.getID()) if (got_sp == False): specs_plot.update({spec.getID():''}) comp_specs_n = 0 for comp in comp_specs: comp_specs[comp].sort() comp_specs_n += len(comp_specs[comp]) time_pnts = numpy.arange(0.0, time_end, time_dt) points_n = int(round(time_end/time_dt)) if (len(time_pnts) == (points_n + 1)): time_pnts = numpy.delete(time_pnts, len(time_pnts)-1) res = numpy.zeros([iter_n, points_n, comp_specs_n]) r = srng.create('mt19937', 256) r.initialize(7233) if (solver == 'Wmdirect'): sim = ssolver.Wmdirect(mdl, mesh, r) elif (solver == 'Wmrk4'): sim = ssolver.Wmrk4(mdl, mesh, r) sim.setDT(0.0001) else: raise NameError("Unsupported solver. SBML importer accepts well-mixed solvers 'Wmrk4' and 'Wmdirect'") for it in range (0, iter_n): sim.reset() iSbml.reset() iSbml.setupSim(sim) for tp in range(0, points_n): sim.run(time_pnts[tp]) i = 0 for comp in comp_specs: for spec in comp_specs[comp]: res[it, tp, i] = sim.getCompConc(comp, spec) i+=1 iSbml.updateSim(sim, time_dt) mean_res = numpy.mean(res, 0) i=0 for comp in comp_specs: for spec in comp_specs[comp]: if (spec in specs_plot): if (specs_plot[spec]): plot(time_pnts, mean_res[:,i], label = spec+ ", "+ comp, color = specs_plot[spec]) else: plot(time_pnts, mean_res[:,i], label = spec+ ", "+ comp) i+=1 legend(loc = 'best', numpoints=1) xlabel('Time (s)') ylabel('Conc (M)') show()
def setUp(self): KCST = 10000.0 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.vsys1 = smodel.Volsys('vsys1', self.model) self.vsys2 = smodel.Volsys('vsys2', self.model) self.reac1 = smodel.Reac('reac1', self.vsys1, lhs=[A, B], rhs=[C], kcst=KCST) self.reac2 = smodel.Reac('reac2', self.vsys2, lhs=[D, E], rhs=[F], kcst=KCST) self.geom = sgeom.Geom() self.comp1 = sgeom.Comp('comp1', self.geom, 1e-18) self.comp1.addVolsys('vsys1') self.comp2 = sgeom.Comp('comp2', self.geom, 1e-18) self.comp2.addVolsys('vsys2') 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.tmcomp1 = sgeom.TmComp('comp1', self.mesh, comp1_tets) self.tmcomp1.addVolsys('vsys1') self.tmcomp2 = sgeom.TmComp('comp2', self.mesh, comp2_tets) self.tmcomp2.addVolsys('vsys2') self.rng = srng.create('r123', 512) self.rng.initialize(1000)
def test_masteq(): mdl = smod.Model() A = smod.Spec('A', mdl) volsys = smod.Volsys('vsys', mdl) # Production R1 = smod.Reac('R1', volsys, lhs=[], rhs=[A], kcst=KCST_f) R2 = smod.Reac('R2', volsys, lhs=[A], rhs=[], kcst=KCST_b) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') rng = srng.create('mt19937', 1000) rng.initialize(int(time.time() % 4294967295)) sim = ssolv.Wmdirect(mdl, geom, rng) sim.reset() tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res = numpy.zeros([ntpnts]) sim.restore('./validation_cp/cp/masteq') for t in range(0, ntpnts): sim.run(tpnts[t]) res[t] = sim.getCompCount('comp1', 'A') def fact(x): return (1 if x == 0 else x * fact(x - 1)) # Do cumulative count, but not comparing them all. # Don't get over 50 (I hope) steps_n_res = numpy.zeros(50) for r in res: steps_n_res[int(r)] += 1 for s in range(50): steps_n_res[s] = steps_n_res[s] / ntpnts passed = True max_err = 0.0 k1 = KCST_b k2 = KCST_f * (6.022e23 * 1.0e-15) # Compare 5 to 15 for m in range(5, 16): analy = (1.0 / fact(m)) * math.pow((k2 / k1), m) * math.exp(-(k2 / k1)) assert (tol_funcs.tolerable(steps_n_res[m], analy, tolerance))
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 test_forev(): mdl = smod.Model() A = smod.Spec('A', mdl) B = smod.Spec('B', mdl) volsys = smod.Volsys('vsys', mdl) R1 = smod.Reac('R1', volsys, lhs=[A], rhs=[B], kcst=KCST_f) R2 = smod.Reac('R2', volsys, lhs=[B], rhs=[A], kcst=KCST_b) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') rng = srng.create('mt19937', 512) rng.initialize(int(time.time() % 4294967295)) sim = ssolv.Wmdirect(mdl, geom, rng) sim.reset() tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res_m = numpy.zeros([NITER, ntpnts, 2]) for i in range(0, NITER): sim.restore('./validation_cp/cp/first_order_rev') for t in range(0, ntpnts): sim.run(tpnts[t]) res_m[i, t, 0] = sim.getCompConc('comp1', 'A') * 1e6 res_m[i, t, 1] = sim.getCompConc('comp1', 'B') * 1e6 mean_res = numpy.mean(res_m, 0) Aeq = COUNT * (KCST_b / KCST_f) / (1 + (KCST_b / KCST_f)) / (VOL * 6.0221415e26) * 1e6 Beq = (COUNT / (VOL * 6.0221415e26)) * 1e6 - Aeq max_err = 0.0 passed = True for i in range(ntpnts): if i < 7: continue assert (tol_funcs.tolerable(mean_res[i, 0], Aeq, tolerance)) assert (tol_funcs.tolerable(mean_res[i, 1], Beq, tolerance))
def cbsa2steps(cbsa_model): import steps.geom as swm import steps.model as smodel import steps.rng as srng import steps.solver as ssolver mdl = smodel.Model() vsys = smodel.Volsys('vsys', mdl) mols = [smodel.Spec('M'+str(i), mdl) for i in range(1,cbsa_model.exp_n_molecules)] reactions = [] for i in range(1,cbsa_model.exp_n_reactions): reactants = list(np.where(cbsa_model.expS[:,i] < 0)[0]) reactants_sto = list(cbsa_model.expS[:,i][reactants]*-1) modifiers = list(np.where(cbsa_model.expR[:,i] > 0)[0]) modifiers_sto = list(cbsa_model.expR[:,i][modifiers]) products = list(np.where(cbsa_model.expS[:,i] > 0)[0]) products_sto = list(cbsa_model.expS[:,i][products]) reactants += modifiers reactants_sto += modifiers_sto products += modifiers products_sto += modifiers_sto reactants_objs = [[mols[reactants[j]-1] for k in range(reactants_sto[j])] for j in range(len(reactants))] reactants_objs = [item for sublist in reactants_objs for item in sublist] products_objs = [[mols[products[j]-1] for k in range(products_sto[j])] for j in range(len(products))] products_objs = [item for sublist in products_objs for item in sublist] reactions.append(smodel.Reac("R"+str(i), vsys, lhs=reactants_objs, rhs=products_objs, kcst=cbsa_model.exp_k[i])) wmgeom = swm.Geom() comp = swm.Comp('comp', wmgeom) comp.addVolsys('vsys') comp.setVol(1.6667e-21) r = srng.create('mt19937', 256) r.initialize(int(timer())) sim = ssolver.Wmdirect(mdl, wmgeom, r) sim.reset() for i in range(1,cbsa_model.exp_n_molecules): sim.setCompConc('comp', 'M'+str(i), cbsa_model.exp_x0[i]*1e-6) return sim
def init_sim(model, mesh, seed, param): # previous setup # rng = srng.create('r123', 512) # rng.initialize(seed) # sim = ssolver.Tetexact(model, mesh, rng, True) # Create the solver objects if param['SSA_solver'] == 'TetODE': sim = ssolver.TetODE(model, mesh, calcMembPot=sim_parameters['EF_solver']) sim.setTolerances(1.0e-6, 1e-6) elif param['SSA_solver'] == 'Tetexact': rng = srng.create('mt19937', 512) rng.initialize(seed) sim = ssolver.Tetexact(model, mesh, rng, calcMembPot=sim_parameters['EF_solver']) sim.reset() sim.setEfieldDT(param['EF_dt']) else: raise ValueError('SSA solver ' + param['SSA_solver'] + 'not available') print('Running Rallpack1 test with ' + param['SSA_solver']) # Correction factor for deviation between mesh and model cylinder: area_cylinder = np.pi * param['diameter'] * param['length'] area_mesh_factor = sim.getPatchArea('memb') / area_cylinder # Set initial conditions memb = sgeom.castToTmPatch(mesh.getPatch('memb')) for t in memb.tris: sim.setTriCount(t, 'Leak', 1) sim.setMembPotential('membrane', param['E_M']) sim.setMembVolRes('membrane', param['R_A']) sim.setMembCapac('membrane', param['C_M'] / area_mesh_factor) v_zmin = mesh.getROIData('v_zmin') I = param['Iinj'] / len(v_zmin) for v in v_zmin: sim.setVertIClamp(v, I) return sim
def get_solver(solver_type, mdl, geom): r = srng.create('r123', 1000) if solver_type == "Wmrk4": solver = ssolv.Wmrk4(mdl, geom) solver.setDT(1e-5) return solver elif solver_type == "Wmdirect": solver = ssolv.Wmdirect(mdl, geom, r) return solver if solver_type == "Wmrssa": solver = ssolv.Wmrssa(mdl, geom, r) return solver elif solver_type == "Tetexact": solver = ssolv.Tetexact(mdl, geom, r) return solver else: assert (False)
def test_foirev(): mdl = smod.Model() A = smod.Spec('A', mdl) volsys = smod.Volsys('vsys', mdl) R1 = smod.Reac('R1', volsys, lhs=[A], rhs=[], kcst=KCST) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') rng = srng.create('mt19937', 1000) rng.initialize(int(time.time() % 4294967295)) sim = ssolv.Wmdirect(mdl, geom, rng) sim.reset() tpnts = np.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res_m = np.zeros([NITER, ntpnts, 1]) res_std1 = np.zeros([ntpnts, 1]) res_std2 = np.zeros([ntpnts, 1]) for i in range(0, NITER): sim.restore('./validation_cp/cp/first_order_irev') for t in range(0, ntpnts): sim.run(tpnts[t]) res_m[i, t, 0] = sim.getCompCount('comp1', 'A') mean_res = np.mean(res_m, 0) std_res = np.std(res_m, 0) m_tol = 0 s_tol = 0 passed = True for i in range(ntpnts): if i == 0: continue analy = N * np.exp(-KCST * tpnts[i]) std = np.power((N * (np.exp(-KCST * tpnts[i])) * (1 - (np.exp(-KCST * tpnts[i])))), 0.5) if not tol_funcs.tolerable(analy, mean_res[i], tolerance): passed = False assert (tol_funcs.tolerable(std, std_res[i], tolerance))
def setup_module(): global rng, DT, INT, NINJECT, DCST, tolerance, MESHFILE rng = srng.create('r123', 1024) rng.initialize(1000) # The max unsigned long # plotting dt; sim endtime: DT = 0.02 INT = 3.02 # Number of molecules injected in centre; diff constant NINJECT = 1000 DCST = 0.01e-9 # Error from non-zero injection width etc should be less than 1% tolerance = 1.0 / 100 ######################################################################## MESHFILE = 'ring2_or10_ir9_injx0width2_60084tets.inp'
def setup_module(): global rng, NITER, DT, INT, NINJECT, DCST, tolerance, MESHFILE rng = srng.create('r123', 1024) rng.initialize(1000) # The max 32bit unsigned long # Number of iterations; plotting dt; sim endtime: NITER = 100 DT = 0.02 INT = 3.02 # Number of molecules injected in centre; diff constant NINJECT = 5000 DCST = 0.01e-9 # In tests <1% fail with tolerance of 5% tolerance = 5.0 / 100 ######################################################################## MESHFILE = 'ring2_or10_ir9_injx0width2_640tets.inp'
def setup_module(): global rng rng = srng.create('r123', 1024) rng.initialize(1000) # The max unsigned long global NITER, DT, INT, NINJECT, DCST, tolerance # Number of iterations; plotting dt; sim endtime: NITER = 10 DT = 0.01 INT = 0.21 # Number of molecules injected in centre; diff constant; number of tets sampled: NINJECT = 100000 DCST = 0.02e-9 # With good code <1% fail with a tolerance of 5% tolerance = 5.0 / 100 ######################################################################## global SAMPLE, MESHFILE SAMPLE = 32552 # all tets MESHFILE = 'sphere_rad10_33Ktets_adaptive' # create the array of tet indices to be found at random global tetidxs tetidxs = np.zeros(SAMPLE, dtype='int') for i in range(SAMPLE): tetidxs[i] = i # further create the array of tet barycentre distance to centre global tetrads, tetvols tetrads = np.zeros(SAMPLE) tetvols = np.zeros(SAMPLE)
def setup_module(): global rng, NITER, DT, INT, NINJECT, DCST, tolerance, MESHFILE rng = srng.create('r123', 1024) rng.initialize(1000) # The max unsigned long # Number of iterations; plotting dt; sim endtime: NITER = 100 DT = 0.01 INT = 0.21 # Number of molecules injected in center; diff constant; number of tets sampled: NINJECT = 1000 DCST = 0.02e-9 # With good code <1% fail with a tolerance of 6% tolerance = 6.0 / 100 ######################################################################## MESHFILE = 'coin_10r_1h_13861.inp'
def setup_module(): global rng, DT, INT, DCST, FLUX, SAMPLE, MESHFILE, tetidxs, tetrads, tolerance rng = srng.create('r123', 512) rng.initialize(1000) # The max unsigned long DT = 0.001 INT = 0.025 DCST = 0.05e-9 FLUX = 300000.0 # The flux at the boundaries, SAMPLE = 12033 # All tets MESHFILE = 'cyl_diam0_4__len10_12Ktets_STEPS' # create the array of tet indices to be found at random tetidxs = np.zeros(SAMPLE, dtype='int') # further create the array of tet barycentre distance to centre tetrads = np.zeros(SAMPLE) # Small expected error from non plane source tolerance = 3.0 / 100
def setUp(self): mdl = smodel.Model() self.v1 = 1e-20 self.v2 = 2e-20 self.a1 = 3e-14 self.kreac = 200.0 self.ksreac = 100.0 S1 = smodel.Spec('S1', mdl) S2 = smodel.Spec('S2', mdl) S1S2 = smodel.Spec('S1S2', mdl) vsys = smodel.Volsys('vsys', mdl) ssys = smodel.Surfsys('ssys', mdl) smodel.Reac('reac', vsys, lhs=[S1, S2], rhs=[S2, S2], kcst=self.kreac) smodel.SReac('sreac', ssys, ilhs=[S1], slhs=[S2], srhs=[S1S2], kcst=self.ksreac) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom) comp1.setVol(self.v1) comp1.addVolsys('vsys') comp2 = sgeom.Comp('comp2', geom) comp2.setVol(self.v2) comp1.addVolsys('vsys') patch = sgeom.Patch('patch', geom, comp1, comp2) patch.addSurfsys('ssys') patch.setArea(self.a1) self.mdl, self.geom, self.rng = mdl, geom, srng.create('mt19937',512) self.rng.initialize(1234)
def init_sim(model, mesh, seed, param): rng = srng.create('r123', 512) # previous setup # rng.initialize(seed) rng.initialize(steps.mpi.rank + 1000) memb = sgeom.castToTmPatch(mesh.getPatch('memb')) # partition geometry across hosts (tet_hosts, tri_hosts) = host_assignment_by_axis(mesh, memb.tris) # sim = ssolver.TetOpSplit(model, mesh, rng, True, tet_hosts, tri_hosts) sim = ssolver.TetOpSplit(model, mesh, rng, param['EF_solver'], tet_hosts, tri_hosts) # Correction factor for deviation between mesh and model cylinder: area_cylinder = np.pi * param['diameter'] * param['length'] area_mesh_factor = sim.getPatchArea('memb') / area_cylinder # Set initial conditions sim.reset() for t in memb.tris: sim.setTriCount(t, 'Leak', 1) sim.setEfieldDT(param['EF_dt']) sim.setMembPotential('membrane', param['E_M']) sim.setMembVolRes('membrane', param['R_A']) sim.setMembCapac('membrane', param['C_M'] / area_mesh_factor) v_zmin = mesh.getROIData('v_zmin') I = param['Iinj'] / len(v_zmin) for v in v_zmin: sim.setVertIClamp(v, I) return sim
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 = 1.0 / 100 ####################### Second order irreversible AA ################### global KCST_soAA, CONCA_soAA, CONCB_soAA, tolerance_soAA KCST_soAA = 50.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 = 1.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 = 100.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 = 1.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 CCST_so2d = KCST_so2d / (6.02214179e23 * AREA_so2d) NITER_so2d = 1000 # The number of iterations # In tests fewer than 0.1% fail with tolerance of 2% tolerance_so2d = 2.0 / 100 ############################ Common parameters ######################## global VOL DT = 0.1 # Sampling time-step INT = 1.1 # Sim endtime VOL = 9.0e-18 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) 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) 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) 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) 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) 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) 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) 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) SR1_so2d = smod.SReac('SR1_so2d', surfsys, slhs=[A_so2d, B_so2d], srhs=[C_so2d], kcst=KCST_so2d) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') patch1 = sgeom.Patch('patch1', geom, comp1, area=AREA_so2d) patch1.addSurfsys('ssys') rng = srng.create('r123', 512) rng.initialize(1000) sim = ssolv.Wmdirect(mdl, geom, 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
#R1 = smod.Reac('R1', volsys, lhs = [A,B], rhs = [C]) #R1.setKcst(RCST) D_a = smod.Diff('D_a', volsys, A, dcst = DCSTA) #D_b = smod.Diff('D_b', volsys, B, dcst = DCSTB) #D_c = smod.Diff('D_c', volsys, C, dcst = DCSTB) mesh, nodeproxy, tetproxy, triproxy = smeshio.importAbaqus('brick_40_4_4_2_comp.inp', scale) ntets = mesh.ntets tet_groups = tetproxy.blocksToGroups() Atets = tet_groups['EB1'] nATets = len(Atets) Btets = tet_groups['EB2'] nBTets = len(Btets) comp1 = sgeom.TmComp('comp1', mesh, xrange(mesh.ntets)) comp1.addVolsys('vsys') rng = srng.create('mt19937', 16384) rng.initialize(1) print "create sim" sim = ssolv.Tetexact(mdl, mesh, rng) print "reset" sim.reset() #set molecules sim.setTetCount(0, "A", 1) sim.run(1e-3)
math.pow((baryc[2]-cbaryc[2]),2)) # Store the radial distance (in microns): tetrads[i] = r * 1.0e6 print "Tetrahedron samples found" return mesh ######################################################################## model = gen_model() tmgeom = gen_geom() rng = srng.create('mt19937', 512) rng.initialize(2903) sim = solvmod.Tetexact(model, tmgeom, rng) tpnts = numpy.arange(0.0, INT, DT) # Find how many "time points" we have ntpnts = tpnts.shape[0] # Create the data structure: iterations x time points x tet samples res = numpy.zeros((NITER, ntpnts, SAMPLE)) # Fetch the index of the tetrahedron at the centre of the mesh ctetidx = tmgeom.findTetByPoint([0.0, 0.0, 0.0]) # Run NITER number of iterations:
# In test runs, with good code, < 1% will fail with a 1.5% tolerance tolerance = 2.0 / 100 ######################################################################## mdl = smod.Model() A = smod.Spec('A', mdl) volsys = smod.Volsys('vsys', mdl) R1 = smod.Reac('R1', volsys, lhs=[A], rhs=[], kcst=KCST) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') rng = srng.create('mt19937', 1000) rng.initialize(int(time.time() % 4294967295)) sim = ssolv.Wmdirect(mdl, geom, rng) sim.reset() tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res_m = numpy.zeros([NITER, ntpnts, 1]) res_std1 = numpy.zeros([ntpnts, 1]) res_std2 = numpy.zeros([ntpnts, 1]) sim.reset() sim.setCompCount('comp1', 'A', N) sim.checkpoint('./validation_cp/cp/first_order_irev')
def test_masteq(): "Reaction - Production and degradation (Wmdirect)" ######################################################################## KCST_f = 100 / (6.022e23 * 1.0e-15) # The reaction constant, production KCST_b = 10 # The reaction constant, degradation VOL = 1.0e-18 DT = 0.1 # Sampling time-step INT = 200000.1 # Sim endtime # Tolerance for the comparison: # In tests with good code <1% fail with tolerance of 1.5% tolerance = 1.5 / 100 ######################################################################## mdl = smod.Model() A = smod.Spec('A', mdl) volsys = smod.Volsys('vsys', mdl) # Production R1 = smod.Reac('R1', volsys, lhs=[], rhs=[A], kcst=KCST_f) R2 = smod.Reac('R2', volsys, lhs=[A], rhs=[], kcst=KCST_b) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) comp1.addVolsys('vsys') rng = srng.create('r123', 1000) rng.initialize(1000) sim = ssolv.Wmdirect(mdl, geom, rng) sim.reset() tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res = numpy.zeros([ntpnts]) sim.reset() sim.setCompCount('comp1', 'A', 0) for t in range(0, ntpnts): sim.run(tpnts[t]) res[t] = sim.getCompCount('comp1', 'A') def fact(x): return (1 if x == 0 else x * fact(x - 1)) # Do cumulative count, but not comparing them all. # Don't get over 50 (I hope) steps_n_res = numpy.zeros(50) for r in res: steps_n_res[int(r)] += 1 for s in range(50): steps_n_res[s] = steps_n_res[s] / ntpnts passed = True max_err = 0.0 k1 = KCST_b k2 = KCST_f * (6.022e23 * 1.0e-15) # Compare 5 to 15 for m in range(5, 16): analy = (1.0 / fact(m)) * math.pow((k2 / k1), m) * math.exp(-(k2 / k1)) assert tol_funcs.tolerable(steps_n_res[m], analy, tolerance)
volComp = volComp * pow(10,-3) comp.vol = volComp species = iSbml.getSpecies() #Dict specie --> concentration molecules = iSbml.setMols(smodel, mdl, species) # Name Specie --> Mols in STEPS reactions = iSbml.getReactions(molecules) iSbml.instantiate_reaction(smodel, volsys, reactions) ############ r = srng.create('mt19937', 256) r.initialize(7233) tpnt = np.arange(0.0, ENDTIME, DT) res_m = np.zeros([NITER, POINTS, len(species)]) legendDict = {} print "Setting up the model" sim = ssolver.Wmdirect(mdl, mesh, r) print "before simulation" for it in range (0, NITER): sim.reset() iSbml.set_initial_conditions(sim, species) for t in xrange(0,POINTS):
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 = 1 # The number of iterations # Tolerance for the comparison: tolerance_foi = 1.0e-4 / 100 ####################### First order reversible ######################### global KCST_f_for, KCST_b_for, COUNT_for, tolerance_for KCST_f_for = 20.0 # The reaction constant KCST_b_for = 5.0 COUNT_for = 100000 # Can set count or conc NITER_for = 1 # The number of iterations tolerance_for = 1.0e-4 / 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 = 1 # The number of iterations tolerance_soA2 = 1.0e-4 / 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 = 1 # The number of iterations tolerance_soAA = 1.0e-4 / 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 = 1 # The number of iterations tolerance_soAB = 1.0e-4 / 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 = 1 # The number of iterations tolerance_toA3 = 1.0e-4 / 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 = 1 # The number of iterations tolerance_toA2B = 1.0e-4 / 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 = 1 # The number of iterations tolerance_so2d = 1.0e-4 / 100 ############################ Common parameters ######################## global VOL DT = 0.1 # Sampling time-step INT = 1.1 # Sim endtime NITER_max = 1 ######################################################################## 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.TetODE(mdl, mesh, rng) sim.setTolerances(1e-9, 1e-7) global tpnts, ntpnts tpnts = numpy.arange(0.0, INT, DT) ntpnts = tpnts.shape[0] res_m_foi = numpy.zeros([NITER_foi, 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): 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 mean_res_foi = numpy.mean(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
#import the geometry module that contains the objects used to #define the geometry, namely steps.geom. wmgeom = swm.Geom() #generate parent container object comp = swm.Comp('comp', wmgeom) comp.addVolsys('vsys') comp.setVol(1.6667e-27) #To this symple model, we only create one compartment and we #store it in the variable called comp. import steps.rng as srng #import package with alias srng. r = srng.create('mt19937', 256) #we actually generate a random number generator we want. #using the function steps.rng.create() #STEPS currently only implements one pseudo RNG algorithm, 'mt19937' r.initialize(23412) #initialize the random number generator with a seed value import steps.solver as ssolver #to create the actual solver object, first of all we import the #package in which all solvers have been implemented sim = ssolver.Wmdirect(mdl, wmgeom, r) sim.reset() #reset the function on the solver project
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # STEPS - STochastic Engine for Pathway Simulation # Copyright (C) 2007-2011 Okinawa Institute of Science and Technology, Japan. # Copyright (C) 2003-2006 University of Antwerp, Belgium. # # See the file AUTHORS for details. # # This file is part of STEPS. # # STEPS is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # STEPS is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # import steps.model as smod import steps.geom as sgeom import steps.rng as srng import steps.solver as ssolv import math import time
math.pow((baryc[1]-cbaryc[1]),2) + \ math.pow((baryc[2]-cbaryc[2]),2)) # Store the radial distance (in microns): tetrads[i] = r*1.0e6 print "Tetrahedron samples found" return mesh ######################################################################## model = gen_model() tmgeom = gen_geom() rng = srng.create('mt19937', 512) rng.initialize(2903) # The max unsigned long sim = solvmod.Tetexact(model, tmgeom, rng) tpnts = numpy.arange(0.0, INT, DT) # Find how many "time points" we have ntpnts = tpnts.shape[0] # Create the data structure: iterations x time points x tet samples res = numpy.zeros((NITER, ntpnts, SAMPLE)) # Fetch the index of the tetrahedron at the centre of the mesh ctetidx = tmgeom.findTetByPoint([0.0, 0.0, 0.0]) # Run NITER number of iterations: