compute count/type command — LAMMPS documentation

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

# compute count/type command

## Syntax

    compute ID group-ID count/type mode

- ID, group-ID are documented in compute command

- count/type = style name of this compute command

- mode = atom or bond or angle or dihedral or improper

## Examples

    compute 1 all count/type atom
    compute 1 flowmols count/type bond

## Description

Added in version 15Jun2023.

Define a computation that counts the current number of atoms for each atom type. Or the number of bonds (angles, dihedrals, impropers) for each bond (angle, dihedral, improper) type.

The former can be useful if atoms are added to or deleted from the system in random ways, e.g. via the fix deposit, fix pour, or fix evaporate commands. The latter can be useful in reactive simulations where molecular bonds are broken or created, as well as angles, dihedrals, impropers.

Note that for this command, bonds (angles, etc) are the topological kind enumerated in a data file, initially read by the read_data command or defined by the molecule command. They do not refer to implicit bonds defined on-the-fly by bond-order or reactive pair styles based on the current conformation of small clusters of atoms.

These commands can turn off topological bonds (angles, etc) by setting their bond (angle, etc) types to negative values. This command includes the turned-off bonds (angles, etc) in the count for each type:

- fix shake

- delete_bonds

These commands can create and/or break topological bonds (angles, etc). In the case of breaking, they remove the bond (angle, etc) from the system, so that they no longer exist (bond_style quartic and BPM bond styles are exceptions, see the discussion below). Thus they are not included in the counts for each type:

- delete_bonds remove

- bond_style quartic

- fix bond/react

- fix bond/create

- fix bond/break

- BPM package bond styles

If the mode setting is atom then the count of atoms for each atom type is tallied. Only atoms in the specified group are counted.

The atom count for each type can be normalized by the total number of atoms like so:

    compute typevec all count/type atom # number of atoms of each type
    variable normtypes vector c_typevec/atoms # divide by total number of atoms
    variable ntypes equal extract_setting(ntypes) # number of atom types
    thermo_style custom step v_normtypes[*${ntypes}] # vector variable needs upper limit

Similarly, bond counts can be normalized by the total number of bonds. The same goes for angles, dihedrals, and impropers (see below).

If the mode setting is bond then the count of bonds for each bond type is tallied. Only bonds with both atoms in the specified group are counted.

For mode = bond, broken bonds with a bond type of zero are also counted. The bond_style quartic and BPM bond styles break bonds by doing this. See the Howto broken bonds doc page for more details. Note that the group setting is ignored for broken bonds; all broken bonds in the system are counted.

If the mode setting is angle then the count of angles for each angle type is tallied. Only angles with all 3 atoms in the specified group are counted.

If the mode setting is dihedral then the count of dihedrals for each dihedral type is tallied. Only dihedrals with all 4 atoms in the specified group are counted.

If the mode setting is improper then the count of impropers for each improper type is tallied. Only impropers with all 4 atoms in the specified group are counted.

## Output info

This compute calculates a global vector of counts. If the mode is atom or bond or angle or dihedral or improper, then the vector length is the number of atom types or bond types or angle types or dihedral types or improper types, respectively.

If the mode is bond this compute also calculates a global scalar which is the number of broken bonds with type = 0, as explained above.

These values can be used by any command that uses global scalar or vector values from a compute as input. See the Howto output page for an overview of LAMMPS output options.

The scalar and vector values calculated by this compute are both “intensive”.

## Restrictions

none

## Related commands

none

## Default

none