How can I count neighboring atoms from a specific group in LAMMPS?

I’m working on a simulation where I deposit a nanoparticle onto a larger one. The larger nanoparticle follows Langevin dynamics. I want the deposited nanoparticle to follow Langevin dynamics only after it reaches the surface of the other nanoparticle. If it starts following Langevin dynamics immediately upon deposition, it won’t reach the surface.

For the case of depositing a single atom, the problem can be solved by counting the number of neighbors of the deposited atom. Once the atom has more than 1 neighbor it can be considered deposited. However, this approach doesn’t work when depositing an entire nanoparticle.

I was wondering if there’s a way to compute the number of neighbors that belong to a specific group—for example, to count how many neighboring atoms from the substrate are close to each atom in the deposited nanoparticle.

You can do it by invoking compute coord/atom (there is an example of its use here https://arxiv.org/pdf/2503.14020, page 10), see compute coord/atom command — LAMMPS documentation

While I’m here, I am pointing out that your method of adjusting the thermostat after a certain event is rather unusual and may raise some suspicion in the future.

Thank you for your prompt response. It’s true is unusual, but I need to deposit multiple nanoparticles in the same spot. I did not come up with other Ideas to do it if not move the deposition region after every deposition happen and I wanted to avoid this. If you have other ideas I’m open.
Thank you for your feedback.

If you need to prevent something from moving, you can also add an additional harmonic potential once the particle deposits. While this is still hacking the simulation, as you are introducing an extra force to alter the behavior, I believe it would be easier to defend.

Simon