sisl.utils.misc module

Miscellaneous routines

sisl.utils.misc.merge_instances(*args, **kwargs)[source]

Merges an arbitrary number of instances together.

Parameters:

name: str or MergedClass

name of class to merge

sisl.utils.misc.name_spec(name)[source]

Split into a tuple of name and specifier, delimited by {...}.

Parameters:

name: str

string to split

Returns:

tuple of str

returns the name and the specifier (without delimiter) in a tuple

Examples

>>> name_spec('hello')
'hello', None
>>> name_spec('hello{TEST}')
'hello', 'TEST'
sisl.utils.misc.direction(d)[source]

Return the index coordinate index corresponding to the Cartesian coordinate system.

Parameters:

d: {0, ‘X’, ‘x’, 1, ‘Y’, ‘y’, 2, ‘Z’, ‘z’}

returns the integer that corresponds to the coordinate index. If it is an integer, it is returned as is.

Returns:

int

The index of the Cartesian coordinate system.

Examples

>>> direction(0)
0
>>> direction('Y')
1
>>> direction('z')
2
sisl.utils.misc.angle(s, radians=True, in_radians=True)[source]

Convert the input string to an angle, either radians or degrees.

Parameters:

s : str

If s starts with 'r' it is interpreted as radians [0:2pi]. If s starts with 'a' it is interpreted as a regular angle [0:360]. If s ends with 'r' it returns in radians. If s ends with 'a' it returns in regular angle.

s may be any mathematical equation which can be intercepted through eval.

radians : bool

Whether the returned angle is in radians. Note than an 'r' at the end of s has precedence.

in_radians : bool

Whether the calculated angle is in radians. Note than an 'r' at the beginning of s has precedence.

Returns:

float

the angle in the requested unit

sisl.utils.misc.iter_shape(shape)[source]

Generator for iterating a shape by returning consecutive slices

Parameters:

shape : array_like

the shape of the iterator

Yields:

tuple of int

a tuple of the same length as the input shape. The iterator is using the C-indexing.

Examples

>>> for slc in iter_shape([2, 1, 3]):
>>>    print(slc)
[0, 0, 0]
[0, 0, 1]
[0, 0, 2]
[1, 0, 0]
[1, 0, 1]
[1, 0, 2]