1313** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS
1414Created : Friday May 27 12:19:00 2016(+0530)
1515Version
16- Last-Updated: Tue 29 Jan 15:15:10 2019(+0530)
16+ Last-Updated: Thr 18 July 15:15:10 2019(+0530)
1717 By: HarshaRani
1818**********************************************************************/
1919/****************************
20202019
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
2124Jan 29: getColor are taken from chemConnectUtil, group's width and height are written
22252018
2326Dec 07: using fixXreac's restoreXreacs function to remove xfer
4952import os
5053import moose
5154from 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
5356from moose .chemUtil .graphUtils import *
5457from moose .fixXreacs import restoreXreacs
5558import numpy as np
6164except Exception as e :
6265 pass
6366
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+
6482def mooseWriteSBML (modelpath , filename , sceneitems = {}):
6583 global foundLibSBML_
6684 msg = " "
@@ -74,6 +92,7 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
7492
7593 #sbmlDoc = SBMLDocument(3, 1)
7694 filepath , filenameExt = os .path .split (filename )
95+ filepath = checkPath (filepath )
7796 if filenameExt .find ('.' ) != - 1 :
7897 filename = filenameExt [:filenameExt .find ('.' )]
7998 else :
@@ -188,13 +207,14 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
188207
189208 if moose .exists (key .path + '/info' ):
190209 ginfo = moose .element (key .path + '/info' )
210+ textColor ,color = getColor (ginfo )
191211 if ginfo .height and ginfo .width :
192212 grpAnno = grpAnno + "<moose:x>" + str (ginfo .x ) + "</moose:x>\n "
193213 grpAnno = grpAnno + "<moose:y>" + str (ginfo .y ) + "</moose:y>\n "
194214 grpAnno = grpAnno + "<moose:width>" + str (ginfo .width ) + "</moose:width>\n "
195215 grpAnno = grpAnno + "<moose:height>" + str (ginfo .height ) + "</moose:height>\n "
196216 if ginfo .color :
197- grpAnno = grpAnno + "<moose:bgColor>" + ginfo . color + "</moose:bgColor>\n "
217+ grpAnno = grpAnno + "<moose:bgColor>" + color + "</moose:bgColor>\n "
198218 if ginfo .notes :
199219 grpAnno = grpAnno + "<moose:Notes>" + ginfo .notes + "</moose:Notes>\n "
200220 grpAnno = grpAnno + "</moose:GroupAnnotation>"
@@ -207,11 +227,16 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
207227 consistencyMessages = ""
208228 SBMLok = validateModel (sbmlDoc )
209229 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'
211236 writeSBMLToFile (sbmlDoc , writeTofile )
212237 return True , consistencyMessages , writeTofile
213238
214- if ( not SBMLok ) :
239+ else :
215240 #cerr << "Errors encountered " << endl
216241 consistencyMessages = "Errors encountered"
217242 return - 1 , consistencyMessages
@@ -952,6 +977,14 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
952977 if spename .find (
953978 "cplx" ) != - 1 and isinstance (moose .element (spe .parent ), moose .EnzBase ):
954979 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+
955988 if (moose .element (enz .parent ), moose .PoolBase ):
956989 # print " found a cplx name ",spe.parent,
957990 # moose.element(spe.parent).parent
@@ -1038,6 +1071,13 @@ def writeSpecies(modelpath, cremodel_, sbmlDoc, sceneitems,speGroup):
10381071 speciAnno = speciAnno + "<moose:motorConstant>" + str (spe .motorConst )+ "</moose:motorConstant>\n "
10391072 speciAnno = speciAnno + "</moose:ModelAnnotation>"
10401073 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 )
10411081 return True
10421082
10431083
@@ -1205,6 +1245,11 @@ def recalculatecoordinates(modelpath, mObjlist,xcord,ycord):
12051245 else :
12061246 srcdesConnection = {}
12071247 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+
12081253 #print srcdesConnection
12091254 '''
12101255 #meshEntry,xmin,xmax,ymin,ymax,positionInfoExist,sceneitems = setupMeshObj(modelpath)
0 commit comments