Example #1
0
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
Example #2
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)
Example #3
0
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
Example #4
0
def gen_geom():
    # import the tetrahedral mesh
    mesh = meshio.importAbaqus('astrocyte.inp', 1e-6)[0]
    # create a compartment comprising all mesh tetrahedrons
    ntets = mesh.countTets()

    # create cytosolic compartment
    cyto = stetmesh.TmComp('cyto', mesh, range(ntets))
    # add volume system to cytosol
    cyto.addVolsys('vsys')

    # create ER compartment
    er = stetmesh.Comp('er', mesh)
    # Assign volume to ER
    er.setVol(0.00314e-19)
    # add volume system to ER
    cyto.addVolsys('er_vsys')

    # Define surfaces
    # "cylinder_mesh.txt" describes Cyto & ER surfaces to import
    input = open("cylinder_mesh.txt", 'r')
    ASTRO_TRIS = pickle.load(input)
    ER_TRIS = pickle.load(input)
    input.close()

    # create the patch for ER membrane
    er_patch = stetmesh.TmPatch('er_patch', mesh, ER_TRIS, cyto)
    er_patch.addSurfsys('ssys')

    # create the patch for astrocyte plasma membrane
    cyto_patch = stetmesh.TmPatch('cyto_patch', mesh, ASTRO_TRIS, icomp=cyto)
    cyto_patch.addSurfsys('mb_surf')

    # return geometry container object
    return mesh, ASTRO_TRIS, ER_TRIS
Example #5
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))
    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)
Example #7
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))
Example #8
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
Example #9
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))
Example #10
0
def get_geom(geom_type):
    if geom_type == "well_mixed":
        geom = sgeom.Geom()
        comp = sgeom.Comp("comp", geom, 1e-18)
        comp.addVolsys("vsys")
        return geom
    elif geom_type == "tetmesh":
        mesh_loc = None
        if __name__ == "__main__":
            mesh_loc = "meshes/1x1x1.inp"
        else:
            mesh_loc = "validation_rd/meshes/1x1x1.inp"
        mesh = meshio.importAbaqus(mesh_loc, 1e-6)[0]
        comp = sgeom.TmComp("comp", mesh, range(mesh.ntets))
        comp.addVolsys("vsys")
        return mesh
    else:
        assert (False)
#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
#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
Example #12
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)
Example #13
0
def test_soirevAA():
    KCST = 50.0e6  # The reaction constant

    CONCA = 20.0e-6
    CONCB = CONCA

    VOL = 9.0e-18

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

    # In test runs, with good code, <0.1% will fail with a tolerance of 1%
    tolerance = 1.0 / 100

    ########################################################################

    mdl = smod.Model()

    A = smod.Spec('A', mdl)
    B = smod.Spec('B', mdl)
    C = smod.Spec('C', mdl)

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

    R1 = smod.Reac('R1', volsys, lhs=[A, B], rhs=[C], kcst=KCST)

    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, 3])

    for i in range(0, NITER):
        sim.restore('./validation_cp/cp/second_order_irev_AA')
        for t in range(0, ntpnts):
            sim.run(tpnts[t])
            res_m[i, t, 0] = sim.getCompConc('comp1', 'A')
            res_m[i, t, 1] = sim.getCompConc('comp1', 'B')

    mean_res = numpy.mean(res_m, 0)

    invA = numpy.zeros(ntpnts)
    invB = numpy.zeros(ntpnts)
    lineA = numpy.zeros(ntpnts)
    lineB = numpy.zeros(ntpnts)

    max_err = 0.0
    passed = True
    for i in range(ntpnts):
        invA[i] = (1.0 / mean_res[i][0])
        invB[i] = (1.0 / mean_res[i][1])
        lineA[i] = (1.0 / CONCA + ((tpnts[i] * KCST)))
        lineB[i] = (1.0 / CONCB + ((tpnts[i] * KCST)))

        assert (tol_funcs.tolerable(invA[i], lineA[i], tolerance))
        assert (tol_funcs.tolerable(invB[i], lineB[i], tolerance))
Example #14
0
A10_bind_Ca_b.setKcst(667)
Ob_bind_Ca_b.setKcst(2000)
Ia_bind_Ca_b.setKcst(16)

A00_bind_Ca_b.setKcst(1)
Pb_bind_Ca_b.setKcst(150)
Sa_bind_Ca_b.setKcst(20)

A01_bind_IP3_b.setKcst(18)

#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()
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)
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))
Example #17
0
        else:
            DScales_ShellOut[i].append(2*Shells_radii[i][j+1]/((Shells_radii[i][j+1]**2 - Shells_radii[i][j+2]**2)*0.2e-6))
            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')
Example #18
0
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]

res_m = numpy.zeros([NITER, ntpnts, 1])
res_std1 = numpy.zeros([ntpnts, 1])
res_std2 = numpy.zeros([ntpnts, 1])
Example #19
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)
Example #20
0
A00_bind_Ca_b.setKcst(1)
Pb_bind_Ca_b.setKcst(150)
Sa_bind_Ca_b.setKcst(20)

A01_bind_IP3_b.setKcst(18)

#A00_0a_Ca_channel_f.setKcst(1e-3)  		#########I can't find a right number!#############
#A00_Ob_Ca_channel_f.setKcst(1e-3)			#########I can't find a right number!#############
#A00_Oc_Ca_channel_f.setKcst(1e-3)			#########I can't find a right number!#############

#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, vol=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()

import steps.rng as srng
Example #21
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
Example #22
0
RCa_bind_Ca_b.setKcst(10)
R2Ca_bind_Ca_f.setKcst(40e6)
R2Ca_bind_Ca_b.setKcst(15)
R3Ca_bind_Ca_f.setKcst(60e6)
R3Ca_bind_Ca_b.setKcst(20)
R_Ca_channel_f.setKcst(2e8)

#########################
# Geom setup
#########################

import steps.geom as swm
wmgeom = swm.Geom()

# Create the cytosol compartment
cyt = swm.Comp('cyt', wmgeom)
cyt.setVol(1.6572e-19)

# Create the Endoplasmic Reticulum compartment
ER = swm.Comp('ER', wmgeom, vol=1.968e-20)

# ER is the 'inner' compartment, cyt is the 'outer' compartment
memb = swm.Patch('memb', wmgeom, ER, cyt)
memb.addSurfsys('ssys')
memb.setArea(0.4143e-12)

print 'Inner compartment to memb is', memb.getIComp().getID()

print 'Outer compartment to memb is', memb.getOComp().getID()

#########################