validate_identifier

emmet.core.mpid.validate_identifier(idx, serialize=False, *, strict=False, allowed_prefixes=STRICT_ID_PREFIXES)

Format an input string or identifier as a valid Materials Project format identifier.

Return type:

str | MPID | AlphaID

Parameters:
  • idx (str | MPID | AlphaID)

  • serialize (bool)

  • strict (bool)

  • allowed_prefixes (Iterable[str])

Parameters

idxstr, MPID, AlphaID

The input identifier, can either be an already instantiated identifier object, or a plain string

serializebool = False

If True, returns the string representation of the identifier object. If False, returns the object.

strictbool = False

If False (default), any input that AlphaID can parse is accepted, e.g. “fake-149” -> AlphaID(“fake-ft”). If True, the input must also pass check_strict_identifier: a bare id (“149”, “ft”) or “<prefix>-<id>” with a prefix in allowed_prefixes. Inputs such as “fake-149”, “mp_ft” or “mp-” raise a ValueError.

allowed_prefixesIterable[str] = STRICT_ID_PREFIXES

Prefixes permitted in strict mode. Ignored when strict is False.