Skip to content

Commit

Permalink
added documentations to missing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjamesgarza committed Apr 29, 2024
1 parent ce5289e commit 31e6b79
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions src/acom_music_box/music_box_reaction_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down

0 comments on commit 31e6b79

Please sign in to comment.