LaTeX forum ⇒ Math & SciencetikZ | Drawing Molecules

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

tikZ | Drawing Molecules

Postby ghostanime2001 » Thu Oct 25, 2012 11:25 am

I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing. I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds). I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms? Also, how do you orient bonds at different angles?

Tags:

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Thu Oct 25, 2012 11:36 am

ghostanime2001 wrote:I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing. […]

It is exactly the other way round.
ghostanime2001 wrote:[…] I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds). I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms? Also, how do you orient bonds at different angles?

And the chemfig manual didn't help? I'm sure that all your question are answered by just reading a bit in the package manual.
  1. \documentclass[11pt]{standalone}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{chemfig}
  4.  
  5. \setatomsep{2em}
  6.  
  7. \begin{document}
  8. \chemfig{N=[:30]N}
  9. \end{document}

If you expect specific help, a proper, self-contained and minimal example along with an adequate problem description is essential. That is something you should have learned by now.


Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Oct 25, 2012 12:04 pm

ghostanime2001 wrote:I want to draw molecules with tikZ not with chemfig because tikZ has more flexibility of tweaking bond lengths and atomic spacing.

Of course you can but IMHO you will soon notice that it's also a lot more work.

ghostanime2001 wrote:I tried to change these parameters with chemfig but there were lots of intricacies that I didn't like (for example really really short bonds).

If I had to guess (and apparently I have to) you probably set chemfig's atom sep to a short value but haven't read section 4 Length of a bond of the manual where the impacts are explained.

ghostanime2001 wrote:I can create single bonds between atoms, but how do you create double bonds/triple bonds for example between a carbon and oxygen atom or between two nitrogen atoms


See section 2 Different kinds of bonds.

ghostanime2001 wrote:Also, how do you orient bonds at different angles?

See section 3 Bond angle.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Thu Oct 25, 2012 9:28 pm

Thank for all your help. But I already know what you were talking about. In my post I was wondering weather similar effects (bonds, angles, bond length) can be done with tikz. I already know how to do it with chemfig.

Also, I know that between "slimmer" and "thicker" atoms the bond length varies that is why I am trying to change to tikz so that the bond length remains exactly the same length regardless of how thick or thin the width of atoms are.

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Oct 25, 2012 9:32 pm

Well, of course you can draw molecules with TikZ. The proof: chemfig uses TikZ. There is no chemistry library for TikZ if that's what you mean. You'd have to draw everything “by hand”, i.e., program it yourself.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Thu Oct 25, 2012 9:35 pm

That's exactly what I'm after but I how do you draw double bonds and triple bonds with TIKZ ?

User avatar
cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm

Postby cgnieder » Thu Oct 25, 2012 9:43 pm

I'm unsure what you want really... Do you already have code and are struggling with adding a second line (or third, resp.)? If so, please show what you already have so far.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Thu Oct 25, 2012 9:47 pm

ghostanime2001 wrote:That's exactly what I'm after but I how do you draw double bonds and triple bonds with TIKZ ?

  • Why are you so stubborn in this matter?
  • Why do you insist on this more difficult and more complicated method?
  • Are there any really good reasons against the package?

m(
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Postby ghostanime2001 » Fri Oct 26, 2012 9:06 am

I guess this could work as a MWE example. How do I set the bond length to be the same length for example 1cm?

  1. \documentclass[fleqn]{article}
  2. \usepackage[margin=1in]{geometry}
  3. \usepackage{chemmacros}
  4. \usepackage{chemfig}
  5. \usepackage{mhchem}
  6. \usepackage{tikz}
  7. \setlength{\parindent}{0pt}
  8. \setlength{\parskip}{0pt}
  9. \setlength{\mathindent}{0pt}
  10. \newcommand{\s}{\par\medskip}
  11. \newcommand{\sm}{\par\smallskip}
  12. \newcommand{\bs}{\par\bigskip}
  13. \pagestyle{empty}
  14. \usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri,matrix}
  15. \begin{document}
  16. \begin{tikzpicture}
  17. \node (a) {C};
  18. \node (b) [above=of a] {H};
  19. \node (c) [below=of a] {H};
  20. \node (d) [left=of a] {H};
  21. \node (e) [right=of a] {C};
  22. \node (f) [below right=of e] {O};
  23. \node (g) [right=of f] {H};
  24. \node at (a.north east) {+};
  25. \draw (a.north) to (b.south);
  26. \draw (a.south) to (c.north);
  27. \draw (d.east) to (a.west);
  28. \draw (e.west) to (a.east);
  29. \draw (f.west) to (e.east);
  30. \draw (f.east) to (g.west);
  31. \end{tikzpicture}
  32. \end{document}
Attachments
chemfig-bond-length.png
chemfig-bond-length.png (18.22 KiB) Viewed 7185 times

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Fri Oct 26, 2012 10:24 am

ghostanime2001 wrote:[…] How do I set the bond length to be the same length for example 1cm? […]

Isn't this exactly what chemfig does?
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{chemfig}
  4.  
  5. \setatomsep{1cm}
  6.  
  7. \begin{document}
  8. \chemfig{\chemabove{C}{\hspace{1pc}\scriptstyle +}(-[2]H)(-[4]H)(-[6]H)-C-[:-60]O-H}
  9. \end{document}
Attachments
tmp.png
tmp.png (2.74 KiB) Viewed 7184 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 2 guests