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 902157e commit 5587980
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 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 @@ -145,8 +145,10 @@ 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}")
if v not 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 5587980

Please sign in to comment.