def _addParameters(self, params): from .. import sim for label, param in params.items(): # regions if 'regions' not in param: print( ' Error creating State %s: "regions" parameter was missing' % (label)) continue if not isinstance(param['regions'], list): param['regions'] = [param['regions']] try: nrnRegions = [ self.rxd['regions'][region]['hObj'] for region in param['regions'] ] except: print(' Error creating State %s: could not find regions %s' % (label, param['regions'])) if 'name' not in param: param['name'] = None if 'charge' not in param: param['charge'] = 0 if 'value' not in param: param['value'] = 0 if isinstance(param['value'], basestring): funcStr = self._replaceRxDStr(param['value'], constants=True, regions=True, species=True) # create final function dynamically from string importStr = ' from neuron import crxd as rxd \n from netpyne import sim' afterDefStr = 'sim.net.rxd["parameters"]["%s"]["initialFunc"] = value' % ( label) funcStr = 'def value (node): \n%s \n return %s \n%s' % ( importStr, funcStr, afterDefStr) # convert to lambda function try: exec(funcStr, {'rxd': rxd}, {'sim': sim}) value = sim.net.rxd["parameters"][label]["initialFunc"] except: print( ' Error creating Parameter %s: cannot evaluate "value" expression -- "%s"' % (label, param['value'])) continue else: value = param['value'] # call rxd method to create Region self.rxd['parameters'][label]['hObj'] = rxd.Parameter( regions=nrnRegions, value=value, charge=param['charge'], name=param['name']) print(' Created Parameter %s' % (label))
# Who? x = rxd.Species( [cyt, org, cyt_org_membrane, cyt_ecs_membrane, ecs], name="x", d=1.0, charge=1, initial=0, ) Xcyt = x[cyt] Xorg = x[org] Xecs = x[ecs] # What? - produce X in cell 1 # parameter to limit production to cell 1 cell1_param = rxd.Parameter(org, initial=lambda node: 1.0 if node.segment.sec == cell1 else 0) # production with a rate following Michaels Menton kinetics createX = rxd.Rate(Xorg, cell1_param[org] * 1.0 / (10.0 + Xorg)) # leak between organelles and cytosol cyt_org_leak = rxd.MultiCompartmentReaction(Xcyt, Xorg, 1e4, 1e4, membrane=cyt_org_membrane, membrane_flux=False) from math import pi e = 1.60217662e-19
d=1e3, charge=1, initial=init(10.0, 140.0), ecs_boundary_conditions=140) x = rxd.Species([cyt, mem, ecs], name='x', charge=1) ki, ko, nai, nao, xi, xo = k[cyt], k[ecs], na[cyt], na[ecs], x[cyt], x[ecs] # gates ngate = rxd.State([cyt, mem], name='ngate', initial=0.24458654944007166) mgate = rxd.State([cyt, mem], name='mgate', initial=0.028905534475191907) hgate = rxd.State([cyt, mem], name='hgate', initial=0.7540796658225246) # somaA parameter pA = rxd.Parameter([cyt, mem], name='paramA', initial=lambda nd: 1 if nd.segment in somaA else 0) #What # gates m_gate = rxd.Rate(mgate, (minf - mgate) / mtau) h_gate = rxd.Rate(hgate, (hinf - hgate) / htau) n_gate = rxd.Rate(ngate, (ninf - ngate) / ntau) # Nernst potentials ena = 1e3 * h.R * (h.celsius + 273.15) * log(nao / nai) / h.FARADAY ek = 1e3 * h.R * (h.celsius + 273.15) * log(ko / ki) / h.FARADAY gna = pA * gnabar * mgate**3 * hgate gk = pA * gkbar * ngate**4
def Declare_Parameters(**kwargs): """helper function enabling clean declaration of parameters in top namespace""" for key, value in kwargs.items(): globals()[key] = rxd.Parameter(r, name=key, initial=value)
from neuron import h, crxd as rxd h.load_file("stdrun.hoc") cell = h.Section(name="cell") r = rxd.Region([cell]) def Declare_Parameters(**kwargs): """helper function enabling clean declaration of parameters in top namespace""" for key, value in kwargs.items(): globals()[key] = rxd.Parameter(r, name=key, initial=value) def Declare_Species(**kwargs): """helper function enabling clean declaration of species in top namespace""" for key, value in kwargs.items(): globals()[key] = rxd.Species(r, name=key, initial=value) k3 = rxd.Parameter(r, name="k3", initial=1.2) k4 = rxd.Parameter(r, name="k4", initial=0.6) P2 = rxd.Species(r, name="P2", initial=0.0614368) T2 = rxd.Species(r, name="T2", initial=0.0145428) C = rxd.Species(r, name="C", initial=0.207614) h.finitialize(-65) h.continuerun(72)
cyt = rxd.Region(h.allsec(), name='cyt', nrn_region='i') # membrane mem = rxd.Region(h.allsec(), name='cell_mem', geometry=rxd.membrane()) # extracellular ecs = rxd.Extracellular(-100, -100, -100, 100, 100, 100, dx=33) # Who? ions & gates # intracellular sodium & potassium na = rxd.Species([cyt, mem], name='na', d=1, charge=1, initial=10) k = rxd.Species([cyt, mem], name='k', d=1, charge=1, initial=54.4) # extracellular parameters provide a constant concentration for the Nernst potential and reactions. kecs = rxd.Parameter(ecs, name='k_ecs', charge=1, value=2.5) naecs = rxd.Parameter(ecs, name='na_ecs', charge=1, value=140) # an undistinguished charged ion for the leak current x = rxd.Species([cyt, mem, ecs], name='x', charge=1) # define the various species and parameters on the intracellular and extracellular regions ki, ko, nai, nao, xi, xo = k[cyt], kecs[ecs], na[cyt], naecs[ecs], x[cyt], x[ ecs] # the gating states ngate = rxd.State([cyt, mem], name='ngate', initial=0.24458654944007166) mgate = rxd.State([cyt, mem], name='mgate', initial=0.028905534475191907) hgate = rxd.State([cyt, mem], name='hgate', initial=0.7540796658225246) # parameter to limit rxd reaction to somaA
def init(ics, ecs): return lambda nd: ecs if isinstance(nd, rxd.node.NodeExtracellular ) else ics # ions k = rxd.Species([cyt, mem], name='k', d=1, charge=1, initial=54.4, represents='CHEBI:29103') kecs = rxd.Parameter([ecs], name='k', value=2.5, charge=1, represents='CHEBI:29103') na = rxd.Species([cyt, mem], name='na', d=1, charge=1, initial=10.0, represents='CHEBI:29101') naecs = rxd.Parameter([ecs], name='na_ecs', value=140, charge=1, represents='CHEBI:29101')
def init(ics, ecs): return lambda nd: ecs if isinstance(nd, rxd.node.NodeExtracellular ) else ics # ions k = rxd.Species([cyt, mem], name="k", d=1, charge=1, initial=54.4, represents="CHEBI:29103") kecs = rxd.Parameter([ecs], name="k", value=2.5, charge=1, represents="CHEBI:29103") na = rxd.Species([cyt, mem], name="na", d=1, charge=1, initial=10.0, represents="CHEBI:29101") naecs = rxd.Parameter([ecs], name="na", value=140, charge=1, represents="CHEBI:29101")
k = rxd.Species([cyt, mem, ecs], name="k", d=1, charge=1, initial=init(54.4, 2.5)) na = rxd.Species([cyt, mem, ecs], name="na", d=1, charge=1, initial=init(10.0, 140.0)) x = rxd.Species([cyt, mem, ecs], name="x", charge=1) ki, ko, nai, nao, xi, xo = k[cyt], k[ecs], na[cyt], na[ecs], x[cyt], x[ecs] # gates ngate = rxd.Species([cyt, mem], name="ngate", initial=0.24458654944007166) mgate = rxd.Species([cyt, mem], name="mgate", initial=0.028905534475191907) hgate = rxd.Species([cyt, mem], name="hgate", initial=0.7540796658225246) # mycellA parameter pA = rxd.Parameter( [cyt, mem], name="paramA", initial=lambda nd: 1 if nd.segment.sec in mycellA.all else 0, ) # What # gates m_gate = rxd.Rate(mgate, (minf - mgate) / mtau) h_gate = rxd.Rate(hgate, (hinf - hgate) / htau) n_gate = rxd.Rate(ngate, (ninf - ngate) / ntau) # Nernst potentials ena = 1e3 * h.R * (h.celsius + 273.15) * log(nao / nai) / h.FARADAY # 63 ek = 1e3 * h.R * (h.celsius + 273.15) * log(ko / ki) / h.FARADAY # -74 gna = pA * gnabar * mgate ** 3 * hgate gk = pA * gkbar * ngate ** 4
from neuron import h, crxd as rxd from matplotlib import pyplot h.load_file('stdrun.hoc') cell = h.Section(name='cell') r = rxd.Region([cell]) def Declare_Parameters(**kwargs): '''helper function enabling clean declaration of parameters in top namespace''' for key, value in kwargs.items(): globals()[key] = rxd.Parameter(r, name=key, initial=value) def Declare_Species(**kwargs): '''helper function enabling clean declaration of species in top namespace''' for key, value in kwargs.items(): globals()[key] = rxd.Species(r, name=key, initial=value) k3 = rxd.Parameter(r, name='k3', initial=1.2) k4 = rxd.Parameter(r, name='k4', initial=0.6) P2 = rxd.Species(r, name='P2', initial=0.0614368) T2 = rxd.Species(r, name='T2', initial=0.0145428) C = rxd.Species(r, name='C', initial=0.207614) h.finitialize(-65) h.continuerun(72)