13

It is possible to draw something like the figure below using TikZ enter image description hereor any other Latex package?

  • 2
    You can certainly create an image with TikZ or PSTricks. But in my opinion it is too complicated as image. I am often very brief, especially in my questions/answers. I believe that with InkScape you could convert your image to a TikZ or PSTricks code if I remember correctly and save a lot of time. – Sebastiano Aug 12 '18 at 20:12
  • @Sebastiano It is a good point, but I don't think this is too much for TikZ really. When I read the title I was worried the OP wanted to draw something more like en.wikipedia.org/wiki/Alpha-amylase#/media/… and came here with the intention of saying the same thing as you! :P But this cartoon is well within TikZ's capabilities I think, if one can be bothered – Au101 Aug 12 '18 at 21:54
33

I'd use pics for that. This allows you to draw the same thing, possibly with some variation, over and over. In this example, I use

\draw (1.2,2.9) pic[rotate=25] {Enzyme B=3};

Here, Enzyme B is the second of your enzymes, and 3 means both receptors (?) are filled. If I would had chosen 0, 1 or 2 instead, none, the lower one or the upper one would have been filled. (1.2,2.9) is the coordinate, and as you see, you can rotate the pic (or subject it to other transformations like scale for instance). I have left a few enzymes to be placed for you as an exercise. ;-) (EDIT: Made the radii of the bummies a bit smaller and adjustable.)

\documentclass[tikz, margin=3.14mm]{standalone} 
\pgfkeys{tikz/.cd,
bummy radius/.store in=\BummyRadius,
bummy radius=1.6mm
}
\tikzset{pics/.cd,
  Enzyme A/.style={
    code={
      \draw[thin,fill=green!30] (0.3,0) arc(90:270:0.15) -- (0.3,-0.3) to[out=-90,in=0] (0,-0.5)
      to[out=180,in=-90] (-0.3,-0.3) to (-0.3,0.3) to[out=90,in=180] (0,0.5)
      to[out=0,in=90] (0.3,0.3) arc(90:270:0.15) --cycle;
      \ifnum#1=1
       \fill[red!80] (1.1mm+\BummyRadius,-0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,-0.21) circle (\BummyRadius);
      \fi 
      \ifnum#1=2
       \fill[red!80] (1.1mm+\BummyRadius,0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,0.21) circle (\BummyRadius);
      \fi 
      \ifnum#1=3
       \fill[red!80] (1.1mm+\BummyRadius,-0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,-0.21) circle (\BummyRadius);
       \fill[red!80] (1.1mm+\BummyRadius,0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,0.21) circle (\BummyRadius);
      \fi 
    } 
  },
  Enzyme B/.style={
     code={
       \draw[thin,fill=green!30] (0.3,-0.02) -- (0.1,-0.02) |- (0.3,-0.4)
      |- (-0.3,-0.5) |- (0.3,0.5) |- (0.1,0.4) |- (0.3,0.02) -- cycle;
      \ifnum#1=1
       \fill[red!80] (1.1mm+\BummyRadius,-0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,-0.21) circle (\BummyRadius);
      \fi 
      \ifnum#1=2
       \fill[red!80] (1.1mm+\BummyRadius,0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,0.21) circle (\BummyRadius);
      \fi 
      \ifnum#1=3
       \fill[red!80] (1.1mm+\BummyRadius,-0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,-0.21) circle (\BummyRadius);
       \fill[red!80] (1.1mm+\BummyRadius,0.21) circle (\BummyRadius) (1.1mm+2.8*\BummyRadius,0.21) circle (\BummyRadius);
      \fi 
     }
   },
} 

\begin{document}
\begin{tikzpicture}
\draw[blue!40,ultra thick] plot[domain=-7.5:7.5,variable=\x,smooth,samples=50]
(\x,{tanh(\x/1.5)+3*exp(-0.5*\x*\x)});
\foreach \X in {-2.5,2.5}
{\draw[thick,dashed] (\X,-1) -- (\X,8);}
% left panel
\foreach \X in {0,1.5}
{\foreach \Y in {1,...,5}
{\draw (\X-7+0.1*rand,1.5*\Y+0.1*rand) pic[rotate=rand*20] {Enzyme A=0};}}
\draw (-3.3,6.8) pic[rotate=rand*20] {Enzyme B=0};
\draw (-3.4,5.3) pic[rotate=rand*20] {Enzyme B=0};
% middle
\foreach \X in {0,1.25}
{\foreach \Y [evaluate=\Y as \Z using {int(5-\Y)}]in {3,4,5}
{\draw (\X-2+0.1*rand,1.5*\Y+0.1*rand) pic[rotate=rand*20] {Enzyme A=\Z};}}
\draw (-1.2,2.8) pic {Enzyme A=3};
\foreach \X in {0,1.25}
{\foreach \Y [evaluate=\Y as \Z using {int(5-\Y)}]in {3,4,5}
{\draw (\X+0.75+0.1*rand,1.5*\Y+0.1*rand) pic[rotate=rand*20] {Enzyme B=\Z};}}
\draw (1.2,2.9) pic[rotate=25] {Enzyme B=3};
% right panel
\foreach \X in {0,1.5}
{\foreach \Y in {1,...,5}
{\draw (\X+5.5+0.1*rand,1.25*\Y+1+0.1*rand) pic[rotate=rand*20] {Enzyme B=3};}}
\draw (3.3,6.8) pic[rotate=rand*20] {Enzyme A=3};
\draw (3.4,5.3) pic[rotate=rand*20] {Enzyme A=3};
\end{tikzpicture}
\end{document}

enter image description here

  • 13
    Wow! You are truly a TikZ wizard-marmot. – Alan Munn Aug 13 '18 at 2:39
  • 5
    My eyes find it hard to believe that you have created a code exactly identical to the figure. You are extraordinary. – Sebastiano Aug 13 '18 at 7:41
  • 1
    Impressive! Now I'll try do adjust to my problem. Thank you very much! – Thales Souza Freire Aug 13 '18 at 19:09
14

just for fun and recognizing that marmot's code is really practical, a version with other options that require manual positioning, to get the result as close to the example; the enzymes have conditional parts derived from marmot's answer, but these are activated or deactivated with 0 or 1 to avoid defining 4 states.

RESULT: enter image description here

MWE:

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\definecolor{mygreen}{HTML}{BED395}
\definecolor{myblue}{HTML}{87ABEC}
\definecolor{linegreen}{HTML}{989F7F}
\definecolor{color1}{HTML}{DFD8C8}
\begin{document}
\pagecolor{color1}
    \begin{tikzpicture}
    \def\activator(#1){
        \begin{scope}[shift={(#1)}]
        \draw[line width=1pt,linegreen,fill=red](0,0)
            arc (180:40:0.15) arc (140:0:0.15) arc (0:-140:0.15) arc (-40:-180:0.15);
        \end{scope}

    }
    \def\enzymeA(#1)[#2]#3#4{
        \begin{scope}[shift={(#1)},rotate=#2]
        \draw[linegreen,fill=mygreen,line width=1pt]    (-0.5,0.76)
            -| ++ (1,-0.3) -| ++ (-0.4,-0.4) -| ++ (0.4,-0.12) -| ++ (-0.4,-0.4) -| ++ (0.4,-0.3) -| cycle;
            \ifnum#3=1 \activator(0.3,0.26) \fi
            \ifnum#4=1 \activator(0.3,-0.26) \fi
        \end{scope}
    }

    \def\enzymeB(#1)[#2]#3#4{
        \begin{scope}[shift={(#1)},rotate=#2]
        \draw[linegreen,fill=mygreen,line width=1pt](-0.5,0.76-0.3)
            arc (180:90:0.3) -- ++ (0.4,0) arc (90:0:0.3) arc (90:270:0.22) -- ++ (0,-0.05) arc (90:270:0.22) 
            arc (0:-90:0.3) -- ++ (-0.4,0) arc (-90:-180:0.3) -| cycle;
            \ifnum#3=1 \activator(0.4,0.24) \fi
            \ifnum#4=1 \activator(0.4,-0.25) \fi
        \end{scope}
    }
    %Start drawing the thing
    \draw[myblue,line width=3pt]
    (1.5,0) 
        to [out=0, in=180,out looseness=1.8,in looseness=0.4] ++(9,6)
        to [out=0, in=180,out looseness=0.4,in looseness=2] ++(9,-4);
    \draw[dash pattern = on 10pt off 10pt, very thick](0,0)++(6,0) -- ++(0,14);
    \draw[dash pattern = on 10pt off 10pt, very thick](6,0)++(9,0) -- ++(0,14);
    %Draw void enzymes B
    \foreach \x/\y/\rotation in {
        0/4/-5,
        1.5/5/10,
        3/4/10,
        0.2/6/-15, 
        2/7/10,
        3.5/6/-15,
        0.2/8/5,
        1.5/9/5,
        0.1/10/-10,
        1.5/11/26,
        0.2/12/-10,
        1.7/13/10,
        7/12/26,
        9/13/-10
        }
    {
        \enzymeB(\x,\y)[\rotation]{0}{0}
    }
    %Draw activated enzymes B
    \foreach \x/\y/\rotation in {
        8/6/-20,
        16/10/15,
        16/12/-15
        }
    {
        \enzymeB(\x,\y)[\rotation]{1}{1}
    }
    %Draw void enzymes A
    \foreach \x/\y/\rotation in {
        5/9/10,
        4.5/11/-5,
        13/13/-15
        }
    {
        \enzymeA(\x,\y)[\rotation]{0}{0}
    }
    %Draw activated enzymes A
    \foreach \x/\y/\rotation in {
        20/3.5/-15,
        18.2/3.5/26,
        20/5.4/15,
        18.5/5.4/10,
        19.2/7.3/-5,
        17.7/7.1/-5,
        19.7/9.1/-15,
        18/9/10,
        20./11/15,
        18.2/11/-5,
        20/13/15,
        18.2/13/-15,
        14/5.4/-10,
        12.5/6.2/26
        }
    {
        \enzymeA(\x,\y)[\rotation]{1}{1}
    }
    %Incomplete activation enzymes
    \enzymeB(7,8)[26]{0}{1}
    \enzymeB(7,10)[-15]{0}{1}
    \enzymeB(9,8.5)[15]{1}{0}
    \enzymeB(9,10.5)[-15]{0}{1}
    \enzymeA(12,11)[15]{1}{0}
    \enzymeA(14,11)[-15]{0}{1}
    \enzymeA(12,8.5)[15]{1}{0}
    \enzymeA(14,8.5)[-26]{0}{1}
    \end{tikzpicture}

\end{document}
10

Since that is just a very quick answer, here are just the “styles“ that are necessary:

\documentclass[border=5pt,tikz]{standalone}
\begin{document}
    \begin{tikzpicture}[green!70!black]
        \begin{scope}[rotate=75]
            \draw (0,0) arc(0:180:.5);
            \draw (1,0) arc(0:180:.5);
                \draw (-1.5,.5) arc(180:270:.5);
                \draw (-1.5,.5) --+ (0,.5) arc(-180:-270:.5) --+ (2,0);
                \draw (1.5,1) arc(0:90:.5);
            \draw (1.5,1) --+ (0,-.5) arc(0:-90:.5);
        \end{scope}
        \fill[yshift=-4cm,xshift=-1.7cm,green!70!black!50] (0,2) -- (0,0) --+ (1.5,0) --+ (1.5,.3) --+ (1.1,.3) --+ (1.1,.9) --+ (1.5,.9) --+ (1.5,1) -- (1.1,1) --+ (0,.7) --+ (.4,.7) --+ (.4,1) -- cycle;
        \begin{scope}[xshift=-1.2cm,yshift=-5cm]
            \draw[very thick,red!70!black,fill=red!70!black!80] (0,0) circle(.5);
            \draw[very thick,red!70!black,fill=red!70!black!80] (.5,0) circle(.5);
                \draw[red!70!black!80,fill=red!70!black!80] (0,0) circle(.5);
                \draw[red!70!black!80,fill=red!70!black!80] (.5,0) circle(.5);
        \end{scope}
    \end{tikzpicture}
\end{document}

Here is the output:

Screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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