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

Set species and rates configured in micm #261

Merged
merged 1 commit into from
Oct 14, 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
14 changes: 13 additions & 1 deletion src/acom_music_box/evolving_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import re
from .conditions import Conditions

import logging
logger = logging.getLogger(__name__)

class EvolvingConditions:
"""
Expand Down Expand Up @@ -177,7 +179,17 @@ def read_conditions_from_file(cls, file_path):
species_concentrations = {}

for key in other_keys:
condition_type, label, unit = key.split('.')
parts = key.split('.')
condition_type, label, unit = None, None, None
if len(parts) == 3:
condition_type, label, unit = parts
elif len(parts) == 2:
condition_type, label = parts
else:
error = f"Unexpected format in key: {key}"
logger.error(error)
raise ValueError(error)

if condition_type == 'CONC':
species_concentrations[label] = row[key]
else:
Expand Down
16 changes: 12 additions & 4 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@ def order_reaction_rates(curr_conditions, rate_constant_ordering):
"""
ordered_rate_constants = np.zeros(len(rate_constant_ordering), dtype=np.float64)

for rate_label, value in curr_conditions.reaction_rates.items():
ordered_rate_constants[rate_constant_ordering[rate_label]] = value
for rate_label, _ in rate_constant_ordering.items():
if rate_label not in curr_conditions.reaction_rates:
logger.warning(f"Reaction rate '{rate_label}' not found in current conditions.")
continue
else:
ordered_rate_constants[rate_constant_ordering[rate_label]] = curr_conditions.reaction_rates[rate_label]

return ordered_rate_constants

Expand All @@ -285,7 +289,11 @@ def order_species_concentrations(curr_conditions, species_constant_ordering):
"""
concentrations = np.zeros(len(species_constant_ordering), dtype=np.float64)

for species, value in curr_conditions.species_concentrations.items():
concentrations[species_constant_ordering[species]] = value
for species, _ in species_constant_ordering.items():
if species not in curr_conditions.species_concentrations:
logger.warning(f"Species '{species}' not found in current conditions.")
continue
else:
concentrations[species_constant_ordering[species]] = curr_conditions.species_concentrations[species]

return concentrations