\(\renewcommand{\AA}{\text{Å}}\)

# compute command

## Syntax

```
compute ID group-ID style args
```

ID = user-assigned name for the computation

group-ID = ID of the group of atoms to perform the computation on

style = one of a list of possible style names (see below)

args = arguments used by a particular style

## Examples

```
compute 1 all temp
compute newtemp flow temp/partial 1 1 0
compute 3 all ke/atom
```

## Description

Define a diagnostic computation that will be performed on a group of atoms. Quantities calculated by a compute are instantaneous values, meaning they are calculated from information about atoms on the current timestep or iteration, though internally a compute may store some information about a previous state of the system. Defining a compute does not perform the computation. Instead computes are invoked by other LAMMPS commands as needed (e.g., to calculate a temperature needed for a thermostat fix or to generate thermodynamic or dump file output). See the Howto output page for a summary of various LAMMPS output options, many of which involve computes.

The ID of a compute can only contain alphanumeric characters and underscores.

Computes calculate and store any of four *styles* of quantities:
global, per-atom, local, or per-grid.

A global quantity is one or more system-wide values, e.g. the temperature of the system. A per-atom quantity is one or more values per atom, e.g. the kinetic energy of each atom. Per-atom values are set to 0.0 for atoms not in the specified compute group. Local quantities are calculated by each processor based on the atoms it owns, but there may be zero or more per atom, e.g. a list of bond distances. Per-grid quantities are calculated on a regular 2d or 3d grid which overlays a 2d or 3d simulation domain. The grid points and the data they store are distributed across processors; each processor owns the grid points which fall within its subdomain.

As a general rule of thumb, computes that produce per-atom quantities
have the word “atom” at the end of their style, e.g. *ke/atom*.
Computes that produce local quantities have the word “local” at the
end of their style, e.g. *bond/local*. Computes that produce
per-grid quantities have the word “grid” at the end of their style,
e.g. *property/grid*. And styles with neither “atom” or “local” or
“grid” at the end of their style name produce global quantities.

Global, per-atom, local, and per-grid quantities can also be of three
*kinds*: a single scalar value (global only), a vector of values, or a
2d array of values. For per-atom, local, and per-grid quantities, a
“vector” means a single value for each atom, each local entity
(e.g. bond), or grid cell. Likewise an “array”, means multiple values
for each atom, each local entity, or each grid cell.

Note that a single compute can produce any combination of global, per-atom, local, or per-grid values. Likewise it can produce any combination of scalar, vector, or array output for each style. The exception is that for per-atom, local, and per-grid output, either a vector or array can be produced, but not both. The doc page for each compute explains the values it produces.

When a compute output is accessed by another input script command it is referenced via the following bracket notation, where ID is the ID of the compute:

c_ID |
entire scalar, vector, or array |

c_ID[I] |
one element of vector, one column of array |

c_ID[I][J] |
one element of array |

In other words, using one bracket reduces the dimension of the quantity once (vector \(\to\) scalar, array \(\to\) vector). Using two brackets reduces the dimension twice (array \(\to\) scalar). Thus, for example, a command that uses global scalar compute values as input can also process elements of a vector or array. Depending on the command, this can either be done directly using the syntax in the table, or by first defining a variable of the appropriate style to store the quantity, then using the variable as an input to the command.

Note that commands and variables which take compute outputs as input typically do not allow for all styles and kinds of data (e.g., a command may require global but not per-atom values, or it may require a vector of values, not a scalar). This means there is typically no ambiguity about referring to a compute output as c_ID even if it produces, for example, both a scalar and vector. The doc pages for various commands explain the details, including how any ambiguities are resolved.

In LAMMPS, the values generated by a compute can be used in several ways:

The results of computes that calculate a global temperature or pressure can be used by fixes that do thermostatting or barostatting or when atom velocities are created.

Global values can be output via the thermo_style custom or fix ave/time command. Or the values can be referenced in a variable equal or variable atom command.

Per-atom values can be output via the dump custom command. Or they can be time-averaged via the fix ave/atom command or reduced by the compute reduce command. Or the per-atom values can be referenced in an atom-style variable.

Local values can be reduced by the compute reduce command, or histogrammed by the fix ave/histo command, or output by the dump local command.

The results of computes that calculate global quantities can be either “intensive” or “extensive” values. Intensive means the value is independent of the number of atoms in the simulation (e.g., temperature). Extensive means the value scales with the number of atoms in the simulation (e.g., total rotational kinetic energy). Thermodynamic output will normalize extensive values by the number of atoms in the system, depending on the “thermo_modify norm” setting. It will not normalize intensive values. If a compute value is accessed in another way (e.g., by a variable), you may want to know whether it is an intensive or extensive value. See the page for individual computes for further info.

LAMMPS creates its own computes internally for thermodynamic output. Three computes are always created, named “thermo_temp”, “thermo_press”, and “thermo_pe”, as if these commands had been invoked in the input script:

```
compute thermo_temp all temp
compute thermo_press all pressure thermo_temp
compute thermo_pe all pe
```

Additional computes for other quantities are created if the thermo style requires it. See the documentation for the thermo_style command.

Fixes that calculate temperature or pressure, i.e. for thermostatting or barostatting, may also create computes. These are discussed in the documentation for specific fix commands.

In all these cases, the default computes LAMMPS creates can be replaced by computes defined by the user in the input script, as described by the thermo_modify and fix modify commands.

Properties of either a default or user-defined compute can be modified via the compute_modify command.

Computes can be deleted with the uncompute command.

Code for new computes can be added to LAMMPS; see the Modify page for details. The results of their calculations accessed in the various ways described above.

Each compute style has its own page which describes its arguments and what it does. Here is an alphabetic list of compute styles available in LAMMPS. They are also listed in more compact form on the Commands compute doc page.

There are also additional accelerated compute styles included in the LAMMPS distribution for faster performance on CPUs, GPUs, and KNLs. The individual style names on the Commands compute page are followed by one or more of (g,i,k,o,t) to indicate which accelerated styles exist.

ackland/atom - determines the local lattice structure based on the Ackland formulation

adf - angular distribution function of triples of atoms

aggregate/atom - aggregate ID for each atom

angle - energy of each angle sub-style

angle/local - theta and energy of each angle

angmom/chunk - angular momentum for each chunk

ave/sphere/atom - compute local density and temperature around each atom

basal/atom - calculates the hexagonal close-packed “c” lattice vector of each atom

body/local - attributes of body sub-particles

bond - energy of each bond sub-style

bond/local - distance and energy of each bond

born/matrix - second derivative or potential with respect to strain

centro/atom - centro-symmetry parameter for each atom

centroid/stress/atom - centroid based stress tensor for each atom

chunk/atom - assign chunk IDs to each atom

chunk/spread/atom - spreads chunk values to each atom in chunk

cluster/atom - cluster ID for each atom

cna/atom - common neighbor analysis (CNA) for each atom

cnp/atom - common neighborhood parameter (CNP) for each atom

com - center of mass of group of atoms

com/chunk - center of mass for each chunk

contact/atom - contact count for each spherical particle

coord/atom - coordination number for each atom

count/type - count of atoms or bonds by type

damage/atom - Peridynamic damage for each atom

dihedral - energy of each dihedral sub-style

dihedral/local - angle of each dihedral

dilatation/atom - Peridynamic dilatation for each atom

dipole - dipole vector and total dipole

dipole/chunk - dipole vector and total dipole for each chunk

dipole/tip4p - dipole vector and total dipole with TIP4P pair style

dipole/tip4p/chunk - dipole vector and total dipole for each chunk with TIP4P pair style

displace/atom - displacement of each atom

dpd - total values of internal conductive energy, internal mechanical energy, chemical energy, and harmonic average of internal temperature

dpd/atom - per-particle values of internal conductive energy, internal mechanical energy, chemical energy, and internal temperature

edpd/temp/atom - per-atom temperature for each eDPD particle in a group

efield/atom - electric field at each atom

efield/wolf/atom - electric field at each atom

entropy/atom - pair entropy fingerprint of each atom

erotate/asphere - rotational energy of aspherical particles

erotate/rigid - rotational energy of rigid bodies

erotate/sphere - rotational energy of spherical particles

erotate/sphere/atom - rotational energy for each spherical particle

event/displace - detect event on atom displacement

fabric - calculates fabric tensors from pair interactions

fep - compute free energies for alchemical transformation from perturbation theory

fep/ta - compute free energies for a test area perturbation

force/tally - force between two groups of atoms via the tally callback mechanism

fragment/atom - fragment ID for each atom

global/atom - assign global values to each atom from arrays of global values

group/group - energy/force between two groups of atoms

gyration - radius of gyration of group of atoms

gyration/chunk - radius of gyration for each chunk

gyration/shape - shape parameters from gyration tensor

gyration/shape/chunk - shape parameters from gyration tensor for each chunk

heat/flux - heat flux through a group of atoms

heat/flux/tally - heat flux through a group of atoms via the tally callback mechanism

heat/flux/virial/tally - virial heat flux between two groups via the tally callback mechanism

hexorder/atom - bond orientational order parameter q6

hma - harmonically mapped averaging for atomic crystals

improper - energy of each improper sub-style

improper/local - angle of each improper

inertia/chunk - inertia tensor for each chunk

ke - translational kinetic energy

ke/atom - kinetic energy for each atom

ke/atom/eff - per-atom translational and radial kinetic energy in the electron force field model

ke/eff - kinetic energy of a group of nuclei and electrons in the electron force field model

ke/rigid - translational kinetic energy of rigid bodies

composition/atom - local composition for each atom

mliap - gradients of energy and forces with respect to model parameters and related quantities for training machine learning interatomic potentials

momentum - translational momentum

msd - mean-squared displacement of group of atoms

msd/chunk - mean-squared displacement for each chunk

msd/nongauss - MSD and non-Gaussian parameter of group of atoms

nbond/atom - calculates number of bonds per atom

omega/chunk - angular velocity for each chunk

orientorder/atom - Steinhardt bond orientational order parameters Ql

pace - atomic cluster expansion descriptors and related quantities

pair - values computed by a pair style

pair/local - distance/energy/force of each pairwise interaction

pe - potential energy

pe/atom - potential energy for each atom

pe/mol/tally - potential energy between two groups of atoms separated into intermolecular and intramolecular components via the tally callback mechanism

pe/tally - potential energy between two groups of atoms via the tally callback mechanism

plasticity/atom - Peridynamic plasticity for each atom

pod/atom - POD descriptors for each atom

podd/atom - derivative of POD descriptors for each atom

pod/local - local POD descriptors and their derivatives

pod/global - global POD descriptors and their derivatives

pressure - total pressure and pressure tensor

pressure/alchemy - mixed system total pressure and pressure tensor for fix alchemy runs

pressure/uef - pressure tensor in the reference frame of an applied flow field

property/atom - convert atom attributes to per-atom vectors/arrays

property/chunk - extract various per-chunk attributes

property/grid - convert per-grid attributes to per-grid vectors/arrays

property/local - convert local attributes to local vectors/arrays

ptm/atom - determines the local lattice structure based on the Polyhedral Template Matching method

rattlers/atom - identify under-coordinated rattler atoms

rdf - radial distribution function \(g(r)\) histogram of group of atoms

reaxff/atom - extract ReaxFF bond information

reduce - combine per-atom quantities into a single global value

reduce/chunk - reduce per-atom quantities within each chunk

reduce/region - same as compute reduce, within a region

rheo/property/atom - convert atom attributes in RHEO package to per-atom vectors/arrays

rigid/local - extract rigid body attributes

saed - electron diffraction intensity on a mesh of reciprocal lattice nodes

slcsa/atom - perform Supervised Learning Crystal Structure Analysis (SL-CSA)

slice - extract values from global vector or array

smd/contact/radius - contact radius for Smooth Mach Dynamics

smd/damage - damage status of SPH particles in Smooth Mach Dynamics

smd/hourglass/error - error associated with approximated relative separation in Smooth Mach Dynamics

smd/internal/energy - per-particle enthalpy in Smooth Mach Dynamics

smd/plastic/strain - equivalent plastic strain per particle in Smooth Mach Dynamics

smd/plastic/strain/rate - time rate of the equivalent plastic strain in Smooth Mach Dynamics

smd/rho - per-particle mass density in Smooth Mach Dynamics

smd/tlsph/defgrad - deformation gradient in Smooth Mach Dynamics

smd/tlsph/dt - CFL-stable time increment per particle in Smooth Mach Dynamics

smd/tlsph/num/neighs - number of particles inside the smoothing kernel radius for Smooth Mach Dynamics

smd/tlsph/shape - current shape of the volume of a particle for Smooth Mach Dynamics

smd/tlsph/strain - Green–Lagrange strain tensor for Smooth Mach Dynamics

smd/tlsph/strain/rate - rate of strain for Smooth Mach Dynamics

smd/tlsph/stress - per-particle Cauchy stress tensor for SPH particles

smd/triangle/vertices - coordinates of vertices corresponding to the triangle elements of a mesh for Smooth Mach Dynamics

smd/ulsph/effm - per-particle effective shear modulus

smd/ulsph/num/neighs - number of neighbor particles inside the smoothing kernel radius for Smooth Mach Dynamics

smd/ulsph/strain - logarithmic strain tensor for Smooth Mach Dynamics

smd/ulsph/strain/rate - logarithmic strain rate for Smooth Mach Dynamics

smd/ulsph/stress - per-particle Cauchy stress tensor and von Mises equivalent stress in Smooth Mach Dynamics

smd/vol - per-particle volumes and their sum in Smooth Mach Dynamics

snap - gradients of SNAP energy and forces with respect to linear coefficients and related quantities for fitting SNAP potentials

sna/atom - bispectrum components for each atom

sna/grid - global array of bispectrum components on a regular grid

sna/grid/local - local array of bispectrum components on a regular grid

snad/atom - derivative of bispectrum components for each atom

snav/atom - virial contribution from bispectrum components for each atom

sph/e/atom - per-atom internal energy of Smooth-Particle Hydrodynamics atoms

sph/rho/atom - per-atom density of Smooth-Particle Hydrodynamics atoms

sph/t/atom - per-atom internal temperature of Smooth-Particle Hydrodynamics atoms

spin - magnetic quantities for a system of atoms having spins

stress/atom - stress tensor for each atom

stress/cartesian - stress tensor in cartesian coordinates

stress/cylinder - stress tensor in cylindrical coordinates

stress/mop - normal components of the local stress tensor using the method of planes

stress/mop/profile - profile of the normal components of the local stress tensor using the method of planes

stress/spherical - stress tensor in spherical coordinates

stress/tally - stress between two groups of atoms via the tally callback mechanism

tdpd/cc/atom - per-atom chemical concentration of a specified species for each tDPD particle

temp - temperature of group of atoms

temp/asphere - temperature of aspherical particles

temp/body - temperature of body particles

temp/chunk - temperature of each chunk

temp/com - temperature after subtracting center-of-mass velocity

temp/cs - temperature based on the center-of-mass velocity of atom pairs that are bonded to each other

temp/deform - temperature excluding box deformation velocity

temp/deform/eff - temperature excluding box deformation velocity in the electron force field model

temp/drude - temperature of Core–Drude pairs

temp/eff - temperature of a group of nuclei and electrons in the electron force field model

temp/partial - temperature excluding one or more dimensions of velocity

temp/profile - temperature excluding a binned velocity profile

temp/ramp - temperature excluding ramped velocity component

temp/region - temperature of a region of atoms

temp/region/eff - temperature of a region of nuclei and electrons in the electron force field model

temp/rotate - temperature of a group of atoms after subtracting out their center-of-mass and angular velocities

temp/sphere - temperature of spherical particles

temp/uef - kinetic energy tensor in the reference frame of an applied flow field

ti - thermodynamic integration free energy values

torque/chunk - torque applied on each chunk

vacf - velocity auto-correlation function of group of atoms

vcm/chunk - velocity of center-of-mass for each chunk

viscosity/cos - velocity profile under cosine-shaped acceleration

voronoi/atom - Voronoi volume and neighbors for each atom

xrd - X-ray diffraction intensity on a mesh of reciprocal lattice nodes

## Restrictions

none

## Default

none