def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(), refractory=0 * ms, level=0, clock=None, unit_checking=True, compile=False, freeze=False, implicit=True, Cm=0.9 * uF / cm**2, Ri=150 * ohm * cm, bc_type=2, diffeq_nonzero=True): clock = guess_clock(clock) N = len(morphology) # number of compartments if isinstance(model, str): model = Equations(model, level=level + 1) model += Equations(''' v:volt # membrane potential ''') # Process model equations (Im) to extract total conductance and the remaining current if use_sympy: try: membrane_eq = model._string['Im'] # the membrane equation except: raise TypeError, "The transmembrane current Im must be defined" # Check conditional linearity ids = get_identifiers(membrane_eq) _namespace = dict.fromkeys( ids, 1. ) # there is a possibility of problems here (division by zero) _namespace['v'] = AffineFunction() eval(membrane_eq, model._namespace['v'], _namespace) try: eval(membrane_eq, model._namespace['v'], _namespace) except: # not linear raise TypeError, "The membrane current must be linear with respect to v" # Extracts the total conductance from Im, and the remaining current z = symbolic_eval(membrane_eq) symbol_v = sympy.Symbol('v') b = z.subs(symbol_v, 0) a = -sympy.simplify(z.subs(symbol_v, 1) - b) gtot_str = "_gtot=" + str(a) + ": siemens/cm**2" I0_str = "_I0=" + str(b) + ": amp/cm**2" model += Equations( gtot_str + "\n" + I0_str, level=level + 1) # better: explicit insertion with namespace of v else: raise TypeError, "The Sympy package must be installed for SpatialNeuron" # Equations for morphology (isn't it a duplicate??) eqs_morphology = Equations(""" diameter : um length : um x : um y : um z : um area : um**2 """) full_model = model + eqs_morphology NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory, level=level + 1, clock=clock, unit_checking=unit_checking, implicit=implicit) self.model_with_diffeq_nonzero = diffeq_nonzero self._state_updater = SpatialStateUpdater(self, clock) self.Cm = ones(len(self)) * Cm self.Ri = Ri self.bc_type = bc_type #default boundary condition on leaves self.bc = ones(len(self)) # boundary conditions on branch points self.changed = True # Insert morphology self.morphology = morphology self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)
def __init__(self, morphology=None, model=None, threshold=None, reset=NoReset(), refractory=0 * ms, level=0, clock=None, unit_checking=True, compile=False, freeze=False, Cm=0.9 * uF / cm**2, Ri=150 * ohm * cm): clock = guess_clock(clock) N = len(morphology) # number of compartments if isinstance(model, str): model = Equations(model, level=level + 1) model += Equations(''' v:volt # membrane potential ''') # Process model equations (Im) to extract total conductance and the remaining current if use_sympy: try: membrane_eq = model._string['Im'] # the membrane equation except: raise TypeError, "The transmembrane current Im must be defined" # Check conditional linearity ids = get_identifiers(membrane_eq) _namespace = dict.fromkeys( ids, 1. ) # there is a possibility of problems here (division by zero) _namespace['v'] = AffineFunction() eval(membrane_eq, model._namespace['v'], _namespace) try: eval(membrane_eq, model._namespace['v'], _namespace) except: # not linear raise TypeError, "The membrane current must be linear with respect to v" # Extracts the total conductance from Im, and the remaining current z = symbolic_eval(membrane_eq) symbol_v = sympy.Symbol('v') b = z.subs(symbol_v, 0) a = -sympy.simplify(z.subs(symbol_v, 1) - b) gtot_str = "_gtot=" + str(a) + ": siemens/cm**2" I0_str = "_I0=" + str(b) + ": amp/cm**2" model += Equations( gtot_str + "\n" + I0_str, level=level + 1) # better: explicit insertion with namespace of v else: raise TypeError, "The Sympy package must be installed for SpatialNeuron" # Equations for morphology (isn't it a duplicate??) eqs_morphology = Equations(""" diameter : um length : um x : um y : um z : um area : um**2 """) full_model = model + eqs_morphology # Create the state updater NeuronGroup.__init__(self, N, model=full_model, threshold=threshold, reset=reset, refractory=refractory, level=level + 1, clock=clock, unit_checking=unit_checking, implicit=True) #Group.__init__(self, full_model, N, unit_checking=unit_checking, level=level+1) #self._eqs = model #var_names = full_model._diffeq_names self.Cm = Cm # could be a vector? self.Ri = Ri self._state_updater = SpatialStateUpdater(self, clock) #S0 = {} # Fill missing units #for key, value in full_model._units.iteritems(): # if not key in S0: # S0[key] = 0 * value #self._S0 = [0] * len(var_names) #for var, i in zip(var_names, count()): # self._S0[i] = S0[var] # Insert morphology self.morphology = morphology self.morphology.compress(diameter=self.diameter, length=self.length, x=self.x, y=self.y, z=self.z, area=self.area)