A recurrent activity in computational chemistry workflow is the plotting of electronic spectra obtained from quantum chemistry packages. To improve these tasks, I developed a useful notebook, which contains functions to read and make spectrum plots. This blog article contains a brief explanation of how the PlotSpectrum.nb works and its features. Although, the code can be used easily through the instructions contained in the notebook and this is the most recommended way to start using it for your projects.
The present version of the notebook was written for the Wolfram Mathematica package. The language choice can be a deterrent to widespread use and I plan to migrate the development of this program to Python 3 soon.
The notebook obtains the data of transition energies and intensities from tables in the Comma-Separated Values (CSV) format. The standard units used for these quantities are electronvolts and oscillator power, respectively. I also made available in my GitHub a BASH script example to get the spectroscopic data from a typical Gaussian09 output automatically from standard TD-DFT/CIS calculations.
Usage of PlotSpectrum.py
We have two great families of functions in the notebook: listPlotPeaks and plotPeaks, which have variations according to the chosen distribution function.
listPlotPeaks functions
This function enables the plot of the list of electronic transitions in a vertical lines layout. It is very useful because is the direct picture of the vertical transitions obtained by the quantum chemistry calculation.
listPlotPeaks[data_?ListQ, color_] :=
ListPlot[data,
Filling -> Axis,
PlotRange -> {{All, All}, {0.0, All}},
PlotStyle -> Directive[PointSize[Large], color],
ImageSize -> 600]
plotPeaks functions
These plot functions are based on the sum of the convolutions of the statistical distributions over each vertical transition. You can choose different versions like plotGaussPeaks, plotLorentzPeaks, and plotVoigtPeaks.
plotGaussPeaks[data_?ListQ, \\[Sigma]_?NumericQ, xMin_?NumericQ, xMax_?NumericQ, color_, legends_?StringQ] :=
Plot[getGaussPeaks[x, data, \\[Sigma]], {x, xMin, xMax},
PlotRange -> {{xMin, xMax}, All},
Frame -> True, FrameLabel -> {Style[\"Energy (eV)\", FontSize -> 16],
Style[\"Oscillator Strength\", FontSize -> 16]}, FrameTicksStyle -> Directive[FontSize -> 14],
PlotStyle -> Directive[color], ImageSize -> 600,
PlotLegends -> Placed[SwatchLegend[{legends}], Above],
PerformanceGoal -> \"Speed\"]
One of my favorite tools is the manipulateGaussSpectrum, in which you can dynamically try and choose the best parameters for your plot. In this case, the Manipulate tool enables the selection of the range of the energy axis plot and the σ value of the Gauss distribution. Once you get experienced, you can fully enjoy the flexibility of the Wolfram language.
I hope you enjoy it! If you like it, give a star in the CompChemTools project!
Best regards!