From c67a48b5783534a6b11029f3959fdc6d4c297709 Mon Sep 17 00:00:00 2001 From: Julia Schumann Date: Fri, 8 Nov 2024 00:46:16 +0100 Subject: [PATCH] fix rates in results for haber data, specify h5 file, which can be processed --- .../schema_packages/catalysis.py | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/nomad_catalysis/schema_packages/catalysis.py b/src/nomad_catalysis/schema_packages/catalysis.py index 0787330..cbdd383 100644 --- a/src/nomad_catalysis/schema_packages/catalysis.py +++ b/src/nomad_catalysis/schema_packages/catalysis.py @@ -1513,7 +1513,7 @@ def read_haber_data(self, archive, logger): # noqa: PLR0912, PLR0915 This function reads the h5 data from the data file and assigns the data to the corresponding attributes of the class. """ - if self.data_file.endswith('.h5'): + if self.data_file.endswith('NH3_Decomposition.h5'): with archive.m_context.raw_file(self.data_file, 'rb') as f: import h5py @@ -1723,7 +1723,11 @@ def check_and_read_data_file(self, archive, logger): if self.data_file.endswith('.csv') or self.data_file.endswith('.xlsx'): self.read_clean_data(archive, logger) elif self.data_file.endswith('.h5'): - self.read_haber_data(archive, logger) + if self.data_file.endswith('NH3_Decomposition.h5'): + self.read_haber_data(archive, logger) + else: + logger.info("""This h5 file format currently not supported. Please + contact the plugin developers if you want to add support for this.""") else: logger.error( """Data file format not supported. Please provide a @@ -1988,6 +1992,17 @@ def plot_figures(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: fig = self.single_plot(x, x_text, y.to(unit_dict[var]), y_text, title) self.figures.append(PlotlyFigure(label=title, figure=fig.to_plotly_json())) + fig1 = self.conversion_plot(x, x_text, logger) + if fig1 is not None: + self.figures.append( + PlotlyFigure(label='Conversion', figure=fig1.to_plotly_json()) + ) + + if self.results[0].rates: + self.make_rates_plot(x, x_text) + + if not self.results[0].products: + return if ( self.results[0].products is not None and self.results[0].products != [] @@ -2008,14 +2023,6 @@ def plot_figures(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: self.figures.append( PlotlyFigure(label='Selectivity', figure=fig0.to_plotly_json()) ) - fig1 = self.conversion_plot(x, x_text, logger) - if fig1 is not None: - self.figures.append( - PlotlyFigure(label='Conversion', figure=fig1.to_plotly_json()) - ) - - if self.results[0].rates: - self.make_rates_plot(x, x_text) if not self.results[0].reactants_conversions: return @@ -2165,7 +2172,14 @@ def reduce_haber_data(self, archive: 'EntryArchive', logger: 'BoundLogger') -> N name='molecular hydrogen', reaction_rate=Rates * ureg.mmol / ureg.g / ureg.hour, ) - archive.results.properties.catalytic.reaction.rate = [h2_rate] + rates = [] + rates.append(h2_rate) + set_nested_attr( + archive.results.properties.catalytic.reaction, + 'rates', + rates, + ) + # archive.results.properties.catalytic.reaction.rate = [h2_rate] react = Reactant( name='ammonia', conversion=Convs, gas_concentration_in=NH3concs