How to Find then Pull Information from One Particle

I have a stack of particles on the z axis and my intent is to extract various physical information from the particle that is on top of that stack (furthest from the xy-plane).

My current method is to leverage compute reduce to find the max z position using,

compute maxz region_of_stacked_particles reduce max z

This provides a scalar value of the z-position of the particle with the highest z-position from the region of stacked particles.

Next, I believe the a logical next step would be to use group command put the particle with that z-position into a group that I can then pull information from it (such as end the simulation when it gets displaced past a threshold value).

However, I’m unsure of the best way to put this into effect within the group documentation. Something similar to the example

compute 1 all pe/atom
compute 2 all reduce sum c_1
thermo_style custom step temp pe c_2
run 0

variable eatom atom “c_1 > -3.0”
group hienergy variable eatom

Seem like a good direction, but the variable command won’t take an argument like “z > c_zmax” to pull any particles greater than zmax into the group.

Does anyone in the community know of a way to find an particle and then put it into a group?

Seem like a good direction, but the variable command won’t take an argument like “z > c_zmax” to pull any particles greater than zmax into the group.

You could create a region based on that criteria, see region command — LAMMPS documentation then create a group from that.

1 Like

Well you have two problems:

  1. Identify the atom with the maximum z value
  2. Define a group with just that one atom

The first can be done with the replace keyword of the compute reduce command:

variable id atom id
compute idz  all reduce max v_id z replace 1 2

This will determine the maximum z value and instead of also determining the maximum atom ID it will return the entry for which z is maximal, i.e. its atom ID.

To define a group, you need a dynamic group since the atom ID for the atom with the maximum z may change. For this you now need to define a variable that is non-zero only for the atom that has the atom ID returned by the first element returned by compute idz:

variable zmax equal c_idz[1]
variable idz atom id==v_zmax
group zmax dynamic all var idz

Now the group zmax will always contain the atom with the maximum z.

For more details, please study the documentation for the commands “compute reduce”, “group” and “variable”.

1 Like

Thank you very much for your reply! Please allow me to check my understanding of each step:

variable id atom id

This creates a vector variable that is all of the ID’s of atoms in the simulation. This is needed because the next step needs a variable vector with this information in it.

compute idz  all reduce max v_id z replace 1 2

This computes the maximum z-position for particles in the all group and replaces each value in the vector variable id with the ID of the particle with that that maximum value. The result is a compute vector.

variable zmax equal c_idz[1]

This creates a scalar variable equal to the ID number of the particle with the maximum z-position. Really could have been any value of the vector, since all values of the c_idz vector should be the same.

variable idz atom id==v_zmax

Create a vector (per-atom) variable version of the scalar version of variable zmax. This is needed because the next command needs a per-atom variable.

group zmax dynamic all var idz

Assign all particles with the ID of idz (that of the largest z-position) to a dynamic group.

If we instead wanted to sign to a non-dynamic group, the following command should work:

group top_probe id ${zmax}

Is my understanding correct?

I am not your tutor and this is a forum and not a classroom. All the information you need is in my previous post and the documentation I pointed out to you. If you need confirmation about details, you need to construct simple test cases (following the documentation) and experiment with them. This is how you teach yourself some skills and this is how things work here.

Just one comment about some very obvious mistake, you are confusing atom style and vector style. An atom style variable is a per-atom scalar. Only computes and fixes can have per-atom vectors. An equal style variable is a global scalar and a vector style variable a global vector. When posting in a forum (and when writing publications) it is crucial to use accurate and precise descriptions, so you better make an effort.

How about:

compute zmax all reduce max z
compute peatom all pe/atom
variable pe_maxz_peratom atom (z==c_zmax)*c_peatom
compute pe_maxz all reduce sum pe_maxz_peratom

(I use group all because I don’t remember the region selection syntax – adjust accordingly.)

Also see the replace keyword of compute reduce.

1 Like

Perfect explanation! Thank you.