Ndx2group does not create a group

Dear Lammps Users,

I am trying to compress a fluid between surfaces and then I’d like to apply a shear. I process as follows:

  1. I create two input files, one for compression and one for shearing.

  2. I define a group of atoms with the group command in the first input and wrote their index in a file using group2ndx.

  3. In the second input file I would like to read the previously generated file.ndx using the ndx2group command.

My understanding is that this will allow me to define the group in the first input (compression stage) but use it also in the second input (shearing stage) without having to define it explicitly again.

The problem is that the ndx2group processes the file but no group is created and the simulations crash

To test the command I decided to run a simpler simulation, I modified the in.flow.couette input file from the examples (examples/flow) to first generate the ndx file and then read it in the next run. It still crashes saying that no group has been found

LAMMPS VERSION: 8 February 2023 with COLVARS package installed.
Attached is the relevant file input file
in.flow.couette (1.5 KB)

I hope that my explanation was clear.

Best regards,


Thanks for the report and the reproducer input.

There are two issues here:

  • Your input does not request using an atom map, but the ndx2group command depends on it.
    Without atom map, it will create an empty group.
    So adding a line like atom_modify map array is required.
    The command should detect this and exit with an error. I’m adding code for that now.
  • There is a subtle bug in how group names are assigned when specifying the group name.
    Basically, if you specify the group name, it will create a group with an empty name because of that bug. This bug will be fixed in the next feature release of LAMMPS.
    So if you use the ndx2group command without arguments and configure an atom map, it should restore the group.

This patch file if applied to your source should fix both issues:
ndx2group-fix.patch (1.3 KB)

Everything worked like a charm. Thank you very much!