Skip to content

Commit

Permalink
Implemented get param and obs in simulate adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Jul 7, 2024
1 parent 050fc2b commit b525380
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 5 additions & 8 deletions t3/simulate/cantera_constantHP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rmgpy.tools.canteramodel import generate_cantera_conditions
from rmgpy.tools.data import GenericData

from t3.common import get_observable_label_from_header, get_parameter_from_header
from t3.logger import Logger
from t3.simulate.adapter import SimulateAdapter
from t3.simulate.factory import register_simulate_adapter
Expand Down Expand Up @@ -400,23 +401,19 @@ def get_sa_coefficients(self):

# extract kinetic SA
for rxn in reaction_sensitivity_data:
# for kinetics, get `ethane(1)` from `dln[ethane(1)]/dln[k8]: H(6)+ethane(1)=H2(12)+C2H5(5)`
observable_label = rxn.label.split('[')[1].split(']')[0]
observable_label = get_observable_label_from_header(rxn)
if observable_label not in sa_dict['kinetics']:
sa_dict['kinetics'][observable_label] = dict()
# for kinetics, get k8 from `dln[ethane(1)]/dln[k8]: H(6)+ethane(1)=H2(12)+C2H5(5)` then only extract 8
parameter = rxn.label.split('[')[2].split(']')[0]
parameter = get_parameter_from_header(rxn)
parameter = int(parameter[1:])
sa_dict['kinetics'][observable_label][parameter] = rxn.data

# extract thermo SA
for spc in thermodynamic_sensitivity_data:
# for thermo get 'C2H4(8)' from `dln[ethane(1)]/dH[C2H4(8)]`
observable_label = spc.label.split('[')[1].split(']')[0]
observable_label = get_observable_label_from_header(spc)
if observable_label not in sa_dict['thermo']:
sa_dict['thermo'][observable_label] = dict()
# for thermo get 'C2H4(8)' from `dln[ethane(1)]/dH[C2H4(8)]`
parameter = spc.label.split('[')[2].split(']')[0]
parameter = get_parameter_from_header(spc)
sa_dict['thermo'][observable_label][parameter] = spc.data

return sa_dict
Expand Down
11 changes: 5 additions & 6 deletions t3/simulate/rmg_constantTP.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import itertools
import os
import pandas as pd
import re

Check notice

Code scanning / CodeQL

Unused import Note

Import of 're' is not used.
import shutil
from typing import List, Optional

Expand All @@ -18,7 +19,8 @@
from rmgpy.tools.loader import load_rmg_py_job
from rmgpy.tools.plot import plot_sensitivity

from t3.common import get_chem_to_rmg_rxn_index_map, get_species_by_label, get_values_within_range, time_lapse
from t3.common import get_chem_to_rmg_rxn_index_map, get_species_by_label, get_values_within_range, \
get_observable_label_from_header, get_parameter_from_header, time_lapse
from t3.logger import Logger
from t3.simulate.adapter import SimulateAdapter
from t3.simulate.factory import register_simulate_adapter
Expand Down Expand Up @@ -256,17 +258,14 @@ def get_sa_coefficients(self) -> Optional[dict]:
elif '/dG[' in header:
sa_type = 'thermo'
if sa_type is not None:
observable_label = header.split('[')[1].split(']')[0]
observable_label = get_observable_label_from_header(header)
observable = get_species_by_label(observable_label, self.rmg_model.reaction_model.core.species)
if observable is None:
self.logger.error(f'Could not identify observable species for label: {observable_label}')
observable_label = observable.to_chemkin()
if observable_label not in sa_dict[sa_type].keys():
sa_dict[sa_type][observable_label] = dict()
# parameter extraction examples:
# for species get 'C2H4(8)' from `dln[ethane(1)]/dG[C2H4(8)]`
# for reaction, get 8 from `dln[ethane(1)]/dln[k8]: H(6)+ethane(1)=H2(12)+C2H5(5)`
parameter = header.split('[')[2].split(']')[0]
parameter = get_parameter_from_header(header)
if sa_type == 'kinetics':
parameter = parameter[1:]
parameter = chem_to_rmg_rxn_index_map[int(parameter)] \
Expand Down

0 comments on commit b525380

Please sign in to comment.