returns a molecule pattern representing the largest common substructure for the input molecules.


uses params to determine equivalence between atoms and bonds.

Details and Options

  • MoleculeMaximumCommonSubstructure attempts to find the maximum common substructure (MCS) present in all the molecules.
  • MoleculeMaximumCommonSubstructure returns a MoleculePattern object, which can be used in functions such as MoleculePlot, MoleculePlot3D, MoleculeContainsQ and FindMoleculeSubstructure.
  • When comparing substructures, equivalence between atoms or bonds is determined by params, which can be Automatic, None or a list {param1,param2,} of matching parameters. Possible values for the parami include:
  • "AtomicNumber"match atoms with the same atomic number
    "Valence"match atomic valence
    "FormalCharge"match the atomic formal charge
    "AtomChirality"match the atom chirality (R) or (S)
    "RingAtomQ"only match ring atoms with other ring atoms
    "BondType"match the bond type
    "BondStereo"match the double bond stereo (E) or (Z)
    "RingBondQ"only match ring bond with other ring bonds
    "CompleteRings"only match complete rings
  • The default value of Automatic is equivalent to {"AtomicNumber","BondType"}.
  • With the option setting TimeConstraintt, MoleculeMaximumCommonSubstructure waits t seconds before returning the largest common substructure found so far.


open allclose all

Basic Examples  (3)

Find the maximum common substructure for three molecules:

Highlight the structure in place:

Find the maximum common substructure between two short linear molecules:

By relaxing the match parameters to not look at atomic number, the size of the structure is increased:

Find the maximum common substructure among a group of medium-sized molecules:

Display the common substructure highlighted in place:

Scope  (7)

By default, atoms must have the same atomic number to match; oxygen does not match carbon:

Remove this restriction to get a larger substructure:

Formal charges are not considered by default when comparing atoms, so the zwitterionic and normal forms of glycine match:

Include "FormalCharge" as well as atom and bond types to make the pattern more restrictive:

Include "Valence" to control whether trivalent and pentavalent phosphorus match:

By default, atoms in rings will match atoms in straight chains:

Use "RingAtomQ" so that only ring atoms are matched:

Both of these molecules contain two cyclopentane rings connected by a single bond:

When "RingBondQ" is used, the connecting bond no longer matches because it is part of a larger ring in the second molecule:

Include atom chirality to restrict the matching between two enantiomers:

By default, partial rings can be included in the common substructure:

Use the "CompleteRings" parameter to ensure only full rings are matched:

Options  (1)

TimeConstraint  (1)

Computing the MCS for two molecules can be computationally expensive:

By including a short time constraint, it is often possible to find an approximate MCS:

Applications  (2)

Find the common substructure among a series of synthetic opioid analgesics:

Illustrate the "morphine rule" of medicinal chemistry by highlighting the substructure on morphine:

Define a function to compute the similarity between two molecules based on the number of bonds in the MCS:

Phenol and benzene have 6 out of 7 heavy atoms in common:

Choose the most similar molecules from a random set:

Wolfram Research (2021), MoleculeMaximumCommonSubstructure, Wolfram Language function,


Wolfram Research (2021), MoleculeMaximumCommonSubstructure, Wolfram Language function,


Wolfram Language. 2021. "MoleculeMaximumCommonSubstructure." Wolfram Language & System Documentation Center. Wolfram Research.


Wolfram Language. (2021). MoleculeMaximumCommonSubstructure. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2023_moleculemaximumcommonsubstructure, author="Wolfram Research", title="{MoleculeMaximumCommonSubstructure}", year="2021", howpublished="\url{}", note=[Accessed: 16-April-2024 ]}


@online{reference.wolfram_2023_moleculemaximumcommonsubstructure, organization={Wolfram Research}, title={MoleculeMaximumCommonSubstructure}, year={2021}, url={}, note=[Accessed: 16-April-2024 ]}