1212#** copyright (C) 2003-2016 Upinder S. Bhalla. and NCBS
1313#Created : Friday June 13 12:19:00 2016(+0530)
1414#Version
15- #Last-Updated:Tuesday June 21 12.22 .37
16- # By:
15+ #Last-Updated:Tuesday June 21 17.48 .37
16+ # By: Harsha
1717#**********************************************************************/
1818
1919# This program is used to merge models
4040# and warn the user the same reaction name with different sub or product
4141# -- No
4242# copy the reaction
43+
4344import sys
4445from . import _moose as moose
4546
@@ -50,7 +51,6 @@ def merge(A,B):
5051
5152 comptAdict = comptList (apath )
5253 comptBdict = comptList (bpath )
53-
5454
5555 for key in comptBdict .keys ():
5656
@@ -69,8 +69,8 @@ def merge(A,B):
6969 #Merging Pool
7070 poolName_a = []
7171 poolListina = moose .wildcardFind (comptAdict [key ].path + '/##[ISA=PoolBase]' )
72-
73- neutral_compartment = findgroup_compartment (poolListina [0 ])
72+ if poolListina :
73+ neutral_compartment = findgroup_compartment (poolListina [0 ])
7474 for pl in poolListina :
7575 poolName_a .append (pl .name )
7676
@@ -86,10 +86,37 @@ def merge(A,B):
8686 else :
8787 print " Check this pool, parent which doesn't have ChemCompt or Enz" ,
8888
89+ #Mergering StimulusTable
90+ stimName_a = []
91+ stimListina = moose .wildcardFind (comptAdict [key ].path + '/##[ISA=StimulusTable]' )
92+ if stimListina :
93+ neutral_compartment = findgroup_compartment (stimListina [0 ])
94+ for st in stimListina :
95+ stimName_a .append (st .name )
96+ for stb in moose .wildcardFind (comptBdict [key ].path + '/##[ISA=StimulusTable]' ):
97+ if stb .name in stimName_a :
98+ sA = comptAdict [key ].path + '/' + stb .name
99+ sB = comptBdict [key ].path + '/' + stb .name
100+ stAOutput = subprdList (sA ,"output" )
101+ stBOutput = subprdList (sB ,"output" )
102+ sas = set (stAOutput )
103+ sbs = set (stBOutput )
104+ uniq = (sas .union (sbs ) - sas .intersection (sbs ))
105+ for u in uniq :
106+ if u not in stAOutput :
107+ src = moose .element (sA )
108+ des = moose .element (comptAdict [key ].path + '/' + u )
109+ moose .connect (src ,'output' ,des ,'setConcInit' )
110+ else :
111+ st1 = moose .StimulusTable (comptAdict [key ].path + '/' + stb .name )
112+ for sb in sbs :
113+ des = moose .element (comptAdict [key ].path + '/' + sb )
114+ moose .connect (st1 ,'output' ,des ,'setConcInit' )
89115 #Mergering Reaction
90116 reacName_a = []
91117 reacListina = moose .wildcardFind (comptAdict [key ].path + '/##[ISA=ReacBase]' )
92- neutral_compartment = findgroup_compartment (poolListina [0 ])
118+ if reacListina :
119+ neutral_compartment = findgroup_compartment (poolListina [0 ])
93120
94121 for re in reacListina :
95122 reacName_a .append (re .name )
@@ -109,20 +136,23 @@ def merge(A,B):
109136 bS = set (rBsubname )
110137 aP = set (rAprdname )
111138 bP = set (rBprdname )
112- hasSameSub = True
113- hasSamePrd = True
114- if len (aS .union (bS ) - aS .intersection (bS )):
115- hasSameSub = False
116-
117- if len (aP .union (bP ) - aP .intersection (bP )):
118- hasSamePrd = False
119-
120- if not all ((hasSameSub ,hasSamePrd )):
139+
140+ hasSameSub ,hasSamePrd = True ,True
141+ hassameSlen ,hassamePlen = False ,False
142+
143+ hasSameSub = not (len (aS .union (bS ) - aS .intersection (bS )))
144+ hasSamePrd = not (len (aP .union (bP ) - aP .intersection (bP )))
145+
146+ hassameSlen = ( len (rAsubname ) == len (rBsubname ))
147+ hassamePlen = ( len (rAprdname ) == len (rBprdname ))
148+
149+
150+ if not all ((hasSameSub ,hasSamePrd ,hassameSlen ,hassamePlen )):
121151 war_msg = war_msg + "Reaction \" " + reac .name + "\" also contains in modelA but with different"
122- if not hasSameSub :
152+ if not all (( hasSameSub , hassameSlen )) :
123153 war_msg = war_msg + " substrate "
124154
125- if not hasSamePrd :
155+ if not all (( hasSamePrd , hassamePlen )) :
126156 war_msg = war_msg + " product"
127157 war_msg = war_msg + ", reaction is duplicated in modelA. \n Modeler should decide to keep or remove this reaction"
128158
@@ -143,7 +173,9 @@ def merge(A,B):
143173 rBprdname = subprdList (reac ,"prd" )
144174 mooseConnect (comptAdict [key ].path ,reac ,rBsubname ,"sub" )
145175 mooseConnect (comptAdict [key ].path ,reac ,rBprdname ,"prd" )
146- print "c " , copied , "\n warning " ,war_msg , "\n Duplicated " ,duplicated
176+ print "\n copied: " , copied , \
177+ "\n \n Duplicated: " ,duplicated , \
178+ "\n \n warning: " ,war_msg
147179 return copied ,duplicated ,war_msg
148180def loadModels (filename ):
149181 apath = '/'
@@ -187,24 +219,6 @@ def subprdList(reac,subprd):
187219 for rs in rtype :
188220 rname .append (rs .name )
189221 return rname
190- def mergeAtoB (a ,b ):
191-
192- ca = moose .wildcardFind (m1path + '/##[ISA=PoolBase]' )
193- cb = moose .wildcardFind (m2path + '/##[ISA=PoolBase]' )
194-
195- cca = {}
196- ccb = {}
197- for c in ca :
198- cca [c .name ] = c
199- for c in cb :
200- ccb [c .name ] = c
201- avalue = cca .keys ()
202- bvalue = ccb .keys ()
203- #print cca,ccb
204- print " bvalue " ,len (bvalue ), " avalue " ,len (avalue )
205- myset = list (set (cca .keys ()).union (set (ccb .keys ())))
206- print " insder " ,myset , len (myset )
207- return model1
208222
209223def findCompartment (element ):
210224 while not mooseIsInstance (element ,["CubeMesh" ,"CyclMesh" ]):
0 commit comments