From 5a3d41f4f7ef547cee7e489bcde5bd7504426acf Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:17:29 +0100 Subject: [PATCH 01/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index a20e4cf4..8512ced4 100644 --- a/environment.yml +++ b/environment.yml @@ -11,7 +11,7 @@ dependencies: - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 - openff-models >=0.0.5 - pip - - pydantic + - pydantic <2.0.0 - pytest - pytest-cov - pytest-xdist From bfe740ec8b4856047e84dc41959de177d1dc1dc5 Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:29:58 +0100 Subject: [PATCH 02/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 8512ced4..bf48035b 100644 --- a/environment.yml +++ b/environment.yml @@ -9,7 +9,7 @@ dependencies: - openff-toolkit >=0.13.0 - openff-units ==0.2.0 # https://github.com/openforcefield/openff-units/issues/69 - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 - - openff-models >=0.0.5 + - openff-models >=0.0.5,<0.1.0 - pip - pydantic <2.0.0 - pytest From 19f834dd4f7215ef2022ebcdaa1f2e41ebe7e10c Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:36:17 +0100 Subject: [PATCH 03/14] try updating units --- environment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index bf48035b..6f86f608 100644 --- a/environment.yml +++ b/environment.yml @@ -7,8 +7,8 @@ dependencies: - networkx - numpy - openff-toolkit >=0.13.0 - - openff-units ==0.2.0 # https://github.com/openforcefield/openff-units/issues/69 - - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 + - openff-units >=0.2.1 # https://github.com/openforcefield/openff-units/issues/69 + - pint >=0.22 # https://github.com/openforcefield/openff-units/issues/69 - openff-models >=0.0.5,<0.1.0 - pip - pydantic <2.0.0 From 81f624a4abba339d582539b159edf84fdaba7796 Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:42:12 +0100 Subject: [PATCH 04/14] Update environment.yml --- environment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 6f86f608..dcf4e113 100644 --- a/environment.yml +++ b/environment.yml @@ -7,8 +7,8 @@ dependencies: - networkx - numpy - openff-toolkit >=0.13.0 - - openff-units >=0.2.1 # https://github.com/openforcefield/openff-units/issues/69 - - pint >=0.22 # https://github.com/openforcefield/openff-units/issues/69 + - openff-units <0.2.1 # https://github.com/openforcefield/openff-units/issues/69 + - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 - openff-models >=0.0.5,<0.1.0 - pip - pydantic <2.0.0 From 4e4d14ba885afa3009123bd09f69d302728a61bb Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:42:37 +0100 Subject: [PATCH 05/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index dcf4e113..bf48035b 100644 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,7 @@ dependencies: - networkx - numpy - openff-toolkit >=0.13.0 - - openff-units <0.2.1 # https://github.com/openforcefield/openff-units/issues/69 + - openff-units ==0.2.0 # https://github.com/openforcefield/openff-units/issues/69 - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 - openff-models >=0.0.5,<0.1.0 - pip From 3fa1218c9b87298c2c1749dc6869da289767d405 Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:48:42 +0100 Subject: [PATCH 06/14] Update environment.yml --- environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yml b/environment.yml index bf48035b..ae355a7b 100644 --- a/environment.yml +++ b/environment.yml @@ -20,5 +20,6 @@ dependencies: # docs - pydata-sphinx-theme - sphinx-jsonschema==1.15 + - sphinx <7.1.2 - pip: - autodoc_pydantic From 33970375ce17236159f1af503384902d604fb0ce Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:55:44 +0100 Subject: [PATCH 07/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index ae355a7b..bab844f7 100644 --- a/environment.yml +++ b/environment.yml @@ -22,4 +22,4 @@ dependencies: - sphinx-jsonschema==1.15 - sphinx <7.1.2 - pip: - - autodoc_pydantic + - autodoc_pydantic<2.0.1 From 32811582163b8da2c5266c0707cd084be81b895a Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 11:58:44 +0100 Subject: [PATCH 08/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index bab844f7..8c544104 100644 --- a/environment.yml +++ b/environment.yml @@ -22,4 +22,4 @@ dependencies: - sphinx-jsonschema==1.15 - sphinx <7.1.2 - pip: - - autodoc_pydantic<2.0.1 + - autodoc_pydantic<2.0.0 From 3c90b415e7661c976eaaecb9835daaeda33e5e1c Mon Sep 17 00:00:00 2001 From: Irfan Alibay Date: Wed, 2 Aug 2023 12:28:02 +0100 Subject: [PATCH 09/14] Update environment.yml --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 8c544104..6e008cf8 100644 --- a/environment.yml +++ b/environment.yml @@ -9,7 +9,7 @@ dependencies: - openff-toolkit >=0.13.0 - openff-units ==0.2.0 # https://github.com/openforcefield/openff-units/issues/69 - pint <0.22 # https://github.com/openforcefield/openff-units/issues/69 - - openff-models >=0.0.5,<0.1.0 + - openff-models >=0.0.5 - pip - pydantic <2.0.0 - pytest From 1ab5503675daf231623f31c078e1c908f1dc9598 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 4 Aug 2023 10:23:00 +0100 Subject: [PATCH 10/14] FEAT: add LigandNetwork.is_connected() method --- gufe/ligandnetwork.py | 10 +++++++++- gufe/tests/test_ligand_network.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gufe/ligandnetwork.py b/gufe/ligandnetwork.py index 5b81a0bb..1e3c1abf 100644 --- a/gufe/ligandnetwork.py +++ b/gufe/ligandnetwork.py @@ -46,7 +46,7 @@ def _from_dict(cls, dct: dict): return cls.from_graphml(dct['graphml']) @property - def graph(self) -> nx.Graph: + def graph(self) -> nx.MultiDiGraph: """NetworkX graph for this network""" if self._graph is None: graph = nx.MultiDiGraph() @@ -178,3 +178,11 @@ def enlarge_graph(self, *, edges=None, nodes=None) -> LigandNetwork: nodes = set([]) return LigandNetwork(self.edges | set(edges), self.nodes | set(nodes)) + + def is_connected(self) -> bool: + """Are all ligands in the network (indirectly) connected to each other + + A "False" value indicates that either some ligands have no edges or that + there are separate networks that do not link to each other. + """ + return nx.is_weakly_connected(self.graph) diff --git a/gufe/tests/test_ligand_network.py b/gufe/tests/test_ligand_network.py index 2afc6506..f500c0a4 100644 --- a/gufe/tests/test_ligand_network.py +++ b/gufe/tests/test_ligand_network.py @@ -260,3 +260,9 @@ def test_to_graphml(self, simple_network, ligandnetwork_graphml): def test_from_graphml(self, simple_network, ligandnetwork_graphml): assert LigandNetwork.from_graphml(ligandnetwork_graphml) == simple_network.network + + def test_is_connected(self, simple_network): + assert simple_network.network.is_connected() + + def test_is_not_connected(self, singleton_node_network): + assert not singleton_node_network.network.is_connected() From f653a85e86d4d766cc55d250965862ea29eef5e9 Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Thu, 10 Aug 2023 15:58:31 +1000 Subject: [PATCH 11/14] Prevent _GufeTozenizableMeta.__call__ from overwriting signature of __init__ --- gufe/tokenization.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gufe/tokenization.py b/gufe/tokenization.py index c537f5a9..1f50fc90 100644 --- a/gufe/tokenization.py +++ b/gufe/tokenization.py @@ -61,6 +61,24 @@ def __call__(cls, *args, **kwargs): instance = TOKENIZABLE_REGISTRY[key] return instance + def __init__(cls, clsname, bases, attrs): + """ + Restore the signature of __init__ or __new__ + """ + if inspect.signature(cls.__new__) != inspect.signature(object.__new__): + sig = inspect.signature(cls.__new__) + elif inspect.signature(cls.__init__) != inspect.signature(object.__init__): + sig = inspect.signature(cls.__init__) + else: + # No __new__ or __init__ method defined + return super().__init__(clsname, bases, attrs) + + # Remove the first parameter (cls/self) + parameters = tuple(sig.parameters.values()) + cls.__signature__ = sig.replace(parameters=parameters[1:]) + + return super().__init__(clsname, bases, attrs) + class _ABCGufeClassMeta(_GufeTokenizableMeta, abc.ABCMeta): # required to make use of abc.ABC in classes that use _ComponentMeta @@ -132,6 +150,7 @@ def __eq__(self, other): def __hash__(self): return hash(self.key) + def _gufe_tokenize(self): """Return a list of normalized inputs for `gufe.base.tokenize`. From fdcfe3b1d9d5a23feb6beee57b501b5d7a529534 Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Thu, 10 Aug 2023 16:18:07 +1000 Subject: [PATCH 12/14] Remove accidental newline --- gufe/tokenization.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gufe/tokenization.py b/gufe/tokenization.py index 1f50fc90..2cead759 100644 --- a/gufe/tokenization.py +++ b/gufe/tokenization.py @@ -150,7 +150,6 @@ def __eq__(self, other): def __hash__(self): return hash(self.key) - def _gufe_tokenize(self): """Return a list of normalized inputs for `gufe.base.tokenize`. From b631e9e7f7c27ff6b256ff3c2c18b347b27fca56 Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 11 Aug 2023 11:28:29 +0100 Subject: [PATCH 13/14] tests for issue #217 --- gufe/tests/test_ligand_network.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gufe/tests/test_ligand_network.py b/gufe/tests/test_ligand_network.py index f500c0a4..b876da4c 100644 --- a/gufe/tests/test_ligand_network.py +++ b/gufe/tests/test_ligand_network.py @@ -266,3 +266,11 @@ def test_is_connected(self, simple_network): def test_is_not_connected(self, singleton_node_network): assert not singleton_node_network.network.is_connected() + + +def test_empty_ligand_network(mols): + # issue #217 + n = LigandNetwork(edges=[], nodes=[mols[0]]) + + assert len(n.edges) == 0 + assert len(n.nodes) == 1 From f362f3485328e3de9ea866d143213803f73fecaf Mon Sep 17 00:00:00 2001 From: richard gowers Date: Fri, 11 Aug 2023 11:39:26 +0100 Subject: [PATCH 14/14] fixes TypeError in LigandNetwork with no edges fixes #217 --- gufe/ligandnetwork.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gufe/ligandnetwork.py b/gufe/ligandnetwork.py index 1e3c1abf..abb2dc9a 100644 --- a/gufe/ligandnetwork.py +++ b/gufe/ligandnetwork.py @@ -2,6 +2,7 @@ # For details, see https://github.com/OpenFreeEnergy/gufe from __future__ import annotations +from itertools import chain import json import networkx as nx from typing import FrozenSet, Iterable, Optional @@ -30,7 +31,8 @@ def __init__( nodes = [] self._edges = frozenset(edges) - edge_nodes = set.union(*[{edge.componentA, edge.componentB} for edge in edges]) + edge_nodes = set(chain.from_iterable((e.componentA, e.componentB) + for e in edges)) self._nodes = frozenset(edge_nodes) | frozenset(nodes) self._graph = None