Created
September 4, 2023 10:20
-
-
Save jamesrswift/bc9205131667164d2adfd0133dd4aac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Defines a macro for showing mass spectra | |
\usepackage{options} | |
\usepackage{environ} | |
\usepackage{pgfmath} | |
\usepackage{pgfplotstable} | |
\options{ | |
/MassSpectrum/.new family, | |
/MassSpectrum/dim/width/.new length = 0.9\textwidth, | |
/MassSpectrum/dim/height/.new length = 8cm, | |
/MassSpectrum/mz/min/.new value = 40, | |
/MassSpectrum/mz/max/.new value = 250, | |
/MassSpectrum/caliper/yoffset/.new value = 2, | |
} | |
\NewEnviron{MassSpectrumEnvironment}[1]{ | |
{\options{/MassSpectrum,#1}{ | |
\BODY | |
}} | |
} | |
\newcommand{\MassSpectrum}[2]{ | |
\pgfplotstableread[col sep=comma]{#1}{\data} | |
\MassSpectrumIndexIntensities{\data} | |
\begin{tikzpicture} | |
\begin{axis}[ | |
ycomb,mark=none, | |
%========================================== | |
ylabel={Relative Intensity (\si{\percent})}, | |
xlabel={Mass-to-Charge Ratio ($m/z$)}, | |
%========================================== | |
xmin=\option{/MassSpectrum/mz/min}, | |
xmax=\option{/MassSpectrum/mz/max}, | |
%========================================== | |
width=\option{/MassSpectrum/dim/width}, | |
height=\option{/MassSpectrum/dim/height}, | |
%========================================== | |
ymin=0,ymax=110, | |
xtick pos=left, | |
xtick align=outside, | |
ytick pos=left, | |
ytick align=outside, | |
] | |
% | |
\addplot[ | |
no markers | |
] table[x=mass,y=intensity] {\data}; | |
% | |
#2 | |
% | |
\end{axis} | |
\MassSpectrumIndexInstensitiesClear{\data} | |
\end{tikzpicture} | |
} | |
\newcommand{\MassSpectrumIndexIntensities}[1]{ | |
\pgfplotstableforeachcolumnelement{mass}\of{#1}\as\mass{% | |
\pgfplotstablegetelem{\pgfplotstablerow}{intensity}\of{#1} | |
\expandafter\pgfmathsetmacro\csname massSpec\mass\endcsname{\pgfplotsretval} | |
} | |
} | |
\newcommand{\MassSpectrumIndexInstensitiesClear}[1]{ | |
\pgfplotstableforeachcolumnelement{mass}\of{#1}\as\mass{% | |
\expandafter\pgfmathsetmacro\csname massSpec\mass\endcsname{} | |
} | |
} | |
\newcommand{\MassSpectrumGetIntensityAt}[1]{ | |
\expandafter{\csname massSpec#1\endcsname} | |
} | |
\newcommand{\MassSpectrumTitle}[1]{ | |
\node[anchor=north west] at (rel axis cs:0,1) {#1}; | |
} | |
\newcommand{\MassSpectrumWriteText}[3]{ | |
\node[anchor=south] at (axis cs: #1, #2) {\footnotesize{#3}}; | |
} | |
\newcommand{\MassSpectrumCalloutManual}[2]{ | |
\MassSpectrumWriteText{#1}{#2}{#1} | |
} | |
\newcommand{\MassSpectrumCallout}[1]{ | |
\MassSpectrumCalloutManual{#1}{\MassSpectrumGetIntensityAt{#1}} | |
} | |
\newcommand{\MassSpectrumCalloutAnnotate}[4]{ | |
\draw[help lines] | |
(axis cs:#3,#4) | |
-- (axis cs:#1,#2); | |
\node[style={fill=white}] at (axis cs:#3,#4) {\footnotesize{#1}} -- (axis cs:#1,#2); | |
} | |
\newcommand{\MassSpectrumCaliper}[4]{ | |
\draw[help lines, |-] | |
(axis cs:#1,\MassSpectrumGetIntensityAt{#1}+\option{/MassSpectrum/caliper/yoffset}) | |
-- (axis cs:#1,#3); | |
\draw[help lines, |-] | |
(axis cs:#2,\MassSpectrumGetIntensityAt{#2}+\option{/MassSpectrum/caliper/yoffset}) | |
-- (axis cs:#2,#3); | |
\draw[help lines] | |
(axis cs:#1,#3) | |
-- (axis cs:#2,#3) | |
node [midway, centered, sloped, text=black, style={fill=white}] {\footnotesize{#4}}; | |
} |
Author
jamesrswift
commented
Sep 4, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment