2.3.6. System propertiesΒΆ

Similar to what is described in System properties, the instances of lammps, PyLammps, or IPyLammps can be used to extract different kinds of information about the active LAMMPS instance and also to modify some of it. 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.

Warning

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 sub-domains.

from lammps import lammps

lmp = lammps()
lmp.file("in.sysinit")

natoms = lmp.get_natoms()
print(f"running simulation with {natoms} atoms")

lmp.command("run 1000 post no");

for i in range(10):
   lmp.command("run 100 pre no post no")
   pe = lmp.get_thermo("pe")
   ke = lmp.get_thermo("ke")
   print(f"PE = {pe}\nKE = {ke}")

lmp.close()

Methods: