|
| 1 | +# Generates time-series response to a Ca pulse for each of the models. No |
| 2 | +# diffusion involved. |
| 3 | + |
| 4 | +import sys |
| 5 | +import numpy as np |
| 6 | +import pylab |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +import moose |
| 9 | +import abstrModelEqns2 |
| 10 | +import rdesigneur as rd |
| 11 | +import time |
| 12 | + |
| 13 | + |
| 14 | +def singleCompt( name, params ): |
| 15 | + mod = moose.copy( '/library/' + name + '/' + name, '/model' ) |
| 16 | + A = moose.element( mod.path + '/A' ) |
| 17 | + Z = moose.element( mod.path + '/Z' ) |
| 18 | + Z.nInit = 1 |
| 19 | + Ca = moose.element( mod.path + '/Ca' ) |
| 20 | + CaStim = moose.element( Ca.path + '/CaStim' ) |
| 21 | + runtime = params['preStimTime'] + params['stimWidth'] + params['postStimTime'] |
| 22 | + steptime = 100 |
| 23 | + |
| 24 | + CaStim.expr += ' + x2 * (t > ' + str( runtime ) + ' ) * ( t < ' + str( runtime + steptime ) + ' )' |
| 25 | + print CaStim.expr |
| 26 | + tab = moose.Table2( '/model/' + name + '/Atab' ) |
| 27 | + #for i in range( 10, 19 ): |
| 28 | + #moose.setClock( i, 0.01 ) |
| 29 | + ampl = moose.element( mod.path + '/ampl' ) |
| 30 | + phase = moose.element( mod.path + '/phase' ) |
| 31 | + moose.connect( tab, 'requestOut', A, 'getN' ) |
| 32 | + ampl.nInit = params['stimAmplitude'] * 1 |
| 33 | + phase.nInit = params['preStimTime'] |
| 34 | + |
| 35 | + ksolve = moose.Ksolve( mod.path + '/ksolve' ) |
| 36 | + stoich = moose.Stoich( mod.path + '/stoich' ) |
| 37 | + stoich.compartment = mod |
| 38 | + stoich.ksolve = ksolve |
| 39 | + stoich.path = mod.path + '/##' |
| 40 | + runtime += 2 * steptime |
| 41 | + |
| 42 | + moose.reinit() |
| 43 | + moose.start( runtime ) |
| 44 | + t = np.arange( 0, runtime + 1e-9, tab.dt ) |
| 45 | + return name, t, tab.vector |
| 46 | + #pylab.plot( t, tab.vector, label='[A] (mM)' ) |
| 47 | + |
| 48 | + #pylab.show() |
| 49 | + |
| 50 | +def plotBoilerplate( panelTitle, plotPos, xlabel = ''): |
| 51 | + ax = plt.subplot( 8,4,plotPos ) |
| 52 | + #ax.xaxis.set_ticks( i[1] ) |
| 53 | + #ax.locator_params( |
| 54 | + ax.spines['top'].set_visible( False ) |
| 55 | + ax.spines['right'].set_visible( False ) |
| 56 | + ax.tick_params( direction = 'out' ) |
| 57 | + if (((plotPos -1)/4) % 2) == 0: |
| 58 | + ax.set_xticklabels([]) |
| 59 | + else: |
| 60 | + ax.set_xlabel( xlabel ) |
| 61 | + for tick in ax.xaxis.get_major_ticks(): |
| 62 | + tick.tick2On = False |
| 63 | + for tick in ax.yaxis.get_major_ticks(): |
| 64 | + tick.tick2On = False |
| 65 | + |
| 66 | + if (plotPos % 4) == 1: |
| 67 | + plt.ylabel( 'conc', fontsize = 16 ) |
| 68 | + # alternate way of doing this separately. |
| 69 | + #plt.yaxis.label.size_size(16) |
| 70 | + #plt.title( 'B' ) |
| 71 | + ax.text( -0.3, 1, panelTitle, fontsize = 18, weight = 'bold', |
| 72 | + transform=ax.transAxes ) |
| 73 | + return ax |
| 74 | + |
| 75 | +def plotPanelB(): |
| 76 | + panelB = [] |
| 77 | + panelBticks = [] |
| 78 | + panelB.append( singleCompt( 'fhn', abstrModelEqns2.makeFHN() ) ) |
| 79 | + panelB.append( singleCompt( 'bis', abstrModelEqns2.makeBis() ) ) |
| 80 | + panelB.append( singleCompt( 'negFB', abstrModelEqns2.makeNegFB() ) ) |
| 81 | + panelB.append( singleCompt( 'negFF', abstrModelEqns2.makeNegFF() ) ) |
| 82 | + |
| 83 | + panelBticks.append( np.arange( 0, 4.00001, 1 ) ) |
| 84 | + panelBticks.append( np.arange( 0, 4.00001, 1 ) ) |
| 85 | + panelBticks.append( np.arange( 0, 15.00001, 5 ) ) |
| 86 | + panelBticks.append( np.arange( 0, 6.00001, 2 ) ) |
| 87 | + moose.delete( '/model' ) |
| 88 | + |
| 89 | + for i in zip( panelB, panelBticks, range( len( panelB ) ) ): |
| 90 | + plotPos = i[2] + 5 |
| 91 | + ax = plotBoilerplate( 'B', plotPos ) |
| 92 | + plt.plot( i[0][1], i[0][2] ) |
| 93 | + xmax = ax.get_xlim()[1] |
| 94 | + #ax.xaxis.set_ticks( np.arange( 0, xmax, 50 ) ) |
| 95 | + ax.xaxis.set_ticks( np.arange( 0, 200.001, 50 ) ) |
| 96 | + ax.yaxis.set_ticks( i[1] ) |
| 97 | + |
| 98 | +def runPanelCDEF( name, dist, seqDt, numSpine, seq, stimAmpl ): |
| 99 | + preStim = 10.0 |
| 100 | + blanks = 20 |
| 101 | + rdes = rd.rdesigneur( |
| 102 | + useGssa = False, |
| 103 | + turnOffElec = True, |
| 104 | + chemPlotDt = 0.1, |
| 105 | + #diffusionLength = params['diffusionLength'], |
| 106 | + diffusionLength = 1e-6, |
| 107 | + cellProto = [['cell', 'soma']], |
| 108 | + chemProto = [['dend', name]], |
| 109 | + chemDistrib = [['dend', 'soma', 'install', '1' ]], |
| 110 | + plotList = [['soma', '1', 'dend' + '/A', 'n', '# of A']], |
| 111 | + ) |
| 112 | + rdes.buildModel() |
| 113 | + #for i in range( 20 ): |
| 114 | + #moose.setClock( i, 0.02 ) |
| 115 | + A = moose.vec( '/model/chem/dend/A' ) |
| 116 | + Z = moose.vec( '/model/chem/dend/Z' ) |
| 117 | + print moose.element( '/model/chem/dend/A/Adot' ).expr |
| 118 | + print moose.element( '/model/chem/dend/B/Bdot' ).expr |
| 119 | + print moose.element( '/model/chem/dend/Ca/CaStim' ).expr |
| 120 | + phase = moose.vec( '/model/chem/dend/phase' ) |
| 121 | + ampl = moose.vec( '/model/chem/dend/ampl' ) |
| 122 | + vel = moose.vec( '/model/chem/dend/vel' ) |
| 123 | + vel.nInit = 1e-6 * seqDt |
| 124 | + ampl.nInit = stimAmpl |
| 125 | + stride = int( dist ) / numSpine |
| 126 | + phase.nInit = 10000 |
| 127 | + Z.nInit = 0 |
| 128 | + for j in range( numSpine ): |
| 129 | + k = blanks + j * stride |
| 130 | + Z[k].nInit = 1 |
| 131 | + phase[k].nInit = preStim + seq[j] * seqDt |
| 132 | + moose.reinit() |
| 133 | + runtime = 50 |
| 134 | + snapshot = preStim + seqDt * (numSpine - 0.8) |
| 135 | + print snapshot |
| 136 | + #snapshot = 26 |
| 137 | + moose.start( snapshot ) |
| 138 | + avec = moose.vec( '/model/chem/dend/A' ).n |
| 139 | + moose.start( runtime - snapshot ) |
| 140 | + tvec = [] |
| 141 | + for i in range( 5 ): |
| 142 | + tab = moose.element( '/model/graphs/plot0[' + str( blanks + i * stride ) + ']' ) |
| 143 | + dt = tab.dt |
| 144 | + tvec.append( tab.vector ) |
| 145 | + moose.delete( '/model' ) |
| 146 | + return dt, tvec, avec |
| 147 | + |
| 148 | +def makePassiveSoma( name, length, diameter ): |
| 149 | + elecid = moose.Neuron( '/library/' + name ) |
| 150 | + dend = moose.Compartment( elecid.path + '/soma' ) |
| 151 | + dend.diameter = diameter |
| 152 | + dend.length = length |
| 153 | + dend.x = length |
| 154 | + return elecid |
| 155 | + |
| 156 | +def plotOnePanel( tLabel, dt, tplot, numSyn, plotRange, tick ): |
| 157 | + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt |
| 158 | + ax = plotBoilerplate( tLabel, 1 + start ) |
| 159 | + for i in range( 5 ): |
| 160 | + plt.plot( t, tplot[i] ) |
| 161 | + ax.yaxis.set_ticks( np.arange( 0, plotRange, tick ) ) |
| 162 | + |
| 163 | + |
| 164 | +def plotPanelCDEF( seq, row ): |
| 165 | + makePassiveSoma( 'cell', 100e-6, 10e-6 ) |
| 166 | + start = (row -1) * 4 |
| 167 | + tLabel = chr( ord( 'A' ) + row - 1 ) |
| 168 | + xLabel = chr( ord( 'C' ) + row - 1 ) |
| 169 | + xplot = [] |
| 170 | + #dt, tplot, avec = runPanelCDEF( 'fhn', 15.0, 3.0, 5, seq, 0.4 ) |
| 171 | + dt, tplot, avec = runPanelCDEF( 'fhn', 5.0, 0.5, 5, seq, 0.4 ) |
| 172 | + xplot.append( avec ) |
| 173 | + #plotOnePanel( dt, 'B', tplot, 5, 1.5, 0.5 ) |
| 174 | + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt |
| 175 | + #ax = plotBoilerplate( tLabel, 1 + start ) |
| 176 | + ax = plotBoilerplate( tLabel, 1 + start, 'Time (s)') |
| 177 | + for i in range( 5 ): |
| 178 | + plt.plot( t, tplot[i] ) |
| 179 | + yl = ax.get_ylim()[1] |
| 180 | + ax.yaxis.set_ticks( np.arange( 0, 4.0001, 1.0 ) ) |
| 181 | + |
| 182 | + #dt, tplot, avec = runPanelCDEF( 'bis', 5.0, 4.0, 5, seq, 1.0 ) |
| 183 | + dt, tplot, avec = runPanelCDEF( 'bis', 15.0, 2.0, 5, seq, 1.0 ) |
| 184 | + xplot.append( avec ) |
| 185 | + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt |
| 186 | + ax = plotBoilerplate( tLabel, 2 + start, 'Time (s)' ) |
| 187 | + for i in range( 5 ): |
| 188 | + plt.plot( t, tplot[i] ) |
| 189 | + yl = ax.get_ylim()[1] |
| 190 | + ax.yaxis.set_ticks( np.arange( 0, 3.0001, 1.0 ) ) |
| 191 | + |
| 192 | + dt, tplot, avec = runPanelCDEF( 'negFB', 5.0, 2.0, 5, seq, 1.0 ) |
| 193 | + xplot.append( avec ) |
| 194 | + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt |
| 195 | + ax = plotBoilerplate( tLabel, 3 + start, 'Time (s)') |
| 196 | + for i in range( 5 ): |
| 197 | + plt.plot( t, tplot[i] ) |
| 198 | + ax.yaxis.set_ticks( np.arange( 0, 10.00001, 5.0 ) ) |
| 199 | + |
| 200 | + dt, tplot, avec = runPanelCDEF( 'negFF', 5.0, 4.0, 5, seq, 1.0 ) |
| 201 | + xplot.append( avec ) |
| 202 | + t = np.arange( 0, len( tplot[0] ), 1.0 ) * dt |
| 203 | + ax = plotBoilerplate( tLabel, 4 + start, 'Time (s)') |
| 204 | + for i in range( 5 ): |
| 205 | + plt.plot( t, tplot[i] ) |
| 206 | + ax.yaxis.set_ticks( np.arange( 0, 5.00001, 2.0 ) ) |
| 207 | + |
| 208 | + for i in zip( range(4), (4.0, 3.0, 10, 4 ), (1, 1, 5, 2) ): |
| 209 | + ax = plotBoilerplate( xLabel, 9 + start + i[0], 'Position( um)' ) |
| 210 | + plt.plot( xplot[i[0]][:50] ) |
| 211 | + ax.yaxis.set_ticks( np.arange( 0, i[1] * 1.0000001, i[2] ) ) |
| 212 | + |
| 213 | +################################################################## |
| 214 | +if __name__ == '__main__': |
| 215 | + moose.Neutral( '/library' ) |
| 216 | + moose.Neutral( '/model' ) |
| 217 | + |
| 218 | + t1 = time.time() |
| 219 | + fig = plt.figure( figsize = (10,10), facecolor='white' ) |
| 220 | + fig.subplots_adjust( left = 0.18 ) |
| 221 | + plotPanelB() |
| 222 | + plotPanelCDEF( [0,1,2,3,4], 3 ) |
| 223 | + plotPanelCDEF( [4,1,0,3,2], 4 ) |
| 224 | + print ("Time taken = ", time.time() - t1) |
| 225 | + plt.tight_layout() |
| 226 | + |
| 227 | + plt.show() |
| 228 | + |
| 229 | + |
0 commit comments