Skip to content

Commit

Permalink
refactor rates plot
Browse files Browse the repository at this point in the history
  • Loading branch information
schumannj committed Oct 2, 2024
1 parent bd4519a commit d6843bd
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 15 deletions.
85 changes: 72 additions & 13 deletions src/nomad_catalysis/schema_packages/catalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Material,
Product,
Properties,
Rate,
Reactant,
Reaction,
ReactionConditions,
Expand Down Expand Up @@ -377,7 +378,7 @@ def populate_results(self, archive: 'EntryArchive', logger) -> None:
mapping=quantities_results_mapping,
target=archive.results.properties.catalytic.catalyst,
)
if len(self.catalyst_type) > 1:
if self.catalyst_type is list and len(self.catalyst_type) > 1:
for n in range(1, len(self.catalyst_type)):
archive.results.properties.catalytic.catalyst.catalyst_type.append(
self.catalyst_type[n]
Expand Down Expand Up @@ -677,7 +678,12 @@ def update_chemical_info(self):
# If the value is a string, it refers to another key, so resolve it
if isinstance(chemical_key, str):
chemical_key = chemical_data[chemical_key]

# If the value is not a string or a dictionary, it is not in the database, try
# to resolve it by removing capital letters
elif not isinstance(chemical_key, dict):
chemical_key = chemical_data.get(self.name.lower())
if isinstance(chemical_key, str):
chemical_key = chemical_data[chemical_key]
pure_component = PubChemPureSubstanceSection()
pure_component.name = self.name
if chemical_key:
Expand Down Expand Up @@ -1925,18 +1931,66 @@ def plot_figures(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
)

if self.results[0].rates:
rates_list = [
'reaction_rate',
'rate',
'specific_mass_rate',
'specific_surface_area_rate',
'turnover_frequency',
]
rates_units = {
'reaction_rate': ['mmol reagent/g_cat/h', 'mmol/g/hour'],
'rate': ['g reagent/g_cat/h', '1/hour'],
'specific_mass_rate': ['mmol reagent/g_cat/h', '1/hour'],
'specific_surface_area_rate': [
'mmol reagent/m**2 cat/h',
'mmol/m**2/hour',
],
'turnover_frequency': ['1/h', '1/hour'],
}
previous_rate = []

fig = go.Figure()
for i, c in enumerate(self.results[0].rates):
fig.add_trace(
go.Scatter(
x=x,
y=self.results[0].rates[i].reaction_rate,
name=self.results[0].rates[i].name,
)
)
if i == 0:
for rate_str in rates_list:
y, y_text = self.get_y_data(
{rate_str: 'rates.' + rate_str}, rate_str
)
if y is not None:
y.to(rates_units[rate_str][1])
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=self.results[0].rates[i].name,
)
)
y_text = y_text + ' (' + rates_units[rate_str][0] + ')'
previous_rate = rate_str
break
else:
y = getattr(self.results[0].rates[i], previous_rate)
if y is not None:
y.to(rates_units[previous_rate][1])
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=self.results[0].rates[i].name + ' ' + rate_str,
)
)

# fig.add_trace(
# go.Scatter(
# x=x,
# y=self.results[0].rates[i].reaction_rate,
# name=self.results[0].rates[i].name,
# )
# )
fig.update_layout(title_text='Rates', showlegend=True)
fig.update_xaxes(title_text=x_text)
fig.update_yaxes(title_text='reaction rates (mmol product/g cat/h)')
fig.update_yaxes(title_text=y_text)
self.figures.append(
PlotlyFigure(label='Rates', figure=fig.to_plotly_json())
)
Expand Down Expand Up @@ -2005,9 +2059,9 @@ def reduce_haber_data(self, archive: 'EntryArchive', logger: 'BoundLogger') -> N
'Temp': self.reaction_conditions.set_temperature,
'Whsv': self.reaction_conditions.weight_hourly_space_velocity,
'Flow': self.reaction_conditions.total_flow_rate,
'Rate': self.results[0].reactants_conversions[0].conversion,
'Conv': self.reaction_conditions.reagents[0].gas_concentration_in,
'NH3conc': self.results[0].rates[0].reaction_rate,
'Conv': self.results[0].reactants_conversions[0].conversion,
'NH3conc': self.reaction_conditions.reagents[0].gas_concentration_in,
'Rate': self.results[0].rates[0].reaction_rate,
'Time': self.results[0].time_on_stream,
}
data_dict_no_ramps = {}
Expand Down Expand Up @@ -2082,6 +2136,11 @@ def reduce_haber_data(self, archive: 'EntryArchive', logger: 'BoundLogger') -> N
archive.results.properties.catalytic.reaction.reaction_conditions.time_on_stream = ( # noqa: E501
Times * ureg.second
)
h2_rate = Rate(
name='molecular hydrogen',
reaction_rate=Rates * ureg.mmol / ureg.g / ureg.hour,
)
archive.results.properties.catalytic.reaction.rate = [h2_rate]

react = Reactant(
name='ammonia', conversion=Convs, gas_concentration_in=NH3concs
Expand Down
41 changes: 39 additions & 2 deletions src/nomad_catalysis/schema_packages/chemical_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
'cas_number': '74-82-8',
},
'CH4': 'methane', # Reference to 'methane'
'Methane': 'methane', # Reference to 'methane'
'ethane': {
'pub_chem_id': 6324,
'iupac_name': 'ethane',
Expand Down Expand Up @@ -250,6 +249,7 @@
'cas_number': '106-97-8',
},
'n-butane': 'butane', # Reference to 'butane'
'n-Butane': 'butane', # Reference to 'butane'
'nbutane': 'butane', # Reference to 'butane'
'2-methylpropane': {
'pub_chem_id': 6360,
Expand All @@ -266,6 +266,33 @@
'isobutane': '2-methylpropane',
'Isobutane': '2-methylpropane',
'ibutane': '2-methylpropane',
'butan-1-ol': {
'pub_chem_id': 263,
'iupac_name': 'butan-1-ol',
'molecular_formula': 'C4H10O',
'molecular_mass': 74.073164938,
'molar_mass': 74.12,
'monoisotopic_mass': 74.073164938,
'inchi': 'InChI=1S/C4H10O/c1-2-3-4-5/h5H,2-4H2,1H3',
'inchi_key': 'LRHPLDYGYMQRHN-UHFFFAOYSA-N',
'smile': 'CCCCO',
'canonical_smile': 'CCCCO',
'cas_number': '71-36-3',
},
'butanol': 'butan-1-ol', # Reference to 'butan-1-ol'
'butanal': {
'pub_chem_id': 261,
'iupac_name': 'butanal',
'molecular_formula': 'C4H8O',
'molecular_mass': 72.057514874,
'molar_mass': 72.11,
'monoisotopic_mass': 72.057514874,
'inchi': 'InChI=1S/C4H8O/c1-2-3-4-5/h4H,2-3H2,1H3',
'inchi_key': 'ZTQSAGDEMFDKMZ-UHFFFAOYSA-N',
'smile': 'CCCC=O',
'canonical_smile': 'CCCC=O',
},
'butyraldehyde': 'butanal', # Reference to 'butanal'
'pent-1-ene': {
'pub_chem_id': 8004,
'iupac_name': 'pent-1-ene',
Expand Down Expand Up @@ -303,7 +330,6 @@
'methyl alcohol': 'methanol', # Reference to 'methanol'
'MeOH': 'methanol', # Reference to 'methanol'
'CH3OH': 'methanol', # Reference to 'methanol'
'Methanol': 'methanol', # Reference to 'methanol'
'formic acid': {
'pub_chem_id': 284,
'iupac_name': 'formic acid',
Expand Down Expand Up @@ -375,6 +401,8 @@
},
'1-propanol': 'propan-1-ol', # Reference to 'propan-1-ol'
'n-propanol': 'propan-1-ol', # Reference to 'propan-1-ol'
'npropanol': 'propan-1-ol', # Reference to 'propan-1-ol'
'propanol': 'propan-1-ol', # Reference to 'propan-1-ol'
'methyl acetate': {
'pub_chem_id': 6589,
'iupac_name': 'methyl acetate',
Expand Down Expand Up @@ -410,6 +438,11 @@
},
'butylene': '1-butene', # Reference to '1-butene'
'n-Butene': '1-butene', # Reference to '1-butene'
'butene': {
'iupac_name': 'butene',
'molecular_formula': 'C4H8',
}, # unspecified isomer
'nictbutene': 'butene', # Reference to 'butene', unspecified isomer
'furan': {
'pub_chem_id': 8029,
'iupac_name': 'furan',
Expand All @@ -429,4 +462,8 @@
},
'maleic anhydride': 'furan-2,5-dione', # Reference to 'furan-2,5-dione'
'MAN': 'furan-2,5-dione', # Reference to 'furan-2,5-dione'
'p>=5c': {
'name': 'p>=5c',
'iupac_name': 'C5+',
}, # unspecified longer hydrocarbon
}

0 comments on commit d6843bd

Please sign in to comment.