magnon.utils

Functions

is_array_like(obj, ndim)

Check if the input object is an array-like structure with a specific number of dimensions.

all_same_shape(*arrays)

Check whether all input arrays have the same shape.

all_same_length(*arrays)

Check whether all input arrays have the same length.

ensure_vector_magnetic_moments(atoms)

Ensure that the ASE Atoms object has vector (3D) magnetic moments for each atom.

Module Contents

magnon.utils.is_array_like(obj, ndim)

Check if the input object is an array-like structure with a specific number of dimensions.

Parameters:
  • obj (object) – Object to be checked.

  • ndim (int) – Number of dimensions expected.

Returns:

True if the object is array-like with the specified number of dimensions, False otherwise.

Return type:

bool

Raises:

Exception – If the object cannot be converted to a NumPy array.

magnon.utils.all_same_shape(*arrays)

Check whether all input arrays have the same shape.

Parameters:

arrays (array-like) – Variable number of arrays to compare.

Returns:

True if all arrays have the same shape, False otherwise.

Return type:

bool

magnon.utils.all_same_length(*arrays)

Check whether all input arrays have the same length.

Parameters:

arrays (array-like) – Variable number of arrays to compare.

Returns:

True if all arrays have the same length, False otherwise.

Return type:

bool

magnon.utils.ensure_vector_magnetic_moments(atoms)

Ensure that the ASE Atoms object has vector (3D) magnetic moments for each atom.

Parameters:

atoms (ase.Atoms) – ASE atoms object to be validated.

Returns:

atoms – ASE Atoms object with vector magnetic moments.

Return type:

ase.Atoms

Notes

ASE allows initial_magnetic_moments to be either scalar or vector. This function guarantees vector format, which is useful for handling non-collinear magnetism.