diff --git a/src/acom_music_box/__init__.py b/src/acom_music_box/__init__.py index 56c3f272..f3eed4ed 100644 --- a/src/acom_music_box/__init__.py +++ b/src/acom_music_box/__init__.py @@ -4,7 +4,7 @@ This package contains modules for handling various aspects of a music box, including species, products, reactants, reactions, and more. """ -__version__ = "2.5.3" +__version__ = "2.5.4" from .utils import convert_time, convert_pressure, convert_temperature, convert_concentration from .model_options import BoxModelOptions diff --git a/src/acom_music_box/evolving_conditions.py b/src/acom_music_box/evolving_conditions.py index 91a9375e..5859b46d 100644 --- a/src/acom_music_box/evolving_conditions.py +++ b/src/acom_music_box/evolving_conditions.py @@ -3,6 +3,9 @@ import re from .conditions import Conditions +import logging +logger = logging.getLogger(__name__) + class EvolvingConditions: """ @@ -177,7 +180,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: diff --git a/src/acom_music_box/music_box.py b/src/acom_music_box/music_box.py index 3ff70741..8ce74186 100644 --- a/src/acom_music_box/music_box.py +++ b/src/acom_music_box/music_box.py @@ -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 @@ -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