Skip to content

Commit

Permalink
Added flux.count_species_in_well()
Browse files Browse the repository at this point in the history
To properly count species in cases where a species label is contained within another species label, e.g., 'NO' and 'NO2'. This is avoided when using RMG labels like 'S(1243)', but is not avoided when generating flux diagrams for non-RMG generated Cantera models
  • Loading branch information
alongd committed Nov 28, 2023
1 parent 380b764 commit 8c0ab52
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion t3/utils/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,14 +894,37 @@ def get_opposite_rxn_species(rxn: str, spc: str) -> List[str]:
"""
arrow = ' <=> ' if ' <=> ' in rxn else ' => '
wells = rxn.split(arrow)
counts = wells[0].count(spc), wells[1].count(spc)
counts = count_species_in_well(well=wells[0], spc=spc), count_species_in_well(well=wells[1], spc=spc)
i = int(counts[0] > counts[1])
species = wells[i].split(' + ')
for token in [' + M', ' (+M)', 'M', ' + ']:
species = [s.replace(token, '') for s in species]
return [s for s in species if s != '']


def count_species_in_well(well: str,
spc: str,
) -> int:
"""
Count the number of times a species appears in a well.
Args:
well (str): The well string.
spc (str): The species label.
Returns:
int: The number of times a species appears in the well.
"""
count = 0
for token in [' + M', ' (+M)', 'M']:
well = well.replace(token, '')
splits = well.split(' + ')
for s in splits:
if s == spc:
count += 1
return count


def unpack_stoichiometry(labels: List[str]) -> Tuple[List[str], List[int]]:
"""
Unpack stoichiometry.
Expand Down

0 comments on commit 8c0ab52

Please sign in to comment.