def latex_emit_initial_state(self, f: TextIO): f.write("\n\n initial state:\n\n\n") for species_index in range(self.number_of_species): num = self.initial_state[species_index] if num > 0: f.write(str(num) + " molecules of ") latex_emit_molecule(f, species_index) f.write("\n\n")
def generate_list_of_all_species_report(self): with open( self.reports_folder + "/list_of_all_species.tex", "w", ) as f: generate_latex_header(f) for species_index in range(self.number_of_species): f.write("\n\n\n") latex_emit_molecule(f, species_index) generate_latex_footer(f)
def generate_consumption_report(self, mol_entry: MoleculeEntry): target_species_index = mol_entry.parameters["ind"] ( producing_reactions, consuming_reactions, final_counts, ) = self.extract_species_consumption_info(target_species_index) histogram_file = (self.reports_folder + "/final_count_histogram_" + str(target_species_index) + ".pdf") visualize_molecule_count_histogram(final_counts, histogram_file) with open( self.reports_folder + "/consumption_report_" + str(target_species_index) + ".tex", "w", ) as f: generate_latex_header(f) f.write("consumption report for") latex_emit_molecule(f, target_species_index) f.write("\n\n") f.write("molecule frequency at end of simulations") f.write("\\raisebox{-.5\\height}{" + "\\includegraphics[scale=0.5]{" + "./final_count_histogram_" + str(target_species_index) + ".pdf" + "}}\n\n") f.write("producing reactions:\n\n\n") for reaction_index, frequency in sorted( producing_reactions.items(), key=lambda item: -item[1]): f.write(str(frequency) + " occurrences:\n") self.latex_emit_reaction(f, reaction_index) f.write("consuming reactions:\n\n\n") for reaction_index, frequency in sorted( consuming_reactions.items(), key=lambda item: -item[1]): f.write(str(frequency) + " occurrences:\n") self.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def generate_pathway_report(self, mol_entry: MoleculeEntry, min_frequency: int): target_species_index = mol_entry.parameters["ind"] if target_species_index not in self.reaction_pathways_dict: self.extract_reaction_pathways(target_species_index) with open( self.reports_folder + "/pathway_report_" + str(target_species_index) + ".tex", "w", ) as f: pathways = self.reaction_pathways_dict[target_species_index] generate_latex_header(f) f.write("pathway report for\n\n") latex_emit_molecule(f, target_species_index) self.latex_emit_initial_state(f) f.write("\\newpage\n\n\n") for _, unique_pathway in sorted( pathways.items(), key=lambda item: -item[1]["frequency"]): frequency = unique_pathway["frequency"] if frequency > min_frequency: f.write(str(frequency) + " occurrences:\n") for reaction_index in unique_pathway["pathway"]: self.latex_emit_reaction(f, reaction_index) f.write("\\newpage\n") else: break generate_latex_footer(f)
def generate_pathway_report(self, mol_entry: MoleculeEntry, number_of_pathways=100, sort_by_frequency=True): target_species_index = mol_entry.parameters["ind"] if target_species_index not in self.reaction_pathways_dict: self.extract_reaction_pathways(target_species_index) if sort_by_frequency: suffix = "frequency" else: suffix = "cost" with open( self.reports_folder + "/pathway_report_" + str(target_species_index) + "_" + suffix + ".tex", "w", ) as f: pathways = self.reaction_pathways_dict[target_species_index] generate_latex_header(f) f.write("pathway report for\n\n") latex_emit_molecule(f, target_species_index) if sort_by_frequency: f.write("\n\ntop " + str(number_of_pathways) + " pathways sorted by frequency") else: f.write("\n\ntop " + str(number_of_pathways) + " pathways sorted by cost") f.write("\\vspace{1cm}") self.latex_emit_initial_state(f) f.write("\\newpage\n\n\n") if sort_by_frequency: def sort_function(item): return -item[1]["frequency"] else: def sort_function(item): return item[1]["weight"] count = 1 for _, unique_pathway in sorted(pathways.items(), key=sort_function): frequency = unique_pathway["frequency"] weight = unique_pathway["weight"] f.write("pathway " + str(count) + "\n\n") f.write("path weight: " + str(weight) + "\n\n") f.write(str(frequency) + " occurrences:\n") for reaction_index in unique_pathway["pathway"]: self.latex_emit_reaction(f, reaction_index) f.write("\\newpage\n") count += 1 if count > number_of_pathways: break generate_latex_footer(f)