Skip to content

Commit

Permalink
added method to generate reaction config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjamesgarza committed Mar 1, 2024
1 parent 398d571 commit 8edf3b9
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 10 deletions.
Binary file added src/__pycache__/music_box_product.cpython-39.pyc
Binary file not shown.
Binary file added src/__pycache__/music_box_reactant.cpython-39.pyc
Binary file not shown.
Binary file modified src/__pycache__/music_box_reaction_list.cpython-39.pyc
Binary file not shown.
85 changes: 78 additions & 7 deletions src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from music_box_evolving_conditions import EvolvingConditions
from music_box_reaction_list import ReactionList
from music_box_reaction import Reaction
from music_box_reactant import Reactant
from music_box_product import Product
from music_box_species_list import SpeciesList
from music_box_species import Species
from music_box_model_options import BoxModelOptions
Expand Down Expand Up @@ -63,7 +65,11 @@ def generateConfig(self):
speciesConfig = self.generateSpeciesConfig()
print(speciesConfig)

reactionConfig = self.generateReactionConfig()
print(reactionConfig)

pass

def generateSpeciesConfig(self):
"""
Generate a JSON configuration for the species in the box model.
Expand All @@ -72,14 +78,14 @@ def generateSpeciesConfig(self):
str: A JSON-formatted string representing the species configuration.
"""

#Established relative tolerance
relTolerance = {
"type" : "RELATIVE_TOLERANCE",
"value" : self.species_list.relative_tolerance
}

speciesArray = []
speciesArray.append(relTolerance)

#Adds relative tolerance if value is set
if(self.species_list.relative_tolerance != None):
relativeTolerance = {}
relativeTolerance["Type"] = "RELATIVE_TOLERANCE"
relativeTolerance["value"] = self.species_list.relative_tolerance
speciesArray.append(relativeTolerance)

#Adds species to config
for species in self.species_list.species:
Expand Down Expand Up @@ -115,4 +121,69 @@ def generateSpeciesConfig(self):

return json.dumps(species_json)


def generateReactionConfig(self):
"""
Generate a JSON configuration for the reactions in the box model.
Returns:
str: A JSON-formatted string representing the reaction configuration.
"""
reacList = {}

#Add mechanism name if value is set
if self.reaction_list.name != None:
reacList["name"] = self.reaction_list.name

reacList["type"] = "MECHANISM"

reactionsArray = []

#Adds reaction to config
for reaction in self.reaction_list.reactions:
reac = {}

#Adds reaction name if value is set
if(reaction.reaction_type != None):
reac["type"] = reaction.reaction_type

reactants = {}

#Adds reactants
for reactant in reaction.reactants:
quantity = {}

#Adds reactant quantity if value is set
if reactant.quantity != None:
quantity["quantity"] = reactant.quantity
reactants[reactant.name] = quantity

reac["reactants"] = reactants

products = {}

#Adds products
for product in reaction.products:
yield_value = {}

#Adds product yield if value is set
if product.yield_value != None:
yield_value["yield"] = product.yield_value
products[product.name] = yield_value

reac["products"] = products

#Adds reaction name if value is set
if(reaction.name != None):
reac["MUSICA name"] = reaction.name

reactionsArray.append(reac)

reacList["reactions"] = reactionsArray

reactionsJson = {
"camp-data" : [reacList]
}

return json.dumps(reactionsJson)

2 changes: 1 addition & 1 deletion src/music_box_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Product:
yield_value (float): The yield of the product.
"""

def __init__(self, species, yield_value):
def __init__(self, species, yield_value=None):
"""
Initializes a new instance of the Product class.
Expand Down
2 changes: 1 addition & 1 deletion src/music_box_reactant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Reactant:
quantity (float): The quantity of the reactant.
"""

def __init__(self, species, quantity):
def __init__(self, species, quantity=None):
"""
Initializes a new instance of the Reactant class.
Expand Down
4 changes: 3 additions & 1 deletion src/music_box_reaction_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class ReactionList:
reactions (List[Reaction]): A list of Reaction instances.
"""

def __init__(self, reactions=None):
def __init__(self, name=None, reactions=None):
"""
Initializes a new instance of the ReactionList class.
Args:
reactions (List[Reaction]): A list of Reaction instances. Default is an empty list.
"""

self.name = name
self.reactions = reactions if reactions is not None else []

def add_reaction(self, reaction):
Expand Down

0 comments on commit 8edf3b9

Please sign in to comment.