From dc5d074dd3bd05108ec5fe51ea2990d052a2b735 Mon Sep 17 00:00:00 2001 From: tebuck <2237442+tebuck@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:41:45 -0400 Subject: [PATCH 1/5] Check for extension at end of filename during BNGL and SBML import --- bng/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bng/__init__.py b/bng/__init__.py index 61531da0..360ba5bf 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 ('mcell' in context.scene): print ( "Pulling object structure from XML file: " + self.filepath ) mcell = context.scene.mcell From 83293157c74e2b7bde370e5f15549fb69982367c Mon Sep 17 00:00:00 2001 From: tebuck <2237442+tebuck@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:45:00 -0400 Subject: [PATCH 2/5] Do not replace existing geometry when `self.add_to_model_objects == False` during SBML import --- bng/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bng/__init__.py b/bng/__init__.py index 360ba5bf..77abb25e 100644 --- a/bng/__init__.py +++ b/bng/__init__.py @@ -80,7 +80,7 @@ def execute(self, context): ### THIS ENTIRE SECTION IS A QUICK HACK TO HANDLE XML IMPORTING ### ### - if is_file_xml and ('mcell' in context.scene): + 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 From 5ca395179e7ac94c419d68dafca56fe8bacf388d Mon Sep 17 00:00:00 2001 From: tebuck <2237442+tebuck@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:54:51 -0400 Subject: [PATCH 3/5] Convert to list to prevent `AttributeError` --- bng/sbml2json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bng/sbml2json.py b/bng/sbml2json.py index 2d2655dc..8b53664b 100644 --- a/bng/sbml2json.py +++ b/bng/sbml2json.py @@ -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 = [] From adbd4627c6809e6dc13eb5406410bbae59c0eb4b Mon Sep 17 00:00:00 2001 From: tebuck <2237442+tebuck@users.noreply.github.com> Date: Sun, 12 Jul 2020 18:59:29 -0400 Subject: [PATCH 4/5] Fix `KeyError` during SBML import --- bng/sbml2json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bng/sbml2json.py b/bng/sbml2json.py index 8b53664b..4d1012fd 100644 --- a/bng/sbml2json.py +++ b/bng/sbml2json.py @@ -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'] From b78f8054fe73bd910b59e303085192d082e1b5b0 Mon Sep 17 00:00:00 2001 From: tebuck <2237442+tebuck@users.noreply.github.com> Date: Mon, 13 Jul 2020 14:28:26 -0400 Subject: [PATCH 5/5] Fix MCell `Error: Undefined variable: if` during SBML import --- bng/sbml2json.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bng/sbml2json.py b/bng/sbml2json.py index 4d1012fd..04b67cf4 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))