# Category Archives: Chemistry

## Energy level ladder plots made trivial

I have written a simple but fairly nice script for generating energy level ladder plots. It uses matplotlib on python.

You feed it a file with some energy parameters and pairs of energy levels and descriptors and get a consistent graph out of it which can be saved as a raster or vector graphic. These plots are sort of hard to do consistently in Excel and the like.

You can grab the files here.

The archives consist of the script, some examples and the manual. You will need python 2.6 and matplotlib. Older versions may work but are untested.

I hope someone finds this useful, as I certainly do.

The package is released under the GPL.

Edit: I have updated the package to fix a bug which interfered with rendering of *.pdf files in Adobe Reader 8

## Blackbody Curves

Something I worked on last night. Wrote a program to generate relative radiance curves for ideal blackbodies at different temperatures from Planck’s Law, used Excel to graph them and then embellished in Photoshop. These emission curves explain why very hot objects become incandescent, and the integrals of these curves determine their colour (cooler objects glow dull red, hot objects glow yellow-orange, and very hot objects glow blue-white). The gradient is modified from David Eccles’ normalised linear spectrum, which was released to the public domain. My modifications mean that the spectrum is only qualitatively correct, placing more emphasis on yellow.

This adventure was inspired by an exercise in my ancient copy of Atkins Physical Chemistry, which asks readers to write a program that outputs blackbody spectra and optionally numerically integrates them. There’s also a question involving a glow worm being propelled through space *via* photon momentum, quite a charming imagination ðŸ˜€

## Representing spin graphs in GraphViz

I was recently looking for a way to represent systems of interacting spins (e.g. to depict Heisenberg coupling between metal centres) and determined that there had to be some kind of deep, transcendental, graph-theoretic truth underlying coupled metal centres. After meditating hard I had gained no real insight, apart from the fact that I could represent these systems as undirected graphs, with each node representing a center and each edge representing a linear combination of exchange pathway contributions. Happily, there exists a program that is capable of attractively rendering graphs of nodes and edges, called GraphViz. GraphViz is seemingly mostly used for representing IT networks and FSMs, but it’s general enough to depict any kind of directed or undirected graph. I set to work making my dream come true:

graph cadisp1 { graph[bgcolor="transparent"]; node [fontname="calibri", fontsize="14.00", shape=circle, style="bold,filled" fillcolor=white height="0.8"]; edge [style=bold]; splines=true; overlap=false; {node [height="0.8", shape=circle, style="bold,filled" fillcolor=lightgray] B1 B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4} A1 [label=" 2â†‘ "];B1 [label="3/2â†‘"];C1 [label="3/2â†‘"];D1 [label="3/2â†‘"]; A2 [label=" 2â†“ "];B2 [label="3/2â†‘"];C2 [label="3/2â†‘"];D2 [label="3/2â†‘"]; A3 [label=" 2â†‘ "];B3 [label="3/2â†“"];C3 [label="3/2â†‘"];D3 [label="3/2â†‘"]; A4 [label=" 2â†‘ "];B4 [label="3/2â†“"];C4 [label="3/2â†“"];D4 [label="3/2â†‘"]; B1 -- C1 -- D1 -- B1; A1 -- B1; A1 -- C1; A1 -- D1; A2 -- B2 -- C2 -- A2; D2 -- A2; D2 -- B2; D2 -- C2; A3 -- B3 -- C3 -- A3; D3 -- A3; D3 -- B3; D3 -- C3; A4 -- B4 -- C4 -- A4; D4 -- A4; D4 -- B4; D4 -- C4; }

And out pops an automatically formatted SVG file. This was quicker to write than it would have been to construct by hand, and required only a little bit of finishing up in Inkscape to seal the deal:

Irritatingly, GraphViz requires html character encodings for non-ASCII characters, necessitating the &# codes to render â†‘ and â†“ respectively. I see that WordPress has automatically formatted these codes…Â Finishing up consisted of shading the dissimilar spin states and using continuous or dashed edges to highlight parallel and antiparallel relationships between centres (all single-determinantial!). Optionally, I could label the edges to show the magnitude of the coupling as some multiple of pairwise J values. I feel that the shading and dashing helps better bring out the symmetry of the broken symmetry states, so that I only need to stare slack-jawed for a short time before I know what to stipulate the symmetry as in the computational chemistry software of my choice after I’ve blu-tacked the graph to my cube (hint: clockwise from top left it’s C_{s}, C_{s}, C_{3v}, C_{3v}).

The geometry of the cluster in real life is elegant and approximately tetrahedral, however this could also serve as a representation of a tetranuclear cluster with trigonal planar geometry and the appropriate exchange pathways (I have been told such systems are known) or indeed any other crazy asymmetric geometry with the necessary exchange pathways. Edges don’t represent bonds, and as such they may stand in for any number of intervening ligands working in concert for the full pairwise couplings experienced by the metals. In the end however, I will probably decide that I cannot realistically put these into a document on the basis that they are simply too abstract, or worse, too pretentious (these things tend to go hand-in-hand) for people to like. Fantasies of inventing a popular diagram type aside, I acknowledge that people – myself included – usually dig more concrete representations that can be recognised at a glance. For this, traditional molecular stick diagrams – perhaps with attendant spin arrows – serve admirably and are ubiquitous in literature.

Oh well, we shall see.