Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a follow up of drawing cellulose and aligning monomers in chemfig.

I'm trying to refine the structure adding some hydrogen bonds. No problem with the intra-chain ones, but I cannot figure out how to join atoms in two adjacent \chemfig command. Here you are my attempt.

Note that the red bond (emerging from OH in C6) is not properly placed. It should emerge from H instead than from O.

This is another problem, but the main one is to connect the H bonds between the two chains.

I suppose I have to manipulate the bounding boxes, but I do not have the palest idea on how to do it.

\documentclass{article}
\usepackage{chemfig}

\begin{document}

\definesubmol{180-glucoBeta}{
  -[:-10,.7,,,magenta]4
  (
    -[:10](-[:-150,0.7]-[6,0.7]OH)
    -[:-10]O(-[:50,.75])(-[:8,1.1,,,dash pattern=on 1pt off 1pt,green])
  )
  -[:50](-[:-170]HO)
  -[:-10](-[:55,0.7]OH)
  -[:10]1(-[2,0.7]H)
  -[:-10,.7,,,magenta]{\color{magenta}{O}}
}


\definesubmol{glucoBeta_H_bond}{
-[:10,.7,,,magenta]4
  (
    -[:-10](-[:150,0.7]-[2,0.7]OH(-[:100,1,,,dash pattern=on 1pt off 1pt,red]))
    -[:10]O(-[:-50,.75])(-[:-8,1.1,,,dash pattern=on 1pt off 1pt,green])
  )
  -[:-50](-[:170]HO(-[:-80,,,,dash pattern=on 1pt off 1pt,brown]))
  -[:10](-[:-55,0.7]OH)
  -[:-10]1(-[6,0.7]H)
  -[:10,.7,,,magenta]{\color{magenta}{O}} 
}

\chemfig[][scale=.75]{
  -[:-10,.7,,,,dash pattern=on 2pt off 2pt, magenta]O
  !{glucoBeta_H_bond}
  !{180-glucoBeta}
  !{glucoBeta_H_bond}
  !{180-glucoBeta}
  !{glucoBeta_H_bond}
  -[:-10,.7,,,dash pattern=on 2pt off 2pt, magenta]
}


\chemfig[blue][scale=.75]{
  -[:-10,.7,,,dash pattern=on 2pt off 2pt, magenta]O
  !{glucoBeta_H_bond}
  !{180-glucoBeta}
  !{glucoBeta_H_bond}
  !{180-glucoBeta}
  !{glucoBeta_H_bond}
  -[:-10,.7,,,dash pattern=on 2pt off 2pt, magenta]
}

\end{document}

enter image description here

share|improve this question

1 Answer 1

up vote 3 down vote accepted

connections between two molecules

If the question is how to draw connections between two molecules created with separate calls of \chemfig then the answer is in principle an easy one. ChemFig's molecules are TikZ pictures, really, and the atoms are nodes in this sense. As such they can be named through ChemFig's @{<node name>} syntax and connected afterwards through some \tikz[remember picture, overlay]...; or ChemFig's wrapper \chemmove{}.

The following example

\documentclass{article}
\usepackage{chemfig}
\begin{document}
General idea:\par
\chemfig{-[7]@{a}-[1]}

\vskip2em

\chemfig{-[1]@{b}-[7]}
\chemmove{ \draw[red,dotted] (a)--(b); }
\end{document}

gives after two compilations:

enter image description here

In your case, however, I don't think this is the best approach. In order to be able to connect the nodes they need to have unique names. If you use one node name repeatedly only the last instance is remembered:

As a consequence the method is not so nice when the nodes to be connected are hidden in repeated submols:

\documentclass{article}
\usepackage{chemfig}
\begin{document}

problem with molecules derived from submols:\par
\definesubmol{foo}{-[7]@{a}-[1]}
\definesubmol{bar}{-[1]@{b}-[7]}

\chemfig{!{foo}!{bar}!{foo}!{bar}}

\vskip2em

\chemfig{!{foo}!{bar}!{foo}!{bar}}
\chemmove{ \draw[green,dashed] (a)--(b); }

\end{document}

enter image description here

Finding the right atom

This addresses your second question:

Note that the red bond (emerging from OH in C6) is not properly placed. It should emerge from H instead than from O.

ChemFig provides a solution for this. Every bond in \chemfig{} has an optional arguments with five parameters:

-[<direction>,<length factor>,<departure>,<arrival>,<tikz options>]

The ones interesting here are <departure> and <arrival> which are integers specifying the numbers of the desired departure and arrival atoms. ChemFig's manual has the following example:

\documentclass{article}
\usepackage{chemfig}
\begin{document}

\chemfig{ABCD-[:75,,2,3]EFG}\qquad
\chemfig{ABCD-[:75,,,2]EFG}\qquad
\chemfig{ABCD-[:75,,3,2]EFG}

\end{document}

enter image description here

Proposed solution

In order to get two strands of cellulose I would suggest to save one submol of two glucoses with hydrogen bonds. Here's a possible definition using the turned-glucoBeta submol from my answer to the question you linked:

\definesubmol{bridged}{
  -[:10,.7,,,glycosid]4
  (
    -[:-10](-[:150,0.7]-[2,0.7]OH)
    -[:10]{\color{red}{O}}(-[:-8,1.2,,,bridge])
    -[:-50,.75]
  )
  -[:-50]
  (
    -[:170]HO
    -[6,,2,2,bridge]
    OH
    -[6,.7]
    -[:-30]
    -[:170]4(-[:-170,.475,,,glycosid])
    -[:-50](-[:170]HO)
    -[:10](-[:-50,.7]OH)
    -[:-10]1(-[6]H)(-[:10,.7,,,glycosid]{\color{glyc}O}!{turned-glucoBeta})
    -[:130]{\color{red}O}(-[:-8,1.2,,,bridge])
    -[:-170]
  )
  -[:10](-[:-55,0.7]OH)
  -[:-10]1(-[6,0.7]H)
  -[:10,.7,,,glycosid]{\color{glyc}O}
  !{turned-glucoBeta}
}

This submol can now be used repeatedly to get the polymer:

enter image description here

The full code

\documentclass[margin=.5cm]{standalone}
\usepackage{chemfig}
\tikzset{
  bridge/.style={dotted,blue} ,
  glycosid/.style={glyc}
}
\colorlet{glyc}{green}

\definesubmol{turned-glucoBeta}{
  -[:-10,.7,,,glycosid]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,,,glycosid]{\color{glyc}{O}}
}
\definesubmol{bridged}{
  -[:10,.7,,,glycosid]4
  (
    -[:-10](-[:150,0.7]-[2,0.7]OH)
    -[:10]{\color{red}{O}}(-[:-8,1.2,,,bridge])
    -[:-50,.75]
  )
  -[:-50]
  (
    -[:170]HO
    -[6,,2,2,bridge]
    OH
    -[6,.7]
    -[:-30]
    -[:170]4(-[:-170,.475,,,glycosid])
    -[:-50](-[:170]HO)
    -[:10](-[:-50,.7]OH)
    -[:-10]1(-[6]H)(-[:10,.7,,,glycosid]{\color{glyc}O}!{turned-glucoBeta})
    -[:130]{\color{red}O}(-[:-8,1.2,,,bridge])
    -[:-170]
  )
  -[:10](-[:-55,0.7]OH)
  -[:-10]1(-[6,0.7]H)
  -[:10,.7,,,glycosid]{\color{glyc}O}
  !{turned-glucoBeta}
}
\begin{document}
\chemfig{!{bridged}!{bridged}!{bridged}}
\end{document}
share|improve this answer
    
Due to my ignorance of tikz, the code is a little obscure, but it make sense also chemically. The monomer "sensu strictu" is actually the "bridged" you wrote. There's only a lacking H bond in your code: the one in the lower part. I'm still studying your code. In the meanwhile I added this bond with \definesubmol{turned-glucoBeta}{ -[:-10,.7,,,glycosid]4 ( -[:10](-[:-150,0.7]-[6,0.7]OH) -[:-10]O(-[:50,.75])(-[:8,1.1,,,dash pattern=on 1pt off 1pt,green]) ) –  Ottorino Mar 15 '13 at 21:01
    
@Ottorino well, I must admit I haven't paid too much attention to get the chemical details right... –  cgnieder Mar 16 '13 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.