20190926 Note from the ModelDB administrator: this model was updated so that running the model is easier than described below: just start mosinit.hoc with nrngui (see top-level readme for more instructions and below for additional details).

Copyright (c) California Institute of Technology, 2006 -- All Rights Reserved
Royalty free license granted for non-profit research and educational purposes.

Extracellular Action Potential Simulation

  1. Overview
  2. References
  3. Setup
    1. Linux
    2. Macintosh
    3. Windows
  4. Running the NEURON Simulation
    1. Choosing the Parameters
    2. Running the Simulation
    3. Program Output
    4. Running Additional Simulations
  5. Running the Matlab Program
    1. Calculating and Plotting Extracellular Action Potentials
    2. Comparing Simulation Parameter
    3. Comparing Extracellular Action Potentials
    4. Comparing Intracellular Action Potentials
    5. Plotting Intracellular Details
    6. Measuring Extracellular Action Potential Features
    7. How To "Undo" a Trial
  6. Analyzing Voltage Gradients
    1. Running the Simplified Neuron Simulation
    2. Plotting the Voltage Gradients in Matlab
  7. Setting Up Your Own Simulations
    1. Running Simulations with Different Cell Morphologies
    2. Running Simulations with Different Types of Cells
    3. Running Simulations with Different Channel Models
  8. Getting Help and Helping with EAPS

Overview

The Extracellular Action Potential Simulation (EAPS) package consists of two sections:
  1. A NEURON Simulation Environment program that runs simulations, producing the output necessary to calculate EAP's. The NEURON simulation is designed to run from the command line, although it can also be run using the NEURON gui.
  2. Several Matlab scripts that calculates the EAP's using the Line Source Approximation (LSA) and plots and analyzes the results. There are also a set of functions for plotting intracellular data produced by the simulation.
In principal the Matlab code can be re-used for simulation environments other than NEURON, as long as they produce output (membrane currents and geometry) in the same format.

These instruction assume that you have the NEURON Simulation Environment and Matlab installed.

(top)

References

For background reading, the publications concerning the development of the EAPS pacakge are (in chronological order):
  1. Holt G. (1998). A Critical Reexamination of Some Assumptions and Implications of Cable Theory in Neurobiology. PhD thesis, California Insitute of Technology.
  2. Holt G and Koch C (1999). Electrical interactions via the extracellular potential near cell bodies. Journal of Computational Neuroscience, 6:169-184.
  3. Gold C, Henze DA, Koch C, and Buzsáki G. (2006). On the original of the extracellular action potential waveform: a modeling study. Journal of Neurophysiology, 95:3113--3128.
  4. Gold C, Henze DA, Koch C. (2007). Using Extracellular Action Potential Recordings to Tune Compartmental Models. Journal of Computational Neuroscience. In Press.

Publications based on the EAPS package should always reference 2 (Holt and Koch, 1999) and 3 (Gold et al., 2006) and may also reference 1 and 4 if they are related to the detailed issues analyzed in those papers.

(top)

Setup

Linux

Change to the eaps/mod directory and type:

nrnivmodl

You should see a lot of status messages generated by the compiler ending with

Successfully created i686/special

If you don't get this result consult the documentation for NMODL in the NEURON book.

Macintosh

  1. Open the eaps directory, and the directory containing your NEURON installation.
  2. Drag the folder 'mod' on to the mknrndll icon. You should see a terminal open,and spew a lot of status messages generated by the compiler ending with

    Successfully created i686/special

    (Or if your Macintosh has a powerpc chip that would be '...powerpc/special'. You may have to modify some of the commands below based on your processor type.)

Windows

Important note for Window's users: If you unpack the archive with Winzip you must create two folders in the eaps directory structure:
  1. eaps\output
  2. eaps\mat\lsa\temp
The reason for this is that Winzip does not create empty folders that were part of the archive.

After unpacking the archive and creating those two empty folders,

A terminal window will open and you willsee a lot of status messages generated by the compiler ending with

nrnmech.dll was built successfully.

(top)

Running the NEURON Simulation

To run the NEURON simulation you first choose the parameters by editing/creating a parameter definition file, then run the simulation in the manner appropriate for your platform.

Choosing the Parameters

Change to the directory eaps/hoc/params. There should be 11 files: The parameters that will be used for the simulation are the file named d151_params.hoc. To choose different parameters for the simulation, copy one of the files d151_params_x.hoc to the name d151_params.hoc (i.e. remove the _x extension). When simulating a cell with name foo.hoc the program will use the parameters in the file foo_params.hoc

Running the Simulation

To run the program you start the compiled mod file executable mod/i686/special (or mod/powerpc/special for Macintosh) with the following files as parameters: The following describes the procedure for Linux, Macintosh and Windows.

Linux

Change to the root eaps directory and enter the command line:

You will first see some text describing the stages of the setup procedure, followed by many lines like this:

d151(0001).171: t=13.19 / dt=0.0147, soma.v(.5)=7.1 [Soma_vmax=7.1 @ t=13.2]

If you read these you should see that the cell starts at rest, fires a single action potential, and then repolarizes.

Macintosh

Run the Terminal application (in the Utilities folder, under Applications.) Change to the root eaps directory with the cd command. Enter the command line:

You will first see some text describing the stages of the setup procedure, followed by many lines like this:

d151(0001).171: t=13.19 / dt=0.0147, soma.v(.5)=7.1 [Soma_vmax=7.1 @ t=13.2]

If you read these you should see that the cell starts at rest, fires a single action potential, and then repolarizes.

Windows

  1. (20190926 Note from the ModelDB Administrator: the following edit is no longer necessary as an upgrade to this archive
    includes the use of the function unix_mac_pc() provided by NEURON to detect the platform and set the WINDOWS variable.
    )
    You must first make a small edit to one of the .hoc files. With any text editor, open the file

    Near the top of the file, location the section "LINUX/MAC VS. WINDOWS" and change the line

    to

    Save the file.

  2. Run the Command Prompt application (under Accessories, on the start menu)
  3. Change the directory to eaps. If you put the EAPS package in c:\ (the root directory) then you would use the command:

  4. Enter the following command and parameters (copy & paste):

    A NEURON shell will open. You will first see some text describing the stages of the setup procedure, followed by many lines like this:

    d151(0001).171: t=13.19 / dt=0.0147, soma.v(.5)=7.1 [Soma_vmax=7.1 @ t=13.2]

    If you read these you should see that the cell starts at rest, fires a single action potential, and then repolarizes.

Program Output

Running the simulation should have created the directory eaps/output/d151_0001/nrn and generated the following files:

Running Additional Simulations

The directory and all the files were all numbered one ("d151_0001") because this was your first simulation for cell d151. In the folder eaps/cells there is now a file d151_trial_trial_num.txt that will keep track of the number of trials and provide each new experiment a new number. (Note to windows users: Notepad does not properly display this file. Use wordpad or a programming text editor such as emacs to view/modify this file.)

Go back to the directory eaps/hoc/params and re-name a different file as d151_params.hoc (or modify the numbers but not the code in the d151_params.hoc file directly.)

Rerun the NEURON simulation to create the directory eaps/output/d151_0002/nrn and a new set of output files.

(top)

Running the Matlab Program

To examine the results and calculate the EAP's start Matlab and change to the directory eaps/mat. Run the script addpaths.m - this will add all the sub-directories to the search path. You can then run all the scripts which are in sub-directories.

Note: when using the Matlab functions you should keep eaps/mat as the current directory, because many files are loaded or saved using relative directory paths based on that assumption. If this is inconvenient, you can switch to using absolute paths by modifying the file eaps/mat/file_util/get_root_path.m

Calculating and Plotting Extracellular Action Potentials

Run the following script: Then: This should make a plot showing the extracellular action potentials similar to the bottom of Figure 3 but showing the EAP's at many more locations. (Note that the cell is reflected along the Y axis in comparison with the figure in (Gold, Henze and Koch, 2007).)

The parameters are as follows:

  1. The first parameter is the cell name.
  2. The second parameter is the trial number. You can leave this empty ('[]') and it will default to the last trial run for the cell.
  3. The third parameter are the start and ending time from the simulation to calculate for. When empty (as in the example above) this defaults to a 4 ms window starting 1 ms before the maximum soma potential. This is usually a good window for calculating EAPs.
  4. The fourth parameter "0.3" controls the extracellular conductivity, in Seimens-1 meters. (To get the more familiar Ωcm from S-1m take 100/σ.)
  5. The fifth (array) parameter are the minimum and maximum X and Y coordinates for the grid of points to calculate and plot - measured in μm.
  6. The sixth parameter is the Z plane in μm (the soma is at Z=0 so this is the standard plane for the calculation.)
  7. The final parameter is the grid spacing in μm at which to calculate. You can specify the bounds in plot_eap_grid (the 5th parameter) to be smaller than those you used in zplane_eap_calc but not greater.

Read the header in the Matlab code file eaps/mat/lsa/zplane_eap_calc.m and eaps/mat/plot_extra/plot_eap_grid.m for details on these function and the parameters.

Comparing Simulation Parameters

Assuming you have run two different simulations, run the script: This will print out all the parameters that are not the same for the two simulations. Note that the default units of conductance density are S/cm2. There are shortcuts for using this script: you can enter simply and it will compare the two most recent trials for the cell. Also, you can use and the script will compare the most recent trial (whatever it is) with the trial number you entered.

Comparing Extracellular Potentials

Run the following script:

This should make a plot of two extracellular action potential traces as in Figure 1(iv) from (Gold, Henze and Koch, 2007). The . If you run four simulations with the different parameters in eaps/hoc/params and enter the additional trial numbers for the second parameter of compare_extra_trials you will fully re-create Figure 1(iv).

In order to re-create Figures 1(v) and 1(vi) you will first need to re-calculate the extracellular potentials on a finer grid. Use the command:

This will calculate the EAP's on a grid spanning x=-100 to 0, y=0 to 50, spaced at 10 micrometers. Repeat this for any other NEURON trials you have run (the trial number is the second parameter.) Now run the following two comparisons:

These will re-create Figures 1(v) and 1(vi) (if you have run all four parameter sets, set the second parameter to to include all 4 trials, i.e. [1 2 3 4]).

Note that the percentage errors do not match those in (Gold, Henze and Koch, 2007). That's because we have not included the parameters for weighting the peak in the error calculation. For the last parameter (empty brackets, above) use the array [10 0.5]. That incdicates to weight the peak 10x, and for subsequent points next to the peak decrease the weight by a factor of 0.5 (1/2) until it is below 1 (at which point the weight will be 1 for all remaining points.) For example:

Also note that the orientation of the Y axis in the simulation is the reverse of that described in (Gold, Henze and Koch, 2007).

Comparing Intracellular Potentials

Run the following script:

This should make a plot of two intracellular action potential traces as in Figure 1(i) from (Gold, Henze and Koch, 2007). If you run four simulations with the different parameters in eaps/hoc/params and enter the additional trial numbers for the second parameter of compare_intra_trials you will fully re-create Figure 1(i).

In order to re-create Figures 1(ii) and 1(iii) re-run the script replacing the parameter 'soma' with 'apical1_0222' and 'apical1_02222211111'. These are the name of sections in the apical trunk approximately 100 and 200 micro-meters from the soma. Use the same parameters to apply the peak weighting to the error calculating, as described in the previous section.

Read the header of the Matlab code file eaps/mat/plot_intra/compare_intra_trials.m for details on the function and the parameters.

Plotting Intracellular Details

To plot the intra-cellular details produced by the first simulation try the following command:

This should open a plot similar to Figure 3 in the paper (there is actually an additional column showing the state of the gating particles for the K+ currents.) The exact details will depend on which simulation you ran. The parameter 1 (2nd parameter) controls which trial number to plot. Each row in the plot shows the details for a given section, the name of which is showed in the title for each row.

The parameters 'ax' and 'k' indicate that the plot should show details for the axial currents and the K+ currents. In this parameters list you can also add 'na' and 'ca' to show details for the Na+ and Ca2+ currents. Depending on your screen size you may want to use only one of these options at a time. Every plot will show the membrane potential and membrane currents.

Note that the orientation of the axial currents in the soma is the reverse of that described in (Gold, Henze and Koch, 2007). The NEURON program defines inward axial current as coming from the '0' end of the compartment and outward current is defined as coming from the '1' end of the compartment. However, in the .hoc file cells/d151.hoc the 0 end of the soma is the one connected to the apical dendrites while the 1 end is connected to the basal dendrites and axon: this is the reverse of the orientation used in the paper. The orientation in the paper was switched to match the circuit diagram, Figure 1.

You can make the same plots for different parts of the cell. Try replacing the parameter 'approx' (for "apical proximal") with 'axon', 'apdist' or 'basal'.

In order to see a picture of the cell showing where the named sections are run the script:

this will create a flattened picture of the cell with the names of the sections next to them.

The last parameter (empty []) is the start/end times for the plot, which defaults to a 4 ms window starting 1 ms before the maximum soma potential.

Read the header of the Matlab code file eaps/mat/plot_intra/plot_intra_trials.m and eaps/mat/plot_cell/plot_cell_labels.m for details on these function and the parameters.

Measuring Extracellular Potential Features

To measure the features of a single sample of an EAP run the script:

This will plot the single EAP at the location x=0, y=20, z=0 the set of measurements described in (Gold, Henze and Koch, 2007) and some others that were not used in the publication. You can run the script for other trials or locations by changing the parameters. (The second parameter is the trial number, and the 4th is the location in µm.)

Note: in order to measure the decay from the K+ phase peak you must have Matlab Curve Fitting Toolbox installed. If you do not have the toolbox, you can comment out this part of the code. See the file eaps/mat/meas_eap/measure_eap.m for details.

To make boxplots of the measurements as in (Gold, Henze and Koch, 2007) run the script

This assumes that you have run trials 1-4 with the 4 different parameter files provided. If you have run fewer trials, than change the second parameter to reflect the correct trial numbers. The last parameter sets a threshold of 0.04 mV (40 µV) for EAP's to be included in the statistics.

Also note that the figures in (Gold, Henze and Koch, 2007) were made by measuring EAPs in a 50 x 50 grid with a spacing of 10 μm. So you may want to re-caclulate the EAPs and run the measurement at this finer scale.

Note: in order to make the boxplot you must have Matlab Statistics Toolbox installed Unfortunately, there is no workaround provided for this.

Read the header of the Matlab code file eaps/mat/meas_eap/plot_eap_measure.m and eaps/mat/meas_eap/plot_meas_compare.mfor details on these function and the parameters.

(top)

How to "Undo" a Trial

If you do any significant amount of work with this EAPS you will eventually run trials that you did not mean to. Maybe you meant to set the parameter to some value but you mistyped it or maybe you meant to change a parameter and forgot to modify the parameter at all! If you do not want to keep the result from a trial you can "undo" a trial from matlab as follows: As you can guess from the output, the script removes the output directory created for the trial and decrements the trial counter by one.

Note: This script is only designed for linux/mac. There is probably some good Windows equivalent - if you know how to do this and would like to contribute an improved function please email the author. See the section Getting Help and Helping with EAPS.

(top)

Analyzing Voltage Gradients

The EAPS package also contains the code to run the simulations of the simplified neuron and analysis of voltage gradients decribed in Gold, Henze and Koch (2007), Section 3.7, (The Relationship Between the Membrane Potential and Extracellular Potential)

Running the Simplified Neuron Simulation

Run the NEURON simulation as usual for the cell named 'line' - this is the simplifed single cylinder neuron. For mac/linux with an i686 processor that would be:

from the root eaps directory.

The default parameter file for the line neuron are the parameters based on the B simulation. There are also parameter files to run simulations based on the C and D parameters.

Plotting the Voltage Gradients in Matlab

After running the NEURON simulation for the simplified neuron (line) first calculate the extracellular action potentials around the cell:

Note: when you run this you will see a lot of error warnings like this:

The reason for these warnings is that the LSA is attempting to calculate the EAP's at positions that lie directly on the neuron line segments (i.e. points along the line Y=0.) This does not cause a problem: it just generates a bunch of Nan values in the result. But if you don't want to see these messages just type:

You can plot the eap's, as usual:

Note: you will need to change the voltage scaling to get a good picture of the weaker EAP's around the line. There is code in the top of plot_eap_grid that you can un-comment for this purpose.

In order to plot the voltage gradient use the following matlab function:

This should make a figure similar to Figure 8 of Gold, Henze and Koch (2007). If you re-run the simulation with parameters "C" and "D" you can recreate figures 9 and 10 from the paper.

You can also make intra-cellular detail plots for the line neuron. Try:

You can make the same plots for different parts of the cell. Try replacing the parameter 'approx' (for "apical proximal") with 'apdist', 'basprox' or 'badist'. One end of the cylinder is labeled "apical" ("ap") and the other is labeled "basal" ("ba"). For the B type simulation the two are identical, but simulation D you will see the action potential initiate at one end and then travel to the far end.

(top)

Setting Up Your Own Simulations

Running Simulations with Different Cell Morphologies

To use another cell morphology in place of D151 we assume that you start with a .hoc file describing the morphology that includes 3-D point information (i.e. it should include many pt3dadd(...) functions in the code.) The LSA cannot be run without 3-D data.

An important issue is the naming convention for the dendrites and axonal sections of the cell. These names are used for assigning the appropriate mechanisms and conductances to the different types of sections. The EAPS Neuron simulation program assumes the following:

If your neuron's morphology file does not follow these naming conventions you can either change it so that it does, or alter the NEURON program so that it recognizes your own convention. To do this, modify the procedure make_lists() in the NEURON code file cell_util.hoc. This procedure is the place where the program actually searches for the aforementioned strings in the section names. Throughout the code the different types of sections are referenced by sections lists (for dendrites, myelin and nodes sections) or by a section reference (for the soma, initial segment and hillock ). Those sections lists/references are created in the make_lists() procedure so that if you use a different naming convention you only need to change that one procedure.

Next you must do two things to tell the program which parameters to load for your file, and how to name the output directories and trial number files:

  1. Set the values of the strings neuron_name and cell_type at the top of your morphology file. neuron_name should be the name of the hoc file you are loading and cell_type should be "ca1pyr" (to start with) - these will be used by the neuron program to determine the name of the parameter files to load. It should like something like:

  2. Copy the file eaps/hoc/params/d151_params.hoc and re-name it to neuronname_params.hoc where neuronname is the name you defined in the previous step.

There are a few additional steps necessary, so that you can make the intracellular detail plots from your cell (if you do not wish to make such plots, these steps are unnecessary).

  1. In the file eaps/hoc/current_util.hoc define a new procedure neuronname_add_detail_sections() where neuronname is the same as the string you defined above. Following the example of d151_add_detail_sections(), enter which compartments of your cell should have full details saved from the simulation. These are the compartments for which you will be able to plot intracellular details.
  2. In the file eaps/hoc/current_util.hoc add a few lines to the procedure setup_detail_print():

    where neuroname is the name of your cell. Put this code right next to the similar code for d151 (either before or after - it doesn't make a difference.)
  3. Next you must also add these compartments to the Matlab code, so when you run the script plot_intra_detail it knows which compartments correspond to which category. In order to do this, modify the Matlab files eaps/mat/get_detail_secs.m and eaps/mat/get_detail_xs.m. Your new code should mirror the code defined for d151 but using the names of the sections and the compartment x's you defined in neuronname_add_detail_sections(). Note that classification of the compartments given by the plot_desc parameter is completely arbitrary - you can define whatever categories you like, or none at all.
Sometimes it may be hard to decide what compartments you want to save details for by simply looking at the .hoc file. In these cases you might want run your first simulation only saving details for the soma. After you have done this, use the Matlab script plot_cell_labels described above (in the section Plotting Intracellular Details) to visualize the cell with the compartment names. Then decide which compartments to save details for.

Running Simulations with Different Types of Cells

If you would like to define simulations based on a different type of cell (other than CA1 pyramidal) but using the channel model provided, follow these steps:

  1. Copy the file eaps/hoc/params/ca1pyr_standard_params.hoc and re-name it to eaps/hoc/params/celltype_standard_params.hoc where celltype is the name of your cell type.
  2. Make any changes to the file eaps/hoc/params/celltype_standard_params.hoc necessary so that it accurately reflects the properties of your cell type. Note that you should be changing only the numbers in the define_param procedure calls.
  3. Change the cell_type parameter at the top of your cell's .hoc file to the new type.
  4. Run the simulation as described in the section Running the NEURON Simulation.

All of the kinetics of the ion channels, passive parameters, linear changes in conductance density distributions, and spine density distributions are defined in the standard_params.hoc file. By changing these you can make simulations for different classes of cells with relatively minor changes to the code. (Of course, determining the correct values for these parameters may be a significant research task...)

Running Simulations with Different Channel Models

Changing the EAPS package to support a different channel model (different NMODL mechanisms) requires moderately significant changes to the NEURON code. The same steps apply if you are adding an additional NMODL mechanism to those that are now in the EAPS package or if you are replacing some or all of the mechanisms with new ones. Note: if you only want to remove some mechanisms from the simulation, it is simplest to define their conductances to be zero everywhere. That way they won't effect the simulation and you don't have to change any code!

The code is not currently setup to support multiple channel models so by setting up your own channel model you will no longer be able to run the channel model that came with the package. Of course, one could envision improvements to the code which would allow a program parameter to inform the code which model is being run and take appropriate action. This would require additional programming and a detailed understanding of the NEURON program.

First, you will want to define a standard membrane params file appropriate to your channel model. This is basically the same as what was described in the previous section, Running Simulations with Different Types of Cells. You are not required to follow the same method as used in the sample (define all parameters of the NMODL mechanism through the "define_param" function) but it is strongly advised - especially if you will be experimenting with different values for the mechanism parameters. If you are only adding a mechanism you need only add any required params for the new mechanism.

The second and greater task is that you will have to re-write nearly the entire file membrane_init.hoc. Most of this file deals with inserting mechanisms and setting the peak conductances for different types of sections. The top level function called by the main program is init_membrane(), so as long as you keep that consistent it will integrate with the existing main program.

A procedure in membrane_init.hoc that should be kept but modified is the procedure make_mechanism_list(): this procedure plays a crucial role in the export of compartment details. It defines the list of "mechdesc" templates. This list of templates describes all the mechanisms and their components that should be exported for the compartments defined for detailed data export. Naturally you should copy the existing examples, substituting the names and relevant variables of your own NMODL mechanisms. See mechdesc.hoc and current_util.hoc for more details. If you simply leave this procedure empty than no details of the ionic mechanisms will be saved in the detail data.

Important note: The code that exports the net membrane current for each compartment (the key data for use in the Line Source Approximation) only looks for capacitive, Na+, K+, and passive leak current. If any mechanisms you add uses other types of current (i.e. Cl-, or non-specific ions as in mixed-ion channels, shunts, synapses, etc.) then you must modify the procedure read_compartment_currents() in current_util.hoc (and also some of the other helper functions - you'll have to read this code carefully.) Omission of even a relatively small current can have a surprisingly large impact on the resulting extracellular potential because if any current is missing the net membrane current will become unbalanced (not equal to zero.) This will tend to increase the extracellular potential amplitude without altering the waveform shape. The EAPS package includes a useful utility for debugging these types of changes: eaps/mat/neuron_util/check_current_balance.m. This script will plot the net current for the entire membrane alongside the membrane current for the soma. In principal the net membrane current for the entire cell is zero, but in practice there is some small deviation due to discretization and rounding errors. After making changes to current_util.hoc you should run check_current_balance.m and confirm that the deviations from zero net current are many orders of magnitude smaller than the peak soma current. It would be nice if the deviation is on the order of one millionth (1e-6) of the peak soma current but in practice you may see deviations up to one ten thousandth (1e-4). If the deviation is any larger than this it is almost certain that you have introduced a bug in the current export procedures.

(top)

Getting Help and Helping with EAPS

Note that the EAPS package is provided "as is" and there is no guarantee of support. The only functionality is that described here and it is assumed the users will be NEURON/Matlab programmers of sufficient ability to make any modifications they require for their own purposes.

That said, we will be starting a discussion thread (or more than one) in the NEURON User's Group Forum. All questions should be directed there so that others can benefit from the answers. The author of the package will check the User's group and post answers as often as possible.

If you would like to make improvements or extend the functionality of EAPS you are welcome to contribute! (Bug reports are welcome.) Contact the author by emailing carl at klab dot caltech dot edu. This code could become a true open source project if there is anyone out there who actually wants to contribute anything.

(top)