From 0970f90b6ff47c30ecbcebfb02ba3a9770ab1bc7 Mon Sep 17 00:00:00 2001 From: CalCraven <54594941+CalCraven@users.noreply.github.com> Date: Mon, 8 Aug 2022 12:00:38 -0500 Subject: [PATCH] Fix for bug with mbuild missing edges in bond graph (#1049) * Fix for bug with mbuild missing edges in bond graph * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- mbuild/bond_graph.py | 2 +- mbuild/tests/test_coordinate_transform.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mbuild/bond_graph.py b/mbuild/bond_graph.py index da189eedb..ecfc6aed2 100644 --- a/mbuild/bond_graph.py +++ b/mbuild/bond_graph.py @@ -147,7 +147,7 @@ def compose(self, graph): adj = self._adj for node, neighbors in graph._adj.items(): if self.has_node(node): - (adj[node].add(neighbor) for neighbor in neighbors) + [adj[node].add(neighbor) for neighbor in neighbors] else: # Add new node even if it has no bond/neighbor adj[node] = neighbors diff --git a/mbuild/tests/test_coordinate_transform.py b/mbuild/tests/test_coordinate_transform.py index b6de79362..fc806a4dd 100644 --- a/mbuild/tests/test_coordinate_transform.py +++ b/mbuild/tests/test_coordinate_transform.py @@ -448,3 +448,16 @@ def test_z_axis_transform(self, h2o): for i in range(4): z_axis_transform(h2o) assert np.allclose(h2o.xyz, init_xyz, atol=1e-4) + + def test_bondgraph(self, ch3): + ch3_2 = mb.clone(ch3) + mb.force_overlap(ch3_2, ch3_2["up"], ch3["up"]) + ch3.add(ch3_2) + bgraph = ch3.bond_graph + for edge0, edge1 in bgraph.edges(): + assert bgraph.has_edge(edge0, edge1) + assert bgraph.has_edge(edge1, edge0) + neighbors = {"C": 4, "H": 1} + for node in bgraph.nodes(): + x = map(lambda node: node.name, bgraph._adj[node]) + assert neighbors[node.name] == len(list(x))