From a12dbebd13373c245bb9cf377137169591bd9c92 Mon Sep 17 00:00:00 2001 From: Tomas Sherwen Date: Wed, 24 Mar 2021 15:36:01 +0000 Subject: [PATCH] Minor updates for automated KPP tagging --- AC_tools/KPP.py | 8 ++++++-- scripts/KPP_mk_tagged_GC_Mechanism.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/AC_tools/KPP.py b/AC_tools/KPP.py index bff790c..f1ecb3f 100644 --- a/AC_tools/KPP.py +++ b/AC_tools/KPP.py @@ -1616,11 +1616,13 @@ def calc_fam_loss_by_route(wd=None, fam='LOx', ref_spec='O3', if rtn_by_fam: return dfFam + def add_tags4strs2mech(rxn_dicts, tagged_rxns={}, search_strs=None, counter=0, search_reactants=False, search_products=False, - tag_prefix='T'): + tag_prefix='T', + debug=False): """ Tag reactions in provided string found in KPP reaction string @@ -1649,7 +1651,7 @@ def add_tags4strs2mech(rxn_dicts, tagged_rxns={}, re5 = '(\\s+)' # White Space 2 rg = re.compile(re1+re2+re3+re4, re.IGNORECASE | re.DOTALL) # ( Or just all reactions that contain a species of interest ) - current_tag = '{}{}'.format(tag_prefix, counter) + current_tag = '{}{:0>3}'.format(tag_prefix, counter) for search_str in search_strs: for key_ in list(rxn_dicts.keys()): df = rxn_dicts[key_] @@ -1667,6 +1669,8 @@ def add_tags4strs2mech(rxn_dicts, tagged_rxns={}, if search_str in str2search4search_str: # Update the counter (NOTE: counter starts from 1) counter += 1 + if debug: + print( counter, current_tag ) # Check if rxn already tagged, if so just use that tag. m = rg.search(rxn_str) if m: diff --git a/scripts/KPP_mk_tagged_GC_Mechanism.py b/scripts/KPP_mk_tagged_GC_Mechanism.py index 2c73cf3..b10e4b9 100644 --- a/scripts/KPP_mk_tagged_GC_Mechanism.py +++ b/scripts/KPP_mk_tagged_GC_Mechanism.py @@ -155,7 +155,9 @@ def main(folder=None, print_formatted_KPP_file=True, GC_version=None, # Add tags for halogen families rxn_dicts, tagged_rxns = AC.add_tags4strs2mech(rxn_dicts, counter=counter, search_strs=search_strs, - tagged_rxns=tagged_rxns, ) + tagged_rxns=tagged_rxns, +# debug=debug + ) counter = max(tagged_rxns.keys()) current_tag = '{}{}'.format(tag_prefix, counter) @@ -201,7 +203,6 @@ def main(folder=None, print_formatted_KPP_file=True, GC_version=None, counter = max(tagged_rxns.keys()) current_tag = '{}{}'.format(tag_prefix, counter) - # - Add the species to the species_df # Number of reactions tagged alltags = [tagged_rxns[i]['tag'] for i in list(tagged_rxns.keys())]