Skip to content

Commit d6e5711

Browse files
authored
Merge pull request #335 from hrani/master
xref pool are not wirtten and cleaned up if part of Reaction/Enzyme
2 parents 169d0c8 + fac76ad commit d6e5711

File tree

4 files changed

+186
-130
lines changed

4 files changed

+186
-130
lines changed

python/moose/SBML/readSBML.py

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
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 Nov 19 15:45:00 2018(+0530)
16+
Last-Updated: Fri Nov 30 17:30:00 2018(+0530)
1717
By:HarshaRani
1818
**********************************************************************/
1919
2018
20+
Nov 30: - groups and subgroups are read from xml to moose
2021
Nov 19: - reading and creating CylMesh and EndoMesh if specified in the Annotation field in compartment
2122
definition, also checking if EndoMesh missing/wrong surround compartment
2223
Oct 26: - validator can be switchedoff by passing validate="off" while readSBML files
@@ -200,7 +201,7 @@ def mooseReadSBML(filepath, loadpath, solver="ee",validate="on"):
200201
moose.delete(basePath)
201202
loadpath = moose.Shell('/')
202203
#return basePath, ""
203-
loaderror = msgCmpt+msgRule+msgReac+noRE
204+
loaderror = msgCmpt+str(msgRule)+msgReac+noRE
204205
if loaderror != "":
205206
loaderror = loaderror
206207
return moose.element(loadpath), loaderror
@@ -226,6 +227,7 @@ def checkFuncDef(model):
226227
if foundbvar and foundfuncMathML:
227228
funcDef[f.getName()] = {'bvar':bvar, "MathML": fmath.getRightChild()}
228229
return funcDef
230+
229231
def checkGroup(basePath,model):
230232
groupInfo = {}
231233
modelAnnotaInfo = {}
@@ -238,26 +240,36 @@ def checkGroup(basePath,model):
238240
groupAnnoInfo = getObjAnnotation(p, modelAnnotaInfo)
239241
if groupAnnoInfo != {}:
240242
if moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]):
241-
if not moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getId()):
242-
moosegrp = moose.Neutral(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getId())
243+
if "Group" in groupAnnoInfo:
244+
if moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]):
245+
if moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName()):
246+
moosegrp = moose.element(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName())
247+
else:
248+
moosegrp = moose.Neutral(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName())
249+
else:
250+
moose.Neutral(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"])
251+
if moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName()):
252+
moosegrp = moose.element(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName())
253+
else:
254+
moosegrp = moose.Neutral(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+groupAnnoInfo["Group"]+'/'+p.getName())
243255
else:
244-
moosegrp = moose.element(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getId())
256+
if not moose.exists(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getName()):
257+
moosegrp = moose.Neutral(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getName())
258+
else:
259+
moosegrp = moose.element(basePath.path+'/'+groupAnnoInfo["Compartment"]+'/'+p.getName())
245260
moosegrpinfo = moose.Annotator(moosegrp.path+'/info')
246261
moosegrpinfo.color = groupAnnoInfo["bgColor"]
247-
else:
248-
print ("Compartment not found")
249-
262+
else:
263+
print ("Compartment not found")
250264
if p.getKind() == 2:
251265
if p.getId() not in groupInfo:
252-
#groupInfo[p.getId()]
266+
memlists = []
253267
for gmemIndex in range(0,p.getNumMembers()):
254268
mem = p.getMember(gmemIndex)
255-
256-
if p.getId() in groupInfo:
257-
groupInfo[p.getId()].append(mem.getIdRef())
258-
else:
259-
groupInfo[p.getId()] =[mem.getIdRef()]
269+
memlists.append(mem.getIdRef())
270+
groupInfo[p.getId()] = {"mpath":moosegrp, "splist":memlists}
260271
return groupInfo
272+
261273
def setupEnzymaticReaction(enz, groupName, enzName,
262274
specInfoMap, modelAnnotaInfo,deletcplxMol):
263275
enzPool = (modelAnnotaInfo[groupName]["enzyme"])
@@ -605,9 +617,13 @@ def createReaction(model, specInfoMap, modelAnnotaInfo, globparameterIdValue,fun
605617

606618
if (reac.isSetId()):
607619
rId = reac.getId()
608-
groups = [k for k, v in groupInfo.items() if rId in v]
609-
if groups:
610-
group = groups[0]
620+
#groups = [k for k, v in groupInfo.items() if rId in v]
621+
for k,v in groupInfo.items():
622+
if rId in v["splist"]:
623+
group = v["mpath"]
624+
625+
# if groups:
626+
# group = groups[0]
611627
if (reac.isSetName()):
612628
rName = reac.getName()
613629
rName = rName.replace(" ", "_space_")
@@ -681,12 +697,12 @@ def createReaction(model, specInfoMap, modelAnnotaInfo, globparameterIdValue,fun
681697
sp = react.getSpecies()
682698
sp = str(idBeginWith(sp))
683699
speCompt = specInfoMap[sp]["comptId"].path
684-
685700
if group:
686-
if moose.exists(speCompt+'/'+group):
687-
speCompt = speCompt+'/'+group
688-
else:
689-
speCompt = (moose.Neutral(speCompt+'/'+group)).path
701+
speCompt = group.path
702+
# if moose.exists(speCompt+'/'+group):
703+
# speCompt = speCompt+'/'+group
704+
# else:
705+
# speCompt = (moose.Neutral(speCompt+'/'+group)).path
690706
if moose.exists(speCompt + '/' + rName):
691707
rName =rId
692708
reaction_ = moose.Reac(speCompt + '/' + rName)
@@ -1125,7 +1141,6 @@ def pullnotes(sbmlId, mooseId):
11251141
objInfo = moose.element(mooseId.path + '/info')
11261142
objInfo.notes = notes
11271143

1128-
11291144
def createSpecies(basePath, model, comptSbmlidMooseIdMap,
11301145
specInfoMap, modelAnnotaInfo,groupInfo):
11311146
# ToDo:
@@ -1145,10 +1160,13 @@ def createSpecies(basePath, model, comptSbmlidMooseIdMap,
11451160

11461161
sName = None
11471162
sId = spe.getId()
1148-
1149-
groups = [k for k, v in groupInfo.items() if sId in v]
1150-
if groups:
1151-
group = groups[0]
1163+
group = ""
1164+
#groups = [k for k, v in groupInfo.items() if sId in v]
1165+
for k,v in groupInfo.items():
1166+
if sId in v["splist"]:
1167+
group = v["mpath"]
1168+
# if groups:
1169+
# group = groups[0]
11521170
if spe.isSetName():
11531171
sName = spe.getName()
11541172
sName = sName.replace(" ", "_space_")
@@ -1166,10 +1184,11 @@ def createSpecies(basePath, model, comptSbmlidMooseIdMap,
11661184
# "false": is {unit of amount}/{unit of size} (i.e., concentration or density).
11671185
# "true": then the value is interpreted as having a unit of amount only.
11681186
if group:
1169-
if moose.exists(comptEl+'/'+group):
1170-
comptEl = comptEl+'/'+group
1171-
else:
1172-
comptEl = (moose.Neutral(comptEl+'/'+group)).path
1187+
comptEl = group.path
1188+
# if moose.exists(comptEl+'/'+group):
1189+
# comptEl = comptEl+'/'+group
1190+
# else:
1191+
# comptEl = (moose.Neutral(comptEl+'/'+group)).path
11731192
if (boundaryCondition):
11741193
poolId = moose.BufPool(comptEl + '/' + sName)
11751194
else:
@@ -1253,7 +1272,6 @@ def createSpecies(basePath, model, comptSbmlidMooseIdMap,
12531272

12541273
return (True," ")
12551274

1256-
12571275
def transformUnit(unitForObject, hasonlySubUnit=False):
12581276
# print "unit
12591277
# ",UnitDefinition.printUnits(unitForObject.getDerivedUnitDefinition())

python/moose/SBML/writeSBML.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
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: Thr 12 Nov 14:15:10 2018(+0530)
16+
Last-Updated: Fri 30 Nov 15:15:10 2018(+0530)
1717
By: HarshaRani
1818
**********************************************************************/
1919
/****************************
2020
2018
21+
Nov 30: group id is changed from name to moose_id and group.name is added along with annotation for group listing
22+
Nov 22: searched for _xfer_ instead of xfer
2123
Nov 12: xfer cross compartment molecules are not written to SBML instead written the original molecule also for connecting Reaction and Enzyme
2224
Nov 06: All the Mesh Cyl,Cube,Neuro,Endo Mesh's can be written into SBML format with annotation field where Meshtype\
2325
numDiffCompts,isMembraneBound and surround are written out.
@@ -152,20 +154,24 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
152154
mplugin = cremodel_.getPlugin("groups")
153155
group = mplugin.createGroup()
154156
name = str(idBeginWith(moose.element(key).name))
155-
group.setId(name)
157+
moosegrpId = name +"_" + str(moose.element(key).getId().value) + "_" + str(moose.element(key).getDataIndex())
158+
group.setId(moosegrpId)
159+
group.setName(name)
160+
156161
group.setKind("collection")
157162
if moose.exists(key.path+'/info'):
158163
ginfo = moose.element(key.path+'/info')
159164
else:
160165
ginfo = moose.Annotator(key.path+'/info')
161166
groupCompartment = findCompartment(key)
162-
if ginfo.color != '':
163-
grpAnno = "<moose:GroupAnnotation>"
164-
grpAnno = grpAnno + "<moose:Compartment>" + groupCompartment.name + "</moose:Compartment>\n"
165-
if ginfo.color:
166-
grpAnno = grpAnno + "<moose:bgColor>" + ginfo.color + "</moose:bgColor>\n"
167-
grpAnno = grpAnno + "</moose:GroupAnnotation>"
168-
group.setAnnotation(grpAnno)
167+
grpAnno = "<moose:GroupAnnotation>"
168+
grpAnno = grpAnno + "<moose:Compartment>" + groupCompartment.name + "</moose:Compartment>\n"
169+
if moose.element(key.parent).className == "Neutral":
170+
grpAnno = grpAnno + "<moose:Group>" + key.parent.name + "</moose:Group>\n"
171+
if ginfo.color:
172+
grpAnno = grpAnno + "<moose:bgColor>" + ginfo.color + "</moose:bgColor>\n"
173+
grpAnno = grpAnno + "</moose:GroupAnnotation>"
174+
group.setAnnotation(grpAnno)
169175

170176
for values in value:
171177
member = group.createMember()
@@ -605,7 +611,8 @@ def processRateLaw(objectCount, cremodel, noofObj, type, mobjEnz):
605611
nameList_[:] = []
606612
for value, count in objectCount.items():
607613
value = moose.element(value)
608-
if re.search("xfer",value.name):
614+
615+
if re.search("_xfer_",value.name):
609616
modelRoot = value.path[0:value.path.index('/',1)]
610617
xrefPool = value.name[:value.name.index("_xfer_")]
611618
xrefCompt = value.name[value.name.index("_xfer_") + len("_xfer_"):]
@@ -897,7 +904,7 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
897904
# getting all the species
898905
for spe in moose.wildcardFind(modelpath + '/##[0][ISA=PoolBase]'):
899906
#Eliminating xfer molecules writting
900-
if not re.search("xfer",spe.name):
907+
if not re.search("_xfer_",spe.name):
901908

902909
sName = convertSpecialChar(spe.name)
903910
comptVec = findCompartment(spe)

python/moose/chemMerge/merge.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,17 @@ def mergeChemModel(src,des):
144144
poolListinb = {}
145145
poolListinb = updatePoolList(comptBdict)
146146

147-
R_Duplicated, R_Notcopiedyet,R_Daggling = [], [], []
148-
E_Duplicated, E_Notcopiedyet,E_Daggling = [], [], []
147+
R_Duplicated, R_Notcopiedyet,R_Dangling = [], [], []
148+
E_Duplicated, E_Notcopiedyet,E_Dangling = [], [], []
149149
for key in list(dictComptA.keys()):
150150
funcExist, funcNotallowed = [], []
151151
funcExist,funcNotallowed = functionMerge(dictComptB,dictComptA,key)
152152

153153
poolListinb = updatePoolList(dictComptB)
154-
R_Duplicated,R_Notcopiedyet,R_Daggling = reacMerge(dictComptA,dictComptB,key,poolListinb)
154+
R_Duplicated,R_Notcopiedyet,R_Dangling = reacMerge(dictComptA,dictComptB,key,poolListinb)
155155

156156
poolListinb = updatePoolList(dictComptB)
157-
E_Duplicated,E_Notcopiedyet,E_Daggling = enzymeMerge(dictComptB,dictComptA,key,poolListinb)
157+
E_Duplicated,E_Notcopiedyet,E_Dangling = enzymeMerge(dictComptB,dictComptA,key,poolListinb)
158158

159159
# if isinstance(src, str):
160160
# if os.path.isfile(src) == True:
@@ -209,15 +209,15 @@ def mergeChemModel(src,des):
209209
for ed in list(E_Notcopiedyet):
210210
print ("%s " %str(ed.name))
211211

212-
if R_Daggling or E_Daggling:
213-
print ("\n Daggling reaction/enzyme are not allowed in moose, these are not merged to %s from %s" %(dfile, sfile))
214-
if R_Daggling:
212+
if R_Dangling or E_Dangling:
213+
print ("\n Dangling reaction/enzyme are not allowed in moose, these are not merged to %s from %s" %(dfile, sfile))
214+
if R_Dangling:
215215
print("Reaction: ")
216-
for rd in list(R_Daggling):
216+
for rd in list(R_Dangling):
217217
print ("%s " %str(rd.name))
218-
if E_Daggling:
218+
if E_Dangling:
219219
print ("Enzyme:")
220-
for ed in list(E_Daggling):
220+
for ed in list(E_Dangling):
221221
print ("%s " %str(ed.name))
222222

223223
## Model is saved
@@ -436,7 +436,7 @@ def copy_deleteUnlyingPoolObj(pool,path):
436436
poolcopied = moose.copy(pool,path)
437437
copied = True
438438
# deleting function and enzyme which gets copied if exist under pool
439-
# This is done to ensure daggling function / enzyme not copied.
439+
# This is done to ensure Dangling function / enzyme not copied.
440440
funclist = []
441441
for types in ['setConc','setN','increment']:
442442
funclist.extend(moose.element(poolcopied).neighbors[types])
@@ -456,7 +456,7 @@ def updatePoolList(comptAdict):
456456

457457
def enzymeMerge(comptD,comptS,key,poolListind):
458458
war_msg = ""
459-
RE_Duplicated, RE_Notcopiedyet, RE_Daggling = [], [], []
459+
RE_Duplicated, RE_Notcopiedyet, RE_Dangling = [], [], []
460460
comptDpath = moose.element(comptD[key]).path
461461
comptSpath = moose.element(comptS[key]).path
462462
objD = moose.element(comptDpath).parent.name
@@ -501,7 +501,7 @@ def enzymeMerge(comptD,comptS,key,poolListind):
501501
RE_Notcopiedyet.append(es)
502502
else:
503503
# -- it is dagging reaction
504-
RE_Daggling.append(es)
504+
RE_Dangling.append(es)
505505
else:
506506
#Same Enzyme name
507507
# -- Same substrate and product including same volume then don't copy
@@ -551,12 +551,12 @@ def enzymeMerge(comptD,comptS,key,poolListind):
551551
if eSsubname and eSprdname:
552552
RE_Notcopiedyet.append(es)
553553
else:
554-
RE_Daggling.append(es)
554+
RE_Dangling.append(es)
555555

556-
return RE_Duplicated,RE_Notcopiedyet,RE_Daggling
556+
return RE_Duplicated,RE_Notcopiedyet,RE_Dangling
557557

558558
def reacMerge(comptS,comptD,key,poolListina):
559-
RE_Duplicated, RE_Notcopiedyet, RE_Daggling = [], [], []
559+
RE_Duplicated, RE_Notcopiedyet, RE_Dangling = [], [], []
560560
war_msg = ""
561561
comptSpath = moose.element(comptS[key]).path
562562
comptDpath = moose.element(comptD[key]).path
@@ -594,9 +594,9 @@ def reacMerge(comptS,comptD,key,poolListina):
594594
RE_Notcopiedyet.append(rs)
595595
else:
596596
# -- it is dagging reaction
597-
RE_Daggling.append(rs)
598-
#print ("This reaction \""+rb.path+"\" has no substrate/product daggling reaction are not copied")
599-
#war_msg = war_msg+"\nThis reaction \""+rb.path+"\" has no substrate/product daggling reaction are not copied"
597+
RE_Dangling.append(rs)
598+
#print ("This reaction \""+rb.path+"\" has no substrate/product Dangling reaction are not copied")
599+
#war_msg = war_msg+"\nThis reaction \""+rb.path+"\" has no substrate/product Dangling reaction are not copied"
600600

601601
else:
602602
#Same reaction name
@@ -640,9 +640,9 @@ def reacMerge(comptS,comptD,key,poolListina):
640640
if rSsubname and rSprdname:
641641
RE_Notcopiedyet.append(rs)
642642
else:
643-
RE_Daggling.append(rs)
643+
RE_Dangling.append(rs)
644644

645-
return RE_Duplicated,RE_Notcopiedyet,RE_Daggling
645+
return RE_Duplicated,RE_Notcopiedyet,RE_Dangling
646646

647647
def subprdList(reac,subprd):
648648
rtype = moose.element(reac).neighbors[subprd]

0 commit comments

Comments
 (0)