Giving `fix efield` a vector field from a CSV table

TIL how to use variables’ definitions, and then use them in fix efield. If I understand correctly, this method only enables defining electric fields of analytic expressions. I have a CSV table of numerical values of an electric potential (which I can compute it’s gradient of course). It was generated by a different program with certain electrode voltages defined there - not necessarily something analytic.

Is it possible to create a variable that will get values from such a CSV table? Or perhaps directly into the fix efield command?

The easiest thing to do is get Fourier coefficients for your function and then construct a per-atom variable calculating the Fourier expansion:

variable kx equal 2*PI/lx
variable fourierx atom 1.5*sin(x*kx+2)-0.25*sin(2*x*kx-0.4)+ ...

Also, there’s an entire package for electrode molecular dynamics called, well, ELECTRODE. Check it out and see if it can’t generate electrodes with a potential difference naturally for you.