AtomCount

AtomCount[mol]

gives the number of atoms in the molecule represented by mol.

AtomCount[mol,patt]

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

Details and Options

  • Possible forms 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
  • With the default option setting IncludeHydrogensAll, AtomCount will include implicit hydrogen atoms. Use IncludeHydrogens"ExplicitOnly" to exclude these hydrogens.

Examples

open allclose all

Basic Examples  (2)

Count the number of atoms in phenol:

Count the number of carbon atoms:

Count the number of non-carbon atoms:

Count the number of carbon atoms with exactly one hydrogen attached:

Count the number of nitrogen atoms inside a ring:

Highlight the cyclic nitrogen using MoleculePlot:

Options  (1)

IncludeHydrogens  (1)

AtomCount will include all atoms by default:

Use IncludeHydrogensNone to exclude the hydrogens, which make up the majority of atoms:

This is equivalent to using a pattern excluding hydrogen atoms:

Properties & Relations  (1)

Because Molecule will try to fill valences with hydrogen atoms, hydrogen atoms will be included in the count even if they were not in the original molecule expression:

To exclude implicit hydrogen atoms, use:

Alternatively, to stop hydrogen atoms from appearing, use the Molecule option ValenceFillingNone:

The resulting molecule contains a single atom with unpaired electrons:

Wolfram Research (2019), AtomCount, Wolfram Language function, https://reference.wolfram.com/language/ref/AtomCount.html (updated 2020).

Text

Wolfram Research (2019), AtomCount, Wolfram Language function, https://reference.wolfram.com/language/ref/AtomCount.html (updated 2020).

CMS

Wolfram Language. 2019. "AtomCount." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/AtomCount.html.

APA

Wolfram Language. (2019). AtomCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AtomCount.html

BibTeX

@misc{reference.wolfram_2023_atomcount, author="Wolfram Research", title="{AtomCount}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/AtomCount.html}", note=[Accessed: 29-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_atomcount, organization={Wolfram Research}, title={AtomCount}, year={2020}, url={https://reference.wolfram.com/language/ref/AtomCount.html}, note=[Accessed: 29-March-2024 ]}