MoleculeSubstructureCount[mol,patt]
gives a count of the number of times patt appears as a substructure in mol.
MoleculeSubstructureCount[patt]
represents an operator form of MoleculeSubstructureCount that can be applied to a molecule.
MoleculeSubstructureCount
MoleculeSubstructureCount[mol,patt]
gives a count of the number of times patt appears as a substructure in mol.
MoleculeSubstructureCount[patt]
represents an operator form of MoleculeSubstructureCount that can be applied to a molecule.
Details and Options
- patt should be one of the following forms:
-
MoleculePattern[…] a molecule pattern Atom[…] a pattern for a single atom Bond[{a1,a2}] a bond between atoms with specified patterns - By default, substructure matches are pruned to remove multiple matches to the same set of atoms. Use the option Overlaps->True to disable this behavior.
- MoleculeSubstructureCount takes the following options:
-
IgnoreStereochemistry False whether to ignore stereochemistry IncludeHydrogens Automatic whether to include hydrogen atoms Overlaps False whether to include matches that overlap
Examples
open all close allBasic Examples (3)
Count all carboxylic acid groups that are in a molecule:
MoleculeSubstructureCount[Molecule[{"O", "C", "O", "C", "C", "C", "C", "O", "O", "N", "N", "H", "H", "H", "H"},
{Bond[{1, 2}, "Double"], Bond[{2, 3}, "Single"], Bond[{2, 4}, "Single"], Bond[{4, 5}, "Aromatic"],
Bond[{5, 6}, "Aromatic"], Bond[{6, 7}, "Single"], Bond[{7, 8}, "Double"], Bond[{7, 9}, "Single"],
Bond[{6, 10}, "Aromatic"], Bond[{10, 11}, "Aromatic"], Bond[{11, 4}, "Aromatic"],
Bond[{3, 12}, "Single"], Bond[{5, 13}, "Single"], Bond[{9, 14}, "Single"],
Bond[{10, 15}, "Single"]}, {}], MoleculePattern["C(=O)[OH]"]]MoleculePlot[Molecule[{"O", "C", "O", "C", "C", "C", "C", "O", "O", "N", "N", "H", "H", "H", "H"},
{Bond[{1, 2}, "Double"], Bond[{2, 3}, "Single"], Bond[{2, 4}, "Single"], Bond[{4, 5}, "Aromatic"],
Bond[{5, 6}, "Aromatic"], Bond[{6, 7}, "Single"], Bond[{7, 8}, "Double"], Bond[{7, 9}, "Single"],
Bond[{6, 10}, "Aromatic"], Bond[{10, 11}, "Aromatic"], Bond[{11, 4}, "Aromatic"],
Bond[{3, 12}, "Single"], Bond[{5, 13}, "Single"], Bond[{9, 14}, "Single"],
Bond[{10, 15}, "Single"]}, {}], MoleculePattern["C(=O)[OH]"]]Count carbonyls adjacent to nitrogen atoms:
MoleculeSubstructureCount[Molecule[{"C", "N", "C", "O", "C", "C", "N", "C", "N", "C", "N", "C", "C", "O", "H", "H", "H", "H",
"H", "H", "H", "H", "H", "H"}, {Bond[{1, 2}, "Single"], Bond[{2, 3}, "Aromatic"],
Bond[{3, 4}, "Double"], Bond[{3, 5}, "Aromatic"], Bond[{5, 6 ... ], Bond[{1, 16}, "Single"],
Bond[{1, 17}, "Single"], Bond[{8, 18}, "Single"], Bond[{10, 19}, "Single"],
Bond[{10, 20}, "Single"], Bond[{10, 21}, "Single"], Bond[{12, 22}, "Single"],
Bond[{12, 23}, "Single"], Bond[{12, 24}, "Single"]}, {}],
MoleculePattern[{"N", "C", "O"}, {Bond[{1, 2}, "Single" | "Aromatic"], Bond[{2, 3}, "Double"]}]]MoleculeSubstructureCount[MoleculePattern["CNC"]] /@ {Molecule[{"C", "C", "C", "C", "C", "C", "N", "C", "C", "O", Atom["C", "HydrogenCount" -> 1],
Atom["C", "HydrogenCount" -> 1], Atom["N", "FormalCharge" -> 1, "UnpairedElectronCount" -> 1],
"C", Atom["C", "HydrogenCount" -> 1], Atom["O", "Forma ... ,
Association["StereoType" -> "DoubleBond", "StereoBond" -> {8, 9}, "Value" -> "Opposite",
"Ligands" -> {7, 10}], Association["StereoType" -> "DoubleBond", "StereoBond" -> {46, 47},
"Value" -> "Together", "Ligands" -> {51, 48}]}}], Molecule[{"O", Atom["C", "HydrogenCount" -> 1], Atom["C", "HydrogenCount" -> 1], "O", "P", "O",
"O", "O", Atom["C", "HydrogenCount" -> 1], "O", Atom["C", "HydrogenCount" -> 1], "N", "C", "N",
Atom["C", "HydrogenCount" -> 1], Atom["C", "Hydrog ... n" -> "Counterclockwise"], Association["StereoType" -> "Tetrahedral",
"ChiralCenter" -> 18, "Direction" -> "Counterclockwise"],
Association["StereoType" -> "Tetrahedral", "ChiralCenter" -> 25,
"Direction" -> "Counterclockwise"]}}], Molecule[{"O", "C", "N", "C", "C", "Cl", "C", "C", "C", "C", "Cl", "N", "C", "N", "C", "C", "N",
"C", Atom["C", "HydrogenCount" -> 1], "C", "O", "N", "C", "C", "C", "C", "C", "C", "C", "C", "C",
"C", "C", "F", "C", "C", "C", "C", "C", "C", "F ... , Bond[{10, 4}, "Aromatic"],
Bond[{19, 14}, "Single"], Bond[{33, 28}, "Aromatic"], Bond[{40, 35}, "Aromatic"]},
{StereochemistryElements -> {Association["StereoType" -> "Tetrahedral", "ChiralCenter" -> 19,
"Direction" -> "Clockwise"]}}]}Scope (2)
Create a molecule from an ExternalIdentifier and find how many carbon-oxygen bonds it has:
MoleculeSubstructureCount[
Molecule[ExternalIdentifier["WikidataID", "Q27269295", <|"Label" -> "detorubicin", "Description" -> "chemical compound"|>]],
Bond[{"C", "O"}]
]Find the three molecules with the most halogen atoms:
TakeLargestBy[Molecule /@ IconizedObject[«list of 20 SMILES strings»], MoleculeSubstructureCount[Atom["Cl" | "F" | "Br" | "I"]], 3]Options (3)
IgnoreStereochemistry (1)
By default, stereoisomers do not match:
MoleculeSubstructureCount[Molecule["l-alanine"],
MoleculePattern["C[C@@H](N)C(=O)O"]]Use IgnoreStereochemistryTrue to get a positive match:
MoleculeSubstructureCount[Molecule["l-alanine"],
MoleculePattern["C[C@@H](N)C(=O)O"], IgnoreStereochemistry -> True]IncludeHydrogens (1)
By default, substructure matching is performed using a molecule's hydrogen-suppressed graph, unless the pattern contains explicit hydrogen atoms:
MoleculeSubstructureCount[Molecule[{"C", "C", "C", "Cl"}, {Bond[{1, 2}, "Single"], Bond[{2, 3}, "Single"],
Bond[{2, 4}, "Single"]}, {}], Bond[{"C", "H"}, "Single"]]Some matches to hydrogen will be missed for more involved patterns. In the following example, the pattern is for a carbon atom bonded to either a hydrogen or chlorine atom, but only finds the C-Cl bond:
MoleculeSubstructureCount[Molecule[{"C", "C", "C", "Cl"}, {Bond[{1, 2}, "Single"], Bond[{2, 3}, "Single"],
Bond[{2, 4}, "Single"]}, {}], Bond[{"C", Atom["AtomicNumber" -> (1 | 17)]}, "Single"]]Use the option IncludeHydrogensTrue to make sure hydrogens are treated as explicit for the purposes of pattern matching:
MoleculeSubstructureCount[Molecule[{"C", "C", "C", "Cl"}, {Bond[{1, 2}, "Single"], Bond[{2, 3}, "Single"],
Bond[{2, 4}, "Single"]}, {}], Bond[{"C", Atom["AtomicNumber" -> (1 | 17)]}, "Single"], IncludeHydrogens -> All]Overlaps (1)
By default, six carbon‐carbon bonds are found in benzene:
MoleculeSubstructureCount[Molecule["benzene"], Bond[{"C", "C"}, _]]By default, substructure matches are pruned to remove multiple matches to the same set of atoms. Use the option OverlapsTrue to count each match separately:
MoleculeSubstructureCount[Molecule["benzene"], Bond[{"C", "C"}, _], Overlaps -> True]Applications (1)
aalist = EntityList[EntityClass["Chemical", "AminoAcids"]]Create a pattern for the carboxyl group:
carboxylPattern = MoleculePattern["C(=O)[OH]"]Select all amino acids that contain two carboxyl groups:
Select[aalist, MoleculeSubstructureCount[#, carboxylPattern] === 2&]Show the selected molecules with the carboxyl groups highlighted:
MoleculePlot[#, carboxylPattern]& /@ %Related Guides
History
Text
Wolfram Research (2021), MoleculeSubstructureCount, Wolfram Language function, https://reference.wolfram.com/language/ref/MoleculeSubstructureCount.html.
CMS
Wolfram Language. 2021. "MoleculeSubstructureCount." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MoleculeSubstructureCount.html.
APA
Wolfram Language. (2021). MoleculeSubstructureCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MoleculeSubstructureCount.html
BibTeX
@misc{reference.wolfram_2026_moleculesubstructurecount, author="Wolfram Research", title="{MoleculeSubstructureCount}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/MoleculeSubstructureCount.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_moleculesubstructurecount, organization={Wolfram Research}, title={MoleculeSubstructureCount}, year={2021}, url={https://reference.wolfram.com/language/ref/MoleculeSubstructureCount.html}, note=[Accessed: 13-June-2026]}