def load(self, secs, dx_3d_size, rxds=None): """ Must be called after all secs are set. :param secs: :param dx_3d_size: If 3D geometry is True, define the size of the single compartment size. :param rxds: dictionary which contains previously added RxDTool objects """ rxdca = rxds['RxDCa'] # PMCA Pump self.pmca = rxd.Species(regions=rxdca.cyt, initial=760 * nM, name='pmca', charge=0, d=0) self.pmca_ca = rxd.Species(regions=rxdca.cyt, initial=120 * nM, name='pmca_ca', charge=0, d=0) self.pmca_ca_reaction = rxd.Reaction(rxdca.ca + self.pmca, self.pmca_ca, 0.05e-3 / (nM * ms), 9e-3 / (nM * ms)) self.pmca_ca__pmca_reaction = rxd.Reaction(self.pmca_ca, self.pmca, 3.0e-3 / (nM * ms), 0) # CaOut
def declare_species(**kwargs): """enables clean declaration of species in top namespace""" for key in sorted(kwargs): globals()[key] = rxd.Species(r, name=key, initial=kwargs[key], atolscale=1 * nM)
def scalar_bistable(rxdstr): if rxdstr == 'rxd': from neuron import rxd else: from neuron import crxd as rxd h.load_file('stdrun.hoc') s = h.Section(name='s') s.nseg = 101 cyt = rxd.Region(h.allsec()) c = rxd.Species(cyt, name='c', initial=lambda node: 1 if 0.4 < node.x < 0.6 else 0, d=1) r = rxd.Rate(c, -c * (1 - c) * (0.3 - c)) h.finitialize() h.run() #check the results result = h.Vector(c.nodes.concentration) cmpV = h.Vector(scalar_bistable_data[rxdstr]) cmpV.sub(result) cmpV.abs() if cmpV.sum() < 1e-6: sys.exit(0) sys.exit(-1)
def do_sim(simulation, sim_control=None): """setup a simulation""" global na, cell # hide the simulation control panel, if there was one if sim_control: sim_control.unmap() cell = FleidervishNeuron() # add sodium diffusion everywhere allsec = rxd.Region(h.allsec(), nrn_region='i') na = rxd.Species(allsec, d=0.6, name='na', charge=1) # create a current clamp and add it to the cell cell.ic = h.IClamp(cell.soma(0.5)) cell.ic.dur = 3 # ms cell.ic.amp = 1.5 # nA # setup graphs needed by both simulations concentration_graph = h.Graph(False) concentration_graph.size(0, 3000, 4, 4.4) voltage_graph = h.Graph(False) voltage_graph.size(0, 3000, -90, 60) h.graphList[0].append(voltage_graph) h.graphList[1].append(concentration_graph) # pop up the run control h.nrncontrolmenu() # call the funciton which actually sets up the specific simulation simulation(cell, voltage_graph, concentration_graph)
def trivial_ecs(self, scale): from neuron import h, crxd as rxd import numpy import warnings warnings.simplefilter("ignore", UserWarning) h.load_file('stdrun.hoc') tstop = 10 if scale: #variable step case h.CVode().active(True) h.CVode().event(tstop) else: #fixed step case h.dt = 0.1 sec = h.Section() #NEURON requires at least 1 section # enable extracellular RxD rxd.options.enable.extracellular = True # simulation parameters dx = 1.0 # voxel size L = 9.0 # length of initial cube Lecs = 21.0 # lengths of ECS # define the extracellular region extracellular = rxd.Extracellular(-Lecs / 2., -Lecs / 2., -Lecs / 2., Lecs / 2., Lecs / 2., Lecs / 2., dx=dx, volume_fraction=0.2, tortuosity=1.6) # define the extracellular species k_rxd = rxd.Species(extracellular, name='k', d=2.62, charge=1, atolscale=scale, initial=lambda nd: 1.0 if abs(nd.x3d) <= L / 2. and abs(nd.y3d) <= L / 2. and abs(nd.z3d) <= L / 2. else 0.0) # record the concentration at (0,0,0) ecs_vec = h.Vector() ecs_vec.record(k_rxd[extracellular].node_by_location(0, 0, 0)._ref_value) h.finitialize() h.continuerun(tstop) #run the simulation # compare with previous solution ecs_vec.sub(h.Vector(trivial_ecs_data[scale])) ecs_vec.abs() if ecs_vec.sum() > 1e-9: return -1 return 0
def basicRxD3D(): from neuron import h, rxd s = h.Section(name='s') s.L = s.diam = 1 cyt = rxd.Region([s]) ca = rxd.Species(cyt) rxd.set_solve_type(dimension=3) h.finitialize(-65) h.fadvance() return 1
def load(self, secs, dx_3d_size, rxds=None): """ Must be called after all secs are set. :param secs: List of sections (real HOC objects) :param dx_3d_size: If 3D geometry is True, define the size of the single compartment size. :param rxds: dictionary which contains previously added RxDTool objects """ self.cyt = rxd.Region(secs=secs, nrn_region='i', dx=dx_3d_size) # 1/nM = 1 × 1/10^-9M = 10^3/10^3 × 1/10^-9M = 1000/(10^3×10^-9M) = 1000/10^-6M = 1000/uM # Ca2+ self.ca = rxd.Species(regions=self.cyt, initial=75 * nM, name='ca', charge=2, d=174.3 / sec) # Calbindin buffer self.calbindin = rxd.Species(regions=self.cyt, initial=159982 * nM, name='calbindin', charge=0, d=9.3 / sec) self.calbindin_ca = rxd.Species(regions=self.cyt, initial=18 * nM, name='calbindin_ca', charge=0, d=9.3 / sec) self.calbindin_ca_reaction = rxd.Reaction(self.ca + self.calbindin, self.calbindin_ca, 0.028e-3 / (nM * ms), 19.6 / (nM * ms)) # Calmodulin buffer self.calmodulin = rxd.Species(regions=self.cyt, initial=12600 * nM, name='calmodulin', charge=0, d=4 / sec) self.calmodulin_ca2 = rxd.Species(regions=self.cyt, initial=200 * nM, name='calmodulin_ca2', charge=0, d=4 / sec) self.calmodulin_ca4 = rxd.Species(regions=self.cyt, initial=3 * nM, name='calmodulin_ca4', charge=0, d=4 / sec) self.calmodulin_ca2_reaction = rxd.Reaction( 2 * self.ca + self.calmodulin, self.calmodulin_ca2, 6e-6 / (nM * ms), 9.1e-3 / (nM * ms)) self.calmodulin_ca4_reaction = rxd.Reaction( 2 * self.ca + self.calmodulin_ca2, self.calmodulin_ca4, 0.1e-3 / (nM * ms), 1000e-3 / (nM * ms))
h.load_file('stdrun.hoc') h.CVode().active(True) sec = h.Section() # the extracellular space ecs = rxd.Extracellular(-55, -55, -55, 55, 55, 55, dx=10, volume_fraction=0.2, tortuosity=1.6) # Who? x = rxd.Species([ecs], name='x', d=0.0, charge=1, initial=0) def callbackfun(): return 1000 x[ecs].node_by_location(-20, 0, 0).include_flux(1000) x[ecs].node_by_location(0, 0, 0).include_flux(callbackfun) x[ecs].node_by_location(20, 0, 0).include_flux(sec(0.5)._ref_v) h.finitialize(1000) h.CVode().event(10) h.continuerun(10)
from neuron import h, rxd from matplotlib import pyplot h.load_file('stdrun.hoc') from neuron.units import mM, ms sim_time = 100 axon_terminal = h.Section(name="axon_terminal") #synaptic_cleft = rxd.Region([axon_terminal], nrn_region='o') axon_terminal_region = rxd.Region([axon_terminal], nrn_region='i') ca_intra = rxd.Species(axon_terminal_region, name="ca", charge=2, d=0, initial=5e-4, atolscale=1e-6) F = rxd.Species(axon_terminal_region, name="F", initial=0.001) FA = rxd.Species(axon_terminal_region, name="FA", initial=0) kb = rxd.Parameter(axon_terminal_region, name="kb", value=1e16 / (mM**4 * ms)) ku = rxd.Parameter(axon_terminal_region, name="ku", value=0.1 / ms) myreaction = rxd.Reaction(F + 4 * ca_intra, FA, kb, ku) #, regions=axon_terminal_region) tvec = h.Vector().record(h._ref_t) Fvec = h.Vector().record(F.nodes._ref_concentration) FAvec = h.Vector().record(FA.nodes._ref_concentration) h.finitialize(-65) h.continuerun(10)
from neuron import h, rxd h.load_file("stdrun.hoc") cell = h.Section(name="cell") r = rxd.Region([cell]) Ca = rxd.Species(r, name="ca", charge=2, initial=60e-3) reaction_decay = rxd.Reaction(Ca, 0 * Ca, 1e-8) tvec = h.Vector().record(h._ref_t) cavec = h.Vector().record(Ca.nodes[0]._ref_concentration) h.finitialize(-70) h.continuerun(10) if __name__ == "__main__": from matplotlib import pyplot pyplot.plot(tvec, cavec) pyplot.show()
55, 55, dx=10, volume_fraction=0.2, tortuosity=1.6) soma_cell_1 = rxd.Region([cell_1.soma], nrn_region="i", geometry=rxd.Shell(0.8, 1)) soma_cell_2 = rxd.Region([cell_2.soma], nrn_region="i", geometry=rxd.Shell(0.8, 1)) species_x = rxd.Species( [ecs, soma_cell_1, soma_cell_2], name="species_x", d=1, charge=1, initial=1, ecs_boundary_conditions=0, ) Species_y = rxd.Species( [soma_cell_1, ecs], name="species_y", d=1, charge=1, initial=1, ecs_boundary_conditions=0, ) Species_z = rxd.Species([soma_cell_1], name="species_z", d=1, charge=1,
#any resemblance to experimental values is purely coincidental. fc = 0.7 fe = 0.3 caCYT_init = 1.0 cyt = rxd.Region(h.allsec(), nrn_region='i', geometry=rxd.FractionalVolume(fc, surface_fraction=1)) er = rxd.Region(h.allsec(), geometry=rxd.FractionalVolume(fe)) cyt_er_membrane = rxd.Region(h.allsec(), geometry=rxd.ScalableBorder( 1, on_cell_surface=False)) ca = rxd.Species([cyt, er], d=caDiff, name="ca", charge=2, initial=caCYT_init) ip3 = rxd.Species(cyt, d=ip3Diff, initial=ip3_init) ip3r_gate_state = rxd.State(cyt_er_membrane, initial=0.8) h_gate = ip3r_gate_state[cyt_er_membrane] minf = ip3[cyt] * 1000. * ca[cyt] / (ip3[cyt] + kip3) / (1000. * ca[cyt] + kact) k = gip3r * (minf * h_gate)**3 ip3r = rxd.MultiCompartmentReaction(ca[er], ca[cyt], k, k, membrane=cyt_er_membrane) serca = rxd.MultiCompartmentReaction(ca[cyt] > ca[er],
results["species"] = set(my_species) results["name"] = sec.hname() results["hoc_internal_name"] = sec.hoc_internal_name() results["cell"] = sec.cell() # all_active_reactions = [r() for r in rxd_module._all_reactions if r() is not None] return results if __name__ == "__main__": from pprint import pprint from neuron import h, rxd soma = h.Section(name="soma") soma.insert("hh") soma.insert("pas") soma.nseg = 3 iclamp = h.IClamp(soma(0.3)) gaba = h.ExpSyn(soma(0.7)) dend = h.Section(name="dend") dend.connect(soma) cyt = rxd.Region([dend], name="cyt", nrn_region="i") er = rxd.Region([dend], name="er") na = rxd.Species(cyt, name="na", charge=1) ca = rxd.Species([cyt, er], name="ca", charge=2) h.finitialize(-65) pprint(psection(soma)) print("\n") pprint(psection(dend))
gmem = rxd.Region(glia, name="cell_mem", geometry=rxd.membrane()) dx = vo**(1.0 / 3.0) ecs = rxd.Extracellular(-2 * dx, -2 * dx, -2 * dx, 2 * dx, 2 * dx, 2 * dx, dx=dx) # ecs = rxd.Extracellular(-100, -100, -100, 100, 100, 100, dx=33) # SPECIES/PARAMETERS------------------------------------------------------------------------------------------------------------------------ # intracellular/extracellular species (Na+, K+, Cl-) na = rxd.Species([cyt, mem, ecs], name="na", d=1, charge=1, initial=concentration(15.5, 161.5)) k = rxd.Species([cyt, mem, ecs], name="k", d=1, charge=1, initial=concentration(142.5, 7.8)) cl = rxd.Species([cyt, mem, ecs], name="cl", d=1, charge=-1, initial=concentration(6.0, 130)) glial_na = rxd.Parameter([gcyt, gmem], name="na", charge=1, value=18) # Na in book is 55 for astrocyte glial_k = rxd.Parameter([gcyt, gmem], name="k", charge=1, value=80)
ncrec.threshold = 0 # 10 mV is default, lower it ltimevec.append(timevec) lidvec.append(idvec) lncrec.append(ncrec) # record the spikes at soma rxd.options.use_reaction_contribution_to_jacobian = False # faster (checked a few days before 10/16/13) fc, fe = 0.83, 0.17 # cytoplasmic, er volume fractions cyt = rxd.Region(rxdsec, nrn_region='i', geometry=rxd.FractionalVolume(fc, surface_fraction=1)) er = rxd.Region(rxdsec, geometry=rxd.FractionalVolume(fe)) cyt_er_membrane = rxd.Region(rxdsec, geometry=rxd.ScalableBorder(1)) caDiff = 0.233 ca = rxd.Species([cyt, er], d=caDiff, name='ca', charge=2, initial=dconf['cacytinit']) caexinit = dconf['caexinit'] caextrude = rxd.Rate(ca, (caexinit - ca[cyt]) / taurcada, regions=cyt, membrane_flux=False) ip3 = rxd.Species(cyt, d=0.283, name='ip3', initial=0.0) # action of IP3 receptor Kip3 = 0.13 Kact = 0.4 minf = ip3[cyt] * 1000. * ca[cyt] / (ip3[cyt] + Kip3) / (1000. * ca[cyt] + Kact) ip3r_gate_state = rxd.State(cyt_er_membrane, initial=0.8) h_gate = ip3r_gate_state[cyt_er_membrane]
from neuron import h, rxd, gui from neuron.rxd import initializer h.CVode().active(1) rxdsec = [h.Section(), h.Section()] cyt = rxd.Region(rxdsec) er = rxd.Region(rxdsec) ca = rxd.Species([cyt, er]) caextrude = rxd.Rate(ca, 1) # test for forced initialization before model fully described initializer._do_init() ip3 = rxd.Species(cyt) h.tstop = 1000 h.run()
from neuron import h, rxd h.load_file("stdrun.hoc") sec = h.Section(name="sec") sec.L = 10 sec.nseg = 11 sec.diam = 5 rxd.set_solve_type(dimension=3) cyt = rxd.Region(h.allsec(), name="cyt", nrn_region="i") ip3 = rxd.Species(cyt, name="ip3", initial=lambda nd: 1000 if nd.segment == sec(0.3) else 0) def callbackfun(): return 1000 for nd in ip3.nodes(sec(0.1)): nd.include_flux(1000) for nd in ip3.nodes(sec(0.5)): nd.include_flux(callbackfun) for nd in ip3.nodes(sec(0.9)): nd.include_flux(sec(0.3)._ref_ip3i) h.finitialize(-70) h.continuerun(10) import numpy
from matplotlib import pyplot h.load_file('stdrun.hoc') # In[2]: axon = h.Section(name='s1') axon_terminal = h.Section(name='s') axon.connect(axon_terminal) axon_terminal_region = rxd.Region([axon_terminal], nrn_region='i') synaptic_cleft = rxd.Region([axon_terminal], nrn_region='o') terminal_membrane = rxd.Region(h.allsec(), geometry=rxd.DistributedBoundary(1)) # In[3]: VA = rxd.Species([axon_terminal_region], name="VA", initial=10, charge=1) T = rxd.Species([synaptic_cleft], name="T", initial=10, charge=1) # In[4]: # if you comment the exocytosis line below, the error will go away exocytosis = rxd.MultiCompartmentReaction(VA[axon_terminal_region], T[synaptic_cleft], 500, 0, membrane=terminal_membrane, membrane_flux=True) # In[5]: VA_conc = h.Vector().record(VA.nodes[0]._ref_concentration)
species = [ 'cAMP', 'PKAcAMP2', 'PKAcAMP4', 'PKA', 'PKAr', 'PKAc', 'AMP', 'ATP', 'PDE4', 'PDE4cAMP' ] windows = [0, 0, 0, 2, 1, 1, 3, 3, 4, 4] tolscales = [1.0 for i in range(0, len(species))] print "my_volume = " + str(my_volume) + " l ?= " + str( dend.L * (dend.diam / 2)**2 * 3.14159265358) + " um3" specs = [] for ispec in range(0, len(species)): specs.append( rxd.Species(cyt, name='spec' + str(ispec), charge=0, initial=initvalues[ispec], atolscale=tolscales[ispec])) cAMP_flux_rate = rxd.Parameter(cyt, initial=0) #specs[0] cAMP #specs[1] PKA2cAMP #specs[2] PKA4cAMP #specs[3] PKA #specs[4] PKAr #specs[5] PKAc #specs[6] AMP #specs[7] ATP #specs[8] PDE4 #specs[9] PDE4cAMP reaction1 = rxd.Reaction(specs[3] + specs[0] * 4 <> specs[2], ks[0], ks[1])
gmem = rxd.Region(glia, name='cell_mem', geometry=rxd.membrane()) dx = vo**(1.0 / 3.0) ecs = rxd.Extracellular(-2 * dx, -2 * dx, -2 * dx, 2 * dx, 2 * dx, 2 * dx, dx=dx) #ecs = rxd.Extracellular(-100, -100, -100, 100, 100, 100, dx=33) #SPECIES/PARAMETERS------------------------------------------------------------------------------------------------------------------------ #intracellular/extracellular species (Na+, K+, Cl-) na = rxd.Species([cyt, mem, ecs], name='na', d=1, charge=1, initial=concentration(15.5, 161.5)) k = rxd.Species([cyt, mem, ecs], name='k', d=1, charge=1, initial=concentration(142.5, 7.8)) cl = rxd.Species([cyt, mem, ecs], name='cl', d=1, charge=-1, initial=concentration(6.0, 130)) glial_na = rxd.Parameter([gcyt, gmem], name='na', charge=1, value=18) #Na in book is 55 for astrocyte glial_k = rxd.Parameter([gcyt, gmem], name='k', charge=1, value=80)
fe = 0.3 caCYT_init = 0.1 cyt = rxd.Region(h.allsec(), name='cyt', nrn_region='i', geometry=rxd.FractionalVolume(fc, surface_fraction=1)) er = rxd.Region(h.allsec(), name='er', geometry=rxd.FractionalVolume(fe / 2.)) cyt_er_membrane = rxd.Region(h.allsec(), name='mem', geometry=rxd.ScalableBorder( 1, on_cell_surface=False)) ca = rxd.Species([cyt, er], d=caDiff, name="ca", charge=2, initial=caCYT_init) ip3 = rxd.Species(cyt, d=ip3Diff, name="ip3", initial=ip3_init) ip3r_gate_state = rxd.Species(cyt_er_membrane, name="gate", initial=0.8) h_gate = ip3r_gate_state[cyt_er_membrane] minf = ip3[cyt] * 1000. * ca[cyt] / (ip3[cyt] + kip3) / (1000. * ca[cyt] + kact) k = gip3r * (minf * h_gate)**3 ip3r = rxd.MultiCompartmentReaction(ca[er], ca[cyt], k, k, membrane=cyt_er_membrane) serca = rxd.MultiCompartmentReaction(ca[cyt],
from neuron import h, rxd from matplotlib import pyplot h.load_file('stdrun.hoc') cell = h.Section(name='cell') r = rxd.Region([cell]) Ca = rxd.Species(r, name='ca', charge=2, initial=60e-3) reaction_decay = rxd.Reaction(Ca, 0 * Ca, 1e-8) tvec = h.Vector().record(h._ref_t) cavec = h.Vector().record(Ca.nodes[0]._ref_concentration) h.finitialize(-70) h.continuerun(10) pyplot.plot(tvec, cavec) pyplot.show()
-Lx / 2.0, -Ly / 2.0, -Lz / 2.0, Lx / 2.0, Ly / 2.0, Lz / 2.0, dx=10, volume_fraction=0.2, tortuosity=1.6, ) # Who? -- define the species k = rxd.Species( ecs, name="k", d=2.62, charge=1, initial=lambda nd: 40 if nd.x3d**2 + nd.y3d**2 + nd.z3d**2 < 50**2 else 3.5, ) na = rxd.Species(ecs, name="na", d=1.78, charge=1, initial=134) ko, nao = k[ecs], na[ecs] # What? # No extracellular reactions, just diffusion. class Neuron: """A neuron with soma and fast and persistent sodium currents, potassium currents, passive leak and potassium leak and an accumulation mechanism."""
Db = 0 Dcab = 0 # create sections soma = h.Section(name="soma") dend = h.Section(name="dend") soma.L = 100 soma.diam = 1 soma.nseg = 101 dend.L = 100 dend.diam = 1 dend.nseg = 101 soma.connect(dend) r = rxd.Region(h.allsec()) Ca = rxd.Species(r, name='Ca', d=Dca) Buf = rxd.Species(r, name='Buf', d=Db) CaBuf = rxd.Species(r, name='CaBuf', d=Dcab) buffering = rxd.Reaction(Ca + Buf, CaBuf, kf, kb) # # set initial concentrations to ca0, b0, cab0 in soma, # and to 0.001 in dend # Ca.initial = lambda node: (ca0 if node.sec._sec == soma else 0.001) Buf.initial = lambda node: (b0 if node.sec._sec == soma else 0.001) CaBuf.initial = lambda node: (cab0 if node.sec._sec == soma else 0.001) h.init() species_0_trace = h.Vector()
import numpy from matplotlib import pyplot import time # needed for standard run system h.load_file('stdrun.hoc') dend = h.Section() dend.nseg = 501 # WHERE the dynamics will take place where = rxd.Region(h.allsec()) # WHO the actors are u = rxd.Species(where, d=1, initial=0) # HOW they act bistable_reaction = rxd.Rate(u, -u * (1 - u) * (0.3 - u)) # initial conditions h.finitialize() for node in u.nodes: if node.x < .2: node.concentration = 1 def plot_it(color='k'): y = u.nodes.concentration x = u.nodes.x # convert x from normalized position to microns
def __init__(self, x, y, z, rec=False): self.x = x self.y = y self.z = z self.soma = h.Section(name="soma", cell=self) # add 3D points to locate the neuron in the ECS self.soma.pt3dadd(x, y, z + somaR, 2.0 * somaR) self.soma.pt3dadd(x, y, z - somaR, 2.0 * somaR) # Where? -- define the intracellular space and membrane self.cyt = rxd.Region(self.soma, name="cyt", nrn_region="i") self.mem = rxd.Region(self.soma, name="mem", geometry=rxd.membrane()) cell = [self.cyt, self.mem] # Who? -- the relevant ions and gates self.k = rxd.Species(cell, name="k", d=2.62, charge=1, initial=125) self.na = rxd.Species(cell, name="na", d=1.78, charge=1, initial=10) self.n = rxd.State(cell, name="n", initial=0.25512) self.ki, self.nai = self.k[self.cyt], self.na[self.cyt] # What? -- gating variables and ion currents self.n_gate = rxd.Rate(self.n, phin * (ninf - self.n) / taun) # Nernst potentials ena = 1e3 * h.R * (h.celsius + 273.15) * log( nao / self.nai) / h.FARADAY ek = 1e3 * h.R * (h.celsius + 273.15) * log(ko / self.ki) / h.FARADAY # Persistent Na current self.nap_current = rxd.MultiCompartmentReaction( self.nai, nao, gnap * nap_minf * nap_hinf * (v - ena), mass_action=False, membrane=self.mem, membrane_flux=True, ) # Na current self.na_current = rxd.MultiCompartmentReaction( self.nai, nao, gna * minf**3 * (1.0 - self.n) * (v - ena), mass_action=False, membrane=self.mem, membrane_flux=True, ) # K current self.k_current = rxd.MultiCompartmentReaction( self.ki, ko, gk * self.n**4 * (v - ek), mass_action=False, membrane=self.mem, membrane_flux=True, ) # K leak self.k_leak = rxd.MultiCompartmentReaction( self.ki, ko, gl * (v - ek), mass_action=False, membrane=self.mem, membrane_flux=True, ) # passive leak self.soma.insert("pas") self.soma(0.5).pas.g = pas_gl self.soma(0.5).pas.e = pas_el if rec: # record membrane potential (shown in figure 1C) self.somaV = h.Vector() self.somaV.record(self.soma(0.5)._ref_v, rec)
h.load_file("stdrun.hoc") soma = h.Section(name="soma") soma.diam = soma.L = 10 # the geometry of the ecs doesn't matter in the constant case ecs = rxd.Region([soma], name="ecs", nrn_region="o", geometry=rxd.Shell(1, 2)) cyt = rxd.Region([soma], name="cyt", nrn_region="i") mem = rxd.Region([soma], name="mem", geometry=rxd.membrane()) cao = rxd.Parameter(ecs, charge=2) ca = rxd.Species( [cyt], d=1, # with single section and nseg=1 only affects extracellular name="ca", charge=2, initial=lambda node: 1e-3 if node.region == cyt else 0, ) e = 1.60217662e-19 scale = 1e-14 / e # rate constant is in terms of molecules/um2 ms ca_pump = rxd.MultiCompartmentReaction( ca[cyt], cao[ecs], ca[cyt] * scale, custom_dynamics=True, membrane_flux=True, membrane=mem,
def wave_search(size, size_segments, time_period, times, au, Du): # needed for standard run system h.load_file('stdrun.hoc') global dend dend = h.Section() dend.L = size dend.nseg = size_segments # WHERE the dynamics will take place where = rxd.Region(h.allsec()) # WHO the actors are global u global z global v u = rxd.Species(where, d=Du, initial=0.5) # activator z = rxd.Species(where, d=20, initial=0.5) # inhibitor v = rxd.Species(where, d=0, initial=(1 / dend.L) * 30) # modulator # HOW they act a = au b = -0.4 c = 0.6 d = -0.8 u0 = 0.5 z0 = 0.5 av = 5.0 kz = 0.001 bistable_reaction1 = rxd.Rate(u, (a * (u - u0) + b * (z - z0) - av * (u - u0)**3) * (v**-2)) bistable_reaction2 = rxd.Rate(z, (c * (u - u0) + d * (z - z0)) * (v**-2)) # initial conditions h.finitialize() for node in u.nodes: if node.x < .2: node.concentration = 0.6 if node.x > .8: node.concentration = 0.6 for node in z.nodes: if node.x < .2: node.concentration = 0.6 if node.x > .8: node.concentration = 0.6 # Setting up time frame global u_timespace T_d = times T = time_period u_timespace = [] for i in np.arange(0, T_d): h.continuerun(i * T) u_timespace.append(u.nodes.concentration) # activator FFT source files u_fft_y = u.nodes.concentration u_fft_y = u_fft_y - np.mean(u_fft_y) u_fft_x = u.nodes.x global u_fft_x_norm u_fft_x_norm = dend.L * np.array(u_fft_x) # inhibitor FFT source files z_fft_y = z.nodes.concentration z_fft_y = z_fft_y - np.mean(z_fft_y) z_fft_x = z.nodes.x z_fft_x_norm = dend.L * np.array(u_fft_x) # activator FFT Y1 = np.fft.fft(u_fft_y) N = len(Y1) / 2 + 1 dt = dend.L / dend.nseg fa = 1.0 / dt X = np.linspace(0, fa / 2, N, endpoint=True) # inhibitor FFT Y2 = np.fft.fft(z_fft_y) X2 = np.linspace(0, fa / 2, N, endpoint=True) # # if ((np.amax(Y1) - np.amin(Y1) < .01) or (np.amax(Y2) - np.amin(Y2) < .01)): # return 0 if (len(X) == len(2.0 * np.abs(Y1[:N] / N))): u_maxx = (np.argmax(2.0 * np.abs(Y1[:N] / N))) wavelen = np.around(1 / X[u_maxx]) plot_it(time_period, times, u_timespace) plt.savefig('results/plots/{0}_{1}_{2}_{3}_{4}_{5}.png'.format( size, size_segments, time_period, times, au, Du)) return wavelen
kserca = 0.1 kip3 = 0.15 kact = 0.4 ip3rtau = 2000 h.CVode().active(1) h.cvode.atol(1e-10) # define the regions for the rxd cyt = rxd.Region(h.allsec(), nrn_region='i', geometry=rxd.FractionalVolume(fc, surface_fraction=1)) er = rxd.Region(h.allsec(), geometry=rxd.FractionalVolume(fe)) cyt_er_membrane = rxd.Region(h.allsec(), geometry=rxd.FixedPerimeter(1)) # the species and other states ca = rxd.Species([cyt, er], d=caDiff, name='ca', charge=2, initial=cac_init) ip3 = rxd.Species(cyt, d=ip3Diff, initial=ip3_init) ip3r_gate_state = rxd.State(cyt_er_membrane, initial=0.8) h_gate = ip3r_gate_state[cyt_er_membrane] # pumps and channels between ER and Cytosol serca = rxd.MultiCompartmentReaction(ca[cyt] > ca[er], gserca / ((kserca / (1000. * ca[cyt]))**2 + 1), membrane=cyt_er_membrane, custom_dynamics=True) leak = rxd.MultiCompartmentReaction(ca[er] != ca[cyt], gleak, gleak, membrane=cyt_er_membrane)
from matplotlib import pyplot import numpy import __main__ name = __main__.__file__ if name[-3:] == '.py': name = name[:-3] h.load_file('stdrun.hoc') dend = h.Section() dend.diam = 2 dend.nseg = 101 dend.L = 100 diff_constant = 1 r = rxd.Region(h.allsec()) ca = rxd.Species(r, d=diff_constant, initial=lambda node: 1 if 0.4 < node.x < 0.6 else 0) h.finitialize() for t in [25, 50, 75, 100, 125]: h.continuerun(t) pyplot.plot([seg.x for seg in dend], ca.states) pyplot.tight_layout() pyplot.savefig('{0}.png'.format(name))