Hi Francois, not sure if you have solved this yet. I believe it won't be possible to use AllChem.ReplaceSubstructs without breaking the rings or enumerating them. You can however use reactions for this problem. Here's an example based on yours:
mol = Chem.MolFromSmiles('O=c1[nH]cccc1') rxn = AllChem.ReactionFromSmarts('[c:1](=[O:2])[nH:3]>>[c:1]([O:2])[nH0:3]') ps = rxn.RunReactants([Chem.MolFromSmiles('O=c1[nH]cccc1')]) Chem.MolToSmiles(ps[0][0]) 'Oc1ccccn1' Hope this helps! Best, Fio On Thu, Jan 7, 2021 at 10:33 PM Francois Berenger <mli...@ligand.eu> wrote: > Dear list, > > I have been trying to replace this SMARTS pattern in a ring: > > 'c(=O)[nH]' > > By this SMILES fragment: > > 'c(O)n' > > My trials using a single SMARTS pattern search then replace > break open the ring, which is not what I want. > > My not working trial code: > --- > mol = Chem.MolFromSmiles('O=c1[nH]cccc1') > pat = Chem.MolFromSmarts('c(=O)[nH]') > rep = Chem.MolFromSmarts('c(O)n') > res = AllChem.ReplaceSubstructs(mol,pat,rep) > Chem.MolToSmiles(res[0]) > 'ccccc(n)O' > --- > > The example molecule is just an example; the ring might be smaller > and/or have more heteroatoms. > > Should I use a chemical reaction for this? > > Am I forced to describe full rings in both SMARTS patterns?! > I don't want to have to enumerate all the possibilities... > > I can make it ~work~ using two replacements: > first 'c(=O)' to 'c(O)' > then > '[nH]' to 'n' > But this is less precise than what I really want > and I believe it will change molecules or places I don't want to change. > > Thanks a lot and happy new year! > F. > > > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss