| 368 | | |
| 369 | | |
| 370 | | |
| 371 | | |
| | 368 | class _mh_build_nineml_celltype(type): |
| | 369 | """ |
| | 370 | Metaclass for building NineMLCellType subclasses |
| | 371 | Called by nineml_celltype_from_model |
| | 372 | """ |
| | 373 | def __new__(cls, name, bases, dct): |
| | 374 | |
| | 375 | |
| | 376 | #Extract Parameters Back out from Dict: |
| | 377 | nineml_model = dct['nineml_model'] |
| | 378 | synapse_components = dct['synapse_components'] |
| | 379 | |
| | 380 | # Reduce the model: |
| | 381 | from nineml.abstraction_layer import models |
| | 382 | reduction_process = models.ModelToSingleComponentReducer(nineml_model, componentname=name) |
| | 383 | reduced_component = reduction_process.reducedcomponent |
| | 384 | |
| | 385 | # New: |
| | 386 | dct["combined_model"] = reduction_process.reducedcomponent |
| | 387 | dct["default_parameters"] = dict( (name, 1.0) for name in reduced_component.parameters ) |
| | 388 | dct["default_initial_values"] = dict((name, 0.0) for name in reduced_component.state_variables) |
| | 389 | dct["synapse_types"] = [syn.namespace for syn in synapse_components] |
| | 390 | dct["standard_receptor_type"] = (dct["synapse_types"] == ('excitatory', 'inhibitory')) |
| | 391 | dct["injectable"] = True # need to determine this. How?? |
| | 392 | dct["conductance_based"] = True # how to determine this?? |
| | 393 | dct["model_name"] = name |
| | 394 | |
| | 395 | |
| | 396 | dct["recordable"] = [port.name for port in reduced_component.analog_ports] + ['spikes', 'regime'] |
| | 397 | dct["weight_variables"] = dict([ (syn.namespace,syn.namespace+'_'+syn.weight_connector ) |
| | 398 | for syn in synapse_components ]) |
| | 399 | #{'cobaInhib':'cobaInhib_q', 'cobaExcit':'cobaExcit_q',} |
| | 400 | |
| | 401 | |
| | 402 | logger.debug("Creating class '%s' with bases %s and dictionary %s" % (name, bases, dct)) |
| | 403 | # generate and compile NMODL code, then load the mechanism into NEUORN |
| | 404 | dct["builder"](reduced_component, dct["weight_variables"], hierarchical_mode=True) |
| | 405 | # TODO: weight variables should really be stored within combined_model |
| | 406 | |
| | 407 | return type.__new__(cls, name, bases, dct) |
| | 408 | |
| | 409 | |
| | 410 | |
| | 411 | class CoBaSyn(object): |
| | 412 | def __init__(self, namespace, weight_connector): |
| | 413 | self.namespace = namespace |
| | 414 | self.weight_connector = weight_connector |
| | 415 | |
| | 416 | |
| | 417 | |
| | 418 | |
| | 419 | |