Debian Codegraph @

texmf-dist/doc/latex/chemobabel/chemobabel-en.tex

raw
1 %%
2 %% This is file `chemobabel-en.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% chemobabel.dtx (with options: `en')
8 %%
9 %% IMPORTANT NOTICE:
10 %%
11 %% For the copyright see the source file.
12 %%
13 %% Any modified versions of this file must be renamed
14 %% with new filenames distinct from chemobabel-en.tex.
15 %%
16 %% For distribution of the original source see the terms
17 %% for copying and modification in the file chemobabel.dtx.
18 %%
19 %% This generated file may be distributed as long as the
20 %% original source files, as listed above, are part of the
21 %% same distribution. (The sources need not necessarily be
22 %% in the same archive or directory.)
23 %%
24 %% This document describes the usage of `chemobabel.sty',
25 %% a LaTeX package for generating chemical structural formulas
26 %% using Open Babel and Inkscape.
27 %%
28 %% Copyright 2014-2022 Acetaminophen (Hironobu YAMASHITA)
29 %% Email : h.y.acetaminophen[a t]gmail.com
30 %% GitHub : https://github.com/aminophen
31 %% Blog : http://acetaminophen.hatenablog.com/
32 %% Twitter : @aminophen
33 %%
34 \documentclass[12pt]{ltjsarticle}
35 \usepackage[margin=20mm]{geometry}
36 \usepackage[english]{babel}
37 \usepackage[nofontspec,defaultsups]{newpxtext}
38 \usepackage[zerostyle=c,straightquotes]{newtxtt}
39 \usepackage{newpxmath}
40 \usepackage{ascmac}
41 \usepackage[librsvg]{chemobabel}
42 \usepackage[bookmarksnumbered=true,hidelinks,%
43 pdftitle={User Manual for chemobabel.sty},%
44 pdfauthor={Hironobu Yamashita (Acetaminophen)},%
45 pdfsubject={TeX \& LaTeX Advent Calendar 2014},%
46 pdfkeywords={chemistry,open babel,chemdraw,smiles}]{hyperref}
47 \usepackage{footnotebackref}
48 \makeatletter
49 \long\def\@makecaption#1#2{%
50 \vskip\abovecaptionskip
51 \sbox\@tempboxa{#1: #2}%
52 \global\@minipagefalse
53 \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
54 \vskip\belowcaptionskip}
55 \makeatother
56 \newcount\TestCount
57 \def\XyM{\ifnum\fam=-1\relax\fam=0\relax\fi\TestCount=\fam
58 X\kern-.30em\smash{\raise.50ex\hbox{$\fam\TestCount\Upsilon$}}%
59 \kern-.30em{M}}
60 \def\XyMTeX{\XyM\kern-.1em\TeX}
61 \def\Lpack#1{\textsf{#1}}
62 \def\Lcode#1{\texttt{#1}}
63 \def\Lmeta#1{\textit{#1}}
64 \def\Lver#1{\Lpack{chemobabel} #1}
65 \def\TikZ{Ti\textit{k}Z}
66 \title{\Lpack{chemobabel} \\[1ex]
67 \normalsize --- Chemical Structures from MDL Molfiles,
68 ChemDraw Files or SMILES Notations --- \\
69 }
70 \author{Hironobu Yamashita (@aminophen)}
71 \begin{document}
72 \renewcommand{\figurename}{Fig.\,}
73 \pagenumbering{roman}
74 \maketitle
75
76 This document (\jobname.pdf) describes the usage of \Lpack{chemobabel.sty},
77 a \LaTeX\ package for \textbf{generating chemical structural formulas}
78 to be inserted in your documents.
79 The formulas can be generated \textbf{from many kinds of chemical data
80 formats}, including MDL Molfiles, ChemDraw files and even from
81 SMILES notations, with the help of Open Babel.
82 The formulas below are generated using this method.\footnote{Unless
83 otherwise noted, this documentation used \Lcode{\input{obversion.txt}}}
84
85 日本語版ドキュメントはchemobabel-ja.pdfを参照してください。
86
87 \begin{figure}[ht]
88 \centering
89 \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{} \quad
90 \chemobabel*[width=90mm]{draw/Brevetoxin A.mol}
91 \caption{Firefly luciferin \& Brevetoxin A (from MDL Molfiles)}
92 \end{figure}
93
94 \begin{figure}[ht]
95 \centering
96 \chemobabel[width=80mm]{draw/ATP.cdx}{} \hspace{1cm}
97 \chemobabel*[width=30mm]{draw/Glucose.cdx}
98 \caption{ATP (Adenosine triphosphate) \& Glucose (from ChemDraw files)}
99 \end{figure}
100 \begin{center}\small
101 Note: with Open Babel 3.1.1 the chemical structure of ATP from the .cdx file
102 becomes wrong.\\ See \url{https://github.com/openbabel/openbabel/issues/338}
103 \end{center}
104
105 \begin{figure}[ht]
106 \centering
107 \smilesobabel[width=36mm]{CCO}{} \hspace{1cm}
108 \smilesobabel*[width=40mm]{CC(C(=O)O)N} \hspace{1cm}
109 \smilesobabel*[width=30mm]{C1[C@H](C)C[C@@H](O)C1}
110 \caption{Ethanol, Alanine \& (1\textit{S},3\textit{S})-3-Methylcyclopentanol (from SMILES notations)}
111 \end{figure}
112
113 \begin{figure}[ht]
114 \centering
115 \smilesobabel*[width=30mm]{CC(=O)Nc1ccc(cc1)O} \hspace{1cm}
116 \smilesobabel*[width=40mm]{C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O}
117 \caption{Acetaminophen (Paracetamol) \& $\alpha$-\textsc{d}-Glucose (from SMILES notations)}
118 \end{figure}
119
120 \begin{figure}[ht]
121 \centering
122 This package is maintained on GitHub:\par
123 \url{https://github.com/aminophen/chemobabel}\par
124 If you have questions, please let me know.
125 \end{figure}
126
127 \begin{figure}[ht]
128 \centering
129 Also available on CTAN:
130 \url{https://www.ctan.org/pkg/chemobabel}\par
131 Distributed with \TeX\ Live and MiK\TeX.
132 Below is a short description for CTAN:\par
133 \begin{screen}
134 This package provides a way to convert and include
135 chemical structure graphics from various chemical formats,
136 such as ChemDraw files, MDL molfile or SMILES notations
137 using Open Babel.
138 To use this \LaTeX\ package, it is necessary to enable execution
139 of the following external commands via \Lcode{latex -shell-escape}.
140 \begin{itemize}
141 \item \Lcode{obabel} (Open Babel)
142 \item \Lcode{inkscape} or \Lcode{rsvg-convert}
143 (for SVG -> PDF/EPS conversion)
144 \item \Lcode{pdfcrop} or \Lcode{ps2eps}
145 (optional; for cropping large margins of PDF/EPS)
146 \end{itemize}
147 \end{screen}
148 \end{figure}
149
150 \clearpage
151 \setcounter{tocdepth}{3}
152 \tableofcontents
153
154 \clearpage
155 \pagenumbering{arabic}
156
157 \section{Introduction}
158
159 \subsection{Motivation for Development}
160
161 As you already know, \LaTeX\ is being used all over the world.
162 However, when it comes to drawing chemical strucutral formulas,
163 ways of inserting formulas into \LaTeX\ documents are very limited.
164 I think it is mainly due to lack of both reliable and simple methods
165 of doing this that many of the researchers in chemistry are reluctant
166 to use \LaTeX\ system.
167
168 Some \TeX/\LaTeX\ macros and packages are already available from
169 \href{http://www.ctan.org/}{CTAN}:
170 \begin{itemize}
171 \item \href{http://www.ctan.org/pkg/xymtex}{\XyMTeX}:
172 a set of packages for drawing chemical structural formulas
173 \item \href{http://www.ctan.org/pkg/chemfig}{\Lpack{chemfig}}:
174 a package which draws molecules using \TikZ
175 \end{itemize}
176 These packages are reliable and almost all kinds of structural formulas
177 can be drawn in a consistent way. However, a lot of practice will be
178 required before one can come to make full use of them.
179
180 You can also insert structural formulas with \verb|\includegraphics| of
181 PDF or EPS files exported from special softwares for chemists, such as
182 \href{http://www.cambridgesoft.com/Ensemble_for_Chemistry/ChemDraw/}{ChemDraw}
183 and other similar programs.
184 In this case, you have to save files in both chemical formats
185 (such as \verb|.cdx| or \verb|.mol|) and graphical formats
186 (\verb|.pdf| or \verb|.eps|) manually.
187
188 This new package, \Lpack{chemobabel.sty}, will offer a new choice for
189 chemists who need chemical structures inserted in their \LaTeX\ documents.
190 In this method, we use \href{http://openbabel.org/}{Open Babel} for
191 generating chemical structural formulas in SVG format,
192 and \href{https://inkscape.org/en/}{Inkscape} for converting SVG to PDF/EPS.
193 Both programs are open source and cross-platform, and being actively maintained.
194
195 \paragraph{About Open Babel}
196
197 Open Babel is a toolbox specially designed to handle many kinds of
198 chemical data. It is an open, collaborative project allowing anyone to search,
199 convert, analyze, or store data from molecular modeling, chemistry,
200 solid-state materials, biochemistry, or related areas.
201 See \href{http://openbabel.org/}{Official Website} for detail.
202
203 \clearpage
204
205 \subsection{Idea and Approach}
206
207 First I found a post on Noel O'Blog \cite{NOB1}, \cite{NOB2} and
208 the comment \cite{JLA} about generating chemical structural formulas
209 from SMILES notations using Open Babel.
210 I thought the method described in these posts were very interesting,
211 but I didn't like all the programs could be executed by
212 \verb|-shell-escape| option.
213 At the same time, I encountered a macro for copying all
214 \verb|\includegraphics| from one source file to another \cite{OKU},
215 which made me conceive of an idea of extracting minimal source code
216 which needs \verb|-shell-escape| option.
217
218 I thought this method would be applicable to converting ChemDraw files into
219 graphics, but I could not find any project attempting to realize this idea.
220 I found a project named
221 \href{http://chemdrawinlatex.sourceforge.net/}{Chemdraw in \LaTeX}
222 on Sourceforge, but now it was closed.
223 This drove me to develop a new package to simplify the process for
224 inserting chemical structural formulas into \LaTeX\ documents.
225
226
227 \clearpage
228
229 \section{Before you begin}
230
231 \subsection{Installing dependent softwares}
232
233 First, you have to install \href{http://openbabel.org/}{Open Babel} and
234 \href{https://inkscape.org/en/}{Inkscape}
235 (or \href{http://librsvg.sourceforge.net/download/}{librsvg}) on your
236 computer, and export PATH to the required command-line programs,
237 \Lcode{obabel} and \Lcode{inkscape} (or \Lcode{rsvg-convert}).
238 The package also uses \Lcode{pdfcrop} (or \Lcode{ps2eps}) to
239 crop large margins, but it is included in \TeX\ Live.
240 You can confirm by executing following commands:
241 In UNIX operating system:
242 \begin{verbatim}
243 $ which obabel
244 $ which inkscape (if you choose inkscape)
245 $ which rsvg-convert (if you choose librsvg)
246 \end{verbatim}
247
248 In Windows operating system:
249 \begin{verbatim}
250 > where obabel
251 > where inkscape (if you choose inkscape)
252 > where rsvg-convert (if you choose librsvg)
253 \end{verbatim}
254
255 And when you get some command echo, installation should be successful.
256
257 \subsection{Loading the package}
258
259 In the preamble of your document, declare
260 \begin{verbatim}
261 \usepackage{chemobabel}
262 \end{verbatim}
263 to load \Lpack{chemobabel} package.
264 The package depends on \Lpack{graphicx}.
265
266 \clearpage
267
268 \section{Basic Usage}
269 \label{basic}
270
271 \subsection{Conversion from Chemical Structure Data Files}
272
273 Suppose you have \verb|ATP.cdx|, a file with chemical structural formula
274 of ATP (Adenosine triphosphate) drawn in ChemDraw, and
275 \verb|Brevetoxin A.mol|, a MDL Molfile which can be obtained from
276 \href{http://www.chemspider.com/}{ChemSpider} (originally \verb|9041092.mol|).
277
278 Use \verb|\chemobabel| command as follows. I put original files in a
279 subdirectory \Lcode{draw}, so added \Lcode{draw/} before the actual filename.
280 Of course you can put in the same directory with your \LaTeX\ file.
281
282 \begin{verbatim}
283 \chemobabel[width=90mm]{draw/ATP.cdx}{}
284 \chemobabel*[width=120mm]{draw/Brevetoxin A.mol}
285 \end{verbatim}
286
287 Then, typeset with \verb|-shell-escape| option.
288 Remember to use this option, otherwise it won't allow \LaTeX\ to
289 call any external command-line programs, such as obabel and inkscape!
290 \begin{verbatim}
291 $ pdflatex -shell-escape test.tex
292 \end{verbatim}
293 You will see in \verb|chemobabelimgdir| subdirectory ``chemobabelimg[NUM].pdf'',
294 and output file test.pdf will be Figure~\ref{fig:chem1}:
295
296 \begin{figure}[h]
297 \centering
298 \chemobabel[width=90mm]{draw/ATP.cdx}{} \\ \vspace{1cm}
299 \chemobabel*[width=120mm]{draw/Brevetoxin A.mol}
300 \caption{Conversion from ATP.cdx and Brevetoxin A.mol}\label{fig:chem1}
301 \end{figure}
302
303 The syntax is:
304 \begin{center}
305 \verb|\chemobabel[|\Lmeta{options}\verb|]{|\Lmeta{filename}\verb|}{|\Lmeta{obabel options}\verb|}| \\
306 \verb|\chemobabel*[|\Lmeta{options}\verb|]{|\Lmeta{filename}\verb|}|
307 \end{center}
308 \verb|\chemobabel| takes one optional parameter and two mandatory parameters.
309 \begin{itemize}
310 \item The optional parameter \Lmeta{options} in the box brackets
311 is passed to \verb|\includegraphics|.
312 If omitted, the default ``clip,scale=1' is assumed.
313 \item The first mandatory parameter \Lmeta{filename} is the file name
314 which contains chemical structural formula.
315 \item The second mandatory parameter \Lmeta{obabel options}
316 is passed to \verb|obabel| command
317 (see Section \ref{depict} for some examples).
318 \end{itemize}
319 If you want to leave the second parameter empty,
320 a shorthand form \verb|\chemobabel*| is also available
321 (since \Lver{v0.9k [2022/10/09]}).
322
323 \subsection{Conversion from SMILES Notations}
324
325 You can also write SMILES notations directly in your \LaTeX\ file to be
326 converted into structural formulas.
327 For example, \verb|CCO| is the SMILES notation of ethanol, and
328 \verb|CC(=O)Nc1ccc(cc1)O| is that of acetaminophen (paracetamol).
329 Use \verb|\smilesobabel| command as follows:
330
331 \begin{verbatim}
332 \smilesobabel{CCO}{}
333 \smilesobabel*[width=25mm]{CC(=O)Nc1ccc(cc1)O}
334 \end{verbatim}
335
336 Again typeset with \verb|-shell-escape| option:
337 \begin{verbatim}
338 $ pdflatex -shell-escape test.tex
339 \end{verbatim}
340 This time you will get ``smilesobabelimg[NUM].pdf'' and ``test.pdf''
341 as Figure~\ref{fig:smi1}.
342 \begin{figure}[h]
343 \centering
344 \smilesobabel{CCO}{} \quad
345 \smilesobabel*[width=25mm]{CC(=O)Nc1ccc(cc1)O}
346 \caption{Conversion from SMILES notation}\label{fig:smi1}
347 \end{figure}
348
349 The syntax is:
350 \begin{center}
351 \verb|\smilesobabel[|\Lmeta{options}\verb|]{|\Lmeta{SMILES notation}\verb|}{|\Lmeta{obabel options}\verb|}| \\
352 \verb|\smilesobabel*[|\Lmeta{options}\verb|]{|\Lmeta{SMILES notation}\verb|}|
353 \end{center}
354 The only difference from \verb|\chemobabel| is that
355 \Lmeta{SMILES notation} should be placed in the first braces.
356 You can put any kinds of SMILES notations in parameters of
357 \verb|\smilesobabel|, even when they contain some special characters
358 such as a backslash (\verb|\|) and a percent symbol (\verb|%|).
359 Similarly, parameters of \verb|\chemobabel| can also contain
360 these special characters.
361 \begin{verbatim}
362 \smilesobabel*[width=28mm]{Cl/C=C/Br}
363 \smilesobabel*[width=28mm]{Cl/C=C\Br}
364 \end{verbatim}
365 \begin{figure}[h]
366 \centering
367 \smilesobabel*[width=28mm]{Cl/C=C/Br} \quad
368 \smilesobabel*[width=28mm]{Cl/C=C\Br}
369 \end{figure}
370
371 \noindent \textbf{Notes for users of earlier versions \Lver{v0.6 [2015/06/29]} or older}
372
373 In earlier versions of \Lpack{chemobabel}, it was necessary for users
374 to pay another attention when using these \LaTeX\ special characters.
375 However, the workaround I had suggested before was far from desirable
376 because ``casual \LaTeX\ users'' were forced to change category codes
377 of these characters manually.
378
379 To solve this problem, I improved the internal macros since \Lver{v0.7 [2015/08/26]}.
380 Now you can put any kinds of SMILES notations directly without worrying
381 about special characters (\verb|\|, \verb|%|, etc).
382 Note that the undesirable workaround (like changing \verb|\catcode| inside
383 \verb|\begingroup| ... \verb|\endgroup|) has now become rather harmful.
384
385
386 \clearpage
387
388 \subsection{Package options}
389
390 By default, \Lpack{chemobabel} converts chemical structures into
391 PDF images using Inkscape. However, you can switch the image format
392 and the conversion program if you like.
393
394 When you are using drivers which do not support PDF figures (such as dvips),
395 it will be helpful if \Lpack{chemobabel} converts them into EPS images.
396 For this purpose, you can use:
397 \begin{verbatim}
398 \usepackage[eps]{chemobabel}
399 \end{verbatim}
400 The option \verb|eps| switches the image format
401 (that is, output format from Inkscape) into EPS (since
402 \Lver{v0.9d [2016/02/28]}).\footnote{Moreover, since
403 \Lver{v0.9l [2022/10/22]}, the package automatically switches to
404 EPS mode when using dvips.}
405
406 You can also change the image conversion program from ``Inkscape'' to
407 ``rsvg-convert'' (since \Lver{v0.9e [2016/03/07]}).
408 The program rsvg-convert is faster than inkscape, so it will be useful.
409 For this purpose, use \verb|librsvg| option:
410 \begin{verbatim}
411 \usepackage[librsvg]{chemobabel}
412 \end{verbatim}
413 The default behavior is equivalent to the \verb|pdf| and \verb|inkscape| options:
414 \begin{verbatim}
415 \usepackage[pdf,inkscape]{chemobabel}
416 \end{verbatim}
417
418 Moreover, Open Babel v2.4.0 or later versions generate images with
419 a rather large margin. To avoid this, the images are cropped
420 using \verb|pdfcrop| for PDF or \verb|ps2eps| for EPS
421 (since \Lver{v0.9i [2022/09/12]}).
422 If you want to disable this cropping, please add \verb|nocrop| option:
423 \begin{verbatim}
424 \usepackage[nocrop]{chemobabel}
425 \end{verbatim}
426
427 \clearpage
428
429 \subsection{For Safer Typesetting...}
430 \label{extract}
431
432 With the basic method described in Section \ref{basic},
433 you will get desired output in almost any situation.
434 However, it is sometimes NOT desirable to use \verb|-shell-escape| option,
435 because with that option \LaTeX\ can call \emph{any} external command-line
436 programs whether you like it or not.
437 This means that there is a chance for unknown programs to be executed,
438 and this can be dangerous especially in case that you don't write your
439 own \LaTeX\ code. To avoid this problem, I provide a workaround for
440 extracting all \verb|\chemobabel| and \verb|\smilesobabel| commands
441 to another \LaTeX\ file (Reference: \TeX\ Forum \cite{OKU}).
442
443 All you have to do is to add \verb|extract| option when loading the package:
444 \begin{verbatim}
445 \usepackage[extract]{chemobabel}
446 \end{verbatim}
447 When typesetting, usual command
448 \begin{verbatim}
449 $ pdflatex test.tex
450 \end{verbatim}
451 can be used.
452 With \verb|extract| option, all \Lpack{chemobabel} does is extracting
453 all \verb|\chemobabel| and \verb|\smilesobabel| commands from the
454 original \LaTeX\ file.
455 You will get ``ChemFigFile.tex'' in the current directory, a minimal
456 \LaTeX\ source file which includes all \verb|\chemobabel| and
457 \verb|\smilesobabel| commands.
458 You can simply typeset it by
459 \begin{verbatim}
460 $ pdflatex -shell-escape ChemFigFile.tex
461 \end{verbatim}
462 and you will get PDF figures in the same way
463 as described in Section \ref{basic}.
464 After this, typeset your own document again
465 (this time you should remove \verb|extract| option):
466 \begin{verbatim}
467 $ pdflatex test.tex
468 \end{verbatim}
469 This time you will get desired output ``test.pdf''
470 which includes figures properly.
471 This method will also save you a lot of time for typesetting.
472
473 \paragraph{Note on the option \Lcode{-output-directory}}
474
475 When using the option \Lcode{-output-directory} of \TeX,
476 the extracted code ``ChemFigFile.tex'' goes there
477 but the subdirectory \verb|chemobabelimgdir| and
478 generated images stay in the current working directory.
479 To process the resulting files correctly, it would be
480 necessary to move files properly.
481
482 \clearpage
483
484 \section{Advanced Usage}
485
486 \subsection{Options for Depiction}
487 \label{depict}
488
489 As I have already mentioned, in both \verb|\chemobabel| and \verb|\smilesobabel|,
490 you can give some \Lmeta{obabel options} in the second braces.
491 Here I will introduce some examples.
492 \begin{itemize}
493 \item
494 \begin{verbatim}
495 \smilesobabel{CC(=O)Nc1ccc(cc1)O}{-xa}
496 \end{verbatim}
497 executes a command which gives a formula with all carbon atoms shown:
498 \begin{verbatim}
499 $ obabel -:"CC(=O)Nc1ccc(cc1)O" -O smilesobabelimg[NUM].svg -xa
500 \end{verbatim}
501 \item
502 \begin{verbatim}
503 \smilesobabel{CC(=O)Nc1ccc(cc1)O}{-xu -xC}
504 \end{verbatim}
505 gives one without element-specific atom coloring or terminal carbon atoms:
506 \begin{verbatim}
507 $ obabel -:"CC(=O)Nc1ccc(cc1)O" -O smilesobabelimg[NUM].svg -xu -xC
508 \end{verbatim}
509 \item
510 \begin{verbatim}
511 \chemobabel{ATP.cdx}{-xd}
512 \end{verbatim}
513 You can add \Lcode{-xd} option to remove filenames from ChemDraw figures with Open Babel 2.x.
514 \begin{verbatim}
515 $ obabel -:"ATP.cdx" -O chemobabelimg[NUM].svg -xd
516 \end{verbatim}
517 \end{itemize}
518
519 \begin{figure}[ht]
520 \centering
521 \smilesobabel[width=21mm]{CC(=O)Nc1ccc(cc1)O}{} \hspace{1cm}
522 \smilesobabel[width=25mm]{CC(=O)Nc1ccc(cc1)O}{-xa} \hspace{1cm}
523 \smilesobabel[width=21mm]{CC(=O)Nc1ccc(cc1)O}{-xu}
524 \caption{Acetaminophen (Paracetamol): Nothing, \Lcode{-xa}, \Lcode{-xu}}
525 SMILES: \verb|CC(=O)Nc1ccc(cc1)O|
526 \end{figure}
527
528 \begin{figure}[ht]
529 \centering
530 \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{} \hspace{1cm}
531 \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{-xC} \hspace{1cm}
532 \smilesobabel[width=25mm]{C1[C@H](C)C[C@@H](O)C1}{-xt}
533 \caption{(1\textit{S},3\textit{S})-3-Methylcyclopentanol: Nothing, \Lcode{-xC}, \Lcode{-xt}}
534 SMILES: \verb|C1[C@H](C)C[C@@H](O)C1|
535 \end{figure}
536
537 \begin{figure}[ht]
538 \centering
539 \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{} \hspace{1cm}
540 \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xa -xu} \hspace{1cm}
541 \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xu -xC}
542 \caption{3-Ethylbenzoyl chloride: Nothing, \Lcode{-xa -xu}, \Lcode{-xu -xC}}
543 SMILES: \verb|CCc1cccc(c1)C(=O)Cl|
544 \end{figure}
545
546 \begin{figure}[ht]
547 \centering
548 \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{--highlight "cC=O blue"} \hspace{1cm}
549 \smilesobabel[width=42mm]{CCc1cccc(c1)C(=O)Cl}{-xA --genalias}
550 \caption{3-Ethylbenzoyl chloride: \Lcode{--highlight "cC=O blue"}, \Lcode{-xA --genalias}}
551 SMILES: \verb|CCc1cccc(c1)C(=O)Cl|
552 \end{figure}
553
554 \begin{figure}[ht]
555 \centering
556 \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{} \hspace{1cm}
557 \chemobabel[width=65mm]{draw/Firefly luciferin.mol}{-xa}
558 \caption{Firefly luciferin (from MDL Molfiles): Nothing, \Lcode{-xa}}
559 \end{figure}
560
561 \begin{figure}[ht]
562 \centering
563 \chemobabel[width=70mm]{draw/ATP.cdx}{} \hspace{1cm}
564 \chemobabel[width=70mm]{draw/ATP.cdx}{-xd}
565 \caption{ATP (from ChemDraw files): Nothing, \Lcode{-xd}}
566 \end{figure}
567
568 \begin{figure}[ht]
569 For more details, see
570 \href{http://openbabel.org/docs/dev/Command-line_tools/babel.html}{obabel and babel}
571 and
572 \href{http://openbabel.org/docs/dev/FileFormats/SVG_2D_depiction.html}{SVG depiction (svg)}
573 in Open Babel documentation.
574 \end{figure}
575
576 \clearpage
577
578 \subsection{More complex structural formulas}
579
580 Open Babel can generate more complex structural formulas from SMILES notations.
581
582 \begin{figure}[ht]
583 \centering
584 \smilesobabel*[width=55mm]{CN1CC[C@]23c4c5ccc(c4O[C@H]2[C@H](C=C[C@H]3[C@H]1C5)O)O}
585 \caption{($-$)-Morphine}
586 SMILES: \verb|CN1CC[C@]23c4c5ccc(c4O[C@H]2[C@H](C=C[C@H]3[C@H]1C5)O)O|
587 \end{figure}
588
589 \begin{figure}[ht]
590 \centering
591 \smilesobabel*[width=150mm]{C[C@@H]1C[C@H]2[C@@H](CC(=O)O2)O[C@H]3C[C@@H]4[C@H](C[C@@H]([C@@H]5[C@@H](O4)C/C=C\C[C@@H]6[C@@H](O5)C/C=C\[C@@H]7[C@@H](O6)CCC[C@@H]8[C@@](O7)(C[C@@H]9[C@@H](O8)C[C@@H]2[C@@H](O9)[C@H](C[C@H](O2)CC(=C)C=O)O)C)C)O[C@@]3(C1)C}
592 \caption{Brevetoxin A}
593 SMILES (Sorry but too long): \verb|C[C@@H]1C[C@H]2[C@@H](CC(=O)O2)O[C@H]3C[C@@H]4[C@H](C[C@@H]([C@@H]5[C@@H](O4)C/C=C\C[C@@H]6[C@@H](O5)C/C=C\[C@@H]7[C@@H](O6)CCC[C@@H]8[C@@](O7)(C[C@@H]9[C@@H](O8)C[C@@H]2[C@@H](O9)[C@H](C[C@H](O2)CC(=C)C=O)O)C)C)O[C@@]3(C1)C|
594 \end{figure}
595
596 However, the results are sometimes undesirable and may also be
597 different depending on version numbers.
598 Here are some examples:
599
600 \clearpage
601
602 \begin{figure}[p]
603 Cephalostatin-1 (Example from \href{http://en.wikipedia.org/wiki/Simplified_molecular-input_line-entry_system}{Wikipedia}): \\
604 \verb|C[C@@](C)(O1)C[C@@H](O)[C@@]1(O2)[C@@H](C)[C@@H]3CC=C4[C@]3(C2)C(=O)C[C@H]5[C@H]4CC[C@@H](C6)[C@]5(C)Cc(n7)c6nc(C[C@@]89(C))c7C[C@@H]8CC[C@@H]%10[C@@H]9C[C@@H](O)[C@@]%11(C)C%10=C[C@H](O%12)[C@]%11(O)[C@H](C)[C@]%12(O%13)[C@H](O)C[C@@]%13(C)CO|
605 \begin{center}
606 \includegraphics[scale=0.85]{figures/Mac231-Cephalostatin-1.pdf}
607 \caption{Cephalostatin-1 (figure from Open Babel for Mac 2.3.1)}
608 \includegraphics[scale=0.5]{figures/Win232-Cephalostatin-1.pdf}
609 \caption{Cephalostatin-1 (figure from Open Babel for Win 2.3.2)}
610 \end{center}
611 \end{figure}
612
613 \begin{figure}[p]
614 Sesamin: \verb|c1cc2c(cc1C3C4COC(C4CO3)c5ccc6c(c5)OCO6)OCO2|
615 \begin{center}
616 \centering
617 \includegraphics[scale=0.5]{figures/Mac231-sesamin-normal.pdf}
618 \includegraphics[scale=0.5]{figures/Mac231-sesamin-gen2d.pdf}
619 \caption{Sesamin (figures from Open Babel for Mac 2.3.1; Normal and \Lcode{--gen2d})}
620 \includegraphics[scale=0.5]{figures/Win232-sesamin-normal.pdf}
621 \includegraphics[scale=0.5]{figures/Win232-sesamin-gen2d.pdf}
622 \caption{Sesamin (figures from Open Babel for Win 2.3.2; Normal and \Lcode{--gen2d})}
623 \end{center}
624 \end{figure}
625
626 \clearpage
627
628 Also, Open Babel may generate wrong structures from SMILES notations.
629 Here we can see the formula generated from a SMILES notation lacks one double bond.
630 \begin{figure}[ht]
631 \centering
632 \includegraphics[scale=0.6]{figures/Exact-FireflyLuciferin.pdf}
633 \caption{Firefly luciferin: exact structure from ChemSpider ID 4588411}
634 \includegraphics[scale=0.6]{figures/Win232-FireflyLuciferin.pdf}
635 \caption{Firefly luciferin?: output from Open Babel for Win 2.3.2}
636 \smilesobabel*[width=66mm]{C1[C@@H](N/C(=c\2/nc3c(=CC(=O)C=C3)s2)/S1)C(=O)O}
637 \caption{Firefly luciferin?: output from current Open Babel}
638 SMILES: \verb|C1[C@@H](N/C(=c\2/nc3c(=CC(=O)C=C3)s2)/S1)C(=O)O|
639 \end{figure}
640
641 We can avoid all these problems by using \verb|\chemobabel| with \verb|.mol| or
642 \verb|.cdx| files, instead of \verb|\smilesobabel|.
643 However, the fact that many complex structures can be generated from
644 only one character string is very interesting, isn't it?
645
646 \clearpage
647
648 \section{Note for Compatibility}
649
650 \subsection{Advantages of \Lpack{chemobabel}}
651
652 The macros \verb|\smiles| (written by Noel O'Boyle \cite{NOB1}) and
653 \verb|\obabel| (depends on \Lpack{graphvizObabel.sty} by
654 Jakob Lykke Andersen's \cite{JLA}) can be used as follows:
655 \begin{verbatim}
656 %% ----- for \smiles command -----
657 \newcounter{smilescounter}
658 \setcounter{smilescounter}{1}
659 \newcommand{\smiles}[1]{
660 \immediate\write18{obabel -:"#1" -O smilesimg\arabic{smilescounter}.png}
661 \includegraphics{smilesimg\arabic{smilescounter}.png}
662 \addtocounter{smilescounter}{1}
663 }
664 ...
665 \smiles{CCO}
666 %% -----
667 \end{verbatim}
668 \begin{verbatim}
669 %% ----- for \obabel command -----
670 \usepackage{graphvizObabel}
671 ...
672 \obabel[scale=0.6]{CCO}
673 %% -----
674 \end{verbatim}
675 However, \verb|\smiles| command creates raster graphics (.png) and
676 has no options to pass to \verb|\includegraphics|, and \verb|\obabel| command
677 sometimes does not work because of lack of file extension (.pdf) and
678 possibility of giving errors with empty optional parameters.
679 These problems are solved in \verb|\smilesobabel|.
680
681 \clearpage
682
683 \section{Limitations and Alternatives}
684
685 This method relies on Open Babel for generating structural formulas,
686 even without drawing anything by yourself.
687 Of course you can modify and customize these structures to some extent,
688 but this method will not be suitable for fine control of the output.
689 Also, computer-generated formulas may sometimes be unnatural and undesirable.
690 Therefore this method will be useful only when you need a simple method
691 for inserting structural formulas with minimal modification.
692 If you are not satisfied with the output, consider using {\XyMTeX} or
693 \Lpack{chemfig} packages instead.
694
695 I also found following packages which can be used for similar purpose:
696 \begin{itemize}
697 \item \href{http://www.ctan.org/pkg/mol2chemfig}{\Lpack{mol2chemfig}}:
698 convert chemical structures from MDL molfile format
699 to \Lpack{chemfig} source code
700 \end{itemize}
701
702 \clearpage
703
704 \section{Technical information}
705 \label{detail}
706
707 According to
708 \href{http://www.daylight.com/meetings/summerschool98/course/dave/smiles-intro.html}{SMILES Tutorial},
709 special characters are used in SMILES syntax are the followings:
710 \begin{itemize}
711 \item Roman alphabets: \verb|A-Z|, \verb|a-z|
712 \item Numbers: \verb|1-10|
713 \item Brackets: \verb|[ ] ( )|
714 \item Others:
715 \begin{itemize}
716 \item \verb|*| (unspecified atomic number)
717 \item \verb|.| (disconnection)
718 \item \verb|+| (charge sign)
719 \item \verb|-| (single bond or charge sign)
720 \item \verb|=| (double bond)
721 \item \verb|#| (triple bond)
722 \item \verb|$| (quadruple bond)
723 \item \verb|:| (aromatic bond)
724 \item \verb|%| (used when more than 10 ring closures)
725 \item \verb|/|, \verb|\| (configuration around double bonds)
726 \item \verb|@| (tetrahedral chirality)
727 \item \verb|>| (reaction)
728 \end{itemize}
729 \end{itemize}
730
731 It is important to prevent these characters from being translated as
732 \LaTeX\ special characters.
733 However, a backslash (\verb|\|) is a default escape character in \LaTeX,
734 and a percent symbol (\verb|%|) also has a special meaning as a comment character.
735 In \Lpack{chemobabel} (higher than v0.7), all these characters are
736 handled properly by changing category codes temporarily (like \verb+\verb+). \\
737
738 \clearpage
739
740 \section{Version History}
741
742 \begin{table}[h]
743 \centering
744 \begin{tabular}{ll}
745 2014/12/01 v0.1 & Made public as \Lpack{smilesobabel.sty} \\
746 2014/12/02 v0.2 & Add options which can be passed to obabel. \\
747 2014/12/07 v0.3 & Change name of package: \Lpack{chemobabel.sty} \\
748 & Images are stored in \Lcode{chemobabelimgdir}. \\
749 & Add \verb|\chemobabel| command. \\
750 2014/12/09 v0.4 & Fix a bug: (Thanks: Yusuke Terada) \\
751 & Extra spaces at the end of lines are removed. \\
752 2014/12/20 v0.5 & Add \verb|extract| option. \\
753 2015/06/29 v0.6 & Improve warning messages. \\
754 2015/08/26 v0.7 & Solve \verb|\catcode|-related problems in \verb|\smilesobabel|. \\
755 2015/08/27 v0.8 & Improve \verb|\smilesobabel| a little. \\
756 2015/08/28 v0.9 & Improve \verb|\smilesobabel|: (Thanks: ZR) \\
757 & Exclude $\varepsilon$-\TeX\ dependency. \\
758 2015/08/29 v0.9a & Improve \verb|\chemobabel| a little. \\
759 2016/01/06 v0.9b & Support Lua\TeX-0.85.0 and later versions. \\
760 2016/02/09 v0.9c & Fix a bug; forgotten in v0.9b. \\
761 2016/02/28 v0.9d & Add \verb|eps| and \verb|pdf| options. \\
762 2016/03/07 v0.9e & Add \verb|librsvg| and \verb|inkscape| options. \\
763 2016/10/23 v0.9f & Incorporate \verb|extract| option into main package. \\
764 2018/01/23 v0.9g & Minor refactor of code. \\
765 2022/09/11 v0.9h & Support Inkscape version 1.0 command line syntax. \\
766 2022/09/12 v0.9i & Crop images before inclusion, add \verb|nocrop| option. \\
767 2022/09/19 v0.9j & Check shell-escape status to show better error message. \\
768 & This is the first release on CTAN! \\
769 2022/10/09 v0.9k & Add \verb|\chemobabel*| and \verb|\smilesobabel*|. \\
770 & Warn if a user need to run another \LaTeX. \\
771 & Improve \verb|[extract]| to take over user-given package options. \\
772 2022/10/22 v0.9l & Default to EPS mode if PDF inclusion is unsupported by the driver. \\
773 & Default \verb|clip| for image inclusion. \\
774 \end{tabular}
775 \end{table}
776
777 \textbf{Important!}
778 \begin{itemize}
779 \item In Version 0.2, the number of parameters set in \verb|\smilesobabel| is changed!
780 \item From Version 0.3, the package name is changed to \Lpack{chemobabel.sty}.
781 \item From Version 0.7, the \verb|\catcode|-related workaround is rather harmful.
782 \end{itemize}
783
784 \clearpage
785
786 \begin{thebibliography}{9}
787 \bibitem{NOB1}
788 \href{http://baoilleach.blogspot.jp/2012/03/cheer-up-your-latex-with-smiles-support.html}{Cheer up your \LaTeX\ with SMILES support} -- Noel O'Blog
789 \bibitem{NOB2}
790 \href{http://baoilleach.blogspot.jp/2012/04/cheer-up-your-latex-with-smiles-support.html}{Cheer up your \LaTeX\ with SMILES support II} -- Noel O'Blog
791 \bibitem{JLA}
792 \href{http://imada.sdu.dk/~jlandersen/}{\LaTeX: Graphviz and OpenBabel} -- Jakob Lykke Andersen
793 \bibitem{OKU}
794 \href{http://oku.edu.mie-u.ac.jp/tex/mod/forum/discuss.php?d=1411}{文章内の画像のみを表示する方法} -- \TeX\ Forum \\
795 (How to extract only figures in \LaTeX\ source)
796 \bibitem{ACE1}
797 \href{http://acetaminophen.hatenablog.com/entry/2014/11/02/130624}{化学構造式を\TeX で(1):自動化による簡単生成} -- Acetaminophen's diary \\
798 (Chemical Structural Formula in \LaTeX\ (1): An Easy Method by Auto-generation)
799 \bibitem{ACE2}
800 \href{http://acetaminophen.hatenablog.com/entry/2014/11/02/130624}{化学構造式を\TeX で(2):自動化の注意点と解消法} -- Acetaminophen's diary \\
801 (Chemical Structural Formula in \LaTeX\ (2): Important Notes for Auto-generation and Solution)
802 \bibitem{ACE3}
803 \href{http://acetaminophen.hatenablog.com/entry/2014/11/05/135927}{化学構造式を\TeX で(3):補足事項} -- Acetaminophen's diary \\
804 (Chemical Structural Formula in \LaTeX\ (3): Supplement)
805 \end{thebibliography}
806
807 \noindent
808 \textbf{Note}: \href{http://acetaminophen.hatenablog.com/}{Acetaminophen's diary} is my own blog! (Sorry, but only in Japanese)
809
810 I added a post about this package on the 8th day of \href{http://www.adventar.org/calendars/553}{\TeX\ \& \LaTeX\ Advent Calendar 2014} (in Japanese):
811 \begin{itemize}
812 \item \href{http://acetaminophen.hatenablog.com/entry/2014/12/08/053519}{誰でも簡単! 化学構造式を\LaTeX に取り込むパッケージ} -- Acetaminophen's diary \\
813 (An easy way to insert chemical structural formulas into \LaTeX\ documents)
814 \end{itemize}
815
816 \end{document}
817 \endinput
818 %%
819 %% End of file `chemobabel-en.tex'.