Keep the number of molecules a constant in a region by fix deposit

Dear lammps users

I have a group of mulecules in a specific region. The number decreases with the simulation time and the rate of decrease is not a constant. I would like to keep the molecules constant using fix deposit. This is what I did

compute cout_oxy_bottom group_reservoir_bottom count/type atom
variable inserted_water equal (${num_oxy_left}-c_cout_oxy_bottom[1])
molecule mol_water TIP3P.txt
fix add_water solution deposit v_inserted_water 0 1000 12235 region Region_piston_bottom global v_dis near 2 mol mol_water shake fShakeWATER

However, the variable is not evaluated every timestep, hence the v_inserted_water is not an integer. Could anyone suggest how keep the number of molecule constant using fix deposit? If it is not doable by fix deposit. Any commands in lammps can do this?

Thank you.

You cannot just add a v_somename argument to a command and expect it to work. Support for using variable references as input has to be programmed into the C++ source code for a command. Thus, you can only use it when the documentation says it is allowed. Otherwise you can only use ${somename} expansion, which is useless in this case because the expansion is done by the input preprocessor when the command is executed and cannot be updated.

Fix deposit has no feature for that, you would have to implement it into the C++ code. There is also a conceptual issue here. What if the number of atoms is too large?? That may not happen in your case, but it is implied in “keep constant” that fix deposit would also include functionality from fix evaporate.

The closest I can think of would be fix gcmc, but that can be a nightmare to get set up right.

How about an alternate approach? Why not just break down your simulation into a loop with many short runs. After each run, you can check if and how many atoms are missing, then you can issue a suitable fix deposit command using ${somename} expansion for the next round (or not).

Thanks for your useful reply.

I am following the suggestions to break the simulation into loop with many short runs. The idea come to my mind is to use bash script with -var options in lammps command line. Getting the final number of molecules after each run, then calculating the number in bash script and passing the variable to lammps command line. However, this idea requires to define a variable in input and use it in fix deposit command, which is not suppoted yet. Could you please give a little bit more explaination or example about the alternative approach?
In additon, is it possible to output the trajectory files and other output of fix to same file if running many short runs by loops?

I was talking about using a loop within the LAMMPS input. Some examples are here: jump command — LAMMPS documentation

Please re-read my previous post with more care.