What Was the Goal?

For the GSoC 2018 event I proposed to develop tools for handling N-body simulations. It was planned to develop an interface system of potentials, forces, constraints, thermostating, which will allow one to use those components as construction blocks during the implementation of arbitrary N-body simulations.

NBodySimulator.jl

During the GSoC 2018 such tools were created in DiffEqPhysics project, devoted to solving physical problems formulated in terms of differential equations. At some point of coding period there were enough functions and features for N-body simulations to separate them into their own project.

NBodySimulator.jl was created in JuliaDiffEq organization as a container of tools for N-body simulations, including molecular dynamics, interaction of celestial bodies, charged particles, etc. Using the tools different systems of N-bodies can be modelled:

  • charged particles
  • magnetic particles
  • neutral atoms and molecules
  • celestial bodies
  • SPC/Fw water model
  • liquid argon and other Lennard-Jones fluids

For example, in the field of gravitationally interacting bodies, choreography is a periodic solution in which all the bodies are equally spread out along a single orbit. Here is one of such 5-body choreography modelled using NBodySimulator:

Here should appear a gif of the 5-body choreography

Flexible development of new systems is possible thanks to the following implemented potentials:

  • electrostatic
  • magnetostatic
  • Lennard-Jones
  • harmonic bonds between particles
  • harmonic angle made from pairs of bonds

One even can define a custom potential using interface of NBodySimulator described in the documentation and create their own structure for a system of particles or just use universal PotentialNBodySystem.

Specifically for molecular dynamics simulations four thermostats were created:

  • Anderesen thermostat
  • Berendsen thermostat
  • Nosé-Hoover thermostat
  • Langevin thermostat

For analyzing results of simulations one can use the following tools:

  • Radial distribution function calculation
  • Mean squared displacement calculation
  • Kinetic, potential, total energy functions

Radial distribution of liquid argon particles is shown in the next figure. rdf of liquid argon

Integration of NBodySimulator.jl with Makie.jl via its recipes allows one to create animations of water molecules:

It is also possible to import data from and export data to PDB files, and then, for example, visualize particles in VMD software. Though, it is fully implemented only for water for now.

Difficulties

The first trouble I faced with was implementation of periodic boundary conditions. It seems obvious for me now how to force particles going through one of the simulation cell boundary to appear at the opposite side of the box. But during the first weeks of coding for the GSoC, particles in my simulations were jumping all over the box, suddenly approaching to each other, creating strong repulsive force… and making the simulation finish with failure.

The second problem was the Langevin thermostating for water. It turned out to be difficult to understand how to write equations of the Langevin dynamics and therefore how to write code for molecules consisting of different atoms. Nevertheless, the problem was solved (the damping term of the Langevin equation should depend on the mass of an atom). Here is the example of thermostating the SPC/Fw model of water at 300 K: langevin thermostating for water

Further Work

As the next important step I plan to submit an article about NBodySimulator.jl to JOSS.

Certainly the work under development and improvement of the tools should be continued.

  • Performance improvements are the top of the list, because duration of calculations is important and the package aims to be performance competitive with established projects in the field.
  • Implementation of the Ewald summation or other algorithms for approximation of the long range potentials is highly needed for correct calculations.
  • The Nosé-Hoover chains or more advanced MD water models (TIP4P/2005, OPC, etc.) would be interesting for molecular dynamics simulations.
  • Handling rotation of magnetic moments will make NBodySimulator a great tool for simulating ferromagnetic fluids and elastomers.
  • For preparing further instructions and advice for users it can be useful to compare different integrators of differential equation from JuliaDiffEq solving N-body problems.

Documentation

The documentation for N-body simulation tools consists of

Code

All the features and tools I developed during the GSoC event were separated into a brand new project called NBodySimulator.jl.

But before that the development was proceeding inside DiffEqPhysics.jl project.

This is the list of my pull requests:

DiffEqPhysics.jl

NBodySimulator

Conclusion

All the tasks and goals of the GSoC project were completed.

Further work will be devoted to submitting a JOSS article and improvement of NBodySimulator project in order to make it a full-fledged open source tool for N-body simulations.