The first program I ever wrote was a molecular dynamics simulator. Molecular
dynamics is a simulation paradigm where atoms or molecules
in a body are placed in a 2- or 3-dimensional space. Forces are computed
between them using various potential functions (amongst the simplest being
Lennard-Jones potential, ie. V = k * (r**-12 - r**-6)
, where r
is the
distance between pairs of atoms). And then the positions of the particles are
updated using the Verlet algorithms which are based on Fourier
expansions of Newton's laws of motion.
A nice open source example of a molecular dynamics simulator is LAMMPS (wiki), which is developed by Sandia National Laboratory.
I wrote my own simulator in Java. This was back in the summer of 2007, so the GNU compiler project included a Java compiler which was what I was given to compile the program. It was also the first time ever for me using Linux, so I was completely unfamiliar with the CLI. (This is something all beginners have to go through, and I very sincerely do not ever want to forget what it was like so I can better understand and help other colleagues who are equally novice.)
In retrospect, the GNU Compiler for Java was a very cool project. I specifically remember the project's product page stating that their intent was to treat Java just like any other language, ie. that the language could be compiled to a native executable, rather than having to run it on the Java Virtual Machine.
But starting out, it was a miserable experience. I had two files: Atom.java
,
and MDSim.java
. I could trivially compile each of them to a .class
file. I
could create simple executables from single .java
files. But I just. could.
not. compile both of the two files into a single executable. My research team
was unable to help as well; I tried asking our post-doctoral researcher, but he
said he couldn't help because he didn't know Java. And I was denied when I
asked to install a more familiar IDE to make things simpler.
So finally, after days of endless web searches and documentation reading until by sheer luck (ie. trying everything with brute force), I finally managed to figure out the magic incatation:
gcj MDSim.java Atom.java
Aha! So the order of the filenames matters it seems.
And so I spent probably 2 whole weeks of my research internship trying to figure out how to write a 3 parameter command. The code was obviously not finished by that point, but that was undoubtedly the hardest part of the coding project.
From here, I was able to implement a very cool but still basic MD simulator.
-
I implemented periodic boundary conditions to reduce the influence of surface effects
-
I implemented body-centered and face-centered cubic lattices; I recall my research advisor stating that Lennard-Jones potential is not stable for simple cubic lattices
-
I implemented functions to measure things like the temperature of the crystal lattice
-
I visualised the results using a program called
minimol
, though I'm not even sure that it exists anymore -
Since the computer I was running on had two cores, I was able to perform computing the pairwise potentials between atoms in parallel, halving the program's runtime.
It was very cool seeing how in certain cases, the lattice would be a stable solid, while in others, it would melt. Tuning the starting temperature of the material just to the edge of the melting point and seeing how it reacted was very interesting. There were probably also additional functions that I could have implemented to quantify the solid's stability, but I'm pretty sure that I didn't do that.
Conclusion
In retrospect it was a very cool project. At the time, I did not at all appreciate that value of that kind of work. My silly 19-year-old self did not consider running computer simulations to be "real research". So I decided to leave that research project in favour of one that had a more laboratory-based experimental component. It actually turns out that I'm really bad at labwork for many reasons, one of which being that I am, well, very clumsy.
But in any case, as I continue moving further from the university chapter of my life, I can't help ponder the alternate reality where I stayed on the project and continued working in computational materials science. I think I would have been very good at it.