Color Refinement#

stereomolgraph.algorithms._color_refine.numpy_int_tuple_hash(arr: np.ndarray[tuple[int, ...], np.dtype[np.int64]], out: None | np.ndarray[tuple[Literal[1], ...], np.dtype[np.int64]] = None) np.ndarray#

Mimics the python SipHash hashing function for tuples of integers with numpy int64 arrays.

Return type:

ndarray

def SipHash(arr_slice):

h = 0x345678 mult = 1000003 length = len(arr_slice) for i in range(1, length + 1):

h = (h ^ arr_slice[i-1]) * mult mult += 82520 + 2 * (length - i)

return h + 97531

stereomolgraph.algorithms._color_refine.numpy_int_multiset_hash(arr: ndarray[tuple[int, ...], dtype[int64]], out: None | ndarray[tuple[Literal[1], ...], dtype[int64]] = None) ndarray#

Hash function for a multiset (order-independent with duplicates) of integers. Works by sorting the elements and then applying the tuple hashing function.

Return type:

ndarray

stereomolgraph.algorithms._color_refine.label_hash(mg: MolGraph, atom_labels: Collection[str] = ('atom_type',)) ndarray[tuple[int], dtype[int64]]#

Generates a hash for each atom based on choosen attributes.

Parameters:
  • mg (MolGraph) – MolGraph object containing the atoms.

  • atom_labels (Collection[str]) – Iterable of attribute names to use for hashing. (default: ('atom_type',))

Return type:

ndarray[tuple[int], dtype[int64]]

stereomolgraph.algorithms._color_refine.morgan_generator(mg: MolGraph, atom_labels: None | ndarray[tuple[int], dtype[int64]] = None) Iterator[ndarray[tuple[int], dtype[int64]]]#

Color refinement algorithm for MolGraph.

This algorithm refines the atom coloring based on their connectivity. Identical to the Weisfeiler-Lehman (1-WL) algorithm.

Parameters:
  • mg (MolGraph) – MolGraph object containing the atoms and their connectivity.

  • max_iter – Maximum number of iterations for refinement. Default is None, which means it will run until convergence.

Return type:

Iterator[ndarray[tuple[int], dtype[int64]]]

stereomolgraph.algorithms._color_refine.color_refine_hash_mg(graph: MolGraph) int#

Color-refined hash for plain MolGraph objects.

Return type:

int

stereomolgraph.algorithms._color_refine.color_refine_hash_smg(graph: StereoMolGraph) int#

Color-refined hash for StereoMolGraph objects.

Drops the extra sentinel slot the stereo generator appends.

Return type:

int

stereomolgraph.algorithms._color_refine.color_refine_hash_crg(graph: CondensedReactionGraph) int#

Color-refined hash for CondensedReactionGraph objects.

Return type:

int

stereomolgraph.algorithms._color_refine.color_refine_hash_scrg(graph: StereoCondensedReactionGraph) int#

Color-refined hash for StereoCondensedReactionGraph objects.

Return type:

int