# DNA in Chemfig, Backbone

I would like to make a chemical molecule, using the chemfig environment in order to create DNA. However, I would only want the sugar-backbone included without any bases. I have tried to alter the source code found on this link:

chemfig and lego-style molecule construction

in order to get to it, but I'm not too good and half the time I have no clue what codes mean. Can any one help me?

The following code, which is basically a shortened version of the code that was posted here should produce the figure you want to achieve.

\documentclass{minimal}
\usepackage{chemfig,xstring}
\makeatletter

% "\derivesubmol" defines the new #1 submol, obtained by replacing all the
%  occurrences of "#3" by "#4" in the code of #2 submol

% arguments: #1 = new submol name, #2 = old submol name,
%            #3 = old substring, #4 = new substring
\newcommand*\derivesubmol[4]{%
\saveexpandmode\saveexploremode\expandarg\exploregroups
\csname @\ifcat\relax\noexpand#2first\else second\fi oftwo\endcsname
{\expandafter\StrSubstitute\@car#2\@nil}
{\expandafter\StrSubstitute\csname CF@@#2\endcsname}
{\@empty#3}{\@empty#4}[\temp@]%
\csname @\ifcat\relax\noexpand#1first\else second\fi oftwo\endcsname
{\expandafter\let\@car#1\@nil}
{\expandafter\let\csname CF@@#1\endcsname}\temp@
\restoreexpandmode\restoreexploremode
}
\makeatother

\setatomsep{2.5em}
\setcrambond{2pt}{}{}

\definesubmol{rt1}{-[2]rt1}
\definesubmol{rt2}{-[6,.6]rt2}

\definesubmol{ribose}{%
-[:-90,2]%
(%
-[:25,1.176]O%
-[:-25,1.176]%
)%
<[:-45,0.8]%
(%
-[0,,,,line width=2pt,shorten <=-.5pt,shorten >=-.5pt]%
(!{rt2})%
>[:45,0.8]%
(!{rt1})%
)%
}

\definesubmol{phosphate}{-[6,.6]O-[6,1.5]P(-[4,.8]HO)(=[6,0.8]O)-[,1.5]O}

\begin{document}

\derivesubmol{deoxyribose}{ribose}{(!{rt2})}{}% replace "(!{rt2})" by nothing
\derivesubmol{rt1}{rt1}{rt1}{base}
\chemfig{
!{deoxyribose}
!{phosphate}
!{deoxyribose}
!{phosphate}
}

\end{document}


First the building blocks "ribose" and "phosphate" are defined using \defsubmol. rt1 and rt2 are anchoring points or placeholders that can be replaced by whatever you define using \derivesubmol. As the original example already states, rt2 is replaced by "nothing" to obtain deoxyribose and rt1 can be replaced by the code for the corresponding base (as done in the original example) or just by the word "base" as I did in the above example.

## UPDATE

As stated by Marco Froelich in the comments, the CH2-Group at the 5' end of the deoxyribose molecules is missing. The following MWE contains this gruop as well and produces the image below.

\documentclass{minimal}
\usepackage{chemfig,xstring}
\makeatletter

% "\derivesubmol" defines the new #1 submol, obtained by replacing all the
%  occurrences of "#3" by "#4" in the code of #2 submol

% arguments: #1 = new submol name, #2 = old submol name,
%            #3 = old substring, #4 = new substring
\newcommand*\derivesubmol[4]{%
\saveexpandmode\saveexploremode\expandarg\exploregroups
\csname @\ifcat\relax\noexpand#2first\else second\fi oftwo\endcsname
{\expandafter\StrSubstitute\@car#2\@nil}
{\expandafter\StrSubstitute\csname CF@@#2\endcsname}
{\@empty#3}{\@empty#4}[\temp@]%
\csname @\ifcat\relax\noexpand#1first\else second\fi oftwo\endcsname
{\expandafter\let\@car#1\@nil}
{\expandafter\let\csname CF@@#1\endcsname}\temp@
\restoreexpandmode\restoreexploremode
}
\makeatother

\setatomsep{2.5em}
\setcrambond{2pt}{}{}

\definesubmol{rt1}{-[2]rt1}
\definesubmol{rt2}{-[6,.6]rt2}

\definesubmol{ribose}{%
-[:-30,1]%
-[:-90,1]%
(%
-[:25,1.176]O%
-[:-25,1.176]%
)%
<[:-45,0.8]%
(%
-[0,,,,line width=2pt,shorten <=-.5pt,shorten >=-.5pt]%
(!{rt2})%
>[:45,0.8]%
(!{rt1})%
)%
}

\definesubmol{phosphate}{-[6,.6]O-[6,1.5]P(-[4,.8]HO)(=[6,0.8]O)-[,1.5]O}

\begin{document}

\derivesubmol{deoxyribose}{ribose}{(!{rt2})}{}% replace "(!{rt2})" by nothing
\derivesubmol{rt1}{rt1}{rt1}{base}
\chemfig{
!{deoxyribose}
!{phosphate}
!{deoxyribose}
!{phosphate}
}

\end{document}


What I changed: I basically just added the following line -[:-30,1]% to draw the CH2-group and shortened the bond length from 2 to 1 in the following line: -[:-90,1]%.

• UPDATE: would it be possible to include the carbon link between the phosphate group -> deoxyribose? @leandriis – Marco Froelich Sep 18 '17 at 7:50
• @Marco Froelich: I have edited my answer according to your question. I hope this suits your needs. – leandriis Sep 18 '17 at 9:20