network_tools#

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.

Parameters:

components (list[SmallMoleculeComponent])

Returns:

Dict of formal charge states mapped to lists of the corresponding molecules.

Return type:

dict[int, list[gufe.SmallMoleculeComponent]]

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

Bases: _AbstractClusterer

Clustering compounds based on scaffolds. Attempts to cluster compounds based on their scaffolds. Built on rdkit’s rdScaffoldNetwork module.

Parameters:

scaffold_looseness (int, optional) – A heuristic parameter 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. Assigning too high a value for scaffold_looseness may result in inappropriately generic scaffolds being used, while too low will result in too many scaffolds being identified. By default 9.

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

components (list[Component])

Returns:

cid_components

Return type:

dict[int, list[Component]]

static find_solution(mol_to_candidates: dict[Mol, list[tuple[str, int]]]) tuple[tuple[str, int], ...] | None#

Find the best scaffolds that cover all mols

Parameters:

mol_to_candidates (dict[Chem.Mol, list[tuple[str, int]]) – Dict of rdkit mols and their scaffolds as (scaffold smiles, n heavy atoms)

Returns:

List of (scaffold smiles, n heavy atoms)

Return type:

list[tuple[str, int]]

static formulate_answer(solution: tuple[tuple[str, int], ...] | None, mols_to_norm: dict[Component, Mol]) dict[str, list[Component]]#

Relate the solution scaffolds back to the input Components.

Parameters:
  • solution (list[tuple[str, int]]) – Solution scaffolds, such as those generated by ScaffoldClusterer.find_solution().

  • mols_to_norm (dict[Component, Chem.Mol])

Returns:

Dict of scaffold names and their corresponding Components.

Return type:

dict[str, list[Component]]

static generate_scaffold_network(mols: list[Mol]) ScaffoldNetwork#

Generate the scaffold network from rdkit mol objects.

Parameters:

mols (list[Chem.Mol])

Return type:

rdScaffoldNetwork.ScaffoldNetwork

static match_scaffolds_to_source(network: ScaffoldNetwork, mols: list[Mol], hac_heuristic: int) dict[Mol, list[tuple[str, int]]]#

Match scaffolds in network back to normalized input mols. i.e. for each molecule, determine which scaffolds can apply.

Parameters:
  • network (rdScaffoldNetwork.ScaffoldNetwork)

  • mols (list[Chem.Mol])

  • hac_heuristic (int)

Return type:

dict[Chem.Mol, list[tuple[str, int]]]

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 used to separate 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]. By default MorganFingerprintTransformer().

  • cluster (ClusterMixin, optional) – Clustering algorithm compatible with scikit-learn, by default KMeans(n_clusters=5, n_init=”auto”)

  • n_processes (int, optional) – Number of processes that can be used for the network generation, by default 1.

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

Featurize and cluster components according to their features.

Parameters:

components (list[Component])

Returns:

Clustered compounds, represented as {clusterid: [Component]}

Return type:

dict[int, list[Component]]

network_tools.network_handling#

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

Merge networks into a single LigandNetwork. networks must have nodes in common to be merged.

Parameters:

networks (list[LigandNetwork])

Returns:

Merged network

Return type:

LigandNetwork

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

Merge network1 with network2. At least one node needs to be present in both network1 and network2.

Parameters:
  • network1 (LigandNetwork)

  • network2 (LigandNetwork)

Returns:

Merged network

Return type:

LigandNetwork

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

Adds component as a node to network according to the provided concatenator algorithm.

Parameters:
  • network (LigandNetwork)

  • component (Component)

  • concatenator (NetworkConcatenator)

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 component and it corresponding edges from the network.

Parameters:
  • network (LigandNetwork)

  • component (Component | list[Component])

  • must_stay_connected (bool, optional) – Require that the resulting LigandNetwork is still connected, by default True.

Returns:

Copy of network without component or the corresponding edges.

Return type:

LigandNetwork

Raises:

RuntimeError – If the resulting LigandNetwork is not connected.

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

Remove transformation from network

Parameters:
  • network (LigandNetwork)

  • transformation (LigandAtomMapping | tuple[Component, Component] | list[LigandAtomMapping])

  • must_stay_connected (bool, optional) – Require that the resulting network remain connected, by default True,

Returns:

Copy of network without transformation.

Return type:

LigandNetwork

Raises:

RuntimeError – If the resulting LigandNetwork is not connected.