Accessing number of bonds in python operated LAMMPS or length of internal LAMMPS data array

Dear LAMMPS user,

I am using the python interface to operate LAMMPS v 15Feb16 and I am having trouble accessing the topological information of the system. I use ‘bond/local dist’ compute to calculate the bond data and then extract_compute() to extract the data into python. I get a pointer to the array with bond distances and I want to access that data by iterating over all of the bonds. Unfortunately the extract_compute() gives me a LP_c_double pointer and I don’t know how to find out the length of the original array (the internal LAMMPS data array that the pointer points to i.e. number of bonds). Is there a way to access the number of entries in the internal LAMMPS data array or a way to extract number of bonds/angles/dihedrals in the system from the python interface. I am using ‘fix bond/break’ throughout my simulation so I cannot just use the initial topology as the information changes dynamically.

Thank you for any help
Best regards
Jacek Golebiowski

Dear LAMMPS user,

I am using the python interface to operate LAMMPS v 15Feb16 and I am having trouble accessing the topological information of the system. I use ‘bond/local dist’ compute to calculate the bond data and then extract_compute() to extract the data into python. I get a pointer to the array with bond distances and I want to access that data by iterating over all of the bonds. Unfortunately the extract_compute() gives me a LP_c_double pointer and I don’t know how to find out the length of the original array (the internal LAMMPS data array that the pointer points to i.e. number of bonds). Is there a way to access the number of entries in the internal LAMMPS data array or a way to extract number of bonds/angles/dihedrals in the system from the python interface. I am using ‘fix bond/break’ throughout my simulation so I cannot just use the initial topology as the information changes dynamically.

an API to access the size of a local compute would have to be added to
the library interface and then also added to the python wrapper. the
size and order of entries of local computes varies.

axel.

Dear Axel,

In that case, do you know if there is a way to access the number of bonds/angles/dihedrals in the simulaiton through the python interface?

Best regards
Jacek

Dear Axel,

In that case, do you know if there is a way to access the number of bonds/angles/dihedrals in the simulaiton through the python interface?

no. an API for that would need to be added to the library interface
and then to the python wrapper as well.

axel.

“Adding an API” sounds complicated, but it’s not.

To get the # of bonds, angles, etc, you simply

need to add one line to the lammps_extract_global

method in src/library.cpp. And extract

lmp->atom->nbonds, for example.

No one has asked for it before, so it isn’t yet there.

Python would then have access to it as well.

It would also be simple to add a new function in library.cpp that

extracts lengths of local vectors/arrays.

Steve

"Adding an API" sounds complicated, but it's not.

To get the # of bonds, angles, etc, you simply
need to add one line to the lammps_extract_global
method in src/library.cpp. And extract
lmp->atom->nbonds, for example.

come to think of it. a lot of this kind of introspection should be in
richard berger's extended python interface.
while the original intent was to simplify unit testing for individual
LAMMPS commands, it might be useful in that case, too.
the extension for the size of local data would still be needed, though, IIRC.

axel.

Yes that sounds like a good idea. I can add it.

Richard

That would be great.

Thank you all for your help,
Jacek