Obtain ID atoms belong to a Group

Dear all

I have a group called “type111” which has 10 atoms of type 1. I would like to print each of the ids of these 10 atoms, for which I use the command “compute 5 type111 property/atom id”, a loop of a variable “y” ranging from 1 to 10 and a variable “z”. To print what would be the ids of the atoms that belong to type111, I assign the variable “z” each one of what I would expect to be the elements of the vector created in the compute through the command c_5[$y] inside the loop. I know from a file that I printed previously that the ids of this group are 1, 2, 4, 5, 6, 7, 8, 10, 11, 12. However, when I run the simulation I get as a result 1, 2, 0, 4, 5, 6, 7, 8, 0, 10. So, it gives me to understand that what the program does is to take each value “y” and compare it with the list of id of the c_5, and if it finds it prints it with its value, and if not, prints it as 0; that is why 3 and 9 are printed as 0. I also support this under the fact that I changed the ids of the atoms to numbers between 20 and 30 and all 10 prints were 0. Can you help me find a better approach that will allow me to print the ids of this group (type11) of atoms? These are the lines.

group type111 type 1

compute 5 type111 property/atom id
run 1000

variable y loop 10
label myfirstloop2
variable z equal c_5[$y]

print “${z}”
next y
jump SELF myfirstloop2



A xxx/atom compute will always produce a per-atom array or vector. When restricted by a group the output for non-group atoms will be 0. So you would have to loop over all atoms and only print items that are not 0.

However this kind of output is very inefficient and limits parallel scaling. A simpler and more efficient way to get the same information would be to use a custom style dump for the group.

Dear Kohlmey,

Thank you. I understand what you are saying. My interest is to use the IDs of the atoms that belong to the group to make changes on them, such as changing their type. Is it possible to use the information that is stored in the dump for that specific group to extract the IDs of those atoms that belong to the group and operate on them in the same script?

If you want to change the type of a group of atoms, you can use the set command directly. Why go through the hoops of processing atoms individually? If necessary, the type (or many other supported properties) can be determined with an atom style variable.

Serializing the process by looping is rarely a good idea. The LAMMPS script language is not a full programming language.

Dear Kolhmey,

Suppose I have a solid surface and a gas atoms around it. Both are of the same element but in one phase they have a different chemical nature which is reflected in a their parameters. I would like that when the gas atoms approach the surface, they are trapped to the surface, and thus changed their parameters to those of the solid. I do this by the criterion of their distance with respect to a distance from the surface. That is why I make a loop going through the IDs of the gas atoms.

But thinking a bit about your recommendations, the computational costs, so on. I think it will be better to define a region on the surface that defines me a dynamic group of atoms of the gas and then change their parameters through the “set” command. So in each multipole of the run that I define, it evaluate which atoms of the gas phase are in the region on the surface and change theirs parameter to solid phase. This way the loop will be over time and not atom by atom. Am I right?



Unless you are simulating an unusually dense gas, the potential for the gas is mostly irrelevant for a gas-solid system. The number of gas atoms will be extremely small at the length scales available to MD simulations, so you can just use the potential for the solid for all atoms.

You need a very good argument for doing something different and you have to prove and not just guess that it makes a significant difference. The method you propose is rather approximate, too. If you suddenly switch potentials on atoms, you usually insert a substantial amount of (unphysical!) potential energy into the system.

Have you talked your plans over with someone that has some experience?

Dear Kohlmey,

I am currently working with the charging and discharging of nanobatteries. Actually, it is just a test for a more complex system composed of cathode, anode, electrolyte and an external electric field. I understand what you told me about potential energy. I am planning to parameterize to reduce these problems.

Thank you very much for your replies.

Best regards,