12

The problem I had to face yesterday was related to draw a cellulose molecule with chemfig. In particular I'm not familiar with tikz, so I had problems in aligning the monomers.

I was used to xymtec, but when I moved to debian wheezy I soon discovered that it is going to be obsolete. So here I am trying to re-learn things again.

Here a example on how I tried to solve the problem. It was a trial and error process. I'm sure there are a more elegant solutions.

It took me almost half a day to find this rough code, so I would like to know if it can be improved.

I'm writing this here, since this site was very helpful, so I would like to give something back.

\documentclass{minimal}
\usepackage{chemfig}

\definesubmol{glucoBeta}{
       ?(4-[:190,0.7])
        -[:-50](-[:170]HO)
        -[:10](-[:-55,0.7]OH)
        -[:-10]1(-[6,0.7]H)(-[:10]O)
        -[:130]{\color{red}{O}}
        -[:190]?(-[:150,0.7]-[2,0.7]OH)
}

\begin{document}

FIRST EXAMPLE \\
\chemfig[][scale=0.85]{!{glucoBeta}}
\vflipnext
 \chemfig[][scale=0.85]{!{glucoBeta}}
\chemfig[][scale=0.85]{!{glucoBeta}}
\vflipnext
 \chemfig[][scale=0.85]{!{glucoBeta}}\\
\bigskip

SECOND EXAMPLE\\

\chemfig[][scale=0.85]{!{glucoBeta}}
\vflipnext
 \chemfig[yshift=-7mm][scale=0.85]{!{glucoBeta}}
\chemfig[][scale=0.85]{!{glucoBeta}}
\vflipnext
 \chemfig[yshift=-7mm][scale=0.85]{!{glucoBeta}}


\end{document}

Output

enter image description here

Moriambar
  • 11,466
Ottorino
  • 853
  • 7
  • 10
  • 3
    XymTeX is not obsolete that I know of: the fact it doesn't go to CTAN makes installation a bit of work, but if you are happy with it then I guess it's worth it. – Joseph Wright Mar 15 '13 at 07:01

1 Answers1

7

I believe a better idea would be to define two submols:

  1. the glucose, i.e. the submol, in a way that it starts from “4” and ends in “1”
  2. a second one identical to the first but all angles mirrored

Then you can simply put one glucose after another in \chemfig{} to get the cellulose structure. No need for flipping and manual adjustment for vertical shifts. IMHO this is also semantically better since you'll have one molecule structure representing the cellulose.

\documentclass[margin=5pt]{standalone}
\usepackage{chemfig}

% this submol starts at the left-most bond (to C4)
% and ends at the right-most bond (from C1);
% it does not use the ?-syntax to avoid unwanted
% connections between different instances of the
% glucose rings:
\definesubmol{glucoBeta}{
  -[:10,.7]4
  (
    -[:-10](-[:150,0.7]-[2,0.7]OH)
    -[:10]{\color{red}{O}}-[:-50,.75]
  )
  -[:-50](-[:170]HO)
  -[:10](-[:-55,0.7]OH)
  -[:-10]1(-[6,0.7]H)
  -[:10,.7]O
}

% this submol is the same as the one before except
% that every bond has been changed to the opposite direction:
\definesubmol{turned-glucoBeta}{
  -[:-10,.7]4
  (
    -[:10](-[:-150,0.7]-[6,0.7]OH)
    -[:-10]{\color{red}{O}}-[:50,.75]
  )
  -[:50](-[:-170]HO)
  -[:-10](-[:55,0.7]OH)
  -[:10]1(-[2,0.7]H)
  -[:-10,.7]O
}

\begin{document}

% both submols can now be used together in one call of
% \chemfig in order to draw the cellulose structure:
\chemfig{HO!{glucoBeta}!{turned-glucoBeta}!{glucoBeta}!{turned-glucoBeta}H}

\end{document}

enter image description here

cgnieder
  • 66,645
  • Neat solution, cgnieder. Thanks for the code. I didn't know that it was possible to subtract angles the way yoiu did. Could I push your patient a little further and ask where in the manual this technique is mentioned ?

    @joseph wright

    I will keep on using xymtec,which it seems to me more effective to write chemical equations. But It's nice to have both packages to learn from.

    – Ottorino Mar 15 '13 at 08:48
  • @Ottorino I believe this is a misunderstanding: I manually changed all angles and simple named the second submol 180-glucoBeta. I could have chosen another name quite as well... It would be neat if it was possible to change all angles automatically but I'm afraid this is not possible. – cgnieder Mar 15 '13 at 08:53
  • I see.

    I'm still working on it, trying to add hydrogen bonds and I'm realizing that the difference between "glucoBeta" and "180-glucoBeta" lies in some minus signs here and there where appropriate.

    – Ottorino Mar 15 '13 at 10:47
  • As I said before, I'm trying to add some hydrogen bonds in the structure. I had no problem in inserting the intra-chain bonds, those between the emiacetalic O and the prospicient OH (bound to C in position 3).

    I can also draw another chain underneath, but I cannot connect with bonds (inter-chain) between the OH (C6) in the lower chain and the OH (C3) in the upper chain.

    As far as I understood is possible to join atoms within a \chemfig command, but not between two subsequent \chemfig commands.

    Should I open a new discussion, or continue here ?

    – Ottorino Mar 15 '13 at 14:17
  • 1
    »As far as I understood is possible to join atoms within a \chemfig command, but not between two subsequent \chemfig commands.« - That is basically correct. If you have a follow-up question it is better to post it as a new one. Comments are meant for clarifying the question at hand. – cgnieder Mar 15 '13 at 14:26