How to use this manual

1) How to use Manual (you're here: continue!)

Tells how to use the manual to model neurons, and where to start if you don't have much expertise with computer.

2) Hardware and software needed (Read if you are transporting NeuronC)

Describes type of computer equipment and software support is necessary to run NeuronC. This information will allow you to get NeuronC running on many types of personal computers and workstations.

3) NeuronC basis in analogy (Read if you're a beginner)

Explains what kind of neural behavior NeuronC models, and how it simulates the voltages and currents in neural circuits. This is important if you're starting out in modeling and need a basic understanding of numerical simulation.

For a more complete summary of how NeuronC works, refer to the modeling paper: Smith, R.G. (1990) "NeuronC: A language based on C for dynamically simulating neural networks of the visual system."

4) NeuronC statements and syntax (Carefully read; refer to later)

This section describes every NeuronC language statement, its meaning and function in a typical NeuronC modeling program.

5) How to construct a neural circuit.

This section describes how to go about designing a neural circuit.

6) How to add new channel types. (Skim, refer to later)

This section describes how to modify existing Hodgkin-Huxley channels and also new sequential-state types. If you need to modify the rate constant function you can look up "channels" in Section 4.

7) How to run nc (Refer when running models)

This section describes how to use the "nc", "stim", "plotmod", and "vid" commands. It explains the command line switches which allow you to run nc remotely on a workstation and allow you to display the data on a video screen.

8) Predefined variables (Read before making working model)

A list of all predefined variables that have special meanings for NeuronC. You can use these variables to control things like the type and resolution of the graphics display, and time increment for the numerical simulation.

9) References

References for background information about modeling neural circuits.

10) Programming examples (Use as a recipe book!)

Some examples of use of NeuronC language statements in simple models. You can use these examples practice your modeling skill by copying and then modifying them. You can use "modules" of NeuronC statements like a cookbook recipe to make larger programs.

11) NeuronC syntax (Use if you want to check nc syntax)

This gives the syntax file for the NeuronC language, and explains how to read syntax files written for YACC (UNIX tool for creating languages.

Click here to return to Table of Contents


Hardware needed for NeuronC

NeuronC requires a fast math processor because its simulation of neural circuits uses lots of floating point calculations. If a large neural circuit is simulated, NeuronC also requires a lot of memory. Memory use is proportional to network size; an average compartment and its associated connections require about 400 bytes of storage.

Another requirement of NeuronC is graphics with enough resolution to display colored charts on the screen. NeuronC can be run without graphics to produce a list of recordings but it is useful to display this information in graphical form.

Some excellent computer choices for running NeuronC include:

   1) Pentium, Pentium II, or AMD K6 with:

       16-64 MB memory
       SVGA or accelerated VGA,
       1 GB hard disk
       1024x768 monitor
       Linux operating system (download from sunsite.unc.edu:/pub/Linux)

2) Sun, SGI, DEC, or HP workstation with 64 MB or more of memory, UNIX operating system.

3) Mainframe computer running UNIX.


Software required to run NeuronC

NeuronC is currently being developed with the Linux operating system. This is a free UNIX-like operating system that is very powerful and easy to install. Any version of Linux, for example "Slackware", "Debian", or "Red Hat" will do. You can download these distributions from an ftp site, or you can purchase a CDRom and install Linux directly from it. Virtually any computer that can run UNIX will also run NeuronC.

If you would like to run NeuronC under DOS you can compile it with the Delorie gcc compiler (www.delorie.com). A version of NeuronC that runs under DOS is available (with limited graphcis).

The directory "nc" contains all the files needed to run NeuronC. The "nc" directory contains the source codes for "nc", "stim" and "plotmod", along with some examples of neural circuit programs. The "pl" directory contains the source codes for "vid" and "hpflt" and "ibmflt" which are the graphics drivers for the video screen and plotter, respectively. The "plot" directory contains the Ampex plot package which is the source code for the graphics language that "vid" and "hpflt" use. Normally the plot subroutines are compiled into a library called "libP.a" which is used when linking nc and plotmod.

Click here to return to Table of Contents


NeuronC basis in analogy

Click here to return to Table of Contents

Biological modeling

To model a biological system is to make an analogy between that system and some other process. The model may be simply a conceptual one, in which case it is an analogy in thought only. Conceptual models are very important for us because we use our thinking processes and intuition every day to model events in the real world. Without an intuitive model, we could not find our way through a city or determine what the next step should be in a novel experiment.

One way to think of computational modeling is "quantitative imagination"; the computational approach to neuroscience is merely an addition to conceptual modeling. The value of the computational approach is to add a quantitative dimension to our intuition about the function of a neural circuit.

The relation between a biological system and the computational model of it depends on analogy in exactly the same way that a conceptual model does. With this type of analogy, we assert that the model represents the biology in a direct quantitative way, but this assertion depends on our intuitive knowledge and experience about the biological system. Seen in this context, a language for neural simulation provides a concise description of a neural circuit's biological form/function for us, but a definition of difference equations for a computer.

Click here to return to section index


Numerical modeling

Cables and electrotonic decay over space

Several numerical method conventions for modeling neural circuitry exist in the literature. Rall's (1959) cable model allowed currents and voltages in neurons with linear passive membrane properties and branching dendritic trees to be described reasonably accurately. More recently, cable theory has been extended into the time domain (Jack et al. 1975), but still typically requires linear membrane conductances. Ideally we would like a way to model any neural element (cable, synapse, voltage-sensitive channel) in this type of continuous model.

The main idea of cable modeling is that a neural dendrite acts like an electric cable with an inside conductor (cytoplasm of neuron) covered by an insulator (membrane). Two ideas form the basis for this analogy:

1) Current flow through a patch of passive membrane is proportional to the voltage difference between the inside and outside of the membrane.

          im = (Vout-Vin) / rm              (1)
          
          where:

          im = current through membrane
          rm = resistance of membrane
2) Voltage along the inside of the dendrite (the conductor) is reduced by axial current flow through the dendritic cytoplasm.
          d(Vin)/dx   =  ri * I              (2)

          where:

          ri = axial resistance
          I  = axial current
          x  = axial distance along dendrite
     
differentiating with respect to x:
          d2(Vin)/dx2 =  ri * dI/dx          (3)
but the change in axial current within one small patch of dendrite is precisely equal to the membrane current:
          dI/dx = im                         (4)
combining (1) (3) and (4):
          d2Vin/dx2 = (Vin-Vout) * ri/rm     (5)
The solution of this differential equation defines an electric circuit with exponential decay of voltage along the length of a neural dendrite. Voltage and current signals along a passive dendritic tree can be calculated easily using exponential functions (Rall, 1959).

For an infinite cable:

          V = I * ri * lambda * e^-x/lambda   (6)

          where:

                V = voltage along cable at distance x from end
                I = current injected into cable at end
               ri = axial resistance of cable, ohm/cm
           lambda = space constant, sqrt (rm/ri),
               rm = membrane resistance of cable, ohm*cm

Click here to return to section index


Compartments

Compartmental modeling, developed especially for neural simulation (Cooley and Dodge, 1966; Rall, 1967; Joyner et al., 1978) has allowed many different kinds of neural properties to be simulated, including cable properties, membrane capacitance and channel kinetics, synaptic connections, and time variation of these properties. Compartmental modeling does not use analytical functions to calculate voltages along a cable, thus there is no need to assume that membranes are linear. Although the compartmental method can be used to simulate without time (static modeling), often time is included (dynamic modeling).

Each compartment consists of a volume of cytoplasm small enough that its internal voltage is nearly the same everywhere; this condition is called "isopotential". The compartments are connected together by resistors which represent the dendritic axial resistance. The reduction of a neural circuit to a series of connected compartments is justified by analogy because a series of connected isopotential compartments acts very much like a cable if each compartment is small compared with the length of the cable. In addition to the appropriate amount of membrane, each compartment may have other properties such as multiple connections to neighboring compartments and membrane channels with special properties.

Derivation of cable equation for compartments:

     dV2/dx = V3 - V2 = I2 * ri         (7)
     dV3/dx = V2 - V1 = I1 * ri         (8)

     d2V/dx2 = (V3 - V2) - (V2 - V1)    (9)
By Ohm's Law, the voltage across a resistor is equal to the electric current multiplied by the resistance:
     d2V/dx2 = I2 * ri - I1 * ri        (10)
             = ri * (I2 - I1)           (11)
by Kirchoff's Law, the current flow into a node equals the current flow out of the node:
     I2 - I1 = Im                       (12)
But the membrane current equals the compartment voltage divided by the membrane resistance:
     Im = V2 / rm                       (13) 
Combining (11), (12), and (13),
     d2V/dx2 = V * ri/rm                (14)
Note that (14) is identical to (5).

Click here to return to section index


Cable equation in time

1) Current flow through a patch of passive membrane is also proportional to the voltage change between the inside and outside of the membrane over time. Adding this effect to the static current flow (equation 1):
          im = (Vout-Vin) / rm +  dVin/dt * cm              (15)
where:
          im = current through membrane
          rm = resistance of membrane
          cm = capacitance of membrane
          t  = time
Including axial voltage drop (as in equation 3):
          d2Vin/dx2 = (Vin-Vout) * ri/rm + dVin/dt * cm     (16)
where:
          ri  = axial resistance
          rm  = membrane resistance
          cm  = membrane capacitance
          t   = time
          Vin = voltage inside cell
This is the standard equation that neurophysiologists use to describe voltage in a cable in space and time.

Click here to return to section index


Synapses

Biological synaptic connections are quite complex. They consist of a mechanism that releases a chemical neurotransmitter coupled to a mechanism for modulating the postsynaptic channel conductance. NeuronC synapses are a simplified version of the biological mechanism and have several parameters which control their function.

To simulate the mechanism of neurotransmitter release, NeuronC uses a static "transfer function" which defines how much neurotransmitter is released as a function of presynaptic voltage. The neurotransmitter action is modified by a time function which delays and low-pass filter the neurotransmitter action. The time-filtered neurotransmitter level defines the conductance of the postsynaptic channel.

This synaptic model very simplified because it leaves out such details as: presynaptic calcium channel activity, calcium activated vesicle release, neurotransmitter binding kinetics, etc. However, the NeuronC synaptic parameters are easy to understand and can simulate a wide variety of synaptic types. Each parameter is "separable"; that is changing its value does not affect other synaptic function parameters. In addition, synaptic parameters can be modified during a runtime to allow a wide variety of neural plasticity functions to be simulated.

Click here to return to section index


Reversal potentials, Nernst and GHK equation

One way to find the conductance of a channel during a physiology experiment is to find its reversal potential, the voltage above and below which the channel current reverses. Assuming the channel is ohmic (acts like a linear resistor) the channel's current is the product of the voltage times the conductance, where the voltage is the reversal potential minus the membrane voltage.

    G = I / V

  where:
         I = current
         G = conductance of open channel
         V = reversal potential minus membrane voltage
If the ionic concentrations in the internal and external medium are known, it is possible to calculate the voltage at which no current flows for an ion. This is known as the ion's Nernst potential and is very similar to the definition of "reversal potential". It is a function of the internal and external ion concentrations and temperature:

          V = RT / zF * ln (co / ci)
 where:
          V = Nernst potential
          T = temperature (^To^TK)
         co = external concentration
         ci = internal concentration
          z = valency of ion
The Nernst potential is a useful approximation of the driving force for an ion through a membrane channel because it defines the voltage at which no net current flows through the channel. Knowing the Nernst potential for the major ions is a great help in understanding electric current flow through a channel.

It would be convenient if the reversal potential for a channel could be calculated directly from the Nernst potential of the channel's major ion. However, the driving force for electric current through a channel is not exactly the same as the Nernst potential for the channel's major ion, for several reasons. Every channel allows other ions to pass too. The relative permeability of "other" ions can range from 0.0005 for K through a Ca channel to 0.2 for Ca through an NMDA channel. The effect of having several ions pass through a channel is that its reversal potential is a function of all the ion concentrations and their respective permeabilities. That function is the GHK voltage equation:

                             ( Nao * pna + Ko * pk )
           V = RT / zF *  ln  --------------------
                             ( Nai * pna + Ki * pk )
 where:
           V = GHK potential (reversal potential for the channel)
           T = temperature (deg K)
         Nao = Na external concentration
         Nai = Na external concentration
         pNa = Na permeability through channel
          Ko = K  external concentration
          Ki = K  external concentration
          pK = K  permeability through channel
           z = valency of ions ( must be same valencies,
                                  if different use eqn below)

To accurately compute the current through a channel, we need to compute the reversal potential from the GHK voltage equation and for this we need to know ion concentrations and relative permeabilities.

In NeuronC, each channel type has a data structure that contains the channel's conductance (and its temperature dependency) and the channel's permeability to several different ions so that an accurate reversal potential can be computed.

A more detailed version of the GHK voltage equation is required when both monovalent and divalent ions are permeable through a channel:

                        ( Nao * pNa + Ko * pK + 4 * p'Ca * Cao )
        V = RT / F *  ln -----------------------------------------   + Vs
                        ( Nai * pNa + Ki * pK + 4 * p'Ca * Cai * ef) 

 where:
           V = GHK potential (reversal potential for the channel)
          Vs = surface potential due to external Cao (set by dcavoff, dcaspvrev)
           T = temperature (deg K)
         Nao = Na external concentration
         Nai = Na external concentration
         pNa = Na permeability through channel
          Ko = K  external concentration
          Ki = K  external concentration
          pK = K  permeability through channel
         Cao = Ca external concentration
         Cai = Ca external concentration
         pCa = Ca permeability through channel 
          ef =   exp((V-Vs) F / RT )
        p'Ca = modified Ca permeability = pCa / (1 + ef)
This more detailed GHK voltage equation is an "implicit" function, i.e. V is on both left and right sides of the equation. The reason for the extra terms for Ca is that Ca++ has a valence of 2 so the normal GHK equation for RT/zf is RT/2F. The extra terms have the effect of adding the extra 2. [ This equation is derived from the GHK current equations for mono- and di-valent ions assuming "independence" between ion motion in a "constant field theory" by Lewis (1979), J. Physiol. 286: 417-445. Though more complete than the simple GHK equation above, ions in some combinations do not have independence so even a more complex equation would be necessary at some combinations of ion concentrations to completely specify ion flux. ]

To solve this equation, a starting value for V is given and "ef" computed, and the equation solved for a new estimate of V. The process continues for 2-5 iterations until the difference between the new and old estimates for V is small ( 0.1 mV ).

The surface potential Vs is a function of the concentration of divalent ions on the external surface of the membrane (for our purposes, Cao). External calcium shifts both gating properties and reversal potentials, though to different amounts. The shift in the gating properties is about 18 mV negative for each factor of 10 increase in Cao. Therefore an increase in Cao makes the membrane voltage more negative (for gating channels) and causes Na channels to be less activated. The effect on the reversal potential is positive but less, and is set by the "dcaspvrev" variable (default = 0.18), which multiplies dcavoff (.018) for a value of 3.2 mV positive shift / factor of 10 increase in cao.

Click here to return to section index


Photoreceptor responses

The response of photoreceptors to light is simulated in NeuronC by a special set of difference equations bundled into a "transduction mechanism". This mechanism is a simplified model of the biochemical transduction cascade now thought to exist in photoreceptors. The model includes several important effects widely assumed to characterize the light response, such as flash response waveshape, response linearity over a narrow range, response saturation with bright flashes, and adaptation with background light.

Two-stage dynamic model

Dynamic compartmental modeling depends on 2 levels of abstraction for its analogy with a neural circuit. At the first level, a circuit is broken into small compartments which are modeled as electronic circuits. At the second level, a computer simulates the operation of the electronic circuits in time using difference equations evaluated with standard mathematics functions. Either of these steps (neural -> electronic, electronic -> difference eqn.) can be accomplished in other ways, such as by simulation on an analog computer, but it is convenient to run the complete simulation on a digital computer.

Click here to return to section index


Space constant, compartment size, and spatial accuracy

Compartmental modeling is limited in the accuracy of its spatial representation, that is, the accuracy of voltage relationships along a neural cable. Spatial accuracy is related to the "space constant", or how far current flows laterally through a cable. If the space constant is small, current flows laterally only a short distance before it passes through the membrane, and smaller compartments are needed to simulate this accurately. Inversely, longer compartments are allowable with a large space constant. A useful rule is to create compartments equal to 0.1 times the space constant, that is, to cause any segment of a cable shorter than 1 tenth of a space constant to be isopotential. The space constant of a cable segment is determined by its diameter, axial and membrane resistance (not by its length).

NeuronC uses an automatic method for determining compartment size. It calculates each neural cable's space constant (from diameter, axial and membrane resistance) then calculates the compartment size as a fraction of the space constant (normally 1/10th). This causes the size of the compartments to be varied according to the properties of the cable that defines them.

Click here to return to section index


Time steps and numerical integration

The time properties of the neural circuit can be effectively simulated by breaking the passage of time into small steps. These time steps must be short enough that a compartment's voltage does not change much during the step. The voltage change in a compartment is proportional to the current flowing to neighboring compartments so if the time step is small enough, the actual voltage change is closely approximated (to first order) by a constant derived from current flows. This approximation is justified by analogy because if the voltage in all the compartments doesn't change much during a time step, then the current flow from a compartment to its neighboring compartments cannot change much. The voltage at the next time step is computed by integrating the voltage change from the previous step; this process is termed "numerical integration".

It is relatively easy to simulate almost any time-related change in properties of neural elements using a compartmental model, because by analogy these properties do not change for the purposes of the simulation during the course of one time step. Small jumps in channel properties, for example, are allowable over a sequence of time steps because if they're small enough, they faithfully represent the effect of continuous change.

Click here to return to section index


Stability

Numerical simulation of compartments sometimes gives incorrect answers (even using time steps small enough to assure good accuracy) because of mathematical instability. If compartments are closely coupled so that current spreads easily between them ("stiff coupling"), the numerical simulation can develop oscillations over space and time that grow very large and make the simulation useless. This happens because inevitable roundoff errors in the computer numeric processing cause alternate, incorrect solutions to the difference equations to swamp the correct ones. There are several ways to to assure freedom from this type of instability. First, one can reduce the time step, but this reduces the computation speed. Second, one can increase the size of the compartments to increase the axial resistance connecting them. This causes the compartments to be less closely coupled to each other. Third, a better way is to use an "implicit" mode of integration as described below.

Click here to return to section index


Three methods of numeric integration

Euler method

The simplest method of numerically integrating a compartmental model, the Euler method (or "forward Euler"), is to calculate the voltage change during a time step from the current flows that existed into compartments at the beginning of the time step. This calculation is simple and very fast but is subject to the instability problem from stiff coupling discussed above. As a result, time steps need to be very small when voltage changes are large, for instance when a voltage clamp shifts the clamp voltage quickly. Even though the actual calculation per time step is very fast, the Euler method is often extremely slow overall, because it may requires smaller time steps than other methods. The Euler method is an "explicit" method because the calculation of voltage for the end of a time step in a compartment depends only on information available at the start of the time step.

Implicit method

As described above, one way to increase speed is to cause the numeric simulation to be unconditionally stable for any size time step. Stability allows larger time steps to be taken and increases accuracy, so it significantly increases the speed of simulation. Stability can be achieved by calculating the voltage change in a compartment based on current flows at the end of the time step. By computing all the voltage changes as a function of each other, the problem of mathematical instability is avoided and all the compartments have correct voltage and current flows at the end of each time step. This is called the "implicit" method because the voltage in a compartment calculated for the end of a time step depends not only on other compartments' voltages but also on itself, i.e. the voltage is an implicit function of itself.

The implicit method ("backwards Euler" method) of numerical integration is more difficult to calculate than the Euler method because the voltages and current flows for the end of the time step are not known until the voltage calculation for each compartment is complete. However this type of computation is equivalent to solving a system of N simultaneous equations in N unknowns (N=number of compartments), which is solvable by matrix techniques.

Crank-Nicholson method

The assumption that voltage change is constant during a time step simplifies numerical integration, but in fact the voltage change may not be constant. Often the voltage change calculated at the beginning of the time step may vary significantly from the voltage change calculated at the end of the time step. This would be the case, for example, if a large conductance turned on during the time step. Assuming that the voltage function has constant curvature (constant second derivative of voltage with time), one way to achieve better accuracy is to average the voltage changes calculated at beginning and end (take the average of Euler and implicit methods), and to use this average voltage change for integrating the voltage through the entire time step. This is called the Crank-Nicolson method, used originally for computing heat flow, and is more accurate than the implicit method and faster than Euler's method. The Crank-Nicolson method is a "second-order time" method because it calculates the derivative at two places (beginning and end) during each time step (see Joyner, et al, 1978 and Hines, 1989).

Although there are higher-order methods to calculate the continuous voltage during a time step, these methods always require more computation per time step. Thus, there is a compromise between accuracy and speed, and higher-order numerical integration schemes are only useful if their time steps can be made proportionately longer. Empirically, the second-order Crank-Nicolson method is often faster than the Euler or implicit methods because larger time steps can be taken as a consequence of its better accuracy (see Moore and Ramon, 1974). However, fourth-order (in time) methods are often slower than second- order methods for simulations of neural circuits with commonly used timesteps (between 10 and 100 usec).

Click here to return to section index


Difference equations for implicit method

What follows is the derivation of the difference equation for one compartment, using the Crank-Nicholson implicit method of numerical integration (refer to figure). This derivation shows only 2 neighbor compartments for clarity, but the derivation is similar when a compartment has many connections to other compartments. The calculation is repeated for all compartments several times for each time step until the value of "v2n" converges.
Voltage change in a compartment =  dt/c * average of new and old currents

v2n-v2 = k * ( (i1 + i3 + i1n + i3n) / 2 - ( i2 + i2n) / 2 )  

v2n-v2 = k/2 * ((v1-v2)*s1 + (v3-v2)*s2 + (v1n-v2n)*s1 +
                    (v3n-v2n)*s2  - (v2-vm + v2n-vm)*sm  ) 

v2n-v2 = k/2 * ( v1*s1 + v3*s2 - v2  * (s1+s2+sm) + v1n*s1 + 
                    v3n*s2 + 2*vm*sm - v2n * (s1+s2+sm) )

v2n * (1 + k/2 * (s1+s2+sm)) = v2 + k/2 * ( v1*s1 + v3*s2 -
                    v2 * (s1+s2+sm) + v1n*s1 + v3n*s2 + 2*vm*sm )

v2n = (v2 + k/2 * ( v1*s1 + v3*s2 - v2 * (s1+s2+sm) + v1n*s1 +
                    v3n*s2 + 2*vm*sm)) / (1 + k/2 * (s1+s2+sm))

v2n = (v2 + k/2 * ( v1*s1 + v3*s2 - v2 * (s1+s2+sm) + v1n*s1 +
                    v3n*s2 + 2*vm*sm)) * implicit factor
where:
     v2 = voltage in this compartment at start of time step
    v2n = voltage in this compartment at end of time step
     vm = membrane leakage reversal potential
     s1 = conductance to neighbor compartment 1
     s2 = conductance to neighbor compartment 2
     sm = membrane conductance in this compartment 
      k = dt/c
      c = membrane capacitance of compartment
     dt = time step
     implicit factor = 1 / ( 1 + k/2 * (s1+s2+sm))




References: Joyner et al, 1978
            Crank and Nicholson, 1947
            Hines, 1984; 1989

Click here to return to section index


Derivation of first and second-order implicit calculation of alpha and beta rate constants for Hodgkin-Huxley channels.

  dm    = alpham - (alpham+betam) * m          (original HH rate equation) 
  dmest = alpham - (alpham+betam) * mest       (implicit version)
  mest = m + (dm+dmest) / 2                    (second-order C-N version)

  mest = m + (alpham-(alpham+betam)*m + alpham-(alpham+betam)*mest) / 2

  mest (1+alpham+betam) / 2) = alpham + m * (1-(alpham+betam)) / 2)
 
  mest = (alpham + m * (1 - (alpham+betam)/2)) / (1 + (alpham+betam)/2) ( CN )

  mest = k1 * m + k2 

  where:
         k1 = (1 - (alpham+betam)/2) / (1 + (alpham+betam)/2)
         k2 = alpham / (1+(alpham+betam)/2)
Fully implicit version:
  mest = m + alpham-(alpham+betam)*mest        (implicit version)

  mest (1+alpham+betam) = m + alpham

  mest = (alpham + m) / (1 + alpham + betam)

  mest = k1 * m + k2

  where:
         k1 =  1     / (1 + alpham + betam)
         k2 = alpham / (1 + alpham + betam)

Since the multipliers k1 and k2 are functions of only voltage, they are precomputed and placed in lookup tables, after the method of Hines (1984). Since the rate equations are second-order, they need not be re-computed for each iteration for a compartment's voltage. Instead, the implicit estimated value is used and this allows the calculation to run substantially faster.

Click here to return to section index


Derivation of second-order implicit calculation of calcium diffusion in shells and to calcium buffer.

   B + Ca.B = Bt              ( free buffer + Ca-bound buffer = total buffer )

               f >
   B + Ca  <--------> Ca.B    ( defines forward and reverse rates )
             < r

Where:
        Ca   = free [Ca] in shell
        B    = free buffer in shell
        Ca.B = Ca-bound buffer
        Bt   = total buffer
        f    = forward rate, /M/sec
        r    = reverse rate,   /sec
        [ Buffer equations here from Yamada et al. (1998) ]

   d[Ca]/dt = r * [Ca.B] - f [Ca] [B]      ( change in Ca from Ca buffer )

                                        ( change in Ca from spatial diffusion )

   d[Ca]/dt = ( [Ca(left  neighbor shell)] - [Ca(this shell)] ) * S +
           ( [Ca(right neighbor shell)] - [Ca(this shell)] ) * S  


   dCa = dt * r * (Bt - B) - f * Ca * B + (Caj - Cai) * S + (Cak - Cai) * S

   dCaest = dt * r * (Bt - Best) - f * Caest * Best + (Cajest-Caest) * S + (Cakest-Caest) * S


Where:
       dca    = change in Ca at the beginning of the time step
       dcaest = change in Ca at the end of the time step
       i = shell being computed
       j = i - 1  (left neighbor shell)
       k = i + 1  (right neighbor shell)
       Best   = new estimate of B
       Caest  = new estimate of Ca in this shell
       Cajest  = new estimate of left  neighbor Ca
       Cakest  = new estimate of right neighbor Ca
       S = shell diffusion multiplier

Fully implicit solutions

The "difference equation" solution of the above equations for calcium and buffer concentration can be made "fully implicit" by solving for Ca and B at the end of the time step. This solution is more stable but less accurate than the second-order Crank-Nicolson method.

 
  Caest = Ca + dCaest

  Caest = Ca + r*Bt - r*Best - f*Caest*Best + (Cajest+Cakest-2*Caest)*S

  Caest (1+f*Best+2*S) = Ca + r*(Bt-Best) + (Cajest+Cakest)*S
  
  Caest  = Ca + r*(Bt-Best) + (Cajest+Cakest)*S / (1+f*Best+2*S)      (1)

  Best = B +  dBest

       = B + r * (Bt - Best) - f*Caest*Best

  Best (1+r+f*Caest) = B + r*Bt

  Best = (B + r*Bt) / (1+r+f*Caest)                                   (2)

Crank-Nicolson solution

The second order method for solving for calcium and buffer concentration is to compute the values at the middle of the time step by averaging the values from the beginning and the end of the time step. This is more accurate but less stable than the "fully implicit" solution above:

For Calcium:

   Caest = Ca + (dca + dcaest) / 2


Substituting:

  Caest = Cai + ( r * (Bt - B) - f * Ca * B + r * (Bt - Best) - f * Caest * Best +

          (Caj - Cai) * S + (Cak - Cai) * S + (Cajest - Caest) * S + (Cakest - Caest) * S ) / 2

Rearranging:

  Caest = Ca + ( 2*r*Bt - r*B - r*Best - f*Ca*B - f*Caest*Best +

          (Caj + Cak - 2 * Ca + Cajest + Cakest - 2 * Caiest) * S ) / 2


  Caest = Ca * (1 - f*B/2 - S) + r*Bt - r*(B+Best)/2 - f*Caest*Best/2 +

          (Caj + Cak + Cajest + Cakest) * S / 2  -  Caest * S

Solving for Caest:

  Caest * (1 + f*Best/2 + S) = Ca * (1 - f*B/2 - S) + r*Bt - r*(B+Best)/2 +

                               (Caj + Cak + Cajest + Cakest) * S / 2 


Switch f*Best with f*B:              (allowed by Taylor series expansion after Yamada et al, 1998)

  Caest * (1 + f*B/2 + S) = Ca * (1 - f*Best/2 - S) + r*Bt - r*(B+Best)/2 +

                               (Caj + Cak + Cajest + Cakest) * S / 2 


  Caest * (1 + f*B/2 + S) = Ca * (1-S) + r*Bt - r*B/2 - Best*(Ca*f + r) / 2 +

                               (Caj + Cak + Cajest + Cakest) * S / 2 


  Caest = [ Ca + r*(Bt-B/2) - Best*(Ca*f+r)/2 +
		(Caj+Cak+Cajest+Cakest-2*Ca) * S/2 ]  / implf         (3)
  
   Where:
          implf = (1 + f*B/2 + S)


For Buffer: Remove spatial diffusion, solve for Best: Best = B + (dB + dBest) / 2 = B + (r*(Bt - Best) - f*Caest*Best + r*(Bt - B) - f*Ca*B) / 2 Solving for Best: Best (1 + (r+f*Caest)/2) = B + r*(Bt-B/2) - f*Ca*B/2 Best = (B + r*(Bt-B/2) - f*Ca*B/2) / (1 + (r+f*Caest)/2) (4)

Strategy for solving Ca diffusion equations:

The idea here is to write an "implicit" equation that can be solved for the Ca concentration at the end of the time step. This number is dependent on the neighboring Ca concentrations at the end of the time step. These are unknown, but are gradually updated by iterating over all the compartments. Calculate Caest and Best alternately so that buffer gets updated along with Ca.

Iterate equations 1 and 2 (or 3,4) over all the compartments. When change in Caest from one iteration to next is small ( < 1e-10) stop.

Typical number of iterations is 2-5 so computation is relatively fast.

Click here to return to section index


Time constant, time steps, and accuracy

The time constant of a neuron (or a compartment) describes how fast the membrane voltage can change. The time constant is the product of membrane capacitance and the shunting (membrane) resistance, and is normally about 1 to 5 msec for many neurons. However, in some cases the time constant can be much greater, up to 20 msec in photoreceptors or 100 msec in horizontal cells of retina. A long time constant allows larger time steps to be taken for numerical integration because the voltage change per time step is limited by the time constant. A good rule is to use a time step at least 10 times shorter than the membrane time constant; normally 50 to 100 usec (1e-4 sec) is short enough for good accuracy.

Accuracy of voltage change over time can be determined by successive simulation runs with different size time steps. For example, one could decrease the time step by a factor of 2 until the voltage response of the model does not change from a previous run more than a criterion of say, 0.1 percent. This assures an absolute accuracy of 0.1 percent in the voltage calculated.

Click here to return to section index


Drawbacks of compartmental modeling

While dynamic (time-varying) compartmental modeling has many advantages it has several drawbacks as well. First, the time step required to maintain stability and accuracy of voltage in a neural circuit is often very short. In this case many time steps are needed to model even a few milliseconds of time, and the numerical simulation proceeds slowly. If only a rough estimate of a neural circuit's response is needed, it may be better to use a static modeling technique, for which multiple integration time steps are not required.

Second, compartmental modeling breaks up neural circuits into discrete spatial "chunks" which causes the voltage response to be inaccurate. If many tiny compartments are used to describe a neural cable segment, the inaccuracy is insignificant but the model runs slowly. If just a few larger compartments are used to describe the same cable segment, the model runs faster, but waveshapes and amplitudes of the voltage response are noticeably wrong.

The overall problem with compartmental modeling, then, is the generally slow computational speed. Both of the problems with inaccuracy that occur with compartmental modeling (space, time) can be solved by making the model run more calculations, therefore slower. Thus most ambitious compartmental modelers usually end up eyeing large main-frame computers as a "way out" of their modeling problems.

There are many new designs for "parallel" computers (computers with many processors running simultaneously) that are supposed to give a huge increase in speed over standard single-processor computer designs. These parallel computers commpute regular connections between arrays of compartments very quickly. But the connections between compartments in a neural circuit model are often not regular (branch and synaptic connection patterns), so parallel computers designed for regular connections may not be helpful for running neural circuit models. Currently, it seems that our best bet is to concentrate on computers with very fast integer and floating-point operations.

Click here to return to section index