def geom(tissue, sim_opt): """ generate the well-mixed champber containing cells from tissue array """ geom = swm.Geom() # Create the vessel compartment c_ = {} m_ = {} for p in tissue[0].prtcl_names: tag = '0' + p c_["cell_{}".format(tag)] = swm.Comp("cell_{}".format(tag), geom, vol=float(tissue[0].S)**3) c_["cell_{}".format(tag)].addVolsys("volsys{}".format(tag)) for n, cell in enumerate(tissue[1:]): n += 1 for p in cell.prtcl_names: S = float(cell.S) tag = str(n) + p prev_tag = str(n - 1) + p c_["cell_{}".format(tag)] = swm.Comp("cell_{}".format(tag), geom, vol=S**3) c_["cell_{}".format(tag)].addVolsys("volsys{}".format(tag)) m_["memb_{}".format(tag)] = swm.Patch( "memb_{}".format(tag), geom, c_["cell_{}".format(tag)], c_["cell_{}".format(prev_tag)]) m_["memb_{}".format(tag)].addSurfsys("surfsys{}".format(tag)) m_["memb_{}".format(tag)].setArea(S**2) return geom
def getGeom(): mesh = sgeom.Geom() cyt = sgeom.Comp('cyt', mesh) cyt.vol = 0.1e-18 ER = sgeom.Comp('ER', mesh) ER.setVol(0.02e-18) ERmemb = sgeom.Patch('memb', mesh, ER, cyt) ERmemb.addSurfsys('ssys') return mesh
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 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
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)
######################################################################## mdl = smod.Model() A = smod.Spec('A', mdl) B = smod.Spec('B', mdl) C = smod.Spec('C', mdl) surfsys = smod.Surfsys('ssys',mdl) SR1 = smod.SReac('SR1', surfsys, slhs = [A, B], srhs = [C], kcst = KCST) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) patch1 = sgeom.Patch('patch1', geom, comp1, area = AREA) patch1.addSurfsys('ssys') import random rng = srng.create('mt19937', 1000) rng.initialize(int(random.random()*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, 3])
#geometry setup import steps.geom as swm wmgeom = swm.Geom() #create the Cytosole compartment cyt = swm.Comp('cyt', wmgeom) cyt.addVolsys('vsys') cyt.setVol(0.1e-18) #Create the Emdoplasmic Reticulum compartment ER = swm.Comp('ER', wmgeom) ER.addVolsys('vsys') ER.setVol(0.1e-18) #ER it the inner compertment, cyr is the outer compartment memb = swm.Patch('memb', wmgeom, ER, cyt) memb.addSurfsys('ssys') memb.setArea(0.21544368e-12) print 'Inner compartment to memb is', memb.getIComp().getID() print 'Outer compartment to memb is', memb.getOComp().getID() #RNG setup import steps.rng as srng import pylab import numpy r = srng.create('mt19937', 1000) r.initialize(7233) #solver setup
R_bind_IP3_b.kcst = 25800 # 1/s RIP3_bind_Ca_f.kcst = 8000e6 # 1/(Ms) RIP3_bind_Ca_b.kcst = 2000 # 1/s R_bind_Ca_f.kcst = 8.889e6 # 1/(Ms) R_bind_Ca_b.kcst = 5 # 1/s RCa_bind_Ca_f.kcst = 20e6 # 1/(Ms) RCa_bind_Ca_b.kcst = 10 # 1/s RCa2_bind_Ca_f.kcst = 40e6 # 1/(Ms) RCa2_bind_Ca_b.kcst = 15 # 1/s RCa3_bind_Ca_f.kcst = 60e6 # 1/(Ms) RCa3_bind_Ca_b.kcst = 20 # 1/s # GEOMETRY cell = sgeom.Geom() # Create the cytosol compartment cyt = sgeom.Comp('cyt', cell) cyt.addVolsys('vsys') cyt.setVol(0.1e-18) # Create the endoplasmic reticulum lumen compartment ER_lumen = sgeom.Comp('ER_lumen', cell) ER_lumen.addVolsys('vsys') ER_lumen.setVol(0.1e-18) # Create the er membrane (ER_lumen inner, cyt outer) ER_memb = sgeom.Patch('ER_memb', cell, ER_lumen, cyt) ER_memb.addSurfsys('ssys') ER_memb.setArea(0.21544369e-12)
DScales_ShellIn[i].append(2*Shells_radii[i][j+1]/((Shells_radii[i][j]**2 - Shells_radii[i][j+1]**2)*0.2e-6)) shells = [None]*len(Length) rings = [None]*len(Length) #Geometry container object: wmgeom = sgeom.Geom() for i in range(len(Length)): shells[i]=[None]*int(Nannulis[i]) rings[i]=[None]*int(Nannulis[i]) for j in range(int(Nannulis[i])): shells[i][j] = sgeom.Comp('shells'+str(i)+str(j), wmgeom, vol=Shells_vols[i][j]) if j==0: rings[i][j] = sgeom.Patch('rings'+str(i)+str(j), wmgeom, icomp=shells[i][j], area=Rings_areas[i][j]) else: rings[i][j] = sgeom.Patch('rings'+str(i)+str(j), wmgeom, ocomp=shells[i][j-1], icomp=shells[i][j], area=Rings_areas[i][j]) #For all patches, add the surface system for i in range(len(Length)): for j in range(int(Nannulis[i])): if j==0: rings[i][j].addSurfsys('ssys_chans') else: rings[i][j].addSurfsys('ssys_diff') shells[i][j].addVolsys('vsys_buffs')
def test_soirev2d(): VOL = 1.0e-18 COUNTA = 100.0 n=2.0 COUNTB = COUNTA/n KCST = 10.0e10 # The reaction constant AREA = 10.0e-12 CCST = KCST/(6.02214179e23*AREA) NITER = 1000 # The number of iterations DT = 0.05 # Sampling time-step INT = 1.05 # Sim endtime # In tests fewer than 0.1% fail with tolerance of 2% tolerance = 2.0/100 ######################################################################## mdl = smod.Model() A = smod.Spec('A', mdl) B = smod.Spec('B', mdl) C = smod.Spec('C', mdl) surfsys = smod.Surfsys('ssys',mdl) SR1 = smod.SReac('SR1', surfsys, slhs = [A, B], srhs = [C], kcst = KCST) geom = sgeom.Geom() comp1 = sgeom.Comp('comp1', geom, VOL) patch1 = sgeom.Patch('patch1', geom, comp1, area = AREA) patch1.addSurfsys('ssys') import random rng = srng.create('mt19937', 1000) rng.initialize(int(random.random()*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, 3]) for i in range (0, NITER): sim.restore('./validation_cp/cp/second_order_irev_2D') for t in range(0, ntpnts): sim.run(tpnts[t]) res_m[i, t, 0] = sim.getPatchCount('patch1', 'A') res_m[i, t, 1] = sim.getPatchCount('patch1', 'B') mean_res = numpy.mean(res_m, 0) lnBA = numpy.zeros(ntpnts) lineAB = numpy.zeros(ntpnts) C = COUNTA-COUNTB passed =True max_err = 0.0 for i in range(ntpnts): A = mean_res[i][0] B = mean_res[i][1] lnBA[i] = math.log(B/A) lineAB[i] = math.log(COUNTB/COUNTA) -C*CCST*tpnts[i] assert(tol_funcs.tolerable(lnBA[i], lineAB[i], tolerance))