def getPrunnedTree(self, math, remainderPatterns): ''' removes the remainderPatterns leafs from the math tree ''' while (math.getCharacter() == '*' or math.getCharacter() == '/') and len(remainderPatterns) > 0: if libsbml.formulaToString( math.getLeftChild()) in remainderPatterns: remainderPatterns.remove( libsbml.formulaToString(math.getLeftChild())) math = math.getRightChild() elif libsbml.formulaToString( math.getRightChild()) in remainderPatterns: remainderPatterns.remove( libsbml.formulaToString(math.getRightChild())) math = math.getLeftChild() else: if (math.getLeftChild().getCharacter()) == '*': math.replaceChild( 0, self.getPrunnedTree(math.getLeftChild(), remainderPatterns)) if (math.getRightChild().getCharacter()) == '*': math.replaceChild( math.getNumChildren() - 1, self.getPrunnedTree(math.getRightChild(), remainderPatterns)) break return math
def getInstanceRate(self, math, compartmentList, reversible, rReactant, rProduct): #remove compartments from expression math = self.getPrunnedTree(math, compartmentList) if reversible: if math.getCharacter() == '-' and math.getNumChildren() > 1: rateL, nl = (self.removeFactorFromMath( math.getLeftChild().deepCopy(), rReactant, rProduct)) rateR, nr = (self.removeFactorFromMath( math.getRightChild().deepCopy(), rProduct, rReactant)) else: rateL, nl = self.removeFactorFromMath(math, rReactant, rProduct) rateL = "if({0} >= 0 ,{0},0)".format(rateL) rateR, nr = self.removeFactorFromMath(math, rReactant, rProduct) rateR = "if({0} < 0 ,-({0}),0)".format(rateR) nl, nr = 1, 1 else: rateL, nl = (self.removeFactorFromMath(math.deepCopy(), rReactant, rProduct)) rateR, nr = '0', '-1' if reversible: pass return rateL, rateR
def getInstanceRate(self,math,compartmentList, reversible,rReactant,rProduct): #remove compartments from expression math = self.getPrunnedTree(math, compartmentList) if reversible: if math.getCharacter() == '-' and math.getNumChildren() > 1: rateL, nl = (self.removeFactorFromMath( math.getLeftChild().deepCopy(), rReactant, rProduct)) rateR, nr = (self.removeFactorFromMath( math.getRightChild().deepCopy(), rProduct, rReactant)) else: rateL, nl = self.removeFactorFromMath(math, rReactant, rProduct) rateL = "if({0} >= 0 ,{0},0)".format(rateL) rateR, nr = self.removeFactorFromMath(math, rReactant, rProduct) rateR = "if({0} < 0 ,-({0}),0)".format(rateR) nl, nr = 1,1 else: rateL, nl = (self.removeFactorFromMath(math.deepCopy(), rReactant,rProduct)) rateR, nr = '0', '-1' if reversible: pass return rateL,rateR
def getPrunnedTree(self,math,remainderPatterns): ''' removes the remainderPatterns leafs from the math tree ''' while (math.getCharacter() == '*' or math.getCharacter() == '/') and len(remainderPatterns) > 0: if libsbml.formulaToString(math.getLeftChild()) in remainderPatterns: remainderPatterns.remove(libsbml.formulaToString(math.getLeftChild())) math = math.getRightChild() elif libsbml.formulaToString(math.getRightChild()) in remainderPatterns: remainderPatterns.remove(libsbml.formulaToString(math.getRightChild())) math = math.getLeftChild() else: if(math.getLeftChild().getCharacter()) == '*': math.replaceChild(0, self.getPrunnedTree(math.getLeftChild(), remainderPatterns)) if(math.getRightChild().getCharacter()) == '*': math.replaceChild(math.getNumChildren() - 1,self.getPrunnedTree(math.getRightChild(), remainderPatterns)) break return math