diff --git a/bng/__init__.py b/bng/__init__.py index 61531da..77abb25 100644 --- a/bng/__init__.py +++ b/bng/__init__.py @@ -38,14 +38,16 @@ def execute(self, context): if hasattr(external_operators.accessFile,"info"): del external_operators.accessFile.info - if('.bngl') in self.filepath: + is_file_xml = self.filepath.endswith('.xml') + + if self.filepath.endswith('.bngl'): bngfilepath = self.filepath # bngl file path external_operators.filePath=findCellBlenderDirectory()+'bng{0}'.format(os.sep) + self.filepath.split(os.sep)[-1] print ( "Calling bng_operators.execute_bionetgen("+bngfilepath+")" ) bng_operators.execute_bionetgen(self.filepath,context) print ( "Back from bng_operators.execute_bionetgen("+bngfilepath+")" ) - elif('.xml') in self.filepath: + elif is_file_xml: sbmlfilepath = self.filepath external_operators.filePath = sbmlfilepath # sbml file path @@ -67,7 +69,7 @@ def execute(self, context): print ( "Loading release sites from external model..." ) bpy.ops.external.release_site_add() print ( "Done Loading external model" ) - if ('.xml') in self.filepath: + if is_file_xml: #TODO:this is sbml only until we add this information on the bng side print("Loading reaction output ...") bpy.ops.external.reaction_output_add() @@ -78,9 +80,7 @@ def execute(self, context): ### THIS ENTIRE SECTION IS A QUICK HACK TO HANDLE XML IMPORTING ### ### - if ('.xml' in self.filepath) and ('mcell' in context.scene): - # Note that searching for ".xml" in the filepath may not be reliable since it should end with .xml. - # Keeping the same for now. + if is_file_xml and self.add_to_model_objects and ('mcell' in context.scene): print ( "Pulling object structure from XML file: " + self.filepath ) mcell = context.scene.mcell diff --git a/bng/sbml2json.py b/bng/sbml2json.py index 2d2655d..04b67cf 100644 --- a/bng/sbml2json.py +++ b/bng/sbml2json.py @@ -393,10 +393,10 @@ def getInstanceRate(self,math,compartmentList, reversible,rReactant,rProduct): else: rateL, nl = self.removeFactorFromMath(math, rReactant, rProduct) - rateL = "if({0} >= 0 ,{0},0)".format(rateL) + # rateL = "if({0} >= 0 ,{0},0)".format(rateL) rateR, nr = self.removeFactorFromMath(math, rReactant, rProduct) - rateR = "if({0} < 0 ,-({0}),0)".format(rateR) + # rateR = "if({0} < 0 ,-({0}),0)".format(rateR) nl, nr = 1,1 else: rateL, nl = (self.removeFactorFromMath(math.deepCopy(), @@ -426,8 +426,8 @@ def removeFactorFromMath(self, math, reactants, products): #remainderPatterns = [x[0] for x in reactants] math = self.getPrunnedTree(math,remainderPatterns) rateR = libsbml.formulaToString(math) - for element in remainderPatterns: - rateR = 'if({0} >0,({1})/{0} ,0)'.format(element,rateR) + # for element in remainderPatterns: + # rateR = 'if({0} >0,({1})/{0} ,0)'.format(element,rateR) if highStoichoiMetryFactor != 1: rateR = '{0}*{1}'.format(rateR, int(highStoichoiMetryFactor)) @@ -494,7 +494,7 @@ def getContained(compartmentList,container): math = kineticLaw.getMath() reversible = reaction.getReversible() - rateL, rateR = self.getInstanceRate(math,compartmentList.keys(),reversible,rReactant,rProduct) + rateL, rateR = self.getInstanceRate(math,list(compartmentList.keys()),reversible,rReactant,rProduct) #finalReactant = [x[0]] #testing whether we have volume-surface interactions rcList = [] @@ -620,7 +620,7 @@ def getContained(compartmentList,container): tmpR['reactants'] = ' + '.join(prdList) if flagR: virtualReaction= {} - virtualReaction['rxn_name'] = tmpL['rxn_name'] + virtualReaction['rxn_name'] = tmpR['rxn_name'] tmpR.pop('rxn_name') tmpR['products'] = '{0}_{1}_{2}'.format(product[0][0],reactant[0][2],reactant[0][0]) virtualReaction['reactants'] = tmpR['products']