From b5253807ee403ce08770ac263ce82cff08acd39e Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Sun, 16 Jun 2024 00:53:07 +0300 Subject: [PATCH] Implemented get param and obs in simulate adapters --- t3/simulate/cantera_constantHP.py | 13 +++++-------- t3/simulate/rmg_constantTP.py | 11 +++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/t3/simulate/cantera_constantHP.py b/t3/simulate/cantera_constantHP.py index 57c7ee0a6..e4bdd7329 100644 --- a/t3/simulate/cantera_constantHP.py +++ b/t3/simulate/cantera_constantHP.py @@ -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 @@ -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 diff --git a/t3/simulate/rmg_constantTP.py b/t3/simulate/rmg_constantTP.py index 3d7d7cab3..e18a002e8 100755 --- a/t3/simulate/rmg_constantTP.py +++ b/t3/simulate/rmg_constantTP.py @@ -7,6 +7,7 @@ import itertools import os import pandas as pd +import re import shutil from typing import List, Optional @@ -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 @@ -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)] \