def _ion_register(self): charge = self._charge if self._name is not None: ion_type = h.ion_register(self._name, charge) if ion_type == -1: raise RxDException('Unable to register species: %s' % self._name) # insert the species if not already present regions = self._regions if hasattr(self._regions, '__len__') else [self._regions] for r in regions: if r.nrn_region in ('i', 'o'): for s in r.secs: try: ion_forms = [ self._name + 'i', self._name + 'o', 'i' + self._name, 'e' + self._name ] for i in ion_forms: # this throws an exception if one of the ion forms is missing temp = s.__getattribute__(self._name + 'i') except: s.insert(self._name + '_ion') # set to recalculate reversal potential automatically # the last 1 says to set based on global initial concentrations # e.g. nai0_na_ion, etc... h.ion_style(self._name + '_ion', 3, 2, 1, 1, 1, sec=s)
def _ion_register(self): """modified from neuron.rxd.species.Species._ion_register""" ion_type = h.ion_register(self._species, self._charge) if ion_type == -1: raise RxDException('Unable to register species: %s' % self._species) # insert the species if not already present ion_forms = [self._species + 'i', self._species + 'o', 'i' + self._species, 'e' + self._species] for s in h.allsec(): try: for i in ion_forms: # this throws an exception if one of the ion forms is missing temp = s.__getattribute__(i) except: s.insert(self._species + '_ion') # set to recalculate reversal potential automatically # the last 1 says to set based on global initial concentrations # e.g. nao0_na_ion, etc... # TODO: this is happening GLOBALLY even to sections that aren't inside the extracellular domain (FIX THIS) h.ion_style(self._species + '_ion', 3, 2, 1, 1, 1, sec=s)
def _ion_register(self): charge = self._charge if self._name is not None: ion_type = h.ion_register(self._name, charge) if ion_type == -1: raise RxDException('Unable to register species: %s' % self._name) # insert the species if not already present regions = self._regions if hasattr(self._regions, '__len__') else [self._regions] for r in regions: if r.nrn_region in ('i', 'o'): for s in r.secs: try: ion_forms = [self._name + 'i', self._name + 'o', 'i' + self._name, 'e' + self._name] for i in ion_forms: # this throws an exception if one of the ion forms is missing temp = s.__getattribute__(self._name + 'i') except: s.insert(self._name + '_ion') # set to recalculate reversal potential automatically # the last 1 says to set based on global initial concentrations # e.g. nai0_na_ion, etc... h.ion_style(self._name + '_ion', 3, 2, 1, 1, 1, sec=s)
def __init__(self, regions=None, d=0, name=None, charge=0, initial=None): """s = rxd.Species(regions, d = 0, name = None, charge = 0, initial = None) Declare a species. Parameters: regions -- a Region or list of Region objects containing the species d -- the diffusion constant of the species (optional; default is 0, i.e. non-diffusing) name -- the name of the Species; used for syncing with HOC (optional; default is none) charge -- the charge of the Species (optional; default is 0) initial -- the initial concentration or None (if None, then imports from HOC if the species is defined at finitialize, else 0) Note: charge must match the charges specified in NMODL files for the same ion, if any.""" # TODO: if a list of sections is passed in, make that one region # _species_count is used to create a unique _real_name for the species global _species_count # TODO: check about the 0<x<1 problem alluded to in the documentation h.define_shape() self._name = name if name is not None: if not isinstance(name, str): raise Exception('Species name must be a string') if name in _defined_species and _defined_species[name]() is not None: raise Exception('Species "%s" previously defined: %r' % (name, _defined_species[name]())) else: name = _species_count self._id = _species_count _species_count += 1 _defined_species[name] = weakref.ref(self) if regions is None: raise Exception('Must specify region where species is present') if hasattr(regions, '__len__'): regions = list(regions) else: regions = list([regions]) if not all(isinstance(r, region.Region) for r in regions): raise Exception('regions list must consist of Region objects only') self._regions = regions self._real_name = name self.initial = initial self._charge = charge self._d = d # at this point self._name is None if unnamed or a string == name if # named if self._name is not None: ion_type = h.ion_register(name, charge) if ion_type == -1: raise Exception('Unable to register species: %s' % species) # insert the species if not already present for r in regions: if r.nrn_region in ('i', 'o'): for s in r.secs: try: ion_forms = [name + 'i', name + 'o', 'i' + name, 'e' + name] for i in ion_forms: # this throws an exception if one of the ion forms is missing temp = s.__getattribute__(name + 'i') except: s.insert(name + '_ion') # set to recalculate reversal potential automatically # the last 1 says to set based on global initial concentrations # e.g. nai0_na_ion, etc... h.ion_style(name + '_ion', 3, 2, 1, 1, 1, sec=s) self._real_secs = region._sort_secs(sum([r.secs for r in regions], [])) # TODO: at this point the sections are sorted within each region, but for # tree solver (which not currently using) would need sorted across # all regions if diffusion between multiple regions self._secs = [Section1D(self, sec, d, r) for r in regions for sec in r.secs] if self._secs: self._offset = self._secs[0]._offset else: self._offset = 0 self._has_adjusted_offsets = False self._assign_parents() self._update_region_indices()
def __init__(self, regions=None, d=0, name=None, charge=0, initial=None): """s = rxd.Species(regions, d = 0, name = None, charge = 0, initial = None) Declare a species. Parameters: regions -- a Region or list of Region objects containing the species d -- the diffusion constant of the species (optional; default is 0, i.e. non-diffusing) name -- the name of the Species; used for syncing with HOC (optional; default is none) charge -- the charge of the Species (optional; default is 0) initial -- the initial concentration or None (if None, then imports from HOC if the species is defined at finitialize, else 0) Note: charge must match the charges specified in NMODL files for the same ion, if any.""" # TODO: if a list of sections is passed in, make that one region # _species_count is used to create a unique _real_name for the species global _species_count # TODO: check about the 0<x<1 problem alluded to in the documentation h.define_shape() self._name = name if name is not None: if not isinstance(name, str): raise Exception('Species name must be a string') if name in _defined_species and _defined_species[name]( ) is not None: raise Exception('Species "%s" previously defined: %r' % (name, _defined_species[name]())) else: name = _species_count self._id = _species_count _species_count += 1 _defined_species[name] = weakref.ref(self) if regions is None: raise Exception('Must specify region where species is present') if hasattr(regions, '__len__'): regions = list(regions) else: regions = list([regions]) if not all(isinstance(r, region.Region) for r in regions): raise Exception('regions list must consist of Region objects only') self._regions = regions self._real_name = name self.initial = initial self._charge = charge self._d = d # at this point self._name is None if unnamed or a string == name if # named if self._name is not None: ion_type = h.ion_register(name, charge) if ion_type == -1: raise Exception('Unable to register species: %s' % species) # insert the species if not already present for r in regions: if r.nrn_region in ('i', 'o'): for s in r.secs: try: ion_forms = [ name + 'i', name + 'o', 'i' + name, 'e' + name ] for i in ion_forms: # this throws an exception if one of the ion forms is missing temp = s.__getattribute__(name + 'i') except: s.insert(name + '_ion') # set to recalculate reversal potential automatically # the last 1 says to set based on global initial concentrations # e.g. nai0_na_ion, etc... h.ion_style(name + '_ion', 3, 2, 1, 1, 1, sec=s) self._real_secs = region._sort_secs(sum([r.secs for r in regions], [])) # TODO: at this point the sections are sorted within each region, but for # tree solver (which not currently using) would need sorted across # all regions if diffusion between multiple regions self._secs = [ Section1D(self, sec, d, r) for r in regions for sec in r.secs ] if self._secs: self._offset = self._secs[0]._offset else: self._offset = 0 self._has_adjusted_offsets = False self._assign_parents() self._update_region_indices()