Changeset 375
- Timestamp:
- 06/18/08 17:30:31 (5 months ago)
- Files:
-
- trunk/src/common.py (modified) (2 diffs)
- trunk/src/neuron2/__init__.py (modified) (9 diffs)
- trunk/src/neuron2/cells.py (modified) (7 diffs)
- trunk/test/neuron2tests.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/common.py
r369 r375 22 22 """ 23 23 24 def __init__(self, parameter_name, standard_model):24 def __init__(self, parameter_name, model): 25 25 self.parameter_name = parameter_name 26 self.model_name = standard_model.__name__ 27 self.valid_parameter_names = standard_model.default_parameters.keys() 28 self.valid_parameter_names.sort() 26 self.model_name = model.__name__ 27 if issubclass(model, StandardModelType): 28 self.valid_parameter_names = model.default_parameters.keys() 29 self.valid_parameter_names.sort() 30 else: 31 self.valid_parameter_names = ['unknown'] 29 32 30 33 def __str__(self): … … 722 725 for i in range(1, self.ndim): 723 726 self.size *= self.dim[i] 724 self.cell = None # to be defined by child, simulator-specific classes727 ##self.cell = None # to be defined by child, simulator-specific classes 725 728 726 729 def __getitem__(self, addr): trunk/src/neuron2/__init__.py
r371 r375 116 116 common.IDMixin.__init__(self) 117 117 118 def _build_cell(self, cell type, parent=None):118 def _build_cell(self, cell_model, cell_parameters, parent=None): 119 119 gid = int(self) 120 self._cell = cell type.model(**celltype.parameters)# create the cell object121 parallel_context.set_gid2node(gid, rank()) # assign the gid to this node120 self._cell = cell_model(**cell_parameters) # create the cell object 121 parallel_context.set_gid2node(gid, rank()) # assign the gid to this node 122 122 nc = neuron.NetCon(self._cell.source, None) # } associate the cell spike source 123 parallel_context.cell(gid, nc.hoc_obj) # } with the gid (using a temporary NetCon)123 parallel_context.cell(gid, nc.hoc_obj) # } with the gid (using a temporary NetCon) 124 124 self.parent = parent 125 125 … … 139 139 # ============================================================================== 140 140 141 def _create(cell type, n, parent=None):141 def _create(cellclass, param_dict, n, parent=None): 142 142 """ 143 143 Function used by both `create()` and `Population.__init__()` … … 145 145 global gid_counter 146 146 assert n > 0, 'n must be a positive integer' 147 if isinstance(cellclass, basestring): # cell defined in hoc template 148 try: 149 cell_model = getattr(h, cellclass) 150 except AttributeError: 151 raise common.InvalidModelError("There is no hoc template called %s" % cellclass) 152 cell_parameters = param_dict or {} 153 elif issubclass(cellclass, common.StandardCellType): 154 celltype = cellclass(param_dict) 155 cell_model = celltype.model 156 cell_parameters = celltype.parameters 157 else: 158 cell_model = cellclass 159 cell_parameters = param_dict 147 160 first_id = gid_counter 148 161 last_id = gid_counter + n … … 153 166 if is_local: 154 167 all_ids[i] = ID(id) 155 all_ids[i]._build_cell(cell type, parent=parent)168 all_ids[i]._build_cell(cell_model, cell_parameters, parent=parent) 156 169 gid_counter += n 157 170 return all_ids, mask_local, first_id, last_id … … 163 176 If n==1, return just the single id. 164 177 """ 165 all_ids, mask_local, first_id, last_id = _create(cellclass (param_dict), n)178 all_ids, mask_local, first_id, last_id = _create(cellclass, param_dict, n) 166 179 for id in all_ids[mask_local]: 167 180 id.cellclass = cellclass 168 181 initializer.register(*all_ids[mask_local]) 182 all_ids = all_ids.tolist() # not sure this is desirable, but it is consistent with the other modules 169 183 if len(all_ids) == 1: 170 184 all_ids = all_ids[0] … … 176 190 Used by `connect()` and the `Connector` classes. 177 191 """ 192 if not isinstance(source, int) or source > gid_counter or source < 0: 193 raise common.ConnectionError("Invalid source ID: %s" % source) 194 if not isinstance(target, ID): 195 raise common.ConnectionError("Invalid target ID: %s" % target) 178 196 if synapse_type is None: 179 197 synapse_type = weight>=0 and 'excitatory' or 'inhibitory' … … 215 233 for src in sources: 216 234 nc = _single_connect(src, tgt, weight, delay, synapse_type) 217 connection_list.append( (src, tgt, nc))235 connection_list.append(nc) 218 236 return connection_list 219 237 … … 287 305 'v': Recorder('v', population=self)} 288 306 self.label = self.label or 'population%d' % Population.nPop 289 self.celltype = cellclass(cellparams) 307 if isinstance(cellclass, type) and issubclass(cellclass, common.StandardCellType): 308 self.celltype = cellclass(cellparams) 309 else: 310 self.celltype = cellclass 290 311 291 312 # Build the arrays of cell ids … … 293 314 # All are stored in a single numpy array for easy lookup by address 294 315 # The local cells are also stored in a list, for easy iteration 295 self._all_ids, self._mask_local, self.first_id, self.last_id = _create( self.celltype, self.size, parent=self)316 self._all_ids, self._mask_local, self.first_id, self.last_id = _create(cellclass, cellparams, self.size, parent=self) 296 317 self._local_ids = self._all_ids[self._mask_local] 297 318 self._all_ids = self._all_ids.reshape(self.dim) trunk/src/neuron2/cells.py
r371 r375 14 14 ResetRefrac = neuron.new_point_process('ResetRefrac') 15 15 VecStim = neuron.new_hoc_class('VecStim') 16 NetStim = neuron.new_hoc_class('VecStim') 16 17 17 18 def _new_property(obj_hierarchy, attr_name): … … 45 46 v_thresh=-55, t_refrac=2, i_offset=0, v_reset=None, 46 47 v_init=None, tau_e=5, tau_i=5, e_e=0, e_i=-70): 48 49 if v_reset is None: 50 v_reset = v_rest 51 if v_init is None: 52 v_init = v_rest 47 53 48 54 # initialise Section object with 'pas' mechanism … … 54 60 55 61 # insert synapses 56 assert syn_type in ('current', 'conductance'), "syn_type must be either 'current' or 'conductance' "62 assert syn_type in ('current', 'conductance'), "syn_type must be either 'current' or 'conductance'. Actual value is %s" % syn_type 57 63 assert syn_shape in ('alpha', 'exp'), "syn_type must be either 'alpha' or 'exp'" 58 64 synapse_model = StandardIF.synapse_models[syn_type][syn_shape] … … 77 83 for name in self.parameter_names: 78 84 setattr(self, name, locals()[name]) 79 if self.v_reset is None: 80 self.v_reset = self.v_rest 81 if self.v_init is None: 82 self.v_init = self.v_rest 85 83 86 self.spiketimes = neuron.Vector(0) 84 87 … … 126 129 class SpikeSource(object): 127 130 128 def __init__(self, source_type, s piketimes=[]):131 def __init__(self, source_type, start=0, interval=1e12, number=0, spiketimes=[]): 129 132 self.source = source_type() 130 133 if spiketimes: … … 133 136 self.do_not_record = True 134 137 else: 138 for name in 'start', 'interval', 'number': 139 setattr(self.source, name, locals()[name]) 135 140 self.spiketimes = neuron.Vector() 136 141 self.do_not_record = False … … 286 291 def __init__(self, parameters): 287 292 common.SpikeSourcePoisson.__init__(self, parameters) 288 self.parameters['source_type'] = 'NetStim' 289 self.parameters['noise'] = 1 290 293 self.parameters['source_type'] = NetStim 291 294 292 295 class SpikeSourceArray(SpikeSource, common.SpikeSourceArray):

