The ID order of returned values on extract_compute() in Python-lammps interface [lammps()]

Hi, all!
I’m trying to compute the potential energies per atom (pe/atom):
→ lmp.command(‘compute ppa all pe/atom’)
Though I did get a returned vector via → lmp.extract_compute(‘ppa’, 1, 1), I’m wondering the order of the returned atomic energies.
I know that gather_atoms() will return value vectors with sorted atom IDs, while extract_atom() will return vectors with random atom IDs (depending on the processor arrangement). Will extract_compute() follow the order of gather_atom() or extract_atom()?
Is there a way I can verify this, since extract_compute() and extract_atom() are 2 different functions? (Such as computing a property which can be extracted from both extract_compute() and extract_atom())
Also, if I would like to compute an atomic property and get the return values in the order of atom IDs, is there a way I can do this? It seems that neither → gather_atoms(‘ppa’, 1, 1) nor → extract_atom(‘ppa’) works in my case.

Thanks for your help and have a nice day!

Best regards,

The best source of information for details about data structure and arguments of those various functions is the documentation of the C library interface to LAMMPS and/or the comments in the src/library.cpp file in the LAMMPS distribution.

In general, any kind of “extract” type function will provide the data in the same form and order as it is available on the individual MPI ranks (keep in mind that LAMMPS is designed as a parallel program with domain decomposition). Those will present thus any per-atom data in the same order as the local per-atom arrays. The corresponding atom IDs can be obtained by extracting the “id” atom property.

Any kind of “gather” type function on the other hand will collect the data into atom-ID order and broadcast it to all MPI ranks.

Neither of these are correct. While “ppa” is an ID of a per-atom compute it is not a per-atom attribute that is associated with the atom itself. Per-atom properties are listed here: 4.9.2. LAMMPS Atom and AtomVec Base Classes — LAMMPS documentation

If you want the equivalent of gather_atoms() for computes or fixes instead of the extract_fix() or extract_compute() methods, you need to use the generic gather() method.
Unfortunately, the scatter/gather functionality in the LAMMPS library interface and the Python module has not been fully revised (like the rest of the module code) and documented. So you need to read the corresponding source code to obtain necessary information.

1 Like

Thank you very much!
I do find that there’s a general “gather()” function in LAMMPS but it seems there’s no description from LAMMPS Python doc. And as expected, hard-code “gather(‘ppa’, 1, 1)” is not working, so I guess I would stick to extract_compute() and match the IDs from extract_atom(‘id’) currently.

Thank you again and have a day!

Best regards,

lmp.gather(“c_ppa”, 1, 1) should work.

1 Like