Connect producing different results in hoc and python

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

Moderator: hines

Post Reply
vellamike

Connect producing different results in hoc and python

Post by vellamike »

I am transporting some code from hoc to python and encountered this problem. The code loads a morphology using xopen and then after creating some sections connects them to the soma of the morphology thus:

Code: Select all

  soma connect hill(0), 1
  hill connect iseg(0), 1
  iseg connect myelin[0](0), 1
  myelin[0] connect node[0](0), 1

  for i=0,n_axon_seg-2  { 
      node[i] connect myelin[i+1](0), 1 
      myelin[i+1] connect node[i+1](0), 1
When I did what I thought was the equivalent in python:

Code: Select all

    n_axon_seg=5
    h.soma.connect(hill,0,1)
    hill.connect(iseg,0,1)
    iseg.connect(myelin_sections[0],0,1)
    myelin_sections[0].connect(node_sections[0],0,1)
     
    for i in range(0,n_axon_seg-1):
        node_sections[i].connect(myelin_sections[i+1](0),1)
        myelin_sections[i+1].connect(node_sections[i+1],0,1)
my shape plot looks weird (split into two separate halves, one each end of the axon). And I get the following error:
Notice: soma(0) had previously been connected to parent sapath(0)
I hope this is enough information to solve this problem?
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Connect producing different results in hoc and python

Post by ted »

Here's how to answer your own question:

Execute your hoc code, then type
topology()
at the oc> prompt and note what you got.

Then execute your Python code, and type
h.topology()
at the >>> prompt and see what you got.

It will be most illuminating if you would report your findings.

Hint 1: If you see strange names like
PySec_b7f48aa0
you can decipher them by typing the name of a section at the >>> prompt and seeing what Python returns (for me, this particular Python object is the soma).

Hint 2: How to interpret topology()'s printout: in this example

Code: Select all

|-|       soma(0-1)
   `|       dend1(1-0)
     `|       dend2(1-0)
 `|       ax(0-1)
means that ax's 0 end is attached to the 0 end of soma, which is fine.
However, dend1's 1 end is connected to soma's 1 end, and dend2's 1 end is attached to the 0 end of dend1--which is OK as far as the cable equation is concerned, but is going to cause trouble with shape plots (for a pertinent case study see chapter 6 of the NEURON Book) and is also going to cause trouble in any code that assumes that distance from the root of the model cell (the 0 end of the root section) increases with increasing range.
vellamike

Re: Connect producing different results in hoc and python

Post by vellamike »

Thanks for your help, I've used the topology() method to try and solve this problem but don't have enough experience to interpret what I'm seeing. Here is the topology() output of the hoc code:

Code: Select all

|-|       sapath(0-1)
   `|       apath[0](0-1)
     `|       apath[1](0-1)
       `|       apath[2](0-1)
         `|       apath[3](0-1)
           `|       apath[4](0-1)
             `|       apath[5](0-1)
               `|       apath[6](0-1)
                 `|       apath[7](0-1)
                   `|       apath[8](0-1)
                     `|       apath[9](0-1)
                       `|       apath[10](0-1)
                         `|       apath[11](0-1)
                           `|       apath[12](0-1)
                             `|       apath[13](0-1)
                               `|       apath[14](0-1)
                                 `|       apath[15](0-1)
                                   `|       apath[16](0-1)
                                     `|       apath[17](0-1)
                                       `|       apath[18](0-1)
                                         `|       apath[19](0-1)
                                           `|       apath[20](0-1)
                                             `|       apath[21](0-1)
                                               `|       apath[22](0-1)
                                                 `|       apath[23](0-1)
                                                   `|       apath[24](0-1)
                                                     `|       apath[25](0-1)
                                                       `|       apath[26](0-1)
                                                         `|       apath[27](0-1)
                                                           `|       apath[28](0-1)
                                                             `|       apath[29](0-1)
                                                               `|       apath[30](0-1)
                                                                 `|       apath[31](0-1)
                                                                   `|       apath[32](0-1)
                                                                     `|       apath[33](0-1)
                                                                       `|       apath[34](0-1)
                                                                         `|       apath[35](0-1)
                                                                           `|       apath[36](0-1)
                                                                             `|       apath[37](0-1)
                                                                               `|       apath[38](0-1)
                                                                                 `|       apath[39](0-1)
                                                                                   `|       apath[40](0-1)
                                                                                     `|       apath[41](0-1)
                                                                                       `|       apath[42](0-1)
                                                                                         `|       apath[43](0-1)
                                                                                           `|       apath[44](0-1)
                                                                                             `|       apath[45](0-1)
                                                                                              `|       atip[10](0-1)
                                                                         `-|       dend1[0](0-1)
                                                                           `|       atip[32](0-1)
                                                                     `|       dend1[1](0-1)
                                                                       `|       dend1[2](0-1)
                                                                        `|       atip[31](0-1)
                                                                       `|       dend1[3](0-1)
                                                                         `|       dend1[4](0-1)
                                                                          `|       atip[30](0-1)
                                                                         `|       dend1[5](0-1)
                                                                          `|       atip[29](0-1)
                                   `--|       dend1[6](0-1)
                                       `|       dend1[7](0-1)
                                        `|       atip[28](0-1)
                                       `|       dend1[8](0-1)
                                        `|       atip[27](0-1)
                         `|       dend1[9](0-1)
                           `|       dend1[10](0-1)
                            `|       atip[26](0-1)
                           `|       dend1[11](0-1)
                            `|       atip[25](0-1)
                       `|       dend1[12](0-1)
                         `-|       dend1[13](0-1)
                            `-|       dend1[14](0-1)
                              `|       atip[24](0-1)
               `-|       dend1[15](0-1)
                  `|       dend1[16](0-1)
                   `|       atip[23](0-1)
             `--|       dend1[17](0-1)
               `|       atip[22](0-1)
           `|       dend1[18](0-1)
             `|       dend1[19](0-1)
               `|       dend1[20](0-1)
                `|       atip[21](0-1)
         `---|       dend1[21](0-1)
            `|       atip[20](0-1)
 `|       soma(0-1)
   `|       s(0-1)
     `|       dend3[0](0-1)
       `|       dend3[1](0-1)
        `|       atip[3](0-1)
       `|       dend3[2](0-1)
         `|       dend3[3](0-1)
           `|       dend3[4](0-1)
             `-|       dend3[5](0-1)
                `-|       dend3[6](0-1)
                  `|       atip[2](0-1)
             `|       dend3[7](0-1)
         `|       dend3[8](0-1)
           `|       dend3[9](0-1)
             `-|       dend3[10](0-1)
                `-|       dend3[11](0-1)
                  `|       atip[1](0-1)
           `--|       dend3[12](0-1)
               `-|       dend3[13](0-1)
                 `|       atip[0](0-1)
   `----|       hill(0-1)
         `----|       iseg(0-1)
               `----|       myelin[0](0-1)
                     `|       node[0](0-1)
                       `----|       myelin[1](0-1)
                             `|       node[1](0-1)
                               `----|       myelin[2](0-1)
                                     `|       node[2](0-1)
                                       `----|       myelin[3](0-1)
                                             `|       node[3](0-1)
                                               `----|       myelin[4](0-1)
                                                     `|       node[4](0-1)
  `|       dend0[0](0-1)
    `|       dend0[1](0-1)
      `|       dend0[2](0-1)
        `|       dend0[3](0-1)
          `|       dend0[4](0-1)
            `|       dend0[5](0-1)
             `|       atip[7](0-1)
            `|       dend0[6](0-1)
              `-|       dend0[7](0-1)
                `|       atip[6](0-1)
      `|       dend0[8](0-1)
        `|       dend0[9](0-1)
          `-|       dend0[10](0-1)
            `|       atip[5](0-1)
    `|       dend0[11](0-1)
      `|       dend0[12](0-1)
        `-|       dend0[13](0-1)
           `-|       dend0[14](0-1)
             `|       atip[4](0-1)
  `|       leakyseal(0-1)
  `|       dend2[0](0-1)
    `|       dend2[1](0-1)
      `---|       dend2[2](0-1)
         `|       atip[9](0-1)
      `|       dend2[3](0-1)
       `|       atip[8](0-1)
  `|       dend4[0](0-1)
    `|       dend4[1](0-1)
      `|       dend4[2](0-1)
       `|       atip[12](0-1)
      `|       dend4[3](0-1)
       `|       atip[11](0-1)
  `-|       dend5[0](0-1)
     `-|       dend5[1](0-1)
       `|       atip[13](0-1)
  `|       dend6[0](0-1)
    `|       dend6[1](0-1)
      `|       dend6[2](0-1)
        `|       dend6[3](0-1)
          `|       dend6[4](0-1)
            `-|       dend6[5](0-1)
              `|       atip[19](0-1)
          `|       dend6[6](0-1)
           `|       atip[18](0-1)
        `--|       dend6[7](0-1)
          `|       atip[17](0-1)
    `|       dend6[8](0-1)
      `|       dend6[9](0-1)
        `-|       dend6[10](0-1)
          `|       atip[16](0-1)
        `-|       dend6[11](0-1)
          `|       atip[15](0-1)
      `-|       dend6[12](0-1)
        `|       atip[14](0-1)

1 
and this is the output of above attempt at a python-equivalent:

Code: Select all

Notice: soma(0) had previously been connected to parent sapath(0)

|-|       sapath(0-1)
   `|       apath[0](0-1)
     `|       apath[1](0-1)
       `|       apath[2](0-1)
         `|       apath[3](0-1)
           `|       apath[4](0-1)
             `|       apath[5](0-1)
               `|       apath[6](0-1)
                 `|       apath[7](0-1)
                   `|       apath[8](0-1)
                     `|       apath[9](0-1)
                       `|       apath[10](0-1)
                         `|       apath[11](0-1)
                           `|       apath[12](0-1)
                             `|       apath[13](0-1)
                               `|       apath[14](0-1)
                                 `|       apath[15](0-1)
                                   `|       apath[16](0-1)
                                     `|       apath[17](0-1)
                                       `|       apath[18](0-1)
                                         `|       apath[19](0-1)
                                           `|       apath[20](0-1)
                                             `|       apath[21](0-1)
                                               `|       apath[22](0-1)
                                                 `|       apath[23](0-1)
                                                   `|       apath[24](0-1)
                                                     `|       apath[25](0-1)
                                                       `|       apath[26](0-1)
                                                         `|       apath[27](0-1)
                                                           `|       apath[28](0-1)
                                                             `|       apath[29](0-1)
                                                               `|       apath[30](0-1)
                                                                 `|       apath[31](0-1)
                                                                   `|       apath[32](0-1)
                                                                     `|       apath[33](0-1)
                                                                       `|       apath[34](0-1)
                                                                         `|       apath[35](0-1)
                                                                           `|       apath[36](0-1)
                                                                             `|       apath[37](0-1)
                                                                               `|       apath[38](0-1)
                                                                                 `|       apath[39](0-1)
                                                                                   `|       apath[40](0-1)
                                                                                     `|       apath[41](0-1)
                                                                                       `|       apath[42](0-1)
                                                                                         `|       apath[43](0-1)
                                                                                           `|       apath[44](0-1)
                                                                                             `|       apath[45](0-1)
                                                                                              `|       atip[10](0-1)
                                                                         `-|       dend1[0](0-1)
                                                                           `|       atip[32](0-1)
                                                                     `|       dend1[1](0-1)
                                                                       `|       dend1[2](0-1)
                                                                        `|       atip[31](0-1)
                                                                       `|       dend1[3](0-1)
                                                                         `|       dend1[4](0-1)
                                                                          `|       atip[30](0-1)
                                                                         `|       dend1[5](0-1)
                                                                          `|       atip[29](0-1)
                                   `--|       dend1[6](0-1)
                                       `|       dend1[7](0-1)
                                        `|       atip[28](0-1)
                                       `|       dend1[8](0-1)
                                        `|       atip[27](0-1)
                         `|       dend1[9](0-1)
                           `|       dend1[10](0-1)
                            `|       atip[26](0-1)
                           `|       dend1[11](0-1)
                            `|       atip[25](0-1)
                       `|       dend1[12](0-1)
                         `-|       dend1[13](0-1)
                            `-|       dend1[14](0-1)
                              `|       atip[24](0-1)
               `-|       dend1[15](0-1)
                  `|       dend1[16](0-1)
                   `|       atip[23](0-1)
             `--|       dend1[17](0-1)
               `|       atip[22](0-1)
           `|       dend1[18](0-1)
             `|       dend1[19](0-1)
               `|       dend1[20](0-1)
                `|       atip[21](0-1)
         `---|       dend1[21](0-1)
            `|       atip[20](0-1)
|-|       node4(0-1)
 `|       myelin4(1-0)
   `|       node3(1-0)
     `----|       myelin3(1-0)
           `|       node2(1-0)
             `----|       myelin2(1-0)
                   `|       node1(1-0)
                     `----|       myelin1(1-0)
                           `|       node0(1-0)
                             `----|       myelin0(1-0)
                                   `----|       iseg(1-0)
                                         `|       hill(1-0)
                                           `|       soma(1-0)
                                            `|       dend6[0](0-1)
                                              `|       dend6[1](0-1)
                                                `|       dend6[2](0-1)
                                                  `|       dend6[3](0-1)
                                                    `|       dend6[4](0-1)
                                                      `-|       dend6[5](0-1)
                                                        `|       atip[19](0-1)
                                                    `|       dend6[6](0-1)
                                                     `|       atip[18](0-1)
                                                  `--|       dend6[7](0-1)
                                                    `|       atip[17](0-1)
                                              `|       dend6[8](0-1)
                                                `|       dend6[9](0-1)
                                                  `-|       dend6[10](0-1)
                                                    `|       atip[16](0-1)
                                                  `-|       dend6[11](0-1)
                                                    `|       atip[15](0-1)
                                                `-|       dend6[12](0-1)
                                                  `|       atip[14](0-1)
                                            `-|       dend5[0](0-1)
                                               `-|       dend5[1](0-1)
                                                 `|       atip[13](0-1)
                                            `|       dend4[0](0-1)
                                              `|       dend4[1](0-1)
                                                `|       dend4[2](0-1)
                                                 `|       atip[12](0-1)
                                                `|       dend4[3](0-1)
                                                 `|       atip[11](0-1)
                                            `|       dend2[0](0-1)
                                              `|       dend2[1](0-1)
                                                `---|       dend2[2](0-1)
                                                   `|       atip[9](0-1)
                                                `|       dend2[3](0-1)
                                                 `|       atip[8](0-1)
                                            `|       leakyseal(0-1)
                                            `|       dend0[0](0-1)
                                              `|       dend0[1](0-1)
                                                `|       dend0[2](0-1)
                                                  `|       dend0[3](0-1)
                                                    `|       dend0[4](0-1)
                                                      `|       dend0[5](0-1)
                                                       `|       atip[7](0-1)
                                                      `|       dend0[6](0-1)
                                                        `-|       dend0[7](0-1)
                                                          `|       atip[6](0-1)
                                                `|       dend0[8](0-1)
                                                  `|       dend0[9](0-1)
                                                    `-|       dend0[10](0-1)
                                                      `|       atip[5](0-1)
                                              `|       dend0[11](0-1)
                                                `|       dend0[12](0-1)
                                                  `-|       dend0[13](0-1)
                                                     `-|       dend0[14](0-1)
                                                       `|       atip[4](0-1)
                                           `|       s(0-1)
                                             `|       dend3[0](0-1)
                                               `|       dend3[1](0-1)
                                                `|       atip[3](0-1)
                                               `|       dend3[2](0-1)
                                                 `|       dend3[3](0-1)
                                                   `|       dend3[4](0-1)
                                                     `-|       dend3[5](0-1)
                                                        `-|       dend3[6](0-1)
                                                          `|       atip[2](0-1)
                                                     `|       dend3[7](0-1)
                                                 `|       dend3[8](0-1)
                                                   `|       dend3[9](0-1)
                                                     `-|       dend3[10](0-1)
                                                        `-|       dend3[11](0-1)
                                                          `|       atip[1](0-1)
                                                   `--|       dend3[12](0-1)
                                                       `-|       dend3[13](0-1)
                                                         `|       atip[0](0-1)

1.0
So the two certainly look different but I can't understand why the python code I used to connect the sections should produce different results to the hoc code.
vellamike

Re: Connect producing different results in hoc and python

Post by vellamike »

Fixed it! When I had a close look at topology I realised that parents/children were reversed. Unfortunately I don't know enough about this so I'll have to read up. The Python code which gave the equivalent result was:

Code: Select all

    n_axon_seg=5
    hill.connect(h.soma,1,0)
    iseg.connect(hill,1,0)
    myelin_sections[0].connect(iseg,1,0)
    node_sections[0].connect(myelin_sections[0],1,0)
     
    for i in range(0,n_axon_seg-1):
        myelin_sections[i+1].connect(node_sections[i],1,0)
        node_sections[i+1].connect(myelin_sections[i+1],1,0)
I found the h.connect statement is a bit confusing because it took me quite some time to realise that

Code: Select all

apical.connect(soma,1,0)
is the same as

Code: Select all

connect apical(0), soma(1) 
but not the same as

Code: Select all

soma.connect(apical,0,1)
Post Reply