Skip to content

Commit 0997a46

Browse files
authored
Merge pull request #341 from hrani/master
using existing restoreXreacs function to remove _xfer_ objects before…
2 parents ed7c4d5 + 4dfac33 commit 0997a46

File tree

3 files changed

+69
-81
lines changed

3 files changed

+69
-81
lines changed

python/moose/SBML/readSBML.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
except ImportError:
8383
pass
8484

85-
def mooseReadSBML(filepath, loadpath, solver="ee",validate="on"):
85+
def mooseReadSBML(filepath, loadpath, solver="ee",validate="True"):
8686
"""Load SBML model
8787
"""
8888
global foundLibSBML_
@@ -105,7 +105,7 @@ def mooseReadSBML(filepath, loadpath, solver="ee",validate="on"):
105105
filep = open(filepath, "r")
106106
document = libsbml.readSBML(filepath)
107107
tobecontinue = False
108-
if validate == "on":
108+
if validate == "True":
109109
tobecontinue = validateModel(document)
110110
else:
111111
tobecontinue = True

python/moose/SBML/writeSBML.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
**********************************************************************/
1919
/****************************
2020
2018
21+
Dec 07: using fixXreac's restoreXreacs function to remove xfer
2122
Dec 03: add diff and motor constants to pool
2223
Nov 30: group id is changed from name to moose_id and group.name is added along with annotation for group listing
2324
Nov 22: searched for _xfer_ instead of xfer
@@ -48,6 +49,7 @@
4849
from moose.SBML.validation import validateModel
4950
from moose.chemUtil.chemConnectUtil import *
5051
from moose.chemUtil.graphUtils import *
52+
from moose.fixXreacs import restoreXreacs
5153

5254
foundLibSBML_ = False
5355
try:
@@ -84,6 +86,7 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
8486
if not moose.exists(modelpath):
8587
return False, "Path doesn't exist"
8688
elif moose.exists(modelpath):
89+
moose.fixXreacs.restoreXreacs(modelpath)
8790
checkCompt = moose.wildcardFind(modelpath+'/##[0][ISA=ChemCompt]')
8891

8992
mObj = moose.wildcardFind(moose.element(modelpath).path+'/##[0][ISA=PoolBase]'+','+
@@ -612,15 +615,15 @@ def processRateLaw(objectCount, cremodel, noofObj, type, mobjEnz):
612615
nameList_[:] = []
613616
for value, count in objectCount.items():
614617
value = moose.element(value)
615-
618+
'''
616619
if re.search("_xfer_",value.name):
617620
modelRoot = value.path[0:value.path.index('/',1)]
618621
xrefPool = value.name[:value.name.index("_xfer_")]
619622
xrefCompt = value.name[value.name.index("_xfer_") + len("_xfer_"):]
620623
orgCompt = moose.wildcardFind(modelRoot+'/##[FIELD(name)='+xrefCompt+']')[0]
621624
orgPool = moose.wildcardFind(orgCompt.path+'/##[FIELD(name)='+xrefPool+']')[0]
622625
value = orgPool
623-
626+
'''
624627
nameIndex = value.name + "_" + \
625628
str(value.getId().value) + "_" + str(value.getDataIndex()) + "_"
626629
clean_name = (str(idBeginWith(convertSpecialChar(nameIndex))))

python/moose/genesis/writeKkit.py

Lines changed: 62 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
__maintainer__ = "Harsha Rani"
1010
__email__ = "[email protected]"
1111
__status__ = "Development"
12-
__updated__ = "Nov 22 2018"
12+
__updated__ = "Dec 08 2018"
1313

1414
# 2018
15+
# Dec 08: using restoreXreacs from fixXreacs
1516
# Nov 22: searched for _xfer_ instead of xfer
1617
# Nov 21: xfer pool are not written and cleaned up if part of Reaction/Enzyme or notes,
1718
# group are checked under all the mesh
@@ -27,7 +28,8 @@
2728
import moose
2829
from moose.chemUtil.chemConnectUtil import *
2930
from moose.chemUtil.graphUtils import *
30-
31+
from moose.fixXreacs import restoreXreacs
32+
3133
foundmatplotlib_ = False
3234
try:
3335
import matplotlib
@@ -75,7 +77,7 @@ def mooseWriteKkit( modelpath, filename, sceneitems={}):
7577
global cmin,cmax,xmin,xmax,ymin,ymax
7678
cmin, xmin, ymin = 0, 0, 0
7779
cmax, xmax, ymax = 1, 1, 1
78-
80+
moose.fixXreacs.restoreXreacs(modelpath)
7981
compt = moose.wildcardFind(modelpath+'/##[0][ISA=ChemCompt]')
8082
maxVol = estimateDefaultVol(compt)
8183
positionInfoExist = True
@@ -184,12 +186,10 @@ def calPrime(x):
184186

185187
def storeCplxEnzMsgs( enz, f ):
186188
for sub in enz.neighbors["subOut"]:
187-
sub = xfer(sub)
188189
s = "addmsg /kinetics/" + trimPath( moose.element(sub) ) + " /kinetics/" + trimPath(enz) + " SUBSTRATE n \n";
189190
s = s+ "addmsg /kinetics/" + trimPath( enz ) + " /kinetics/" + trimPath( sub ) + " REAC sA B \n";
190191
f.write(s)
191192
for prd in enz.neighbors["prd"]:
192-
prd = xfer(prd)
193193
s = "addmsg /kinetics/" + trimPath( enz ) + " /kinetics/" + trimPath(prd) + " MM_PRD pA\n";
194194
f.write( s )
195195
for enzOut in enz.neighbors["enzOut"]:
@@ -202,13 +202,11 @@ def storeMMenzMsgs( enz, f):
202202
prdList = enz.neighbors["prd"]
203203
enzDestList = enz.neighbors["enzDest"]
204204
for esub in subList:
205-
esub = xfer(esub)
206205
es = "addmsg /kinetics/" + trimPath(moose.element(esub)) + " /kinetics/" + trimPath(enz) + " SUBSTRATE n \n";
207206
es = es+"addmsg /kinetics/" + trimPath(enz) + " /kinetics/" + trimPath(moose.element(esub)) + " REAC sA B \n";
208207
f.write(es)
209208

210209
for eprd in prdList:
211-
eprd = xfer(eprd)
212210
es = "addmsg /kinetics/" + trimPath( enz ) + " /kinetics/" + trimPath( moose.element(eprd)) + " MM_PRD pA \n";
213211
f.write(es)
214212
for eenzDest in enzDestList:
@@ -223,16 +221,6 @@ def storeEnzMsg( enzList, f):
223221
else:
224222
storeCplxEnzMsgs( enz, f )
225223

226-
def xfer(xferpool):
227-
if re.search("_xfer_",xferpool.name):
228-
modelRoot = xferpool.path[0:xferpool.path.index('/',1)]
229-
xrefPool = xferpool.name[:xferpool.name.index("_xfer_")]
230-
xrefCompt = xferpool.name[xferpool.name.index("_xfer_") + len("_xfer_"):]
231-
orgCompt = moose.wildcardFind(modelRoot+'/##[FIELD(name)='+xrefCompt+']')[0]
232-
orgPool = moose.wildcardFind(orgCompt.path+'/##[FIELD(name)='+xrefPool+']')[0]
233-
xferpool = orgPool
234-
return xferpool
235-
236224
def storeChanMsg(chanList,f):
237225
for channel in chanList:
238226
for chanOL in channel.neighbors['out']:
@@ -392,13 +380,11 @@ def storeReacMsg(reacList,f):
392380
sublist = reac.neighbors["subOut"]
393381
prdlist = reac.neighbors["prd"]
394382
for sub in sublist:
395-
sub = xfer(sub)
396383
s = "addmsg /kinetics/" + trimPath( sub ) + " /kinetics/" + reacPath + " SUBSTRATE n \n";
397384
s = s + "addmsg /kinetics/" + reacPath + " /kinetics/" + trimPath( sub ) + " REAC A B \n";
398385
f.write(s)
399386

400387
for prd in prdlist:
401-
prd = xfer(prd)
402388
s = "addmsg /kinetics/" + trimPath( prd ) + " /kinetics/" + reacPath + " PRODUCT n \n";
403389
s = s + "addmsg /kinetics/" + reacPath + " /kinetics/" + trimPath( prd ) + " REAC B A\n";
404390
f.write( s)
@@ -599,64 +585,63 @@ def writePool(modelpath,f,volIndex,sceneitems):
599585
textcolor = ""
600586

601587
for p in moose.wildcardFind(modelpath+'/##[0][ISA=PoolBase]'):
602-
if not re.search("xfer",p.name):
603-
if findCompartment(p) == moose.element('/'):
604-
error = error + " \n "+p.path+ " doesn't have compartment ignored to write to genesis"
605-
else:
606-
slave_enable = 0
607-
if (p.className == "BufPool" or p.className == "ZombieBufPool"):
608-
pool_children = p.children
609-
if pool_children== 0:
610-
slave_enable = 4
611-
else:
612-
for pchild in pool_children:
613-
if not(pchild.className == "ZombieFunction") and not(pchild.className == "Function"):
614-
slave_enable = 4
615-
else:
616-
slave_enable = 0
617-
break
618-
if (p.parent.className != "Enz" and p.parent.className !='ZombieEnz'):
619-
#Assuming "p.parent.className !=Enzyme is cplx which is not written to genesis"
620-
621-
# x = sceneitems[p]['x']
622-
# y = sceneitems[p]['y']
623-
# if sceneitems != None:
624-
# value = sceneitems[p]
625-
# x = calPrime(value['x'])
626-
# y = calPrime(value['y'])
627-
628-
pinfo = p.path+'/info'
629-
if moose.exists(pinfo):
630-
x = sceneitems[p]['x']
631-
y = sceneitems[p]['y']
632-
else:
633-
x = 0
634-
y = 0
635-
error = error + " \n x and y co-ordinates are not specified for `" + p.name+ "` zero will be assigned"+ " \n "
636-
637-
if moose.exists(pinfo):
638-
color = moose.Annotator(pinfo).getField('color')
639-
color = getColorCheck(color,GENESIS_COLOR_SEQUENCE)
640-
textcolor = moose.Annotator(pinfo).getField('textColor')
641-
textcolor = getColorCheck(textcolor,GENESIS_COLOR_SEQUENCE)
642-
poolsCmpt = findCompartment(p)
643-
geometryName = volIndex[float(poolsCmpt.volume)]
644-
volume = p.volume * NA * 1e-3
645-
if color == "" or color == " ":
646-
color = getRandColor()
647-
if textcolor == "" or textcolor == " ":
648-
textcolor = getRandColor()
649-
f.write("simundump kpool /kinetics/" + trimPath(p) + " 0 " +
650-
str(p.diffConst) + " " +
651-
str(0) + " " +
652-
str(0) + " " +
653-
str(0) + " " +
654-
str(p.nInit) + " " +
655-
str(0) + " " + str(0) + " " +
656-
str(volume)+ " " +
657-
str(slave_enable) +
658-
" /kinetics"+ geometryName + " " +
659-
str(color) +" " + str(textcolor) + " " + str(int(x)) + " " + str(int(y)) + " "+ str(0)+"\n")
588+
if findCompartment(p) == moose.element('/'):
589+
error = error + " \n "+p.path+ " doesn't have compartment ignored to write to genesis"
590+
else:
591+
slave_enable = 0
592+
if (p.className == "BufPool" or p.className == "ZombieBufPool"):
593+
pool_children = p.children
594+
if pool_children== 0:
595+
slave_enable = 4
596+
else:
597+
for pchild in pool_children:
598+
if not(pchild.className == "ZombieFunction") and not(pchild.className == "Function"):
599+
slave_enable = 4
600+
else:
601+
slave_enable = 0
602+
break
603+
if (p.parent.className != "Enz" and p.parent.className !='ZombieEnz'):
604+
#Assuming "p.parent.className !=Enzyme is cplx which is not written to genesis"
605+
606+
# x = sceneitems[p]['x']
607+
# y = sceneitems[p]['y']
608+
# if sceneitems != None:
609+
# value = sceneitems[p]
610+
# x = calPrime(value['x'])
611+
# y = calPrime(value['y'])
612+
613+
pinfo = p.path+'/info'
614+
if moose.exists(pinfo):
615+
x = sceneitems[p]['x']
616+
y = sceneitems[p]['y']
617+
else:
618+
x = 0
619+
y = 0
620+
error = error + " \n x and y co-ordinates are not specified for `" + p.name+ "` zero will be assigned"+ " \n "
621+
622+
if moose.exists(pinfo):
623+
color = moose.Annotator(pinfo).getField('color')
624+
color = getColorCheck(color,GENESIS_COLOR_SEQUENCE)
625+
textcolor = moose.Annotator(pinfo).getField('textColor')
626+
textcolor = getColorCheck(textcolor,GENESIS_COLOR_SEQUENCE)
627+
poolsCmpt = findCompartment(p)
628+
geometryName = volIndex[float(poolsCmpt.volume)]
629+
volume = p.volume * NA * 1e-3
630+
if color == "" or color == " ":
631+
color = getRandColor()
632+
if textcolor == "" or textcolor == " ":
633+
textcolor = getRandColor()
634+
f.write("simundump kpool /kinetics/" + trimPath(p) + " 0 " +
635+
str(p.diffConst) + " " +
636+
str(0) + " " +
637+
str(0) + " " +
638+
str(0) + " " +
639+
str(p.nInit) + " " +
640+
str(0) + " " + str(0) + " " +
641+
str(volume)+ " " +
642+
str(slave_enable) +
643+
" /kinetics"+ geometryName + " " +
644+
str(color) +" " + str(textcolor) + " " + str(int(x)) + " " + str(int(y)) + " "+ str(0)+"\n")
660645
return error
661646

662647
def getColorCheck(color,GENESIS_COLOR_SEQUENCE):

0 commit comments

Comments
 (0)