Skip to content

Commit 8c071cd

Browse files
authored
Cleanup sbml (#447)
* minimum gcc version is 5.X and hdf5 included in cmake as default * CMake correction * Added basepath if exist to compartment Annotation * function input connection done after enzyme, func.expr fixed, corrected stoichiometry for edge case * edgecase if extra path exist it is taken care while writting/reading into/from SBML * correction in basepath to basePath in readSBML
1 parent 9d30995 commit 8c071cd

File tree

2 files changed

+78
-17
lines changed

2 files changed

+78
-17
lines changed

python/moose/SBML/readSBML.py

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,22 @@
1313
** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS
1414
Created : Thu May 13 10:19:00 2016(+0530)
1515
Version
16-
Last-Updated: Mon Sep 21 12:50:00 2020(+0530)
16+
Last-Updated: Tue Apr 5 17:10:00 2022(+0530)
1717
By:HarshaRani
1818
**********************************************************************/
19+
2022:
20+
Apr 05: - edge case NN_mapk15.g, extra Neutral path '/kinetics' exist which
21+
was not created in xml file which was causing ex12.0* example break
22+
This is fixed in writeSBML by adding basepath in compartment Annotation
23+
And same is create in ReadSBML
24+
25+
Mar 22: - function connection are done after Enzyme and Reaction are created
26+
this is because cplx path is modified after Enzyme created, which
27+
would be a problem as path changes
28+
- edge case like pool is parent and product to enzyme, Stoichiometry
29+
need to reduce (eg osc_different_vols)
30+
- function expression fixed if multiple of same pool exist
31+
1932
2020:
2033
Sep 21: - Complex pool which is created at species level is copied under enzyme,
2134
ensuring the value set at species is retained.
@@ -156,7 +169,7 @@ def mooseReadSBML(filepath, loadpath, solver="ee",validate="on"):
156169

157170
mapParameter(model, globparameterIdValue)
158171
msgCmpt = ""
159-
errorFlag,msgCmpt = createCompartment(
172+
errorFlag,msgCmpt,baseId = createCompartment(
160173
baseId, model, comptSbmlidMooseIdMap)
161174

162175
groupInfo = checkGroup(baseId,model,comptSbmlidMooseIdMap)
@@ -165,15 +178,18 @@ def mooseReadSBML(filepath, loadpath, solver="ee",validate="on"):
165178
specInfoMap = {}
166179
errorFlag,warning = createSpecies(
167180
baseId, model, comptSbmlidMooseIdMap, specInfoMap, modelAnnotaInfo,groupInfo)
181+
168182
if errorFlag:
169-
msgRule = createRules(
170-
model, specInfoMap, globparameterIdValue)
183+
errorFlag, msgReac = createReaction(
184+
model, specInfoMap, modelAnnotaInfo, globparameterIdValue,funcDef,groupInfo)
185+
if len(moose.wildcardFind(moose.element(loadpath).path+"/##[ISA=Reac],/##[ISA=EnzBase]")) == 0:
186+
errorFlag = False
187+
noRE = ("Atleast one reaction should be present to display in the widget ")
188+
171189
if errorFlag:
172-
errorFlag, msgReac = createReaction(
173-
model, specInfoMap, modelAnnotaInfo, globparameterIdValue,funcDef,groupInfo)
174-
if len(moose.wildcardFind(moose.element(loadpath).path+"/##[ISA=Reac],/##[ISA=EnzBase]")) == 0:
175-
errorFlag = False
176-
noRE = ("Atleast one reaction should be present to display in the widget ")
190+
msgRule = createRules(
191+
model, specInfoMap, globparameterIdValue)
192+
177193
getModelAnnotation(model, baseId)
178194
if not errorFlag:
179195
# Any time in the middle if SBML does not read then I
@@ -301,7 +317,8 @@ def setupEnzymaticReaction(enz, groupName, enzName, specInfoMap, modelAnnotaInfo
301317
complx1 = moose.copy(complx,enzyme_.path)
302318
else:
303319
complx1 = moose.element(enzyme_.path+'/'+complx.name)
304-
specInfoMap[cplx]["Mpath"] = complx1
320+
specInfoMap[cplx]["Mpath"] = moose.element(complx1)
321+
305322
moose.connect(enzyme_, "cplx", complx1, "reac")
306323
moose.connect(enzyme_, "enz", enzParent, "reac")
307324
sublist = (modelAnnotaInfo[groupName]["substrate"])
@@ -321,7 +338,14 @@ def setupEnzymaticReaction(enz, groupName, enzName, specInfoMap, modelAnnotaInfo
321338
for tr in range(0,enz.getNumProducts()):
322339
sp = enz.getProduct(tr)
323340
spspieces = sp.getSpecies()
324-
enz_prdlist[spspieces] = int(sp.getStoichiometry())
341+
spspieces = sp.getSpecies()
342+
# one of the edge (osc_different_vols) case where pool is a enzyme's parent and
343+
# product, which case the stoichiometry = 2 which is ideally correct for SBML simulator
344+
# but for moose we need to reduce stoichiometry as we connect enzyme parent
345+
if enzPool == spspieces and int(sp.getStoichiometry()) >1:
346+
enz_prdlist[spspieces] = int(sp.getStoichiometry())-1
347+
else:
348+
enz_prdlist[spspieces] = int(sp.getStoichiometry())
325349

326350
for si in range(0, len(sublist)):
327351
sl = sublist[si]
@@ -493,6 +517,8 @@ def getCmptAnnotation(obj):
493517
annotateMap[nodeName] = nodeValue
494518
if nodeName == "surround":
495519
annotateMap[nodeName] = nodeValue
520+
if nodeName == "basePath":
521+
annotateMap[nodeName] = nodeValue
496522
return annotateMap
497523

498524
def getObjAnnotation(obj, modelAnnotationInfo):
@@ -1144,7 +1170,8 @@ def createRules(model, specInfoMap, globparameterIdValue):
11441170
comptvolume.append(poolsCompt.name)
11451171
numVars = funcId.numVars
11461172
x = funcId.path + '/x[' + str(numVars) + ']'
1147-
speFunXterm[i] = 'x' + str(numVars)
1173+
#speFunXterm[i] = 'x' + str(numVars)
1174+
speFunXterm['x'+str(numVars)] = i
11481175
moose.connect(specMapList, 'nOut', x, 'input')
11491176
funcId.numVars = numVars + 1
11501177

@@ -1157,7 +1184,10 @@ def createRules(model, specInfoMap, globparameterIdValue):
11571184
for mem in ruleMemlist:
11581185
if (mem in specInfoMap):
11591186
#exp1 = exp.replace(mem, str(speFunXterm[mem]))
1160-
exp1 = re.sub(r'\b%s\b'% (mem), speFunXterm[mem], exp)
1187+
#exp1 = re.sub(r'\b%s\b'% (mem), speFunXterm[mem], exp)
1188+
exp1 = re.sub(r'\b%s\b'% (mem), list(speFunXterm.keys())[list(speFunXterm.values()).index(mem)], exp,1)
1189+
speFunXterm.pop(list(speFunXterm.keys())[list(speFunXterm.values()).index(mem)])
1190+
11611191
exp = exp1
11621192
elif(mem in globparameterIdValue):
11631193
#exp1 = exp.replace(mem, str(globparameterIdValue[mem]))
@@ -1427,6 +1457,7 @@ def createCompartment(basePath, model, comptSbmlidMooseIdMap):
14271457
return False, "Model has no compartment, atleast one compartment should exist to display in the widget"
14281458
else:
14291459
endo_surr = {}
1460+
toRewritebasepath = True
14301461
for c in range(0, model.getNumCompartments()):
14311462
compt = model.getCompartment(c)
14321463
# print("Compartment " + str(c) + ": "+ UnitDefinition.printUnits(compt.getDerivedUnitDefinition()))
@@ -1461,6 +1492,18 @@ def createCompartment(basePath, model, comptSbmlidMooseIdMap):
14611492
name = sbmlCmptId
14621493
cmptAnnotaInfo = {}
14631494
cmptAnnotaInfo = getCmptAnnotation(compt)
1495+
if "basePath" in cmptAnnotaInfo.keys():
1496+
nl = list(filter(None, (cmptAnnotaInfo["basePath"]).split('/')))
1497+
pathAnno = ""
1498+
if len(nl) > 0:
1499+
for i in range(0,len(nl)):
1500+
pathAnno = pathAnno+'/'+nl[i]
1501+
if not moose.exists(basePath.path+pathAnno):
1502+
rewritebasepath = moose.Neutral(basePath.path+pathAnno)
1503+
if toRewritebasepath:
1504+
basePath = rewritebasepath
1505+
toRewritebasepath = False
1506+
14641507
if "Mesh" in cmptAnnotaInfo.keys():
14651508
if cmptAnnotaInfo["Mesh"] == "CubeMesh" or cmptAnnotaInfo["Mesh"] == "NeuroMesh":
14661509
mooseCmptId = moose.CubeMesh(basePath.path + '/' + name)
@@ -1492,7 +1535,7 @@ def createCompartment(basePath, model, comptSbmlidMooseIdMap):
14921535
elif key in comptSbmlidMooseIdMap:
14931536
del(comptSbmlidMooseIdMap[key])
14941537
return False," EndoMesh's surrounding compartment missing or wrong deleting the compartment check the file"
1495-
return True,""
1538+
return True,"",basePath
14961539

14971540
def setupConcChannel(reac, rName, specInfoMap, reactSBMLIdMooseId,
14981541
modelAnnotaInfo, model, globparameterIdValue):

python/moose/SBML/writeSBML.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS
1414
Created : Friday May 27 12:19:00 2016(+0530)
1515
Version
16-
Last-Updated: Tue 08 Sep 02:22:10 2020(+0530)
16+
Last-Updated: Tue 05 Apr 11:22:10 2022(+0530)
1717
By: HarshaRani
1818
**********************************************************************/
1919
/****************************
20+
2022
21+
Apr 5 : Added basepath in compartment Annotation
2022
2021
2123
Apr 16: replace ReacBase to Reac and EnzBase to Enz as API can has changed
2224
2020
@@ -541,7 +543,6 @@ def writeEnz(modelpath, cremodel_, sceneitems,groupInfo):
541543
enzAnno2 = enzAnno2 +"<moose:enzyme>" + \
542544
(str(idBeginWith(convertSpecialChar(
543545
nameList_[i])))) + "</moose:enzyme>\n"
544-
545546
enzPrd = enz.neighbors["prd"]
546547
noofPrd = len(enzPrd)
547548
if not enzPrd:
@@ -1242,6 +1243,12 @@ def writeCompt(modelpath, cremodel_):
12421243
str(compt.dataIndex) +
12431244
"_")))
12441245
comptID_sbml[compt] = csetId
1246+
nl = list(filter(None, (compt.parent.path).split('/')))
1247+
pathAnno = ""
1248+
if len(nl) > 1:
1249+
for i in range(1,len(nl)):
1250+
pathAnno = pathAnno+'/'+nl[i]
1251+
12451252
if compt.isA("EndoMesh"):
12461253
if comptID_sbml.get(compt.surround) == None:
12471254
createCompt = False
@@ -1253,7 +1260,10 @@ def writeCompt(modelpath, cremodel_):
12531260
"<moose:surround>" + \
12541261
str(comptID_sbml[compt.surround])+ "</moose:surround>\n" + \
12551262
"<moose:isMembraneBound>" + \
1256-
str(compt.isMembraneBound)+ "</moose:isMembraneBound>\n"
1263+
str(compt.isMembraneBound)+ "</moose:isMembraneBound>\n"
1264+
if pathAnno != "":
1265+
comptAnno = comptAnno + "<moose:basePath>" \
1266+
+ pathAnno + "</moose:basePath>"
12571267
if moose.exists(compt.path+'/info'):
12581268
if moose.element(compt.path+'/info').notes != "":
12591269
comptAnno = comptAnno + "<moose:Notes>" \
@@ -1269,6 +1279,10 @@ def writeCompt(modelpath, cremodel_):
12691279
str(compt.diffLength)+ "</moose:diffLength>\n" + \
12701280
"<moose:isMembraneBound>" + \
12711281
str(compt.isMembraneBound)+ "</moose:isMembraneBound>\n"
1282+
if pathAnno != "":
1283+
comptAnno = comptAnno + "<moose:basePath>" \
1284+
+ pathAnno + "</moose:basePath>"
1285+
12721286
if moose.exists(compt.path+'/info'):
12731287
if moose.element(compt.path+'/info').notes != "":
12741288
comptAnno = comptAnno + "<moose:Notes>" \
@@ -1279,6 +1293,10 @@ def writeCompt(modelpath, cremodel_):
12791293
str(compt.className) + "</moose:Mesh>\n" + \
12801294
"<moose:isMembraneBound>" + \
12811295
str(compt.isMembraneBound)+ "</moose:isMembraneBound>\n"
1296+
if pathAnno != "":
1297+
comptAnno = comptAnno + "<moose:basePath>" \
1298+
+ pathAnno + "</moose:basePath>"
1299+
12821300
if moose.exists(compt.path+'/info'):
12831301
if moose.element(compt.path+'/info').notes != "":
12841302
comptAnno = comptAnno + "<moose:Notes>" \

0 commit comments

Comments
 (0)