Example #1
0
 def build_Mod(cls, leakChl, modFileSet):
     
     baseWriter = MM_ModFileWriterBase(suffix=leakChl.getNeuronSuffix())
     
     gbarName = "gLk" 
     eRevName = "eLk"
     gScaleName = "gScale"  
     
     gbarUnits = MM_WriterLeak.Units[gbarName]
     eRevUnits = MM_WriterLeak.Units[eRevName]
     
     # Parameters:
     # {name: (value, unit,range)}
     baseWriter.parameters = { 
       gbarName:   (leakChl.conductance.rescale( gbarUnits ).magnitude, (gbarUnits), None),
       eRevName:   (leakChl.reversalpotential.rescale(eRevUnits).magnitude, (eRevUnits), None),
       gScaleName: (1.0, None, None)
                   }
     
     baseWriter.currentequation = "(v-%s) * %s * %s" % (eRevName, gbarName, gScaleName)
     baseWriter.conductanceequation =  "%s * %s" % (gbarName, gScaleName)
      
     modtxt = baseWriter.GenerateModFile() 
     modFile = ModFile(name=leakChl.name, modtxt=modtxt)
     modFileSet.append(modFile)
 def build_Mod(cls, alphaBetaChl, modFileSet):
     
     gbarName = "gBar" 
     eRevName = "eRev"
     gScaleName = "gScale"  
     
     #gbarUnits = MM_WriterAlphaBeta.Units[gbarName]
     #eRevUnits = MM_WriterAlphaBeta.Units[eRevName]
     
     
     
     baseWriter = MM_ModFileWriterBase(suffix=alphaBetaChl.getNeuronSuffix())
     
     # Naming Conventions:
     stateTau = lambda s: "%stau" % s
     stateInf = lambda s: "%sinf" % s
     stateAlpha = lambda s: "%s_alpha" % s
     stateBeta = lambda s: "%s_beta" % s
     
     #gbarName = "g%sbar" % alphaBetaChl.ion
     #eRevName = "e%s" % alphaBetaChl.ion
     
     
     # State Equations and initial values:
     for s in alphaBetaChl.statevars:
         baseWriter.internalstates[s] = "%s" % stateInf(s) , "%s'=(%s-%s)/%s" % (s, stateInf(s), s, stateTau(s)) 
     
     # Parameters:
     # {name: (value, unit,range)}
     baseWriter.parameters = { 
                   gbarName: (alphaBetaChl.conductance.rescale("S/cm2").magnitude, ("S/cm2"), None),
                   eRevName: (alphaBetaChl.reversalpotential.rescale("mV").magnitude, ("mV"), None),
                   gScaleName: (1.0, None, None)
                   }
     
     # Rates:
     # name : (locals, code), unit
     for s in alphaBetaChl.statevars:
         baseWriter.rates[ stateAlpha(s) ] = (("", stateAlpha(s) + "= StdAlphaBeta( %f,%f,%f,%f,%f, v)" % tuple(alphaBetaChl.statevars[s][0]))), None
         baseWriter.rates[ stateBeta(s) ] = (("", stateBeta(s) + "= StdAlphaBeta( %f,%f,%f,%f,%f, v)" % tuple(alphaBetaChl.statevars[s][1]))), None
         baseWriter.rates[ stateInf(s) ] = (("", stateInf(s) + "= %s/(%s+%s)" % (stateAlpha(s), stateAlpha(s), stateBeta(s))), None)
         baseWriter.rates[ stateTau(s) ] = (("", stateTau(s) + "= 1.0/(%s+%s)" % (stateAlpha(s), stateBeta(s))), "ms")
         baseWriter.ratecalcorder.extend([stateAlpha(s), stateBeta(s), stateInf(s), stateTau(s)])
         
     baseWriter.currentequation = "(v-%s) * %s * %s * %s" % (eRevName, gbarName, alphaBetaChl.eqn, gScaleName)
     baseWriter.conductanceequation = " %s * %s * %s" % (gbarName, alphaBetaChl.eqn, gScaleName)
     baseWriter.functions = """FUNCTION StdAlphaBeta(A,B,C,D,E,V){ StdAlphaBeta = (A + B*V) / (C + exp((D+V)/E)) } """
      
     txt =  baseWriter.GenerateModFile()
     modFile =  ModFile(name=alphaBetaChl.name, modtxt=txt )
     modFileSet.append(modFile)
Example #3
0
    def build_mod(cls, leak_chl, modfile_set):

        base_writer = MM_ModFileWriterBase(suffix=leak_chl.get_neuron_suffix())

        gbar_name = 'gLk'
        e_rev_name = 'eLk'
        g_scale_name = 'gScale'

        gbar_units = NEURONChlWriterLeak.Units[gbar_name]
        e_rev_units = NEURONChlWriterLeak.Units[e_rev_name]

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
          gbar_name: (leak_chl.conductance.rescale(gbar_units).magnitude, (gbar_units), None),
          e_rev_name: (leak_chl.reversalpotential.rescale(e_rev_units).magnitude, (e_rev_units), None),
          g_scale_name: (1.0, None, None)
                      }

        base_writer.currentequation = '(v-%s) * %s * %s' % (e_rev_name, gbar_name, g_scale_name)
        base_writer.conductanceequation = '%s * %s' % (gbar_name, g_scale_name)

        modtxt = base_writer.generate_modfile()
        mod_file = ModFile(name=leak_chl.name, modtxt=modtxt)
        modfile_set.append(mod_file)
    def build_mod(cls, alphabeta_beta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'eLk'
        g_scale_name = 'gScale'

        base_writer = MM_ModFileWriterBase(suffix=alphabeta_beta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s
        state_alpha = lambda s: '%s_alpha' % s
        state_beta = lambda s: '%s_beta' % s

        # State Equations and initial values:
        for s in alphabeta_beta_chl.statevars:
            base_writer.internalstates[s] = "%s" % state_inf(s) , "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
                      #gbar_name: (alphabeta_beta_chl.conductance.toval(ounit="S/cm2"), ("S/cm2"), None),
                      #e_rev_name: (alphabeta_beta_chl.reversalpotential.toval("mV"), ("mV"), None)
                      gbar_name: (alphabeta_beta_chl.conductance.rescale("S/cm2").magnitude, ("S/cm2"), None),
                      e_rev_name: (alphabeta_beta_chl.reversalpotential.rescale("mV").magnitude, ("mV"), None),
                      g_scale_name: (1.0, None, None)
                      }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_beta_chl.statevars:
            base_writer.rates[state_alpha(s)] = (("", state_alpha(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" % tuple(alphabeta_beta_chl.statevars[s][0]))), None
            #base_writer.rates[state_beta(s)] = (("", state_beta(s) + "= StdBetaBeta(%f, %f, %f, %f, %f,  %f, %f, %f, %f, %f,  %f,  v)" % tuple(alphabeta_beta_chl.statevars[s][1] + alphabeta_beta_chl.statevars[s][2] + [alphabeta_beta_chl.beta2threshold.toval(ounit="mV")]))), None
            base_writer.rates[state_beta(s)] = (("", state_beta(s) + "= StdBetaBeta(%f, %f, %f, %f, %f,  %f, %f, %f, %f, %f,  %f,  v)" % tuple(alphabeta_beta_chl.statevars[s][1] + alphabeta_beta_chl.statevars[s][2] + [alphabeta_beta_chl.beta2threshold.rescale("mV").magnitude]))), None
            base_writer.rates[state_inf(s)] = (("", state_inf(s) + "= %s/(%s+%s)" % (state_alpha(s), state_alpha(s), state_beta(s))), None)
            base_writer.rates[state_tau(s)] = (("", state_tau(s) + "= 1.0/(%s+%s)" % (state_alpha(s), state_beta(s))), "ms")
            base_writer.ratecalcorder.extend([state_alpha(s), state_beta(s), state_inf(s), state_tau(s)])

        base_writer.currentequation = "(v-%s) * %s * %s * %s" % (e_rev_name, gbar_name, alphabeta_beta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = "%s * %s * %s" % (gbar_name, alphabeta_beta_chl.eqn, g_scale_name)

        #base_writer.currentequation = "(v-%s) * %s * %s" % (e_rev_name, gbar_name, alphabeta_beta_chl.eqn)
        base_writer.functions = """
                    FUNCTION StdAlphaBeta(A, B, C, D, E, V){ StdAlphaBeta = (A + B*V) / (C + exp((D+V)/E)) }
                    FUNCTION StdBetaBeta(A, B, C, D, E, A2, B2, C2, D2, E2, beta2Threshold, V)
                    {
                        if(V < beta2Threshold)
                        {
                            StdBetaBeta = (A + B*V) / (C + exp((D+V)/E))
                        }
                        else
                        {
                           StdBetaBeta = (A2 + B2*V) / (C2 + exp((D2+V)/E2))
                        }
                    }
                    """
        txt = base_writer.generate_modfile()
        mod_file = ModFile(name=alphabeta_beta_chl.name, modtxt=txt)
        modfile_set.append(mod_file)
Example #5
0
    def build_mod(cls, alphabeta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'e_rev'
        g_scale_name = 'gScale'

        # gbarUnits = NEURONChlWriterAlphaBeta.Units[gbar_name]
        # eRevUnits = NEURONChlWriterAlphaBeta.Units[e_rev_name]

        base_writer = MM_ModFileWriterBase(
            suffix=alphabeta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s
        state_alpha = lambda s: '%s_alpha' % s
        state_beta = lambda s: '%s_beta' % s

        # State Equations and initial values:
        for s in alphabeta_chl.statevars:
            base_writer.internalstates[s] = "%s" % state_inf(
                s), "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
            gbar_name: (alphabeta_chl.conductance.rescale("S/cm2").magnitude,
                        ("S/cm2"), None),
            e_rev_name:
            (alphabeta_chl.reversalpotential.rescale("mV").magnitude, ("mV"),
             None),
            g_scale_name: (1.0, None, None)
        }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_chl.statevars:
            base_writer.rates[state_alpha(s)] = (
                ("", state_alpha(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" %
                 tuple(alphabeta_chl.statevars[s][0]))), None
            base_writer.rates[state_beta(s)] = (
                ("", state_beta(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" %
                 tuple(alphabeta_chl.statevars[s][1]))), None
            base_writer.rates[state_inf(s)] = (
                ("", state_inf(s) + "= %s/(%s+%s)" %
                 (state_alpha(s), state_alpha(s), state_beta(s))), None)
            base_writer.rates[state_tau(s)] = (
                ("", state_tau(s) + "= 1.0/(%s+%s)" %
                 (state_alpha(s), state_beta(s))), "ms")
            base_writer.ratecalcorder.extend(
                [state_alpha(s),
                 state_beta(s),
                 state_inf(s),
                 state_tau(s)])

        base_writer.currentequation = "(v-%s) * %s * %s * %s" % (
            e_rev_name, gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = "%s * %s * %s" % (
            gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.functions = """FUNCTION StdAlphaBeta(A, B, C, D, E, V){ StdAlphaBeta = (A + B*V) / (C + exp((D+V)/E)) } """

        txt = base_writer.generate_modfile()
        mod_file = ModFile(name=alphabeta_chl.name, modtxt=txt)
        modfile_set.append(mod_file)
    def build_mod(cls, alphabeta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'e_rev'
        g_scale_name = 'gScale'

        base_writer = \
            MM_ModFileWriterBase(suffix=alphabeta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s

        # State Equations and initial values:
        for s in alphabeta_chl.statevars_new:
            base_writer.internalstates[s] = '%s' % state_inf(s), "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
                      gbar_name: (alphabeta_chl.conductance.rescale("S/cm2").magnitude, ("S/cm2"), None),
                      e_rev_name: (alphabeta_chl.reversalpotential.rescale("mV").magnitude, ("mV"), None),
                      g_scale_name: (1.0, None, None)
                      }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_chl.statevars_new:
            base_writer.rates[state_inf(s)] = (('', state_inf(s) + "= %sInf(v)" % state_inf(s)), None)
            base_writer.rates[state_tau(s)] = (('', state_tau(s) + "= %sTau(v)" % state_tau(s)), "ms")
            base_writer.ratecalcorder.extend([state_inf(s), state_tau(s)])

        base_writer.currentequation = '(v-%s) * %s * %s * %s' % (e_rev_name, gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = '%s * %s * %s' % (gbar_name, alphabeta_chl.eqn, g_scale_name)

        base_writer.functions = """
        VERBATIM
        #include <gsl_wrapper.h>
        ENDVERBATIM"""

        def buildInterpolatorFunc(state, inftau, funcname):
            if inftau == 'inf':
                interp_str_x = ','.join(['%2.2f' % x for x in alphabeta_chl.statevars_new[s].V])
                interp_str_y = ','.join(['%2.2f' % x for x in alphabeta_chl.statevars_new[s].inf])
            elif inftau == 'tau':
                interp_str_x = ','.join(['%2.2f' % x for x in alphabeta_chl.statevars_new[s].V])
                interp_str_y = ','.join(['%2.2f' % x for x in alphabeta_chl.statevars_new[s].tau])
            else:
                assert False


            variables = {'chlname':state_tau(s), 'nPts':len(alphabeta_chl.statevars_new[s].V), 'x0':interp_str_x, 'y0':interp_str_y, 'funcname':funcname }
            f = """
            FUNCTION %(funcname)s(V)
            {
                VERBATIM {
                    static void* pInterpolator = NULL;
                    if(!pInterpolator)
                    {
                        double x[%(nPts)s] = { %(x0)s };
                        double y[%(nPts)s] = { %(y0)s };
                        int nPts = %(nPts)d;
                        pInterpolator = makeIntWrapper(x, y, nPts);
                    }
                    _l%(funcname)s= interpolate2(_lV, pInterpolator);
                }
                ENDVERBATIM
            }
            \n\n""" % variables
            return f

        for s in alphabeta_chl.statevars_new:
            base_writer.functions +=  buildInterpolatorFunc(state=s, inftau='inf', funcname='%sinfInf' % s)
            base_writer.functions +=  buildInterpolatorFunc(state=s, inftau='tau', funcname='%stauTau' % s)



        txt =  base_writer.generate_modfile()

        # TODO: Remove hard dependancy here
        from morphforge.stdimports import RCMgr
        additional_compile_flags = RCMgr.get('Neuron','additional_compile_flags')  #"-I/home/michael/hw_to_come/morphforge/src/morphforgecontrib/simulation/neuron_gsl/cpp"
        additional_link_flags = RCMgr.get('Neuron','additional_link_flags') # "-L/home/michael/hw_to_come/morphforge/src/morphforgecontrib/simulation/neuron_gsl/cpp -lgslwrapper -lgsl -lgslcblas"
        mod_file =  ModFile(name=alphabeta_chl.name, modtxt=txt, additional_compile_flags=additional_compile_flags, additional_link_flags=additional_link_flags)
        modfile_set.append(mod_file)
    def build_mod(cls, alphabeta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'e_rev'
        g_scale_name = 'gScale'

        base_writer = \
            MM_ModFileWriterBase(suffix=alphabeta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s

        # State Equations and initial values:
        for s in alphabeta_chl.statevars_new:
            base_writer.internalstates[s] = '%s' % state_inf(
                s), "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
            gbar_name: (alphabeta_chl.conductance.rescale("S/cm2").magnitude,
                        ("S/cm2"), None),
            e_rev_name:
            (alphabeta_chl.reversalpotential.rescale("mV").magnitude, ("mV"),
             None),
            g_scale_name: (1.0, None, None)
        }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_chl.statevars_new:
            base_writer.rates[state_inf(s)] = (('', state_inf(s) +
                                                "= %sInf(v)" % state_inf(s)),
                                               None)
            base_writer.rates[state_tau(s)] = (('', state_tau(s) +
                                                "= %sTau(v)" % state_tau(s)),
                                               "ms")
            base_writer.ratecalcorder.extend([state_inf(s), state_tau(s)])

        base_writer.currentequation = '(v-%s) * %s * %s * %s' % (
            e_rev_name, gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = '%s * %s * %s' % (
            gbar_name, alphabeta_chl.eqn, g_scale_name)

        base_writer.functions = """
        VERBATIM
        #include <gsl_wrapper.h>
        ENDVERBATIM"""

        def buildInterpolatorFunc(state, inftau, funcname):
            if inftau == 'inf':
                interp_str_x = ','.join(
                    ['%2.2f' % x for x in alphabeta_chl.statevars_new[s].V])
                interp_str_y = ','.join(
                    ['%2.2f' % x for x in alphabeta_chl.statevars_new[s].inf])
            elif inftau == 'tau':
                interp_str_x = ','.join(
                    ['%2.2f' % x for x in alphabeta_chl.statevars_new[s].V])
                interp_str_y = ','.join(
                    ['%2.2f' % x for x in alphabeta_chl.statevars_new[s].tau])
            else:
                assert False

            variables = {
                'chlname': state_tau(s),
                'nPts': len(alphabeta_chl.statevars_new[s].V),
                'x0': interp_str_x,
                'y0': interp_str_y,
                'funcname': funcname
            }
            f = """
            FUNCTION %(funcname)s(V)
            {
                VERBATIM {
                    static void* pInterpolator = NULL;
                    if(!pInterpolator)
                    {
                        double x[%(nPts)s] = { %(x0)s };
                        double y[%(nPts)s] = { %(y0)s };
                        int nPts = %(nPts)d;
                        pInterpolator = makeIntWrapper(x, y, nPts);
                    }
                    _l%(funcname)s= interpolate2(_lV, pInterpolator);
                }
                ENDVERBATIM
            }
            \n\n""" % variables
            return f

        for s in alphabeta_chl.statevars_new:
            base_writer.functions += buildInterpolatorFunc(
                state=s, inftau='inf', funcname='%sinfInf' % s)
            base_writer.functions += buildInterpolatorFunc(
                state=s, inftau='tau', funcname='%stauTau' % s)

        txt = base_writer.generate_modfile()

        # TODO: Remove hard dependancy here
        additional_compile_flags = "-I/home/michael/hw_to_come/morphforge/src/morphforgecontrib/simulation/neuron_gsl/cpp"
        additional_link_flags = "-L/home/michael/hw_to_come/morphforge/src/morphforgecontrib/simulation/neuron_gsl/cpp -lgslwrapper -lgsl -lgslcblas"
        mod_file = ModFile(name=alphabeta_chl.name,
                           modtxt=txt,
                           additional_compile_flags=additional_compile_flags,
                           additional_link_flags=additional_link_flags)
        modfile_set.append(mod_file)
    def build_mod(cls, alphabeta_beta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'eLk'
        g_scale_name = 'gScale'

        base_writer = MM_ModFileWriterBase(suffix=alphabeta_beta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s
        state_alpha = lambda s: '%s_alpha' % s
        state_beta = lambda s: '%s_beta' % s

        # State Equations and initial values:
        for s in alphabeta_beta_chl.statevars:
            base_writer.internalstates[s] = "%s" % state_inf(s) , "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
                      #gbar_name: (alphabeta_beta_chl.conductance.toval(ounit="S/cm2"), ("S/cm2"), None),
                      #e_rev_name: (alphabeta_beta_chl.reversalpotential.toval("mV"), ("mV"), None)
                      gbar_name: (alphabeta_beta_chl.conductance.rescale("S/cm2").magnitude, ("S/cm2"), None),
                      e_rev_name: (alphabeta_beta_chl.reversalpotential.rescale("mV").magnitude, ("mV"), None),
                      g_scale_name: (1.0, None, None)
                      }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_beta_chl.statevars:
            base_writer.rates[state_alpha(s)] = (("", state_alpha(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" % tuple(alphabeta_beta_chl.statevars[s][0]))), None
            #base_writer.rates[state_beta(s)] = (("", state_beta(s) + "= StdBetaBeta(%f, %f, %f, %f, %f,  %f, %f, %f, %f, %f,  %f,  v)" % tuple(alphabeta_beta_chl.statevars[s][1] + alphabeta_beta_chl.statevars[s][2] + [alphabeta_beta_chl.beta2threshold.toval(ounit="mV")]))), None
            base_writer.rates[state_beta(s)] = (("", state_beta(s) + "= StdBetaBeta(%f, %f, %f, %f, %f,  %f, %f, %f, %f, %f,  %f,  v)" % tuple(alphabeta_beta_chl.statevars[s][1] + alphabeta_beta_chl.statevars[s][2] + [alphabeta_beta_chl.beta2threshold.rescale("mV").magnitude]))), None
            base_writer.rates[state_inf(s)] = (("", state_inf(s) + "= %s/(%s+%s)" % (state_alpha(s), state_alpha(s), state_beta(s))), None)
            base_writer.rates[state_tau(s)] = (("", state_tau(s) + "= 1.0/(%s+%s)" % (state_alpha(s), state_beta(s))), "ms")
            base_writer.ratecalcorder.extend([state_alpha(s), state_beta(s), state_inf(s), state_tau(s)])

        base_writer.currentequation = "(v-%s) * %s * %s * %s" % (e_rev_name, gbar_name, alphabeta_beta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = "%s * %s * %s" % (gbar_name, alphabeta_beta_chl.eqn, g_scale_name)

        #base_writer.currentequation = "(v-%s) * %s * %s" % (e_rev_name, gbar_name, alphabeta_beta_chl.eqn)
        base_writer.functions = """
                    FUNCTION StdAlphaBeta(A, B, C, D, E, V){ StdAlphaBeta = (A + B*V) / (C + exp((D+V)/E)) }
                    FUNCTION StdBetaBeta(A, B, C, D, E, A2, B2, C2, D2, E2, beta2Threshold, V)
                    {
                        if(V < beta2Threshold)
                        {
                            StdBetaBeta = (A + B*V) / (C + exp((D+V)/E))
                        }
                        else
                        {
                           StdBetaBeta = (A2 + B2*V) / (C2 + exp((D2+V)/E2))
                        }
                    }
                    """
        txt = base_writer.generate_modfile()
        mod_file = ModFile(name=alphabeta_beta_chl.name, modtxt=txt)
        modfile_set.append(mod_file)
    def build_mod(cls, alphabeta_chl, modfile_set):

        gbar_name = 'gBar'
        e_rev_name = 'e_rev'
        g_scale_name = 'gScale'

        # gbarUnits = NEURONChlWriterAlphaBeta.Units[gbar_name]
        # eRevUnits = NEURONChlWriterAlphaBeta.Units[e_rev_name]

        base_writer = MM_ModFileWriterBase(suffix=alphabeta_chl.get_neuron_suffix())

        # Naming Conventions:
        state_tau = lambda s: '%stau' % s
        state_inf = lambda s: '%sinf' % s
        state_alpha = lambda s: '%s_alpha' % s
        state_beta = lambda s: '%s_beta' % s

        # State Equations and initial values:
        for s in alphabeta_chl.statevars:
            base_writer.internalstates[s] = "%s" % state_inf(s) , "%s'=(%s-%s)/%s" % (s, state_inf(s), s, state_tau(s))

        # Parameters:
        # {name: (value, unit, range)}
        base_writer.parameters = {
                      gbar_name: (alphabeta_chl.conductance.rescale("S/cm2").magnitude, ("S/cm2"), None),
                      e_rev_name: (alphabeta_chl.reversalpotential.rescale("mV").magnitude, ("mV"), None),
                      g_scale_name: (1.0, None, None)
                      }

        # Rates:
        # name : (locals, code), unit
        for s in alphabeta_chl.statevars:
            base_writer.rates[state_alpha(s)] = (("", state_alpha(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" % tuple(alphabeta_chl.statevars[s][0]))), None
            base_writer.rates[state_beta(s)] = (("", state_beta(s) + "= StdAlphaBeta(%f, %f, %f, %f, %f, v)" % tuple(alphabeta_chl.statevars[s][1]))), None
            base_writer.rates[state_inf(s)] = (("", state_inf(s) + "= %s/(%s+%s)" % (state_alpha(s), state_alpha(s), state_beta(s))), None)
            base_writer.rates[state_tau(s)] = (("", state_tau(s) + "= 1.0/(%s+%s)" % (state_alpha(s), state_beta(s))), "ms")
            base_writer.ratecalcorder.extend([state_alpha(s), state_beta(s), state_inf(s), state_tau(s)])

        base_writer.currentequation = "(v-%s) * %s * %s * %s" % (e_rev_name, gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.conductanceequation = "%s * %s * %s" % (gbar_name, alphabeta_chl.eqn, g_scale_name)
        base_writer.functions = """FUNCTION StdAlphaBeta(A, B, C, D, E, V){ StdAlphaBeta = (A + B*V) / (C + exp((D+V)/E)) } """

        txt = base_writer.generate_modfile()
        mod_file = ModFile(name=alphabeta_chl.name, modtxt=txt, strict_modlunit=True)
        modfile_set.append(mod_file)