Skip to content

Commit

Permalink
Merge pull request #106 from tsherwen/dev
Browse files Browse the repository at this point in the history
Minor updates for automated KPP tagging
  • Loading branch information
tsherwen committed May 25, 2021
2 parents 0fd420c + a12dbeb commit 1d198f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions AC_tools/KPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_]
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions scripts/KPP_mk_tagged_GC_Mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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())]
Expand Down

0 comments on commit 1d198f9

Please sign in to comment.