Background Info: SMARTS is a convention for specifying molecular patterns. It is supported by Mathematica 12's MoleculePattern function.
Problem Setup: Consider
MoleculePattern["[!#6;!#1;!H0]"]]
This means "match atoms that are not carbon and not hydrogen and have more than zero hydrogens attached."
What seems to work OK: The Molecule["CNO"]
has two atoms satisfying that pattern, and indeed, MoleculePlot correctly highlights both the nitrogen and oxygen atoms:
MoleculePlot[
Molecule["CNO"],
MoleculePattern["[!#6;!#1;!H0]"]]
What seems to be a problem: FindMoleculeSubstructure does not find both atoms; it incorrectly only finds the nitrogen (atom 2) but not the oxygen:
FindMoleculeSubstructure[
Molecule["CNO"],
MoleculePattern["[!#6;!#1;!H0]"]]
{<|1 -> 2|>}
(the returned association means "pattern 1 matched by atom 2 in the molecule)
Updated: I think this is an error with the arguments/documentation for FindMoleculeSubstructure. The documentation says that providing no third argument searches for all matches, but if I add the third argument, then I find the correct number of matches. For example:
FindMoleculeSubstructure[
Molecule["CNO"],
MoleculePattern["[!#6;!#1;!H0]"],
10]
{<|1 -> 2|>, <|1 -> 3|>}
(which is correct)
Gratuitous additional examples: This appears to occurs with other MoleculePattern types. The exact same type of problem (two matches correctly found with MoleculePlot, but only one found with FindMoleculeSubstructure) also occurs with MoleculePattern["[C;H3,H4]"]]
for Molecule["CCC"]
, as well as the same "fix".