The Best Way to Implement a Pulse Train?

The basics of how to develop, test, and use models.

The Best Way to Implement a Pulse Train?

Postby skos » Fri Jul 01, 2011 4:50 pm

Hi,

So I'm working with a NEURON model that my supervisor handed me and I have very little experience with NEURON itself. I was asked to implement a method of intraellular stimulation that would use an IClamp to inject current into the soma of a target cell according to a pre-defined frequency. I figured out how to do all the setup work, but I'm at a bit of a loss as to how to implement the actual train. Someone else helped me to create the following code to perform intracellular stimulation on the target cell:

Code: Select all
if (TC_in==1) {
         soma[0]  {
         TC_stim=new IClamp()
         TC_stim.loc(.5)   //inject current in the center of the node//
         TC_stim.del=BASE // BASE is the time till the first stimulation pulse
         TC_stim.dur=PW
         TC_stim.amp=100 //nA//
         }
   }

My question is what the most efficient way to expand this into a pulse train is? I was hoping that I would be able to simply use a vector of time as the TC_stim.del variable, but the documentation seems to suggest otherwise. The other idea that I had was to use a for loop around the entire intracellular stimulation code block to create a separate IClamp with

Code: Select all
for i=0:numpulses {
         soma[0]  {
         TC_stim=new IClamp()
         TC_stim.loc(.5)   //inject current in the center of the node//
         TC_stim.del=BASE+i*PW*2 // BASE is the time till the first stimulation pulse
         TC_stim.dur=PW
         TC_stim.amp=100 //nA//
         }
}


However this seemed like a really wasteful approach. Are there any better approaches to doing this?

Thanks!
skos
 
Posts: 6
Joined: Fri Jul 01, 2011 11:25 am

Re: The Best Way to Implement a Pulse Train?

Postby ted » Fri Jul 01, 2011 5:20 pm

For arbitrary waveforms create an IClamp with del = 0, dur = 1e9, and use the Vector class's play() method to drive its amp variable.

If you want to generate a series of uniform pulses, see this item
I just want a current clamp that will deliver a sequence of current pulses at regular intervals.
in the FAQ list
http://www.neuron.yale.edu/neuron/faq
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: The Best Way to Implement a Pulse Train?

Postby skos » Fri Jul 01, 2011 6:56 pm

Ah, thank you very much! I guess I wasn't quite as thorough as I would have liked in my peruse of the documentation -- I kept searching for "IClamp pulse train" becuase that's the only wording I could think of.
skos
 
Posts: 6
Joined: Fri Jul 01, 2011 11:25 am

Re: The Best Way to Implement a Pulse Train?

Postby skos » Tue Jul 05, 2011 4:31 pm

Hi ted,

Sorry for the stream of most likely stupid questions, but I wanted to check whether the following code would work. Unfortunately I don't have access to the computer with NEURON till tomorrow, but I modified the code to calculate all the necessary parameters and came up with the following for implementing an ipulse1. Would this work okay? All the examples I can find for using the ipusle1 seem to go through the point process manager as opposed to directly setting variables like I do.

Code: Select all
soma[0]  {
TC_stim=new ipulse1(0.5)
   //TC_stim.loc(.5)   //inject current in the center of the node//
   TC_stim.del=BASE
   TC_stim.ton = PW
        TC_stim.toff = TRAIN_INTVL
   TC_stim.amp=100 //nA//
}


If this method doesn't work, are there any adverse effects to using a large number of individual IClamp instances to stimulate each individual pulse? Will there be a large resource drain or anything? I would prefer to keep the code as much in the same style as it currently is, as there are a lot of different projects using the code and I don't want to introduce a bunch of new stuff that everyone has to try and understand.
skos
 
Posts: 6
Joined: Fri Jul 01, 2011 11:25 am

Re: The Best Way to Implement a Pulse Train?

Postby ted » Tue Jul 05, 2011 5:42 pm

The file name is not necessarily the same as the name of anything defined by the contents of the file.
A mod file defines either a point process, a density mechanism, or an artificial cell class. It contains a NEURON block in which there is a statement that declares which of these three it defines, and the name of the thing that it defines.
Case is important.
I don't have ipulse1.mod in front of me, so you will have to examine it yourself to discover what to call an instance of this particular mechanism.

WRT your code example, using the correct name on the right hand side of this statement
TC_stim=new ipulse1(0.5)
should take care of the problem.

I would have written
soma TC_stim=new WhateverItIs(0.5)
TC_stim.del=...
since it minimizes typing and for me a chance to type is a chance to mistype. The only statement that requires "section stack syntax" is the one that creates an instance of the WhateverItIs class.
If this method doesn't work, are there any adverse effects to using a large number of individual IClamp instances to stimulate each individual pulse? Will there be a large resource drain or anything?
Each instance of a class consumes additional resources, but if the entire model is small and the computer is powerful, who cares? The more important considerations lie elsewere. Brute force approaches to writing code are not only inelegant but also often difficult to understand, debug, and maintain. At best they are crude hacks, at worst bad examples that one hopes will not be imitated by others. Finally, one's writings, whether for computers or humans, stands as a testimony to the quality of one's work.

I would prefer to keep the code as much in the same style as it currently is, as there are a lot of different projects using the code and I don't want to introduce a bunch of new stuff that everyone has to try and understand.
I hope that doesn't reflect poorly on the style of the existing code, or on the abilities of unnamed collaborators to learn new things.
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: The Best Way to Implement a Pulse Train?

Postby skos » Tue Jul 05, 2011 6:06 pm

ted wrote:The file name is not necessarily the same as the name of anything defined by the contents of the file.
A mod file defines either a point process, a density mechanism, or an artificial cell class. It contains a NEURON block in which there is a statement that declares which of these three it defines, and the name of the thing that it defines.
Case is important.
I don't have ipulse1.mod in front of me, so you will have to examine it yourself to discover what to call an instance of this particular mechanism.

WRT your code example, using the correct name on the right hand side of this statement
TC_stim=new ipulse1(0.5)
should take care of the problem.

I would have written
soma TC_stim=new WhateverItIs(0.5)
TC_stim.del=...
since it minimizes typing and for me a chance to type is a chance to mistype. The only statement that requires "section stack syntax" is the one that creates an instance of the WhateverItIs class.
If this method doesn't work, are there any adverse effects to using a large number of individual IClamp instances to stimulate each individual pulse? Will there be a large resource drain or anything?
Each instance of a class consumes additional resources, but if the entire model is small and the computer is powerful, who cares? The more important considerations lie elsewere. Brute force approaches to writing code are not only inelegant but also often difficult to understand, debug, and maintain. At best they are crude hacks, at worst bad examples that one hopes will not be imitated by others. Finally, one's writings, whether for computers or humans, stands as a testimony to the quality of one's work.

I would prefer to keep the code as much in the same style as it currently is, as there are a lot of different projects using the code and I don't want to introduce a bunch of new stuff that everyone has to try and understand.
I hope that doesn't reflect poorly on the style of the existing code, or on the abilities of unnamed collaborators to learn new things.


Thanks, I found the error. Apparently ipusle1 is actually Ipulse1. I also took your suggestion regarding instantiating the Ipulse1 without using brackets around all of the parameters. I'm pretty new to NEURON, so I was just following what was done by whoever worked on the code last. As for coding style, it's not so much that the style is bad that it is that we have a bunch of people working with it, from people who are completely comfortable with making extremely elaborate models, to people like myself who have experience programming but very little experience with NEURON, all the way down to people who have never programmed before. While I'm sure that everyone involved is capable of learning NEURON, a lot of them simply don't have any use for changing the NEURON models themselves apart from changing some superficial parameters, nor the time to do so, so I'm trying to stick to the code that they're already familar with.

The code appears to be running without errors now, so thanks for all the help!
skos
 
Posts: 6
Joined: Fri Jul 01, 2011 11:25 am

Re: The Best Way to Implement a Pulse Train?

Postby ted » Wed Jul 06, 2011 12:03 pm

I'm trying to stick to the code that they're already familar with.
Understood. But people learn by example, and an example of good practice is probably most beneficial to those who may be seeing it for the first time. What can be said for examples of mediocre or bad practice?
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine


Return to Getting started

Who is online

Users browsing this forum: No registered users and 1 guest