diff --git a/src/box_model.py b/src/box_model.py index f509698f..df3ccb43 100644 --- a/src/box_model.py +++ b/src/box_model.py @@ -144,6 +144,30 @@ def generateConfig(self, directory): ] config_file.write(json.dumps(data)) + + # Make evolving conditions config + with open(output_path + "/evolving_conditions.csv", 'w', newline='') as evolving_conditions_file: + writer = csv.writer(evolving_conditions_file) + writer.writerow(self.evolving_conditions.headers) + + for i in range(len(self.evolving_conditions.times)): + row = [self.evolving_conditions.times[i]] + + for header in self.evolving_conditions.headers[1:]: + if header == "ENV.pressure.Pa": + row.append(self.evolving_conditions.conditions[i].pressure) + elif header == "ENV.temperature.K": + row.append(self.evolving_conditions.conditions[i].temperature) + elif header.startswith("CONC."): + species_name = header.split('.')[1] + species_concentration = next((x for x in self.evolving_conditions.conditions[i].species_concentrations if x.species.name == species_name), None) + row.append(species_concentration.concentration) + elif header.endswith(".s-1"): + reaction_name = header.split('.')[1] + reaction_rate = next((x for x in self.evolving_conditions.conditions[i].reaction_rates if x.reaction.name == reaction_name), None) + row.append(reaction_rate.rate) + + writer.writerow(row) def generateSpeciesConfig(self): """ @@ -373,7 +397,7 @@ def solve(self, path_to_output = None): next_conditions = None next_conditions_time = 0 next_conditions_index = 0 - if(len(self.evolving_conditions) != 0): + if(len(self.evolving_conditions.conditions) != 0): next_conditions_index = 0 next_conditions = self.evolving_conditions.conditions[0] next_conditions_time = self.evolving_conditions.times[0] diff --git a/src/music_box_evolving_conditions.py b/src/music_box_evolving_conditions.py index 372b151e..bcc6f36a 100644 --- a/src/music_box_evolving_conditions.py +++ b/src/music_box_evolving_conditions.py @@ -14,7 +14,7 @@ class EvolvingConditions: conditions (List[Conditions]): A list of associated conditions. """ - def __init__(self, times=None, conditions=None): + def __init__(self, headers=None, times=None, conditions=None): """ Initializes a new instance of the EvolvingConditions class. @@ -22,6 +22,7 @@ def __init__(self, times=None, conditions=None): time (List[float]): A list of time points. Default is an empty list. conditions (List[Conditions]): A list of associated conditions. Default is an empty list. """ + self.headers = headers if headers is not None else [] self.times = times if times is not None else [] self.conditions = conditions if conditions is not None else [] @@ -80,7 +81,7 @@ def from_UI_JSON(cls, UI_JSON, species_list, reaction_list): conditions.append(Conditions(pressure, temperature, concentrations, rates)) - return cls(times, conditions) + return cls(headers, times, conditions) @classmethod def from_config_JSON(cls, path_to_json ,config_JSON, species_list, reaction_list):