konnektor.network_tools#

konnektor.network_tools.clustering#

class konnektor.network_tools.clustering.charge_clustering.ChargeClusterer#

Bases: _AbstractClusterer

Clusters molecules based on their formal charges

cluster_compounds(components: list[SmallMoleculeComponent]) dict[int, list[SmallMoleculeComponent]]#

Cluster compounds according to formal charge

Returns a dict which has keys of all present formal charge states, mapping to lists of the corresponding molecules

Clustering compounds based on scaffolds

This clusterer attempts to cluster compounds based on their scaffolds. It is built on rdkit’s rdScaffoldNetwork module.

class konnektor.network_tools.clustering.scaffold_clustering.ScaffoldClusterer(scaffold_looseness: int = 9)#

Bases: _AbstractClusterer

Parameters:

scaffold_looseness (int) – a heuristic to define to what extent alternate/smaller scaffolds can be used to match a certain molecule. this value decides how many heavy atoms from the largest scaffold other scaffolds may be permitted. a too high value may result in inappropriately generic scaffolds being used, while too low will result in too many scaffolds being identified

cid_components: dict[int, list[Component]]#
cid_scaffold: dict[int, str]#
cluster_compounds(components: list[Component])#

Cluster compounds according to a given algorithm

static find_solution(mol_to_candidates: dict[Mol, list[str]]) list[tuple[str, int]]#
static formulate_answer(solution: list[tuple[str, int]], mols_to_norm: dict[Component, Mol]) dict[str, list[Component]]#
static generate_scaffold_network(mols: list[Mol]) ScaffoldNetwork#
static match_scaffolds_to_source(network: ScaffoldNetwork, mols: list[Mol], hac_heuristic: int) dict[Mol, list[str]]#
static normalise_molecules(mols: list[Component]) dict[Component, Mol]#
scaffold_looseness: int#
class konnektor.network_tools.clustering.component_diversity_clustering.ComponentsDiversityClusterer(featurize: sklearn.base.TransformerMixin = scikit_mol.fingerprints.MorganFingerprintTransformer, cluster: sklearn.base.ClusterMixin = sklearn.cluster.KMeans, n_processes: int = 1)#

Bases: _AbstractClusterer

This class can be use to seperate components by different features, like charge or morgan fingerprints.

Parameters:
  • featurize (TransformerMixin, optional) – A scikit-learn and scikit-mol compatible featurizer, takes a rdkit mol and transforms to an np.array[number]. As default the morgan fingerprints are used.

  • cluster (ClusterMixin) – a scikit-learn compatible clustering algorithm. as default a KMeans(n_clusters=5, n_init=”auto”) is used.

  • parallel (int, optional) – tries to push the parallelization triggers of featurize and cluster

property cluster_centers: int#
cluster_compounds(components: list[Component]) dict[int, list[Component]]#

The method featurizes and clusters the molecules according to the features.

Parameters:

components (list[Component]) – the list of components, that should be seperated into different categories.

Returns:

the index represents the clusterid, the values are lists of Components, corresponding to the clusters.

Return type:

dict[int, list[Component]]

konnektor.network_tools.network_handling#

konnektor.network_tools.network_handling.merge.merge_networks(networks: list[LigandNetwork]) LigandNetwork#

Merging networks, is similar to a union of a set of nodes and edgees, if they are all connected via at least one edge. This means, that at least one node needs to be present in network1 and network2. If this is not the case, use the network concatenators.

Todo: find a mergable path in multiple sets of networks

Parameters:

networks (list[LigandNetwork]) – Networks for merging

Returns:

returns the merged network

Return type:

LigandNetwork

konnektor.network_tools.network_handling.merge.merge_two_networks(network1: LigandNetwork, network2: LigandNetwork) LigandNetwork#

Merging networks, is similar to a union of a set of nodes and edgees, if they are all connected via at least one edge. This means, that at least one node needs to be present in network1 and network2. If this is not the case, use the network concatenators.

Parameters:
  • network1 (LigandNetwork) – Network 1 for merging

  • network2 – Network 1 for merging

Returns:

returns the merged network

Return type:

LigandNetwork

konnektor.network_tools.network_handling.concatenate.append_component(network: LigandNetwork, component: Component, concatenator: NetworkConcatenator) LigandNetwork#

Add one node to the network, based on the provided concatenators algorithm.

Parameters:
  • network (LigandNetwork) – Network 1 for merging

  • component (Component) – append node to network

  • concatenator (NetworkConcatenator) – A network planner, that concatenates networks.

Returns:

returns the new network

Return type:

LigandNetwork

konnektor.network_tools.network_handling.concatenate.concatenate_networks(ligand_networks: Iterable[LigandNetwork], concatenator: NetworkConcatenator) LigandNetwork#

Concatenate networks, is similar to a union of a set of nodes and edgees, if they are all connected via at least one edge. This means, that at least one node needs to be present in network1 and network2. If this is not the case, use the network concatenators.

Parameters:
  • networks (Iterable[LigandNetwork]) – Network 1 for merging

  • concatenator (NetworkConcatenator) – A network planner, that concatenates networks.

Returns:

returns the concatenated network

Return type:

LigandNetwork

konnektor.network_tools.network_handling.delete.delete_component(network: LigandNetwork, component: Component | list[Component], must_stay_connected: bool = True) LigandNetwork#

Remove the desired component, which is a node of the graph, and its edges from the network.

Parameters:
  • network (LigandNetwork)

  • component (Union[Component, list[Component]]) – component to be removed from the network, which is a node of the graph.

  • must_stay_connected (bool) – ensure, that the resulting Network is still connected.

Returns:

returns a copy of the ligand network without the removed component and edges containing the component.

Return type:

LigandNetwork

konnektor.network_tools.network_handling.delete.delete_transformation(network: LigandNetwork, transformation: LigandAtomMapping | tuple[Component, Component] | list[LigandAtomMapping], must_stay_connected: bool = True) LigandNetwork#

Remove the desired edge from the network

Parameters:
  • network (LigandNetwork)

  • transformation (:Union[LigandAtomMapping, tuple[Component, Component], list[LigandAtomMapping]])

  • must_stay_connected (bool) – ensure, that the resulting Network is still connected.

Returns:

returns a copy of the ligand network without the removed edge.

Return type:

LigandNetwork