Electrostatics in Julia

Does anyone know of Julia libraries implementing electrostatic summations in Julia? (e.g. Ewald, Particle Mesh Ewald, Fast Multipole Method…)

I haven’t been able to find much by googling:

  • A fairly complex bio orientated package which I think is doing more Generalized Born Surface Area type modelling


  • Seems to be a fairly standard 3D Ewald solver, but implemented within a fairly specialist Monte-Carlo code for gas affinity calculations in porous structures.

It seems like such a standard (but fiddly…) requirement for so many modelling applications, that I’d be surprised if no one has implemented something / written a Julia interface to a standard library!


I agree this would be really useful.

See some discussion at https://github.com/jgreener64/Molly.jl/issues/2 where Zarathustra says they have some EWALDS code.

@SebastianM-C may also be interested.


I saw a package not too long ago that had FMM and got excited, but it turned out to be a Julia wrapper for some fortran code (could still be interesting though). Unfortunately, I probably won’t be able to find it again but maybe it helps to know it exists :slight_smile:

[Edit: I take it back, I was able to find it: https://github.com/flatironinstitute/FMM3D, but don’t see any Julia there at the moment. Maybe it was a WIP.]


We have a basic Ewald routine in https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/terms/ewald.jl, would be great to replace it with a more standard one if someone makes it into a package!


Ah, OK! I guess it is one area where Julia surprisingly doesn’t have a package yet.

Antoine, your routine looks like a nice base to build an Ewald.jl package upon (and MIT licensed, unlike the PorousMaterials routine). I guess @jgreener64 would really want a O(NlogN) scaling Particle-Mesh-Ewald method, and for myself I need a 3D sum with 2D periodic boundaries (which can be a bit painful). But all of this could use the same interface. We just need someone to do it :slight_smile: .

There seems to be a binarybuilder for FMM3D, so maybe something is in the works? https://github.com/JuliaPackaging/Yggdrasil/blob/master/F/FMM3D/build_tarballs.jl


@SebastianM-C is a JSoC student working in this right now, so we just ned some good references to send to him. If you’re on the Slack then you should join our chats


Great! I wondered if this might be something needed for the N-body package shortly.

I’m trying to reduce my Slack habit, but can surely join in.

Awesome to hear that. Please keep us in the loop about that project. We have found that on bigger systems our simplistic Ewald routine, which I wrote really not with a focus on speed back in the days, starts to be a major contribution to our setup time in DFTK. We’d love to not spend the time optimising it, if someone else makes a nice package for these type of problems :smile:

#nbody on Slack for anyone who wants to join.


I think this is fairly inevitable. A standard Ewald is O(N^2) and this scales with the system volume. Doing porous structures in a plane-wave DFT code is always a bit of a drag. For classical molecular dynamics, Particle Mesh Ewald is the standard approach, which gets O(N logN) by using a FFT in the reciprocal space summation, but at the cost of some slight artefacts (point charges are replaced by an Gaussian of charge density). I’m not sure if this is used for DFT by anyone. It might be worth looking at what the ‘linear scaling’ DFT codes use, as they must hit this problem head-on.

I think abstracting the DFTK Ewald code into a Ewald.jl package, and then iterating from there (optimising, adding 2D PBCs, particle-mesh etc.) makes a lot of sense in terms of being a useful package quite quickly.

FMM would be really nice, but I suspect it’d make sense to have it in a separate package. And then maybe a ElectrostaticSummation (but actually both Ewald and FMM can be used for long range potentials & forces from other power laws…) interface for both backends?
What do people think?

1 Like

Are there more basic routines for electrostatics / electrodynamics, akin to what https://github.com/juliaphysics provides?

Regarding linear scaling of Ewald: Surely those methods exist, there is for example DOI 10.1103/PhysRevMaterials.2.013806 by Chris Pickard which includes surface charges in a truncated real-space sum to get to linear scaling, it’s just that it has not been a problem to us until recently. Also I think just optimising our code properly (e.g. improving on the real-space / fourier-space balance, general Julia performance issues) could already bear some fruit, so we have not yet bothered implementing more sophisticated stuff.

Regrading what you proposed package-wise: I think it makes sense to have a generic FMM package, which could be used for treating general electrostatic expansions in other domains and an Ewald package to get started. How they eventually grow together I would leave for the future to sort out. I’ve never looked at more clever Ewald routines beyond what we use right now, so I don’t really have an overview what exists and what would fit in. I’d be happy if our code could be used as a starting point. Let me know if I can contribute in some way!

Regarding a good spot for a package: Since Ewald is as far as I know used a lot in molecular science (MD, DFT, …), we could perhaps place the package in JuliaMolSim. I’d be happy to do the setup.

1 Like

There is LaplaceBIE for calculating electrostatic/magnetostatic source effects on homogeneous bodies. I created it after refactoring my previous research on calculating surface equilibrium of magnetic liquid droplet in fast rotating magnetic field. The focus of the package is to calculate surface field which can be used to calculate surface force. In simple terms it allows to calculate force exerted of nails from nearby magnet, or attractive force of dielectric due to presence of charge.

1 Like

Hello! I’m the JSoC student mentioned earlier by @ChrisRackauckas
Regarding the possibility of an Ewald package, I started looking at the code in DFTK, but I would appreciate if you could point me to some references / introductory material on the topic. I discussed with @jgreener64 about creating an API for summing accelerations (given the specific accelerations / forces corresponding to various potentials) and having different summation algorithms is a natural extension.

Initially we discussed that this could go in Molly, but since it looks like there is interest for a separate package (or multiple packages), I think that a good plan would be to start with a separate package and see how Molly can be hooked to use it.

I’ll post an update here after I have some code and maybe we can discuss wish-lists and design decisions on the API in issues / PRs.


There are tons of papers and books on Ewald summation. I read dozens of them and still didn’t understand (and am not 100% sure I understand it fully now). The main point is that the electrostatic energy per unit volume of a macroscopic sample depends on its shape. Mathematically this results from the fact that the sum is not absolutely convergent, and therefore that you can get any result by changing the summation order. However in practice you are interested in bulk properties and not surface effects, and so any method that gives a well-defined result is good. Ewald is such a method. Then in a second step you have to study potential surface effects. There are a few derivations of Ewald, but the simplest I found is to regularize the Coulomb, take the infinite volume limit, then make the regularization parameter tend to zero. We wrote a note with @mfh some time ago here if that helps: http://antoine.levitt.fr/ewald.pdf


What helped me when we tackled the topic last year was Appendix F of Kenny B. Lipkowitz and Thomas R. Cundari Reviews in Computational Chemistry Volume 24 (2007) DOI 10.1002/9780470164112, which talks about the “Mathematical aspects of Ewald summation”. I also recall reading this nice summary. I hope that helps to get started.


By the time you are doing Ewald / FMM sums on structures with atomic scale, you’ve already specialised quite a lot. So I think having a Condensed Matter Theory / Solid-State Chemistry orientated package makes a lot of sense.

There are some even more highfalutin physics approaches to the problem, such as using Maxwell’s equations with a reduced speed of light to make the physics local.

I think this makes a lot of sense. It’s also the obvious place to extend to the 2D and 1D Ewald-like summations, and include the dipole & homogenous background charge (tinfoil boundary conditions), used in electronic structure / physics-like calculations.

Particle-Mesh-Ewald perhaps makes more sense in the context of Molly / Nbody as it’s mainly used for MD (?).

Off topic: Maybe molly would like to join JuliaMolSim? I’m still hoping we can make Molly and JuLIP compatible.

1 Like

That would be awesome! I never thought of JuliaMolSim to be just electronic-structure and interatomic potentials :smile: … from my end MD would fit right in as well.