Get bondgraph#

Extracting the covalent bond graph of a molecular system.

The function molsysmt.topology.get_bondgraph() extracts the network graph of covalent bonds where atoms represent nodes and covalent bonds represent edges.

Added in version 1.0.0.

Basic usage#

Let’s show how to extract a network graph representation of covalent bonds for Met-enkephalin:

import molsysmt as msm
import networkx as nx
import matplotlib.pyplot as plt
molsys = msm.convert(msm.systems['Met-enkephalin']['met_enkephalin.h5msm'])

We extract the bond graph as a NetworkX graph using molsysmt.topology.get_bondgraph():

graph = msm.topology.get_bondgraph(molsys, to_form='networkx.Graph')
n_nodes = graph.number_of_nodes()
n_edges = graph.number_of_edges()
print(f'The graph has {n_nodes} nodes and {n_edges} edges.')
The graph has 72 nodes and 73 edges.

Visualizing the 2D bond graph#

We can render the 2D topology graph using NetworkX and Matplotlib, labeling nodes with their atom names:

atom_names = msm.get(molsys, element='atom', name=True)
labels = {i: atom_names[i] for i in range(len(atom_names))}

plt.figure(figsize=(9, 6))
pos = nx.spring_layout(graph, seed=42)
nx.draw_networkx_nodes(graph, pos, node_color='lightskyblue', node_size=350)
nx.draw_networkx_edges(graph, pos, edge_color='gray', width=1.2)
nx.draw_networkx_labels(graph, pos, labels=labels, font_size=7)
plt.title('Met-enkephalin Covalent Bond Graph')
plt.axis('off')
plt.show()
../../../../_images/3ec8f72a86c0661e28c59298c7133e4d9db1a4a35eb73d12bedb3f0550b40536.png

Connected components analysis#

We can compute the number of connected covalent components using NetworkX functions:

components = list(nx.connected_components(graph))
print(f'Number of connected covalent components: {len(components)}')
Number of connected covalent components: 1