From 9cb9fc3f29a7303f8c1fbdb1014de21e95158497 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Wed, 23 Oct 2024 13:39:11 -0700 Subject: [PATCH 01/21] renaming LigandNetworkPlanner to NetworkPlanner in docs --- src/konnektor/network_planners/NetworkPlanner.py | 4 ++-- .../generators/_abstract_network_generator.py | 8 ++++---- .../generators/cyclic_network_generator.py | 4 ++-- .../generators/minimal_spanning_tree_network_generator.py | 4 ++-- .../network_planners/generators/star_network_generator.py | 4 ++-- .../generators/twin_star_network_generator.py | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/konnektor/network_planners/NetworkPlanner.py b/src/konnektor/network_planners/NetworkPlanner.py index 167f390..984d110 100644 --- a/src/konnektor/network_planners/NetworkPlanner.py +++ b/src/konnektor/network_planners/NetworkPlanner.py @@ -16,8 +16,8 @@ class NetworkPlanner(abc.ABC): def __init__(self, mappers: Union[AtomMapper, list[AtomMapper]], scorer): - """This class is an implementation for the LigandNetworkPlanner interface. - It defines the std. class for a Konnektor LigandNetworkPlanner + """This class is an implementation for the NetworkPlanner interface. + It defines the std. class for a Konnektor NetworkPlanner Parameters ---------- diff --git a/src/konnektor/network_planners/generators/_abstract_network_generator.py b/src/konnektor/network_planners/generators/_abstract_network_generator.py index 30d310f..303e9ab 100644 --- a/src/konnektor/network_planners/generators/_abstract_network_generator.py +++ b/src/konnektor/network_planners/generators/_abstract_network_generator.py @@ -29,8 +29,8 @@ def __init__( progress: bool = False, _initial_edge_lister=None, ): - """This class is an implementation for the LigandNetworkPlanner interface. - It defines the std. class for a Konnektor LigandNetworkPlanner + """This class is an implementation for the NetworkPlanner interface. + It defines the std. class for a Konnektor NetworkPlanner Parameters ---------- @@ -44,8 +44,8 @@ def __init__( number of processes that can be used for the network generation. (default: 1) progress: bool, optional if true a progress bar will be displayed. (default: False) - _initial_edge_lister: LigandNetworkPlanner, optional - this LigandNetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. + _initial_edge_lister: NetworkPlanner, optional + this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner. (default: None) """ diff --git a/src/konnektor/network_planners/generators/cyclic_network_generator.py b/src/konnektor/network_planners/generators/cyclic_network_generator.py index 12c03c5..5493541 100644 --- a/src/konnektor/network_planners/generators/cyclic_network_generator.py +++ b/src/konnektor/network_planners/generators/cyclic_network_generator.py @@ -58,8 +58,8 @@ def __init__( n_processes: int, optional number of processes that can be used for the network generation. (default: 1) - _initial_edge_lister: LigandNetworkPlanner, optional - this LigandNetworkPlanner is used to give the initial set of edges. + _initial_edge_lister: NetworkPlanner, optional + this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. (default: MaximalNetworkPlanner) """ diff --git a/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py b/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py index e1939d1..5df336f 100644 --- a/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py +++ b/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py @@ -39,8 +39,8 @@ def __init__( number of processes that can be used for the network generation. (default: 1) progress: bool, optional if true a progress bar will be displayed. (default: False) - _initial_edge_lister: LigandNetworkPlanner, optional - this LigandNetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. + _initial_edge_lister: NetworkPlanner, optional + this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: diff --git a/src/konnektor/network_planners/generators/star_network_generator.py b/src/konnektor/network_planners/generators/star_network_generator.py index 83d19b1..062ed0e 100644 --- a/src/konnektor/network_planners/generators/star_network_generator.py +++ b/src/konnektor/network_planners/generators/star_network_generator.py @@ -42,8 +42,8 @@ def __init__( number of processes that can be used for the network generation. (default: 1) progress: bool, optional if true a progress bar will be displayed. (default: False) - _initial_edge_lister: LigandNetworkPlanner, optional - this LigandNetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. + _initial_edge_lister: NetworkPlanner, optional + this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: diff --git a/src/konnektor/network_planners/generators/twin_star_network_generator.py b/src/konnektor/network_planners/generators/twin_star_network_generator.py index 86e6c4f..f698379 100644 --- a/src/konnektor/network_planners/generators/twin_star_network_generator.py +++ b/src/konnektor/network_planners/generators/twin_star_network_generator.py @@ -45,8 +45,8 @@ def __init__( number of processes that can be used for the network generation. (default: 1) progress: bool, optional if true a progress bar will be displayed. (default: False) - _initial_edge_lister: LigandNetworkPlanner, optional - this LigandNetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. + _initial_edge_lister: NetworkPlanner, optional + this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: From af0bf95aad5ef154957641404cb556ac61ea0e93 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Thu, 24 Oct 2024 13:20:29 -0700 Subject: [PATCH 02/21] updating max_concatenator docstring to reflect code --- .../concatenators/max_concatenator.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/konnektor/network_planners/concatenators/max_concatenator.py b/src/konnektor/network_planners/concatenators/max_concatenator.py index 34e2566..9ca1cf8 100644 --- a/src/konnektor/network_planners/concatenators/max_concatenator.py +++ b/src/konnektor/network_planners/concatenators/max_concatenator.py @@ -24,19 +24,17 @@ def __init__( show_progress: bool = False, ): """ - This concatenators is connnecting two Networks with all possible - mappings. This is usually most useful for initial edge listing. + This concatenator connnects two Networks with all possible + mappings. This is usually most useful for initial edge listing. Parameters ---------- - mapper: AtomMapper - the atom mapper is required, to define the connection - between two ligands. + mappers: AtomMapper + the atom mapper is required to define the connection + between two ligands. scorer: AtomMappingScorer scoring function evaluating an atom mapping, and giving a score between [0,1]. - n_connecting_edges: int, optional - number of connecting edges. (default: 3) n_processes: int number of processes that can be used for the network generation. (default: 1) From 037114e1419da69834318bf232a88cef88697cc7 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Thu, 24 Oct 2024 13:21:53 -0700 Subject: [PATCH 03/21] fixing some class names in docstrings --- .../concatenators/_abstract_network_concatenator.py | 4 ++-- .../generators/_abstract_network_generator.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py b/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py index d2872e7..65ed548 100644 --- a/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py +++ b/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py @@ -28,8 +28,8 @@ def __init__( n_processes: int = 1, _initial_edge_lister=None, ): - """Base Class for the the LigandNetworkConcatenator classes. - It defines the std. class for a Konnektor LigandNetworkPlanner + """Base Class for the NetworkConcatenator classes. + It defines the std. class for a Konnektor NetworkConcatenator. Parameters ---------- diff --git a/src/konnektor/network_planners/generators/_abstract_network_generator.py b/src/konnektor/network_planners/generators/_abstract_network_generator.py index 303e9ab..19490d7 100644 --- a/src/konnektor/network_planners/generators/_abstract_network_generator.py +++ b/src/konnektor/network_planners/generators/_abstract_network_generator.py @@ -29,17 +29,18 @@ def __init__( progress: bool = False, _initial_edge_lister=None, ): - """This class is an implementation for the NetworkPlanner interface. - It defines the std. class for a Konnektor NetworkPlanner + """This class is an implementation for the NetworkGenerator interface. + It defines the std. class for a Konnektor NetworkGenerator. Parameters ---------- - mapper : AtomMapper + mappers : AtomMapper the AtomMappers to use to propose mappings. At least 1 required, but many can be given, in which case all will be tried to find the lowest score edges scorer : AtomMappingScorer any callable which takes a AtomMapping and returns a float + network_generator: n_processes: int, optional number of processes that can be used for the network generation. (default: 1) progress: bool, optional @@ -49,7 +50,7 @@ def __init__( However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner. (default: None) """ - # generic Network_Planner attribsd + # generic NetworkPlanner attribs super().__init__(mappers=mappers, scorer=scorer) # Konnektor specific variables From f1dd647f675b73d11bea713918f15ff194d729c9 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Thu, 24 Oct 2024 14:48:46 -0700 Subject: [PATCH 04/21] fixing typos --- .../concatenators/_abstract_network_concatenator.py | 2 +- .../concatenators/cyclic_concatenator.py | 1 + .../network_planners/concatenators/max_concatenator.py | 4 ++-- .../network_planners/concatenators/mst_concatenator.py | 10 +++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py b/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py index 65ed548..a0cce6c 100644 --- a/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py +++ b/src/konnektor/network_planners/concatenators/_abstract_network_concatenator.py @@ -33,7 +33,7 @@ def __init__( Parameters ---------- - mapper : AtomMapper + mappers : AtomMapper the AtomMappers to use to propose mappings. At least 1 required, but many can be given, in which case all will be tried to find the lowest score edges diff --git a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py index eb43ad6..eb1fba7 100644 --- a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py +++ b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py @@ -19,6 +19,7 @@ class CyclicConcatenator(NetworkConcatenator): def __init__( self, + # TODO: should this be "mappers" for API consistency, or is it only one mapper by design? mapper: AtomMapper, scorer: AtomMappingScorer, n_connecting_cycles: int = 2, diff --git a/src/konnektor/network_planners/concatenators/max_concatenator.py b/src/konnektor/network_planners/concatenators/max_concatenator.py index 9ca1cf8..6848784 100644 --- a/src/konnektor/network_planners/concatenators/max_concatenator.py +++ b/src/konnektor/network_planners/concatenators/max_concatenator.py @@ -24,7 +24,7 @@ def __init__( show_progress: bool = False, ): """ - This concatenator connnects two Networks with all possible + A NetworkConcatenator that connects two Networks with all possible mappings. This is usually most useful for initial edge listing. Parameters @@ -58,7 +58,7 @@ def concatenate_networks( Parameters ---------- ligand_networks: Iterable[LigandNetwork] - an iterable of ligand networks, that shall be connected. + An iterable of LigandNetworks to connect. Returns ------- diff --git a/src/konnektor/network_planners/concatenators/mst_concatenator.py b/src/konnektor/network_planners/concatenators/mst_concatenator.py index 63054b8..1a84357 100644 --- a/src/konnektor/network_planners/concatenators/mst_concatenator.py +++ b/src/konnektor/network_planners/concatenators/mst_concatenator.py @@ -27,8 +27,8 @@ def __init__( _initial_edge_lister: NetworkConcatenator = None, ): """ - This concatenators is connnecting two Networks with a kruskal like - approach up to the number of connecting edges. + A NetworkConcatenator that connects two Networks with a Kruskal-like + approach, up to the number of connecting edges. Parameters ---------- @@ -39,7 +39,7 @@ def __init__( scoring function evaluating an atom mapping, and giving a score between [0,1]. n_connecting_edges: int, optional - number of connecting edges. (default: 2) + maximum number of connecting edges. (default: 2) n_processes: int number of processes that can be used for the network generation. (default: 1) @@ -49,7 +49,7 @@ def __init__( scorer=scorer, network_generator=MstNetworkAlgorithm(), n_processes=n_processes, - _initial_edge_lister=None, + _initial_edge_lister=None, ## TODO: should this be _initial_edge_lister? ) self.n_connecting_edges = n_connecting_edges @@ -57,7 +57,7 @@ def concatenate_networks( self, ligand_networks: Iterable[LigandNetwork] ) -> LigandNetwork: """ - concatenate the giving networks. + Concatenate the given networks. Parameters ---------- From 5720c00a27a338842b0cb4fa572e8da9b954263b Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Thu, 24 Oct 2024 15:35:00 -0700 Subject: [PATCH 05/21] fixing typos in a few generators --- .../generators/_abstract_network_generator.py | 10 ++--- .../generators/clustered_network_generator.py | 16 ++++---- .../generators/cyclic_network_generator.py | 37 +++++++++++-------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/konnektor/network_planners/generators/_abstract_network_generator.py b/src/konnektor/network_planners/generators/_abstract_network_generator.py index 19490d7..382ee81 100644 --- a/src/konnektor/network_planners/generators/_abstract_network_generator.py +++ b/src/konnektor/network_planners/generators/_abstract_network_generator.py @@ -39,14 +39,14 @@ def __init__( but many can be given, in which case all will be tried to find the lowest score edges scorer : AtomMappingScorer - any callable which takes a AtomMapping and returns a float + Any callable which takes a AtomMapping and returns a float network_generator: n_processes: int, optional - number of processes that can be used for the network generation. (default: 1) + Number of processes that can be used for the network generation. (default: 1) progress: bool, optional - if true a progress bar will be displayed. (default: False) + If `True`, displays a progress bar. (default: False) _initial_edge_lister: NetworkPlanner, optional - this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. + The NetworkPlanner to use to create the initial set of edges. For standard usage, the MaximalNetworkPlanner is used. However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner. (default: None) """ @@ -94,7 +94,7 @@ def generate_ligand_network(self, components: Iterable[Component]) -> LigandNetw Parameters ---------- components : Iterable[Component] - the ligands to include in the Network + the ligands to include in the Network Returns ------- diff --git a/src/konnektor/network_planners/generators/clustered_network_generator.py b/src/konnektor/network_planners/generators/clustered_network_generator.py index c1ec8a4..e8866e4 100644 --- a/src/konnektor/network_planners/generators/clustered_network_generator.py +++ b/src/konnektor/network_planners/generators/clustered_network_generator.py @@ -40,7 +40,7 @@ def __init__( clusterer: ComponentsDiversityClusterer = ComponentsDiversityClusterer( featurize=RDKitFingerprintTransformer(), cluster=KMeans(n_clusters=3) ), - mappers: Union[AtomMapper, list[AtomMapper]] = None, + mappers: Union[AtomMapper, list[AtomMapper]] = None, # include None in this union? scorer=None, n_processes: int = 1, progress: bool = False, @@ -51,19 +51,19 @@ def __init__( The algorithm works as follows: 1. Cluster `Component` s with the `clusterer` obj. 2. Build sub-networks in the clusters using the `sub_network_planners`. - 3. Concatenate all sub-networks using the `concatenator` in order to build the final network. + 3. Concatenate all sub-networks using the `concatenator` to build the final network. Parameters ---------- - clusterer: ComponentsDiversityClusterer - This class is seperating the `Component` s along the first dimension. sub_network_planners: Iterable[NetworkGenerator] - The clusters, are then seperatley translated to sub networks by the sub_network_planners + NetworkGenerator(s) used to translate clusters to sub-networks. concatenator: NetworkConcatenator - The `NetworkConcatenator` is connecting the different sub networks. - mapper: Union[AtomMapper, list[AtomMapper]] - the atom mapper is required, to define the connection between two ligands, if only `NetworkConcatenator` or `NetworkGenerator` classes are passed + A `NetworkConcatenator` used to connect sub-networks. + clusterer: ComponentsDiversityClusterer + Separates the `Component` s along the first dimension. + mappers: Union[AtomMapper, list[AtomMapper]] + Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. Otherwise, (?) (default:None) scorer: AtomMappingScorer scoring function evaluating an `AtomMapping`, and giving a score between [0,1], if only `NetworkConcatenator` or `NetworkGenerator` classes are passed progress: bool, optional diff --git a/src/konnektor/network_planners/generators/cyclic_network_generator.py b/src/konnektor/network_planners/generators/cyclic_network_generator.py index 5493541..aebf93d 100644 --- a/src/konnektor/network_planners/generators/cyclic_network_generator.py +++ b/src/konnektor/network_planners/generators/cyclic_network_generator.py @@ -27,40 +27,45 @@ def __init__( _initial_edge_lister: NetworkGenerator = None, ): """ - The `CyclicNetworkGenerator` is generating a network based on many network cycles. T - his is of interest for analyzing the uncertainty of FE Estimates along the thermodynamic cycles and possibly correct the estimates with cycle closure analysis. + A `NetworkGenerator` that generates a network based on many network cycles. + This is of interest for analyzing the uncertainty of FE Estimates along thermodynamic + cycles and possibly for correcting the estimates with cycle closure analysis. The greedy algorithm builds the network up from a nodewise perspective. - For each node, the algorithm generates all cycles of size `cycle_sizes` and assigns a score to each cylce as the sum of all sub-scores. - Next it selects the `node_present_in_cyces` best score perfoming and node diversity increasing (see below) cycles per node. + For each node, the algorithm generates all cycles of size `cycle_sizes` and assigns a score to each cycle as the sum of all sub-scores. + Next, it selects the `node_present_in_cycles` best score performing and node diversity increasing (see below) cycles per node. The set of selected `Transformations` constructs the graph. - The node diversity criterion is an addition, which biases to spread the cycles on the graph eaqually between all `Components` + The node diversity criterion is an addition which biases to spread the cycles on the graph equally between all `Components`. - The number of cylces, around each `Component` can be defined by `component_present_in_cycles` and allowed cylce size can be tweaked with `cycle_sizes`. For `cycle_sizes` either an integer for providing an expected cycle size (e.g. `3`) or a range of allowed cycle sizes (e.g. `[3,4]`). + The number of cycles around each `Component` can be defined by `component_present_in_cycles` + and the allowed cycle size can be tweaked with `cycle_sizes`. - This layout has a well distributed connectivity between all `Component` s which increases the robustness very well, but still allows for a better graph score then the Twin Star Network, as the connectivity distribution is biased not enforced. - The large number of cycles might be very useful for statical analysis. Nevertheless, the network has an increased amount of `Transformation` s + This layout has well-distributed connectivity between all `Component` s, which increases the robustness very well, + but still allows for a better graph score then the Twin Star Network, as the connectivity distribution is biased not enforced. + The large number of cycles might be very useful for statistical analysis. Nevertheless, the network has an increased amount of `Transformation`s. Parameters ---------- mappers : Union[AtomMapper, list[AtomMapper]] - the AtomMappers to use to propose mappings. At least 1 required, + AtomMapper(s) to use to propose mappings. At least 1 required, but many can be given, in which case all will be tried to find the - lowest score edges + lowest score edges. scorer : AtomMappingScorer - any callable which takes a AtomMapping and returns a float + Any callable which takes a AtomMapping and returns a float. node_present_in_cycles: int - the number of cycles, the node should be present in. + The number of cycles the node should be present in. cycle_sizes: Union[int, List[int]] - the cycle size in the graph, that is used for designing the graph. + The cycle size to be used for designing the graph. When providing a list[int], a range of sizes is allowed (e.g. `[3,4]`). (default: 3) n_processes: int, optional - number of processes that can be used for the network generation. + Number of processes that can be used for the network generation. (default: 1) + progress: bool, optional + If `True`, displays a progress bar. (default: False) _initial_edge_lister: NetworkPlanner, optional - this NetworkPlanner is used to give the initial set of edges. - For standard usage, the Maximal NetworPlanner is used. (default: MaximalNetworkPlanner) + The NetworkPlanner used to give the initial set of edges. + For standard usage, the MaximalNetworkPlanner is used. (default: MaximalNetworkPlanner) """ network_generator = nx_CNG( From 9a1fccec4b73363a799fc1b6321fe963e4a181c4 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 25 Oct 2024 14:34:33 -0700 Subject: [PATCH 06/21] finishing first pass of generator docstring --- .../generators/explicit_network_generator.py | 6 ++--- .../generators/maximal_network_generator.py | 17 +++++++----- ...minimal_spanning_tree_network_generator.py | 12 +++++---- .../n_node_edges_network_generator.py | 4 +-- ...minimal_spanning_tree_network_generator.py | 10 ++++--- .../generators/star_network_generator.py | 11 +++++--- .../generators/twin_star_network_generator.py | 27 +++++++++++-------- 7 files changed, 51 insertions(+), 36 deletions(-) diff --git a/src/konnektor/network_planners/generators/explicit_network_generator.py b/src/konnektor/network_planners/generators/explicit_network_generator.py index c6af132..38657b4 100644 --- a/src/konnektor/network_planners/generators/explicit_network_generator.py +++ b/src/konnektor/network_planners/generators/explicit_network_generator.py @@ -25,11 +25,11 @@ def __init__( Parameters ---------- mapper: AtomMapper - the atom mapper is required, to define the connection between two ligands. + Defines the connection between two ligands. scorer: AtomMappingScorer scoring function evaluating an atom mapping, and giving a score between [0,1]. n_processes: int - number of processes used to build the ligand network + number of processes to use to build the ligand network progress: bool, optional if true a progress bar will be displayed. (default: False) """ @@ -48,7 +48,7 @@ def generate_ligand_network( """ Create a network with pre-defined edges. - This class is can be used as initial_edge_lister + This can be used as initial_edge_lister Parameters ---------- diff --git a/src/konnektor/network_planners/generators/maximal_network_generator.py b/src/konnektor/network_planners/generators/maximal_network_generator.py index 1f59aa5..3b241a2 100644 --- a/src/konnektor/network_planners/generators/maximal_network_generator.py +++ b/src/konnektor/network_planners/generators/maximal_network_generator.py @@ -22,14 +22,17 @@ def __init__( n_processes: int = 1, ): """ - The `MaximalNetworkGenerator` builds for given set of `Component` s a fully connected graph under the assumption each `Component` can be connected to another. - The `Transformation` s of this graph are realized as `AtomMapping` s of pairwise `Component` s. If not all mappings can be created, it will ignore the mapping failure, and return a nearly fully connected graph. + The `MaximalNetworkGenerator` builds a fully connected graph for given set of `Component` s. + It assumes each `Component` can be connected to every other `Component`. + The `Transformation` s of this graph are realized as `AtomMapping` s of pairwise `Component` s. + If not all mappings can be created, it will ignore the mapping failure and return a nearly fully connected graph. - Note: This approach is not very suitable for Free Energy calculations in application cases. However, this approach is very important, as all above approaches use this as an initial solution, they filter down to gain the desired design. + Note: This approach is not very suitable for Free Energy calculations in application cases. + However, this approach is very important, as all other approaches use the Maximal Network as an initial solution, + then remove edges to achieve the desired design. - - This class is recommended as initial_edge_lister for other approaches. - > **Note**: the `MaximalNetworkGenerator` is parallelized and the number of CPUs can be given with `n_processes`. + This class is recommended as an `initial_edge_lister` for other approaches. + > **Note**: the `MaximalNetworkGenerator` is parallelized and the number of CPUs can be given with `n_processes`. > All other approaches in Konnektor benefit from this parallelization and you can use this parallelization with `n_processes` key word during class construction. Parameters @@ -58,7 +61,7 @@ def generate_ligand_network(self, components: Iterable[Component]) -> LigandNetw This will attempt to create (and optionally score) all possible mappings (up to $N(N-1)/2$ for each mapper given). There may be fewer actual - mappings that this because, when a mapper cannot return a mapping for a + mappings than this, because when a mapper cannot return a mapping for a given pair, there is simply no suggested mapping for that pair. This network is typically used as the starting point for other network generators (which then optimize based on the scores) or to debug atom diff --git a/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py b/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py index 5df336f..06e805a 100644 --- a/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py +++ b/src/konnektor/network_planners/generators/minimal_spanning_tree_network_generator.py @@ -20,13 +20,14 @@ def __init__( _initial_edge_lister: NetworkGenerator = None, ): """ - The `MinimalSpanningTreeNetworkGenerator`, builds an minimal spanning tree (MST) network for a given set of `Component` s. The `Transformation` s of the Network, - are represented by an `AtomMapping` s, which are scored by a `AtomMappingScorer`. + The `MinimalSpanningTreeNetworkGenerator`, builds an minimal spanning tree (MST) network for a given set of `Component` s.\ + The `Transformation` s of the Network are represented by an `AtomMapping` s, which are scored by a `AtomMappingScorer`. - For the MST algorithm the Kruskal Algorithm is used. + For the MST algorithm, the Kruskal Algorithm is used. The MST algorithm gives the optimal graph score possible and the minimal required set of `Transformations`. - This makes the MST Network very efficient. However, the MST is not very robust, in case of one failing `Transformation`, the Network is immediatly disconnected. + This makes the MST Network very efficient. However, the MST is not very robust, in case of one failing + `Transformation`, the Network is immediatly disconnected. The disconnectivity will translate to a loss of `Component` s in the final FE Network. Parameters @@ -41,7 +42,8 @@ def __init__( if true a progress bar will be displayed. (default: False) _initial_edge_lister: NetworkPlanner, optional this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. - However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) + However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner. + (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: _initial_edge_lister = MaximalNetworkGenerator( diff --git a/src/konnektor/network_planners/generators/n_node_edges_network_generator.py b/src/konnektor/network_planners/generators/n_node_edges_network_generator.py index 2ae09fe..3fc678e 100644 --- a/src/konnektor/network_planners/generators/n_node_edges_network_generator.py +++ b/src/konnektor/network_planners/generators/n_node_edges_network_generator.py @@ -25,8 +25,8 @@ def __init__( """ The N-Node Edges Network tries to add more redundancy to the MST Network and tries to improve the robustness. - The algorithm first build a MST Network. - After this it will add best score performing `Transformations` in order to guarantee a 'Component' connectivity of `target_node_connectivity`. + The algorithm first build a MST Network. Then it will add best score performing `Transformations` + to guarantee a 'Component' connectivity of `target_node_connectivity`. Parameters diff --git a/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py b/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py index 53ba275..16316f7 100644 --- a/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py +++ b/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py @@ -21,12 +21,14 @@ def __init__( _initial_edge_lister: NetworkGenerator = None, ): """ - The `RedundantMinimalSpanningTreeNetworkGenerator` is an approach, that tries to increase the robustness over `Transformation` failures in an MST like network. + The `RedundantMinimalSpanningTreeNetworkGenerator` is an approach that tries to increase + robustness to `Transformation` failures in an MST-like network. - The algorithm executes the MST algorithm `n_redundancy` times, always removes already selected `Transformations` in each iteration, and finally builds the overlay of all the newtorks. - This is constructing the Redundant MST Network. + This algorithm executes the MST algorithm `n_redundancy` times, always removing + already-selected`Transformations` in each iteration, and finally builds the overlay of all the newtorks. + This is constructs the Redundant MST Network. - In this way the number of edges is increased, but also the network is less vulnerable to `Transformation` failures. + In this way, the number of edges is increased, but the network is also less vulnerable to `Transformation` failures. Parameters ---------- diff --git a/src/konnektor/network_planners/generators/star_network_generator.py b/src/konnektor/network_planners/generators/star_network_generator.py index 062ed0e..ac74c2a 100644 --- a/src/konnektor/network_planners/generators/star_network_generator.py +++ b/src/konnektor/network_planners/generators/star_network_generator.py @@ -22,13 +22,15 @@ def __init__( _initial_edge_lister: NetworkGenerator = None, ): """ - The Star Network is one of the most edge efficient layouts, it basically places all `Transformations` around one central `Component`. + The Star Network is one of the most edge efficient layouts, it basically places + all `Transformations` around one central `Component`. - The algorithm constructs in a first step all possilbe `Transformations`. + The algorithm constructs in a first step all possible `Transformations`. Next it selects in the default variant the in average best transformation score performing `Component` as the central component. Finally all Components are connected with a `Transformation` to the central `Component` - The Star Netwrok is most edge efficient, but not most graph score efficient, as it has to find a central `Component`, which usually is a compromise for all 'Component's. + The Star Netwrok is most edge efficient, but not most graph score efficient, as it has to find a + central `Component`, which usually is a compromise for all 'Component's. From a robustness point of view, the Star Network, will immediatly be disconnected if one `Transformation` fails. However the loss of `Component` s is very limited, as only one ligand is lost per `Transformation` failure. @@ -44,7 +46,8 @@ def __init__( if true a progress bar will be displayed. (default: False) _initial_edge_lister: NetworkPlanner, optional this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. - However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) + However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. + (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: _initial_edge_lister = MaximalNetworkGenerator( diff --git a/src/konnektor/network_planners/generators/twin_star_network_generator.py b/src/konnektor/network_planners/generators/twin_star_network_generator.py index f698379..9e47b23 100644 --- a/src/konnektor/network_planners/generators/twin_star_network_generator.py +++ b/src/konnektor/network_planners/generators/twin_star_network_generator.py @@ -21,16 +21,20 @@ def __init__( _initial_edge_lister: NetworkGenerator = None, ): """ - The Twin Star Network is an expansion to the Star Network. It can be described as multiple star networks, that are overlayed. - - The algorithm is first calculating all possible `Transformation` s for all `Component` s. - Next the in average `n_centers` (default: 2) best performing `Component` s over all transfromation scores are selected and placed into the center of the network. - Finally all components are connected to the selected centers, resulting in $n_{Transformations} = n_{centers}*(n_{Componentes}-n_{centers})$ - - This approach has in the default version the doubled number of `Transformations` compared to the Star Network and therefore also has an increase graph cost. - However on the plus side, this approach builds a lot graph cycles, which could be used to estimate the uncertainty of FE calculations. - Another important aspect is that the node connectivity is centralized around the `n_centers`. This means, - that the selection of the central ligands is very important, as they have a large impact on the `Transformations`. + The Twin Star Network is an expansion to the Star Network. It can be described as multiple star networks that are overlayed. + + The algorithm first calculates all possible `Transformation` s for all `Component` s. + Next, the in average `n_centers` (default: 2) best performing `Component` s over all + transfromation scores are selected and placed into the center of the network. + Finally all components are connected to the selected centers, resulting + in $n_{Transformations} = n_{centers}*(n_{Componentes}-n_{centers})$ + + This approach has, in the default version, double the number of `Transformations` + compared to the Star Network, and therefore also an increased graph cost. + On the plus side, this approach builds many graph cycles, which could be used to estimate the uncertainty of FE calculations. + Another important aspect is that the node connectivity is centralized around the `n_centers` + This means that the selection of the central ligands is very important, as they have a large + impact on the `Transformations`. The `n_centers` option allows you to change the Twin Star to a Triplet Star Network or more. Parameters @@ -47,7 +51,8 @@ def __init__( if true a progress bar will be displayed. (default: False) _initial_edge_lister: NetworkPlanner, optional this NetworkPlanner is used to give the initial set of edges. For standard usage, the Maximal NetworPlanner is used. - However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. (default: MaximalNetworkPlanner) + However in large scale approaches, it might be interesting to use the heuristicMaximalNetworkPlanner.. + (default: MaximalNetworkPlanner) """ if _initial_edge_lister is None: _initial_edge_lister = MaximalNetworkGenerator( From fae4273791703ca674ef8d890250e716ffd4147e Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 8 Nov 2024 13:49:54 -0800 Subject: [PATCH 07/21] mapper->mappers --- .../concatenators/cyclic_concatenator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py index eb1fba7..f783c07 100644 --- a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py +++ b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py @@ -20,7 +20,7 @@ class CyclicConcatenator(NetworkConcatenator): def __init__( self, # TODO: should this be "mappers" for API consistency, or is it only one mapper by design? - mapper: AtomMapper, + mappers: Union[AtomMapper, Iterable[AtomMapper]], scorer: AtomMappingScorer, n_connecting_cycles: int = 2, cycle_sizes: Union[int, list[int]] = 3, @@ -33,12 +33,12 @@ def __init__( Parameters ---------- - mapper: AtomMapper - the atom mapper is required, to define the connection - between two ligands. + mappers: AtomMapper + The AtomMapper(s) to use to propose mappings. At least 1 required, + but many can be given, in which case all will be tried to find the + lowest score edges scorer: AtomMappingScorer - scoring function evaluating an atom mapping, and giving a - score between [0,1]. + Any callable which takes a AtomMapping and returns a float between [0,1] n_connecting_cycles: int, optional build at least n cycles between th networks. (default: 2) cycle_sizes: Union[int, list[int]], optional @@ -50,11 +50,11 @@ def __init__( """ if _initial_edge_lister is None: _initial_edge_lister = MaxConcatenator( - mappers=mapper, scorer=scorer, n_processes=n_processes + mappers=mappers, scorer=scorer, n_processes=n_processes ) super().__init__( - mappers=mapper, + mappers=mappers, scorer=scorer, network_generator=MstNetworkAlgorithm(), n_processes=n_processes, From 3e4a89c8cc27538f1389f6e81ca3bb1a0b966a06 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 8 Nov 2024 13:59:18 -0800 Subject: [PATCH 08/21] fixing network typo --- examples/konnektor_networks.ipynb | 2 +- .../network_planners/generators/star_network_generator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/konnektor_networks.ipynb b/examples/konnektor_networks.ipynb index daa2390..0048c81 100644 --- a/examples/konnektor_networks.ipynb +++ b/examples/konnektor_networks.ipynb @@ -76,7 +76,7 @@ "Next it selects in the default variant the in average best transformation score performing `Component` as the central component.\n", "Finally all Components are connected with a `Transformation` to the central `Component`\n", "\n", - "The Star Netwrok is most edge efficient, but not most graph score efficient, as it has to find a central `Component`, which usually is a compromise for all 'Component's.\n", + "The Star Network is most edge efficient, but not most graph score efficient, as it has to find a central `Component`, which usually is a compromise for all 'Component's.\n", "From a robustness point of view, the Star Network, will immediatly be disconnected if one `Transformation` fails. \n", "However the loss of `Component`s is very limited, as only one ligand is lost per `Transformation` failure." ] diff --git a/src/konnektor/network_planners/generators/star_network_generator.py b/src/konnektor/network_planners/generators/star_network_generator.py index ac74c2a..a9f6b5c 100644 --- a/src/konnektor/network_planners/generators/star_network_generator.py +++ b/src/konnektor/network_planners/generators/star_network_generator.py @@ -29,7 +29,7 @@ def __init__( Next it selects in the default variant the in average best transformation score performing `Component` as the central component. Finally all Components are connected with a `Transformation` to the central `Component` - The Star Netwrok is most edge efficient, but not most graph score efficient, as it has to find a + The Star Network is most edge efficient, but not most graph score efficient, as it has to find a central `Component`, which usually is a compromise for all 'Component's. From a robustness point of view, the Star Network, will immediatly be disconnected if one `Transformation` fails. However the loss of `Component` s is very limited, as only one ligand is lost per `Transformation` failure. From d126c2cdd7960608efb0cc0910981a9972aedaff Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Tue, 12 Nov 2024 10:40:33 -0800 Subject: [PATCH 09/21] removing completed todo --- .../network_planners/concatenators/cyclic_concatenator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py index f783c07..a4d7baa 100644 --- a/src/konnektor/network_planners/concatenators/cyclic_concatenator.py +++ b/src/konnektor/network_planners/concatenators/cyclic_concatenator.py @@ -19,7 +19,6 @@ class CyclicConcatenator(NetworkConcatenator): def __init__( self, - # TODO: should this be "mappers" for API consistency, or is it only one mapper by design? mappers: Union[AtomMapper, Iterable[AtomMapper]], scorer: AtomMappingScorer, n_connecting_cycles: int = 2, From 2a3170b853a81ba96fa91ff43d19b092e9d07541 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz <31974495+atravitz@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:31:18 -0800 Subject: [PATCH 10/21] Apply suggestions from code review Co-authored-by: Hannah Baumann <43765638+hannahbaumann@users.noreply.github.com> --- .../network_planners/generators/cyclic_network_generator.py | 2 +- .../redundant_minimal_spanning_tree_network_generator.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/konnektor/network_planners/generators/cyclic_network_generator.py b/src/konnektor/network_planners/generators/cyclic_network_generator.py index aebf93d..b4fc3ca 100644 --- a/src/konnektor/network_planners/generators/cyclic_network_generator.py +++ b/src/konnektor/network_planners/generators/cyclic_network_generator.py @@ -41,7 +41,7 @@ def __init__( and the allowed cycle size can be tweaked with `cycle_sizes`. This layout has well-distributed connectivity between all `Component` s, which increases the robustness very well, - but still allows for a better graph score then the Twin Star Network, as the connectivity distribution is biased not enforced. + but still allows for a better graph score then the Twin Star Network, as the connectivity distribution is biased and not enforced. The large number of cycles might be very useful for statistical analysis. Nevertheless, the network has an increased amount of `Transformation`s. diff --git a/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py b/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py index 16316f7..038812e 100644 --- a/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py +++ b/src/konnektor/network_planners/generators/redundant_minimal_spanning_tree_network_generator.py @@ -25,7 +25,7 @@ def __init__( robustness to `Transformation` failures in an MST-like network. This algorithm executes the MST algorithm `n_redundancy` times, always removing - already-selected`Transformations` in each iteration, and finally builds the overlay of all the newtorks. + already-selected `Transformations` in each iteration, and finally builds the overlay of all the networks. This is constructs the Redundant MST Network. In this way, the number of edges is increased, but the network is also less vulnerable to `Transformation` failures. From 1df4ab767fae0562818a3dd76bd5412343a669fb Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 15 Nov 2024 07:58:59 -0800 Subject: [PATCH 11/21] adding to maximalnetworkgenerator docstring --- .../network_planners/generators/maximal_network_generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/konnektor/network_planners/generators/maximal_network_generator.py b/src/konnektor/network_planners/generators/maximal_network_generator.py index 3b241a2..30a18d2 100644 --- a/src/konnektor/network_planners/generators/maximal_network_generator.py +++ b/src/konnektor/network_planners/generators/maximal_network_generator.py @@ -27,7 +27,8 @@ def __init__( The `Transformation` s of this graph are realized as `AtomMapping` s of pairwise `Component` s. If not all mappings can be created, it will ignore the mapping failure and return a nearly fully connected graph. - Note: This approach is not very suitable for Free Energy calculations in application cases. + Note: This approach is not recommended for Free Energy calculations in application cases, as it is + very computationally expensive. However, this approach is very important, as all other approaches use the Maximal Network as an initial solution, then remove edges to achieve the desired design. From 6e612907553509c04e369ca92a01da8135ea4f4c Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 15 Nov 2024 08:06:17 -0800 Subject: [PATCH 12/21] adding description for network_generator argument --- .../network_planners/generators/_abstract_network_generator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/konnektor/network_planners/generators/_abstract_network_generator.py b/src/konnektor/network_planners/generators/_abstract_network_generator.py index 382ee81..ef7f8d0 100644 --- a/src/konnektor/network_planners/generators/_abstract_network_generator.py +++ b/src/konnektor/network_planners/generators/_abstract_network_generator.py @@ -24,6 +24,7 @@ def __init__( self, mappers: Union[AtomMapper, list[AtomMapper]], scorer, + ## TODO: rename this to network_algorithm? network_generator: _AbstractNetworkAlgorithm, n_processes: int = 1, progress: bool = False, @@ -40,7 +41,7 @@ def __init__( lowest score edges scorer : AtomMappingScorer Any callable which takes a AtomMapping and returns a float - network_generator: + network_generator: the network algorithm to use n_processes: int, optional Number of processes that can be used for the network generation. (default: 1) progress: bool, optional From ae0973b49bb47d9656f9e26b69917535c0d234db Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 15 Nov 2024 09:09:08 -0800 Subject: [PATCH 13/21] making ClusterNetworkGenerator require mappers param to match parent class --- .../generators/clustered_network_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/konnektor/network_planners/generators/clustered_network_generator.py b/src/konnektor/network_planners/generators/clustered_network_generator.py index e8866e4..5ba0014 100644 --- a/src/konnektor/network_planners/generators/clustered_network_generator.py +++ b/src/konnektor/network_planners/generators/clustered_network_generator.py @@ -35,12 +35,12 @@ class ClusteredNetworkGenerator(NetworkGenerator): def __init__( self, + mappers: Union[AtomMapper, list[AtomMapper], None], sub_network_planners: Iterable[NetworkGenerator] = (CyclicNetworkGenerator,), concatenator: NetworkConcatenator = MstConcatenator, clusterer: ComponentsDiversityClusterer = ComponentsDiversityClusterer( featurize=RDKitFingerprintTransformer(), cluster=KMeans(n_clusters=3) ), - mappers: Union[AtomMapper, list[AtomMapper]] = None, # include None in this union? scorer=None, n_processes: int = 1, progress: bool = False, @@ -63,7 +63,7 @@ def __init__( clusterer: ComponentsDiversityClusterer Separates the `Component` s along the first dimension. mappers: Union[AtomMapper, list[AtomMapper]] - Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. Otherwise, (?) (default:None) + Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. scorer: AtomMappingScorer scoring function evaluating an `AtomMapping`, and giving a score between [0,1], if only `NetworkConcatenator` or `NetworkGenerator` classes are passed progress: bool, optional From 6c237ac8011333675a10136a05495b8b34c0c0d6 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 15 Nov 2024 09:23:29 -0800 Subject: [PATCH 14/21] Revert "making ClusterNetworkGenerator require mappers param to match parent class" This reverts commit ae0973b49bb47d9656f9e26b69917535c0d234db. --- .../generators/clustered_network_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/konnektor/network_planners/generators/clustered_network_generator.py b/src/konnektor/network_planners/generators/clustered_network_generator.py index 5ba0014..e8866e4 100644 --- a/src/konnektor/network_planners/generators/clustered_network_generator.py +++ b/src/konnektor/network_planners/generators/clustered_network_generator.py @@ -35,12 +35,12 @@ class ClusteredNetworkGenerator(NetworkGenerator): def __init__( self, - mappers: Union[AtomMapper, list[AtomMapper], None], sub_network_planners: Iterable[NetworkGenerator] = (CyclicNetworkGenerator,), concatenator: NetworkConcatenator = MstConcatenator, clusterer: ComponentsDiversityClusterer = ComponentsDiversityClusterer( featurize=RDKitFingerprintTransformer(), cluster=KMeans(n_clusters=3) ), + mappers: Union[AtomMapper, list[AtomMapper]] = None, # include None in this union? scorer=None, n_processes: int = 1, progress: bool = False, @@ -63,7 +63,7 @@ def __init__( clusterer: ComponentsDiversityClusterer Separates the `Component` s along the first dimension. mappers: Union[AtomMapper, list[AtomMapper]] - Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. + Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. Otherwise, (?) (default:None) scorer: AtomMappingScorer scoring function evaluating an `AtomMapping`, and giving a score between [0,1], if only `NetworkConcatenator` or `NetworkGenerator` classes are passed progress: bool, optional From b66f0e1b0415313806cfaefa13a8839124cf9bc2 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Fri, 15 Nov 2024 09:29:30 -0800 Subject: [PATCH 15/21] fixing typo in file name --- ...d_network_generator.py => test_clustered_network_generator.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/konnektor/tests/network_planners/generators/{test_clusterd_network_generator.py => test_clustered_network_generator.py} (100%) diff --git a/src/konnektor/tests/network_planners/generators/test_clusterd_network_generator.py b/src/konnektor/tests/network_planners/generators/test_clustered_network_generator.py similarity index 100% rename from src/konnektor/tests/network_planners/generators/test_clusterd_network_generator.py rename to src/konnektor/tests/network_planners/generators/test_clustered_network_generator.py From d595449e1104c9a27f5ad5956ba613628696ba08 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 2 Dec 2024 11:15:45 -0800 Subject: [PATCH 16/21] adding scorer type hint --- .../generators/_abstract_network_generator.py | 10 +++++----- .../generators/_parallel_mapping_pattern.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/konnektor/network_planners/generators/_abstract_network_generator.py b/src/konnektor/network_planners/generators/_abstract_network_generator.py index ef7f8d0..926ffaf 100644 --- a/src/konnektor/network_planners/generators/_abstract_network_generator.py +++ b/src/konnektor/network_planners/generators/_abstract_network_generator.py @@ -3,9 +3,9 @@ import abc import logging -from typing import Iterable, Union +from typing import Callable, Iterable, Union -from gufe import AtomMapper +from gufe import AtomMapper, AtomMapping from gufe import LigandNetwork, Component from konnektor.network_planners._networkx_implementations import ( @@ -23,9 +23,9 @@ class NetworkGenerator(NetworkPlanner): def __init__( self, mappers: Union[AtomMapper, list[AtomMapper]], - scorer, - ## TODO: rename this to network_algorithm? - network_generator: _AbstractNetworkAlgorithm, + scorer: Callable[[AtomMapping], float], + network_generator: _AbstractNetworkAlgorithm, ## TODO: rename this to network_algorithm? + n_processes: int = 1, progress: bool = False, _initial_edge_lister=None, diff --git a/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py b/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py index 93953f7..78847b5 100644 --- a/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py +++ b/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py @@ -3,6 +3,7 @@ import functools import multiprocessing as mult +from typing import Callable, from gufe import AtomMapper, AtomMapping from gufe import SmallMoleculeComponent @@ -70,7 +71,7 @@ def thread_mapping(args) -> list[AtomMapping]: def _parallel_map_scoring( possible_edges: list[tuple[SmallMoleculeComponent, SmallMoleculeComponent]], - scorer: callable, + scorer: Callable[[AtomMapping], float], mappers: list[AtomMapper], n_processes: int, show_progress: bool = True, From 3e0e3d1b9e6aefcef3ebca5ee9a7b3983499253e Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 2 Dec 2024 11:27:02 -0800 Subject: [PATCH 17/21] switching to a note box --- .../network_planners/generators/maximal_network_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/konnektor/network_planners/generators/maximal_network_generator.py b/src/konnektor/network_planners/generators/maximal_network_generator.py index 30a18d2..9a4ce44 100644 --- a/src/konnektor/network_planners/generators/maximal_network_generator.py +++ b/src/konnektor/network_planners/generators/maximal_network_generator.py @@ -27,8 +27,8 @@ def __init__( The `Transformation` s of this graph are realized as `AtomMapping` s of pairwise `Component` s. If not all mappings can be created, it will ignore the mapping failure and return a nearly fully connected graph. - Note: This approach is not recommended for Free Energy calculations in application cases, as it is - very computationally expensive. + ... note:: + This approach is not recommended for Free Energy calculations in application cases, as it is very computationally expensive. However, this approach is very important, as all other approaches use the Maximal Network as an initial solution, then remove edges to achieve the desired design. From 7e738d0308b808a2b439048aced80ff098b2e353 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 2 Dec 2024 11:33:11 -0800 Subject: [PATCH 18/21] updating mst docstring formatting --- .../generators/maximal_network_generator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/konnektor/network_planners/generators/maximal_network_generator.py b/src/konnektor/network_planners/generators/maximal_network_generator.py index 9a4ce44..08a95aa 100644 --- a/src/konnektor/network_planners/generators/maximal_network_generator.py +++ b/src/konnektor/network_planners/generators/maximal_network_generator.py @@ -30,11 +30,11 @@ def __init__( ... note:: This approach is not recommended for Free Energy calculations in application cases, as it is very computationally expensive. However, this approach is very important, as all other approaches use the Maximal Network as an initial solution, - then remove edges to achieve the desired design. + then remove edges to achieve the desired design. This class is recommended as an `initial_edge_lister` for other approaches. - > **Note**: the `MaximalNetworkGenerator` is parallelized and the number of CPUs can be given with `n_processes`. - > All other approaches in Konnektor benefit from this parallelization and you can use this parallelization with `n_processes` key word during class construction. + The `MaximalNetworkGenerator` is parallelized and the number of CPUs can be given with `n_processes`. + All other approaches in Konnektor benefit from this parallelization and you can use this parallelization with `n_processes` key word during class construction. Parameters ---------- From eb33fa40fb566264b9d74bd381b29fb3a5a8a37a Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Mon, 2 Dec 2024 11:47:45 -0800 Subject: [PATCH 19/21] removing straggling comma --- .../network_planners/generators/_parallel_mapping_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py b/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py index 78847b5..ef6a3d6 100644 --- a/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py +++ b/src/konnektor/network_planners/generators/_parallel_mapping_pattern.py @@ -3,7 +3,7 @@ import functools import multiprocessing as mult -from typing import Callable, +from typing import Callable from gufe import AtomMapper, AtomMapping from gufe import SmallMoleculeComponent From ee33ba42bc382ce839f8e1d95dc54d88effb2cf6 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz <31974495+atravitz@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:40:50 -0800 Subject: [PATCH 20/21] Update src/konnektor/network_planners/generators/clustered_network_generator.py Co-authored-by: Hannah Baumann <43765638+hannahbaumann@users.noreply.github.com> --- .../network_planners/generators/clustered_network_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/konnektor/network_planners/generators/clustered_network_generator.py b/src/konnektor/network_planners/generators/clustered_network_generator.py index e8866e4..33d7dc9 100644 --- a/src/konnektor/network_planners/generators/clustered_network_generator.py +++ b/src/konnektor/network_planners/generators/clustered_network_generator.py @@ -63,7 +63,7 @@ def __init__( clusterer: ComponentsDiversityClusterer Separates the `Component` s along the first dimension. mappers: Union[AtomMapper, list[AtomMapper]] - Defines the connection between two ligands if `NetworkConcatenator`s or `NetworkGenerator`s are provided. Otherwise, (?) (default:None) + Defines the connection between two ligands if `NetworkConcatenator` s or `NetworkGenerator` s are provided. Otherwise, (?) (default:None) scorer: AtomMappingScorer scoring function evaluating an `AtomMapping`, and giving a score between [0,1], if only `NetworkConcatenator` or `NetworkGenerator` classes are passed progress: bool, optional From f82cd71577e47b304faf9b7f4de11d2c32562db9 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz <31974495+atravitz@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:00:04 -0800 Subject: [PATCH 21/21] Update src/konnektor/network_planners/generators/cyclic_network_generator.py Co-authored-by: Hannah Baumann <43765638+hannahbaumann@users.noreply.github.com> --- .../network_planners/generators/cyclic_network_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/konnektor/network_planners/generators/cyclic_network_generator.py b/src/konnektor/network_planners/generators/cyclic_network_generator.py index b4fc3ca..2561c91 100644 --- a/src/konnektor/network_planners/generators/cyclic_network_generator.py +++ b/src/konnektor/network_planners/generators/cyclic_network_generator.py @@ -42,7 +42,7 @@ def __init__( This layout has well-distributed connectivity between all `Component` s, which increases the robustness very well, but still allows for a better graph score then the Twin Star Network, as the connectivity distribution is biased and not enforced. - The large number of cycles might be very useful for statistical analysis. Nevertheless, the network has an increased amount of `Transformation`s. + The large number of cycles might be very useful for statistical analysis. Nevertheless, the network has an increased amount of `Transformation` s. Parameters