Elektrine lite

← Feed

@dalke@toots.nu

Post #1909683

2026-03-20 09:44 UTC

Here's an #RDKit #cheminformatics quiz for you all. What do you think this code will output? from rdkit import Chem mol = Chem.MolFromSmiles("C" + "C(C)(C)" * 50 + "C") pat = Chem.MolFromSmarts("[$([CD4H0X4](-*)(-*)(-*)-*)]") print(len(mol.GetSubstructMatches(pat))) No cheating by actually running the code! :) Feel free to explain your reasoning in the comments.

Replies (2)

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

    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.

    Open ##1978201

  • @cdk@fosstodon.org 2026-03-20 11:16

    @dalke we find 50: https://cdkdepict.cloud.vhp4safety.nl/depict/bot/svg?smi=CC(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C(C)(C)C&w=-1&h=-1&abbr=on&hdisp=S&sma=%5B%24(%5BCD4H0X4%5D(-*)(-*)(-*)-*)%5D&zoom=1.3&annotate=none&r=0

    Open ##1978203