19 September 2013

516. Potential energy diagrammes in latex using pgfplots

Given these recent posts, a post on how to represent reaction coordinates in latex was inevitable.

Note: a much prettier example is found here: https://quantumchemistryniser.wordpress.com/2013/05/25/potential-energy-profile-using-pgfplots/

However, I initially couldn't reproduce it, and after spending a few hours with pgfplots I wanted my own style anyway.


But first, a recap:
Once you've completely left office-like wordprocessors behinds and fully embraced the wonder of typesetting in LaTeX you find yourself wanting to produce more and more of the figures directly in latex, rather than simply importing figures.

While nothing beats gnuplot for plotting, and pov-ray (via e.g. gdis) for fancy figures and bkchem for simple 2d structures, there are some nice and simple latex packages that make life easier: I touch on a few in this post: http://verahill.blogspot.com.au/2012/07/debian-texlive-and-style-files-making.html

For chemical formulae, use mhchem -- I think it's standard in debian for texlive. It's indispensable. Also see http://www.ctan.org/pkg/mhchem

For very, very simple chemical structures you can look at chemfig -- I don't use it much though. http://www.ctan.org/tex-archive/macros/latex/contrib/chemfig/

For drawing simple MO diagrammes, modiagram is very pretty: http://www.ctan.org/pkg/modiagram

For drawing NMR pulse sequences there are a few options: http://verahill.blogspot.com.au/2013/08/499-briefly-drawing-nmr-sequences-using.html and http://verahill.blogspot.com.au/2013/08/498-briefly-drawing-nmr-pulse-sequences.html


A dead end: endiagram
It looks very promising, but it didn't work out for me: http://ctan.mirrorcatalogs.com/macros/latex/contrib/endiagram/

Installation:
mkdir ~/texmf/tex/latex/endiagram -p
cd ~/texmf/tex/latex/endiagram
wget http://ctan.mirrorcatalogs.com/macros/latex/contrib/endiagram/endiagram.sty
sudo texhash

You'll need siunitx and tikz as well, but it seems to come with a standard texlive install on debian. Out of the box I kept getting:

! Undefined control sequence.
<argument> \clist_count:N
\l__endiagram_points_clist

l.16 \ENcurve{1,4,0}

In the end I couldn't get it to work properly, even after installing l3kernel -- I don't think it would've been impossible to figure it out, but I was running out of patience.

The solution: pgfplots
So I kept looking, and found this: https://quantumchemistryniser.wordpress.com/2013/05/25/potential-energy-profile-using-pgfplots/

While I couldn't get it to work 'out of the box' (after deleting the nodes depending on the pdf files), I ended up reading the pfgplots manual: http://pgfplots.sourceforge.net/pgfplots.pdf

pgfplots is not meant for drawing potential energy diagrammes, but it can be made to do it -- it's 'dum' in the sense that it's not aware of what a PE diagram is, so you'll have to draw all objects expliticly. In the end, it's actually quite simple though.

I eventually ended up with these two examples:
The code is here:
\documentclass[10pt,a4paper]{article} \usepackage{pgfplots} \usepackage{tikz} \begin{document} %\begin{center} %\begin{tikzpicture}[scale=1.0] %\draw (0,0) --(1,2); %\end{tikzpicture} %\end{center} \begin{tikzpicture} \begin{axis}[ axis x line= bottom, axis y line= left, xmin=-1, xmax=10, ymin=-1, ymax=6, xlabel=Reaction coordinate, ylabel=$\Delta$E (kcal/mol), xtick=\empty ] \addplot[smooth,solid,blue] coordinates { (0,0)(1,0) (2,4)(3,4) (4,3)(5,3) (6,4)(7,4) (8,1)(9,1)}; \node at (axis cs:4.5,2.5) {Intermediate}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{axis}[ axis x line= bottom, axis y line= left, xmin=-1, xmax=6, ymin=-1, ymax=15, xlabel=Reaction coordinate, ylabel=$\Delta$E (kcal/mol), xtick=\empty ] \addplot[smooth,solid,blue] coordinates { (0,0)(1,0)}; \addplot[smooth,dotted,black] coordinates {(1,0)(2,11.7)}; \addplot[smooth,solid,blue] coordinates {(2,11.7)(3,11.7)}; \addplot[smooth,dotted,black] coordinates {(3,11.7)(4,10.5)}; \addplot[smooth,solid,blue] coordinates {(4,10.5)(5,10.5)}; \end{axis} \end{tikzpicture} \end{document}


No comments:

Post a Comment