How to compute the force on a specific group of atoms

Dear LAMMPS Users,

I want to calculate the force of a group of atoms. For example, I define all the atoms that have a z-coordinate greater than 2 nm as a group. Can LAMMPS compute the force on such group? Thank you!

Sincerely,
Steven

2 Likes

Try: compute reduce command — LAMMPS documentation

2 Likes

Thank you for your suggestion! Sorry I just replied. Yes, I checked the documentation, and it looks this command is what I should use here. But I met another problem: How can I define a group based on the coordinates of the atoms? So far I only know how to define the atoms inside a region to be one group.

Thank you,
Steven

1 Like

Please explain the difference between “atoms in a region” and “based on coordinates of atoms”

Sorry I didn’t make it clear. What I want to achieve is to recognize all the atoms that have a coordinate larger than, let’s say, 1 nm in z direction to be a group.

Steven

You could use region plane for that case. region command — LAMMPS documentation

For more complex geometries or conditions, you can also define a group based on an atom style variable. group command — LAMMPS documentation. The selection would be then done on the basis of whether the variable evaluates to zero or non-zero.

2 Likes

Thank you for your help! I think it would work to my problem. I will try it in my code. Thank you so much! Really appreciate it!

Steven

Sorry to bother you again, sir. I’ve been trying these commands, but it seems I still cannot get what I want. In my simulation, some atoms would be changing their positions in z direction with time, which means the number of atoms I want to recognize is dynamic during the whole simulation. So, may I ask if there is any ways to read the atoms that have a z-coordinate higher than a specific value dynamically?

Thank you,
Steven

Please read the documentation of the group command more carefully. It is all there.

2 Likes

I just kept reading the region command. I didn’t realize group command gives this function. Thank you very much sir!

Sincerely,
Steven

Please note that there also is a compute reduce/region command that may achieve the same objective than using compute reduce on a dynamic group based on a region.

1 Like

Got it. I will check it. Thanks for your reminding!

Steven

Dear Dr. Axel,

Could you please help me check if the commands I wrote is right or not for dynamic group? I want to define all the atoms with type 3 and z-coordinate greater than 56.025 as one group with the name of “chips”, and below is what I wrote in LAMMPS:

variable chip atom type==3
variable threshold atom z>56.025
group chips dynamic all var chip var threshold every 1

Then, I want to calculate the total external force acted on this “chips” group, here is what I did:

compute 5 chips reduce sum fx fy fz

Since the external force in x direction is what I need, I think I should be focusing on c_5[1] right? I I’m not sure about this command also, but from the result, the total force calculated is not correct.
Any ideas on where the might be wrong?

Thank you,
Steven

Sorry, I cannot debug code buy just staring at a few lines.
You have to learn to debug this yourself (e.g. by creating a very simple system with just a few atoms bouncing around and comparing the results that you find from the “count” function of a (dynamic) group to see if the number that LAMMPS computes is what you can count yourself from the trajectory.

But in this case I would just use compute reduce/region, as that is also a lower overhead effort.

1 Like

Sorry about the late reply. Thank you for your suggestion! Yes, I will do that! And sorry that I just keep asking questions. This simulation stuffs are really difficult to me.

Thank you,
Steven

No. I don’t have time or interest to be your adviser. This is not about LAMMPS but about how to do research and use a software and its documentation as a tool.

…and yes, this can be make much simpler and to test and debug whether you use a feature you can (and should) construct specific input decks that focus on just the one feature you want to test and understand. This is how you teach yourself something from the documentation (at least that is how I was trained and how I do it until now).

1 Like

OK. I see. Thank you a lot! I will continue working on it.

Sincerely,
Steven