1313** copyright (C) 2003-2017 Upinder S. Bhalla. and NCBS
1414Created : Friday May 27 12:19:00 2016(+0530)
1515Version
16- Last-Updated: Thr 18 July 15 :15:10 2019 (+0530)
16+ Last-Updated: Wed 8 Jan 14 :15:10 2020 (+0530)
1717 By: HarshaRani
1818**********************************************************************/
1919/****************************
20+ 2020
21+ Jan 08: added function to write Concchannel in form of MMenz
22+ Km in the kinetic law for MMenz is written to the power based on the number of substrate
20232019
2124July 18: added a call for autolayout, this was required for cspace model while trying to write from cmd line
2225 while writting file, the filepath is checked
@@ -164,15 +167,17 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
164167 if modelAnno :
165168 cremodel_ .setAnnotation (modelAnno )
166169 groupInfo = {}
170+ reacGroup = {}
167171 compterrors = ""
168172 compartexist , groupInfo ,compterrors = writeCompt (modelpath , cremodel_ )
169173
170174 if compartexist == True :
171175 species = writeSpecies ( modelpath ,cremodel_ ,sbmlDoc ,sceneitems ,groupInfo )
172176 if species :
173177 writeFunc (modelpath , cremodel_ )
174- reacGroup = {}
175178
179+ writeChannel (modelpath ,cremodel_ ,sceneitems ,groupInfo )
180+
176181 writeReac (modelpath , cremodel_ , sceneitems ,groupInfo )
177182
178183 writeEnz (modelpath , cremodel_ , sceneitems ,groupInfo )
@@ -245,7 +250,102 @@ def mooseWriteSBML(modelpath, filename, sceneitems={}):
245250 return False , compterrors
246251 else :
247252 return False ,"Atleast one compartment should exist to write SBML"
248-
253+
254+ def writeChannel (modelpath , cremodel_ , sceneitems ,groupInfo ):
255+ for chan in moose .wildcardFind (modelpath + '/##[0][ISA=ConcChan]' ):
256+ chanannoexist = False
257+ chanGpnCorCol = " "
258+ cleanChanname = convertSpecialChar (chan .name )
259+ compt = ""
260+ notesE = ""
261+ groupName = moose .element ("/" )
262+
263+ if moose .exists (chan .path + '/info' ):
264+ Anno = moose .Annotator (chan .path + '/info' )
265+ notesE = Anno .notes
266+ element = moose .element (chan )
267+ ele = getGroupinfo (element )
268+ ele = findGroup_compt (element )
269+ chanAnno = " "
270+ if ele .className == "Neutral" or sceneitems or Anno .x or Anno .y :
271+ chanannoexist = True
272+ if chanannoexist :
273+ chanAnno = "<moose:ModelAnnotation>\n "
274+ if ele .className == "Neutral" :
275+ groupName = ele
276+ if sceneitems :
277+ #Saved from GUI, then scene co-ordinates are passed
278+ chanGpnCorCol = chanGpnCorCol + "<moose:xCord>" + \
279+ str (sceneitems [chan ]['x' ]) + "</moose:xCord>\n " + \
280+ "<moose:yCord>" + \
281+ str (sceneitems [chan ]['y' ])+ "</moose:yCord>\n "
282+ else :
283+ #Saved from cmdline,genesis coordinates are kept as its
284+ # SBML, cspace, python, then auto-coordinates are done
285+ #and coordinates are updated in moose Annotation field
286+ chanGpnCorCol = chanGpnCorCol + "<moose:xCord>" + \
287+ str (Anno .x ) + "</moose:xCord>\n " + \
288+ "<moose:yCord>" + \
289+ str (Anno .y )+ "</moose:yCord>\n "
290+ chanGpnCorCol = chanGpnCorCol + "<moose:Permeability>" + str (chan .permeability )+ "</moose:Permeability>\n "
291+ chanSub = chan .neighbors ["in" ]
292+ chanPrd = chan .neighbors ["out" ]
293+ if (len (chanSub ) != 0 and len (chanPrd ) != 0 ):
294+ chanCompt = findCompartment (chan )
295+ if not isinstance (moose .element (chanCompt ), moose .ChemCompt ):
296+ return - 2
297+ else :
298+ compt = chanCompt .name + "_" + \
299+ str (chanCompt .getId ().value ) + "_" + \
300+ str (chanCompt .getDataIndex ()) + "_"
301+
302+ channel = cremodel_ .createReaction ()
303+ if notesE != "" :
304+ cleanNotesE = convertNotesSpecialChar (notesE )
305+ notesStringE = "<body xmlns=\" http://www.w3.org/1999/xhtml\" >\n \t \t " + \
306+ cleanNotesE + "\n \t </body>"
307+ channel .setNotes (notesStringE )
308+
309+ chansetId = str (idBeginWith (cleanChanname +
310+ "_" +
311+ str (chan .getId ().value ) +
312+ "_" +
313+ str (chan .getDataIndex ()) +
314+ "_" ))
315+ channel .setId (chansetId )
316+
317+ if groupName != moose .element ('/' ):
318+ if groupName not in groupInfo :
319+ groupInfo [groupName ]= [chansetId ]
320+ else :
321+ groupInfo [groupName ].append (chansetId )
322+
323+ channel .setName (str (idBeginWith (convertSpecialCharshot (chan .name ))))
324+ channel .setReversible (True )
325+ channel .setFast (False )
326+ if chanannoexist :
327+ canAnno = chanAnno + chanGpnCorCol
328+ chanAnno = "<moose:ConcChannel>\n " + \
329+ chanGpnCorCol + "</moose:ConcChannel>"
330+ channel .setAnnotation (chanAnno )
331+ noofSub , sRateLawS = getSubprd (cremodel_ , False , "sub" , chanSub )
332+ # Modifier
333+ chanMod = chan .neighbors ["setNumChan" ]
334+ noofMod , sRateLawM = getSubprd (cremodel_ , False , "enz" , chanMod )
335+
336+ noofPrd , sRateLawP = getSubprd (cremodel_ , False , "prd" , chanPrd )
337+
338+ kl = channel .createKineticLaw ()
339+
340+ fRate_law = compt + " * ( Permeability) * " + sRateLawM + " * (" + sRateLawS + " - " + sRateLawP + ")"
341+ kl .setFormula (fRate_law )
342+ kl .setNotes (
343+ "<body xmlns=\" http://www.w3.org/1999/xhtml\" >\n \t \t " +
344+ fRate_law +
345+ "\n \t </body>" )
346+
347+ channelUnit = permeablUnit (cremodel_ )
348+ printParameters (kl , "Permeability" , chan .permeability , channelUnit )
249349def writeEnz (modelpath , cremodel_ , sceneitems ,groupInfo ):
250350 for enz in moose .wildcardFind (modelpath + '/##[0][ISA=EnzBase]' ):
251351 enzannoexist = False
@@ -535,8 +635,14 @@ def writeEnz(modelpath, cremodel_, sceneitems,groupInfo):
535635 enzPrd = enz .neighbors ["prd" ]
536636 noofPrd , sRateLawP = getSubprd (cremodel_ , False , "prd" , enzPrd )
537637 kl = enzyme .createKineticLaw ()
538- fRate_law = compt + " * ( kcat * " + sRateLawS + " * " + sRateLawM + \
539- " / ( Km" + " + " + sRateLawS + "))"
638+ #rate_law = clean_name + "^" + str(count)
639+ fRate_law = compt + " * ( kcat * " + sRateLawS + " * " + sRateLawM + "/(Km"
640+
641+ if len (enzSub ) > 1 :
642+ fRate_law = fRate_law + "^" + str (len (enzSub ))
643+ print ("enzyme " ,enzyme .name , "number of substrate is greater than 1, kinetics Law Km is written to the power of substrate assumed that km value is factored" )
644+ fRate_law = fRate_law + " + " + sRateLawS + "))"
645+
540646 kl .setFormula (fRate_law )
541647 kl .setNotes (
542648 "<body xmlns=\" http://www.w3.org/1999/xhtml\" >\n \t \t " +
@@ -554,6 +660,38 @@ def printParameters(kl, k, kvalue, unit):
554660 para .setValue (kvalue )
555661 para .setUnits (unit )
556662
663+ def permeablUnit (cremodel_ ):
664+ unit_stream = "litre_per_mmole_per_second"
665+ lud = cremodel_ .getListOfUnitDefinitions ()
666+ flag = False
667+ for i in range (0 , len (lud )):
668+ ud = lud .get (i )
669+ if (ud .getId () == unit_stream ):
670+ flag = True
671+ break
672+ if (not flag ):
673+ unitdef = cremodel_ .createUnitDefinition ()
674+ unitdef .setId (unit_stream )
675+
676+ unit = unitdef .createUnit ()
677+ unit .setKind (UNIT_KIND_LITRE )
678+ unit .setExponent (1 )
679+ unit .setMultiplier (1 )
680+ unit .setScale (0 )
681+
682+ unit = unitdef .createUnit ()
683+ unit .setKind (UNIT_KIND_MOLE )
684+ unit .setExponent (- 1 )
685+ unit .setMultiplier (1 )
686+ unit .setScale (- 3 )
687+
688+ unit = unitdef .createUnit ()
689+ unit .setKind (UNIT_KIND_SECOND )
690+ unit .setExponent (- 1 )
691+ unit .setMultiplier (1 )
692+ unit .setScale (0 )
693+ return unit_stream
694+
557695def KmUnit (cremodel_ ):
558696 unit_stream = "mmole_per_litre"
559697 lud = cremodel_ .getListOfUnitDefinitions ()
@@ -647,7 +785,7 @@ def getSubprd(cremodel_, mobjEnz, type, neighborslist):
647785 rate_law = processRateLaw (
648786 reacPrdCou , cremodel_ , noofPrd , "prd" , mobjEnz )
649787 return len (reacPrd ), rate_law
650- elif type == "enz" :
788+ elif type == "enz" or type == "chan" :
651789 enzModifier = neighborslist
652790 enzModCou = Counter (enzModifier )
653791 noofMod = len (enzModCou )
0 commit comments