This week’s project is a molecular dynamics simulation. Don’t get too excited, it’s not using any of the state-of-art algorithms nor is assembling 3-dimensional structures of complex proteins. I began with a simple carbon chain using only coulomb’s law in a spring-mass system.

The molecule I’m using is this:

Molecular Dynamics

The drawing program is quite simple and wont work for most molecules, but for the 2-dimensional simple molecules (max. of 3 connections per atom) it kinda works.

Later on, putting the program to run, each atom “pushes” all others electrically and the spring “pulls” them back. A good way to solve that is to say that q1 . q2 / x² = – k . x = m . d²x/dx² (where x is a vector) and integrate numerically using Runge-Kutta.

But that’s my first openGL program, so I decided to go easy on the model and actually see it pseudo-working with an iterative-based simulation following the same equations above. This picture is a frame after a few iterations.

Quoting its page: “As this simulation is not using any differential solution, the forces grow and grow until the atom becomes unstable and break apart. Some Runge-Kutta is required to push the realism further.


The webpage of the fully-functional prototype is HERE.

One Reply to “Silly project of the week: molecule dynamics”

  1. I’m having problems with the order of things in the map and in the graph in different computers (expected). I’ve changed the master list to a vector but the graph can’t be changed that easily.

    If the directions of the connections is reversed in your machine (tend to repeat in the same machine), please change the order in the (*it).bond->direction definition in Molecule::naivePositioning().

Leave a Reply

Your email address will not be published. Required fields are marked *