Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/BhallaLab/FindSim into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
upibhalla committed Sep 15, 2023
2 parents a96b273 + d70d868 commit 2eb3949
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 16 deletions.
46 changes: 38 additions & 8 deletions findSim.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,32 @@
import imp # This is apparently deprecated in Python 3.4 and up
else:
import importlib

'''
from simError import SimError
import simWrap
import simWrapMoose
import simWrapHillTau
'''

foundLib_HillTau_ = False
try:
import hillTau
foundLib_HillTau_ = True
except Exception as e:
pass

if __package__ is None or __package__ == '':
from simError import SimError
from simWrap import SimWrap
from simWrapMoose import SimWrapMoose
if foundLib_HillTau_:
from simWrapHillTau import SimWrapHillTau
else:
from FindSim.simError import SimError
from FindSim.simWrap import SimWrap
from FindSim.simWrapMoose import SimWrapMoose
if foundLib_HillTau_:
from FindSim.simWrapHillTau import SimWrapHillTau

convertTimeUnits = {'sec': 1.0,'s': 1.0,
'ms': 1e-3, 'millisec': 1e-3, 'msec' : 1e-3,
Expand Down Expand Up @@ -1337,9 +1358,9 @@ def saveTweakedModel( origFname, dumpFname, mapFile, scaleParam ):
# does a fresh load, tweaks the params, and saves.
fname, extn = os.path.splitext( dumpFname )
if extn == '.g' or extn == '.xml':
localSW = simWrapMoose.SimWrapMoose( mapFile = mapFile, ignoreMissingObj = True, silent = True )
localSW = SimWrapMoose( mapFile = mapFile, ignoreMissingObj = True, silent = True )
elif extn == '.json':
localSW = simWrapHillTau.SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = True, silent = True )
localSW = SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = True, silent = True )
else:
print( "Warning: dumpTweakedModel: File format '{}' not known".format( extn ) )
return
Expand Down Expand Up @@ -1394,9 +1415,9 @@ def runit( expt, model, stims, readouts, getPlots = False ):
def getInitParams( modelFile, mapFile, paramList ):
# ParamList as strings of objpath.field
if modelFile.split('.')[-1] == "json":
sw = simWrapHillTau.SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = False, silent = False )
sw = SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = False, silent = False )
else:
sw = simWrapMoose.SimWrapMoose( mapFile = mapFile, ignoreMissingObj = False, silent = False )
sw = SimWrapMoose( mapFile = mapFile, ignoreMissingObj = False, silent = False )

sw.deleteSimulation()
sw.loadModelFile( modelFile, silentDummyModify, [], "", "" )
Expand Down Expand Up @@ -1457,7 +1478,7 @@ def innerMain( exptFile, scoreFunc = defaultScoreFunc, modelFile = "", mapFile =
readouts.generate = generate

if mapFile != "":
mapFile = mapFile
mapFile = mapFile
else:
mapFile = expt.testMap

Expand All @@ -1468,9 +1489,18 @@ def innerMain( exptFile, scoreFunc = defaultScoreFunc, modelFile = "", mapFile =
if model.fileName.split('.')[-1] == "json":
simWrap = "HillTau"
if simWrap == "":
sw = simWrapMoose.SimWrapMoose( mapFile = mapFile, ignoreMissingObj = ignoreMissingObj, silent = silent )
sw = SimWrapMoose( mapFile = mapFile, ignoreMissingObj = ignoreMissingObj, silent = silent )
elif simWrap == "HillTau":
sw = simWrapHillTau.SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = ignoreMissingObj, silent = silent )
global foundLib_HillTau_
if not foundLib_HillTau_:
print('[WARN] No HillTau found.'
'\nThis module can be installed by using `pip` in terminal:'
'\n\t $ pip install HillTau'
)
return
else:
sw = SimWrapHillTau( mapFile = mapFile, ignoreMissingObj = ignoreMissingObj, silent = silent )

else:
sw = simWrap.SimWrap( ignoreMissingObj = ignoreMissingObj )
model.pauseHsolve = PauseHsolve( optimizeElec )
Expand Down
10 changes: 9 additions & 1 deletion simWrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@
********************************************************************/
'''
import json
from simError import SimError
#from simError import SimError
import numpy as np

if __package__ is None or __package__ == '':
from simError import SimError

else:
from FindSim.simError import SimError



class SimWrap():
def __init__( self, *args, **kwargs ):
self.ignoreMissingObj = kwargs["ignoreMissingObj"]
Expand Down
16 changes: 13 additions & 3 deletions simWrapHillTau.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@
import json
import numpy as np
import moose
from simWrap import SimWrap
from simError import SimError
import hillTau

# from simWrap import SimWrap
# from simError import SimError
# import hillTau
import time

if __package__ is None or __package__ == '':
from simError import SimError
from simWrap import SimWrap
import hillTau
else:
from FindSim.simError import SimError
from FindSim.simWrap import SimWrap
import hilltau as hillTau

SIGSTR = "{:.4g}" # Used for dumping JSON files.

class SimWrapHillTau( SimWrap ):
Expand Down
31 changes: 27 additions & 4 deletions simWrapMoose.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,32 @@
import numpy as np
import moose
import sys
import imp ## May be deprecated from Python 3.4
from simWrap import SimWrap
from simError import SimError

# import imp ## May be deprecated from Python 3.4
# from simWrap import SimWrap
# from simError import SimError


if sys.version_info < (3, 4):
import imp # This is apparently deprecated in Python 3.4 and up
else:
import importlib

foundLib_HillTau_ = False

try:
import hilltau
foundLib_HillTau_ = True
except Exception as e:
pass

if __package__ is None or __package__ == '':
from simError import SimError
from simWrap import SimWrap

else:
from FindSim.simError import SimError
from FindSim.simWrap import SimWrap

MINIMUM_TAU = 1e-3 # Do not permit excessively fast chem time consts.
MINIMUM_TAU_RATIO = 1e-2 # Do not permit excessively large change in tau.
Expand Down Expand Up @@ -291,7 +314,7 @@ def buildModelLookup( self, tempModelLookup ):
self.modelLookup[key] = foundObj

def loadModelFile( self, fname, modifyFunc, scaleParam, dumpFname, paramFname ): # modify arg is a func
#This list holds the entire models Reac/Enz sub/prd list for reference
#This list holds the entire models Reac/Enz sub/prd list for reference
if moose.exists( '/model' ):
raise SimError( "loadModelFile: Model already exists" )
erSPlist = {}
Expand Down

0 comments on commit 2eb3949

Please sign in to comment.