Add charges to a list of atoms

Dear Lammps communities:
In lammps MD simulation I want to add charge (+0.16) to a list of atoms whose atom ID is within [4000, 10000]. I think of a way:

  1. output all the atom charges to file charge1.txt, then manually add 0.16 to the required range of atoms’ change.
  2. read a restart file by: read_restart
  3. Then set the new charge:
    variable newCharge atomfile charge1.txt
    and then set atom * charge v_newCharge

additional: the charge1.txt example file is:
1 -0.5
2 -0.5
3 -0.5

9998 1.5
9999 1.5
10000 1.5

Is the charge1.txt format correct and this method correct?

Thank you for your help and checking this post.

Zhongquan Chen

How about simply doing this?

variable newCharge atom q+0.16
set atom 4000*10000 charge v_newCharge

No file writing, restarting, and file reading required.

Hello Axel,
Thank you for this idea. One thing is that, the charges of the atoms in [4000, 10000] are different. Can I make the “q” in the command a vector like variable?

Please study the variable command documentation. You should find the answer in there.

I saw some information in " Atom Values and Vectors" section. Thank you! I will compare which method is more simple.