许多生化分子,例如核酸,都是由自然界中有限数量的构建块以层次化方式组成的。在排版这些分子时,最好能复制这种方法。对于 DNA 和 RNA,一种自然的方法是:
- 定义核糖、磷酸和碱基(A、C、G、T、U)的单独结构
- 从核糖中提取脱氧核糖
- 通过将核糖或脱氧核糖与每个碱基结合来创建核苷
- 将 DNA 和 RNA 分子写为核苷和磷酸的交替形式。
该chemfig
软件包提供了一个\definesubmol
命令,允许定义子分子,然后可以将其替换为其他分子。但是,该软件包没有提供内置机制来使此类替换的结果可用作新的子分子。因此,问题是如何定义具有以下行为的命令:
% "\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]{% ...
此描述取自软件包作者chemfig
通过电子邮件提供给我的代码。我在下面提供的答案中提供了他的代码运行示例。
为了表明这个问题确实是一个问题,让我补充一点:???
答案1
这个答案是 Christian Tellechea 在私人通信中提供给我的;我把它发布在这里是为了让其他可能感兴趣的人受益。
\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}
\definesubmol{adenine}{N*5([::-18]-*6(-N=-N=(-NH_2)-)=-N=-)}
\definesubmol{uracil}{N*6(-(=O)-NH-(=O)-=-)}
\def\drawhline{\medbreak\hrulefill\medbreak}
\begin{document}
\chemfig{!{ribose}} \quad\quad The ribose template
\drawhline%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\derivesubmol{deoxyribose}{ribose}{(!{rt2})}{}% replace "(!{rt2})" by nothing
\chemfig{!{deoxyribose}} \quad\quad In deoxyribose, substituent rt2 is replaced by nothing
\drawhline
\derivesubmol{deoxyadenosine}{deoxyribose}{!{rt1}}{-[2,0.8]!{adenine}}
\chemfig{!{deoxyadenosine}} \quad\quad \parbox{4in}{Deoxyadenosine is derived from deoxyribose by substituting rt1 with adenine}
\drawhline%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% other method: locally redefine "rt1" submol and display "deoxyribose"
\begingroup
\derivesubmol{rt1}{rt1}{rt1}{!{adenine}}
\chemfig{!{deoxyribose}}
\endgroup
%
\quad\quad \parbox{4in}{Local redefinition of the rt 1 substituent in deoxyribose works, too}
\drawhline%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\derivesubmol{deoxyuridine}{deoxyribose}{!{rt1}}{-[2]!{uracil}}
\chemfig{
!{deoxyuridine}
!{phosphate}
!{deoxyadenosine}
!{phosphate}
!{deoxyuridine}
}
%
\quad\quad \parbox{2.5in}{Using the previously derived dU and dA templates, we can now easily write a DNA molecule}
\end{document}
图中显示的是最后一条命令的结果\chemfig
:
不用说,我对这个解决方案非常满意。如果有人不满意,这个chemfig
软件包可以让他们毫不费力地调整结构的各个方面。我强烈推荐它。
答案2
你的意思不太清楚,但下面的方法似乎更容易使用。请注意,我不是化学家,而且我学化学(中学阶段)已经是很久以前的事了。
\documentclass{minimal}
\usepackage{chemfig}
\setatomsep{2.0em}
\setcrambond{2.0pt}{}{}
\setbondoffset{0.5pt}
\definesubmol{OH}[HO]{OH} % let OH groups figure out which way to point
\definesubmol{phosphonate}{%
P
(=[::90,0.7]O)
(-[::-90,0.7]!{OH})
-[::0,0.7]!{OH}
}
\definesubmol{sub1}{A}
\definesubmol{sub6}{B}
\definesubmol{fructose}{
{}?[a]
(-[:90,0.6]
-[:30,0.7]O
-[:0,0.7]!{sub1}
)
<[:225,0.8]
(-[:-90,0.6]OH)
(-[:180,0.5,,,draw=none] % note the devlishly clever trick
-[:90,1.26,,,draw=none]O?[a]?[b] % to position the oxigen in the ring
)
-[:180,1,,,line width=2pt]
(-[:90,0.6]OH)
>[:135,0.8]?[b]
-[:90,0.6]
-[:150,0.7]O
-[:180,0.7]!{sub6}
}
\begin{document}
\tikzset{sub1/.code=\redefinesubmol{sub1}{#1},
sub6/.code=\redefinesubmol{sub6}{#1}}
\begin{tikzpicture}[x=0.8in,y=0.8in]
\node[anchor=south west] at (0,2) {\chemfig{!{fructose}}};
\begin{scope}[sub1=H,sub6=H]
\node[anchor=south west,sub1=H,sub6=H] at (2.5,2) {\chemfig{!{fructose}}};
\end{scope}
\begin{scope}[sub1=!{phosphonate},sub6=H]
\node[anchor=south west] at (5,2) {\chemfig{!{fructose}}};
\end{scope}
\begin{scope}[sub1=H,sub6=!{phosphonate}]
\node[anchor=south west] at (0,0) {\chemfig{!{fructose}}};
\end{scope}
\begin{scope}[sub1=!{phosphonate},sub6=!{phosphonate}]
\node[anchor=south west] at (2.5,0) {\chemfig{!{fructose}}};
\end{scope}
\end{tikzpicture}
\end{document}
当然你也可以使用选项中的选项sub1
和。sub6
node
也许你可以再解释一下你想要什么?(抱歉我的无知。)
答案3
我写了一个简短申请上述 Christian Tellechea 通过 @MichaelPalmer 提供的答案,添加所有核苷并制作双链图片。完整代码可以在这里找到这里。
\documentclass[11pt]{standalone}
\usepackage{chemfig,xstring} %Draw molecules with easy syntax
\usepackage{times}
\frenchspacing
\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]%
(%
-[::115,1.176]O%
-[::-50,1.176]%
)%
<[::45,0.8]%
(%
-[::45,,,,line width=2pt,shorten <=-.5pt,shorten >=-.5pt]%
(!{rt2})%
>[::45,0.8]%
(!{rt1})%
)%
}
\definesubmol{phosphate}{-[::-45,.6]O-[::0,1.5]P(-[::-90,1]O{^-})(=[::0,0.8]O)-[::90,1.5]O}
\definesubmol{adenine}{N*5([::-18]-*6(-N=-N(<:[::-83,1.6,,,red])=(-N(-[::66]H)-[::-66]H<:[::-18,1.5,,,red])-)=-N=-)}
\definesubmol{adenineR}{N*5([::-18]-=N-*6(-(-N(-[::66]H<:[::-25,1.5,,,red])-[::-66]H)=N(<:[::-76,1.5,,,red])-=N-)=-)}
\definesubmol{guanine}{N*5([::-18]-*6(-N=(-N(-[::66]H<:[::-25,1.6,,,red])-[::-66]H)-N(-H<:[::-17,1.7,,,red])-(=O<:[::-75,1.7,,,red])-)=-N=-)}
\definesubmol{guanineR}{N*5([::-18]-=N-*6(-(=O<:[::45,1.5,,,red])-N(-H<:[::-16,1.5,,,red])-(-N(-[::66]H)-[::-66]H<:[::-9,1.5,,,red])=N-)=-)}
\definesubmol{uracil}{N*6(-(=O)-N(-H)-(=O)-=-)}
\definesubmol{cytosine}{N*6(-(=O<:[::50,1.7,,,red])-N(<:[::-73,1.6,,,red])=(-N(-[::66]H)-[::-66]H<:[::-3,1.5,,,red])-=-)}
\definesubmol{cytosineR}{N*6(-=-(-N(-[::66]H<:[::-19,1.7,,,red])-[::-66]H)=N(<:[::-72,1.6,,,red])-(=O<:[::-75,1.6,,,red])-)}
\definesubmol{thymine}{N*6(-(=O)-N(-H<:[::-10,1.6,,,red])-(=O<:[::-75,1.5,,,red])-(-H_3C)=-)}
\definesubmol{thymineR}{N*6(-=(-H_3C)-(=O<:[::32,1.6,,,red])-N(-H<:[::-33,1.7,,,red])-(=O)-)}
\def\drawhline{\medbreak\hrulefill\medbreak}
\begin{document}
\derivesubmol{deoxyribose}{ribose}{(!{rt2})}{}% replace "(!{rt2})" by nothing
\derivesubmol{deoxyadenosine}{deoxyribose}{!{rt1}}{-[::65,0.8]!{adenine}}
\derivesubmol{deoxyguanosine}{deoxyribose}{!{rt1}}{-[::65,0.8]!{guanine}}
\derivesubmol{deoxyuridine}{deoxyribose}{!{rt1}}{-[::45,0.8]!{uracil}}
\derivesubmol{deoxycytidine}{deoxyribose}{!{rt1}}{-[::45,0.8]!{cytosine}}
\derivesubmol{thymidine}{deoxyribose}{!{rt1}}{-[::45,0.8]!{thymine}}
\derivesubmol{deoxyadenosineR}{deoxyribose}{!{rt1}}{-[::-35,0.8]!{adenineR}}
\derivesubmol{deoxyguanosineR}{deoxyribose}{!{rt1}}{-[::-35,0.8]!{guanineR}}
\derivesubmol{deoxycytidineR}{deoxyribose}{!{rt1}}{-[::-60,0.8]!{cytosineR}}
\derivesubmol{thymidineR}{deoxyribose}{!{rt1}}{-[::-50,0.8]!{thymineR}}
\begin{tikzpicture}
\scriptsize
\node at (1,3) {\chemfig{ [:-65]
!{phosphate}!{deoxyadenosine}!{phosphate}!{deoxyguanosine}!{phosphate}!{thymidine}!{phosphate}!{deoxycytidine}}};
\node at (6.4,2.5) {\chemfig{ [:115]
!{phosphate}!{deoxyguanosineR}!{phosphate}!{deoxyadenosineR}!{phosphate}!{deoxycytidineR}!{phosphate}!{thymidineR}}};
\end{tikzpicture}
\end{document}