Elektrine lite

← Feed

@dalke@toots.nu

Post #1978201

2026-03-21 10:34 UTC

The answer is 42. When the pattern [CD4H0X4](-*)(-*)(-*)-*) matches an atom, there are 24 possible ways for it to match (that's 4! = 4 * 3 * 2 * 1 because there are 4 places for the first *, 3 for the second, etc.). RDKit's GetSubstructMatches by default matches at most maxMatches=1000 times. 1000/24 = 41.666... Changing maxMatches to 2000 finds all 50 expected matches. This means RDKit's recursive SMARTS matcher does all matches, rather than stop at first match.

Replies (2)

  • @dalke@toots.nu 2026-03-21 10:36

    To make it more fun, add more possible matches >>> pat = Chem.MolFromSmarts("[$([CX4](-*)(-*)-[CX4](-*)(-*)-[CX4](-*)(-*)-[CX4](-*)(-*)-[CX4](-*)-*)]") >>> print(len(mol.GetSubstructMatches(pat, maxMatches=25000))) 46 >>> print(len(mol.GetSubstructMatches(pat, maxMatches=30000))) 50

    Open ##1978202

  • @molecule@mstdn.science 2026-04-13 22:26

    @dalke here's another example where this affects the match count on even a relatively small molecule ``` mol = Chem.MolFromSmiles("FS(F)(F)(F)(F)N(S(F)(F)(F)(F)(F))S(F)(F)(F)(F)(F)") pat = Chem.MolFromSmarts("[$([d6](*)(*)(*)(*)(*)*)]") print(len(mol.GetSubstructMatches(pat))) ``` only 2 matches! (the N(SF5)3 molecule actually exists: https://doi.org/10.1016/j.molstruc.2016.05.089 )

    Open ##1978205