Attempting To Simulate Molecular Reactions


About 10 months ago, I attempted to create a simulation sandbox for atomic reactions using the Unity game engine. I wanted to see just how much the engine could handle before it became incredibly unstable. I stumbled back across this project recently and thought that it would only be right to talk about it. 

Each "atom" was created with the default unity 3-dimensional sphere game object, the "atom" would also have a sphere collider attached and my own custom C# script that contained properties that defined the "states" of the "atom". 

The "states" included properties such as the number of protons, neutrons, and electrons (in each shell). This also included several other properties such as whether or not the "atom" was radioactive, magnetic, or stable. There were even properties for compounds, gases, and liquids; making this quite the ambitious simulation. 

Upon the unfortunately frequent circumstance that an "atom" collided with another, the simulation would attempt to compute if the atoms were "compatible" and could become a compound by physically connecting to one another using a Unity "hinge" component at the collision position. If they were not "compatible" and rejected one another, they would reject one another by applying a small amount of force to each other. 

Within the simulation at the time of testing, there were only 6 different types of "atoms", these elements were selected intentionally due to their commonality within the real universe and how simple they are atomically. The elements chosen were:

  1. Carbon
  2. Hydrogen 
  3. Oxygen
  4. Chlorine
  5. Beryllium
  6. Random Mutation
"Random mutation atoms" have a random generation for which properties they contain, this is generated when they are instantiated.  

There's plenty more to discuss on this project. However, I would likely end up writing a several-page book about my findings! Watching my own little vacuum chamber populate varying based on my inputs was quite amusing, especially when I review the live streams that are available on YouTube that I streamed directly from my server overnight: https://www.youtube.com/@renovatesoftwarelabs5106

To conclude what my findings were at the time, I would certainly state that this simulation is far from being anywhere near perfect or even ideal for simulating atomic reactions on this kind of scale. The Unity collision system is buggy at best and causes many particles to escape even when confined within a perfect spherical colder. The performance is also very poor after not even 30 minutes of the simulation running; making the generation of any further reactions in an infinite simulation very slow to render. However, the game engine is not entirely to blame for the lack of any solid results; but my own understanding and knowledge of chemistry and physics at the time of its development. 

I've recently open-sourced this project, feel free to take a look at what is probably spaghetti code:

Comments