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:
version()
: return the numerical version id, e.g. LAMMPS 2 Sep 2015 -> 20150902get_thermo()
: return current value of a thermo keywordget_natoms()
: total # of atoms as intreset_box()
: reset the simulation box sizeextract_setting()
: return a global settingextract_global()
: extract a global quantityextract_box()
: extract box infocreate_atoms()
: create N atoms with IDs, types, x, v, and image flags
In addition to the functions provided by lammps
, PyLammps
objects
have several properties which allow you to query the system state:
- L.system
Is a dictionary describing the system such as the bounding box or number of atoms
- L.system.xlo, L.system.xhi
bounding box limits along x-axis
- L.system.ylo, L.system.yhi
bounding box limits along y-axis
- L.system.zlo, L.system.zhi
bounding box limits along z-axis
- L.communication
configuration of communication subsystem, such as the number of threads or processors
- L.communication.nthreads
number of threads used by each LAMMPS process
- L.communication.nprocs
number of MPI processes used by LAMMPS
- L.fixes
List of fixes in the current system
- L.computes
List of active computes in the current system
- L.dump
List of active dumps in the current system
- L.groups
List of groups present in the current system
Retrieving the value of an arbitrary LAMMPS expressions
LAMMPS expressions can be immediately evaluated by using the eval
method. The
passed string parameter can be any expression containing global thermo command values,
variables, compute or fix data (see Output from LAMMPS (thermo, dumps, computes, fixes, variables)):
result = L.eval("ke") # kinetic energy
result = L.eval("pe") # potential energy
result = L.eval("v_t/2.0")
Example
from lammps import PyLammps
L = PyLammps()
L.file("in.sysinit")
print(f"running simulation with {L.system.natoms} atoms")
L.run(1000, "post no");
for i in range(10):
L.run(100, "pre no post no")
pe = L.eval("pe")
ke = L.eval("ke")
print(f"PE = {pe}\nKE = {ke}")