AtomCount

AtomCount[mol]

gives the number of atoms in the molecule mol.

AtomCount[mol,patt]

gives the number of atoms in the molecule mol matching the atom pattern patt.

Details

  • Possible values for patt are:
  • syman atom with atomic symbol sym
    Atom[rules]an atom with properties described by rules
    MoleculePattern["smarts"]an atom matching the SMARTS string "smarts"
    patt1|patt2|an atom matching any of the patti
  • AtomCount returns the number of atoms explicitly present in mol and does not include implicit hydrogens. For the count including implicit hydrogens, use mol["FullAtomCount"].

Examples

open allclose all

Basic Examples  (2)

Count the number of atoms:

Count the number of carbon atoms:

Count the number of non-carbon atoms:

Count the number of carbon atoms with at least one hydrogen attached:

Count the number of nitrogen atoms inside a ring:

Scope  (1)

AtomCount will only count the atoms in the molecule expression:

Use the property "FullAtomCount" to return the count including implicit hydrogens:

Introduced in 2019
 (12.0)