diff --git a/src/acom_music_box/music_box.py b/src/acom_music_box/music_box.py index 02f6b924..f9b2b112 100644 --- a/src/acom_music_box/music_box.py +++ b/src/acom_music_box/music_box.py @@ -601,6 +601,18 @@ def readFromUIJsonString(self, data): self.evolving_conditions = EvolvingConditions.from_UI_JSON(data, self.species_list, self.reaction_list) def readConditionsFromJson(self, path_to_json): + """ + Reads and parses a JSON file from the CAMP JSON file to set up the box model simulation. + + Args: + path_to_json (str): The JSON path to the JSON file. + + Returns: + None + + Raises: + ValueError: If the JSON string cannot be parsed. + """ with open(path_to_json, 'r') as json_file: data = json.load(json_file) diff --git a/src/acom_music_box/music_box_reaction_list.py b/src/acom_music_box/music_box_reaction_list.py index 216c1817..512ed5ba 100644 --- a/src/acom_music_box/music_box_reaction_list.py +++ b/src/acom_music_box/music_box_reaction_list.py @@ -98,6 +98,20 @@ def add_reaction(self, reaction): @classmethod def get_reactants_from_JSON(self, reaction, species_list): + """ + Retrieves reactants from a JSON object. + + This method iterates over the 'reactants' field of the provided JSON object, + matches each reactant with a species from the provided species list, and + creates a Reactant object for each one. + + Args: + reaction (dict): A dictionary representing a reaction, as parsed from JSON. + species_list (SpeciesList): A list of all possible species. + + Returns: + list: A list of Reactant objects representing the reactants of the reaction. + """ reactants = [] for reactant, reactant_info in reaction['reactants'].items(): @@ -110,6 +124,21 @@ def get_reactants_from_JSON(self, reaction, species_list): @classmethod def get_products_from_JSON(self, reaction, species_list): + """ + Extracts products from a JSON object. + + This method checks if the 'products' field is present in the provided JSON object. + If it is, the method iterates over the 'products' field, matches each product with + a species from the provided species list, and creates a Product object for each one. + + Args: + reaction (dict): A dictionary representing a reaction, as parsed from JSON. + species_list (SpeciesList): A list of all possible species. + + Returns: + list: A list of Product objects representing the products of the reaction, or + an empty list if the 'products' field is not present in the JSON object. + """ products = [] if 'products' in reaction: for product, product_info in reaction['products'].items():