Getting all coordinates in a box

Dear LAMMPS users,

I'm using LAMMPS from C.

What I try to do is: Given a bounding box in 3D,
e.g. (0, 0, 0) and (1, 1, 1) coordinates as min and max,
then I need to find all atoms within this bounding box.

I know I can set-up a LAMMPS variable like this
lammps_command(lmp,"variable XCoords atom x");
which will give me all the atoms with the coord x.
I could then filter these for being inside my box.

I just wonder if I could encode the box condition
directly in a LAMMPS variable command potentially.

Best regards,

You can definitely define a region and then group all atoms in that region in a dynamic group. This works as long as the region should not change. I am not sure how exactly that would help with the post processing tough. Alternatively you could define a per-atom boolean variable that you can read out

Thanks Stefan.

one more question I need to ask: Can one define regions
by a polyeder instead of cuboids?


All regions supported by the latest version of LAMMPS can be found here:

If the region you want is not listed there you will have to add it somehow. In that case, if it is relatively easy for you to express whether or not an atom is inside or outside of the region in a per-atom variable, that might be easier.

Ah okay, thanks.

Yes I hoped it would have overseen something in the documentation. :slight_smile:

I'm wondering if it would be useful or feasible to add this directly to
LAMMPS C API, e.g. checking if a atom is within a polyhedron. Opinions?


Not directly, but you can try the intersection of multiple region plane definitions.