I'm working on my own 3D molecule viewer for my AP Chem class. So far everything's going together nicely. There's a couple of things I'm not sure about though...

Is there a certain rule of thumb or standard for what colors each element inside a molecule should be? For example, Jmol renders oxygen red and hydrogen white:

enter image description here

For my app they are currently grey:

enter image description here

Also, how can I check if there are single bonds, double bonds, etc.? As you can see here, I haven't programmed that yet into my app. Tylenol:

enter image description here enter image description here

I look up coordinates for each molecule in an NCI/CADD group server online database. This database gives me the number of elements, and the X, Y, and Z coordinates for where I should put each element. For example, water:

O   -0.0000   -0.0589   -0.0000
H   -0.8110    0.4677    0.0000
H    0.8110    0.4677    0.0000

It doesn't tell me anything about where bonds go. More info about .xyz file format here.

  • 2
    $\begingroup$ Might I ask which language you want are writing your app in? Because if it is C++ maybe you might be interested in Asymptote which is a vector graphics language with 3D support. With it you can 3D PDF documents and furthermore it integrates very well with LaTeX. Maybe you could use it to write you app. See my answer here: chemistry.stackexchange.com/a/560/189 $\endgroup$
    – Philipp
    Commented Sep 22, 2013 at 1:27
  • $\begingroup$ I'm writing this in Java. I'm using it as an Android/IOS app for my peers in High School. I was originally using the source code of Jmol. It worked but was very laggy. I decided to write a much lighter program that carries out the same function. I currently get 60+ frames a second. With Jmol I got like 15-20. $\endgroup$ Commented Sep 22, 2013 at 1:43
  • 1
    $\begingroup$ Thanks for the info. I wish you good luck with your app. When you're finished I would very much like to try it out if you intend to publish it for everyone. $\endgroup$
    – Philipp
    Commented Sep 22, 2013 at 1:51
  • $\begingroup$ Related: Why do the atoms in molecular models have the colors they have? $\endgroup$ Commented May 30, 2018 at 13:01

2 Answers 2


For the coloring part I would suggest you look at the CPK coloring convention.

As for the decision whether a bond is a single or a double bond: You could make this decision based on the bond length between two atoms. But you will need to find typical values for single, double and triple bonds for every combination of elements which seems a bit too much trouble. On the other hand, the depiction of double and triple bonds is used mostly for bonds between carbon, oxygen, sulfur, phosphorus and nitrogen (for other elements like metals the bond order is not readily identifiable, so I would leave those as single bonds). So, the amount of data to be collected might not be that large.

A very naive way to make the decision how many bonds an atom has could be the following (though this might not be very efficient):

  1. calculate the distances between the atoms
  2. for each element set a maximum distance another atom can be away from an atom of the element in question to be considered a bonding partner
  3. for each element set a maximum number of bonds $N_{\mathrm{max}}$ an atom of this element can have, e.g. 4 for carbon, 4 for nitrogen, 3 for oxygen, etc. (for metals this might be a bit difficult to decide)
  4. for each atom in the system order the list of atoms within bonding distance from lowest to highest distance. From this list choose only the first to $N_{\mathrm{max}}$th atoms as bonding partners. Then look whether some of the bonding partners qualify for double or triple bonds - if so you have to kick out some of the bonding members from the end of your bond candidates so that you don't exceed your maximum bond number.

There will be better ways out there to do this but this one worked for me in the process of creating "static" pictures of molecules.


You asked what size you should use for your atoms. Again, there is no definite answer to this - use whatever looks best for you. Nevertheless, I found that the sizes calculated according to the following formula give rather good looking atom size ratios for the different elements (maybe you have to multiply the resultant values by a constant to give good default sizes):

\begin{equation} \text{size} = \frac{1}{2 \sqrt{2}} \cdot \sqrt[6 \,]{\text{atomic number}} \ . \end{equation}

Furthermore, here is a nice source for some typical bond distances. Other good resources would be the CRC Handbook of Chemistry and Physics or the book by Holleman and Wiberg if you can lay your hands on them. Those might come in handy if you try to adapt my method and look for values for the maximum bond distances. Another advice concerning the maximum bond distances would be that typical values for the bond lengths of bonds containing (transition) metals are between 200 and 300 pm, so a value of 350 or 400 pm might be a good choice for the maximum bond distance for those species.

Concerning the maximum bond number each element can have: here, the typical rules for drawing Lewis structures apply. You can find good resources for this on this site, e.g. here, and in every introductory general chemistry text. But you should be mindful of some special cases. You should not forget the cationic forms of the elements, when thinking about their maximum bond number. For example, carbon usually has 4 bonds, but there are very rare cases where it comes with 5 bonds ($\ce{CH5^{+}}$) although those are practically not important and some not so rare cases where it has 3 bonds (carbenes, carbocations, carbanions), so you might consider a maximum bond number of 5 for carbon, although for nearly all practical purposes 4 might do. Another example is oxygen. It usually has 2 bonds but when it is protonated or in Meerwein's reagent ($\ce{Me3O^{+}BF4^{-}}$) it has 3 bonds. Transition metals are very flexible when it comes to the number of bonds they have - it can be everything from 1 to 6 sometimes even more, so you should choose a high number, e.g. 8, for them.

  • $\begingroup$ Is it necessary to include colors for different isotopes? For example: deuterium, an isotope of hydrogen. $\endgroup$ Commented Sep 22, 2013 at 1:38
  • $\begingroup$ I'd say that this is pretty much your choice. You don't need to stick with CPK coloring if you don't like (parts of) it. Some conventions are pretty widely spread, like white for Hydrogen or red for oxygen, but there are a lot of things I would consider "safe to change". $\endgroup$
    – Philipp
    Commented Sep 22, 2013 at 1:48

To extend on Philipp's excellent answer, I'd like to offer some advice on judging bond orders. Pekka Pyykkö and Michiko Atsumi published covalent (single-, double-, triple-) bond radii for (almost) the entire periodic table in Chem. Eur. J. 2009, 15, 12770-12779. It is summarised in figure 3. These are obtained from experimental or theoretical data. The figure itself can be found on Pyykkö's homepage as a pdf-file. This version has been extended to include tetrahedral covalent radii. I include a screenshot for reference.

covalent element radii

Another interesting and comprehensive publication for sizes of atoms is the list of Van der Waals radii of elements by S. S. Batsanov published in Inorg. Mat. 2001, 37 (9), 871-885. A mirror of the publisher's pdf can be found here. This is probably also a good starting point for deciding the default size of your atoms. Additionally it might help you identify weak interactions.

One last word on colouring: the mentioned CPK colouring scheme is widely known and many chemists understand it intuitively now, but it is not uncommon that programs specify their own schemes. That mostly depends of the background you would like to use. One of the most common deviations is carbon, which originally used black, but nowadays often is displayed grey because many viewers prefer dark backgrounds. Also frequently changed is the colour for hydrogen when using light backgrounds as white doesn't identify as well then.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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