# Chemical formulas with Mathematica

I am aware that there are many many things that we can do in Mathematica, but I am wondering if it is also possible to construct chemical compunds such as for example the one below?: EDIT:

Using @MarcoB suggestions I get the following:

MoleculePlot@ Molecule["FC1=CC(F)=C(C2OCC(COC3=CC=C(N4CCN(C5=CC=C(N6C=NN(C(C(O)C)\ CC)C6=O)C=C5)CC4)C=C3)C2CN7C=NC=N7)C=C1"]

which gives: Why are some molecules red and some others blue? Is there a way to control the color so that all are black for example?

Another possibility I just found was to used something simple like:

MoleculePlot@Molecule["C37H42F2N8O4"]

which gives: In this case, it also gives me automatically different colors for each molecule and also additionally the bonds out and in plane. How can I make normal bonds and tune the color?

• What do you mean by construct? If you want to draw chemical structures, then the industry standards are ChemDraw or similar programs. Have you seen the Molecular structure and computation guide? – MarcoB Jan 4 at 22:52
• Something like this? MoleculePlot@ Molecule["FC1=CC(F)=C(C2OCC(COC3=CC=C(N4CCN(C5=CC=C(N6C=NN(C(C(O)C)CC)C6=O)C=C5)CC4)C=C3)C2CN7C=NC=N7)C=C1"] – MarcoB Jan 4 at 22:58
• If you have version 12.2 you can try MoleculeDraw@MoleculeRecognize@Import["https://i.stack.imgur.com/ZL8dr.png"] – Jason B. Jan 4 at 23:02
• @MarcoB I am aware of ChemDraw but I was just wondering about the capabilities of Mathematica regarding this. Your code is great by the way – John Jan 4 at 23:17
• @JasonB. I have the version 12.1 and it looks like it gets the formula but I am not sure how to get it like in a picture or Tiff – John Jan 4 at 23:18

ClearAll["Global*"]


Assuming that you are starting with a chemical formula

Interpreter["Chemical"]["C37H42F2N8O4"] // InputForm

(* Entity["Chemical", "Posaconazole"] *)


Several forms of diagrams are available:

Entity["Chemical", "Posaconazole"][#] & /@ {"BlackStructureDiagram",
"CHBlackStructureDiagram", "ColorStructureDiagram",
"CHColorStructureDiagram", "LewisDotStructureDiagram", "MoleculePlot",
"StickMoleculePlot", "SpaceFillingMoleculePlot"} // Column EDIT: To increase (double) the font size

Entity["Chemical", "Posaconazole"]["BlackStructureDiagram"] /.
Rule[FontSize, Scaled[s_]] :> Rule[FontSize, Scaled[2 s]] • Bob Hanlon what a fantastic program Mathematica is! Thank you for this. One quick questions if you don't mind. Do you know if it is possible to make the molecules a little bit bigger (change the font of the molecules)? I am accepting your answer. Thanks – John Jan 4 at 23:54
• Use ImageSize with Show to change the size of the diagram: Show[diagram, ImageSize -> Large]. I do not know how to just change the FontSize`. – Bob Hanlon Jan 5 at 0:24