Skip to content

atomlib.types

Vec3 module-attribute

Vec3: TypeAlias = NDArray[floating[Any]]

3D float vector, of shape (3,).

VecLike module-attribute

VecLike: TypeAlias = ArrayLike

3d vector-like

Pts3DLike module-attribute

Pts3DLike: TypeAlias = Union['BBox3D', ArrayLike]

Sequence of 3d points-like

Num module-attribute

Num: TypeAlias = Union[float, int]

Scalar numeric type

ElemLike module-attribute

ElemLike: TypeAlias = Union[str, int]

Element-like

ElemsLike module-attribute

ElemsLike: TypeAlias = Union[
    str,
    int,
    Sequence[Union[ElemLike, Tuple[ElemLike, float]]],
]

ScalarT module-attribute

ScalarT = TypeVar('ScalarT', bound=generic)

numpy.generic-bound type variable

to_vec3

to_vec3(v: VecLike, dtype: None = None) -> NDArray[float64]
to_vec3(
    v: VecLike, dtype: Type[ScalarT]
) -> NDArray[ScalarT]
to_vec3(
    v: VecLike, dtype: Optional[Type[generic]] = None
) -> NDArray[generic]

Broadcast and coerce v to a Vec3 of type dtype.

Source code in atomlib/types.py
def to_vec3(v: VecLike, dtype: t.Optional[t.Type[numpy.generic]] = None) -> NDArray[numpy.generic]:
    """
    Broadcast and coerce `v` to a [`Vec3`][atomlib.types.Vec3] of type `dtype`.
    """

    try:
        v = numpy.broadcast_to(v, (3,)).astype(dtype or numpy.float64)
    except (ValueError, TypeError):
        raise TypeError("Expected a vector of 3 elements.") from None
    return v