Esempio n. 1
0
 def updateFromMoose(self):
     """Update the tick dt from the tick objects"""
     ticks = moose.ematrix('/clock/tick')
     # Items at position 0 are the column headers, hence ii+1
     for ii in range(ticks[0].localNumField):
         self.updateTextFromTick(ii)
     self.updateCurrentTime()
Esempio n. 2
0
 def __getTickListWidget(self):
     layout = QtGui.QGridLayout()
     # Set up the column titles
     layout.addWidget(QtGui.QLabel('Tick'), 0, 0)
     layout.addWidget(QtGui.QLabel('dt'), 0, 1)
     layout.addWidget(QtGui.QLabel('Targets (wildcard)'), 0, 2, 1, 2)
     layout.setRowStretch(0, 1)
     # Create one row for each tick. Somehow ticks.shape is
     # (16,) while only 10 valid ticks exist. The following is a hack
     ticks = moose.ematrix('/clock/tick')
     for ii in range(ticks[0].localNumField):
         tt = ticks[ii]
         layout.addWidget(QtGui.QLabel(tt.path), ii+1, 0)
         layout.addWidget(QtGui.QLineEdit(str(tt.dt)), ii+1, 1)
         layout.addWidget(QtGui.QLineEdit(''), ii+1, 2, 1, 2)
         layout.setRowStretch(ii+1, 1)            
     # We add spacer items to the last row so that expansion
     # happens at bottom. All other rows have stretch = 1, and
     # the last one has 0 (default) so that is the one that
     # grows
     rowcnt = layout.rowCount()
     for ii in range(3):
         layout.addItem(QtGui.QSpacerItem(1, 1), rowcnt, ii)
     layout.setRowStretch(rowcnt, 10)
     # layout.setColumnStretch(1, 1)
     layout.setColumnStretch(2, 2)
     widget = QtGui.QWidget()
     widget.setLayout(layout)
     return widget
Esempio n. 3
0
    def clearPreviousModel(self,modelpathTypeDict):
        for path in modelpathTypeDict.keys():
            if modelpathTypeDict[path] == 'NEUROML':
                if moose.exists('/cells'):
                    moose.delete(moose.ematrix('/cells'))
                if moose.exists('/elec'):
                    moose.delete(moose.ematrix('/elec'))
            elif modelpathTypeDict[path] == 'KKIT':
                if moose.exists('/KKIT'):
                    moose.delete(moose.ematrix('/KKIT'))
            else:
                print 'Did not delete previously loaded file. Restart moose instead'
            '''Harsha Dict is also cleaned up '''
            modelpathTypeDict = {}

        for child in moose.element('/library').getField('children'):
            moose.delete(child)
Esempio n. 4
0
def create_tree(tree, parentpath=''):
    if not tree:
        return
    node = tree[0]
    parent = moose.ematrix(parentpath + '/' + node[0], 1, node[1])
    if len(tree) < 2:
        return
    for sub in tree[1:]:
        create_tree(sub, parent.path)
Esempio n. 5
0
def create_population(container, size):
    """Create a population of `size` single compartmental neurons with
    Na and K channels. Also create SpikeGen objects and SynChan
    objects connected to these which can act as plug points for
    setting up synapses later."""
    path = container.path
    comps = moose.ematrix(path+'/soma', size, 'Compartment')    
    Em = EREST_ACT+10.613e-3
    comps.Em = np.random.normal(Em, np.abs(Em) * 0.1, size)
    comps.initVm = np.random.normal(EREST_ACT, np.abs(EREST_ACT) * 0.1, size)
    comps.Cm = [7.85e-9] * size
    comps.Rm = [4.2e5] * size
    comps.Ra = [190.98] * size
    nachan = moose.copy(create_na_proto(), container, 'na', size)
    nachan.Gbar = [0.942e-3] * size
    nachan.Ek = [115e-3+EREST_ACT] * size
    moose.connect(nachan, 'channel', comps, 'channel', 'OneToOne')
    kchan = moose.copy(create_k_proto(), container, 'k', size)
    kchan.Gbar = [0.2836e-4] * size
    kchan.Ek = [-12e-3+EREST_ACT] * size
    moose.connect(kchan, 'channel', comps, 'channel', 'OneToOne')
    synchan = moose.ematrix(path + '/synchan', size, 'SynChan')
    synchan.Gbar = [1e-8] * size
    synchan.tau1 = [2e-3] * size
    synchan.tau2 = [2e-3] * size
    # Question: What is this going to do? Connect comps[ii] to comps[ii]/synchan? 
    # if we had synchan under each  compartment created like: synchan = moose.SynChan(comps.path + '/synchan')

    m = moose.connect(comps, 'channel', synchan, 'channel', 'OneToOne')

    ## Or would this have been the correct approach?
    # for c in comps: moose.connect(c, 'channel', moose.SynChan(c.path+'/synchan'), 'channel', 'Single')
    spikegen = moose.ematrix(path + '/spikegen', size, 'SpikeGen')
    spikegen.threshold = [0.0] * size
    m = moose.connect(comps, 'VmOut', spikegen, 'Vm', 'OneToOne')
    return {'compartment': comps,
            'spikegen': spikegen,
            'synchan': synchan}
Esempio n. 6
0
def restorestate(filename):    
    wfields = {}
    for cinfo in moose__.element('/classes').children:
        cname = cinfo[0].name
        wfields[cname] = [f[len('set_'):] for f in moose__.getFieldNames(cname, 'destFinfo') 
                          if f.startswith('set_') and f not in ['set_this', 'set_name', 'set_lastDimension', 'set_runTime'] and not f.startswith('set_num_')]
    with h5.File(filename, 'r') as fd:
        typeinfo = fd['/metadata/typeinfo'][:]
        classdict = {}
        dimsdict = dict(zip(typeinfo['path'], typeinfo['dims']))
        classdict = dict(zip(typeinfo['path'], typeinfo['class']))
        parentdict = dict(zip(typeinfo['path'], typeinfo['parent']))
        sorted_paths = sorted(typeinfo['path'], key=lambda x: x.count('/'))
        for path in sorted_paths:
            name = path.rpartition('/')[-1].partition('[')[0]
            moose__.ematrix(parentdict[path] + '/' + name, eval(dimsdict[path]), classdict[path])
        for key in fd['/elements']:
            dset = fd['/elements/'][key][:]
            fieldnames = dset.dtype.names
            for ii in range(len(dset)):
                obj = moose__.element(dset['path'][ii])
                for f in wfields[obj.class_]:
                    obj.setField(f, dset[f][ii])
Esempio n. 7
0
def extract_ftype_doc(cinfo, finfotype, docio):
    """Extract field documentation for all fields of type `finfotype`
    in class `cinfo` into `docio`.

    Parameters
    ----------
    cinfo: moose.Cinfo 
	class info object in MOOSE.
    
    finfotype: str
	finfo type (valueFinfo/srcFinfo/destFinfo/lookupFinfo/sharedFinfo

    docio: StringIO
	IO object to write the documentation into
    """
    numfinfo = moose.getField(cinfo, 'num_'+finfotype, 'unsigned')
    finfo = moose.ematrix('%s/%s' % (cinfo.path, finfotype))
    data = []
    inf = float( 'Inf' )
    max_width_name = -inf
    max_width_type = -inf
    for ii in range(numfinfo):
	fid = moose.melement(finfo, 0, ii, 0)
	
	if finfotype == 'destFinfo' and (fid.name.startswith('get_') or
					 fid.name.startswith('set_')):
	    continue
	
	dtype = type_mangling_regex.sub('', fid.type)
	name = '**`{0}`**'.format( fid.name )
	dtype = '`{0}`'.format( dtype )
	doc = fid.docs
	
	data.append( [ name, dtype, doc ] )
	
	if len( name ) > max_width_name:
	    max_width_name = len( name )
	
	if len( dtype ) > max_width_type:
	    max_width_type = len( dtype )
    
    if len( data ) == 0:
	return
    
    padding = 2
    format_string = '{{0: <{width}}}'
    format_strings = (
	format_string.format( width = max_width_name + padding ),
	format_string.format( width = max_width_type + padding ),
	'{0}'
    )
    col3_alignment = format_strings[0].format('') + format_strings[1].format('')
    for row in data:
	row[2] = row[2].replace( '\n', '\n' + col3_alignment )
    
    column_headings = ( 'Field', 'Type', 'Description' )
    docio.write( '\n' )
    for ( column_heading, format_string ) in zip( column_headings, format_strings ):
	docio.write( format_string.format( column_heading ) )
    docio.write( '\n' )
    for format_string in format_strings:
	docio.write( format_string.format( '----' ) )
    docio.write( '\n' )
    
    for row in data:
	for ( field, format_string ) in zip( row, format_strings ):
	    docio.write( format_string.format( field ) )
	docio.write( '\n' )
Esempio n. 8
0
 def updateTextFromTick(self, tickNo):
     tick = moose.ematrix('/clock/tick')[tickNo]
     widget = self.tickListWidget.layout().itemAtPosition(tickNo + 1, 1).widget()
     if widget is not None and isinstance(widget, QtGui.QLineEdit):
         widget.setText(str(tick.dt))