How to connect multiple compartments of an axon using a for loop?

Particularly useful chunks of hoc and/or NMODL code. May be pedestrian or stunningly brilliant, may make you gasp or bring tears to your eyes, but always makes you think "I wish I had written that; I'm sure going to steal it."
Post Reply
zyousuf
Posts: 2
Joined: Thu Jan 23, 2020 12:46 pm

How to connect multiple compartments of an axon using a for loop?

Post by zyousuf »

So I have an axon which has a 1000 compartments. I have written a for loop that connects the [1] part of one compartment to the [0] of the other and so on until all 1000 compartments are connected. However, I then get the following error: "axon_1[0] connection will form loop
in axon_diam_part2.hoc near line 23". Could anyone help me debug this part of my code? Would really appreciate!!

Code:

numParts =1000
create axon_1[numParts] //axon of 10 um diameter
access axon_1
for (i=0; i<numParts; i=i+1){
axon_1{
length=100
diam=10
Rm=40000 //ohm-cm^2
Ra=200 //ohm-cm
insert hh //Inserting Hodgkin Huxley
}
}

for (i=0; i<numParts; i=i+1){
connect axon_1[i-1](1), axon_1(0) // connects end of axon[0] to start of axon[1]
}

//Inserting stimulus for axon 1
objectvar mystim // This is a variable name
axon_1 mystim = new IClamp(0) // Inserting current stim at start of axon
mystim.del = 100 // ms, Delay until stim turns on
mystim.dur = 100 // ms, How long stim stays on
mystim.amp = 9 // nA, from inside to outside membrane
tstop = 300 // ms, defaults to 5
zyousuf
Posts: 2
Joined: Thu Jan 23, 2020 12:46 pm

Re: How to connect multiple compartments of an axon using a for loop?

Post by zyousuf »

EDIT: For some reason, it isn't showing here that there is an i in square brackets next to the axon_1(0). It's present in my code though. I'm really confused why this isn't working.

for (i=0; i<numParts; i=i+1){
connect axon_1[i-1](1), axon_1(0) // connects end of axon[0] to start of axon[1]
}
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to connect multiple compartments of an axon using a for loop?

Post by ted »

Could anyone help me debug this part of my code?
Do you think the task might be simpler if you used a million "compartments" (sections, actually)? Or maybe it would be easier to figure out what went wrong if you tried just 3.
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to connect multiple compartments of an axon using a for loop?

Post by ted »

For some reason, it isn't showing here that there is an i in square brackets next to the axon_1(0).
Why don't you use the Forum's markup features? Those little buttons above the big edit field include one that is used to wrap blocks of code. Maybe read about this in the Forum's FAQ list, under "Formatting".
Post Reply