Exemplo n.º 1
0
def gen_model():

    # Create the model container object
    mdl = smodel.Model()

    # Create the chemical species
    X = smodel.Spec('X', mdl)
    Y = smodel.Spec('Y', mdl)

    # Create separate volume systems for compartments A and B
    vsysA = smodel.Volsys('vsysA', mdl)
    vsysB = smodel.Volsys('vsysB', mdl)

    # Describe diffusion of molecules in compartments A and B
    # NOTE: diffusion is not defined for species X in compartment B
    diff_X_A = smodel.Diff('diff_X_A', vsysA, X)
    diff_X_A.dcst = 0.1e-9
    diff_X_B = smodel.Diff('diff_X_B', vsysB, X)
    diff_X_B.dcst = 0.1e-9
    diff_Y_A = smodel.Diff('diff_Y_A', vsysA, Y)
    diff_Y_A.dcst = 0.1e-9
    diff_Y_B = smodel.Diff('diff_Y_B', vsysB, Y)
    diff_Y_B.dcst = 0.1e-9

    # Return the container object
    return mdl
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
def gen_model():

    mdl = smodel.Model()

    X = smodel.Spec('X', mdl)
    A = smodel.Spec('A', mdl)
    # Vol/surface systems
    cytosolv = smodel.Volsys('cytosolv', mdl)

    dif_X = smodel.Diff('diffX', cytosolv, X)
    dif_X.setDcst(DCST)

    reac_X = smodel.Reac('reacX', cytosolv, lhs=[A], rhs=[A, X])

    return mdl
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
def gen_model():
    mdl = smodel.Model()
    A = smodel.Spec('A', mdl)
    vsys = smodel.Volsys('cytosolv', mdl)
    diff_A = smodel.Diff('diff_A', vsys, A)
    diff_A.setDcst(DCST)
    return mdl
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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_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()
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
def get_model():
    mdl  = smod.Model()
    A = smod.Spec('A', mdl)
    volsys = smod.Volsys('vsys',mdl)
    R1 = smod.Reac('R1', volsys, lhs = [], rhs = [A])
    R1.setKcst(1e-3)
    return mdl
Exemplo n.º 12
0
    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])
Exemplo n.º 13
0
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))
Exemplo n.º 14
0
def gen_model():

    mdl = smodel.Model()
    A = smodel.Spec('A', mdl)
    ssys = smodel.Surfsys('ssys', mdl)
    diff_A = smodel.Diff('diffA', ssys, A, DCST)

    return mdl
def gen_model():
    
    mdl = smodel.Model()
    X = smodel.Spec('X', mdl)
    ssys = smodel.Surfsys('ssys', mdl)
    diff_X = smodel.Diff('diffX', ssys, X,  DCST)
    
    return mdl
Exemplo n.º 16
0
def gen_model():
    mdl = smodel.Model()
    X = smodel.Spec('X', mdl)
    cytosolv = smodel.Volsys('cytosolv', mdl)
    dif_X = smodel.Diff('diffX', cytosolv, X)
    dif_X.setDcst(DCST)

    return mdl
Exemplo n.º 17
0
def gen_model():
    
    mdl = smod.Model()
    
    # The chemical species
    A = smod.Spec('A', mdl)
    B = smod.Spec('B', mdl)
    C = smod.Spec('C', mdl)
    D = smod.Spec('D', mdl)
    E = smod.Spec('E', mdl)
    F = smod.Spec('F', mdl)
    G = smod.Spec('G', mdl)
    H = smod.Spec('H', mdl)
    I = smod.Spec('I', mdl)
    J = smod.Spec('J', mdl)

    volsys = smod.Volsys('vsys',mdl)


    R1 = smod.Reac('R1', volsys, lhs = [A, B], rhs = [C],  kcst = 1000.0e6)
    R2 = smod.Reac('R2', volsys, lhs = [C],  rhs = [A,B], kcst = 100)
    R3 = smod.Reac('R3', volsys, lhs = [C, D], rhs = [E], kcst = 100e6)
    R4 = smod.Reac('R4', volsys, lhs = [E], rhs = [C,D], kcst = 10)

    R5 = smod.Reac('R5', volsys, lhs = [F, G], rhs = [H], kcst = 10e6)
    R6 = smod.Reac('R6', volsys, lhs = [H], rhs = [F,G], kcst = 1)
    R7 = smod.Reac('R7', volsys, lhs = [H, I], rhs = [J],  kcst = 1e6)
    R8 = smod.Reac('R8', volsys, lhs = [J],  rhs = [H,I], kcst = 0.1*10)


    # The diffusion rules
    D1 = smod.Diff('D1', volsys, A,  100e-12)
    D2 = smod.Diff('D2', volsys, B,  90e-12)
    D3 = smod.Diff('D3', volsys, C, 80e-12)
    D4 = smod.Diff('D4', volsys, D, 70e-12)
    D5 = smod.Diff('D5', volsys, E, 60e-12)
    D6 = smod.Diff('D6', volsys, F,  50e-12)
    D7 = smod.Diff('D7', volsys, G,  40e-12)
    D8 = smod.Diff('D8', volsys, H,  30e-12)
    D9 = smod.Diff('D9', volsys, I,  20e-12)
    D10 = smod.Diff('D10', volsys, J, 10e-12)
    
    return mdl
Exemplo n.º 18
0
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))
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
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
Exemplo n.º 22
0
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))
Exemplo n.º 23
0
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
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
N = 50  # Can set count or conc
VOL = 1.0e-18

NITER = 100000  # The number of iterations
DT = 0.1  # Sampling time-step
INT = 1.1  # Sim endtime

# Tolerance for the comparison:
# 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]
Exemplo n.º 26
0
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
Exemplo n.º 27
0
#based on the paper "stochastic chemical reactions"
#model:
#X1bar ->c1-> Y1

import steps.model as smodel
#import package steps.model that contains all the definitions of
#the objects and functions you need to describe the physics and
#chemistory.

mdl = smodel.Model()
#mdl variable for discribing model.
#create a top-level container object for our model this top model
#container is required for all simulations in STEPS.

molX1bar = smodel.Spec('molX1bar', mdl)
molY1 = smodel.Spec('molY1', mdl)
#create 2 steps.model.Spec objects corresponding to 2 chamical
#spicies

vsys = smodel.Volsys('vsys', mdl)
#create a volume system
#volume systems art container objects that group a number of
#stoichimetric reaction rules.

c1reac_f = smodel.Reac('c1reac_f', vsys, lhs=[molX1bar], rhs=[molY1], kcst=0.2)
#create the reaction rules themselves
#what is cicst = 0.3e6?

import steps.geom as swm
#import the geometry module that contains the objects used to
Exemplo n.º 28
0
tolerance = 7.5/100


# create the array of tet indices to be found at random
tetidxs = numpy.zeros(SAMPLE, dtype = 'int')
# further create the array of tet barycenter distance to center
tetrads = numpy.zeros(SAMPLE)

########################################################################
rng = srng.create('mt19937', 512) 
rng.initialize(int(time.time()%4294967295)) # The max unsigned long


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,B], rhs = [])

R1.setKcst(RCST)

D_a = smod.Diff('D_a', volsys, A)
D_a.setDcst(DCSTA)
D_b = smod.Diff('D_b', volsys, B)
D_b.setDcst(DCSTB)

Exemplo n.º 29
0
    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)
Exemplo n.º 30
0
    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()