Skip to content

Commit

Permalink
added method for generating species config
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjamesgarza committed Mar 1, 2024
1 parent 24d93e4 commit b72c48b
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 23 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added src/__pycache__/music_box_reaction.cpython-39.pyc
Binary file not shown.
Binary file not shown.
Binary file added src/__pycache__/music_box_species.cpython-39.pyc
Binary file not shown.
Binary file not shown.
80 changes: 72 additions & 8 deletions src/box_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import json

from music_box_evolving_conditions import EvolvingConditions
from music_box_reaction_list import ReactionList
from music_box_reaction import Reaction
from music_box_species_list import SpeciesList
from music_box_species import Species
from music_box_model_options import BoxModelOptions
from music_box_conditions import Conditions

class BoxModel:
"""
Expand All @@ -16,7 +21,8 @@ class BoxModel:
evolvingConditions (List[EvolvingConditions]): List of evolving conditions over time.
"""

def __init__(self, box_model_options, species_list, reaction_list, initial_conditions, evolving_conditions):
def __init__(self, box_model_options=None, species_list=None, reaction_list=None,
initial_conditions=None, evolving_conditions=None, config_file=None):
"""
Initializes a new instance of the BoxModel class.
Expand All @@ -26,12 +32,15 @@ def __init__(self, box_model_options, species_list, reaction_list, initial_condi
reaction_list (ReactionList): A list of reactions.
initial_conditions (Conditions): Initial conditions for the simulation.
evolving_conditions (List[EvolvingConditions]): List of evolving conditions over time.
config_file (String): File path for the configuration file to be located. Default is "camp_data/config.json".
"""
self.boxModelOptions = box_model_options
self.speciesList = species_list
self.reactionList = reaction_list
self.initialConditions = initial_conditions
self.evolvingConditions = evolving_conditions
self.box_model_options = box_model_options
self.species_list = species_list
self.reaction_list = reaction_list
self.initial_conditions = initial_conditions
self.evolving_conditions = evolving_conditions
self.config_file = config_file if config_file is not None else "camp_data/config.json"


def add_evolving_condition(self, time_point, conditions):
"""
Expand All @@ -44,10 +53,65 @@ def add_evolving_condition(self, time_point, conditions):
evolving_condition = EvolvingConditions(time=[time_point], conditions=[conditions])
self.evolvingConditions.append(evolving_condition)

def generateFiles(self):
def generateConfig(self):
"""
TODO: Generate configuration JSON files for the box model simulation.
TODO: Generate configuration JSON for the box model simulation.
"""
# TODO: Implement the logic to generate configuration files.
# This method is a placeholder, and the actual implementation is required.

speciesConfig = self.generateSpeciesConfig()
print(speciesConfig)

pass
def generateSpeciesConfig(self):
"""
Generate a JSON configuration for the species in the box model.
Returns:
str: A JSON-formatted string representing the species configuration.
"""

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

speciesArray = []

#Adds species to config
for species in self.species_list.species:
spec = {}

#Add species name if value is set
if(species.name != None):
spec["name"] = species.name

spec["type"] = "CHEM_SPEC"

#Add species absoluate tolerance if value is set
if(species.absolute_tolerance != None):
spec["absolute tolerance"] = species.absolute_tolerance

#Add species phase if value is set
if(species.phase != None):
spec["phase"] = species.phase

#Add species molecular weight if value is set
if(species.molecular_weight != None):
spec["molecular weight [kg mol-1]"] = species.molecular_weight

#Add species density if value is set
if(species.density != None):
spec["density [kg m-3]"] = species.density

speciesArray.append(spec)

species_json = {
"camp-data" : speciesArray
}

return json.dumps(species_json)


8 changes: 4 additions & 4 deletions src/music_box_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(self, pressure, temperature, species_concentrations=None, reaction_
"""
self.pressure = pressure
self.temperature = temperature
self.speciesConcentrations = species_concentrations if species_concentrations is not None else []
self.reactionRates = reaction_rates if reaction_rates is not None else []
self.species_concentrations = species_concentrations if species_concentrations is not None else []
self.reaction_rates = reaction_rates if reaction_rates is not None else []

def add_species_concentration(self, species_concentration):
"""
Expand All @@ -34,7 +34,7 @@ def add_species_concentration(self, species_concentration):
Args:
species_concentration (SpeciesConcentration): The SpeciesConcentration instance to be added.
"""
self.speciesConcentrations.append(species_concentration)
self.species_concentration.append(species_concentration)

def add_reaction_rate(self, reaction_rate):
"""
Expand All @@ -43,4 +43,4 @@ def add_reaction_rate(self, reaction_rate):
Args:
reaction_rate (ReactionRate): The ReactionRate instance to be added.
"""
self.reactionRates.append(reaction_rate)
self.reaction_rates.append(reaction_rate)
6 changes: 3 additions & 3 deletions src/music_box_model_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, chem_step_time, output_step_time, simulation_length, grid="bo
simulation_length (float): Length of the simulation in hours.
grid (str): The type of grid. Default is "box".
"""
self.chemStepTime = chem_step_time
self.outputStepTime = output_step_time
self.simulationLength = simulation_length
self.chem_step_time = chem_step_time
self.output_step_time = output_step_time
self.simulation_length = simulation_length
self.grid = grid
2 changes: 1 addition & 1 deletion src/music_box_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, name, reaction_type, reactants=None, products=None):
Initializes a new instance of the Reaction class.
Args:
name (str): The name of the reaction.
type (str): The type of the reaction.
reaction_type (str): The type of the reaction.
reactants (List[Reactant]): A list of Reactant instances representing the reactants. Default is an empty list.
products (List[Product]): A list of Product instances representing the products. Default is an empty list.
Expand Down
10 changes: 5 additions & 5 deletions src/music_box_reaction_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class ReactionList:
Represents a list of chemical reactions.
Attributes:
mechanisms (List[Reaction]): A list of Reaction instances.
reactions (List[Reaction]): A list of Reaction instances.
"""

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

def add_reaction(self, reaction):
"""
Expand All @@ -24,4 +24,4 @@ def add_reaction(self, reaction):
Args:
reaction (Reaction): The Reaction instance to be added.
"""
self.mechanisms.append(reaction)
self.reactions.append(reaction)
2 changes: 1 addition & 1 deletion src/music_box_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Species:
density (float): The density of the species in kg m^-3.
"""

def __init__(self, name, absolute_tolerance, phase, molecular_weight, density):
def __init__(self, name=None, absolute_tolerance=None, phase=None, molecular_weight=None, density=None):
"""
Initializes a new instance of the Species class.
Expand Down
2 changes: 1 addition & 1 deletion src/music_box_species_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, species=None, relative_tolerance=0.0):
relative_tolerance (float): The relative tolerance for the species list. Default is 0.0.
"""
self.species = species if species is not None else []
self.relativeTolerance = relative_tolerance
self.relative_tolerance = relative_tolerance

def add_species(self, species):
"""
Expand Down

0 comments on commit b72c48b

Please sign in to comment.