My recent project: MoleculeViewer

Hello, I have been working on this for a while and thought I would share it. It still needs some work but is getting pretty close to finnished

What it lets you do is view the structure of molecules such as methane or water. I still need to refine how well it shows the molecule structure but so far it can do simple ones.

Here is some screen caps:

Title screen:

Water molecule:

Methane molecule:

Github link:
Tell me what you think!


I like the idea a lot, how far do you intend to go with different molecules? Always fascinated me though its a subject I know next to nothing about.

I have made it so you input a string of text to create certain molecules (see first screen cap), so technically it could model most if not all molecules. I programmed the majority of this last year when I was doing the unit on VSEPR diagrams in chemistry.

I (studying technical physics) love the idea.
What would also be interesting to see is a rendering of the bonding orbitals. (Haven’t seen this in any molecule viewer yet)
Also, it’s better to make a bigger radius of carbon when compared to hydrogen and so on…

Cool, reminds me of that thing called RasMol.

I’m not sure what you mean by bonding orbitals, I haven’t gone over that in chemistry yet.

I never really thought of making the elements having different radius’s, I will definitely try to implement this, thanks for the idea!

Well, you may already know that the electrons moving around the nucleus are not moving in circular (or spherical) paths. Instead there are different kinds of “shapes” where you have a high probability to find an electron.
The two shells that are usually filled first have a spherical shape, those are the 1s and 2s orbitals. Then the next two shells that get filled are the 2p,x and 2p,y and 2p,z orbitals, which have shapes like a two sided lobe, pointing into the x, y and z directions. And then it goes on and on with other orbitals. These are the atomic orbitals.

In a molecule the orbitals where you have a “high chance to find an electron” look very different. One way of calculating them is to make a linear combination of atomic orbitals (LCAO) and minimize the total energy of the molecule, by choosing the right coefficients of the linear combination.
This involves solving the Schrödinger equation with some simplifications (you just cannot solve it otherwise).

Now you can imagine that some of the atomic orbitals are forming a bond when the atom is part of a certain molecule. The structure of the molecule (bond angles and bond order) along with the physical and chemical properties of the molecule is defined by these “bonding orbitals”.

What I mean is that molecules are not held together by rods of electron highways. It would be absolutely amazing if you could also see the bonding orbitals! But I’m glad that you’re interested in this topic. Your project looks cool and it is the first step of “imagining” a molecule.
May I ask how old you are and if you go to school or university?

Wow that a lot of text, thanks for the reply! I am currently in grade 12 doing Chemistry 30. I will have to look into how to implement it but I do get the basic idea of what you are saying.

From what I understand it can be shown through slightly transparent fields around the atom, with the first two electron shells being circular and the rest being two-sided lopes. This helped me understand what you were saying:

Also, do you know how to calculate the angles that each terminal atom would have around the central atom? I have been trying to figure this out for a while so a VSEPR form isn’t needed to determine the angles. I am also taking physics so I can handle calculating forces if that is needed.

Unfortunately calculating bond angles is not trivial. The basic procedure is as follows:

  1. “Guess”, by your own experience, the orbitals that form a bond. For this step alone you should already know how electronic orbitals are filled. There are also forbidden states! (Look up “Pauli principle” if you’re interested)
  2. Write down the Schrödinger equation, this is basically the kinetic and potential energy of all your nuclei and electrons. In this step you fix the nuclei at a certain position relative to each other. The resulting equation can be simplified.
  3. By solving the Schrödinger equation you will find a certain amount of energy for the position of your nuclei from step 2.
  4. Move the nuclei to a different position and repeat step 3.
    And so on…
  5. When you plot the energy as a function of the relative position of the nuclei you will find the total minimum energy. As you take physics you will probably know that nature tends to minimize energy. So this will (probably) be the shape of your molecule.

But this is quite complicated unless you have a very solid knowledge of higher mathematics. Don’t worry, you can learn this if you’re interested. Even I did :wink:

It is far easier for you to look up shapes of molecules in the Internet and have your wonderful application draw them. It’s fantastic! Keep up the good work.

PS: If the energy is at it’s minimum, then the molecule is at it’s equilibrium. This also means at there are no acting forces. :wink:

Thanks, I will look into what schrodinger’s equation is and hopefully figure out how to implement this!

Keep on learning :wink:

I finally got around to doing bond orbitals! I have also used an xml file I found online to allow me to have each atom sized differently. I had some issues trying to make the orbitals transparent so they are just opaque for now


Note: you might be able to simplify your UI code a lot with Lemur. If you are interested then I can offer some tips.

If you are now saying “I have no idea what Lemur is.” then:

I only mention it because nifty can be a handful for the relatively simple UI stuff that you are doing.

I have heard of lemur, I started this project before lemur was introduced so I used nifty. I will definitely look into whether or not lemur would be worth switching to, thanks!

Just a note in case it factors into perceived “stability/maturity” but Lemur has been around for almost 3 years and was used in a prototype form in Mythruna before that. It’s only the big documentation push that was recent.

It’s not quite a visualization of the bonding orbitals yet, but it looks cool! Must be water in outer space. :wink:

1 Like

Ah, that would make sense. Also @Apollo, what can I change about the bond orbitals to make them more accurate?

From the discussion above, I think you already had a good understanding about molecular orbitals. Remember, that these are certain places where you have a high chance to find an electron. Depending on the type of the bond they have different shapes. Take a look here, especially at the sigma and pi bonds. For water, the molecular orbitals look like this.
I think you will just have to dig deeper into physics and chemistry to get a true understanding of this. But your application is so cool, please keep on learning. No one can ever take away the things that are stored in your brain.

Thanks! I will look into the links more when I get home