Change charge of atom during runtime, based on atoms in vicinty

Dear LAMMPS users and developer team,

I am working on Dec 2018 version of LAMMPS. I am doing NVT MD
simulation of ionic solid supercell. There are three main ions in the
system, Li+, Fe2+ and Fe3+. During MD, Li+ is mobile. I want to change
the atom type of Fe during MD run based on Li position. If Li and Fe
are within ionic bond distance, I want to change Fe3+ to Fe2+ and vice
versa otherwise. Can I achieve this condition based changes of ion
type during LAMMPS run? Please let me know the possible ways to
achieve this.

Thank you,
Saurabh

First, take a look at fix bond/react
https://lammps.sandia.gov/doc/fix_bond_react.html

This feature is more powerful than you need (and more complicated than
want), but it might do what you need. (Please read my warning below.)

Otherwise you will have to write custom LAMMPS code that implements
this feature. There is a (very general) guide to writing custom code
form LAMMPS located here:
https://lammps.sandia.gov/doc/Developer.pdf

However the best way to implement your own feature (ie your own "fix")
is to look a a similar fix and modify it to do what you want. Take a
look at "fix atom/swap":

https://lammps.sandia.gov/doc/fix_atom_swap.html

Then download the LAMMPS source code.
https://lammps.sandia.gov/download.html

Go to the "src" subdirectory. Copy the "fix_atom_swap.h" and
"fix_atom_swap.cpp" files and rename them. (And rename the class from
FixAtomSwap, and all references to "atom/swap" inside these files.)
Then change the code you need accordingly, and recompile LAMMPS.

I hope this helps get you started.

WARNING: If you are using periodic boundary conditions and long-range
electrostatics ("kspace pppm"), then you will need to insure that the
system remains neutral at all times. Either you will have to change
the charge of two different atoms simultaneously, or you will have to
stop using long-range electrostatics, ...OR you will have to stop
using periodic boundary conditions. (In LAMMPS all of these options
are possible. I think kspace style "msm" works with non-periodic
boundary conditions. See:
https://lammps.sandia.gov/doc/kspace_style.html)

Cheers

Andrew
P.S. Keep in mind that in LAMMPS it is not possible for an atom to
have any effect another atom which is far away (unless they are
connected with a bond), even if you are willing to modify the LAMMPS
code.

please note, that the model you are describing as some fundamental problems in MD: you will cause a discontinuity in the (potential) energy while changing the charge, and it is not likely that you will see much movement for system sizes and time scales accessible to MD. overall this sounds more like a monte carlos simulation project.

axel.