LAMMPS fix efield output

Hello!

I have used fix 2 all efield 0.025 0 0 to apply 0.025 V/Å filed in x direction, however while doing thermo_style custom f_2 f_2[*] strange values are getting printed other than 0.025 0.025 0 0. Could anyone tell me how to display the output of electric field applied by Lammps within my sample?

Thank you, in advance!

What are “strange values”?

Here is what the documentation says:

This fix computes a global scalar and a global 3-vector of forces, which can be accessed by various output commands. The scalar is the potential energy discussed above. The vector is the total force added to the group of atoms. The scalar and vector values calculated by this fix are “extensive”.

Why do you think that this output should be “0.025 0.025 0 0”?

What is the “output of electric field applied”?

Please note that with just a single command line quoted from a script, it is near impossible to make any specific statements outside of what the documentation already says. There is simply not enough context to understand what you are trying to do and what your system is and so on.

1 Like

Thanks Axel for a prompt response. I have a system of 2 different sets of molecules whose atoms have assigned charges. I am trying to observe whether the fixed electric field applied to this system through the fix efield command remians constant for the entire computation or there are some changes in the value (as I am using fix 1 all nvt and then fix 2 all efield ). Therefore, to ensure that only a constant electric field is applied to the sample, I wanted to simply print the output of the electric field at the end of my computation.

I still don’t understand what you are asking and what you are trying to do. The algorithm applied by fix efield is described in the manual. If you don’t trust that, you need to look at the source code.

How about answering my questions?

There are any number of ways to verify what fix efield does:

  • upon inspecting the source code, the time step variable ntimestep only appears once in the code (to keep equal-style variables updated, briefly), and does not appear in any of the expressions involved in calculating force;
  • indeed, it takes very little work for you to add code lines to print out any internal variable you want at any time you like (in your own private copy)
  • you can check that reset_timestep, which will let you set the time step to an arbitrary number, will not change the thermodynamic output
  • you can use run 0 to force LAMMPS to evaluate forces on every particle and dump custom to output those forces, and then compare forces from simulations with and without fix efield

Then again, if the LAMMPS code is creative enough to take an input like fix 2 all efield 0.025 0 0 and impose a mysterious time-varying electric field, with additional parameters plucked from who knows where and without notifying the user that their system Hamiltonian is now time-dependent, who knows if anything else is valid in the LAMMPS code? :slight_smile:

2 Likes

I have scripted
fix 1 all nvt temp 300 300 100
fix 2 all efield 0.025 0 0

thermo 100
thermo_style custom step f_2 f_2[*]

The values that are printed are as follows:
0 -0.69496862 -2.2759572e-15 0 0
100 -0.50100832 -1.9984014e-15 0 0
200 -0.040856732 -2.553513e-15 0 0
300 -0.09097206 -2.3037128e-15 0 0
400 -0.32046718 -1.9428903e-15 0 0
500 -0.37255267 -2.6090241e-15 0 0
600 -0.53845956 -1.831868e-15 0 0
700 -0.57710999 -2.1649349e-15 0 0
800 -0.3112912 -1.9706459e-15 0 0
900 -0.33213791 -1.8873791e-15 0 0
1000 0.0010568116 -2.0539126e-15 0 0

I don’t understand how is the force in order of e-15?

I wanted to see whether the constant field applied in x direction can be seen as a output by thermo_style custom f_2 f_2[*], which is very naive of me.

Thanks srtee! I would implement your suggestions.

Off the top of my head, when a uniform electric field is applied to an overall charge neutral system, it seems reasonable to expect a total electric force of zero (or as close as possible, up to numerical error).

But I must admit it’s been a while since I’ve done one of those simulations.

Okay I got it now. Thank you!