Hi Chenyang,

If you're really interested in counting the number of times the
substructure appears, you can do that much quicker with
`GetSubstructMatches()`:

In [2]: m = Chem.MolFromSmiles('CC(C)CCO')
In [3]: len(m.GetSubstructMatches(Chem.MolFromSmarts('[CH3;X4]')))
Out[3]: 2

Is that sufficient, or do you actually want to sequentially remove all of
the groups in your list?

If you actually want to remove them, you are probably better off using the
chemical reaction functionality instead of DeleteSubstructs(), which
recalculates the number of implicit Hs on atoms after each call.

-greg


On Mon, Mar 6, 2017 at 4:21 AM, Chenyang Shi <cs3...@columbia.edu> wrote:

> I am new to rdkit but I am already impressed by its vibrant community. I
> have a question regarding deleting substructure. In the RDKIT
> documentation, this is a snippet of code describing how to delete
> substructure:
>
> >>>m = Chem.MolFromSmiles("CC(=O)O")
> >>>patt = Chem.MolFromSmarts("C(=O)[OH]")
> >>>rm = AllChem.DeleteSubstructs(m, patt)
> >>>Chem.MolToSmiles(rm)
> 'C'
>
> This block of code first loads a molecule CH3COOH using SMILES code, then
> defines a substructure COOH using SMARTS code which is to be deleted. After
> final line of code, the program outputs 'C', in SMILES form.
>
> I had wanted to develop a method for detecting number of groups in a
> molecule. In CH3COOH case, I can search number of --CH3 and --COOH group by
> using their respective SMARTS code with no problem. However, when molecule
> becomes more complicated, it is preferred to delete the substructure that
> has been searched before moving to next search using SMARTS code. Well, in
> current case, after searching -COOH group and deleting it, the leftover is
> 'C' which is essentially CH4 instead of --CH3. I cannot proceed with
> searching with SMARTS code for --CH3 ([CH3;A;X4!R]).
>
> Is there any way to work around this?
> Thanks,
> Chenyang
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to