common#

class atomworks.io.common.KeyToIntMapper[source]#

Bases: object

Maps keys to unique integers based on the order of the first appearance of the key.

This is useful for mapping id’s such as chain_id, chain_entity, molecule_iid, etc. to integers.

Example: ```python

chain_id_to_int = KeyToIntMapper() chain_id_to_int(“A”) # 0 chain_id_to_int(“C”) # 1 chain_id_to_int(“A”) # 0 chain_id_to_int(“B”) # 2

```

atomworks.io.common.deduplicate_iterator(iterator: Iterable) Iterator[source]#

Deduplicate an iterator while preserving order.

atomworks.io.common.default(obj: Any, default: Any) Any[source]#
atomworks.io.common.exists(obj: Any) bool[source]#
atomworks.io.common.immutable_lru_cache(maxsize: int = 128, typed: bool = False, deepcopy: bool = True) Callable[source]#

An immutable version of lru_cache for caching functions that return mutable objects.

atomworks.io.common.listmap(func: Callable, *iterables) list[source]#

Like map, but returns a list instead of an iterator.

atomworks.io.common.md5_hash_string(s: str, length: int = 32) str[source]#

Generate an MD5 hash of a string and return the first length characters.

atomworks.io.common.not_isin(element: ndarray, array: ndarray, **isin_kwargs) ndarray[source]#

Like ~np.isin, but more efficient.

atomworks.io.common.sum_string_arrays(*objs: ndarray | str) ndarray[source]#

Sum a list of string arrays / strings into a single string array by concatenating them and determining the shortest string length to set as dtype.

atomworks.io.common.to_hashable(element: Any) Any[source]#

Convert an element to a hashable type.