13
13
** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS
14
14
Created : Friday May 27 12:19:00 2016(+0530)
15
15
Version
16
- Last-Updated: Tue 29 Jan 15:15:10 2019(+0530)
16
+ Last-Updated: Thr 18 July 15:15:10 2019(+0530)
17
17
By: HarshaRani
18
18
**********************************************************************/
19
19
/****************************
20
20
2019
21
+ July 18: added a call for autolayout, this was required for cspace model while trying to write from cmd line
22
+ while writting file, the filepath is checked
23
+ now even for cplxpool's x and y co-ordinates,diff and motor constant are added
21
24
Jan 29: getColor are taken from chemConnectUtil, group's width and height are written
22
25
2018
23
26
Dec 07: using fixXreac's restoreXreacs function to remove xfer
49
52
import os
50
53
import moose
51
54
from moose .SBML .validation import validateModel
52
- from moose .chemUtil .chemConnectUtil import xyPosition ,mooseIsInstance ,findCompartment ,getColor ,setupItem
55
+ from moose .chemUtil .chemConnectUtil import xyPosition ,mooseIsInstance ,findCompartment ,getColor ,setupItem , setupMeshObj
53
56
from moose .chemUtil .graphUtils import *
54
57
from moose .fixXreacs import restoreXreacs
55
58
import numpy as np
61
64
except Exception as e :
62
65
pass
63
66
67
+ def checkPath ( dirName ):
68
+ path = dirName
69
+ if (dirName == "~" or not dirName ):
70
+ if dirName :
71
+ dirName = os .path .expanduser (dirName )
72
+ else :
73
+ dirName = os .getcwd ()
74
+
75
+ if os .access (dirName , os .W_OK ) is not True :
76
+ dirName = os .getcwd ()
77
+ print (path + " not writable, writting to " + dirName + " directory" )
78
+ return dirName
79
+ else :
80
+ return dirName
81
+
64
82
def mooseWriteSBML (modelpath , filename , sceneitems = {}):
65
83
global foundLibSBML_
66
84
msg = " "
@@ -74,6 +92,7 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
74
92
75
93
#sbmlDoc = SBMLDocument(3, 1)
76
94
filepath , filenameExt = os .path .split (filename )
95
+ filepath = checkPath (filepath )
77
96
if filenameExt .find ('.' ) != - 1 :
78
97
filename = filenameExt [:filenameExt .find ('.' )]
79
98
else :
@@ -188,13 +207,14 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
188
207
189
208
if moose .exists (key .path + '/info' ):
190
209
ginfo = moose .element (key .path + '/info' )
210
+ textColor ,color = getColor (ginfo )
191
211
if ginfo .height and ginfo .width :
192
212
grpAnno = grpAnno + "<moose:x>" + str (ginfo .x ) + "</moose:x>\n "
193
213
grpAnno = grpAnno + "<moose:y>" + str (ginfo .y ) + "</moose:y>\n "
194
214
grpAnno = grpAnno + "<moose:width>" + str (ginfo .width ) + "</moose:width>\n "
195
215
grpAnno = grpAnno + "<moose:height>" + str (ginfo .height ) + "</moose:height>\n "
196
216
if ginfo .color :
197
- grpAnno = grpAnno + "<moose:bgColor>" + ginfo . color + "</moose:bgColor>\n "
217
+ grpAnno = grpAnno + "<moose:bgColor>" + color + "</moose:bgColor>\n "
198
218
if ginfo .notes :
199
219
grpAnno = grpAnno + "<moose:Notes>" + ginfo .notes + "</moose:Notes>\n "
200
220
grpAnno = grpAnno + "</moose:GroupAnnotation>"
@@ -207,11 +227,16 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
207
227
consistencyMessages = ""
208
228
SBMLok = validateModel (sbmlDoc )
209
229
if (SBMLok ):
210
- writeTofile = filepath + "/" + filename + '.xml'
230
+ if filepath != [" " ,"\/" ,"/" ]:
231
+ writeTofile = filepath + "/" + filename + '.xml'
232
+ else :
233
+ writeTofile = filename + '.xml'
234
+
235
+ #writeTofile = filepath + "/" + filename + '.xml'
211
236
writeSBMLToFile (sbmlDoc , writeTofile )
212
237
return True , consistencyMessages , writeTofile
213
238
214
- if ( not SBMLok ) :
239
+ else :
215
240
#cerr << "Errors encountered " << endl
216
241
consistencyMessages = "Errors encountered"
217
242
return - 1 , consistencyMessages
@@ -952,6 +977,14 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
952
977
if spename .find (
953
978
"cplx" ) != - 1 and isinstance (moose .element (spe .parent ), moose .EnzBase ):
954
979
enz = spe .parent
980
+ if not moose .exists (spe .path + '/info' ):
981
+ cplxinfo = moose .Annotator (spe .path + '/info' )
982
+ enzpath = moose .element (spe .parent .path + '/info' )
983
+
984
+ cplxinfo .x = moose .element (moose .element (spe .parent .path + '/info' ).x )
985
+
986
+ cplxinfo .y = int ((moose .element (spe .parent .path + '/info' ).y ))+ 10
987
+
955
988
if (moose .element (enz .parent ), moose .PoolBase ):
956
989
# print " found a cplx name ",spe.parent,
957
990
# moose.element(spe.parent).parent
@@ -1038,6 +1071,13 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
1038
1071
speciAnno = speciAnno + "<moose:motorConstant>" + str (spe .motorConst )+ "</moose:motorConstant>\n "
1039
1072
speciAnno = speciAnno + "</moose:ModelAnnotation>"
1040
1073
s1 .setAnnotation (speciAnno )
1074
+ else :
1075
+ #E.g cplx doesn't have info field but findsim layout expecting diffConstant and motorConstant.
1076
+ speciAnno = "<moose:ModelAnnotation>\n "
1077
+ speciAnno = speciAnno + "<moose:diffConstant>" + str (0.0 ) + "</moose:diffConstant>\n "
1078
+ speciAnno = speciAnno + "<moose:motorConstant>" + str (0.0 )+ "</moose:motorConstant>\n "
1079
+ speciAnno = speciAnno + "</moose:ModelAnnotation>"
1080
+ s1 .setAnnotation (speciAnno )
1041
1081
return True
1042
1082
1043
1083
@@ -1205,6 +1245,11 @@ def recalculatecoordinates(modelpath, mObjlist,xcord,ycord):
1205
1245
else :
1206
1246
srcdesConnection = {}
1207
1247
setupItem (modelpath ,srcdesConnection )
1248
+ meshEntry ,xmin ,xmax ,ymin ,ymax ,positionInfoExist ,sceneitems = setupMeshObj (modelpath )
1249
+ if not positionInfoExist :
1250
+ sceneitems = autoCoordinates (meshEntry ,srcdesConnection )
1251
+ sceneitems = autoCoordinates (meshEntry ,srcdesConnection )
1252
+
1208
1253
#print srcdesConnection
1209
1254
'''
1210
1255
#meshEntry,xmin,xmax,ymin,ymax,positionInfoExist,sceneitems = setupMeshObj(modelpath)
0 commit comments