How to read the definition of groups from a file

I would like to do several simulations which have similar settings but different group setting, and I don’t want to define those many groups of atoms in each in.file. Does anyone know how to read the setting of “group” from a file?

Hi @ILEILEILE,

there are many ways to define group in LAMMPS so without more details on how you define your groups in the first place, it is hard to help.

However, if you can automate the writing of a group command, say by getting the index of the involved atoms (like 1 2 3 and 4) and using group fubar index 1 2 3 4, for each simulation, it should be straight forward to include it into a file containing the specific LAMMPS group command for each of your systems and read it in a generic script using the include command. If you give the same name to all the group command files, you can use the same generic file for the other simulation parameters.

There are the group2ndx and ndx2group commands which are atom ID based.

If you use more complex rules you can just write them into a file and use the include command.

You can also define groups from atomfiles:

variable run_number index 1
# change by calling lmp -i my_input.lmp -var run_number 2
variable in_my_group atomfile group_numbers_${run_number}.txt
# 1 for atoms in group (default is 0 so can leave those unspecified)
group my_group variable in_my_group
1 Like