Skip to content

Commit

Permalink
can generate evolving_conditions.csv for config
Browse files Browse the repository at this point in the history
  • Loading branch information
eadlg2 committed Apr 2, 2024
1 parent 4552c4d commit 0f6b434
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 25 additions & 1 deletion src/box_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions src/music_box_evolving_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ 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.
Args:
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 []

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0f6b434

Please sign in to comment.