[CCing the list on this since it may be of general interest]
Dear Tao-wei,
On Wed, May 27, 2009 at 12:29 AM, Tao-wei Huang <[email protected]> wrote:
> Dear Greg,
> Thank you for your reply. My purpose is to construct piece of code with
> RDKit to automatically generate some derivatives of compounds. For instance,
> if my input molecule is mol=cm.MolFromSmiles('CCCCN(C)C'), one of output
> molecules from my code is supposed to be 'CCCCN(=O)(C)C'. I tried two
> approaches to realize this, but none of them works:
> (1) I tried ReplaceSubstructs function:
>>>> mol=cm.MolFromSmiles('CCCCN(C)C')
>>>> N_patt=cm.MolFromSmarts('[$([N]([#6])([#6])[#6])]')
>>>> N_repl=cm.MolFromSmarts('[N+1][O-1]')
>>>> nmol=cm.ReplaceSubstructs(mol, N_patt, N_repl)
>>>> cm.MolToSmiles(nmol)
> Traceback (most recent call last):
> File "<pyshell#11>", line 1, in <module>
> cm.MolToSmiles(nmol)
> ArgumentError: Python argument types in
> Chem.rdmolfiles.MolToSmiles(tuple)
> did not match C++ signature:
> MolToSmiles(class RDKit::ROMol {lvalue} mol, bool isomericSmiles=False,
> bool kekuleSmiles=False, int rootedAtAtom=-1)
This actually is mostly working. The problem you're seeing is that
Chem.ReplaceSubstructs returns a tuple of molecules not just one. You
also should probably use a molecule constructed from SMILES (and not
SMARTS) for the replacement (that way the replacement doesn't contain
query features):
[2]>>> m = Chem.MolFromSmiles('CCCCN(C)C')
[3]>>> N_patt=Chem.MolFromSmarts('[$([N]([#6])([#6])[#6])]')
[6]>>> N_repl=Chem.MolFromSmiles('[N+][O-]')
[8]>>> tpl=Chem.ReplaceSubstructs(m, N_patt, N_repl)
[9]>>> tpl
Out[9] (<rdkit.Chem.rdchem.Mol object at 0x9024ed4>,)
[10]>>> Chem.MolToSmiles(tpl[0])
Out[10] 'CCCC[N+]([O-])(C)C'
Best Regards,
-greg