Re: [Rdkit-discuss] SMARTS pattern replacement inside a ring; without breaking the ring open...

2021-01-12 Thread Francois Berenger

On 12/01/2021 15:10, Fiorella Ruggiu wrote:

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]1')

rxn =
AllChem.ReactionFromSmarts('[c:1](=[O:2])[nH:3]>>[c:1]([O:2])[nH0:3]')

ps = rxn.RunReactants([Chem.MolFromSmiles('O=c1[nH]1')])

Chem.MolToSmiles(ps[0][0])

'Oc1n1'


I was fighting other fires. Thanks a lot for this example!


Hope this helps!

Best,

Fio

On Thu, Jan 7, 2021 at 10:33 PM Francois Berenger 
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]1')
pat = Chem.MolFromSmarts('c(=O)[nH]')
rep = Chem.MolFromSmarts('c(O)n')
res = AllChem.ReplaceSubstructs(mol,pat,rep)
Chem.MolToSmiles(res[0])
'c(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


Re: [Rdkit-discuss] SMARTS pattern replacement inside a ring; without breaking the ring open...

2021-01-11 Thread Fiorella Ruggiu
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]1')
rxn = AllChem.ReactionFromSmarts('[c:1](=[O:2])[nH:3]>>[c:1]([O:2])[nH0:3]')
ps = rxn.RunReactants([Chem.MolFromSmiles('O=c1[nH]1')])
Chem.MolToSmiles(ps[0][0])

'Oc1n1'


Hope this helps!

Best,

Fio



On Thu, Jan 7, 2021 at 10:33 PM Francois Berenger  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]1')
> pat = Chem.MolFromSmarts('c(=O)[nH]')
> rep = Chem.MolFromSmarts('c(O)n')
> res = AllChem.ReplaceSubstructs(mol,pat,rep)
> Chem.MolToSmiles(res[0])
> 'c(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


[Rdkit-discuss] SMARTS pattern replacement inside a ring; without breaking the ring open...

2021-01-07 Thread Francois Berenger

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]1')
pat = Chem.MolFromSmarts('c(=O)[nH]')
rep = Chem.MolFromSmarts('c(O)n')
res = AllChem.ReplaceSubstructs(mol,pat,rep)
Chem.MolToSmiles(res[0])
'c(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