Simulating Electrons with Python

I used Python to simulate electrons interacting with each other

Green Code
4 min readMar 12, 2022


This is an atom.

Image by the author of an atom.

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.

Image by the author of Coulomb's Law.

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.

Image by the author of electrons disgusting each other.

All of these rules were gracefully summarized in 1785 by Charles-Augustin de Coulomb. So this became known as Coulomb's law:



Green Code

I like science, coding and everything in between. Writer at