Retsim: a retinal simulator


Overview

"Retsim" is a set of scripts that construct a simple model of a retinal neuron and its presynaptic circuit. A light stimulus is transduced by an array of photoreceptors (rods and/or cones), and the resulting signals are synaptically transmitted to an array of bipolar cells, which in turn transmit their signals to one or more ganglion cells. The arrays of different neuron types are generated as semi-random arrays, given a cell density and a regularity (mean/s.d) or by array size or number. Synaptic contacts are automatically set based on a connection algorithm specified in a paramater table.

The main script is "retsim1.n" or "retsim.cc" which defines a set of parameters to control the construction of the stimulus, calls construction subroutines to make the different cell arrays, calls connection subroutines to connect the cell arrays, and defines a procedure to display the model, and run an experiment on it. The "makcel" script constructs the neurons, and the "synfuncs" script makes the connections.

Script              Function

retsim              main script, oversees construction, connection, display, and run.
retsim_var          variable definitions, set pointers for command-line values.
makcel              makes arrays of neurons, either realistic or artificial.
synfuncs            connects arrays and individual neurons with synapses based on algorithm.
celseg              makes spheres and cables with biophysical properties.
celfuncs            functions to help make cells.
stimfuncs           stimulus functions.
plot_funcs          plotting functions.
sb_makfuncs         starburst cell make functions.
sb_recfuncs         starburst cell recording functions.
setexpt             sets dynamic loaded experiment files
onplot_movie        movie frame functions
onplot_dsgc_movie   DS ganglion cell movie functions (includes "onplot_movie")
maknval             script to create table of parameters "nval.n".   
expt_gc_cbp_flash   experiment file: defines and sets parameters, sets up and runs experiment.
nval.n              parameter table
runconf/dens.n      channel density table  (subdir runconf is configurable)
runconf/chanparams  channel param table (voffset, tau)

Definining extent of neural arrays

Retsim starts by constructing the largest and most downstream neuron. Typically this is a ganglion cell, but it can also be another neuron such as an amacrine cell (e.g. the starburst amacrine) or a bipolar or horizontal cell. The size of this cell determines how large the model and its arrays of presynaptic cells will be. Next, the presynaptic array is generated, given a cell density and regularity (mean/s.d.). Typically the regularity is set to 5-10, but very realistic arrays can be generated with regularities from 3 (almost random), to 50 (triangular/hexagonal array as in foveal cones). The extent of this array determines the size of the next higher presynaptic array (typically photoreceptors). The neuron types included in the simulation are defined by the user in the "experiment file".

If a smaller array is required, a large cell and array of presynaptic neurons can be trimmed using the "arrsiz" parameter, which sets the maximum size in microns for the array. Any neurons or parts of a neuron outside this limit are trimmed away before the simulation is run.

Generating cell morphologies

To construct a cell with realistic morphology, several algorithms are available:

1) A cell can be digitized from a photograph or a confocal stack of images. The information is placed into a text file, organized by points, called "nodes", that describe the locations of soma, axon, and dendrites and their branch-points. Each node connects with a cable to its "parent" node, and this information is listed in the file, along with the cable diameter, (x,y,z) location, and the "region", used for supplying biophysical properties:

-----------------------start of morphology file---------------------
#
#  beta cell anatomy file,  2006 Oct 4
#
#    node     parent   dia      xbio     ybio    zbio   region      dendr
#
       0        0       21        0        0      -25   SOMA        0
       1        0     2.17       21    -2.47       -8   DEND_PROX   1
       2        1    0.833     22.8   0.0287       -5   DEND_DIST   1
       3        2     1.33     23.3    0.776        0   DEND_DIST   1
       4        0      0.5     13.9    -6.32        0   DEND_DIST   2
       5        0      1.5    -3.25    -33.6      -30   HILLOCK     0
       6        5      0.5    -6.81    -37.6      -30   AXON_THIN   0
       7        6      0.5    -25.5    -66.4      -30   AXON_THIN   0
       8        7      0.5    -121.2  -160.2      -30   AXON_PROX   0
The variables "SOMA", "DEND_PROX", "DEND_DIST", etc. are labels for the region. These labels are variables that are defined in retsim_var.cc. You may change the values of these variables, and you may add your own additional ones in the morphology file. You may also use another set of labels, "R1", "R2", "R3", etc. that are predefined in retsim_var.cc. These regions are for use in the "dens_xxx.n" file (see below), where each column defines the density of channels and other values such as Rm, Ri, complam, and color for that cell region.

The "dendr" column defines dendrite numbers to be utilized for selectively constructing dendrites. If any of the command-line variables "sbac_dend1,sbac_dend2 ... sbac_dend5" are set, the dendrites with these numbers will be constructed from the morphology file, and other dendrites will not be constructed. If in addition the "sbac_dend_cplam" variable is set, the other dendrites (not set in sbac_dend1-5) that would have not been constructed are now constructed with compartment size set by sbac_dend_cplam. This arrangement is useful for constructing a model with just one or a few dendrites included with small compartments for high resolution, and all the other with large compartments, to minimize the number of total compartments. Other variables gc_dend1-5 and aii_dend1-5 are also defined for use with these cell types.

There are several methods available for digitizing neural morphologies:

Digizing neurons with Xfig

You can digitize manually using a photograph or drawing imported into "xfig" (illustrator program in Linux). You digitize a cell's morphology to label its nodes with numbers (see Constructing Neural Circuits->Digitizing cell morphologies"). You manually enter the labels for each node. Xfig will then remember their (x,y) positions. Save the .fig file, convert to Neuron-C format (above) using "fig2nc", then use a text editor to correct the parent nodes and add the diameters. You can find fig2nc in "nc/models/retsim/runconf".

Digizing neurons with IJ-MorphDig

IJ-MorphDig is a Java plugin for ImageJ, an image-processor program. You can import a stack of confocal images, then place node points, along with their diameters measured with a "caliper tool". MorphDig outputs the data in the Neuron-C standard morphology format (above). You can find the IJ-MorphDig package in "nc/models/retsim/runconf".

Digizing neurons with NeuroLucida

You can convert neural morphologies from NeuroLucida format using "dsconv2", which is a script in bash/gawk for Linux. You can find this script in "nc/models/ds/ds3".

Digizing neurons with Neuromantic

You can convert neural morphologies from Neuromantic format using "neuroman2nc", which is a script in bash/gawk for Linux. You can find this script in "nc/models/retsim/runconf".

Artificial morphology from parameters

You can generate an artificial morphology by algorithm (in "retsim/makcel.cc"), based on the number of primary dendrites, dendritic field extent, and branching pattern. Quite realistic morphologies can be generated for horizontal cells, some types of amacrine and ganglion cells.

Artificial morphology from connection algorithm

An artificial morphology can be generated by the connection algorithm. A "skeleton" of the cell consisting of the soma and proximal dendrites is created at the appropriate location (see "Making arrays of neurons" above) and the dendrites or axon (where applicable) are extended to the closest branch of the nearest neuron of the other type. For example, photoreceptors connect to horizontal cells by extending the horizontal cell dendrites. This algorithm is performed sequentially over all the photoreceptors, at random using a Gaussian probability profile, so that relatively random branches are generated for the first several photoreceptors, which generates a relatively realistic branching pattern.

Array topology from connection algorithm

To generate an array of neurons, you specify the morphology type, either from a digitized file, or from an artificial morphology type. You can also specify the size and rotation of the cell. Normally the rotation is random so that you can use a digitized morphology without concern that its dendrites will generate a regular array of dendritic overlaps. The density of the array can be specified either using the overall array size in microns along with a number of cells, or by defining the cell density (cells/mm2).

Displaying the model

To display the morphology, use the "-d 1" command-line switch. This will display all the cells but not the node numbers or the compartments. To display nodes, use the "-d 9" switch, which displays the node numbers superimposed on the morphology. This is also described in the help table printout from "retsim -h", which shows all of the possible display features. To display the compartments, use the "-d 6" or "-d 15" switch.

Displaying nodes
To set the display of node numbers in the model, you can set which of the node numbers to display, 2 => the cell number, and 3 => the nodes within the cell. You can also set the font size for the node number by taking a size in the range 0.1 - 5, dividing by 10, and adding this to the node number, then multiply by -1. For example, for a display of the nodes in a cell with a small font, you can use -3.05. For a display of the cell number in an array of cells, you can use -2.2.

To set the node number and font display for a cell type, set the variable "cell_nscale" (cell = cell name) with the display number as described above. You can set this variable on the command line, or in the experiment file in the "setparams()" procedure. To set the node displays for all the cell types, use the variable "node_scale". If set, the "cell_nscale" variable overrides the "node_scale" variable.

Displaying nodes in one type or cell
Often one wants to see the node numbers for only one type of cell, for example, the cell number in an array of cells, or the nodes within one specific cell. To do this, you can set "disp_ct" and "disp_cn". If you set "disp_ct" the simulator will only display cells that contain nodes of that cell type. If you also set "disp_cn" the simulator will display only the cell with that cell number.
  retsim --expt gc_cbp_flash --node_scale -2.1 -d 9 -v | vid
  retsim --expt gc_cbp_flash --node_scale -2.1 --gcb_nscale -3.05 -d 9 -v | vid

Neural and biophysical parameters

Neuron parameter file "nval.n"

Retsim is organized around a table of parameters "nval.n". Each column contains the parameters for one cell type, and each row gives the values of one parameter for all the cell types. The table can be viewed and modified using a standard text editor, which makes it easy to change/copy values. The "nval.n" table sets the default values for the construction of the neural circuit. It is created by "maknval" which allows different versions of nval.n to be created. The parameter values in "nval.n" can be specified individually in any particular experiment, using the "getn(PARM)" and "setn(PARM,val)" functions, or from the command line using variables that you define and set in the experiment file, in the "defparams()" and "setparams()" procedures.

How to create nval.n neuron parameter file

To create a new nval.n file, you can modify an existing nval.n file or you can make a new one by running:
"maknval.n > nval.n".
To add new parameters to nval.n, you can edit "maknval.cc", compile it with "make maknval", and run "maknval > nval.n" as shown above, then copy nval.n to "nval.h":
cp nval.n nval.h
Then remove the numerical parameter definitions from the end of nval.n using an editor such as vi or kwrite. Next, remove the nval.n table at the beginning of nval.h. Next, copy nval.h to "nval_var.h", "nval_var.cc", and "nval_var_set.cc" and edit these files to leave only their correct contents, shown in comments in the file. Then remove this content from nval.h. Last, "make clean" and "make retsim". This description is included in the beginning of "nval.n".

Adding new parameters to "nval.n"
The last (right) column in the nval.n file is the name of the parameter. This name is a variable that has an integer value, which is preset by default. To add a new parameter, you can edit the nval.n file and add a new row. Then you edit the maknval.cc file to add the new parameter, and run "maknval > nval.n". Then copy the nval.n file to nval.h, and edit nval.h to give new versions of nval.h, nval_var.h, nval_var.cc, and nval_var_set.cc.

You can simplify the nval.n file to remove the columns and rows that are not required for your experiment. This does not require any changes to nval.h, nval_var.h, nval_var.cc, or nval_var_set.cc. The rows and columns can be in any order (except for the first row and the last column, which contain the labels). This works because the rows and colums are described by labels, and when retsim reads in the nval.n file, the data from the file is placed in the correct row and column by referring to the labels.

Description of parameters in "nval.n"

The first block of the nval.n parameters describes how a neuron is to be constructed, some of its biophysical parameters, and also the density and maximum number of cells in an array. The second block, starting with CELPRE1, sets the input synaptic connections for a neuron. The third, fourth, and all the other blocks of parameters starting with CELPOST(1,2,3...) define the output synaptic connections. Note that the default values are set by the "maknval.cc" (maknval.n) file that generates the nval.n file.

First block of parameters in nval.n, for constructing cells:

_MAKE      # whether to make this cell type
_MAKE_DEND # whether to make dendrites
_MAKE_AXON # whether to make axon
_MAKE_DIST # whether to make axon distal
_NMADE     # number of cells made
_MAXNUM    # maximum number of cells of this type
_NCOLOR    # color of this cell type for display
_MAXCOV    # max coverage factor (for arrays)
_MAXSYNI   # max number of syn input cells per celltype
_MAXSYNO   # max number of syn output cells per celltyp
_DENS      # density of this type (per mm2)
_REGU      # regularity (mean/stdev) of spacing
_MORPH     # morphology (=0 -> file, or >0 -> artificial)
_COMPLAM   # compartment size (default=complam)
_BIOPHYS   # add biophys properties (use channel density file dens_xxx.n)
_CHNOISE   # add membrane channel noise properties  
_RATIOK    # set K density values as ratio from Na
_VSTART    # initial resting potential, when BIOPHYS==0
_VREV      # membrane potential for Rm (VCl), when BIOPHYS==0
_NRM       # the cell's Rm when BIOPHYS==0
_SOMADIA   # Soma diameter for artificial morphology
_SOMAZ     # Z location (x,y loc determined by array)
_DENDARB   # type of dendritic tree, non-branched, branched, etc (retsim.h).
_DENDARBZ  # dendritic arborization level for artificial morphology (synfuncs.cc)
_DENZDIST  # dendritic arborization z tolerance for synaptic input. (synfuncs.cc)
_STRATDIA  # stratif. annulus dia (fract of treedia) for artificial morphology. (synfuncs.cc)
_DTIPDIA   # diameter of dendritic tips for artificial morphology (makcel.cc,synfuncs.cc)
_DTREEDIA  # diameter of dendritic tree (for artificial and real morphology, allows synaptic connection). 
_AXARBT    # type of axonal tree 
_AXARBZ    # axonal arborization level for artificial morphology
_AXTIPDIA  # diameter of axonal tips for artificial morphology
_AXARBDIA  # diameter of axonal arbor (for synaptic connections, synfuncs.cc)
_MAXSDIST  # maximum synaptic distance (for synaptic connections, synfuncs.cc)
_TAPERSPC  # space constant of diameter taper for artificial morphology.
_TAPERABS  # abs diameter for taper for artificial morphology.
_NDENDR    # number of first-order dendrites for artificial morphology.
_GROWTHR   # distance thresh for growth of dendrites for artificial morphology.
Second block of parameters in nval.n, describing synaptic inputs to a cell type. Each of these ends in a number which is the "synaptic input number" for a cell type. There are 8 possible inputs.

_CELPRE1   # cell type to connect to (negative -> no connection)
_CONPRE1   # connection number of presyn cell
_CELCONV1  # number of presyn cells to connect to
_GROWPOST1 # grow when making conn from presyn cell
Blocks for synaptic output parameters, note that each block ends with the same number which is the "synaptic output number". There are a maximum of 7 possible outputs:

_CELPOST1  # cell type to connect to (negative, no connection)
_CONPOST1  # connection number for postsyn cell (its synaptic input number from above)
_CELDIV1   # number of postsyn cells to connect to (maximum)
_GROWPRE1  # grow when making conn to postsyn cell
_SYNSPAC1  # synaptic spacing in dendritic tree (if positive, this enables many synaptic outputs per cell)
_SYNANN1   # inner dia of annulus in dendritic tree (allows synapses outside this radius)
_SYNANG1   # angle for postsynaptic cell (sets allowable angle in degrees)
_SYNRNG1   # range of angles for postsynaptic cell (if positive, sets allowable range, if neg, set angle from somas)
_USEDYAD1  # synapse is dyad using preexisting type 
_DYADTYP1  # type of dyad synapse to connect with(sets which type of presynaptic cell for dyad 1->2 cells )
_AUTAPSE1  # synapse back to presynaptic node (allows cell to connect to itself)
_SYNNUM1   # number of synapses per connection (sets more than 1 synapse per connection, typical for bipolar cells)
_SENSCA1   # synaptic release sensitivity calcium (use [Ca]i for driving release instead of expon function)
_SRRPOOL1  # synaptic readily releasable pool (sets size of pool)
_SMAXRATE1 # maximum synaptic release rate (sets maximum release rate)
_SGAIN1    # synaptic gain (sets exponential gain, mV/efold increase, when not using [Ca] sensitivity)
_SVGAIN1   # synaptic vgain (sets additional linear gain factor)
_SDURH1    # synaptic high pass time const. (sets high pass filter for release)
_SNFILTH1  # synaptic high pass nfilt (sets number of high-pass filters for release)
_SHGAIN1   # synaptic high pass gain (sets high pass filter gain relative to unfiltered release)
_SHOFFS1   # synaptic high pass offset (sets offset in mV for high pass func for release)
_SVSIZ1    # synaptic vesicle size (sets vesicle size without changing overall release, i.e. changes release rate)
_SCOND1    # synaptic conductance (maximum conductance when potsynaptic receptor is saturated)
_STHRESH1  # synaptic threshold (threshold for exponential release in mV).
_SVNOISE1  # 1->allow vesicle noise, override, vnoise=0 
_SCOV1     # 1=Poisson, <1->more regular, gamma dist (sets properties of noise distribution for release)
_SDUR1     # synaptic event time const. (sets time constant for lowpass filter of vesicle release: mini shape)
_SFALL1    # synaptic event fall time const. (sets separate first order fall time for mini PSPs)
_SNFILT1   # synaptic vesicle nfilt (sets number of lowpass filters for mini waveshape)
_STRCONC1  # synaptic transmitter concentration. (multiplier for neurotrans conc with ligand-gated channel)
_SRESP1    # synaptic response (ampa,gaba,gj,etc). (sets which Markov state diagram to use)
_SCNFILT1  # second mesng. nfilt (number of lowp filters in postsynaptic cascade)
_SCDUR1    # second mesng. time const.(time const of filter in postsynaptic cascade)
_SCGAIN1   # synaptic second messenger gain (gain of second messenger)
_SCOFF1    # synaptic second messenger offset (offset of second messenger)
_SCNOISE1  # 1->allow channel noise, override, cnoise=0 (sets noise of postsynaptic channel)
_SNCHAN1   # number of channels (sets number of postsyn channels)
_SUNIT1    # synaptic channel unitary conductace (sets conductance of unitary channel)
_SVREV1    # synaptic reversal potential (usually either 0 for excitatoryh, or -0.065 for inhibitory)

Channel density file "dens.n"

When the "biophys" parameter is set to 1 in the nval.n file, retsim reads biophysical parameters such as conductance densities of voltage-gated channels, the starting voltage "vstart", the reversal potential for Rm "vrev", and Rm and Cm from a separate file (default name "retsim/runconf/dens_default.n"). This file contains a table that contains the channel types and their conductance densities for each region of the neuron. Each cell type has a default density file (e.g. "dens_dsgc.n"), but you can also give the file any name. You can specify on the command line which density file to use with "--densfile.n file.n", where file.n is your density file. You can also set this filename in the experiment file in the "setparams()" procedure.

Note that when the "biophys" parameter in the nval.n file is set to 0, then retsim does not read the dens_xxx.n file, and takes the "vstart", "vrev", "Rm", and "Cm" parameters from nval.n instead of a density file.

You can customize the density file using variables instead of numbers in the columns, for example, in the listing below, "drm" means use the default value of Rm preset by retsim. When retsim reads the numbers from the density file, it looks up any variables in the symbol table and replaces the variable with its numeric value. This means that you can use any variable, either predefined internally in the simulator (in retsim_var.cc), or defined in your experiment file, as long as the variable's value is defined before the density file is read. You can define the variable in the "defparams()" procedure, and you can set its value in the "setparams()" procedure or in the command line. The density file is read after this.

A typical dens.n file for retsim is:

# Default membrane properties (density) file
#
# Densities of currents for the cell's different regions (S/cm2).
#
#      DEND_DIST DEND_PROX SOMA HILLOCK AXON_THIN AXON  AXON_DIST VARICOS R9  R10 
#
0       R1      R2      R3        R4    R5      R6      R7      R8     R9     R10
#
_NA     0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    50e-3   0e-3   0e-3   0e-3  # Na2
_NA5    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3   0e-3   0e-3  # Na5
_NA6    35e-3   0e-3    0e-3    4e-3    4e-3    0e-3    0e-3    0e-3   0e-3   0e-3  # Na6
_NA8    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3   0e-3   0e-3  # Na8
_KDR    15e-3   0e-3    0e-3    15e-3   15e-3   20e-3   10e-3   0e-3   0e-3   0e-3  # K1
_KA     35e-3   0e-3    0e-3    35e-3   35e-3   0e-3    0e-3    0e-3   0e-3   0e-3  # K3
_KH     0e-3    0e-3    0e-3    0.09e-3 0e-3    0.8e-3  0e-3    0e-3   0e-3   0e-3  # K4
_SKCA1  0.12e-3 0e-3    0e-3    0.12e-3 0.00e-3 0e-3    0e-3    0e-3   0e-3   0e-3  # KCA4
_SKCA2  0.01e-3 0e-3    0e-3    0.04e-3 0.02e-3 0e-3    0e-3    0e-3   0e-3   0e-3  # KCA5
_BKCA   0e-3    0e-6    0e-3    0e-3    0e-6    0e-6    0e-6    0e-6   0e-3   0e-3  # KCA3
_CA_L   0.014e-3 0e-3   0e-3 0.014e-3 0.014e-3  0e-3    0e-3    0e-3   0e-3   0e-3  # Ca1
_CA_T   0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3    0e-3   0e-3   0e-3  # Ca5
_CAP    2e-7    0e-3    0e-3    1e-7    1e-7    0e-12   0e-3    0e-3   0e-3   0e-3  # CAPUMP
_CAE    0e-7    0e-3    0e-3    0e-7    0e-7    0e-12   0e-3    0e-3   0e-3   0e-3  # Caexch
_VST    dvs     dvs     dvs     dvs     dvs     dvs     dvs     dvs    dvs    dvs   # vstart
_VRV    vk      vk      vk      vk      vk      vk      vk      vk     vk     vk    # vrev
_RM     drm     drm     drm     drm     drm     drm     drm     drm    drm    drm   # Rm
_CM     dcm     dcm     dcm     dcm     dcm     dcm     dcm     dcm    dcm    dcm   # Cm
_CPL    cplam   cplam   cplam   cplam   cplam   cplam   cplam   cplam  cplam  cplam # cplam
_COL    green   blue    red     blue    blue    magenta yellow  gray   ltred  brown # color


Channel density file format

The "density file" (retsim/runconf/dens_xxx.n) defines the biophysical properties of a cell, region by region. Each column defines the biophysical properties of one region. The first (left) column of the density file is the name of the biophysical parameter, such as NA, KDR, or RM. These labels are the names of variables that have been set by default to have a value to index into the internal list of channel types. Some of the names, for instance, NA, KDR, KA, SKCA1, are aliases for other internal variables that contain the correct index number. The alternative internal values are in the last column, the comments to the right of the "#". The other columns (2-11) of the density file define conductance density values for each membrane channel type to be inserted into the cables and spheres of the model in the appropriate region.

The rows and columns of the density file can be in any order, and unused rows or columns can be deleted, because each column and row is indexed by the label at the top or left column, respectively. Any rows or columns undefined in the density file are set to zero.

You can tell the simulator to temporarily remove a row, for example, to remove a channel type from all regions in the cell, by redefining the variable to a value outside the allowable range of values. Or you can temporarily remove a region by redefining the variable to a value outside the number of regions. For example:

retsim --expt cell_vclamp --celltype dbp1 --dbp1_densfile dens_dbp1.n --KDR 99
or,
retsim --expt cell_vclamp --celltype dbp1 --dbp1_densfile dens_dbp1.n --R4 99
The first example runs expt_cell_vclamp.cc with the density file dens_dbp1.n file, except with the density of KDR set to 0 everywhere in the cell. The second example runs expt_cell_vclamp.cc with values in region R4 set to zero. Some of the rows, the values that are not conductances (RM, RI, VST, VRV, CPL, COL) are set to non-zero default values when the indexes are set out of range in this way. In "celseg.cc" look for zerodens (default densities).

Temperature dependence

The channel conductances vary with temperature, but are defined by convention in the dens_xxx.n file at 22 deg C. you must be careful to define them correctly for the temperature at which you are running the model ("tempcel"). At run-time (see "celseg.cc"), the conductance densities specified in the dens_xxx.n file are converted to number densities (n/um2) by dividing by the channel's unitary conductance (dxxxu). If channel noise is set, this number density affects the amount of noise generated by the channels. If you set the unitary conductance to 1e-8, then the conductance density specified in the dens_xxx.n file (S/cm2) directly defines the channel number density (n/um2). The unitary contuctance is modulated by temperature (controlled by a Q10 "dqxxx" value, see "Channel statement" in ncman2.html), but its value is specified at 22deg C.

Other channel types
To see all the possible channel types, see the "retsim/runconf/dens_default_full.n" file. If you want to add a channel type, if it's similar to an existing one, but differs in the time constant and/or the voltage offsets, you an set these parameters in the "runconf/chanparams" file. If you need to add a new channel type, see ncman3.html, "Adding New Channel Types". Once the new channel type has been added to the simulator, you can add it to retsim in the retsim_var.cc and celseg.cc files. Then you can add the new channel type to the dens_xxx.n file.

Region labels
The region labels are listed in the first row, above the numeric values of the table. They are "R1", "R2", "R3", ..., and are defined as integers by the simulator. They are used as an index into the internal array that the simulator creates by reading in the density file. Alternate labels are: "DEND_DIST", "DEND_PROX", "SOMA", "AXON", etc. Both sets of labels are are defined in retsim.h, and they are supposed to be specified in column 7 of the morphology file. If you want to selectively add or remove some regions of the model, there are selection variables (MAKE_DEND, MAKE_AXON, etc, set in the nval.n file) that allow you to make one region while ignoring other regions. You can also make up your own names for region labels and define them as integers in the experiment file in the defparams() procedure. Note that the labels that you want to use must be uncommented, that is, without a "#" in the first char on the line.

Adding rows and columns to the dens.n file
You can also add or remove lines (rows) in the density file, because the index label in the first column allows the simulator to correctly insert the information from the row into the internal channel density array. The first column contains names of variables that have been predefined with integer values to index into the density array. There are (currently) 38 possible biophysical properties that be defined by a row in the density file (see runconf/dens_default_full.n). Any properties that you don't include will be set to zero. You can add new lines into the middle of the array as long as their label in the first column is set to a valid name. You can change the value of the label variables in the "setparams()" procedure. You can also define alternate name labels as variables in the experiment file and use these instead of the existing name labels. They only need to contain the correct integer index. In addition, you can add or remove columns to define a different number of regions as long as the label at the top is set correctly. The columns can be in a different order because they are indexed by the predefined column labels.

Setting complam for regions
The compartment lambda ("complam") sets the size of the compartments. A larger complam generates larger compartments, and thus fewer of them. The default complam is a global variable, but you can also set the complam separately for each celltype, and for each region within a cell. To set the compartment size for a region, you can include a _CPL (=_CPLAM) row containing variables or number constants. If this row is not included, or if the value is zero or negative, then the complam is taken from the COMPLAM row in the nval_xxx.n file. If this value is zero or negative, the default complam is used. Thus, the _CPL row is optional.

Setting color for regions
To set the color of a cell's spheres and cables for display, you can set the colors of its regions by including the _COL row in the dens_xxx.n file with number constants or variables (blue, green, cyan, red, ...). To tell the simulator to use these colors, you define the cell's color as "rcolor", which is a special predefined value. You can do this in the nval_xxx.n file, or by setting the internal color value in the nval array using calls in "setparams()" to "setn()" and "getn()" (defined in "retsim.h"). If you set the cell's color to "rcolor", but don't include the _COL row in the density file, a default color map will set the colors by region. You can also set the color for the whole cell by setting the NCOLOR parameter for that cell type in the nval_xxx.n file. If this value is negative, the cell's color will be set by the cell number (the second dimension of its node number).

Channel parameter offset file "chanparams"

In addition to the channel density file you can specify a modification in the kinetics of the channels for a cell type. You can add a voltage to the activation and inactivation functions, and you can speed or slow the kinetics to modify the channel behavior. The "retsim/runconf/chanparams" file is a symbolic file with columns for each cell type that has channels, and rows that specify offsets or rate multipliers for each type of channel.

An entry in "chanparams" for the Na 1.2 channel type:

columns:        gca     gcb     gcaoff  gcboff  sb      dsgc    aii

#Na 1.2 channel parameters
Na2.offm:        0.001   0.001   0.001   0.001   0.005   0.0025  0.002
Na2.offh:        0.001   0.001   0.001   0.001   0.005   0.0025  0.002
Na2.taua:        1       1       1       1       1       1       24
Na2.taub:        1       1       1       1       1       1       24
Na2.tauc:        1       1       1       1       1       1       24
Na2.taud:        1       1       1       1       1       1       24

Connecting neurons

After the presynaptic arrays of neurons are generated, they are synaptically connected with an algorithm that for each presynaptic neuron connects it to a nearby postsynaptic neuron(s), and extends the presynaptic axon or the postsynaptic dendritic tree, if appropriate, to create a realistic anatomy. Realistic numbers of connections are generated, so that a postsynaptic neuron can receive synaptic connections from several presynaptic neurons, with multiple contacts if appropriate, and a presynaptic neuron can connect to several postsynaptic neurons if appropriate. For example, a bipolar cell receives synaptic contacts from several photoreceptors, but the nearest ones are most likely to make contacts.

One connection algorithm available in retsim calculates a Gaussian probability for making connections, so that each connection is made at random, yet the closest presynaptic neurons are more likely to connect. This allows two random arrays of neurons to be connected with Gaussian weighting functions relatively smoothly. The exact number of connections between a presynaptic and a postsynaptic cell can vary, but the average is closely controlled.

The type of connection algorithm used is specified by the type of presynaptic arbor and the the type of postsynaptic arbor. These properties are specified in the nval.n file as DENDARB and AXARBT. A value of 0 means non-branched, 1 means branched, and 2 means highly branched. When connecting a synapse to an unbranched postsynaptic dendritic tree, the postsynaptic tree is extended to generate more branches from the soma if the GROWPOST parameter for that synapse is set. A branched postsynaptic cell will extend new branches from its proximal dendrites. A highly branched postsynaptic cell will not grow branches but will allow synaptic contacts to be made if the presynaptic cell is within a criterion distance (MAXSDIST).

Trimming the unconnected neural arrays

After the neural arrays are generated and interconnected according to a connection algorithm, the neurons that didn't get connected are removed. This is necessary because the presynaptic circuit of a ganglion cell only extends typically 20-50 um beyond the ganglion cell's dendritic tips, yet precisely which presynaptic neurons are connected depends on the connection algorithm, as well as the original placement of the neurons in the presynaptic arrays.

During the synaptic connection procedure, for each neuron the numbers of presynaptic and postsynaptic neurons it connects to are totaled and saved in a table. Any neurons that don't connect to a postsynaptic cell are removed. The process is started by first checking the layer immediately presynaptic to the ganglion cell, i.e. the bipolar cells, and afterwards checking the more distal neurons, i.e. the photoreceptors.

To see all the neurons, even those that didn't get connected, you can set the parameter "remove_nconns" to 0, either on the command line or in the setparams() procedure.

Stimulus types

Stimuli can include voltage clamp, current clamp, and a variety of light stimuli such as spots, bars, sine wave gratings, etc. A special transduction element is available that voltage clamps the cell to which it is attached at a voltage specified by the stimulus intensity. When the stimulus procedure is called, the stimulus is added to a list that is run at the correct time during the simulation (i.e. during the "step()" procedure). To generate complex stimuli, for example a bar moving to/fro, a set of stimulus functions is available in "stimfuncs".

Record types

A variety of recording methods are available. An experiment can define a list of nodes to record from, either current or voltage. Light flux into a photoreceptor can be recorded, as well as the concentration of calcium or a neurotransmitter or second messenger. The recorded values can be stored into an array or file or plotted onto the video screen.

Several plotting functions are available to generate plots. Plots can include several traces, e.g. several recording points, and several of these plots can be displayed simultaneously on the screen. Each trace can have its own color and a label and units. Plotting functions are available for "voltage at a node", "synaptic release rate", or for displaying the voltage or some other parameter of a neuron as a color applied to the display of morphology.

Onplot procedure

An "onplot" procedure can be defined which runs automatically at plot time, i.e. when the plot traces are updated, controlled by the "ploti" variable. Although this procedure is not necessary (because the simulation can be run incrementally), it allows the simulation to run faster. For example, the onplot procedure allows a special procedure to compute some function of the neural circuit's responses. It also can be used to plot more complex functions, such as the color-coded voltage superimposed on the morphology. For the compiled version, the onplot procedure is defined by the "setonplot()" procedure.

Making movies

To make a movie, include "onplot_movie" in your experiment file, and call it at plot time, i.e. inside the "onplot()" procedure. At each plot step, it displays the voltage (or other parameter such as inactivation) of the membrane as a color code superimposed on the morphology.

You can look at the movie using the "vid" display, or you can generate separate frames using the "-P name" command line switch. This creates an individual PostScript file for each frame, which you can convert to another appropriate file format. Typically you will need to convert all the frames to a ppm format, then use "mpeg_encode" to create a movie.

You create the movie with a shell script like this:

#! /bin/tcsh -f
#
# make_movie script
#
ps2ppm100 $argv*.ps
movconvert -f "$argv"_ -n 2000
cp xxx_paramfile2 "$argv"_paramfile2
replace xxx "$argv" "$argv"_paramfile2
mpeg_encode "$argv"_paramfile2
rm "$argv"*.ppm

Since the vid display integrates the graphics input from the simulator, the frames it generates after the first do not contain static objects (calibration bars, etc) that should remain throughout the movie. The "movconvert" program accomplishes this integration in the movie for the frames in .ppm format. These are then read and converted to a standard movie format by "mpeg_encode". To view the movie in you can use "mplayer".

Compiling and linking the compiled version

The NeuronC API is defined in "nc/src/ncfuncs.h" and described in the NeuronC User's Manual. Each function call in "ncfuncs.h" replaces a statement in the interpreted version of NeuronC. The retsim script defines an array of neurons and connects them using these function calls. To see an example of source code for this compiled version, see the "retsim.cc" model in nc/models/retsim". The command-line switches for "retsim" are identical to those listed by "nc -h", but note that running "retsim" without arguments displays a list of simulation experiments and parameters. In addition simulation variables can be set from the command line.

The NeuronC API is incorporated into a static library called "libnc.a". This file is created in "nc/src" and must be linked with a neural circuit program such as "nc/models/retsim/retsim.cc". To link this library correctly you may need to set the "NC_HOME" variable in nc/models/retsim/makefile, either by setting it as an environment variable or by changing the makefile. The libnc.a library is created as a static library because as a dynamic library it reduces run-time speed.

The experiments defined for "nc/models/retsim" such as "expt_gc_cbp_flash.cc" are compiled to be dynamically linked to the "retsim" program at runtime, i.e. each experiment is compiled into a dynamic library, e.g. "expt_gc_cbp_flash.so". To allow this process of dynamic runtime linking, you must set the environment variable LD_LIBRARY_PATH or include the directory where the experiment ".so" file is located in (for Linux) "/etc/ld.so.conf". That will allow the runtime linker to find "expt_gc_cbp_flash.so"

(tcsh)  setenv LD_LIBRARY_PATH .
(bash)  export LD_LIBRARY_PATH="."

Another way to direct the dynamic linking process is to make a symbolic link from a file in /usr/local/lib to the experiment .so file in nc/models/retsim. The dynamic linker will identify the file because it starts with "lib_": ln -s /usr/local/lib/lib_expt_gc_cbp_flash.so expt_gc_cbp_flash.so

At the top of the "retsim.cc" script, there are several files included:

 #include "ncio.h"         // defines "ncfprintf()" for I/O to a C++ stream
 #include "ncfuncs.h"      // defines the C++ functions for the simulator
 #include "retcolors.h"    // defines the standard colors 0-15  
 #include "retsim.h"       // defines constants and functions for retsim.cc
 #include "retsim_var.cc"  // defines parameters and "setptrs()" which initializes them
 #include "ncinit.h"       // defines a null "setptrs()" in case it is not already defined
 #include "setexpt.h"      // defines "defparams()", "setparams()", "setdens()" and "runexpt()" for the experiment file
Most of these header files are in the retsim directory, but some are in the nc/src directory. If you are compiling retsim in a different location than nc/models/retsim, you need to set the NC_HOME environment variable in "retsim/makefile":
# NC_HOME = ~/nc

Compiling retsim on Mac OSX

The Mac OSX uses a slightly different way to link dynamic libraries. From the nc/models/retsim directory, you need to edit the "makefile" which is responsible for compiling and linking retsim. You only need to uncomment the line (i.e. remove the "#"):

# OSFLAGS = -DMACOSX
Then enter "make" on the command line. This will compile and link all the source code correctly on the Mac.

Parameter initialization

Note that a call to "setptr()" or "setptrn()" is necessary for each variable that you will set from the command line (or from the GUI window that runs the simulator). These function calls find and set the address of a parameter and store it in a symbol table for the simulator's run-time initialization. The "setptr()" function initializes the variable to its "undefined" value, so that later the "notinit()" function can tell whether the variable has been initialized -- this is useful to decide whether a default value should be applied. The "setptrn()" function is exactly the same as "setptr()" except that it does not initialize the parameter. This is useful when you want to initialize the variable to a certain value.

Defining an experiment

The retsim script is controlled by a set of variables that tell it which neurons to create and how to connect them. The variables are read from the default neuron parameter table, "nval.n", but are also set by an "experiment file", and from the command line.

Typically an experiment file defines the general form of the experiment. It directs retsim which cells to include in the model, what synaptic connections and biophysical properties they should have. Then the retsim script constructs the neural circuit model, and returns control back to the experiment file, which runs the experiment. The retsim script, either the interpreted ("retsim1.n") or compiled ("retsim.cc") version, is designed to be run with many different experiments. It is typically run with several script files which define the details of how to construct all the neurons and how to connect them. Many experiment files can be created to define different circuits or different experiment protocols.

Usually the experiment file allows parameters to change the details, i.e. the exact details of the neurons or their spacing, the size, frequency, or timing of a stimulus, or the exact form of the output plots. The idea is to minimize the number of different experiment files by selecting appropriate parameters to control their behavior.

An interpreted experiment file is written in the nc script language, and should contain the "setparams()" procedure, (and optionally the "setdens()" procedure), and "runexpt()" procedure, as explained below. The setparams() procedure sets the values of parameters, for example to control how the circuit is constructed. The "runexpt()" procedure sets up stimuli and plots, and runs the experiment using a "step" or "run" statement. A good way to start would be to take an existing experiment, e.g. "expt_gc_cbp_flash.n", and modify it to make a different circuit and/or experiment.

A compiled experiment file is written as a standard .cc file, then compiled and linked as a dynamically-linked library (in linux, ".so"). This allows the retsim script to select an experiment file at runtime instead of requiring that retsim be linked separately with each experiment file. A good way to accomplish this is to look in the "makefile" and modify an existing entry for compiling and linking an experment file.

The experiment file typically contains 3 procedures which are automatically run by the "retsim" script (see "setexpt.cc"):

defparams()   Defines the experiment and its parameters for command line.
	      This is called before the nval.n parameter file is read,
              so you can set a different nval file name here, or on
	      the command line. Also called before the "setvar()" 
              procedure sets variables from the command line. 
              
setparams()   Sets variables controlling construction of the circuit
              after the neuron parameter (nval) file has been read.
	      Called after defparams(), but before the density files
	      are read, and before construction of the neural circuit.

setdens()     Sets neuron parameters and variables modifying the 
	      channel densities after they have been read from the 
	      density files. Optional, called after densities have been
              read in, but before construction.

runexpt()     Runs the experiment. Fine tunes neurons, sets stimuli and plots.
              Called after circuit is constructed.
The "runexpt()" procedure can include a "for" statement to run an experiment iteratively. Typically, a stimulus is generated, and the "step()" procedure is called to run the simulation forward in time. Then the loop runs the stimulus again, possibly with a small variation, e.g. a different clamp voltage for a voltage clamp, and the step procedure is run again.
// The defparams procedure defines parameters needed by the experiment.
//  It is run before "setvar()" (which defines the parameters from the command line). 

void defparams(void)
{
  setptr("temp_freq", &temp_freq);
  setptr("ntrials",   &ntrials);
  setptr("dstim",     &dstim);
  setptr("sdia",      &sdia);
  setptr("stimtime",  &stimtime);
  setptr("minten",    &minten);
  setptr("scontrast", &scontrast);
}

// The setparams procedure sets parameters needed for construction of the circuit.

void setparams(void)
{
  make_rods = 0;
  make_cones= 1;        /* make cones, cbp, gc */
  make_ha   = 0;
  make_hb   = 0;
  make_cbp  = 1;
  make_gc   = 1;
  if (notinit(bg_inten)) bg_inten = 2.0e4;      /* background light intensity */
}

// The setdens procedure allows the user to modify channel densities read from the 
// density files. 

void setdens(void)
{
  if (!notinit(cone_cond)) setval(xcone,SCOND5,cone_cond);		// override synaptic val
  if (!notinit(ca_cond)) celdens[cone][_CA][R_AXON] bg_inten = ca_cond; // override Ca density, S/m2

}

// The runexpt() procedure sets up the experiment stimuli and plots, and
//  runs the experiment using "step()" or "run()".  

void runexpt(void)
{
   double temp_freq;

  if (notinit(stimtime))   stimtime = .10;       /* stimulus time */
  if (notinit(minten))       minten = bg_inten;  /* background intensity (for make cone)*/
  if (notinit(scontrast)) scontrast = .5;        /* intensity increment */
  if (notinit(temp_freq)) temp_freq = 2;

  dtrial = 1 / temp_freq;
  exptdur = dtrial * ntrials;

  plot_v_nod(ct=xcone,cn=midcone,n=soma,Vmin=-.037,Vmax =-.027,colr=cyan,"", -1, -1); /* plot Vcones*/
  stim_spot(sdia, 0, 0, minten*scontrast, start=t+stimtime,dur=dstim);
  step(dtrial);
}

Examples of how to run retsim

   nc     --expt gc_cbp_flash --ninfo 2 -d 1 -v retsim1.n | vid                       display the model
   retsim --expt gc_cbp_flash --ninfo 2 -d 1 -v           | vid 

   nc     --expt gc_cbp_flash --ninfo 2 -d 9 -v retsim1.n | vid                       display the nodes
   retsim --expt gc_cbp_flash --ninfo 2 --node_scale -3.05 -d 9 -v   | vid 

   retsim --expt gc_cbp_flash --ninfo 2 -d 9 -v   | vid -c > file.ps                  make .ps file.
   
   nc     --expt gc_cbp_flash -d 1 -R retsim1.n > file.pov                            display into povray format
   retsim --expt gc_cbp_flash -d 1 -R           > file.pov

   povray +h1000 +w1000 +ifile.pov +dx                                                generate image with povray

   nc     --expt gc_cbp_flash --mxrot 90 -d 1 -v retsim1.n | vid                      rotate, display the model
   retsim --expt gc_cbp_flash --mxrot 90 -d 1 -v           | vid 

   nc     --expt gc_cbp_flash --ninfo 2 --arrsiz 100 -d 1 -v retsim1.n | vid          limit model to 100 um
   retsim --expt gc_cbp_flash --ninfo 2 --arrsiz 100 -d 1 -v           | vid 

   nc     --expt gc_cbp_flash --ninfo 2 --n_cbp 1 --n_gc 0 -d 1 -v retsim1.n | vid    limit model to 1 bipolar
   retsim --expt gc_cbp_flash --ninfo 2 --n_cbp 1 --n_gc 0 -d 1 -v           | vid 

   nc     --expt gc_cbp_flash --ninfo 2 -v retsim1.n | vid                            run model, display plots
   retsim --expt gc_cbp_flash --ninfo 2 -v | vid 

   nc     --expt gc_cbp_flash retsim1.n > file.r                                      run model into data file
   retsim --expt gc_cbp_flash           > file.r 

   plotmod file.r | vid                                                                display plots from data file