<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\subsection{Working with sub-molecules}

The \chf package supplies a nifty mechanism to assemble larger molecules from predefined fragments, or sub-molecules. The following (hand-coded) example builds aspirin from two sub-molecules:

\lstinputlisting{hand-coded-tex/aspirin.tex}

\cfpic{hand-coded-tex/aspirin}

As a more advanced example, let us piece together the structure of Sodium Green, a fluorescent sodium indicator dye (the figure below was ripped from an information sheet by the supplier, Molecular Probes).

\begin{center}
\includegraphics[width=0.75\textwidth]{examples/hand-coded-tex/sodium-green.png}
\end{center}

The molecule contains two moieties of dichlorofluorescein, attached to a crown ether via a linker. We start with dichlorofluorescein as one submol and the crown ether-cum-linkers as the other.

\lstinputlisting{dichlorofluorescein1.sh}

Now, we put the two pieces together, starting with the bridging carbonyl group:

\lstinputlisting{hand-coded-tex/sodium-green1}

which gives us the following fabulous result:

\cfpic{hand-coded-tex/sodium-green1}

What went wrong here? Submol expansion is essentially string substitution. When the submol is filled in, the connection to the preceding part of the molecule is made by whichever atom happens to have been rendered first, and the last rendered atom of the submol connects to the subsequent parts of the structure. Thus, we need to tell \mcf the order in which to render the atoms. To identify the atoms that we want to join, we display all atom numbers in the structure.

\lstinputlisting[firstline=2]{dichlorofluorescein2.sh}

\cfpic{hand-coded-tex/sodium-green2}

For dichlorofluorescein, we need to connect to atom 22. For the crown ether, we want to enter at atom 12 coming from the left, and leave at atom 32 on the right. To render the sub-molecules accordingly, we use the \lstinline!--entry-atom! or \lstinline!-e! as well as the \lstinline!--exit-atom! or \lstinline!-x! options:

\lstinputlisting[firstline=2]{dichlorofluorescein3.sh}

We put the whole molecule together:

\lstinputlisting{hand-coded-tex/sodium-green3.tex}

This produces

\cfpic{hand-coded-tex/sodium-green3}

which is what we want \ldots\ well, almost; the entry and exit amine groups of the crown ether submol now each have one surplus hydrogen. This problem cannot be fixed using \mcf but requires editing of the generated code by hand.

</pre></body></html>