Skip to content

Commit

Permalink
Simplify invalid chemical symbol error message
Browse files Browse the repository at this point in the history
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
  • Loading branch information
ml-evs and CasperWA committed Sep 23, 2021
1 parent 49fa172 commit 97484de
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions optimade/models/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from optimade.server.warnings import MissingExpectedField

EXTENDED_CHEMICAL_SYMBOLS = CHEMICAL_SYMBOLS + EXTRA_SYMBOLS
EXTENDED_CHEMICAL_SYMBOLS = set(CHEMICAL_SYMBOLS + EXTRA_SYMBOLS)


__all__ = (
Expand Down Expand Up @@ -146,7 +146,9 @@ class Species(BaseModel):
@validator("chemical_symbols", each_item=True)
def validate_chemical_symbols(cls, v):
if not (v in EXTENDED_CHEMICAL_SYMBOLS):
raise ValueError(f"{v} MUST be in {EXTENDED_CHEMICAL_SYMBOLS}")
raise ValueError(
f'{v!r} MUST be an element symbol, e.g., "C", "He", or a special symbol from {EXTRA_SYMBOLS}.'
)
return v

@validator("concentration", "mass")
Expand Down

0 comments on commit 97484de

Please sign in to comment.