2.3.7. Per-atom properties

Similar to what is described in Per-atom properties, the instances of lammps, PyLammps, or IPyLammps can be used to extract atom quantities and modify some of them. The main difference between the interfaces is how the information is exposed.

While the lammps is just a thin layer that wraps C API calls, PyLammps and IPyLammps expose information as objects and properties.

In some cases the data returned is a direct reference to the original data inside LAMMPS cast to ctypes pointers. Where possible, the wrappers will determine the ctypes data type and cast pointers accordingly. If numpy is installed arrays can also be extracted as numpy arrays, which will access the C arrays directly and have the correct dimensions to protect against invalid accesses.


When accessing per-atom data, please note that this data is the per-processor local data and indexed accordingly. These arrays can change sizes and order at every neighbor list rebuild and atom sort event as atoms are migrating between subdomains.

from lammps import lammps

lmp = lammps()

nlocal = lmp.extract_global("nlocal")
x = lmp.extract_atom("x")

for i in range(nlocal):
   print("(x,y,z) = (", x[i][0], x[i][1], x[i][2], ")")



Numpy Methods: