Skip to content

Commit

Permalink
Asterisk is already used for excited state in photochemistry
Browse files Browse the repository at this point in the history
  • Loading branch information
bjodah committed Apr 23, 2024
1 parent c7a9c1d commit da3f3ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions chempy/util/parsing.py
Expand Up @@ -96,7 +96,7 @@ def _get_formula_parser():
| '{' formula '}'
| '[' formula ']' ) count prime charge?
formula :: term+
hydrate :: ( '.' | '\u00B7' | '*' ) count? formula
hydrate :: ( '..' | '\u00B7' | '.' ) count? formula
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
compound :: count formula hydrate? state?
Expand All @@ -115,7 +115,7 @@ def _get_formula_parser():
| '{' formula '}'
| '[' formula ']' ) count prime charge?
formula :: term+
hydrate :: ( '..' | '\u00B7' | '*' ) count? formula
hydrate :: ( '..' | '\u00B7' | '.' ) count? formula
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
compound :: count formula hydrate? state?
"""
Expand Down Expand Up @@ -387,9 +387,7 @@ def formula_to_composition(

stoich_tok, chg_tok = _formula_to_parts(formula, prefixes, suffixes)[:2]
tot_comp = {}
if ".." in stoich_tok:
parts = stoich_tok.split("..")
elif "\u00b7" in stoich_tok:
if "\u00b7" in stoich_tok:
parts = stoich_tok.split('\u00b7')
elif '.' in stoich_tok:
warnings.warn(
Expand All @@ -399,7 +397,8 @@ def formula_to_composition(
)
parts = stoich_tok.split('.')
else:
parts = list(filter(len, internal_asterisk.split(stoich_tok)))
parts = stoich_tok.split("..")


for idx, stoich in enumerate(parts):
if idx == 0:
Expand Down Expand Up @@ -536,8 +535,6 @@ def to_reaction(line, substance_keys, token, Cls, globals_=None, **kwargs):
)


internal_asterisk = re.compile(r"([^\s\*]+)\*([a-zA-Z0-9]+)")


def _formula_to_format(
sub,
Expand All @@ -549,7 +546,6 @@ def _formula_to_format(
):
parts = _formula_to_parts(formula, prefixes.keys(), suffixes)
parts0 = parts[0].replace("..", "\u00B7")
parts0 = internal_asterisk.sub("\u00B7", parts0)
if '.' in parts0:
warnings.warn(
("dot is ambiguous in chempy-0.8.x, prefer '*' or '' for complexes."
Expand Down
2 changes: 1 addition & 1 deletion chempy/util/tests/test_parsing.py
Expand Up @@ -724,7 +724,7 @@ def test_composition_dot_as_crystal_water_chempy08x():
as floating point delimiter in fractional stoichiometric coefficients."""
ref = {30: 1, 7: 2, 8: 12, 1: 12}
assert formula_to_composition('Zn(NO3)2{}6H2O'.format('\u00B7')) == ref
assert formula_to_composition('Zn(NO3)2*6H2O') == ref
assert formula_to_composition('Zn(NO3)2..6H2O') == ref
# https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html#ensuring-code-triggers-a-deprecation-warning
with pytest.deprecated_call():
assert formula_to_composition('Zn(NO3)2.6H2O') == ref

0 comments on commit da3f3ef

Please sign in to comment.