8
$\begingroup$

In Huckel Method, by numbering the sp2 carbons in a molecule with conjugated double bonds, we can assemble its secular determinant in a form similar to the adjacency matrix of a graph. Taking trans-stilbene as a example:

enter image description here

Its secular determinant takes this simplified form:

[[x,1,0,0,0,1,0,0,0,0,0,0,0,0],
 [1,x,1,0,0,0,0,0,0,0,0,0,0,0],
 [0,1,x,1,0,0,0,0,0,0,0,0,0,0],
 [0,0,1,x,1,0,0,0,0,0,0,0,0,0],
 [0,0,0,1,x,1,0,0,0,0,0,0,0,0],
 [1,0,0,0,1,x,1,0,0,0,0,0,0,0],
 [0,0,0,0,0,1,x,1,0,0,0,0,0,0],
 [0,0,0,0,0,0,1,x,1,0,0,0,0,0],
 [0,0,0,0,0,0,0,1,x,1,0,0,0,1],
 [0,0,0,0,0,0,0,0,1,x,1,0,0,0],
 [0,0,0,0,0,0,0,0,0,1,x,1,0,0],
 [0,0,0,0,0,0,0,0,0,0,1,x,1,0],
 [0,0,0,0,0,0,0,0,0,0,0,1,x,1],
 [0,0,0,0,0,0,0,0,1,0,0,0,1,x]]

To convert it to a adjacency matrix, it's necessary just to replace the x variables in the main diagonal with zeroes.

Now the problem is: if we start with the adjacency matrix, not knowing the structure beforehand, one needs to grab pen and paper and do a bit of scribbling to see the shape it represents, as that information is not apparent just by glancing at the matrix. This procedure is a bit slow and error-prone when the molecule is large.

I noticed WolframAlpha allows us to get a graph representation from the adjacency matrix, as shown here for Benzene, but as the site uses proprietary software, we soon run into artificial limitations. My stilbene matrix exceeds maximum character limit, for example:

enter image description here

And it also can't be automated for larger number of structures.

So I'd like to ask some recommendations on how to do the same, but using Free / Open Source Software. Python libraries would be great, to ease automation.

$\endgroup$

1 Answer 1

9
$\begingroup$

NetworkX

This is a widely-used Python library for graph theory stuff. Open source (https://github.com/networkx/networkx) under a 3-clause BSD license.

Caveat: since this is a tool that knows nothing about chemistry, the "chemical" nature of the structure might get lost in the projection of the network (e.g., some bond lengths might not look reasonable). However, OP's question suggested an interest in a rough structure. For sufficiently complicated things, especially with significant 3D structure, this will probably run into trouble. It does an okay job on trans-stilbene, though. Play with different layouts to see which are perform best with your molecules.

import networkx as nx
import numpy as np

x = 0  # so this is a proper adjacency matrix

adj = [[x,1,0,0,0,1,0,0,0,0,0,0,0,0],
 [1,x,1,0,0,0,0,0,0,0,0,0,0,0],
 [0,1,x,1,0,0,0,0,0,0,0,0,0,0],
 [0,0,1,x,1,0,0,0,0,0,0,0,0,0],
 [0,0,0,1,x,1,0,0,0,0,0,0,0,0],
 [1,0,0,0,1,x,1,0,0,0,0,0,0,0],
 [0,0,0,0,0,1,x,1,0,0,0,0,0,0],
 [0,0,0,0,0,0,1,x,1,0,0,0,0,0],
 [0,0,0,0,0,0,0,1,x,1,0,0,0,1],
 [0,0,0,0,0,0,0,0,1,x,1,0,0,0],
 [0,0,0,0,0,0,0,0,0,1,x,1,0,0],
 [0,0,0,0,0,0,0,0,0,0,1,x,1,0],
 [0,0,0,0,0,0,0,0,0,0,0,1,x,1],
 [0,0,0,0,0,0,0,0,1,0,0,0,1,x]]

# note that NetworkX requires that you wrap in a numpy array
graph = nx.Graph(np.array(adj))

nx.draw(graph)

network visualization of bondgraph

I've used this approach to debug problems with structures before (IIRC, I used MDTraj's Topology.to_bondgraph method, which produces an NetworkX graph, in my case). You can easily label nodes with atom names -- see NetworkX tutorial for more.

$\endgroup$
2
  • 1
    $\begingroup$ What do you think of Gephi and Graphviz? $\endgroup$ Sep 17, 2021 at 14:48
  • 2
    $\begingroup$ @EJoshuaS-ReinstateMonica Most of my experience is from working from within Python, so I haven't used the stand-alone apps. Graphviz tools can be used for layout within NetworkX -- those often give better layouts if I don't like the NetworkX defaults. $\endgroup$
    – dwhswenson
    Sep 17, 2021 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .