Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self):
"""Set the vm_init from the spin button and prepare the simulator"""
if len(self.manager.vecRefs) == 0:
print "No vector Created. Create at least one vector to run the simulation"
else:
v_init = self.ui.vSpinBox.value()
# Set the v_init
h.v_init = v_init
h.finitialize(v_init)
h.fcurrent()
# Reset the time in the GUI
self.ui.time_label.setNum(h.t)
def simulate(cell, tstop=500, vinit=-55):
''' simulation control
Parameters
----------
cell: NEURON cell
cell for simulation
tstop: int (ms)
simulation time
vinit: int (mV)
initialized voltage
'''
h.finitialize(vinit)
balance(cell)
if h.cvode.active():
h.cvode.active()
else:
h.fcurrent()
h.frecord_init()
h.tstop = tstop
h.v_init = vinit
h.run()
# running_ = 1
def simulate(pool, tstop=30000, vinit=-55):
''' simulation control
Parameters
----------
cell: NEURON cell
cell for simulation
tstop: int (ms)
simulation time
vinit: int (mV)
initialized voltage
'''
h.finitialize(vinit)
for i in pool:
cell = pc.gid2cell(i)
balance(cell)
if h.cvode.active():
h.cvode.active()
else:
h.fcurrent()
h.frecord_init()
h.tstop = tstop
h.v_init = vinit
pc.set_maxstep(0.5)
h.stdinit()
pc.psolve(tstop)
def reset():
"""Reset the state of the current network to time t = 0."""
state.running = False
state.t = 0
state.tstop = 0
h.finitialize()
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))
set_nonvint_block(_callback)
if __name__ == '__main__':
exec(test) # see above string
s = h.Section()
print("fixed step finitialize")
h.finitialize(0)
print("fixed step fadvance")
h.fadvance()
h.load_file('stdgui.hoc')
print("cvode active")
h.cvode_active(1)
print("cvode step finitialize")
h.finitialize(0)
print("cvode fadvance")
h.fadvance()
def runSim ():
from .. import sim
sim.pc.barrier()
if hasattr(sim.cfg,'use_local_dt') and sim.cfg.use_local_dt:
try:
sim.cvode.use_local_dt(1)
if sim.cfg.verbose: print('Using local dt.')
except:
if sim.cfg.verbose: 'Error Failed to use local dt.'
sim.pc.barrier()
sim.timing('start', 'runTime')
preRun()
h.finitialize(float(sim.cfg.hParams['v_init']))
if sim.cfg.coreneuron == True:
if sim.rank == 0: print('\nRunning simulation using CoreNEURON for %s ms...' % sim.cfg.duration)
sim.cfg.cache_efficient = True
sim.cvode.cache_efficient(1)
sim.pc.nrncore_run("-e %g"%sim.cfg.duration, 0)
else:
if sim.rank == 0: print('\nRunning simulation for %s ms...'%sim.cfg.duration)
sim.pc.psolve(sim.cfg.duration)
sim.pc.barrier() # Wait for all hosts to get to this point
sim.timing('stop', 'runTime')
if sim.rank==0:
print(' Done; run time = %0.2f s; real-time ratio: %0.2f.' %
(sim.timingData['runTime'], sim.cfg.duration/1000/sim.timingData['runTime']))
# Run parameters
cfg = specs.SimConfig() # object of class cfg to store simulation configuration
cfg.duration = 500 # Duration of the simulation, in ms
cfg.recordTraces = {'ca': {'sec': 'soma', 'loc': 0.5, 'var': 'cai'},
'buf': {'sec': 'soma', 'loc': 0.5, 'var': 'bufi'},
'cabuf': {'sec': 'soma', 'loc': 0.5, 'var': 'cabufi'}}
cfg.analysis['plotTraces'] = {'include': ['cell'], 'ylim':[0, 0.0001], 'overlay': True}
#------------------------------------------------------------------------------
# RUN MODEL
#------------------------------------------------------------------------------
sim.create(netParams,cfg)
h.finitialize()
sim.simulate()
sim.analyze()
netStimLabels = list(sim.net.params.stimSourceParams.keys())+['allNetStims','eachPop']
for item in sim.cfg.analysis['plotSpikeHist']['include']:
if item in netStimLabels:
sim.cfg.recordStim = True
break
if sim.cfg.recordStim:
sim.simData['stims'] = Dict()
for cell in sim.net.cells:
cell.recordStimSpikes()
# intrinsic cell variables recording
if sim.cfg.recordTraces:
# if have rxd objects need to run h.finitialize() before setting up recording so pointers available
if len(sim.net.params.rxdParams) > 0:
h.finitialize()
# get list of cells from argument of plotTraces function
if 'plotTraces' in sim.cfg.analysis and 'include' in sim.cfg.analysis['plotTraces']:
cellsPlot = utils.getCellsList(sim.cfg.analysis['plotTraces']['include'])
else:
cellsPlot = []
# get actual cell objects to record from, both from recordCell and plotCell lists
cellsRecord = utils.getCellsList(sim.cfg.recordCells)+cellsPlot
for key in list(sim.cfg.recordTraces.keys()): sim.simData[key] = Dict() # create dict to store traces
for cell in cellsRecord:
cell.recordTraces() # call recordTraces function for each cell
# record h.t
if sim.cfg.recordTime and len(sim.simData) > 0: