lattpy.utils

Contains miscellaneous utility methods.

exception lattpy.utils.LatticeError[source]

Bases: Exception

exception lattpy.utils.ConfigurationError[source]

Bases: LatticeError

property msg
property hint
exception lattpy.utils.SiteOccupiedError(atom, pos)[source]

Bases: ConfigurationError

exception lattpy.utils.NoAtomsError[source]

Bases: ConfigurationError

exception lattpy.utils.NoConnectionsError[source]

Bases: ConfigurationError

exception lattpy.utils.NotAnalyzedError[source]

Bases: ConfigurationError

exception lattpy.utils.NotBuiltError[source]

Bases: ConfigurationError

lattpy.utils.min_dtype(a, signed=True)[source]

Returns the minimum required dtype to store the given values.

Parameters:
aarray_like

One or more values for determining the dtype. Should contain the maximal expected values.

signedbool, optional

If True the dtype is forced to be signed. The default is True.

Returns:
dtypedtype

The required dtype.

lattpy.utils.chain(items, cycle=False)[source]

Creates a chain between items

Parameters:
itemsSequence

items to join to chain

cyclebool, optional

cycle to the start of the chain if True, default: False

Returns:
chain: list

chain of items

lattpy.utils.create_lookup_table(array, dtype=<class 'numpy.uint8'>)[source]

Converts the given array to an array of indices linked to the unique values.

Parameters:
arrayarray_like
dtypeint or np.dtype, optional

Optional data-type for storing the indices of the unique values. By default np.uint8 is used, since it is assumed that the input-array has only a few unique values.

Returns:
valuesnp.ndarray

The unique values occuring in the input-array.

indicesnp.ndarray

The corresponding indices in the same shape as the input-array.

lattpy.utils.frmt_num(num, dec=1, unit='', div=1000.0)[source]

Returns a formatted string of a number.

Parameters:
numfloat

The number to format.

decint, optional

Number of decimals. The default is 1.

unitstr, optional

Optional unit suffix. By default no unit-strinmg is used.

divfloat, optional

The divider used for units. The default is 1000.

Returns:
num_str: str
lattpy.utils.frmt_bytes(num, dec=1)[source]

Returns a formatted string of the number of bytes.

lattpy.utils.frmt_time(seconds, short=False, width=0)[source]

Returns a formated string for a given time in seconds.

Parameters:
secondsfloat

Time value to format

shortbool, optional

Flag if short representation should be used.

widthint, optional

Optional minimum length of the returned string.

Returns:
time_str: str