Example #1
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)
    def setUp(self):
        DCST = 0.08e-10
        self.model = smodel.Model()
        A = smodel.Spec('A', self.model)

        self.vsys = smodel.Volsys('vsys', self.model)
        self.ssys = smodel.Surfsys('ssys', self.model)
        self.diff = smodel.Diff("diff", self.vsys, A, DCST)
        self.sdiff = smodel.Diff("diff", self.ssys, A, DCST)

        if __name__ == "__main__":
            self.mesh = meshio.importAbaqus('meshes/test_mesh.inp', 1e-7)[0]
        else:
            self.mesh = meshio.importAbaqus(
                'parallel_std_string_bugfix_test/meshes/test_mesh.inp',
                1e-7)[0]

        self.tmcomp = sgeom.TmComp('comp', self.mesh, range(self.mesh.ntets))
        self.tmcomp.addVolsys('vsys')
        self.surf_tris = self.mesh.getSurfTris()
        self.tmpatch = sgeom.TmPatch('patch',
                                     self.mesh,
                                     self.surf_tris,
                                     icomp=self.tmcomp)
        self.tmpatch.addSurfsys('ssys')

        self.rng = srng.create('r123', 512)
        self.rng.initialize(1000)

        tet_hosts = gd.binTetsByAxis(self.mesh, steps.mpi.nhosts)
        tri_hosts = gd.partitionTris(self.mesh, tet_hosts, self.surf_tris)
        self.solver = solv.TetOpSplit(self.model, self.mesh, self.rng,
                                      solv.EF_NONE, tet_hosts, tri_hosts)

        self.solver.reset()
def 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
Example #4
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)
Example #5
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)
Example #6
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)
Example #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]
        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])
Example #8
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
Example #9
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
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
Example #11
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
Example #12
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
Example #13
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
Example #14
0
########################################################################
#                                                                      #
#                            Anomalous Diffusion                       #
#                                                                      #
########################################################################


########################################################################
# Create Model

import steps.model as smodel

mdl = smodel.Model()
X = smodel.Spec('X', mdl)
dend_vsys = smodel.Volsys('vsys', mdl)
dif_X = smodel.Diff('diffX', dend_vsys, X, 2e-9)

########################################################################
# Create Gemoetry

import steps.utilities.meshio as meshio

meshes = []
for d in [0, 2, 4, 8]:
    meshes.append(meshio.importAbaqus('%i_20_0.7.inp' % (d), 1e-6, None, "%i_20_0.7_conf" % (d))[0])

########################################################################
# Create Random number generator

import steps.rng as srng
import time
Example #15
0
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)


mesh = meshio.loadMesh('./validation_rd/meshes/brick_40_4_4_1686tets')[0]

VOLA = mesh.getMeshVolume()/2.0
VOLB = VOLA

ntets = mesh.countTets()

acomptets = []
bcomptets = []
max = mesh.getBoundMax()
import random
import steps.model as smodel
import steps.geom as sgeom
import steps.rng as srng
import steps.solver as solv
from steps.utilities import meshio
import time

DCST = 0.2e-9

# define model
model = smodel.Model()
A = smodel.Spec('A', model)
surfsys = smodel.Surfsys('ssys', model)
D_a = smodel.Diff('D_a', surfsys, A)
DCST = 0.2e-9
D_a.setDcst(DCST)

mesh = meshio.importAbaqus2("mesh_tet.inp", "mesh_tri.inp", 1e-6,
                            "mesh_conf")[0]

boundary_tris = mesh.getROIData("boundary")
v1_tets = mesh.getROIData("v1_tets")

comp1 = sgeom.TmComp("comp1", mesh, v1_tets)

patch1 = sgeom.TmPatch("patch", mesh, boundary_tris, comp1)
patch1.addSurfsys("ssys")

neigh_tris = mesh.getROIData("neigh_tri")
Example #17
0
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# STEPS - STochastic Engine for Pathway Simulation
# Copyright (C) 2007-2011 Okinawa Institute of Science and Technology, Japan.
# Copyright (C) 2003-2006 University of Antwerp, Belgium.
#
# See the file AUTHORS for details.
#
# This file is part of STEPS.
#
# STEPS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# STEPS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import steps.model as smod
import steps.geom as sgeom
import steps.rng as srng
import steps.solver as ssolv
import math
import time
import steps.utilities.meshio as smeshio
Example #18
0
PVMg = smodel.Spec('PVMg', mdl_det)
# PVCa
PVCa = smodel.Spec('PVCa', mdl_det)
# Mg
Mg = smodel.Spec('Mg', mdl_det)

# Vol/surface systems

vsys_stoch = smodel.Volsys('vsys_stoch', mdl_stoch)
ssys_stoch = smodel.Surfsys('ssys_stoch', mdl_stoch)

vsys_det = smodel.Volsys('vsys_det', mdl_det)
ssys_det = smodel.Surfsys('ssys_det', mdl_det)

# Diffusions
diff_Ca = smodel.Diff('diff_Ca', vsys_det, Ca_det)
diff_Ca.setDcst(DCST)
diff_CBsf = smodel.Diff('diff_CBsf', vsys_det, CBsf)
diff_CBsf.setDcst(DCB)
diff_CBsCa = smodel.Diff('diff_CBsCa', vsys_det, CBsCa)
diff_CBsCa.setDcst(DCB)
diff_CBCaf = smodel.Diff('diff_CBCaf', vsys_det, CBCaf)
diff_CBCaf.setDcst(DCB)
diff_CBCaCa = smodel.Diff('diff_CBCaCa', vsys_det, CBCaCa)
diff_CBCaCa.setDcst(DCB)
diff_PV = smodel.Diff('diff_PV', vsys_det, PV)
diff_PV.setDcst(DPV)
diff_PVCa = smodel.Diff('diff_PVCa', vsys_det, PVCa)
diff_PVCa.setDcst(DPV)
diff_PVMg = smodel.Diff('diff_PVMg', vsys_det, PVMg)
diff_PVMg.setDcst(DPV)
Example #19
0
OUTPUTFILE = "reac_diff.trace"
########################################################################

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

#R1.setKcst(RCST)

D_a = smod.Diff('D_a', volsys, A, dcst=DCSTA)
#D_b = smod.Diff('D_b', volsys, B, dcst = DCSTB)
#D_c = smod.Diff('D_c', volsys, C, dcst = DCSTB)

mesh, nodeproxy, tetproxy, triproxy = smeshio.importAbaqus(
    'brick_40_4_4_2_comp.inp', scale)
ntets = mesh.ntets
tet_groups = tetproxy.blocksToGroups()
Atets = tet_groups['EB1']
nATets = len(Atets)
Btets = tet_groups['EB2']
nBTets = len(Btets)
comp1 = sgeom.TmComp('comp1', mesh, xrange(mesh.ntets))
comp1.addVolsys('vsys')

rng = srng.create('mt19937', 16384)
Example #20
0
def model(tissue):
    """ initialises model using tissue array """

    mdl = smodel.Model()
    unique_p = []
    for cell in tissue:
        [unique_p.append(p) for p in cell.prtcl_names if p not in unique_p]

    NP = []
    NPi = []
    NPR = []
    # Create particles and corresponding species
    for p in unique_p:
        # Free NPs
        NP.append(smodel.Spec('N{}'.format(p), mdl))
        # internalised NPs
        NPi.append(smodel.Spec('N{}i'.format(p), mdl))
        # complexes state: NPs bound to a cell receptor
        # NPR.append(smodel.Spec('N{}R'.format(p), mdl))

        # receptor state: 'naive' state (no bound NPs)
    R = smodel.Spec('R', mdl)
    NPR = smodel.Spec('NPR', mdl)
    d = {}
    rxn_ = {}
    dfsn_ = {}
    # Lpop where cell and particle properties are connected to reactions
    for n, cell in enumerate(tissue):
        for p_idx, p in enumerate(unique_p):
            tag = str(n) + p
            prtcl = getattr(cell, p)
            d["surfsys{}".format(tag)] = smodel.Surfsys(
                "surfsys{}".format(tag), mdl)
            d["volsys{}".format(tag)] = smodel.Volsys("volsys{}".format(tag),
                                                      mdl)
            k_diff = prtcl['D'] / (float(cell.S) * float(cell.S))

            dfsn_["frwd_{}".format(tag)] = smodel.SReac(
                "frwd_{}".format(tag),
                d["surfsys{}".format(tag)],
                ilhs=[NP[p_idx]],
                orhs=[NP[p_idx]],
                kcst=k_diff)
            dfsn_["bkwd_{}".format(tag)] = smodel.SReac(
                "bkwd_{}".format(tag),
                d["surfsys{}".format(tag)],
                olhs=[NP[p_idx]],
                irhs=[NP[p_idx]],
                kcst=k_diff)

            # binding reactions:
            if 'k_a' in prtcl:
                k_bind = prtcl['k_a']
                k_unbind = prtcl['k_d']
                k_intern = prtcl['k_i']
                rxn_["bind_{}".format(tag)] = smodel.Reac(
                    "bind_{}".format(tag),
                    d["volsys{}".format(tag)],
                    lhs=[NP[p_idx], R],
                    rhs=[NPR],
                    kcst=k_bind)
                rxn_["unbind_{}".format(tag)] = smodel.Reac(
                    "unbind_{}".format(tag),
                    d["volsys{}".format(tag)],
                    lhs=[NPR],
                    rhs=[NP[p_idx], R],
                    kcst=k_unbind)
                rxn_["intern_{}".format(tag)] = smodel.Reac(
                    "intern_{}".format(tag),
                    d["volsys{}".format(tag)],
                    lhs=[NPR],
                    rhs=[NPi[p_idx], R],
                    kcst=k_intern)

            # Diffusion
            dfsn1 = smodel.Diff('dfsn1',
                                d["volsys{}".format(tag)],
                                NP[p_idx],
                                dcst=k_diff)
            dfsn2 = smodel.Diff('dfsn2',
                                d["volsys{}".format(tag)],
                                NPR,
                                dcst=k_diff)
            dfsn3 = smodel.Diff('dfsn3',
                                d["volsys{}".format(tag)],
                                R,
                                dcst=k_diff)
            dfsn4 = smodel.Diff('dfsn4',
                                d["volsys{}".format(tag)],
                                NPi[p_idx],
                                dcst=k_diff)

    return mdl
Example #21
0
                           srhs=[CaP_m0],
                           k=lambda V: 1.0e3 * 1. * beta_cap(V * 1.0e3),
                           vrange=vrange)

# current that will start for channels in the n4 conformational state:
OC_CaP = smodel.GHKcurr('OC_CaP',
                        ssys,
                        CaP_m3,
                        Ca,
                        virtual_oconc=Ca_oconc,
                        computeflux=True)

#Set single channel permeability
OC_CaP.setP(CaP_P)

diff_Ca_cyt = smodel.Diff('diff_Ca_cyt', vsys0, Ca,
                          DCST)  # name, where, what, how fast
diff_Ca_ER = smodel.Diff('diff_Ca_ER', vsys1, Ca,
                         DCST)  # name, where, what, how fast

# diff_Ca_sens    = smodel.Diff('diff_Ca_sens', surfsys2, Ca_sens,  DCST) # name, where, what, how fast

# define compartments:
cyto_comp = stetmesh.TmComp('cyto_comp', mesh, CS_tet_IDs)
ER_comp = stetmesh.TmComp('ER_comp', mesh, ER_tet_IDs)

# get surf tris in comps:
CS_memb_tris = meshctrl.findSurfTrisInComp(mesh, cyto_comp)
ER_memb_tris = meshctrl.findOverlapTris(mesh, CS_tet_IDs, ER_tet_IDs)

# patches:
ER_surf = stetmesh.TmPatch('ER_surf',
import random
import steps.model as smodel
import steps.geom as sgeom
import steps.rng as srng
import steps.solver as solv
from steps.utilities import meshio
import time

DCST = 0.2e-9

# define model
model = smodel.Model()
A = smodel.Spec('A', model)
volsys = smodel.Volsys('vsys', model)
D_a = smodel.Diff('D_a', volsys, A)
D_a.setDcst(DCST)

# setup geometry
mesh = meshio.importAbaqus2("mesh_tet.inp", "mesh_tri.inp", 1e-6, "mesh_conf")[0]
comp = sgeom.TmComp("comp", mesh, range(mesh.ntets))
comp.addVolsys("vsys")

# boundary triangles splitting v1 and v2
boundary_tris = mesh.getROIData("boundary")
# tetrahedrons in v1 and adjancent to the boundary
boundary_tets1 = mesh.getROIData("boundary_tets_1")
# tetrahedrons in v2 and adjancent to the boundary
boundary_tets2 = mesh.getROIData("boundary_tets_2")

# pairing their indices
Example #23
0
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import ip3r_model

# Import model
mdl = ip3r_model.getModel()

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

# Fetch reference to Calcium and IP3 Spec objects
Ca = mdl.getSpec('Ca')
IP3 = mdl.getSpec('IP3')

# Create diffusion rules
Ca_diff = smodel.Diff('Ca_diff', volsys, Ca, DCST_Ca)
IP3_diff = smodel.Diff('IP3_diff', volsys, IP3, DCST_IP3)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Import mesh
import steps.utilities.meshio as meshio

mesh = meshio.loadMesh("ip3r_mesh")[0]

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

# Create random number generator
r = srng.create('mt19937', 512)
r.initialize(456)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Example #24
0
    def setUp(self):
        self.DCST = 0.08e-12

        self.model = smodel.Model()
        A = smodel.Spec('A', self.model)
        X = smodel.Spec('X', self.model)

        self.ssys1 = smodel.Surfsys('ssys1', self.model)
        self.ssys2 = smodel.Surfsys('ssys2', self.model)
    
        self.sreac = smodel.SReac('sreac', self.ssys1, slhs = [A], srhs = [A],  kcst = 1e5)
        self.diff1 = smodel.Diff('diffX1', self.ssys1, X, self.DCST)
        self.diff2 = smodel.Diff('diffX2', self.ssys2, X, self.DCST)

        if __name__ == "__main__":
            self.mesh = meshio.loadMesh('meshes/coin_10r_1h_13861')[0]
        else:
            self.mesh = meshio.loadMesh('sdiff_bugfix_test/meshes/coin_10r_1h_13861')[0]

        ntets = self.mesh.countTets()
        self.comp = sgeom.TmComp('cyto', self.mesh, range(ntets))

        alltris = self.mesh.getSurfTris()

        patchA_tris = []
        patchB_tris = []
        patchA_bars = set()
        patchB_bars = set()

        for t in alltris:
            vert0, vert1, vert2 = self.mesh.getTri(t)
            if (self.mesh.getVertex(vert0)[2] > 0.0 \
                and self.mesh.getVertex(vert1)[2] > 0.0 \
                and self.mesh.getVertex(vert2)[2] > 0.0):
                if self.mesh.getTriBarycenter(t)[0] > 0.0:
                    patchA_tris.append(t)
                    bar = self.mesh.getTriBars(t)
                    patchA_bars.add(bar[0])
                    patchA_bars.add(bar[1])
                    patchA_bars.add(bar[2])
                else:
                    patchB_tris.append(t)
                    bar = self.mesh.getTriBars(t)
                    patchB_bars.add(bar[0])
                    patchB_bars.add(bar[1])
                    patchB_bars.add(bar[2])

        self.patchA = sgeom.TmPatch('patchA', self.mesh, patchA_tris, icomp = self.comp)
        self.patchA.addSurfsys('ssys1')
        self.patchB = sgeom.TmPatch('patchB', self.mesh, patchB_tris, icomp = self.comp)
        self.patchB.addSurfsys('ssys2')

        # Find the set of bars that connect the two patches as the intersecting bars
        barsDB = patchA_bars.intersection(patchB_bars)
        barsDB=list(barsDB)

        # Create the surface diffusion boundary
        self.diffb = sgeom.SDiffBoundary('sdiffb', self.mesh, barsDB, [self.patchA, self.patchB])

        ctetidx = self.mesh.findTetByPoint([0.0, 0.0, 0.5e-6])
        ctet_trineighbs = self.mesh.getTetTriNeighb(ctetidx)
        self.ctri_idx=-1
        for t in ctet_trineighbs: 
            if t in patchA_tris+patchB_tris:
                self.ctri_idx = t

        self.rng = srng.create('r123', 512)
        self.rng.initialize(1000)
        
        self.solver = solv.Tetexact(self.model, self.mesh, self.rng)
Example #25
0
def gen_model(x, flux):
    ####
    ####
    print "Create sim"
    mdl = smod.Model()

    # Defining chemical compartments
    vsys = smod.Volsys('vsys_Cyt', mdl)
    ssys = smod.Surfsys('ssys', mdl)

    ##
    ## Cytosolic molecule species
    ##
    CYT_MOL_NUM = len(x.CYT_MOL_NAME)
    CYT_MOL = []
    for i in range(CYT_MOL_NUM):
        print i, x.CYT_MOL_NAME[i]
        ns = globals()
        ns[x.CYT_MOL_NAME[i]] = smod.Spec(x.CYT_MOL_NAME[i], mdl)
        # CYT_MOL.append( smod.Spec(CYT_MOL_NAME[i], mdl) )

    ##
    ## Surface molecule species
    ##
    SUR_MOL_NUM = len(x.SUR_MOL_NAME)
    SUR_MOL = []
    for i in range(SUR_MOL_NUM):
        print i, x.SUR_MOL_NAME[i]
        ns = globals()
        ns[x.SUR_MOL_NAME[i]] = smod.Spec(x.SUR_MOL_NAME[i], mdl)

    ##
    ## Cytosolic molecule reactions
    ##
    smod.Reac('on_CB', vsys, lhs=[Ca, CB], rhs=[CBCa], kcst=x.kon_CB)
    smod.Reac('of_CB', vsys, lhs=[CBCa], rhs=[Ca, CB], kcst=x.kof_CB)

    smod.Reac('on_TN1', vsys, lhs=[Ca, N0C0], rhs=[N1C0], kcst=2 * x.kon_TN)
    smod.Reac('of_TN1', vsys, lhs=[N1C0], rhs=[Ca, N0C0], kcst=x.kof_TN)
    smod.Reac('on_RN1', vsys, lhs=[Ca, N1C0], rhs=[N2C0], kcst=x.kon_RN)
    smod.Reac('of_RN1', vsys, lhs=[N2C0], rhs=[Ca, N1C0], kcst=2 * x.kof_RN)

    smod.Reac('on_TN2', vsys, lhs=[Ca, N0C1], rhs=[N1C1], kcst=2 * x.kon_TN)
    smod.Reac('of_TN2', vsys, lhs=[N1C1], rhs=[Ca, N0C1], kcst=x.kof_TN)
    smod.Reac('on_RN2', vsys, lhs=[Ca, N1C1], rhs=[N2C1], kcst=x.kon_RN)
    smod.Reac('of_RN2', vsys, lhs=[N2C1], rhs=[Ca, N1C1], kcst=2 * x.kof_RN)

    smod.Reac('on_TN3', vsys, lhs=[Ca, N0C2], rhs=[N1C2], kcst=2 * x.kon_TN)
    smod.Reac('of_TN3', vsys, lhs=[N1C2], rhs=[Ca, N0C2], kcst=x.kof_TN)
    smod.Reac('on_RN3', vsys, lhs=[Ca, N1C2], rhs=[N2C2], kcst=x.kon_RN)
    smod.Reac('of_RN3', vsys, lhs=[N2C2], rhs=[Ca, N1C2], kcst=2 * x.kof_RN)

    smod.Reac('on_TC1', vsys, lhs=[Ca, N0C0], rhs=[N0C1], kcst=2 * x.kon_TC)
    smod.Reac('of_TC1', vsys, lhs=[N0C1], rhs=[Ca, N0C0], kcst=x.kof_TC)
    smod.Reac('on_RC1', vsys, lhs=[Ca, N0C1], rhs=[N0C2], kcst=x.kon_RC)
    smod.Reac('of_RC1', vsys, lhs=[N0C2], rhs=[Ca, N0C1], kcst=2 * x.kof_RC)

    smod.Reac('on_TC2', vsys, lhs=[Ca, N1C0], rhs=[N1C1], kcst=2 * x.kon_TC)
    smod.Reac('of_TC2', vsys, lhs=[N1C1], rhs=[Ca, N1C0], kcst=x.kof_TC)
    smod.Reac('on_RC2', vsys, lhs=[Ca, N1C1], rhs=[N1C2], kcst=x.kon_RC)
    smod.Reac('of_RC2', vsys, lhs=[N1C2], rhs=[Ca, N1C1], kcst=2 * x.kof_RC)

    smod.Reac('on_TC3', vsys, lhs=[Ca, N2C0], rhs=[N2C1], kcst=2 * x.kon_TC)
    smod.Reac('of_TC3', vsys, lhs=[N2C1], rhs=[Ca, N2C0], kcst=x.kof_TC)
    smod.Reac('on_RC3', vsys, lhs=[Ca, N2C1], rhs=[N2C2], kcst=x.kon_RC)
    smod.Reac('of_RC3', vsys, lhs=[N2C2], rhs=[Ca, N2C1], kcst=2 * x.kof_RC)

    ##
    ## Ca pump and VGCC
    ##

    smod.SReac('PA_To_PA_Ca',
               ssys,
               slhs=[PA],
               ilhs=[Ca],
               srhs=[PA_Ca],
               kcst=150 * 1e6)
    smod.SReac('PA_Ca_To_PA', ssys, slhs=[PA_Ca], srhs=[PA], kcst=12)
    smod.SReac('Leak_To_Leak_Ca',
               ssys,
               slhs=[Leak],
               srhs=[Leak],
               irhs=[Ca],
               kcst=0.015)
    smod.SReac('NR_Glu_To_NR', ssys, slhs=[NR_Glu], srhs=[NR], kcst=50)
    smod.SReac('NR_Glu_To_NR_O', ssys, slhs=[NR_Glu], srhs=[NR_O], kcst=200)
    smod.SReac('NR_O_To_NR_Glu', ssys, slhs=[NR_O], srhs=[NR_Glu], kcst=50)
    smod.SReac('NR_O_To_NR_O_Ca',
               ssys,
               slhs=[NR_O],
               srhs=[NR_O],
               irhs=[Ca],
               kcst=flux)

    ##
    ## Species on left hand side:  Surface (slhs), Outer comp (olhs), Inner comp (ilhs)
    ## Species on right hand side: Surface (srhs), Outer comp (orhs), Inner comp (irhs)
    ##

    # Diffusion rules
    smod.Diff('D_Ca', vsys, Ca, x.DCa)
    smod.Diff('D_N0C0', vsys, N0C0, x.DCaM)
    smod.Diff('D_N0C1', vsys, N0C1, x.DCaM)
    smod.Diff('D_N0C2', vsys, N0C2, x.DCaM)
    smod.Diff('D_N1C0', vsys, N1C0, x.DCaM)
    smod.Diff('D_N1C1', vsys, N1C1, x.DCaM)
    smod.Diff('D_N1C2', vsys, N1C2, x.DCaM)
    smod.Diff('D_N2C0', vsys, N2C0, x.DCaM)
    smod.Diff('D_N2C1', vsys, N2C1, x.DCaM)
    smod.Diff('D_N2C2', vsys, N2C2, x.DCaM)
    smod.Diff('D_CB', vsys, CB, x.DCB)
    smod.Diff('D_CBCa', vsys, CBCa, x.DCB)

    return mdl
Example #26
0
def getModel():
    # Create model container
    mdl = smod.Model()

    # Create chemical species
    ca = smod.Spec('ca', mdl)
    ip3 = smod.Spec('ip3', mdl)
    plc = smod.Spec('plc', mdl)

    # Create calcium buffers
    GCaMP6s = smod.Spec('GCaMP6s', mdl)
    ca_GCaMP6s = smod.Spec('ca_GCaMP6s', mdl)

    # Create IP3R states species
    unb_IP3R = smod.Spec('unb_IP3R', mdl)
    ip3_IP3R = smod.Spec('ip3_IP3R', mdl)
    caa_IP3R = smod.Spec('caa_IP3R', mdl)
    cai_IP3R = smod.Spec('cai_IP3R', mdl)
    open_IP3R = smod.Spec('open_IP3R', mdl)
    cai_ip3_IP3R = smod.Spec('cai_ip3_IP3R', mdl)
    ca2_IP3R = smod.Spec('ca2_IP3R', mdl)
    ca2_ip3_IP3R = smod.Spec('ca2_ip3_IP3R', mdl)

    # ER surface sys
    ssys = smod.Surfsys('ssys', mdl)

    # plasma membrane surface
    mb_surf = smod.Surfsys('mb_surf', mdl)

    # Create volume system
    # cytosol volume system
    vsys = smod.Volsys('vsys', mdl)

    # ER volume system
    er_vsys = smod.Volsys('er_vsys', mdl)

    ##################################
    ##### DEFINE DIFFUSION RULES #####
    ##################################

    # Diffusion constants
    # Diffusion constant of Calcium (buffered)
    DCST = 0.013e-9
    # Diffusion constant of IP3
    DIP3 = 0.280e-9
    # Diffusion constant of GCaMP6s
    DGCAMP = 0.050e-9

    diff_freeca = smod.Diff('diff_freeca', vsys, ca, DCST)
    diff_ip3 = smod.Diff('diff_ip3', vsys, ip3, DIP3)

    diff_GCaMP6s = smod.Diff('diff_GCaMP6s', vsys, GCaMP6s, DGCAMP)
    diff_ca_GCaMP6s = smod.Diff('diff_ca_GCaMP6s', vsys, ca_GCaMP6s, DGCAMP)

    ##################################
    ######## DEFINE REACTIONS ########
    ##################################
    #### Calcium in and out and Buffering Reactions ####

    # Ca -> null
    ca_deg = smod.Reac('ca_deg', vsys, lhs=[ca])

    # Ca leak
    ca_leak = smod.Reac('ca_leak', vsys, rhs=[ca])

    # Calcium binding to GCaMP6s molecules

    GCaMP6s_bind_ca_f = smod.Reac('GCaMP6s_bind_ca_f', vsys, \
                                lhs=[ca, GCaMP6s], rhs=[ca_GCaMP6s])
    GCaMP6s_bind_ca_b = smod.Reac('GCaMP6s_bind_ca_b', vsys, \
                                lhs=[ca_GCaMP6s], rhs=[GCaMP6s, ca])

    #### IP3 Influx and Buffering Reactions ######
    # IP3 leak
    ip3_leak = smod.Reac('ip3_leak', vsys, rhs=[ip3])

    # IP3 degradation
    ip3_deg = smod.Reac('ip3_deg', vsys, lhs=[ip3])

    # ca activating plc_delta-dependent IP3 synthesis
    plc_ip3_synthesis = smod.SReac('plc_ip3_synthesis', mb_surf, \
                                   slhs=[plc], ilhs= [ca], srhs=[plc], irhs= [ca, ip3])

    ##### IP3R kinetics #####
    # surface/volume reaction ca from cytosol binds activating IP3R site on unbound IP3R
    unb_IP3R_bind_caa_f = smod.SReac('unb_IP3R_bind_caa_f', ssys,\
                                     ilhs=[ca], slhs=[unb_IP3R], srhs=[caa_IP3R])
    unb_IP3R_bind_caa_b = smod.SReac('unb_IP3R_bind_caa_b', ssys, \
                                     slhs=[caa_IP3R], srhs=[unb_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds inactivating IP3R site on unbound IP3R
    unb_IP3R_bind_cai_f = smod.SReac('unb_IP3R_bind_cai_f', ssys, \
                                     ilhs=[ca], slhs=[unb_IP3R], srhs=[cai_IP3R])
    unb_IP3R_bind_cai_b = smod.SReac('unb_IP3R_bind_cai_b', ssys, \
                                     slhs=[cai_IP3R], srhs=[unb_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds activating IP3R site on caa_IP3R
    caa_IP3R_bind_ca_f = smod.SReac('caa_IP3R_bind_ca_f', ssys, \
                                    ilhs=[ca], slhs=[caa_IP3R], srhs=[ca2_IP3R])
    caa_IP3R_bind_ca_b = smod.SReac('caa_IP3R_bind_ca_b', ssys, \
                                    slhs=[ca2_IP3R], srhs=[caa_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds activating IP3R site on ip3_IP3R
    ip3_IP3R_bind_caa_f = smod.SReac('ip3_IP3R_bind_caa_f', ssys, \
                                     ilhs=[ca], slhs=[ip3_IP3R], srhs=[open_IP3R])
    ip3_IP3R_bind_caa_b = smod.SReac('ip3_IP3R_bind_caa_b', ssys, \
                                     slhs=[open_IP3R], srhs=[ip3_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds inactivating IP3R site on ip3_IP3R
    ip3_IP3R_bind_cai_f = smod.SReac('ip3_IP3R_bind_cai_f', ssys, \
                                     ilhs=[ca], slhs=[ip3_IP3R], srhs=[cai_ip3_IP3R])
    ip3_IP3R_bind_cai_b = smod.SReac('ip3_IP3R_bind_cai_b', ssys, \
                                     slhs=[cai_ip3_IP3R], srhs=[ip3_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds activating IP3R site on cai_IP3R
    cai_IP3R_bind_ca_f = smod.SReac('cai_IP3R_bind_ca_f', ssys, \
                                    ilhs=[ca], slhs=[cai_IP3R], srhs=[ca2_IP3R])
    cai_IP3R_bind_ca_b = smod.SReac('cai_IP3R_bind_ca_b', ssys, \
                                    slhs=[ca2_IP3R], srhs=[cai_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds inactivating IP3R site on open_IP3R
    open_IP3R_bind_ca_f = smod.SReac('open_IP3R_bind_ca_f', ssys, \
                                     ilhs=[ca], slhs=[open_IP3R], srhs=[ca2_ip3_IP3R])
    open_IP3R_bind_ca_b = smod.SReac('open_IP3R_bind_ca_b', ssys, \
                                     slhs=[ca2_ip3_IP3R], srhs=[open_IP3R], irhs=[ca])

    # surface/volume reaction ca from cytosol binds activating IP3R site on cai_ip3_IP3R
    cai_ip3_IP3R_bind_ca_f = smod.SReac('cai_ip3_IP3R_bind_ca_f', ssys, \
                                        ilhs=[ca], slhs=[cai_ip3_IP3R], srhs=[ca2_ip3_IP3R])
    cai_ip3_IP3R_bind_ca_b = smod.SReac('cai_ip3_IP3R_bind_ca_b', ssys, \
                                        slhs=[ca2_ip3_IP3R], srhs=[cai_ip3_IP3R], irhs=[ca])

    # surface/volume reaction ip3 from cytosol binds unb_IP3R
    unb_IP3R_bind_ip3_f = smod.SReac('unb_IP3R_bind_ip3_f', ssys, \
                                     ilhs=[ip3], slhs=[unb_IP3R], srhs=[ip3_IP3R])
    unb_IP3R_bind_ip3_b = smod.SReac('unb_IP3R_bind_ip3_b', ssys, \
                                     slhs=[ip3_IP3R], srhs=[unb_IP3R], irhs=[ip3])

    # surface/volume reaction ip3 from cytosol binds caa_IP3R
    caa_IP3R_bind_ip3_f = smod.SReac('caa_IP3R_bind_ip3_f', ssys, \
                                     ilhs=[ip3], slhs=[caa_IP3R], srhs=[open_IP3R])
    caa_IP3R_bind_ip3_b = smod.SReac('caa_IP3R_bind_ip3_b', ssys, \
                                     slhs=[open_IP3R], srhs=[caa_IP3R], irhs=[ip3])

    # surface/volume reaction ip3 from cytosol binds cai_IP3R
    cai_IP3R_bind_ip3_f = smod.SReac('cai_IP3R_bind_ip3_f', ssys, \
                                     ilhs=[ip3], slhs=[cai_IP3R], srhs=[cai_ip3_IP3R])
    cai_IP3R_bind_ip3_b = smod.SReac('cai_IP3R_bind_ip3_b', ssys, \
                                     slhs=[cai_ip3_IP3R], srhs=[cai_IP3R], irhs=[ip3])

    # surface/volume reaction ip3 from cytosol binds ca2_IP3R
    ca2_IP3R_bind_ip3_f = smod.SReac('ca2_IP3R_bind_ip3_f', ssys, \
                                     ilhs=[ip3], slhs=[ca2_IP3R], srhs=[ca2_ip3_IP3R])
    ca2_IP3R_bind_ip3_b = smod.SReac('ca2_IP3R_bind_ip3_b', ssys, \
                                     slhs=[ca2_ip3_IP3R], srhs=[ca2_IP3R], irhs=[ip3])

    ##### Ca ions passing through open IP3R channel to cytosol #####
    Ca_IP3R_flux = smod.SReac('R_Ca_channel_f', ssys, \
                              slhs=[open_IP3R], irhs=[ca], srhs=[open_IP3R])

    ##################################
    #### REACTION CONSTANT VALUES ####
    ##################################

    ##### Calcium Influx and Buffering Reactions #####

    # GCaMP6s mediated calcium buffering
    GCaMP6s_bind_ca_f.setKcst(7.78e6)
    GCaMP6s_bind_ca_b.setKcst(1.12)

    ############# VALUES FOR GCAMP6f #################
    ####    GCaMP6s_bind_ca_f.setKcst(1.05e7)	  ####
    ####    GCaMP6s_bind_ca_b.setKcst(3.93)	  ####
    ##################################################

    # Ca ->  null
    ca_deg.setKcst(30)

    # Ca leak
    ca_leak.setKcst(15e-8)

    ##### IP3 Influx and Buffering Reactions #####
    # IP3 leak does not exist in this model. IP3 synthesis only occurs through PLC activity

    # IP3 -> null
    ip3_deg.setKcst(1.2e-4)

    # ca activating plc_delta-dependent IP3 synthesis
    plc_ip3_synthesis.setKcst(1)

    #### IP3R kinetics #####
    caa_f = 1.2e6
    cai_f = 1.6e4
    ip3_f = 4.1e7
    caa_b = 5e1
    cai_b = 1e2
    ip3_b = 4e2
    unb_IP3R_bind_caa_f.setKcst(caa_f)
    unb_IP3R_bind_caa_b.setKcst(caa_b)

    unb_IP3R_bind_cai_f.setKcst(cai_f)
    unb_IP3R_bind_cai_b.setKcst(cai_b)

    caa_IP3R_bind_ca_f.setKcst(cai_f)
    caa_IP3R_bind_ca_b.setKcst(cai_b)

    ip3_IP3R_bind_caa_f.setKcst(caa_f)
    ip3_IP3R_bind_caa_b.setKcst(caa_b)

    ip3_IP3R_bind_cai_f.setKcst(cai_f)
    ip3_IP3R_bind_cai_b.setKcst(cai_b)

    cai_IP3R_bind_ca_f.setKcst(caa_f)
    cai_IP3R_bind_ca_b.setKcst(caa_b)

    open_IP3R_bind_ca_f.setKcst(cai_f)
    open_IP3R_bind_ca_b.setKcst(cai_b)

    unb_IP3R_bind_ip3_f.setKcst(ip3_f)
    unb_IP3R_bind_ip3_b.setKcst(ip3_b)

    caa_IP3R_bind_ip3_f.setKcst(ip3_f)
    caa_IP3R_bind_ip3_b.setKcst(ip3_b)

    cai_IP3R_bind_ip3_f.setKcst(ip3_f)
    cai_IP3R_bind_ip3_b.setKcst(ip3_b)

    cai_ip3_IP3R_bind_ca_f.setKcst(caa_f)
    cai_ip3_IP3R_bind_ca_b.setKcst(caa_b)

    ca2_IP3R_bind_ip3_f.setKcst(ip3_f)
    ca2_IP3R_bind_ip3_b.setKcst(ip3_b)

    # Ca ions passing through open IP3R channel
    Ca_IP3R_flux.setKcst(6e3)

    return mdl
Example #27
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 = 3.0 / 100

    ####################### Second order irreversible AA ###################

    global KCST_soAA, CONCA_soAA, CONCB_soAA, tolerance_soAA

    KCST_soAA = 5.0e6  # The reaction constant

    CONCA_soAA = 20.0e-6
    CONCB_soAA = CONCA_soAA

    NITER_soAA = 1000  # The number of iterations

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

    ####################### Second order irreversible AB ###################

    global KCST_soAB, CONCA_soAB, CONCB_soAB, tolerance_soAB

    KCST_soAB = 5.0e6  # The reaction constant

    CONCA_soAB = 1.0e-6
    n_soAB = 2
    CONCB_soAB = CONCA_soAB / n_soAB

    NITER_soAB = 1000  # The number of iterations

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

    ####################### Third order irreversible A3 ###################

    global KCST_toA3, CONCA_toA3, tolerance_toA3

    KCST_toA3 = 1.0e12  # The reaction constant

    CONCA_toA3 = 10.0e-6

    NITER_toA3 = 1000  # The number of iterations

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

    ####################### Third order irreversible A2B ###################

    global KCST_toA2B, CONCA_toA2B, CONCB_toA2B, tolerance_toA2B

    KCST_toA2B = 0.1e12  # The reaction constant

    CONCA_toA2B = 30.0e-6
    CONCB_toA2B = 20.0e-6

    NITER_toA2B = 1000  # The number of iterations

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

    ####################### Second order irreversible 2D ###################

    global COUNTA_so2d, COUNTB_so2d, CCST_so2d, tolerance_so2d

    COUNTA_so2d = 100.0
    n_so2d = 2.0
    COUNTB_so2d = COUNTA_so2d / n_so2d

    KCST_so2d = 10.0e10  # The reaction constant

    AREA_so2d = 10.0e-12

    NITER_so2d = 1000  # The number of iterations

    # In tests fewer than 0.1% fail with tolerance of 2%
    tolerance_so2d = 1.0 / 100

    ############################ Common parameters ########################

    global VOL

    DT = 0.1  # Sampling time-step
    INT = 1.1  # Sim endtime

    NITER_max = 100000

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

    mdl = smod.Model()
    volsys = smod.Volsys('vsys', mdl)
    surfsys = smod.Surfsys('ssys', mdl)

    # First order irreversible
    A_foi = smod.Spec('A_foi', mdl)
    A_foi_diff = smod.Diff('A_foi_diff', volsys, A_foi, 0.01e-12)
    R1_foi = smod.Reac('R1_foi', volsys, lhs=[A_foi], rhs=[], kcst=KCST_foi)

    # First order reversible
    A_for = smod.Spec('A_for', mdl)
    B_for = smod.Spec('B_for', mdl)
    A_for_diff = smod.Diff('A_for_diff', volsys, A_for, 0.01e-12)
    B_for_diff = smod.Diff('B_for_diff', volsys, B_for, 0.01e-12)
    R1_for = smod.Reac('R1_for',
                       volsys,
                       lhs=[A_for],
                       rhs=[B_for],
                       kcst=KCST_f_for)
    R2_for = smod.Reac('R2_for',
                       volsys,
                       lhs=[B_for],
                       rhs=[A_for],
                       kcst=KCST_b_for)

    # Second order irreversible A2
    A_soA2 = smod.Spec('A_soA2', mdl)
    C_soA2 = smod.Spec('C_soA2', mdl)
    A_soA2_diff = smod.Diff('A_soA2_diff', volsys, A_soA2, 1e-12)
    R1_soA2 = smod.Reac('R1_soA2',
                        volsys,
                        lhs=[A_soA2, A_soA2],
                        rhs=[C_soA2],
                        kcst=KCST_soA2)

    # Second order irreversible AA
    A_soAA = smod.Spec('A_soAA', mdl)
    B_soAA = smod.Spec('B_soAA', mdl)
    C_soAA = smod.Spec('C_soAA', mdl)
    A_soAA_diff = smod.Diff('A_soAA_diff', volsys, A_soAA, 0.2e-12)
    B_soAA_diff = smod.Diff('B_soAA_diff', volsys, B_soAA, 0.2e-12)
    R1_soAA = smod.Reac('R1_soAA',
                        volsys,
                        lhs=[A_soAA, B_soAA],
                        rhs=[C_soAA],
                        kcst=KCST_soAA)

    # Second order irreversible AB
    A_soAB = smod.Spec('A_soAB', mdl)
    B_soAB = smod.Spec('B_soAB', mdl)
    C_soAB = smod.Spec('C_soAB', mdl)
    A_soAB_diff = smod.Diff('A_soAB_diff', volsys, A_soAB, 0.1e-12)
    B_soAB_diff = smod.Diff('B_soAB_diff', volsys, B_soAB, 0.1e-12)
    R1_soAB = smod.Reac('R1_soAB',
                        volsys,
                        lhs=[A_soAB, B_soAB],
                        rhs=[C_soAB],
                        kcst=KCST_soAB)

    # Third order irreversible A3
    A_toA3 = smod.Spec('A_toA3', mdl)
    C_toA3 = smod.Spec('C_toA3', mdl)
    A_soA3_diff = smod.Diff('A_soA3_diff', volsys, A_toA3, 0.2e-12)
    R1_toA3 = smod.Reac('R1_toA3',
                        volsys,
                        lhs=[A_toA3, A_toA3, A_toA3],
                        rhs=[C_toA3],
                        kcst=KCST_toA3)

    # Third order irreversible A2B
    A_toA2B = smod.Spec('A_toA2B', mdl)
    B_toA2B = smod.Spec('B_toA2B', mdl)
    C_toA2B = smod.Spec('C_toA2B', mdl)
    A_soA2B_diff = smod.Diff('A_soA2B_diff', volsys, A_toA2B, 0.1e-12)
    B_soA2B_diff = smod.Diff('B_soA2B_diff', volsys, B_toA2B, 0.1e-12)
    R1_toA3 = smod.Reac('R1_toA2B',
                        volsys,
                        lhs=[A_toA2B, A_toA2B, B_toA2B],
                        rhs=[C_toA2B],
                        kcst=KCST_toA2B)

    # Second order irreversible 2D
    A_so2d = smod.Spec('A_so2d', mdl)
    B_so2d = smod.Spec('B_so2d', mdl)
    C_so2d = smod.Spec('C_so2d', mdl)
    A_so2d_diff = smod.Diff('A_so2d_diff', surfsys, A_so2d, 1.0e-12)
    B_so2d_diff = smod.Diff('B_so2d_diff', surfsys, B_so2d, 1.0e-12)
    SR1_so2d = smod.SReac('SR1_so2d',
                          surfsys,
                          slhs=[A_so2d, B_so2d],
                          srhs=[C_so2d],
                          kcst=KCST_so2d)

    mesh = smeshio.importAbaqus('validation_rd/meshes/sphere_rad1_37tets.inp',
                                1e-6)[0]
    VOL = mesh.getMeshVolume()

    comp1 = sgeom.TmComp('comp1', mesh, range(mesh.ntets))
    comp1.addVolsys('vsys')
    patch1 = sgeom.TmPatch('patch1', mesh, mesh.getSurfTris(), comp1)
    patch1.addSurfsys('ssys')

    CCST_so2d = KCST_so2d / (6.02214179e23 * patch1.getArea())

    rng = srng.create('r123', 512)
    rng.initialize(1000)

    sim = ssolv.Tetexact(mdl, mesh, rng)
    sim.reset()

    global tpnts, ntpnts
    tpnts = numpy.arange(0.0, INT, DT)
    ntpnts = tpnts.shape[0]

    res_m_foi = numpy.zeros([NITER_foi, ntpnts, 1])
    res_std1_foi = numpy.zeros([ntpnts, 1])
    res_std2_foi = numpy.zeros([ntpnts, 1])

    res_m_for = numpy.zeros([NITER_for, ntpnts, 2])

    res_m_soA2 = numpy.zeros([NITER_soA2, ntpnts, 2])

    res_m_soAA = numpy.zeros([NITER_soAA, ntpnts, 3])

    res_m_soAB = numpy.zeros([NITER_soAB, ntpnts, 3])

    res_m_toA3 = numpy.zeros([NITER_toA3, ntpnts, 2])

    res_m_toA2B = numpy.zeros([NITER_toA2B, ntpnts, 3])

    res_m_so2d = numpy.zeros([NITER_so2d, ntpnts, 3])

    for i in range(0, NITER_max):
        sim.reset()

        if i < NITER_foi:
            sim.setCompCount('comp1', 'A_foi', N_foi)

        if i < NITER_for:
            sim.setCompCount('comp1', 'A_for', COUNT_for)
            sim.setCompCount('comp1', 'B_for', 0.0)

        if i < NITER_soA2:
            sim.setCompConc('comp1', 'A_soA2', CONCA_soA2)

        if i < NITER_soAA:
            sim.setCompConc('comp1', 'A_soAA', CONCA_soAA)
            sim.setCompConc('comp1', 'B_soAA', CONCB_soAA)

        if i < NITER_soAB:
            sim.setCompConc('comp1', 'A_soAB', CONCA_soAB)
            sim.setCompConc('comp1', 'B_soAB', CONCB_soAB)

        if i < NITER_toA3:
            sim.setCompConc('comp1', 'A_toA3', CONCA_toA3)

        if i < NITER_toA2B:
            sim.setCompConc('comp1', 'A_toA2B', CONCA_toA2B)
            sim.setCompConc('comp1', 'B_toA2B', CONCB_toA2B)

        if i < NITER_so2d:
            sim.setPatchCount('patch1', 'A_so2d', COUNTA_so2d)
            sim.setPatchCount('patch1', 'B_so2d', COUNTB_so2d)

        for t in range(0, ntpnts):
            sim.run(tpnts[t])

            if i < NITER_foi:
                res_m_foi[i, t, 0] = sim.getCompCount('comp1', 'A_foi')

            if i < NITER_for:
                res_m_for[i, t, 0] = sim.getCompConc('comp1', 'A_for') * 1e6
                res_m_for[i, t, 1] = sim.getCompConc('comp1', 'B_for') * 1e6

            if i < NITER_soA2:
                res_m_soA2[i, t, 0] = sim.getCompConc('comp1', 'A_soA2')

            if i < NITER_soAA:
                res_m_soAA[i, t, 0] = sim.getCompConc('comp1', 'A_soAA')
                res_m_soAA[i, t, 1] = sim.getCompConc('comp1', 'B_soAA')

            if i < NITER_soAB:
                res_m_soAB[i, t, 0] = sim.getCompConc('comp1', 'A_soAB')
                res_m_soAB[i, t, 1] = sim.getCompConc('comp1', 'B_soAB')

            if i < NITER_toA3:
                res_m_toA3[i, t, 0] = sim.getCompConc('comp1', 'A_toA3')

            if i < NITER_toA2B:
                res_m_toA2B[i, t, 0] = sim.getCompConc('comp1', 'A_toA2B')
                res_m_toA2B[i, t, 1] = sim.getCompConc('comp1', 'B_toA2B')
                res_m_toA2B[i, t, 2] = sim.getCompConc('comp1', 'C_toA2B')

            if i < NITER_so2d:
                res_m_so2d[i, t, 0] = sim.getPatchCount('patch1', 'A_so2d')
                res_m_so2d[i, t, 1] = sim.getPatchCount('patch1', 'B_so2d')

    global mean_res_foi, std_res_foi
    mean_res_foi = numpy.mean(res_m_foi, 0)
    std_res_foi = numpy.std(res_m_foi, 0)

    global mean_res_for
    mean_res_for = numpy.mean(res_m_for, 0)

    global mean_res_soA2
    mean_res_soA2 = numpy.mean(res_m_soA2, 0)

    global mean_res_soAA
    mean_res_soAA = numpy.mean(res_m_soAA, 0)

    global mean_res_soAB
    mean_res_soAB = numpy.mean(res_m_soAB, 0)

    global mean_res_toA3
    mean_res_toA3 = numpy.mean(res_m_toA3, 0)

    global mean_res_toA2B
    mean_res_toA2B = numpy.mean(res_m_toA2B, 0)

    global mean_res_so2d
    mean_res_so2d = numpy.mean(res_m_so2d, 0)

    global ran_sim
    ran_sim = True
Example #28
0
def test_masteqdiff():

    SCALE = 1.0

    KCST_f = 100e6 * SCALE  # The reaction constant, degradation
    KCST_b = (20.0e-10 * SCALE)  # The reaction constant, production

    DCST_A = 20e-12
    DCST_B = 20e-12

    B0 = 1  # The number of B moleucles

    DT = 0.1  # Sampling time-step
    INT = 50000.1  # Sim endtime

    filename = 'cube_1_1_1_73tets.inp'

    # A tolerance of 7.5% will fail <1% of the time
    tolerance = 7.5 / 100

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

    mdl = smod.Model()

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

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

    diffA = smod.Diff('diffA', volsys, A)
    diffA.setDcst(DCST_A)
    diffB = smod.Diff('diffB', volsys, B)
    diffB.setDcst(DCST_B)

    # Production
    R1 = smod.Reac('R1', volsys, lhs=[A, B], rhs=[B], kcst=KCST_f)
    R2 = smod.Reac('R2', volsys, lhs=[], rhs=[A], kcst=KCST_b)

    geom = meshio.loadMesh('./validation_rd/meshes/' + filename)[0]

    comp1 = sgeom.TmComp('comp1', geom, range(geom.ntets))
    comp1.addVolsys('vsys')

    rng = srng.create('mt19937', 512)
    rng.initialize(int(time.time() % 4294967295))

    sim = ssolv.Tetexact(mdl, geom, rng)
    sim.reset()

    tpnts = np.arange(0.0, INT, DT)
    ntpnts = tpnts.shape[0]

    res = np.zeros([ntpnts])
    res_std1 = np.zeros([ntpnts])
    res_std2 = np.zeros([ntpnts])

    sim.restore('./validation_cp/cp/masteq_diff')

    b_time = time.time()
    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 = np.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_f / 6.022e23
    k2 = KCST_b * 6.022e23
    v = comp1.getVol() * 1.0e3  # litres

    for m in range(5, 11):
        analy = (1.0 / fact(m)) * np.power(
            (k2 * v * v) / (B0 * k1), m) * np.exp(-((k2 * v * v) / (k1 * B0)))
        assert (tol_funcs.tolerable(steps_n_res[m], analy, tolerance))
Example #29
0
def test_kisilevich():
    "Reaction-diffusion - Degradation-diffusion (Parallel TetOpSplit)"

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

    DCSTA = 400 * 1e-12
    DCSTB = DCSTA
    RCST = 100000.0e6

    #NA0 = 100000    # 1000000            # Initial number of A molecules
    NA0 = 1000
    NB0 = NA0  # Initial number of B molecules

    SAMPLE = 1686

    # <1% fail with a tolerance of 7.5%
    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 barycentre distance to centre
    tetrads = numpy.zeros(SAMPLE)

    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)

    mesh = meshio.loadMesh('validation_rd_mpi/meshes/brick_40_4_4_1686tets')[0]

    VOLA = mesh.getMeshVolume() / 2.0
    VOLB = VOLA

    ntets = mesh.countTets()

    acomptets = []
    bcomptets = []
    max = mesh.getBoundMax()
    min = mesh.getBoundMax()
    midz = 0.0
    compatris = set()
    compbtris = set()
    for t in range(ntets):
        barycz = mesh.getTetBarycenter(t)[0]
        tris = mesh.getTetTriNeighb(t)
        if barycz < midz:
            acomptets.append(t)
            compatris.add(tris[0])
            compatris.add(tris[1])
            compatris.add(tris[2])
            compatris.add(tris[3])
        else:
            bcomptets.append(t)
            compbtris.add(tris[0])
            compbtris.add(tris[1])
            compbtris.add(tris[2])
            compbtris.add(tris[3])

    dbset = compatris.intersection(compbtris)
    dbtris = list(dbset)

    compa = sgeom.TmComp('compa', mesh, acomptets)
    compb = sgeom.TmComp('compb', mesh, bcomptets)
    compa.addVolsys('vsys')
    compb.addVolsys('vsys')

    diffb = sgeom.DiffBoundary('diffb', mesh, dbtris)

    # Now fill the array holding the tet indices to sample at random
    assert (SAMPLE <= ntets)

    numfilled = 0
    while (numfilled < SAMPLE):
        tetidxs[numfilled] = numfilled
        numfilled += 1

    # Now find the distance of the centre of the tets to the Z lower face
    for i in range(SAMPLE):
        baryc = mesh.getTetBarycenter(int(tetidxs[i]))
        r = baryc[0]
        tetrads[i] = r * 1.0e6

    Atets = acomptets
    Btets = bcomptets

    rng = srng.create('r123', 512)
    rng.initialize(1000)

    tet_hosts = gd.binTetsByAxis(mesh, steps.mpi.nhosts)
    sim = solvmod.TetOpSplit(mdl, mesh, rng, False, tet_hosts)

    tpnts = numpy.arange(0.0, INT, DT)
    ntpnts = tpnts.shape[0]

    resA = numpy.zeros((NITER, ntpnts, SAMPLE))
    resB = numpy.zeros((NITER, ntpnts, SAMPLE))

    for i in range(0, NITER):
        sim.reset()

        sim.setDiffBoundaryDiffusionActive('diffb', 'A', True)
        sim.setDiffBoundaryDiffusionActive('diffb', 'B', True)

        sim.setCompCount('compa', 'A', NA0)
        sim.setCompCount('compb', 'B', NB0)

        for t in range(0, ntpnts):
            sim.run(tpnts[t])
            for k in range(SAMPLE):
                resA[i, t, k] = sim.getTetCount(int(tetidxs[k]), 'A')
                resB[i, t, k] = sim.getTetCount(int(tetidxs[k]), 'B')

    itermeansA = numpy.mean(resA, axis=0)
    itermeansB = numpy.mean(resB, axis=0)

    def getdetc(t, x):
        N = 1000  # The number to represent infinity in the exponential calculation
        L = 20e-6

        concA = 0.0
        for n in range(N):
            concA += ((1.0 / (2 * n + 1)) * math.exp(
                (-(DCSTA / (20.0e-6)) * math.pow(
                    (2 * n + 1), 2) * math.pow(math.pi, 2) * t) / (4 * L)) *
                      math.sin(((2 * n + 1) * math.pi * x) / (2 * L)))
        concA *= ((4 * NA0 / math.pi) / (VOLA * 6.022e26)) * 1.0e6

        return concA

    tpnt_compare = [1, 2]
    passed = True
    max_err = 0.0

    for tidx in tpnt_compare:
        NBINS = 10
        radmax = 0.0
        radmin = 10.0
        for r in tetrads:
            if (r > radmax): radmax = r
            if (r < radmin): radmin = r

        rsec = (radmax - radmin) / NBINS
        binmins = numpy.zeros(NBINS + 1)
        tetradsbinned = numpy.zeros(NBINS)
        r = radmin
        bin_vols = numpy.zeros(NBINS)

        for b in range(NBINS + 1):
            binmins[b] = r
            if (b != NBINS): tetradsbinned[b] = r + rsec / 2.0
            r += rsec

        bin_countsA = [None] * NBINS
        bin_countsB = [None] * NBINS
        for i in range(NBINS):
            bin_countsA[i] = []
            bin_countsB[i] = []
        filled = 0

        for i in range(itermeansA[tidx].size):
            irad = tetrads[i]

            for b in range(NBINS):
                if (irad >= binmins[b] and irad < binmins[b + 1]):
                    bin_countsA[b].append(itermeansA[tidx][i])
                    bin_vols[b] += sim.getTetVol(int(tetidxs[i]))
                    filled += 1.0
                    break
        filled = 0
        for i in range(itermeansB[tidx].size):
            irad = tetrads[i]

            for b in range(NBINS):
                if (irad >= binmins[b] and irad < binmins[b + 1]):
                    bin_countsB[b].append(itermeansB[tidx][i])
                    filled += 1.0
                    break

        bin_concsA = numpy.zeros(NBINS)
        bin_concsB = numpy.zeros(NBINS)

        for c in range(NBINS):
            for d in range(bin_countsA[c].__len__()):
                bin_concsA[c] += bin_countsA[c][d]
            for d in range(bin_countsB[c].__len__()):
                bin_concsB[c] += bin_countsB[c][d]

            bin_concsA[c] /= (bin_vols[c])
            bin_concsA[c] *= (1.0e-3 / 6.022e23) * 1.0e6
            bin_concsB[c] /= (bin_vols[c])
            bin_concsB[c] *= (1.0e-3 / 6.022e23) * 1.0e6

        for i in range(NBINS):
            rad = abs(tetradsbinned[i]) * 1.0e-6

            if (tetradsbinned[i] < -5):
                # compare A
                det_conc = getdetc(tpnts[tidx], rad)
                steps_conc = bin_concsA[i]
                assert tol_funcs.tolerable(det_conc, steps_conc, tolerance)

            if (tetradsbinned[i] > 5):
                # compare B
                det_conc = getdetc(tpnts[tidx], rad)
                steps_conc = bin_concsB[i]
                assert tol_funcs.tolerable(det_conc, steps_conc, tolerance)
filename = 'cube_1_1_1_73tets.inp'

# A tolerance of 7.5% will fail <1% of the time
tolerance = 7.5/100

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

mdl  = smod.Model()

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

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

diffA = smod.Diff('diffA', volsys, A)
diffA.setDcst(DCST_A)
diffB = smod.Diff('diffB', volsys, B)
diffB.setDcst(DCST_B)

# Production
R1 = smod.Reac('R1', volsys, lhs = [A, B], rhs = [B], kcst = KCST_f)
R2 = smod.Reac('R2', volsys, lhs = [], rhs = [A], kcst = KCST_b)

geom = meshio.loadMesh('./validation_rd/meshes/'+filename)[0]

comp1 = sgeom.TmComp('comp1', geom, range(geom.ntets))
comp1.addVolsys('vsys')

rng = srng.create('mt19937', 512)
rng.initialize(int(time.time()%4294967295))