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 and Options

  • 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 all close all

Basic Examples  (2)

Count the number of atoms:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Count the number of carbon atoms:

In[3]:=
Click for copyable input
Out[3]=

Count the number of non-carbon atoms:

In[4]:=
Click for copyable input
Out[4]=

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

In[5]:=
Click for copyable input
Out[5]=

Count the number of atoms that have a nitrogen atom inside a ring:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Scope  (1)

Introduced in 2019
(12.0)