About my projects

In this section I publish reports of my hobby projects. These are mostly programming-related, but I occasionally try to do something ex silico as well. I like to write programs that model and simulate physical phenomena or serve as solvers for various puzzles and problems. I do not want to use pre-existing tools too much, instead I prefer writing my own tools and learn more from the mistakes that I make. As do my interests, also my project topics cover a broad range of scientific disciplines. I wish to demonstrate that I am capable of learning various new subjects independently and down to detail, and better yet, that I am adept at applying such knowledge to practice.

Phase field crystal

Phase field crystal (17.9.2015)

Update (27.9.2015)

I updated my manipulator program to support coupling the density field to a static external field. The external field can be used, for example, to emulate the influence of a substrate. Thus, surface ordering can now be studied with my manipulator. As a consequence of these changes, I've done some modifications to this report.

This report deals with my new interactive phase field crystal manipulator. The phase field crystal (PFC) model is a relatively recent (Elder et al., 2002) approach to model (defected) (poly-)crystalline materials at multiple length scales and diffusive time scales. In layperson's terms, the PFC model retains atomic resolution while the systems studied can easily span hundreds of nanometers (~ thousands of atoms in one direction), and it captures slow processes important for the evolution of microstructure in materials. I've been working with PFC models for just over a year now and have applied them to study two-dimensional systems—most importantly graphene.

PFC models are relatively simple and easy to work with. Nevertheless, it's often cumbersome to set up, via code, the initial state of PFC calculations or to automate certain manipulations to the systems studied. We humans are good at noticing patterns and details, and with eye-hand coordination. So, for situations where the benefits of human involvement outweigh its possible mind-numbingness, I wanted to develop a tool that would allow me to take direct control over PFC simulations. The end result is my interactive PFC manipulator code. It does everything your typical PFC program would—propagates a system according to the equation of motion, calculates the free energy and derived quantities, and writes related output—but has also a graphical user interface. The program renders PFC systems in real-time, allows one to manipulate them with the mouse and lets one control the simulation via various parameters that can be changed on the fly. I, for one, expect to benefit from being able to move individual dislocations around effortlessly and to probe the energies corresponding to these manipulated configurations. Moreover, in my research, I'm bound to come across many annoying metastable states that I can now, literally, just wipe away. Lastly, the manipulator makes it easy to carry out quick what-if experiments.

Ever since I started working with PFC stuff, I've had a hard time explaining what it is that I'm doing exactly. I think that my girlfriend, friends, family and relatives still haven't got a clue—"He does something with (graphene and) computers?". The secondary objective for my manipulator, therefore, is to alleviate this difficulty. Using my program, I can show people how PFC systems behave, for example, by preparing, in just seconds and right in front of their eyes, a bicrystal and letting them see how a grain boundary forms between the two crystals. The downside is, of course, that people will think that I get paid for playing a weird and boring computer game. I guess that's not too far from the truth, though.

I didn't think of this at first, but this tool can also help lower the learning curve for students new to PFC modeling. I'm sure that people will get a better picture of PFC models from interacting and playing with them in real-time. With minor modifications, the code can demonstrate also conventional phase field models and serve as an introductory tool to the world of phase field modeling.

I will next cover the basics of PFC models—after all, one of my goals is to better clarify the PFC approach and my work. This will get quite technical, as I wish to give the topic a proper treatment, but I'll do my best to make it understandable. If the following sounds like complete jargon, the manipulator program and the snapshots below will give a much better idea of PFC anyways. After this, I will introduce the functioning of my program and show some highlights.

Phase field crystal

As mentioned, PFC models make it possible to model crystalline material at multiple length scales and at diffusive time scales. PFC allows much larger systems to be studied than density functional theory (DFT) based first-principles calculations, and isn't limited to time spans of mere nanoseconds like molecular dynamics (MD) simulations. PFC dynamics track the evolution of a time-averaged atomic number density field. Albeit similar to that of the density functional theory, the PFC density field isn't as sharply peaked around the atom positions and requires, therefore, far less resolution—little information is needed to describe smooth fields. This translates to less computational effort and explains the large length scales available. PFC models capture elastic and plastic, or spring-like and ductile, material behavior. PFC functionals are rotationally invariant and all orientations for the modeled crystals are, therefore, possible. The absolute and relative translations of the crystals can also be arbitrary. The strength of PFC models isn't in the accuracy of their physical description, but they can predict realistic results—see my master's thesis and previous works.

The energy of a PFC system is given by a free energy functional that takes the density field ψ as its argument. For the standard PFC model, this reads
where the rightmost expression highlights the fact that, for negative ε, or temperatures below melting, the double-well potential is incorporated. The double-well potential means that there are two separate densities that correspond to a minimum energy state. The third term is a non-local contribution arising from deviation from a given curvature. In other words, in the minimum energy state, the density field of the system is periodic—akin to crystalline matter.

What's so important about the energy or its minimum? Well, nature has the universal tendency to pursue energy minima. We can drive the modeled systems towards these minima by assuming, for simplicity, non-conserved, dissipative dynamics. In essence, we are changing the density field so as to maximize the decrease in the energy at every step. In jargon, we are taking the steepest descent in energy in the state space. We violate the conservation of atoms but gain in numerical performance. Then again, many physical systems aren't closed and the total number of particles can fluctuate. The average density must be fixed via a chemical potential term or a third-order term that break the balance between the double-well minima. This offsets the density field from, and keeps it from vanishing to, zero. With a third-order term included (, and already differentiated along with the rest of the right-hand side in the expression below), the dynamics can be expressed as
where c is a coupling coefficient to ϕ, a static external field that can be used, for example, to emulate a substrate.

The manipulator code solves the above dynamics equation numerically using the semi-implicit Fourier space method and thereby marches the systems forward in time. This method can be expressed as
Here, the carets denote Fourier transforms and, indeed, this update formula is evaluated in Fourier space. My own fast Fourier transform (FFT) tools make it possible to compute the transforms with a satisfactory performance. In this case, real data transforms would suffice, but my code doesn't support this. Periodic boundary conditions ensue from use of Fourier transforms.

In addition to the standard PFC model, my manipulator can use the three-mode PFC model which is a bit more complicated but can produce a number of different crystalline phases. This is the model I've used in my work to study graphene.

The manipulator

The program, written in Java, is comprised of four classes that are the user interface (, the PFC simulator (, my own FFT tools ( and a class implementing complex numbers ( The fifth element is an input file that is used to control various things. The following list explains all the input parameters

  • name for the simulation
  • type of initialization; 0: random state, 1: bicrystalline state, 2: read from a data file*
  • filename for the *data file
  • filename for the external field data file; the program's output data files can be used; use a dummy name if no external field is needed
  • coupling coefficient; note that strong coupling may require a shorter time step to retain numerical stability
  • width of the system (must be a power of two!!!)
  • height of the system (must be a power of two!!!)
  • brush radius (you can manipulate the system in various ways using the mouse)
  • tilt angle (°) if initialized with a bicrystalline state
  • x discretization
  • y discretization
  • time step
  • frame update interval
  • write output interval
  • save state interval
  • PFC model; 0: standard PFC, 1: three-mode PFC
  • length scale for initialization and creating new lattice
  • ε
  • λ (three-mode model parameter**)
  • b0 (**)
  • b1 (**)
  • b2 (**)
  • τ
  • μ (**)
  • average density
  • annealing noise amplitude
  • rotation for crystal creation, negative value: random orientation
This zip file contains a runnable jar file for the manipulator, two working input files—one for the one-mode model, another for the three-mode model—and the source code. Just unzip the jar file and the input files into the same directory and you should be able to run the manipulator by simply double-clicking on the jar file—assuming, of course, that you have Java installed. It's better to launch the program from command line to be able to see its output. On Linux and OS X, the command "java -jar GPFC.jar" does the trick.

And now the features of my program. First of all, it renders the systems in real-time. Secondly, multiple keyboard commands are supported:

  • spacebar – pause/resume simulation
  • R – reload input file, you can change most of the input parameters on the fly as long as the simulation is paused first
  • S – writes the system state into a data file
  • I – writes a "screenshot" into an image file
  • M – toggles melting mode
  • A – toggles annealing mode
  • L – toggles crystal creation mode
  • C – toggles copying mode
  • P – toggles pasting mode
  • H – inquires the active brush mode
The last six items are related to "brushing". In melting mode, you can use the mouse to melt certain areas of the system. In annealing mode, you can apply noise to achieve localized simulated annealing. In crystal creation mode, you can overwrite existing lattice with new crystal—just update and reload the input file to get the desired, or a random, lattice orientation. When paused, you can toggle the copying mode and select an area to be copied. In pasting mode, you can drag the copied area to where you desire. Note, however, that if you resume the simulation without pasting first, the "clipboard" is emptied.

This code has a few small bugs that I've noticed, but they're mostly related to the visual aesthetics of pasting. A more fatal problem is that the program sometimes crashes due to an IllegalMonitorStateException. Luckily, this is quite rare and I've decided to ignore this issue. So no guarantees! Use at your own risk! I really don't yet have a clue what I'm doing with all this mouse and keyboard input—I've basically just reverse-engineered everything from some examples that I found online. But I'm learning...


The screen recordings below show what it actually looks like to use the manipulator program. In Video 1, I just fool around with the different brushing modes to give the reader an idea how they work. I draw some new crystals, melt stuff, anneal things and demonstrate copying and pasting. This first recording introduces the standard PFC model.

Video 1. Using my manipulator program to fool around with the standard PFC model.

Video 2 offers a bit more practical demonstration—I manipulate individual dislocations that comprise a grain boundary. The dislocations are melted, annealed, overwritten with new lattice and copy-pasted upon. If one is interested of the minimum energy grain boundary configuration, it is easy to copy-paste the dislocations into a new arrangement to probe the corresponding energy. Via annealing, you can also try to find new dislocation types. Beware however, the three-mode model, captured by this video clip, is prone to producing metastable, possibly even unphysical structures.

Video 2. Using my manipulator program to manipulate individual dislocations along a grain boundary produced by the three-mode model.

Video 3 demonstrates a hexagonal bicrystal coupled to a static, triangular field. This can be viewed, for example, as graphene on a close-packed metallic surface. I switch between two view modes—one depicting only the PFC density field (grayscale/cyan) and the other also the static external field, or substrate (red). Furthermore, I melt and anneal parts of the system, create new lattice and do some copy-pasting. I prepared the substrate via another PFC calculation.

Video 3. Using my manipulator program to fool around with a "graphene monolayer" on a "close-packed surface".


I succeeded in writing a PFC manipulator that takes mouse and keyboard input and renders the systems in real-time. The PFC approach is computationally lightweight which makes such an interactive program practical. Currently, systems with up to tens of thousands of atoms are doable with not too much frustration. In fact, the screen recordings above portray thousands of atoms each. With more efficient, parallelized (or GPU-) FFT routines, I expect far larger systems to become feasible. Nevertheless, as is, this manipulator offers interactive and effortless control over systems that are an order of magnitude larger than is possible exploiting DFT in terms of the atom count. Furthermore, the manipulator reaches diffusive time scales in seconds whereas this is altogether impossible using MD.

In addition to its potential usefulness to the people in the field, I'm confident that this program would be a good starting point for people new to the PFC approach. It's intuitive and effortless to use, and you get immediate response to your actions. I'm also sure that my friends and family will now get a better picture of what I'm doing.

In the future, I expect to benefit directly from my manipulator program, but also from the lessons learned in developing it—after a few higher-priority projects, I'll be able to start writing my very own computer game!


Juggling (1.1.2017)

Vocabulary (7.12.2016)

High-performance phase field crystal (6.8.2016)

Phase field crystal (17.9.2015)

Image stacking (23.7.2015)

Wind tunnel (13.12.2014)

Nebulae (8.11.2014)

Optical lithography (22.7.2014)

Evolution (22.5.2014)

Covalent molecules (23.11.2013)

Sudoku (18.7.2013)

Hama beads (4.6.2013)