Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address issue 169 air density, M third body, catch unexpected JSON #186

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
musica==0.7.3
pandas
pipx
pytest
Expand Down
11 changes: 6 additions & 5 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def solve(self, output_path = None):
next_output_time = curr_time
#runs the simulation at each timestep


while(curr_time <= self.box_model_options.simulation_length):

#outputs to output_array if enough time has elapsed
Expand All @@ -502,7 +502,7 @@ def solve(self, output_path = None):
output_array.append(row)
next_output_time += self.box_model_options.output_step_time

#iterates evolvings conditons if enough time has elapsed
#iterates evolving conditions if enough time has elapsed
while(next_conditions != None and next_conditions_time <= curr_time):

curr_conditions.update_conditions(next_conditions)
Expand All @@ -523,7 +523,8 @@ def solve(self, output_path = None):
BOLTZMANN_CONSTANT = 1.380649e-23
AVOGADRO_CONSTANT = 6.02214076e23;
GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT
air_density = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)
air_density = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)


#solves and updates concentration values in concentration array
if (not ordered_concentrations):
Expand All @@ -535,7 +536,7 @@ def solve(self, output_path = None):

#increments time
curr_time += self.box_model_options.chem_step_time

#outputs to file if output is present
if(output_path != None):
logger.info("path_to_output = {}".format(output_path))
Expand Down Expand Up @@ -705,7 +706,7 @@ def order_species_concentrations(self, curr_conditions, species_constant_orderin
concentrations[concentraton.species.name] = concentraton.concentration

ordered_concentrations = len(concentrations.keys()) * [0.0]

for key, value in concentrations.items():
ordered_concentrations[species_constant_ordering[key]] = value
return ordered_concentrations
Expand Down
9 changes: 7 additions & 2 deletions src/acom_music_box/music_box_conditions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import csv
import os

import logging
logger = logging.getLogger(__name__)

from typing import List
from .music_box_reaction_rate import ReactionRate
from .music_box_species import Species
Expand Down Expand Up @@ -137,9 +141,10 @@ def from_config_JSON(cls, path_to_json, config_JSON, species_list, reaction_list
species_concentrations.append(SpeciesConcentration(species, 0))

# Set initial reaction rates

for reaction in reaction_list.reactions:
if reaction.name != None and not any(reac.reaction.name == reaction.name for reac in reaction_rates):
if (reaction.name is None):
continue
if not any(rate.reaction.name == reaction.name for rate in reaction_rates):
reaction_rates.append(ReactionRate(reaction, 0))


Expand Down
9 changes: 6 additions & 3 deletions src/acom_music_box/music_box_evolving_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ def from_config_JSON(cls, path_to_json ,config_JSON, species_list, reaction_list

# Check if 'evolving conditions' is a key in the JSON config
if 'evolving conditions' in config_JSON:
# Construct the path to the evolving conditions file
evolving_conditions_path = os.path.dirname(path_to_json) + "/" + list(config_JSON['evolving conditions'].keys())[0]
evolving_conditions = EvolvingConditions.read_conditions_from_file( evolving_conditions_path, species_list, reaction_list)
if len(config_JSON['evolving conditions'].keys()) > 0:
# Construct the path to the evolving conditions file
evolving_conditions_path = (os.path.dirname(path_to_json) + "/"
+ list(config_JSON['evolving conditions'].keys())[0])
evolving_conditions = EvolvingConditions.read_conditions_from_file(
evolving_conditions_path, species_list, reaction_list)

return evolving_conditions

Expand Down
14 changes: 9 additions & 5 deletions src/acom_music_box/music_box_reaction_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from .music_box_reactant import Reactant
from .music_box_product import Product

import logging
logger = logging.getLogger(__name__)

class ReactionList:
"""
Represents a list of chemical reactions.
Expand Down Expand Up @@ -114,12 +117,13 @@ def get_reactants_from_JSON(self, reaction, species_list):
"""
reactants = []

for reactant, reactant_info in reaction['reactants'].items():
match = filter(lambda x: x.name == reactant, species_list.species)
species = next(match, None)
quantity = reactant_info['qty'] if 'qty' in reactant_info else None
if ('reactants' in reaction.keys()):
for reactant, reactant_info in reaction['reactants'].items():
match = filter(lambda x: x.name == reactant, species_list.species)
species = next(match, None)
quantity = reactant_info['qty'] if 'qty' in reactant_info else None

reactants.append(Reactant(species, quantity))
reactants.append(Reactant(species, quantity))
return reactants

@classmethod
Expand Down