wulfric.crystal.validate_atoms#

wulfric.crystal.validate_atoms(atoms, required_keys=None, raise_errors=True)[source]#

Validate keys and values of the atoms dictionary.

Checks that all values in the atom's dictionary have the same amount of elements. Checks that atoms have required keys with expected shape of their values.

If one of the following keys is in atoms, then an extra check is performed on its value

  • "names"

    Checks that the value is a list of N str.

  • "species"

    Checks that the value is a list of N str.

    Checks that each element is a valid species of an atom (i.e. Cr, H, Br, Fe, ...) or "X". Note that "CR" is not a valid species, but "Cr" is.

  • "positions"

    Checks that the atoms["positions"] has the shape (N, 3)

  • "spglib_types"

    Checks that the value is a list of N int and each element is >= 1.

For all other keys checks that the values are iterables of the N elements each.

Parameters:
atomsdict

Dictionary of atoms.

required_keyslist of str, optional

List of required keys.

raise_errorsbool, default True

If False, then no errors are raised.

Returns:
check_passedbool

True if all checks passed. False otherwise.

Raises:
TypeError

If atoms[key] is not iterable for any key and raise_errors=False.

ValueError

If any check is not passed and raise_errors=False.