Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Normalize formulas before comparing them #597

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions automol/form/_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

import more_itertools as mit
import pyparsing as pp
from pyparsing import pyparsing_common as ppc

from phydat import ptab
from pyparsing import pyparsing_common as ppc

from ..util import dict_

Expand Down Expand Up @@ -89,7 +88,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 +100,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
Loading