![](https://thegreencode.org/wp-content/uploads/2022/01/red-apple_1f34e.png)
![](https://thegreencode.org/wp-content/uploads/2022/01/red-apple_1f34e.png)
|
This is an atom.
![](https://cdn-images-1.medium.com/max/1600/1*2XmxyMo-tV9ZXC7CLUl4qg.jpeg)
As you observe, it has a central core formed of neutrons and protons. But they are also surrounded by tiny particles called electrons. These particles are arranged in different electron layers called shells.
Most textbox images of atoms are static, so there’s a common subconscious misconception that atoms are static.
That’s far from reality. Both in the nucleus and especially in the electrons shells. The atoms that form us are in constant movement 24/7. They don’t stop.
So, in an attempt to help visualize this constant movement of electrons I decided to simulate them in Python.
Coulomb’s law
As you might know, while protons have a positive charge, electrons have a negative charge.
Therefore, they attract each other.
![](https://cdn-images-1.medium.com/max/1600/1*-yCmjnuuBG71mBx8voU2Bw.jpeg)
The opposite happens if you bring two electrons together; they repel each other.
There is also something to take into account here. In both cases, electrons and protons affect each other in proportion to the distance between each other. In other words, the force they exert on each other is proportional to their distance.
So, if two electrons are far away from each other, they will barely notice the presence of the other.
But, if there’s another electron close enough, things change. Remember electrons disgust each other, so when one sees that an electron is close by, he’ll go “Yuck this disgusting electron is really close to me, let’s get the hell out of here”. And so they go in completely opposite directions.
![](https://cdn-images-1.medium.com/max/1600/1*5R2WIghklZRfBQe3TMgOgg.jpeg)
All of these rules were gracefully summarized in 1785 by Charles-Augustin de Coulomb. So this became known as Coulomb’s law:
![](https://cdn-images-1.medium.com/max/1600/1*r8OobGrS5vAjHKYW36YLdg.png)
So simple, right?
(sorry if that was a bit boring, but now comes the fun part)
Using Python to simulate electrons
You can do a ton of things using python, but one of my favourite ones is drawing. Using some libraries (Turtle, for example) you can do a lot of cool stuff. Like this for example:
![](https://cdn-images-1.medium.com/max/1600/1*vcQ3WcdT_jJQS1g7Lv5rRQ.gif)
Or this:
![](https://cdn-images-1.medium.com/max/1600/1*J_nsLHgouqjjmR20NPd9BA.jpeg)
Pretty cool, eh?
Well, why don’t we use that to simulate electrons?
I started off trying to simulate two electrons. This is how it went.
![](https://cdn-images-1.medium.com/max/1600/1*MU_lP0xzGww6QBzP17Wncw.gif)
You might be thinking “that’s pretty boring” and that’s because it is.
I decided to spice things up a bit and give initial velocity to each electron. This way the two electrons might bump more into each other and produce more exciting patterns.
I also coded it so that electrons would bump into imaginary walls since that would contain them in a confined space.
![](https://cdn-images-1.medium.com/max/1600/1*iqMa55iQapu8ggDoLFTOqw.gif)
But there’s a problem with this; it’s not realistic at all. Although electrons change their paths when they encounter a fellow electron, they pretty much continue as if nothing.
This is really because we need more electrons! Only when more electrons are present do more complex patterns start to form.
More electrons!
The problem with adding more electrons is the number of calculations you need to perform.
When we had only two electrons, there was only one interaction between electrons. When you have 7 electrons, there are 21 interactions. And when you have 50 electrons, there are 1225 interactions. You get the gist, right?
![](https://cdn-images-1.medium.com/max/1600/1*p0rONJdilPPxPK30DfkREQ.jpeg)
So, at every point of the script, I calculate the interactions between a particular electron and all of the others. And then calculate how that electron should move next.
And volià! This is what I got!
I lied to you
Although the results are very cool (in my opinion, let me know what you think), there are obviously not realistic. In fact, basic textbook images of atoms don’t really make justice to their real chaotic nature.
This is what an atom truly looks like.
This is because nothing is certain in the quantum world. For example, it is physically impossible to know the position and the velocity of an electron at the same time. Think about how crazy that is.
That’s why in the photo above, electrons are represented by areas where they could be.
Electrons can be at two places at the same time. So, there’s also that.
Last updated: March 12, 2022