Skip to content

Commit

Permalink
New: Normalize formulas before comparing them
Browse files Browse the repository at this point in the history
  • Loading branch information
avcopan committed Dec 19, 2024
1 parent 16142ad commit c6e523b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion automol/form/_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def normalized(fml: Formula) -> Formula:
:return: The formula, without `None` values
"""
fml = {ptab.to_symbol(k): int(v) for k, v in fml.items() if v}
assert all(v > 0 for v in fml.values()), f"Invalid formula: {fml}"
return fml


Expand All @@ -102,6 +101,9 @@ def match(fml1: Formula, fml2: Formula) -> bool:
:param fml2: Another chemical formula
:return: `True` if so, `False` if not
"""
fml1 = normalized(fml1)
fml2 = normalized(fml2)

excl_symbs1 = dict_.keys_by_value(fml1, lambda x: x < 0)
excl_symbs2 = dict_.keys_by_value(fml2, lambda x: x < 0)
excl_symbs = excl_symbs1 | excl_symbs2
Expand Down

0 comments on commit c6e523b

Please sign in to comment.