def writeReac(modelpath, f): reacList = wildcardFind(modelpath + '/##[ISA=ReacBase]') for reac in reacList: color = "blue" textcolor = "red" kf = reac.numKf kb = reac.numKb xr = cord[reac]['x'] yr = cord[reac]['y'] x = ((xr - xmin) / (xmax - xmin)) * multi y = ((yr - ymin) / (ymax - ymin)) * multi #y = ((ymax-yr)/(ymax-ymin))*multi rinfo = reac.path + '/info' if exists(rinfo): color = Annotator(rinfo).getField('color') color = getColorCheck(color, GENESIS_COLOR_SEQUENCE) textcolor = Annotator(rinfo).getField('textColor') textcolor = getColorCheck(textcolor, GENESIS_COLOR_SEQUENCE) f.write("simundump kreac /kinetics/" + trimPath(reac) + " " + str(0) + " " + str(kf) + " " + str(kb) + " \"\" " + str(color) + " " + str(textcolor) + " " + str(int(x)) + " " + str(int(y)) + " 0\n") return reacList
def writeEnz(modelpath, f): enzList = wildcardFind(modelpath + '/##[ISA=EnzBase]') for enz in enzList: x = random.randrange(0, 10) y = random.randrange(0, 10) textcolor = "green" color = "red" k1 = 0 k2 = 0 k3 = 0 nInit = 0 concInit = 0 n = 0 conc = 0 enzParent = enz.parent if (isinstance(enzParent.className, Pool)) or (isinstance( enzParent.className, ZombiePool)): print(" raise exception enz doesn't have pool as parent") return False else: vol = enzParent.volume * NA * 1e-3 isMichaelisMenten = 0 enzClass = enz.className if (enzClass == "ZombieMMenz" or enzClass == "MMenz"): k1 = enz.numKm k3 = enz.kcat k2 = 4.0 * k3 k1 = (k2 + k3) / k1 isMichaelisMenten = 1 elif (enzClass == "ZombieEnz" or enzClass == "Enz"): k1 = enz.k1 k2 = enz.k2 k3 = enz.k3 cplx = enz.neighbors['cplx'][0] nInit = cplx.nInit[0] xe = cord[enz]['x'] ye = cord[enz]['y'] x = ((xe - xmin) / (xmax - xmin)) * multi y = ((ye - ymin) / (ymax - ymin)) * multi #y = ((ymax-ye)/(ymax-ymin))*multi einfo = enz.path + '/info' if exists(einfo): color = Annotator(einfo).getField('color') color = getColorCheck(color, GENESIS_COLOR_SEQUENCE) textcolor = Annotator(einfo).getField('textColor') textcolor = getColorCheck(textcolor, GENESIS_COLOR_SEQUENCE) f.write("simundump kenz /kinetics/" + trimPath(enz) + " " + str(0) + " " + str(concInit) + " " + str(conc) + " " + str(nInit) + " " + str(n) + " " + str(vol) + " " + str(k1) + " " + str(k2) + " " + str(k3) + " " + str(0) + " " + str(isMichaelisMenten) + " " + "\"\"" + " " + str(color) + " " + str(textcolor) + " \"\"" + " " + str(int(x)) + " " + str(int(y)) + " " + str(0) + "\n") return enzList
def writeplot(tgraphs, f): if tgraphs: for graphs in tgraphs: slash = graphs.path.find('graphs') if not slash > -1: slash = graphs.path.find('graph_0') if slash > -1: conc = graphs.path.find('conc') if conc > -1: tabPath = "/" + graphs.path[slash:len(graphs.path)] else: slash1 = graphs.path.find('/', slash) tabPath = "/graphs/conc1" + graphs.path[slash1:len(graphs. path)] if len(element(graphs).msgOut): poolPath = (element(graphs).msgOut)[0].e2.path poolEle = element(poolPath) poolAnno = (poolEle.path + '/info') fg = Annotator(poolAnno).textColor fg = getColorCheck(fg, GENESIS_COLOR_SEQUENCE) tabPath = re.sub("\[[0-9]+\]", "", tabPath) f.write("simundump xplot " + tabPath + " 3 524288 \\\n" + "\"delete_plot.w <s> <d>; edit_plot.D <w>\" " + fg + " 0 0 1\n")
def storePlotMsgs(tgraphs, f): s = "" if tgraphs: for graph in tgraphs: slash = graph.path.find('graphs') if not slash > -1: slash = graph.path.find('graph_0') if slash > -1: conc = graph.path.find('conc') if conc > -1: tabPath = graph.path[slash:len(graph.path)] else: slash1 = graph.path.find('/', slash) tabPath = "/graphs/conc1" + graph.path[slash1:len(graph. path)] if len(element(graph).msgOut): poolPath = (element(graph).msgOut)[0].e2.path poolEle = element(poolPath) poolName = poolEle.name bgPath = (poolEle.path + '/info') bg = Annotator(bgPath).color bg = getColorCheck(bg, GENESIS_COLOR_SEQUENCE) tabPath = re.sub("\[[0-9]+\]", "", tabPath) s = s+"addmsg /kinetics/" + trimPath( poolEle ) + " " + tabPath + \ " PLOT Co *" + poolName + " *" + bg +"\n" f.write(s)
def getColor(iteminfo): """ Getting a textcolor and background color for the given mooseObject \ If textcolor is empty replaced with green \ background color is empty replaced with blue if textcolor and background is same as it happend in kkit files \ replacing textcolor with random color\ The colors are not valid there are siliently replaced with some values \ but while model building can raise an exception """ textcolor = Annotator(iteminfo).getField('textColor') bgcolor = Annotator(iteminfo).getField('color') if (textcolor == ''): textcolor = 'green' if (bgcolor == ''): bgcolor = 'blue' if (textcolor == bgcolor): textcolor = getRandColor() textcolor = colorCheck(textcolor, "fc") bgcolor = colorCheck(bgcolor, "bg") return (textcolor, bgcolor)
def writeNotes(modelpath, f): notes = "" items = [] items = wildcardFind(modelpath+"/##[ISA=ChemCompt]") +\ wildcardFind(modelpath+"/##[ISA=PoolBase]") +\ wildcardFind(modelpath+"/##[ISA=ReacBase]") +\ wildcardFind(modelpath+"/##[ISA=EnzBase]") +\ wildcardFind(modelpath+"/##[ISA=Function]") +\ wildcardFind(modelpath+"/##[ISA=StimulusTable]") for item in items: if exists(item.path + '/info'): info = item.path + '/info' notes = Annotator(info).getField('notes') if (notes): f.write("call /kinetics/" + trimPath(item) + "/notes LOAD \ \n\"" + Annotator(info).getField('notes') + "\"\n")
def writePool(modelpath, f, volIndex): for p in wildcardFind(modelpath + '/##[ISA=PoolBase]'): slave_enable = 0 if (p.className == "BufPool" or p.className == "ZombieBufPool"): pool_children = p.children if pool_children == 0: slave_enable = 4 else: for pchild in pool_children: if not (pchild.className == "ZombieFunction") and not ( pchild.className == "Function"): slave_enable = 4 else: slave_enable = 0 break #Eliminated enzyme complex pool if ((p.parent).className != "Enz" and (p.parent).className != "ZombieEnz"): xp = cord[p]['x'] yp = cord[p]['y'] x = ((xp - xmin) / (xmax - xmin)) * multi y = ((yp - ymin) / (ymax - ymin)) * multi #y = ((ymax-yp)/(ymax-ymin))*multi pinfo = p.path + '/info' if exists(pinfo): color = Annotator(pinfo).getField('color') color = getColorCheck(color, GENESIS_COLOR_SEQUENCE) textcolor = Annotator(pinfo).getField('textColor') textcolor = getColorCheck(textcolor, GENESIS_COLOR_SEQUENCE) geometryName = volIndex[p.volume] volume = p.volume * NA * 1e-3 f.write("simundump kpool /kinetics/" + trimPath(p) + " 0 " + str(p.diffConst) + " " + str(0) + " " + str(0) + " " + str(0) + " " + str(p.nInit) + " " + str(0) + " " + str(0) + " " + str(volume) + " " + str(slave_enable) + " /kinetics" + geometryName + " " + str(color) + " " + str(textcolor) + " " + str(int(x)) + " " + str(int(y)) + " " + str(0) + "\n")
def autoCoordinates(meshEntry, srcdesConnection): G = nx.Graph() for cmpt, memb in meshEntry.items(): if memb in ["enzyme"]: for enzObj in find_index(memb, 'enzyme'): #G.add_node(enzObj.path) G.add_node(enzObj.path, label='', shape='ellipse', color='', style='filled', fontname='Helvetica', fontsize=12, fontcolor='blue') for cmpt, memb in meshEntry.items(): #if memb.has_key if memb in ["pool", "cplx", "reaction"]: for poolObj in find_index(memb, 'pool'): #G.add_node(poolObj.path) G.add_node(poolObj.path, label=poolObj.name, shape='box', color='', style='filled', fontname='Helvetica', fontsize=9, fontcolor='blue') for cplxObj in find_index(memb, 'cplx'): G.add_node(cplxObj.path) G.add_node(cplxObj.path, label=cplxObj.name, shape='box', color='', style='filled', fontname='Helvetica', fontsize=12, fontcolor='blue') #G.add_edge((cplxObj.parent).path,cplxObj.path) for reaObj in find_index(memb, 'reaction'): #G.add_node(reaObj.path) G.add_node(reaObj.path, label='', shape='circle', color='') for inn, out in srcdesConnection.items(): if (inn.className == 'ZombieReac'): arrowcolor = 'green' elif (inn.className == 'ZombieEnz'): arrowcolor = 'red' else: arrowcolor = 'blue' if isinstance(out, tuple): if len(out[0]) == 0: print(inn.className + ':' + inn.name + " doesn't have input message") else: for items in (items for items in out[0]): G.add_edge(element(items[0]).path, inn.path) if len(out[1]) == 0: print(inn.className + ':' + inn.name + "doesn't have output mssg") else: for items in (items for items in out[1]): G.add_edge(inn.path, element(items[0]).path) elif isinstance(out, list): if len(out) == 0: print("Func pool doesn't have sumtotal") else: for items in (items for items in out): G.add_edge(element(items[0]).path, inn.path) position = graphviz_layout(G) xcord, ycord = [], [] for item in position.items(): xy = item[1] xroundoff = round(xy[0], 0) yroundoff = round(xy[1], 0) xcord.append(xroundoff) ycord.append(yroundoff) xmin = min(xcord) xmax = max(xcord) ymin = min(ycord) ymax = max(ycord) for item in position.items(): xy = item[1] anno = Annotator(item[0] + '/info') Ax = (xy[0] - xmin) / (xmax - xmin) Ay = (xy[1] - ymin) / (ymax - ymin) #anno.x = round(Ax,1) #anno.y = round(Ay,1) #not roundingoff to max and min the co-ordinates for bigger model would overlay the co-ordinates anno.x = xy[0] anno.y = xy[1]
def setupMeshObj(modelRoot): ''' Setup compartment and its members pool,reaction,enz cplx under self.meshEntry dictionaries \ self.meshEntry with "key" as compartment, value is key2:list where key2 represents moose object type,list of objects of a perticular type e.g self.meshEntry[meshEnt] = { 'reaction': reaction_list,'enzyme':enzyme_list,'pool':poollist,'cplx': cplxlist } ''' xmin = 0.0 xmax = 1.0 ymin = 0.0 ymax = 1.0 positionInfoExist = True meshEntry = {} if meshEntry: meshEntry.clear() else: meshEntry = {} xcord = [] ycord = [] n = 1 objPar = collections.OrderedDict() for compt in wildcardFind(modelRoot + '/##[ISA=ChemCompt]'): groupColor = [] try: value = meshEntry[element(compt)] except KeyError: # Compt is not present meshEntry[element(compt)] = {} objPar[element(compt)] = element('/') for grp in wildcardFind(compt.path + '/##[TYPE=Neutral]'): test = [ x for x in wildcardFind(element(grp).path + '/#') if x.className in ["Pool", "Reac", "Enz"] ] #if len(test) >1: grpinfo = Annotator(element(grp).path + '/info') validatecolor = colorCheck(grpinfo.color, "bg") validatedgrpcolor = str(QColor(validatecolor).name()) groupColor.append(validatedgrpcolor) grp_cmpt = findGroup_compt(grp.parent) try: value = meshEntry[element(grp)] except KeyError: # Grp is not present meshEntry[element(grp)] = {} objPar[element(grp)] = element(grp_cmpt) # if n > 1: # validatecolor = colorCheck(grpinfo.color,"bg") # validatedgrpcolor = str(QColor(validatecolor).name()) # if validatedgrpcolor in groupColor: # print " inside " # c = getRandColor() # print " c ",c, c.name() # grpinfo.color = str(c.name()) # groupColor.append(str(c.name())) # print " groupColor ",grpinfo,grpinfo.color, groupColor # n =n +1 for compt in wildcardFind(modelRoot + '/##[ISA=ChemCompt]'): for m in wildcardFind(compt.path + '/##[ISA=PoolBase]'): grp_cmpt = findGroup_compt(m) xcord.append(xyPosition(m.path + '/info', 'x')) ycord.append(xyPosition(m.path + '/info', 'y')) if isinstance(element(grp_cmpt), Neutral): if isinstance(element(m.parent), EnzBase): populateMeshEntry(meshEntry, grp_cmpt, "cplx", m) else: populateMeshEntry(meshEntry, grp_cmpt, "pool", m) else: if isinstance(element(m.parent), EnzBase): populateMeshEntry(meshEntry, compt, "cplx", m) else: populateMeshEntry(meshEntry, compt, "pool", m) for r in wildcardFind(compt.path + '/##[ISA=ReacBase]'): rgrp_cmpt = findGroup_compt(r) xcord.append(xyPosition(r.path + '/info', 'x')) ycord.append(xyPosition(r.path + '/info', 'y')) if isinstance(element(rgrp_cmpt), Neutral): populateMeshEntry(meshEntry, rgrp_cmpt, "reaction", r) else: populateMeshEntry(meshEntry, compt, "reaction", r) for e in wildcardFind(compt.path + '/##[ISA=EnzBase]'): egrp_cmpt = findGroup_compt(e) xcord.append(xyPosition(e.path + '/info', 'x')) ycord.append(xyPosition(e.path + '/info', 'y')) if isinstance(element(egrp_cmpt), Neutral): populateMeshEntry(meshEntry, egrp_cmpt, "enzyme", e) else: populateMeshEntry(meshEntry, compt, "enzyme", e) for f in wildcardFind(compt.path + '/##[ISA=Function]'): fgrp_cmpt = findGroup_compt(f) if isinstance(element(fgrp_cmpt), Neutral): populateMeshEntry(meshEntry, fgrp_cmpt, "function", f) else: populateMeshEntry(meshEntry, compt, "function", f) for t in wildcardFind(compt.path + '/##[ISA=StimulusTable]'): tgrp_cmpt = findGroup_compt(t) xcord.append(xyPosition(t.path + '/info', 'x')) ycord.append(xyPosition(t.path + '/info', 'y')) if isinstance(element(tgrp_cmpt), Neutral): populateMeshEntry(meshEntry, tgrp_cmpt, "stimTab", t) else: populateMeshEntry(meshEntry, compt, "stimTab", t) xmin = min(xcord) xmax = max(xcord) ymin = min(ycord) ymax = max(ycord) positionInfoExist = not (len(np.nonzero(xcord)[0]) == 0 and len(np.nonzero(ycord)[0]) == 0) return (objPar, meshEntry, xmin, xmax, ymin, ymax, positionInfoExist)