Changeset 31374 in project


Ignore:
Timestamp:
09/11/14 12:35:00 (5 years ago)
Author:
Ivan Raikov
Message:

nemo: refactoring nmodl backend for use with templates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/nemo/trunk/nemo-nmodl.scm

    r31356 r31374  
    518518{% endif %}
    519519
    520 ;;
    521 ;; NMODL has a line character limit, so we limit the number of entries
    522 ;; in each RANGE stmt to 10
    523 ;;
    524 {% for exportGroup in groupBy(exports, 10) %}
     520{# NMODL has a line character limit, so we limit the number of entries in each RANGE stmt to 10 #}
     521
     522COMMENT
     523 exports
     524ENDCOMMENT
     525
     526{% for exportGroup in groupBy(10, exports) %}
    525527RANGE {{join(",", exportGroup)}}
    526528{% endfor %}
     
    530532{% endif %}
    531533
     534{#
     535   if rev potential is defined for this ion, declare the ionic current
     536   and reversal potential as range variables, otherwise declare only
     537   the ionic current as a range variable
     538#}
     539
    532540{% for p in permeatingIons %}
    533541{% if (p.species == "non-specific") %}
    534542RANGE {{p.e}}
    535 {% else %}
    536 ;; if rev potential is defined for this ion, declare the ionic current
    537 ;; and reversal potential as range variables, otherwise declare only
    538 ;; the ionic current as a range variable
    539 {% if p.erev  %}
     543{% elseif (p.erev) %}
    540544RANGE {{p.i}}, {{p.e}}
    541545{% else %}
    542546RANGE {{p.i}}
    543547{% endif %}
    544 {% endif %}
     548{% endfor %}
     549
     550{% for p in poolIons %}
     551RANGE {{p.in}}, {{p.out}}
    545552{% endfor %}
    546553
     
    551558{% for m in modulatingIons %}
    552559RANGE {{m.in}}, {{m.out}}
    553 {% endif %}
     560{% endfor %}
    554561{% else %}
    555562{% for a in accumulatingIons %}
     
    558565{% endif %}
    559566
    560 {% for parameterGroup in groupBy(rangeParameters, 10) %}
    561 RANGE {{join(",", rangeParameters)}}
     567COMMENT
     568range parameters
     569ENDCOMMENT
     570
     571{% for parameterGroup in groupBy(10, rangeParameters) %}
     572RANGE {{join(",", parameterGroup)}}
    562573{% endfor %}
    563574
    564 {% for useion in useIons %}
     575COMMENT
     576use ions
     577ENDCOMMENT
     578
     579{% for useIon in useIons %}
    565580{% if (useIon.nonSpecific) %}
    566 NONSPECIFIC_CURRENT {{useion.name}}
    567 {% else %}
    568 {% if (useIon.valence) %}
    569 {% if (useIon.write == []) %}
    570 USEION {{useion.name}} READ {{join (", ", useion.read)}} VALENCE {{useion.valence}}
    571 {% else %}
    572 USEION {{useion.name}} READ {{join (", ", useion.read)}} WRITE {{join (", ", useion.write)}} VALENCE {{useion.valence}}
    573 {% endif %}
    574 {% else %}
    575 {% if (useIon.write == []) %}
    576 USEION {{useion.name}} READ {{join (", ", useion.read)}}
    577 {% else %}
    578 USEION {{useion.name}} READ {{join (", ", useion.read)}} WRITE {{join (", ", useion.write)}}
    579 {% endif %}
    580 {% endif %}
     581NONSPECIFIC_CURRENT {{useIon.name}}
     582{% elseif (useIon.valence && (!(useIon.write == [])) && (!(useIon.read == [])) ) %}
     583USEION {{useIon.name}} READ {{join (", ", useIon.read)}} WRITE {{join (", ", useIon.write)}} VALENCE {{useIon.valence}}
     584{% elseif (useIon.valence && (useIon.write == []) && (!(useIon.read == [])) ) %}
     585USEION {{useIon.name}} READ {{join (", ", useIon.read)}} VALENCE {{useIon.valence}}
     586{% elseif ((!(useIon.write == [])) && (!(useIon.read == [])) ) %}
     587USEION {{useIon.name}} READ {{join (", ", useIon.read)}} WRITE {{join (", ", useIon.write)}}
     588{% elseif ((useIon.write == []) && (!(useIon.read == [])) ) %}
     589USEION {{useIon.name}} READ {{join (", ", useIon.read)}}
    581590{% endif %}
    582591{% endfor %}
    583 
    584 
    585592}
     593
    586594EOF
    587595))
     
    594602#<<EOF
    595603PARAMETER {
    596 {% if (!(currents == [])) %}
    597   LOCAL {{join(",", parameterLocals)}}
     604{% if (!(parameterLocals == [])) %}
     605  LOCAL {{join(",1", parameterLocals)}}
    598606{% endif %}
    599607
     
    613621#<<EOF
    614622STATE {
    615 
    616623{% for stateDef in stateDefs %}
    617624{{stateDef}}
    618625{% endfor %}
    619 
    620626}
    621627
    622628EOF
    623629))
    624 
    625630
    626631(define assigned-template
     
    629634#<<EOF
    630635ASSIGNED {
    631 
    632 {% for assignmentDef in assignmentDefs %}
    633 {{assignmentDef}}
     636{% for assignedDef in assignedDefs %}
     637{{assignedDef}}
    634638{% endfor %}
    635 
    636639}
    637640
    638641EOF
    639642))
    640 
    641643
    642644
     
    645647   (ersatz:template-std-env autoescape: #f)
    646648#<<EOF
    647 {% if (!(assignmentEqDefs == [])) %}
     649{% if (!(assignedEqDefs == [])) %}
    648650PROCEDURE asgns () {
    649 {% if (!(assignmentLocals == [])) %}
    650 LOCAL {{join(",", assignmentLocals)}}
     651{% if (!(assignedEqLocals == [])) %}
     652LOCAL {{join(",", assignedEqLocals)}}
    651653{% endif %}
    652 {% for assignmentEqDef in assignmentEqDefs %}
    653 {{assignmentDef}}
     654{% for assignedEqDef in assignedEqDefs %}
     655{{assignmentEqDef}}
    654656{% endfor %}
    655657}
     
    658660EOF
    659661))
    660 
    661662
    662663
     
    668669PROCEDURE reactions () {
    669670{% if (!(reactionLocals == [])) %}
    670 LOCAL {{join(",", reactionLocals)}}
     671LOCAL {{join(",3", reactionLocals)}}
    671672{% endif %}
    672673{% for reactionEqDef in reactionEqDefs %}
     
    692693}
    693694
     695{% endif %}
    694696EOF
    695697))
    696 
    697 
    698        
    699 (define pools-template
    700   (ersatz:statements-from-string
    701    (ersatz:template-std-env autoescape: #f)
    702 #<<EOF
    703 BREAKPOINT {
    704        
    705         (if (not (null? i-locals)) (pp indent+ (LOCAL ,(slp ", " i-locals))))
    706 
    707         (if has-ode?
    708             (case method
    709               ((#f expeuler)  (pp indent+ (SOLVE states)))
    710               (else           (pp indent+ (SOLVE states METHOD ,method)))))
    711 
    712         (if has-kinetic?   (pp indent+  (SOLVE kstates METHOD sparse)))
    713         (if (not (null? reactions))   (pp indent+ (reactions ())))
    714         (if (not (null? pool-ions)) (pp indent+ (pools ())))
    715         (for-each (lambda (p) (pp indent+ ,(expr->string/NMODL (second p) (first p)))) i-eqs)
    716 
    717         (pp indent "}")
    718698
    719699
     
    11361116               )
    11371117             
    1138 
    1139                (tmpl-vars
     1118        (let* (
     1119               (tenv-enter
     1120                (lambda (x env)
     1121                  (let ((k (car x)) (v (cdr x)))
     1122                    (print "k = " k " v = " v)
     1123                    (cons (cons k (if (null? v) (ersatz:Tlist '()) (ersatz:sexpr->tvalue v))) env))))
     1124
     1125               (tmpl-env
     1126                (fold tenv-enter '()
    11401127                `(
    11411128                  (modelName         . ,sysname)
     
    11831170                                          (lambda (x)
    11841171                                            (let ((u (cdr x)))
     1172                                              (print "u = " u)
    11851173                                              (cases useion u
    11861174                                                     (UseIon (name read write valence)
     
    12171205                                                  (append asgn-eq-defs rate-eq-defs reaction-eq-defs defuns )))))
    12181206                 
    1219                   (parametersLocals . ,parameter-locals)
     1207                  (parameterLocals . ,parameter-locals)
    12201208
    12211209                  (parameterDefs . ,(map (lambda (def)
     
    12241212                                         parameter-defs))
    12251213
    1226                   (stateDefs . ,state-defs)
     1214                  (stateDefs . ,state-defs )
    12271215
    12281216                  (assignedDefs . ,assigned-defs)
     1217
     1218                  (assignedEqLocals . ,asgn-locals)
    12291219
    12301220                  (assignedEqDefs . ,(map (lambda (def)
     
    12331223                                          asgn-eq-defs))
    12341224
    1235                   (reactionsEqDefs . ,(map (lambda (def)
    1236                                              (let ((n (nmodl-name (first def))) (b (second def)))
    1237                                                (expr->string/NMODL b n)))
    1238                                            reaction-eq-defs))
    1239 
    1240 
     1225                  (reactionEqLocals . ,reaction-locals)
     1226
     1227                  (reactionEqDefs . ,(map (lambda (def)
     1228                                            (let ((n (nmodl-name (first def))) (b (second def)))
     1229                                              (expr->string/NMODL b n)))
     1230                                          reaction-eq-defs))
    12411231                  ))
    1242 
     1232                )
    12431233
    12441234               )
    12451235
     1236
    12461237        (pp indent
    1247             ,(instantiate-template prelude-template tmpl-vars)
    1248             ,(instantiate-template neuron-template tmpl-vars)
    1249             ,(instantiate-template parameter-template tmpl-vars)
    1250             ,(instantiate-template state-template tmpl-vars)
    1251             ,(instantiate-template assigned-template tmpl-vars)
     1238            ,(instantiate-template prelude-template tmpl-env)
     1239            ,(instantiate-template neuron-template tmpl-env)
     1240            ,(instantiate-template parameter-template tmpl-env)
     1241            ,(instantiate-template state-template tmpl-env)
     1242            ,(instantiate-template assigned-template tmpl-env)
    12521243            )
    12531244       
     
    12601251
    12611252        (pp indent
    1262             ,(instantiate-template asgns-template tmpl-vars)
    1263             ,(instantiate-template reactions-template tmpl-vars)
    1264             ,(instantiate-template pools-template tmpl-vars)
     1253            ,(instantiate-template asgns-template tmpl-env)
     1254            ,(instantiate-template reactions-template tmpl-env)
     1255            ,(instantiate-template pools-template tmpl-env)
    12651256            )
    12661257       
     
    14641455      ))
    14651456  ))
    1466 
    1467 
    1468 )
     1457))
     1458
     1459
Note: See TracChangeset for help on using the changeset viewer.