Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bug with mbuild missing edges in bond graph #1049

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mbuild/bond_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's interesting how this could make such a big different.

else:
# Add new node even if it has no bond/neighbor
adj[node] = neighbors
Expand Down
13 changes: 13 additions & 0 deletions mbuild/tests/test_coordinate_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))