Any simple way to identify parent segment of point porcess

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

Moderator: hines

Any simple way to identify parent segment of point porcess

Postby rth » Mon Jul 10, 2017 7:30 pm

Dear All,

I apologize for a very trivial question.

I have a python class which reconstructs neuron morphology from an SWF file, sets channels and so on. Now with such a nice reconstruction, I need to create 6k - 10k synapses on dendrite tree. Moreover, there are about 5 different synapses classes, which may be nested (say NMDA and AMPA in the same location, with/without STDP, etc). Of course, I don't want to create multiple synaptic objects from the same synaptic class at the same segment of a dendrite, but after few hours search, I couldn't find a simple way to define if I have at a particular position this kind of synaptic object or not.

The code below illustrates what I need:

Code: Select all
class ampa:
   def __init__(self,compartment,position):
       self.syn = h.Exp2Syn(position, sec=compartment)

if there_is_an_ampa_syn_at_apical[24](0.23) :
    ampa_syn = get_ampa_synapse_object_which_was_create_at_apical[24](0.23)
else:
    ampa_syn = ampa(apical[24],0.23)

ncon = h.NetCon(some_source, ampa_syn)


Note that, if apical compartment has only three segments, apical.nseg=3, attempt to place synapse at position 0.15, 0.20, or 0.25 must return an existing synaptic object because it is the same segment.
rth
 
Posts: 37
Joined: Thu Jun 21, 2012 4:47 pm

Re: Any simple way to identify parent segment of point porce

Postby ramcdougal » Mon Jul 10, 2017 9:49 pm

There's nothing wrong with having multiple AMPA channels on the same segment. It's generally best to keep issues of numerics (e.g. discretization into segments) separate from the description of your model (e.g. what synapses are where). That way, you can change the mesh (e.g. increasing nseg to get a more accurate simulation or reducing the number of segments to get a faster runtime) without changing the model.

That said...

... to do what you describe, it's probably easiest to just use dictionaries to keep track of the locations of existing synapses and query those. The get_segment() method on a point process (like a synapse) returns a normalized location (i.e. x at the center of the segment) that can be used to provide a consistent identifier in the dictionary. For example, you could use something like this:

Code: Select all
from neuron import h
from collections import defaultdict

my_syns = defaultdict(lambda: {})

def syn_in_seg(seg):
    if seg.sec not in my_syns:
        return False
    if any(seg.sec(x) == seg for x in my_syns[seg.sec]): return True
    return False

def add_syn(seg):
    # returns the existing synapse in segment if any, else creates it
    if not syn_in_seg(seg):
        syn = h.ExpSyn(seg)
        my_syns[seg.sec][syn.get_segment().x] = syn
        return syn
    else:
        for x, syn in my_syns[seg.sec].iteritems():
            if seg.sec(x) == seg:
               return syn

s1 = h.Section(name='s1')
s1.nseg = 3
s2 = h.Section(name='s2')
syn1 = add_syn(s1(0.4))
syn2 = add_syn(s1(0.5))
syn3 = add_syn(s1(0.9))
syn4 = add_syn(s2(0.5))
syn5 = add_syn(s2(0.9))

print(syn1 == syn2)  # True
print(syn1 == syn3)  # False
print(syn1 == syn4)  # False
print(syn4 == syn5)  # True


If you want to allow synapses to be garbage collected, store weakrefs of them in the dictionaries.

Again though, you probably SHOULD NOT do this. Nature doesn't know anything about segments, so it places synapses without regard to numerical discretization.
ramcdougal
 
Posts: 89
Joined: Fri Nov 28, 2008 4:38 pm
Location: Yale School of Medicine

Re: Any simple way to identify parent segment of point porce

Postby ted » Tue Jul 11, 2017 10:08 am

There's nothing wrong with having multiple AMPA channels on the same segment
unless they belong to instances of an event-driven point process class (synaptic mechanism) that can be driven by multiple input streams, and you want to exploit that property in order to reduce model complexity and speed up simulations. Which apparently is rth's aim.

Regarding concerns about the effect that changing nseg may have the actual location of point processes, here are some suggestions.
1. During model setup, always defer attachment of point processes until after nseg has been specified.
2. After model setup, should it become necessary to discover whether the spatial grid is sufficiently fine for good simulation accuracy, increase nseg by an odd factor. Remember that the central difference approximation to the cable equation's second spatial derivative has second order accuracy, so tripling nseg will reduce spatial error by a factor of 9.
3. The only completely general way to ensure that a point process is at a particular location is to attach it to the 0 or 1 end of a section. This means that, if you want to attach a synapse to an arbitrary location along a neurite, you must break that neurite into two sections that are joined at the point where you want to attach the synapse. But be aware that this is not electrically equivalent to attaching a synapse to a location that lies in a segment, since internal nodes are associated with membrane capacitance, but the nodes at 0 and 1 are not.
ted
Site Admin
 
Posts: 4987
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: Any simple way to identify parent segment of point porce

Postby rth » Wed Jul 12, 2017 10:17 pm

Thank you, Ted,

unless they belong to instances of an event-driven point process class (synaptic mechanism) that can be driven by multiple input streams, and you want to exploit that property in order to reduce model complexity and speed up simulations. Which apparently is rth's aim.

As you know from Tikidji-Hamburyan et al 2017, the minimization of processor time per neuron is critical for some application, therefore you are absolutely right, I don't want to waste processor time and calculate additional dynamical variables. (the reviewer who quotes Cicero finally endorsed the publication :).

I understand that nseg should be set first. Actually, in my code nseg is set just after the geometry has been loaded. This ensures that segment isn't longer than 1/4 of electrical length. Thank you for the reminder, I'll add into the code a checkpoint, to be sure that the number of segments is an odd number.

The last point is quite dificalt to realize, specificaly in reconstructed morphology with many compartments. It would be very useful if I could reach segments inside a section, like this
Code: Select all
soma = h.Segment()
soma.nseg = 3
soma[0].cm = 0.1
soma[1].cm = 0.2
soma[2].cm = 0.3


Same for point process:
Code: Select all
dendrite = h.Segments()
dendrite.nseg=20
syn = h.Exp2Syn(dendrite[10], sec=dendrite)


I pretty well understand why it wasn't possible in hoc, but in python integration, it is quite simple, isn't it?
Last edited by rth on Wed Jul 12, 2017 11:18 pm, edited 1 time in total.
rth
 
Posts: 37
Joined: Thu Jun 21, 2012 4:47 pm

Re: Any simple way to identify parent segment of point porce

Postby rth » Wed Jul 12, 2017 10:47 pm

ramcdougal, thank you, for the suggestion! That is a very neat solution. But if we start from accuracy and electrical length, the number of segments is a constant, unless my dendrites start growing. From this point of view, the best strategy to minimize the amount of computation is to be sure that if NetCon(s) come to a particular segment of a dendrite, does not create a new synapse if there is the other one in the same segment.

Here is a simple example. We know that fibers create 30 synapses per 10 microns of dendrite length, but this is quite a thick dendrite, so 10 microns is just 3 segments. Therefore it is better to create just 3 synaptic objects and connect fibers (NetCon(s)) to them than 30 synapses. Unfortunately, your code will create 30 synapses with tiny step, which will be attached to just 3 compartments. Computational overhead will be 30/3 = 10!
rth
 
Posts: 37
Joined: Thu Jun 21, 2012 4:47 pm

Re: Any simple way to identify parent segment of point porce

Postby ramcdougal » Wed Jul 12, 2017 11:51 pm

Unfortunately, your code will create 30 synapses with tiny step, which will be attached to just 3 compartments. Computational overhead will be 30/3 = 10!


The add_syn function only creates at most one synapse per segment... so if nseg=3, then it creates at most three synapses. The trick is that it automatically figures out that e.g. dend(0.50001) == dend(0.5), and if you attempt to put a synapse at both places, the second time it just returns the existing object; nothing new is created.
ramcdougal
 
Posts: 89
Joined: Fri Nov 28, 2008 4:38 pm
Location: Yale School of Medicine

Re: Any simple way to identify parent segment of point porce

Postby ramcdougal » Thu Jul 13, 2017 12:04 am

rth wrote:The last point is quite dificalt to realize, specificaly in reconstructed morphology with many compartments. It would be very useful if I could reach segments inside a section, like this
Code: Select all
soma = h.Segment()
soma.nseg = 3
soma[0].cm = 0.1
soma[1].cm = 0.2
soma[2].cm = 0.3


Same for point process:
Code: Select all
dendrite = h.Segments()
dendrite.nseg=20
syn = h.Exp2Syn(dendrite[10], sec=dendrite)


I pretty well understand why it wasn't possible in hoc, but in python integration, it is quite simple, isn't it?


You can make a list of segments with just e.g.:

Code: Select all
somasegs = list(soma)


And then access them as you suggested:

Code: Select all
somasegs[2].cm = 1


In your specific case with a fixed nseg, this is fine, but the position based specification is generally preferable because it'll automatically do the right thing if you switch to running a more or less accurate simulation.
ramcdougal
 
Posts: 89
Joined: Fri Nov 28, 2008 4:38 pm
Location: Yale School of Medicine

Re: Any simple way to identify parent segment of point porce

Postby rth » Thu Jul 13, 2017 1:31 am

Very good point! Thank you!
But how will you use this list to setup point process? Maybe we can use float point position as segment #/nseg ? But this should link somehow to NEURON inner mechanism of position float point resolving.
rth
 
Posts: 37
Joined: Thu Jun 21, 2012 4:47 pm

Re: Any simple way to identify parent segment of point porce

Postby rth » Thu Jul 13, 2017 1:43 am

ramcdougal, I see your point.

Yes, you are right, it is tricky but may work. Actually very good idea. Of course, it is 'workaround', and it will be better to have a direct way inside NEURON+Python module, but it is nice to have a solution. Let me try :)
rth
 
Posts: 37
Joined: Thu Jun 21, 2012 4:47 pm


Return to NEURON + Python

Who is online

Users browsing this forum: No registered users and 2 guests