#NEWLINE# def makeHHneuron( name , par_args , ic_args , const_I = False , apply_TTX = False , rand_seed = None , gentype = 'vode' ) : #NEWLINE# #INDENT# if ( gentype in [ 'vode' , 'euler' ] ) : #NEWLINE# #INDENT# targetlang = 'python' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# targetlang = 'C' #NEWLINE# #UNINDENT# if const_I : #NEWLINE# #INDENT# Iapp_str = 'Iapp' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# Iapp_str = 'Iapp(t)' #NEWLINE# #UNINDENT# Isignal_vardict = make_noise_signal ( 0.1 , 6000 , 0 , 0.4 , 1 , rand_seed ) #NEWLINE# vfn_str = ( '(%s-ionic(v, r, x, c)+As*sin(2*pi*t*f/1000.)+An*noise_sig)/tau_v' % Iapp_str ) #NEWLINE# rfn_str = '(1.29*v+0.79+3.3*pow(v+0.38,2)-r)/tau_r' #NEWLINE# xfn_str = '(7.33*(v+0.86)*(v+0.84)-x)/tau_x' #NEWLINE# cfn_str = '(3*x-c)/tau_c' #NEWLINE# if apply_TTX : #NEWLINE# #INDENT# v_str = 'vrest' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# v_str = 'vv' #NEWLINE# #UNINDENT# auxfndict = { #NEWLINE# #INDENT# 'ionic' : ( [ 'vv' , 'rr' , 'xx' , 'cc' ] , ( '13*(1.37+3.67*%s+2.51*%s*%s)*(vv-Ena)+gr*rr*(vv-Er)+gx*xx*(vv-Ex)+gc*cc*(vv-Ec)' % ( v_str , v_str , v_str ) ) ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not const_I ) : #NEWLINE# #INDENT# auxfndict [ 'Iapp' ] = ( [ 't' ] , 'if(t<thalf, kI*t-0.25, max(kI*(2*thalf-t)-0.25,-0.25))' ) #NEWLINE# #UNINDENT# DSargs = args ( ) #NEWLINE# DSargs . varspecs = { #NEWLINE# #INDENT# 'v' : vfn_str , #NEWLINE# 'r' : rfn_str , #NEWLINE# 'x' : xfn_str , #NEWLINE# 'c' : cfn_str , #NEWLINE# 'noise' : 'An*noise_sig' , #NEWLINE# 'sine' : 'As*sin(2*pi*t*f/1000.)' , #NEWLINE# #UNINDENT# } #NEWLINE# DSargs . inputs = { #NEWLINE# #INDENT# 'noise_sig' : Isignal_vardict [ 'noise1' ] , #NEWLINE# #UNINDENT# } #NEWLINE# DSargs . auxvars = [ 'noise' , 'sine' ] #NEWLINE# if ( not const_I ) : #NEWLINE# #INDENT# DSargs . varspecs [ 'I' ] = 'Iapp(t)' #NEWLINE# DSargs . auxvars . append ( 'I' ) #NEWLINE# #UNINDENT# DSargs . pars = par_args #NEWLINE# DSargs . fnspecs = auxfndict #NEWLINE# DSargs . xdomain = { #NEWLINE# #INDENT# 'v' : [ ( - 2 ) , 2 ] , #NEWLINE# 'r' : [ 0 , 1 ] , #NEWLINE# 'x' : [ 0 , 1 ] , #NEWLINE# 'c' : [ 0 , 1 ] , #NEWLINE# #UNINDENT# } #NEWLINE# DSargs . algparams = { #NEWLINE# #INDENT# 'init_step' : 0.1 , #NEWLINE# 'max_pts' : 1000000 , #NEWLINE# #UNINDENT# } #NEWLINE# if ( gentype == 'vode' ) : #NEWLINE# #INDENT# DSargs . algparams [ 'stiff' ] = True #NEWLINE# #UNINDENT# DSargs . checklevel = 0 #NEWLINE# DSargs . ics = ic_args #NEWLINE# DSargs . name = name #NEWLINE# thresh_ev = Events . makeZeroCrossEvent ( 'v' , 1 , { #NEWLINE# #INDENT# 'name' : 'thresh_ev' , #NEWLINE# 'eventtol' : 1e-05 , #NEWLINE# 'precise' : True , #NEWLINE# 'term' : False , #NEWLINE# #UNINDENT# } , varnames = [ 'v' ] , targetlang = targetlang ) #NEWLINE# min_ev = Events . makeZeroCrossEvent ( ( '(%s-ionic(v, r, x, c)+As*sin(2*pi*t*f/1000.)+An*noise_sig)/tau_v' % Iapp_str ) , 1 , { #NEWLINE# #INDENT# 'name' : 'min_ev' , #NEWLINE# 'eventtol' : 1e-05 , #NEWLINE# 'precise' : True , #NEWLINE# 'term' : False , #NEWLINE# #UNINDENT# } , varnames = [ 'v' , 'r' , 'x' , 'c' ] , parnames = par_args . keys ( ) , inputnames = [ 'noise_sig' ] , fnspecs = auxfndict , targetlang = targetlang ) #NEWLINE# DSargs . events = [ thresh_ev , min_ev ] #NEWLINE# if ( gentype == 'vode' ) : #NEWLINE# #INDENT# return Generator . Vode_ODEsystem ( DSargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( gentype == 'euler' ) : #NEWLINE# #INDENT# return Generator . Euler_ODEsystem ( DSargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( gentype == 'radau' ) : #NEWLINE# #INDENT# return Generator . Radau_ODEsystem ( DSargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( gentype == 'dopri' ) : #NEWLINE# #INDENT# return Generator . Dopri_ODEsystem ( DSargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise NotImplementedError ( ( 'Unknown ODE system type: %s' % gentype ) )