Section of source for h. NetCon() in Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
catharina
Posts: 13
Joined: Tue May 30, 2017 9:42 am

Section of source for h. NetCon() in Python

Post by catharina »

Hello,

I am trying to connect instances of a very simple cell class SimpCell() with NetCons. I am working in python but the cell class SimpCell() is defined in a hoc file and I would like to keep the cell template in hoc.

I am able to create NetCon with a NONE source using "netcon = h.NetCon(None, celllist[jj].synI)". However I can't manage to create NetCons connected to the source cell. I think the problem is the "sec=section" argument for the h.NetCon() function. I have imported the gui to make sure the CVode object exists. I have also tried to retrieve pointers for the section with h.SectionRef() but this doesn't work either..

Here is the python code that I am using:

Code: Select all

import numpy as np
from neuron import h, gui

# Check if CVode exists
h.allobjects("CVode") # Does it work ???
print h.CVode # I assume it exists..

# ----------------------------------------DEFINE NETWORK TOPOLOGY------------------------------------------------------------------ 
# ----------------------------------- define Example network to try out connections----------------
A = np.matrix('0 -1 0 1;1 0 0 0;1 0 0 0;0 0 0 0')# A is directed adjacency matrix

#
# 2
# | (excitatory connection downwards)
# |
# 0 <--| 1 (excitatory connection to the left and an inhibitory to the right)
# | 
# | (excitatory connection downwards)
# 3
#


#-------------------------CREATE INSTANCES OF CELL CLASS "Simpcell"------------------------------------------------------
# very simple cell consisting of one soma and one dendrite with the pointprocesses ExpSyn attached
h.xopen('simpcell.hoc') # load hoc class definition
celllist= h.List() # list object that contains cell instances
#celllist=[] #List that contains instances of cells
N = A.shape[0] # number of nodes in network
for ii in range(N):
    celllist.append(h.SimpCell())
    
    
# Trying to see the topology to figure out the right section name or pointers
h.topology() # Doesn't give any output


# ------------------------CONNECT CELLS WITH EXCITATORY SYNAPSES---------------------------------------------------------
for ii in range(N): # outer loop should iterate over target cells/columns
    for jj in range(N):  # inner loop iterates over source cells/rows
        if (A[ii,jj]==1): #decide whether there should be a connection from this target to this source
            netcon = h.NetCon(celllist[ii].soma(1)._ref_v, celllist[jj].synE, [-20, 0, 0.05], sec=celllist[ii].soma)
#            netcon = h.NetCon(None, celllist[jj].synE) # NetCon without source. This works. Yeah..

            
 #------------------------CONNECT CELLS WITH INHIBITORY SYNAPSES---------------------------------------------------------
        elif (A[ii,jj]==-1): #decide whether there should be a connection from this target to this source')
##            sref = h.SectionRef(sec=celllist[ii].soma) # sref should be a pointer to the specified section???
#            sref = h.SectionRef() # should be a pointer to the currently accessed section
#            netcon = h.NetCon(celllist[ii].soma(1)._ref_v, celllist[jj].synI, [-20, 0, 0.01], sec=sref) # does not accept sec=sref as a section
            netcon = h.NetCon(celllist[ii].soma(1)._ref_v, celllist[jj].synE, [-20, 0, 0.05], sec=celllist[ii].soma) # I think it accepts sec=.. as a section
#            netcon = h.NetCon(None, celllist[jj].synI) #  NetCon without source. This works. Yeah..
And here is the cell class template in hoc:

Code: Select all

begintemplate SimpCell

public soma, dend, synE, synI, nc
public connect2target

create soma , dend

proc init() {

  create soma , dend

  soma {
    nseg=1
    L=30
    diam=30
    insert hh
  }

  dend {
    nseg=11
    L=1000
    diam=2
    insert pas
    g_pas=0.0001
    e_pas=-65
  }

  connect dend(0), soma(1)
  
  synapses()
}

objref synE, synI
proc synapses() {
  /* E0 */   dend synE = new ExpSyn(0.8)	// excitatory synapse
    synE.tau = 2
    synE.e = 0
  /* I1 */   dend synI = new ExpSyn(0.1)	// inhibitory synapse
    synI.tau = 50
    synI.e = -80
}
endtemplate SimpCell

I think there is something important that I am missing at this point and I can't seem to figure it out on my own. It would be very helpful if someone could help me with this.

Greetings, Catharina
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Section of source for h. NetCon() in Python

Post by ramcdougal »

Actually, the error is not related directly to the sec=celllist.soma; that was correct.

The convention in the NEURON documentation (and many others) is that [ and ] in the syntax specification is used to indicate optional parameters... i.e. the stuff inside the brackets can be included or not.

In your case then, simply drop the brackets; i.e. replace your two netcon lines with:

Code: Select all

            netcon = h.NetCon(celllist[ii].soma(1)._ref_v, celllist[jj].synE, -20, 0, 0.05, sec=celllist[ii].soma)
Four other minor comments on your code:
  • Consider using regular Python lists for the cells instead of an h.List. i.e. after defining N,

    Code: Select all

    celllist = [h.SimpCell() for ii in range(N)]
    
  • I can see the output from h.topology() If you can't, I'm guessing your working in a Jupyter/IPython notebook... this is fixed in the latest alpha versions.
  • Consider using h.load_file instead of h.xopen; think of the first as being like a Python import while the second is like a Python execfile. The difference is that the in the first case, the code in the file is guaranteed to be run exactly once, while in the second case if a separate file tried xopen'ing, it'd be rerun.
  • When you "from neuron import gui", that creates an instance of "h.CVode" named "h.cvode". There's no need to check explicitly.
catharina
Posts: 13
Joined: Tue May 30, 2017 9:42 am

Re: Section of source for h. NetCon() in Python

Post by catharina »

Hi,

Thank you very much for you fast reply and also the comments on my code! I wasn't aware of this bracket convention but that obviously makes things way easier.

Indeed I am using a IPython (in spyder) to run my python scripts together with NEURON 7.4 incorporated as a python package. Is there a simple way to upgrade from NEURON 7.4 to 7.5 using it as a python package in linux? Or do I REALLY have to redo all of the installation procedure?

I already tried pip to upgrade but that is obviously not supported. The thing is just that I don't feel like redoing all of the installation procedure for 7.5 because it took me horribly long the first time and I am afraid my whole system setup will blow up and bury me alive.

Greetings, Catharina
Post Reply