def register_default_cosym_observers(script): """Register the standard observers to the cosym script.""" script.cosym_analysis.register_observer( event="analysed_symmetry", observer=SymmetryAnalysisObserver()) script.cosym_analysis.register_observer( event="analysed_clusters", observer=CosymClusterAnalysisObserver()) script.register_observer(event="run_cosym", observer=UnitCellAnalysisObserver()) script.register_observer(event="run_cosym", observer=CosymHTMLGenerator(), callback="make_html") script.register_observer(event="run_cosym", observer=CosymJSONGenerator(), callback="make_json")
def make_html(self, cosym_script): """Collect data from the individual observers and write the html.""" filename = cosym_script.params.output.html if not filename: return self.data.update(CosymClusterAnalysisObserver().make_plots()) self.data.update(UnitCellAnalysisObserver().make_plots()) self.data.update(SymmetryAnalysisObserver().make_tables()) print(f"Writing html report to: {filename}") loader = ChoiceLoader([ PackageLoader("dials", "templates"), PackageLoader("dials", "static", encoding="utf-8"), ]) env = Environment(loader=loader) template = env.get_template("cosym_report.html") html = template.render( page_title="DIALS cosym report", cosym_graphs=self.data["cosym_graphs"], unit_cell_graphs=self.data["unit_cell_graphs"], symmetry_analysis=self.data["symmetry_analysis"], ) with open(filename, "wb") as f: f.write(html.encode("utf-8", "xmlcharrefreplace"))