Ejemplo n.º 1
0
def build_model(mesh, param):
    mdl = smodel.Model()
    memb = sgeom.castToTmPatch(mesh.getPatch('memb'))

    ssys = smodel.Surfsys('ssys', mdl)
    memb.addSurfsys('ssys')

    L = smodel.Chan('L', mdl)
    Leak = smodel.ChanState('Leak', mdl, L)

    # membrane conductance
    area_cylinder = np.pi * param['diameter'] * param['length']
    L_G_tot = area_cylinder / param['R_M']
    g_leak_sc = L_G_tot / len(memb.tris)
    OC_L = smodel.OhmicCurr('OC_L', ssys, chanstate = Leak, erev = param['E_M'], g = g_leak_sc)

    return mdl
Ejemplo n.º 2
0
    def setUp(self):
        mdl = smodel.Model()

        S1 = smodel.Spec('S1', mdl)

        vsys = smodel.Volsys('vsys', mdl)
        ssys = smodel.Surfsys('ssys', mdl)

        smodel.Reac('R01', vsys, lhs=[S1], rhs=[S1], kcst=1)
        smodel.SReac('SR01', ssys, slhs=[S1], srhs=[S1], kcst=1)

        vrange = [-200.0e-3, 50e-3, 1e-3]
        vrate = lambda v: 2.0
        Chan1 = smodel.Chan('Chan1', mdl)
        chanop = smodel.ChanState('chanop', mdl, Chan1)
        chancl = smodel.ChanState('chancl', mdl, Chan1)
        smodel.VDepSReac('VDSR01',
                         ssys,
                         slhs=[chancl],
                         srhs=[chanop],
                         k=vrate,
                         vrange=vrange)
        smodel.VDepSReac('VDSR02',
                         ssys,
                         srhs=[chancl],
                         slhs=[chanop],
                         k=vrate,
                         vrange=vrange)

        Chan1_Ohm_I = smodel.OhmicCurr('Chan1_Ohm_I',
                                       ssys,
                                       chanstate=chanop,
                                       g=20e-12,
                                       erev=-77e-3)

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

        comp1 = sgeom.TmComp('comp1', self.mesh, range(self.mesh.countTets()))
        comp1.addVolsys('vsys')

        patch1 = sgeom.TmPatch('patch1', self.mesh, self.mesh.getSurfTris(),
                               comp1)
        patch1.addSurfsys('ssys')

        self.c1ROIInds = range(10)
        self.p1ROIInds = range(5)
        self.mesh.addROI('comp1ROI', sgeom.ELEM_TET, self.c1ROIInds)
        self.mesh.addROI('patch1ROI', sgeom.ELEM_TRI, self.p1ROIInds)

        membrane = sgeom.Memb('membrane', self.mesh, [patch1], opt_method=1)

        rng = srng.create('mt19937', 512)
        rng.initialize(1234)

        self.sim = ssolver.Tetexact(mdl, self.mesh, rng, True)
        self.sim.setEfieldDT(1e-4)

        self.sim.reset()
Ejemplo n.º 3
0
BKC1O1 = smodel.SReac('BKC1O1', ssys_det, slhs=[BK_C1], srhs=[BK_O1], kcst=0.0)
BKC2O2 = smodel.SReac('BKC2O2', ssys_det, slhs=[BK_C2], srhs=[BK_O2], kcst=0.0)
BKC3O3 = smodel.SReac('BKC3O3', ssys_det, slhs=[BK_C3], srhs=[BK_O3], kcst=0.0)
BKC4O4 = smodel.SReac('BKC4O4', ssys_det, slhs=[BK_C4], srhs=[BK_O4], kcst=0.0)

BKO0C0 = smodel.SReac('BKO0C0', ssys_det, slhs=[BK_O0], srhs=[BK_C0], kcst=0.0)
BKO1C1 = smodel.SReac('BKO1C1', ssys_det, slhs=[BK_O1], srhs=[BK_C1], kcst=0.0)
BKO2C2 = smodel.SReac('BKO2C2', ssys_det, slhs=[BK_O2], srhs=[BK_C2], kcst=0.0)
BKO3C3 = smodel.SReac('BKO3C3', ssys_det, slhs=[BK_O3], srhs=[BK_C3], kcst=0.0)
BKO4C4 = smodel.SReac('BKO4C4', ssys_det, slhs=[BK_O4], srhs=[BK_C4], kcst=0.0)

###### SK channel ################## DETERMINISTIC

SKchan = smodel.Chan('SKchan', mdl_stoch)

SK_C1 = smodel.ChanState('SK_C1', mdl_stoch, SKchan)
SK_C2 = smodel.ChanState('SK_C2', mdl_stoch, SKchan)
SK_C3 = smodel.ChanState('SK_C3', mdl_stoch, SKchan)
SK_C4 = smodel.ChanState('SK_C4', mdl_stoch, SKchan)
SK_O1 = smodel.ChanState('SK_O1', mdl_stoch, SKchan)
SK_O2 = smodel.ChanState('SK_O2', mdl_stoch, SKchan)

SKCAC1 = smodel.SReac('SKCAC1',
                      ssys_stoch,
                      slhs=[SK_C1],
                      ilhs=[Ca_stoch],
                      srhs=[SK_C2],
                      kcst=dirc2_t)
SKCAC2 = smodel.SReac('SKCAC2',
                      ssys_stoch,
                      slhs=[SK_C2],
Ejemplo n.º 4
0
if meshfile_ab == 'Cylinder2_dia2um_L160um_outer0_0.3shell_0.3size_279152tets_adaptive.inp':
    cyl160 = True
else:
    cyl160 = False

########################### BIOCHEMICAL MODEL ###############################

mdl = smodel.Model()

#surface systems (No need for a vol sys)
ssys = smodel.Surfsys('ssys', mdl)

# Potassium channel
Kchan = smodel.Chan('Kchan', mdl)
K_n0 = smodel.ChanState('K_n0', mdl, Kchan)
K_n1 = smodel.ChanState('K_n1', mdl, Kchan)
K_n2 = smodel.ChanState('K_n2', mdl, Kchan)
K_n3 = smodel.ChanState('K_n3', mdl, Kchan)
K_n4 = smodel.ChanState('K_n4', mdl, Kchan)


Kn0n1 = smodel.VDepSReac('Kn0n1', ssys, slhs = [K_n0], srhs = [K_n1], \
                            k=lambda V: 1.0e3 *4.*a_n(V*1.0e3)* Qt, vrange = Vrange)
Kn1n2 = smodel.VDepSReac('Kn1n2', ssys, slhs = [K_n1], srhs = [K_n2], \
                            k=lambda V: 1.0e3 *3.*a_n(V*1.0e3)* Qt, vrange = Vrange)
Kn2n3 = smodel.VDepSReac('Kn2n3', ssys, slhs = [K_n2], srhs = [K_n3], \
                            k=lambda V: 1.0e3 *2.*a_n(V*1.0e3)* Qt, vrange = Vrange)
Kn3n4 = smodel.VDepSReac('Kn3n4', ssys, slhs = [K_n3], srhs = [K_n4], \
                            k=lambda V: 1.0e3 *1.*a_n(V*1.0e3)* Qt, vrange = Vrange)
                     kcst=PVmg_f_kcst)
PVmg_b = smodel.Reac('PVmg_b',
                     vsys_det,
                     lhs=[PVMg],
                     rhs=[Mg, PV],
                     kcst=PVmg_b_kcst)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # CHANNELS  # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

###### CaP channel ##############

CaPchan = smodel.Chan('CaPchan', mdl_stoch)

CaP_m0 = smodel.ChanState('CaP_m0', mdl_stoch, CaPchan)
CaP_m1 = smodel.ChanState('CaP_m1', mdl_stoch, CaPchan)
CaP_m2 = smodel.ChanState('CaP_m2', mdl_stoch, CaPchan)
CaP_m3 = smodel.ChanState('CaP_m3', mdl_stoch, CaPchan)

CaPm0m1 = smodel.VDepSReac('CaPm0m1',
                           ssys_stoch,
                           slhs=[CaP_m0],
                           srhs=[CaP_m1],
                           k=lambda V: 1.0e3 * 3. * alpha_cap(V * 1.0e3) * Qt)
CaPm1m2 = smodel.VDepSReac('CaPm1m2',
                           ssys_stoch,
                           slhs=[CaP_m1],
                           srhs=[CaP_m2],
                           k=lambda V: 1.0e3 * 2. * alpha_cap(V * 1.0e3) * Qt)
CaPm2m3 = smodel.VDepSReac('CaPm2m3',
Ejemplo n.º 6
0
AMPAC1C = smodel.SReac('AMPAC1C', ssys_chans, slhs = [AMPA_C1], srhs = [AMPA_C], kcst = ru1)
AMPAC2C1 = smodel.SReac('AMPAC2C1', ssys_chans, slhs = [AMPA_C2], srhs = [AMPA_C1], kcst = ru2)
AMPAOC2 = smodel.SReac('AMPAOC2', ssys_chans, slhs = [AMPA_O], srhs = [AMPA_C2], kcst = rc)

AMPAD1 = smodel.SReac('AMPAD1', ssys_chans, slhs = [AMPA_C1], srhs = [AMPA_D1], kcst = rd)
AMPAD2 = smodel.SReac('AMPAD2', ssys_chans, slhs = [AMPA_C2], srhs = [AMPA_D2], kcst = rd)

AMPARD1 = smodel.SReac('AMPARD1', ssys_chans, slhs = [AMPA_D1], srhs = [AMPA_C1], kcst = rr)
AMPARD2 = smodel.SReac('AMPARD2', ssys_chans, slhs = [AMPA_D2], srhs = [AMPA_C2], kcst = rr)


###### Leak current channel #####

L = smodel.Chan('L', mdl_stoch)
Leak = smodel.ChanState('Leak', mdl_stoch, L)

OC_L = smodel.OhmicCurr('OC_L', ssys_stoch, chanstate = Leak, erev = L_rev, g = L_G)


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

########### MESH & COMPARTMENTALIZATION #################

##########Import Mesh for EField calculation

# For stochastic sim:

meshfile_ab = 'chop_mesh.inp'
Ejemplo n.º 7
0
Ra = 235.7 * 1.0e-2

# Calcium channel
Ca = smodel.Spec('Ca', model)
# Ca_Ch = smodel.Spec('Ca_Ch', model)
# Ca_sens = smodel.Spec('Ca_sens', model)
# Ca_sens_b = smodel.Spec('Ca_sens_b', model)

Ca.setValence(2)
Ca_oconc = 2e-3

CaP_P = 0.5e-20  # permeability of a single channel (m3/s) HERE IS A PROBLEM (3.72 pS)
CaP_ro = 5 * 3.8e13  # density per square meter

CaPchan = smodel.Chan('CaPchan', model)
CaP_m0 = smodel.ChanState('CaP_m0', model, CaPchan)
CaP_m1 = smodel.ChanState('CaP_m1', model, CaPchan)
CaP_m2 = smodel.ChanState('CaP_m2', model, CaPchan)
CaP_m3 = smodel.ChanState('CaP_m3', model, CaPchan)

CaP_m0_p = 0.92402
CaP_m1_p = 0.073988
CaP_m2_p = 0.0019748
CaP_m3_p = 1.7569e-05

#Units (mV)
vhalfm = -29.458
cvm = 8.429


def minf_cap(V):
Ejemplo n.º 8
0
                     kcst=PVmg_f_kcst)
PVmg_b = smodel.Reac('PVmg_b',
                     vsys,
                     lhs=[PVMg],
                     rhs=[Mg, PV],
                     kcst=PVmg_b_kcst)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # CHANNELS  # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

###### CaP channel ##############

CaPchan = smodel.Chan('CaPchan', mdl)

CaP_m0 = smodel.ChanState('CaP_m0', mdl, CaPchan)
CaP_m1 = smodel.ChanState('CaP_m1', mdl, CaPchan)
CaP_m2 = smodel.ChanState('CaP_m2', mdl, CaPchan)
CaP_m3 = smodel.ChanState('CaP_m3', mdl, CaPchan)

CaPm0m1 = smodel.VDepSReac('CaPm0m1',
                           ssys,
                           slhs=[CaP_m0],
                           srhs=[CaP_m1],
                           k=lambda V: 1.0e3 * 3. * alpha_cap(V * 1.0e3) * Qt)
CaPm1m2 = smodel.VDepSReac('CaPm1m2',
                           ssys,
                           slhs=[CaP_m1],
                           srhs=[CaP_m2],
                           k=lambda V: 1.0e3 * 2. * alpha_cap(V * 1.0e3) * Qt)
CaPm2m3 = smodel.VDepSReac('CaPm2m3',
Ejemplo n.º 9
0
# The number of sim 'time points'; * SIM_DT = sim end time
SIM_NTPNTS = int(SIM_END / SIM_DT) + 1

# # # # # # # # # # # # # DATA COLLECTION # # # # # # # # # # # # # # # # # #

# Length of the mesh, in m
LENGTH = 1000.0e-6

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

mdl = smodel.Model()
ssys = smodel.Surfsys('ssys', mdl)

L = smodel.Chan('L', mdl)
Leak = smodel.ChanState('Leak', mdl, L)

mesh = meshio.loadMesh('meshes/' + meshfile)[0]

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

# Find the tets connected to the bottom face
# First find all the tets with ONE face on a boundary
boundtets = []
#store the 0to3 index of the surface triangle for each of these boundary tets
bt_srftriidx = []

for i in range(mesh.ntets):
    tettemp = mesh.getTetTetNeighb(i)
    if (tettemp[0] == -1 or tettemp[1] == -1 or tettemp[2] == -1
            or tettemp[3] == -1):
Ejemplo n.º 10
0
def test_rallpack3():
    print("Rallpack 3 with TetODE")
    #meshfile ='axon_cube_L1000um_D866m_600tets'
    meshfile = 'axon_cube_L1000um_D866m_1135tets'
    #meshfile = 'axon_cube_L1000um_D866nm_1978tets'

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

    # Potassium conductance, Siemens/m^2
    K_G = 360
    # Sodium conductance, Siemens/m^2
    Na_G = 1200
    # Leak conductance, Siemens/m^2
    L_G = 0.25

    # Potassium reversal potential, V
    K_rev = -77e-3
    # Sodium reversal potential, V
    Na_rev = 50e-3
    # Leak reveral potential, V
    leak_rev = -65.0e-3

    # Potassium channel density
    K_ro = 18.0e12
    # Sodium channel density
    Na_ro = 60.0e12

    # Total leak conductance for ideal cylinder:
    surfarea_cyl = 1.0 * np.pi * 1000 * 1e-12
    L_G_tot = L_G * surfarea_cyl

    # A table of potassium density factors at -65mV, found in getpops. n0, n1, n2, n3, n4
    K_FACS = [0.216750577045, 0.40366011853, 0.281904943772, \
                0.0874997924409, 0.0101845682113 ]

    # A table of sodium density factors. m0h1, m1h1, m2h1, m3h1, m0h0, m1h0, m2h0, m3h0
    NA_FACS = [0.343079175644, 0.0575250437508, 0.00321512825945, 5.98988373918e-05, \
                0.506380603793, 0.0849062503811, 0.00474548939393, 8.84099403236e-05]

    # Ohm.m
    Ra = 1.0

    # # # # # # # # # # # # # # # # SIMULATION CONTROLS # # # # # # # # # # # # # #

    # The simulation dt (seconds); for TetODE this is equivalent to EField dt
    SIM_DT = 5.0e-6

    # Sim end time (seconds)
    SIM_END = 0.1

    # The number of sim 'time points'; * SIM_DT = sim end time
    SIM_NTPNTS = int(SIM_END / SIM_DT) + 1

    # The current injection in amps
    Iinj = 0.1e-9

    # # # # # # # # # # # # # DATA COLLECTION # # # # # # # # # # # # # # # # # #

    # record potential at the two extremes along (z) axis
    POT_POS = np.array([0.0, 1.0e-03])

    POT_N = len(POT_POS)

    # Length of the mesh, in m
    LENGTH = 1000.0e-6

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

    mdl = smodel.Model()
    ssys = smodel.Surfsys('ssys', mdl)

    # K channel
    K = smodel.Chan('K', mdl)
    K_n0 = smodel.ChanState('K_n0', mdl, K)
    K_n1 = smodel.ChanState('K_n1', mdl, K)
    K_n2 = smodel.ChanState('K_n2', mdl, K)
    K_n3 = smodel.ChanState('K_n3', mdl, K)
    K_n4 = smodel.ChanState('K_n4', mdl, K)

    # Na channel
    Na = smodel.Chan('Na', mdl)
    Na_m0h1 = smodel.ChanState('Na_m0h1', mdl, Na)
    Na_m1h1 = smodel.ChanState('Na_m1h1', mdl, Na)
    Na_m2h1 = smodel.ChanState('Na_m2h1', mdl, Na)
    Na_m3h1 = smodel.ChanState('Na_m3h1', mdl, Na)
    Na_m0h0 = smodel.ChanState('Na_m0h0', mdl, Na)
    Na_m1h0 = smodel.ChanState('Na_m1h0', mdl, Na)
    Na_m2h0 = smodel.ChanState('Na_m2h0', mdl, Na)
    Na_m3h0 = smodel.ChanState('Na_m3h0', mdl, Na)

    # Leak
    L = smodel.Chan('L', mdl)
    Leak = smodel.ChanState('Leak', mdl, L)

    # Gating kinetics
    _a_m = lambda mV: ((((0.1 * (25 - (mV + 65.)) / (np.exp(
        (25 - (mV + 65.)) / 10.) - 1)))))
    _b_m = lambda mV: ((((4. * np.exp(-((mV + 65.) / 18.))))))
    _a_h = lambda mV: ((((0.07 * np.exp((-(mV + 65.) / 20.))))))
    _b_h = lambda mV: ((((1. / (np.exp((30 - (mV + 65.)) / 10.) + 1)))))
    _a_n = lambda mV: ((((0.01 * (10 - (mV + 65.)) / (np.exp(
        (10 - (mV + 65.)) / 10.) - 1)))))
    _b_n = lambda mV: ((((0.125 * np.exp(-(mV + 65.) / 80.)))))

    Kn0n1 = smodel.VDepSReac('Kn0n1',
                             ssys,
                             slhs=[K_n0],
                             srhs=[K_n1],
                             k=lambda V: 1.0e3 * 4. * _a_n(V * 1.0e3))
    Kn1n2 = smodel.VDepSReac('Kn1n2',
                             ssys,
                             slhs=[K_n1],
                             srhs=[K_n2],
                             k=lambda V: 1.0e3 * 3. * _a_n(V * 1.0e3))
    Kn2n3 = smodel.VDepSReac('Kn2n3',
                             ssys,
                             slhs=[K_n2],
                             srhs=[K_n3],
                             k=lambda V: 1.0e3 * 2. * _a_n(V * 1.0e3))
    Kn3n4 = smodel.VDepSReac('Kn3n4',
                             ssys,
                             slhs=[K_n3],
                             srhs=[K_n4],
                             k=lambda V: 1.0e3 * 1. * _a_n(V * 1.0e3))

    Kn4n3 = smodel.VDepSReac('Kn4n3',
                             ssys,
                             slhs=[K_n4],
                             srhs=[K_n3],
                             k=lambda V: 1.0e3 * 4. * _b_n(V * 1.0e3))
    Kn3n2 = smodel.VDepSReac('Kn3n2',
                             ssys,
                             slhs=[K_n3],
                             srhs=[K_n2],
                             k=lambda V: 1.0e3 * 3. * _b_n(V * 1.0e3))
    Kn2n1 = smodel.VDepSReac('Kn2n1',
                             ssys,
                             slhs=[K_n2],
                             srhs=[K_n1],
                             k=lambda V: 1.0e3 * 2. * _b_n(V * 1.0e3))
    Kn1n0 = smodel.VDepSReac('Kn1n0',
                             ssys,
                             slhs=[K_n1],
                             srhs=[K_n0],
                             k=lambda V: 1.0e3 * 1. * _b_n(V * 1.0e3))

    Na_m0h1_m1h1 = smodel.VDepSReac('Na_m0h1_m1h1',
                                    ssys,
                                    slhs=[Na_m0h1],
                                    srhs=[Na_m1h1],
                                    k=lambda V: 1.0e3 * 3. * _a_m(V * 1.0e3))
    Na_m1h1_m2h1 = smodel.VDepSReac('Na_m1h1_m2h1',
                                    ssys,
                                    slhs=[Na_m1h1],
                                    srhs=[Na_m2h1],
                                    k=lambda V: 1.0e3 * 2. * _a_m(V * 1.0e3))
    Na_m2h1_m3h1 = smodel.VDepSReac('Na_m2h1_m3h1',
                                    ssys,
                                    slhs=[Na_m2h1],
                                    srhs=[Na_m3h1],
                                    k=lambda V: 1.0e3 * 1. * _a_m(V * 1.0e3))

    Na_m3h1_m2h1 = smodel.VDepSReac('Na_m3h1_m2h1',
                                    ssys,
                                    slhs=[Na_m3h1],
                                    srhs=[Na_m2h1],
                                    k=lambda V: 1.0e3 * 3. * _b_m(V * 1.0e3))
    Na_m2h1_m1h1 = smodel.VDepSReac('Na_m2h1_m1h1',
                                    ssys,
                                    slhs=[Na_m2h1],
                                    srhs=[Na_m1h1],
                                    k=lambda V: 1.0e3 * 2. * _b_m(V * 1.0e3))
    Na_m1h1_m0h1 = smodel.VDepSReac('Na_m1h1_m0h1',
                                    ssys,
                                    slhs=[Na_m1h1],
                                    srhs=[Na_m0h1],
                                    k=lambda V: 1.0e3 * 1. * _b_m(V * 1.0e3))

    Na_m0h0_m1h0 = smodel.VDepSReac('Na_m0h0_m1h0',
                                    ssys,
                                    slhs=[Na_m0h0],
                                    srhs=[Na_m1h0],
                                    k=lambda V: 1.0e3 * 3. * _a_m(V * 1.0e3))
    Na_m1h0_m2h0 = smodel.VDepSReac('Na_m1h0_m2h0',
                                    ssys,
                                    slhs=[Na_m1h0],
                                    srhs=[Na_m2h0],
                                    k=lambda V: 1.0e3 * 2. * _a_m(V * 1.0e3))
    Na_m2h0_m3h0 = smodel.VDepSReac('Na_m2h0_m3h0',
                                    ssys,
                                    slhs=[Na_m2h0],
                                    srhs=[Na_m3h0],
                                    k=lambda V: 1.0e3 * 1. * _a_m(V * 1.0e3))

    Na_m3h0_m2h0 = smodel.VDepSReac('Na_m3h0_m2h0',
                                    ssys,
                                    slhs=[Na_m3h0],
                                    srhs=[Na_m2h0],
                                    k=lambda V: 1.0e3 * 3. * _b_m(V * 1.0e3))
    Na_m2h0_m1h0 = smodel.VDepSReac('Na_m2h0_m1h0',
                                    ssys,
                                    slhs=[Na_m2h0],
                                    srhs=[Na_m1h0],
                                    k=lambda V: 1.0e3 * 2. * _b_m(V * 1.0e3))
    Na_m1h0_m0h0 = smodel.VDepSReac('Na_m1h0_m0h0',
                                    ssys,
                                    slhs=[Na_m1h0],
                                    srhs=[Na_m0h0],
                                    k=lambda V: 1.0e3 * 1. * _b_m(V * 1.0e3))

    Na_m0h1_m0h0 = smodel.VDepSReac('Na_m0h1_m0h0',
                                    ssys,
                                    slhs=[Na_m0h1],
                                    srhs=[Na_m0h0],
                                    k=lambda V: 1.0e3 * _a_h(V * 1.0e3))
    Na_m1h1_m1h0 = smodel.VDepSReac('Na_m1h1_m1h0',
                                    ssys,
                                    slhs=[Na_m1h1],
                                    srhs=[Na_m1h0],
                                    k=lambda V: 1.0e3 * _a_h(V * 1.0e3))
    Na_m2h1_m2h0 = smodel.VDepSReac('Na_m2h1_m2h0',
                                    ssys,
                                    slhs=[Na_m2h1],
                                    srhs=[Na_m2h0],
                                    k=lambda V: 1.0e3 * _a_h(V * 1.0e3))
    Na_m3h1_m3h0 = smodel.VDepSReac('Na_m3h1_m3h0',
                                    ssys,
                                    slhs=[Na_m3h1],
                                    srhs=[Na_m3h0],
                                    k=lambda V: 1.0e3 * _a_h(V * 1.0e3))

    Na_m0h0_m0h1 = smodel.VDepSReac('Na_m0h0_m0h1',
                                    ssys,
                                    slhs=[Na_m0h0],
                                    srhs=[Na_m0h1],
                                    k=lambda V: 1.0e3 * _b_h(V * 1.0e3))
    Na_m1h0_m1h1 = smodel.VDepSReac('Na_m1h0_m1h1',
                                    ssys,
                                    slhs=[Na_m1h0],
                                    srhs=[Na_m1h1],
                                    k=lambda V: 1.0e3 * _b_h(V * 1.0e3))
    Na_m2h0_m2h1 = smodel.VDepSReac('Na_m2h0_m2h1',
                                    ssys,
                                    slhs=[Na_m2h0],
                                    srhs=[Na_m2h1],
                                    k=lambda V: 1.0e3 * _b_h(V * 1.0e3))
    Na_m3h0_m3h1 = smodel.VDepSReac('Na_m3h0_m3h1',
                                    ssys,
                                    slhs=[Na_m3h0],
                                    srhs=[Na_m3h1],
                                    k=lambda V: 1.0e3 * _b_h(V * 1.0e3))

    OC_K = smodel.OhmicCurr('OC_K',
                            ssys,
                            chanstate=K_n4,
                            erev=K_rev,
                            g=K_G / K_ro)
    OC_Na = smodel.OhmicCurr('OC_Na',
                             ssys,
                             chanstate=Na_m3h0,
                             erev=Na_rev,
                             g=Na_G / Na_ro)

    # Mesh geometry
    mesh = meshio.loadMesh('validation_efield/meshes/' + meshfile)[0]

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

    # The tetrahedrons from which to record potential
    POT_TET = np.zeros(POT_N, dtype='uint')

    i = 0
    for p in POT_POS:
        # Assuming axiz aligned with z-axis
        POT_TET[i] = mesh.findTetByPoint([0.0, 0.0, POT_POS[i]])
        i = i + 1

    # Find the tets connected to the bottom face
    # First find all the tets with ONE face on a boundary
    boundtets = []
    #store the 0to3 index of the surface triangle for each of these boundary tets
    bt_srftriidx = []

    for i in range(mesh.ntets):
        tettemp = mesh.getTetTetNeighb(i)
        if (tettemp[0] == -1 or tettemp[1] == -1 or tettemp[2] == -1
                or tettemp[3] == -1):
            boundtets.append(i)
            templist = []
            if (tettemp[0] == -1):
                templist.append(0)
            if (tettemp[1] == -1):
                templist.append(1)
            if (tettemp[2] == -1):
                templist.append(2)
            if (tettemp[3] == -1):
                templist.append(3)
            bt_srftriidx.append(templist)

    assert (boundtets.__len__() == bt_srftriidx.__len__())

    # Find the tets on the z=0 and z=1000um boundaries, and the triangles
    minztets = []
    minztris = []
    maxztris = []
    minzverts = set([])

    boundminz = mesh.getBoundMin()[2] + LENGTH / mesh.ntets
    boundmaxz = mesh.getBoundMax()[2] - LENGTH / mesh.ntets

    for i in range(boundtets.__len__()):
        # get the boundary triangle
        for btriidx in bt_srftriidx[i]:
            zminboundtri = True
            tribidx = mesh.getTetTriNeighb(boundtets[i])[btriidx]
            tritemp = mesh.getTri(tribidx)
            trizs = [0.0, 0.0, 0.0]
            trizs[0] = mesh.getVertex(tritemp[0])[2]
            trizs[1] = mesh.getVertex(tritemp[1])[2]
            trizs[2] = mesh.getVertex(tritemp[2])[2]
            for j in range(3):
                if (trizs[j] > boundminz): zminboundtri = False
            if (zminboundtri):
                minztets.append(boundtets[i])
                minztris.append(tribidx)
                minzverts.add(tritemp[0])
                minzverts.add(tritemp[1])
                minzverts.add(tritemp[2])
                continue

            zmaxboundtri = True
            for j in range(3):
                if (trizs[j] < boundmaxz): zmaxboundtri = False
            if (zmaxboundtri):
                maxztris.append(tribidx)

    n_minztris = len(minztris)
    assert (n_minztris > 0)
    minzverts = list(minzverts)
    n_minzverts = len(minzverts)
    assert (n_minzverts > 0)

    memb_tris = list(mesh.getSurfTris())

    # Doing this now, so will inject into first little z section
    for t in minztris:
        memb_tris.remove(t)
    for t in maxztris:
        memb_tris.remove(t)

    # Create the membrane with the tris removed at faces
    memb = sgeom.TmPatch('memb', mesh, memb_tris, cyto)
    memb.addSurfsys('ssys')

    membrane = sgeom.Memb('membrane',
                          mesh, [memb],
                          opt_method=2,
                          search_percent=100.0)

    # Set the single-channel conductance:
    g_leak_sc = L_G_tot / len(memb_tris)
    OC_L = smodel.OhmicCurr('OC_L',
                            ssys,
                            chanstate=Leak,
                            erev=leak_rev,
                            g=g_leak_sc)

    # Create the solver objects
    sim = ssolver.TetODE(mdl, mesh, calcMembPot=True)
    sim.setTolerances(1.0e-6, 1e-6)

    surfarea_mesh = sim.getPatchArea('memb')
    surfarea_cyl = 1.0 * np.pi * 1000 * 1e-12
    corr_fac_area = surfarea_mesh / surfarea_cyl

    vol_cyl = np.pi * 0.5 * 0.5 * 1000 * 1e-18
    vol_mesh = sim.getCompVol('cyto')
    corr_fac_vol = vol_mesh / vol_cyl

    RES_POT = np.zeros((SIM_NTPNTS, POT_N))

    for t in memb_tris:
        sim.setTriCount(t, 'Leak', 1)

    sim.setPatchCount('memb', 'Na_m0h1', (Na_ro * surfarea_cyl * NA_FACS[0]))
    sim.setPatchCount('memb', 'Na_m1h1', (Na_ro * surfarea_cyl * NA_FACS[1]))
    sim.setPatchCount('memb', 'Na_m2h1', (Na_ro * surfarea_cyl * NA_FACS[2]))
    sim.setPatchCount('memb', 'Na_m3h1', (Na_ro * surfarea_cyl * NA_FACS[3]))
    sim.setPatchCount('memb', 'Na_m0h0', (Na_ro * surfarea_cyl * NA_FACS[4]))
    sim.setPatchCount('memb', 'Na_m1h0', (Na_ro * surfarea_cyl * NA_FACS[5]))
    sim.setPatchCount('memb', 'Na_m2h0', (Na_ro * surfarea_cyl * NA_FACS[6]))
    sim.setPatchCount('memb', 'Na_m3h0', (Na_ro * surfarea_cyl * NA_FACS[7]))
    sim.setPatchCount('memb', 'K_n0', (K_ro * surfarea_cyl * K_FACS[0]))
    sim.setPatchCount('memb', 'K_n1', (K_ro * surfarea_cyl * K_FACS[1]))
    sim.setPatchCount('memb', 'K_n2', (K_ro * surfarea_cyl * K_FACS[2]))
    sim.setPatchCount('memb', 'K_n3', (K_ro * surfarea_cyl * K_FACS[3]))
    sim.setPatchCount('memb', 'K_n4', (K_ro * surfarea_cyl * K_FACS[4]))

    sim.setMembPotential('membrane', -65e-3)
    sim.setMembVolRes('membrane', Ra * corr_fac_vol)
    sim.setMembCapac('membrane', 0.01 / corr_fac_area)

    for v in minzverts:
        sim.setVertIClamp(v, Iinj / n_minzverts)

    for l in range(SIM_NTPNTS):

        sim.run(SIM_DT * l)

        for p in range(POT_N):
            RES_POT[l, p] = sim.getTetV(int(POT_TET[p])) * 1.0e3

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

    # Benchmark
    # At 0um- the end of the mesh
    ifile_benchmark_x0 = open(
        'validation_efield/data/rallpack3_benchmark/rallpack3_0_0.001dt_1000seg',
        'r')

    # At 1000um- the end of the mesh
    ifile_benchmark_x1000 = open(
        'validation_efield/data/rallpack3_benchmark/rallpack3_1000_0.001dt_1000seg',
        'r')

    tpnt_benchmark = []
    v_benchmark_x0 = []
    v_benchmark_x1000 = []

    lines_benchmark_x0 = ifile_benchmark_x0.readlines()[2:]

    # Read in mv and ms
    for line_benchmark_x0 in lines_benchmark_x0:
        nums = line_benchmark_x0.split()
        tpnt_benchmark.append(float(nums[0]))
        v_benchmark_x0.append(float(nums[1]))

    lines_benchmark_x1000 = ifile_benchmark_x1000.readlines()[2:]

    for line_benchmark_x1000 in lines_benchmark_x1000:
        nums = line_benchmark_x1000.split()
        v_benchmark_x1000.append(float(nums[1]))

    # Get rid of the last point which seems to be missing from STEPS
    v_benchmark_x0 = v_benchmark_x0[:-1]
    tpnt_benchmark = tpnt_benchmark[:-1]
    v_benchmark_x1000 = v_benchmark_x1000[:-1]

    rms0 = stats(v_benchmark_x0, RES_POT[:, 0])
    assert (rms0 < 0.15)
    rms1000 = stats(v_benchmark_x1000, RES_POT[:, 1])
    assert (rms1000 < 1.1)
Ejemplo n.º 11
0
CaTm1h1_m1h0 = smodel.SReac('CaTm1h1_m1h0',
                            ssys_det,
                            slhs=[CaT_m1h1],
                            srhs=[CaT_m1h0],
                            kcst=0.0)
CaTm0h1_m0h0 = smodel.SReac('CaTm0h1_m0h0',
                            ssys_det,
                            slhs=[CaT_m0h1],
                            srhs=[CaT_m0h0],
                            kcst=0.0)

##### BK channel ####################

BKchan = smodel.Chan('BKchan', mdl_stoch)

BK_C0 = smodel.ChanState('BK_C0', mdl_stoch, BKchan)
BK_C1 = smodel.ChanState('BK_C1', mdl_stoch, BKchan)
BK_C2 = smodel.ChanState('BK_C2', mdl_stoch, BKchan)
BK_C3 = smodel.ChanState('BK_C3', mdl_stoch, BKchan)
BK_C4 = smodel.ChanState('BK_C4', mdl_stoch, BKchan)
BK_O0 = smodel.ChanState('BK_O0', mdl_stoch, BKchan)
BK_O1 = smodel.ChanState('BK_O1', mdl_stoch, BKchan)
BK_O2 = smodel.ChanState('BK_O2', mdl_stoch, BKchan)
BK_O3 = smodel.ChanState('BK_O3', mdl_stoch, BKchan)
BK_O4 = smodel.ChanState('BK_O4', mdl_stoch, BKchan)

BKCAC0 = smodel.SReac('BKCAC0',
                      ssys_stoch,
                      slhs=[BK_C0],
                      ilhs=[Ca_stoch],
                      srhs=[BK_C1],
Ejemplo n.º 12
0
CaPm2m1 = smodel.SReac('CaPm2m1',
                       ssys_det,
                       slhs=[CaP_m2],
                       srhs=[CaP_m1],
                       kcst=0.0)
CaPm1m0 = smodel.SReac('CaPm1m0',
                       ssys_det,
                       slhs=[CaP_m1],
                       srhs=[CaP_m0],
                       kcst=0.0)

######## CaT channel ##########

CaTchan = smodel.Chan('CaTchan', mdl_stoch)

CaT_m0h0 = smodel.ChanState('CaT_m0h0', mdl_stoch, CaTchan)
CaT_m0h1 = smodel.ChanState('CaT_m0h1', mdl_stoch, CaTchan)
CaT_m1h0 = smodel.ChanState('CaT_m1h0', mdl_stoch, CaTchan)
CaT_m1h1 = smodel.ChanState('CaT_m1h1', mdl_stoch, CaTchan)
CaT_m2h0 = smodel.ChanState('CaT_m2h0', mdl_stoch, CaTchan)
CaT_m2h1 = smodel.ChanState('CaT_m2h1', mdl_stoch, CaTchan)

CaTm0h0_m1h0 = smodel.VDepSReac('CaTm0h0_m1h0',
                                ssys_stoch,
                                slhs=[CaT_m0h0],
                                srhs=[CaT_m1h0],
                                k=lambda V: 1.0e3 * 2. * alpham_cat(V * 1.0e3))
CaTm1h0_m2h0 = smodel.VDepSReac('CaTm1h0_m2h0',
                                ssys_stoch,
                                slhs=[CaT_m1h0],
                                srhs=[CaT_m2h0],