平均能量损失

平均能量损失

tikz我正在尝试使用 LaTeX和重新设计下面(丑陋的)图片chemfig。我已经可以绘制化学分子了,这没问题,我手动放置它们,但后来我想也许图书馆graphdrawing可以为我做到这一点。

在此处输入图片描述

当然,一次性绘制所有内容会产生一些错误(完全可以理解)。所以我想我可以为这些分子绘制大小像“框架”的空节点,并让 Lua 定位它们,然后我只需在放置节点的任何位置绘制化学分子即可。问题是它的nodes distance表现不如预期(或者确实如此?)。设置node distance=4cm我期望节点之间的距离至少为 4 厘米......

相反,我将其设置为 10cm,得到以下结果:

在此处输入图片描述

平均能量损失

\RequirePackage{luatex85}
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usegdlibrary{force}
\begin{document}
    \begin{tikzpicture}
    \begin{scope}[spring layout, node distance=10cm, every edge/.style={draw, very thick, -latex}, every node/.style={minimum width=6cm, minimum height=5cm, draw}]
    \foreach \i in {FA,CA,IFA,IFA3OS,DHCA,DHFA,DHIFA,DHCA3OG,DHFA4OS,DHIFA3OG,IFA3OG,DHFA4OG,FG,IFA3OS,FA4OS,5OFQA,5OCQA,4OCQAL,CA3OS,CA4OS,DHCA3OS} \node (\i) {};
    \draw   (CA)    edge    (FA)
                    edge    (DHCA)
                    edge    (IFA)
                    edge    (CA4OS)
                    edge    (CA3OS)
            (4OCQAL)edge    (CA)
                    edge    (5OFQA)
            (5OCQA) edge    (CA)
            (FA)    edge    (FA4OS)
                    edge    (FG)
                    edge    (DHFA)
            (5OFQA) edge    (FA)
            (DHCA)  edge    (DHFA)
                    edge    (DHCA3OG)
                    edge    (DHCA3OS)
                    edge    (DHIFA)
            (IFA)   edge    (IFA3OG)
                    edge    (IFA3OS)
            (DHFA)  edge    (DHFA4OG)
                    edge    (DHFA4OS)
            (DHIFA) edge    (DHIFA3OG);
    \end{scope}
    \end{tikzpicture}
\end{document}

无关:我遇到的另一个问题是边缘,即使它们是用->箭头指定的不是正在绘制……:/

答案1

目前,您的示例无法编译,因为节点名称不唯一。您可能想使用命令\graph并隐式创建节点。当您重复名称时,只会创建一个节点,但当然它可能与其他节点有许多关系。

选择合适的算法然后使用与该算法相关的选项来调整布局非常重要。node distance适用于某些情况,但并非全部。

这是一个layered layout使用sibling distancelevel distance来强制执行所需间距的版本。

\RequirePackage{luatex85}
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing,graphs}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}
  \graph [layered layout, sibling distance=10cm, level distance=10cm, edges={draw, very thick}, nodes={minimum width=6cm, minimum height=5cm, draw, as=}]
  {
    CA -- { FA, DHCA --  { DHFA, DHCA3OG -- { DHFA4OG, DHFA4OS }, DHCA3OS, DHIFA  -- DHIFA3OG }, IEA -- { IFA3OG, IFA3OS }, CA4OS, CA3OS, 4OCQAL -- 5OFQA -- FA -- { FA4OS, FG, DHFA }, 5OCQA };
  };
\end{tikzpicture}
\end{document}

分层图

改变

layered layout, sibling distance=10cm, level distance=10cm, 

spring layout, node distance=20cm,

我们有

弹簧布局

cooling factor在这种情况下,等等convergence tolerance也会影响结果。

或者将以上内容更改为

spring electrical layout, node distance=10cm, electric charge=5, 

生产

带有额外电荷的弹簧布局

或者不增加electric charge

带有默认电荷的弹簧布局

如果您想要的是箭头,请---><-或替换,然后使用或任意<->设置箭头尖。>=Latex

答案2

好的,我使用@cfr的建议实现了,layered layout并对spring electrical layout使用了一些技巧electrical layout。要在布局之间切换,只需将样式更改use layersspreaded并取消注释该行

% ,O[the central] --[draw=none] {CA,DHCA,FA,DHFA}% For spreaded layout

结果layered layout

在此处输入图片描述

结果spring electrical layout

在此处输入图片描述

代码

\RequirePackage{luatex85}
\documentclass[margin=5mm]{standalone}
\usepackage{tikz,chemfig}
\renewcommand*\printatom[1]{\ensuremath{\mathsf{#1}}}
\newcommand*{\HOOC}[2]{HOOC-[1]-[2]-[1]*6(=-=(-#1)-(-#2)=-)}
\newcommand*{\radicals}[2]{\edef\X{#1}\edef\Y{#2}}
\definesubmol{hooc}{HOOC-[1]-[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-)}
\definesubmol{isohooc}{HOOC-[1]=[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-)}
\definesubmol{quinic}{HOOC-[7]?(-[6]OH)-[:15]-[:-15](-[6]OH)-[:60](-[:-30]OH)-[:195](-[:60,3]O-[7](=[6]O)-[1]=[2]-[1]*6(=-=(-!{\X})-(-!{\Y})=-))-[:165]?}
\def\glucuronide{O-[:30](-[:60](-[:190,0.75]OH)-[:-15](-[:75,0.75]OH)-[:15]?-[:-15,0.75]OH)(-[:15]O-[::-30]?-[0,0.75]COOH)}
\setatomsep{2em}
\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{layered,force}
\begin{document}
    \begin{tikzpicture}[label position=below,
                        every label/.style={red},
                        >=latex,
                        rounded corners,
                        every edge/.append style={line width=6pt},
                        graphs/use layers/.style={layered layout,
                                                    sibling distance=8cm,
                                                    level distance=10cm,
                                                    /tikz/the central/.style={electric charge=-1.2},
                                                    /tikz/4OCQAL/.style={},
                                                    /tikz/DHIFA3OG/.style={},
                                                    /tikz/IFA/.style={},
                                                    /tikz/CA/.style={},
                                                    /tikz/DHCA/.style={}
                        },
                        graphs/spreaded/.style={spring electrical layout, node distance=11cm,
                        /tikz/the central/.style={electric charge=-1.2},
                        /tikz/4OCQAL/.style={node distance=15cm},
                        /tikz/DHIFA3OG/.style={orient=up, orient tail=DHIFA},
                        /tikz/IFA/.style={},
                        /tikz/CA/.style={electric charge=1.5, orient=up, orient tail=DHFA},
                        /tikz/DHCA/.style={orient=left, orient tail=FA}
                        }]
    \graph[use layers, nodes={circle, minimum size=6cm, as=}]{%
    CA[CA] <- {4OCQAL[4OCQAL] -> 5OFQA -> FA, 5OCQA},                       
    CA -> {FA -> {FA4OS, FG, DHFA},
           DHCA[DHCA] -> {DHFA -> {DHFA4OG, DHFA4OS},
                    DHCA3OG,
                    DHCA3OS,
                    DHIFA -> DHIFA3OG[DHIFA3OG]},
           CA4OS,
           CA3OS,
           IFA[IFA] -> {IFA3OG, IFA3OS}
           }
%   ,O[the central] --[draw=none] {CA,DHCA,FA,DHFA}% For spreaded layout
    };  
    \node[label={Ferulic acid}] at (FA) {\radicals{OH}{OCH_3}\chemfig*{!{isohooc}}};

    \node[label={Caffeic acid}] at (CA) {\radicals{OH}{OH}\chemfig*{!{isohooc}}};

    \node[label={Isoferulic acid}] at (IFA) {\radicals{OCH_3}{OH}\chemfig*{!{isohooc}}};

    \node[label={Isoferulic acid-3-O-sulfate}] at (IFA3OS) {\radicals{OSO_3^{-}}{OH}\chemfig*{!{isohooc}}};

    \node[label={Dihydrocaffeic acid}] at (DHCA)
    {\radicals{OH}{OH}\chemfig*{!{hooc}}};

    \node[label={Dihydrocaffeic acid-3-O-glucuronide}] at (DHCA3OG)
    {\radicals{OH}{\glucuronide}\chemfig*{!{hooc}}};

    \node[label={Dihydroferulic acid-4-O-sulfate}] at (DHFA4OS)
    {\radicals{OSO_3^{-}}{OCH_3}\chemfig*{!{hooc}}};

    \node[label={Dihydrocaffeic acid-3-O-sulfate}] at (DHCA3OS)
    {\radicals{OH}{OSO_3^{-}}\chemfig*{!{hooc}}};

    \node[label={Dihydro(iso)ferulic acid-3-O-glucuronide}] at (DHIFA3OG)
    {\radicals{OCH_3}{\glucuronide}\chemfig*{!{hooc}}};

    \node[label={Dihydro(iso)ferulic acid}] at (DHIFA)
    {\radicals{OCH_3}{OH}\chemfig*{!{hooc}}};

    \node[label={Isoferulic acid-3-O-glucuronide}] at (IFA3OG)
    {\radicals{OCH_3}{\glucuronide}\chemfig*{!{isohooc}}};

    \def\glucuronide{O-[:-30,1.5](-[:60](-[:190,0.5]OH)-[:-15](-[:75,0.75]OH)-[:15]?-[:-15,0.75]OH)(-[:15]O-[::-30]?-[0,0.75]COOH)}
    \node[label={Dihydroferulic acid-4-O-glucuronide}] at (DHFA4OG)
    {\radicals{\glucuronide}{OCH_3}\chemfig*{!{hooc}}};

    \node[label={Dihydroferulic acid}] at (DHFA)
    {\radicals{OH}{OCH_3}\chemfig*{!{hooc}}};

    \node[label={Caffeic acid-4-O-sulfate}] at (CA4OS)
    {\radicals{OSO_3^{-}}{OH}\chemfig*{!{hooc}}};

    \node[label={Caffeic acid-3-O-sulfate}] at (CA3OS)
    {\radicals{OCH_3}{OSO_3^{-}}\chemfig*{!{hooc}}};

    \node[label={Ferulic acid-4-O-sulfate}] at (FA4OS)
    {\radicals{OSO_3^{-}}{OCH_3}\chemfig*{!{isohooc}}};

    \node[label={Feruloglycine}] at (FG)
    {\chemfig*{HOOC-[:60]-[:20]NH-[:80](=[:120]O)(-[1]=[2]-[1]*6(=-=(-OH)-(-OCH_3)=-))}};

    \node[label={5-O-Feruloyquinic acid}] at (5OFQA)
    {\radicals{OH}{OCH_3}\chemfig*{!{quinic}}};

    \node[label={5-O-Caffeoylquinic acid}] at (5OCQA)
    {\radicals{OH}{OH}\chemfig*{!{quinic}}};

    \node[label={4-O-Caffeoylquinic acid lactone}] at (4OCQAL)
    {\chemfig*{?[a](=[:135]O)-[:280,2.5]?[b](-[6]OH)-[:15]-[:-15](-[6]OH)-[:60](-[:-30]O-[7](=[6]O)-[1]=[2]-[1]*6(=-=(-OH)-(-OH)=-))-[:195](-[:60]O?[a])-[:165]?[b]}};
    \end{tikzpicture}
\end{document}

有些事情还需要处理,但主要思想就在那里。希望它能对一些化学家或任何人有所帮助:)

相关内容