From ee974e94d64510224d3fd06f2f84d6330d28cb10 Mon Sep 17 00:00:00 2001 From: bhalla Date: Thu, 11 Apr 2024 22:21:27 +0530 Subject: [PATCH] Added code and test case for window baseline normalization. --- TestJson/epsc_window_baseline_norm.json | 82 +++++++++++++++++++++++++ findSim.py | 9 ++- models/loadGABAR.json | 7 +++ models/loadGABAR.py | 16 +++++ 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 TestJson/epsc_window_baseline_norm.json create mode 100644 models/loadGABAR.json create mode 100644 models/loadGABAR.py diff --git a/TestJson/epsc_window_baseline_norm.json b/TestJson/epsc_window_baseline_norm.json new file mode 100644 index 0000000..51e1cb9 --- /dev/null +++ b/TestJson/epsc_window_baseline_norm.json @@ -0,0 +1,82 @@ +{ + "Metadata": { + "transcriber": "Upi", + "organization": "NCBS", + "email": "bhalla@ncbs.res.in", + "source": { + "sourceType": "other", + "doi": "0", + "authors": "None", + "journal": "None. This is a purely fictional _experiment_ for the purposes of testing findSim", + "year": 0, + "figure": "" + }, + "testModel": "models/loadGABAR.py", + "testMap": "models/loadGABAR.json" + }, + "Experiment": { + "design": "TimeSeries", + "species": "rat", + "cellType": "hippocampal CA1 pyramidal neuron", + "notes": "Test removal of baseline in voltage clamp peak estimate" + }, + "Stimuli": [ + { + "timeUnits": "sec", + "quantityUnits": "Hz", + "entity" : { + "name": "synInput", + "alias": "synInput" + }, + "field": "rate", + "data": [ + [0,5] + ] + }, + { + "timeUnits": "sec", + "quantityUnits": "mV", + "entity" : { + "name": "soma", + "alias": "soma" + }, + "field": "Vclamp", + "data": [ + [0,-65.0], + [0.001,0.0], + [0.3,-65.0] + ] + } + ], + "Readouts": { + "timeUnits": "sec", + "quantityUnits": "ratio", + "entity" : { + "name": "vclamp", + "alias": "vclamp" + }, + "field": "current", + "window": {"startt": -0.010, "endt": 0.005, "dt": 0.0005, + "operation": "max", "baseline": "min" + }, + "normalization": { + "entity" : { + "name": "vclamp", + "alias": "vclamp" + }, + "sampling": "start" + }, + "data": [ + [0.21, 1, 0], + [0.23, 1.2, 0], + [0.25, 1.2, 0], + [0.27, 1.2, 0], + [0.29, 1.2, 0] + ] + }, + "Modifications": { + "subset": [ + {"name":"all"} + ] + } +} diff --git a/findSim.py b/findSim.py index 105f482..12ed2e9 100644 --- a/findSim.py +++ b/findSim.py @@ -998,7 +998,7 @@ def putStimsInQ( q, stims, pauseHsolve ): val = float(j[1]) * i.quantityScale t = float(j[0])*i.timeScale heapq.heappush( q, Qentry( t, i, val ) ) - if isElec: + if isElec and pauseHsolve.optimizeElec: # Below we tell the Hsolver to turn off or on for elec calcn. if val == 0.0: heapq.heappush( q, Qentry(t+pauseHsolve.stimSettle, pauseHsolve, 0) ) @@ -1135,6 +1135,9 @@ def parseAndRun( model, stims, readouts, getPlots = False ): qe = heapq.heappop( q ) currt = sw.getCurrentTime() if ( qe.t > currt ): + print( "currt={:.4f}, qt={:.4f}".format( currt, qe.t) ) + if qe.t > 1.5: + print( qe.entry ) sw.advanceSimulation( qe.t - currt, doPlot = getPlots ) if isinstance( qe.entry, Stimulus ): sw.deliverStim( qe ) @@ -1176,12 +1179,12 @@ def parseAndRun( model, stims, readouts, getPlots = False ): if readouts.useNormalization and readouts.normMode == "each": if len( [ y for y in readouts.ratioData if abs(y) < eps ] ) > 0: #raise SimError( "runDoser: Normalization1 failed due to zero denominator: " + str( min( readouts.ratioData ) ) ) - print( "parseAndRun: Normalization1 denom={:.3g} for {}.{}".format(min( readouts.ratioData ), readouts.entities[0], readouts.field ) ) + print( "parseAndRun: Normalization1 denom={:.3g} for {}.{}".format(min( readouts.ratioData ), readouts.entities, readouts.field ) ) readouts.simData = [ x/y if abs(y)>= eps else 0.0 for x, y in zip(readouts.simData, readouts.ratioData) ] else: if abs(norm) < eps: #raise SimError( "runDoser: Normalization2 failed due to zero denominator: " + str( norm ) ) - print( "parseAndRun: Normalization2 denom={:.3g} for {}.{}".format( norm, readouts.entities[0], readouts.field ) ) + print( "parseAndRun: Normalization2 denom={:.3g} for {}.{}".format( norm, readouts.entities, readouts.field ) ) readouts.simData = [0.0] *len( readouts.simData ) else: readouts.simData = [ x/norm for x in readouts.simData ] diff --git a/models/loadGABAR.json b/models/loadGABAR.json new file mode 100644 index 0000000..6292307 --- /dev/null +++ b/models/loadGABAR.json @@ -0,0 +1,7 @@ +{ + "all":["all"], + "soma":["elec/soma"], + "synInput":["elec/soma/gabaR/sh/synapse/synInput_rs"], + "synapse":["elec/soma/gabaR/sh/synapse"] +} + diff --git a/models/loadGABAR.py b/models/loadGABAR.py new file mode 100644 index 0000000..903233c --- /dev/null +++ b/models/loadGABAR.py @@ -0,0 +1,16 @@ +import moose +import rdesigneur as rd +def load( scaleParam, chemFile ): + rdes = rd.rdesigneur( + turnOffElec = True, + elecDt = 5e-5, + chanProto = [['make_GABA()', 'gabaR']], + chanDistrib = [ + ['gabaR', 'soma', 'Gbar', '1' ]], + stimList = [['soma', '1','gabaR', 'periodicsyn', '50 * (t > 0.1)']], + ) + return rdes + +def build( rdes ): + rdes.buildModel() + #moose.le( '/model/elec/soma/gabaR/sh/synapse/synInput_rs' )