Interesting, we have

On Wed, Jul 31, 2019 at 7:25 PM Dan Nealschneider <
dan.nealschnei...@schrodinger.com> wrote:

> I'm trying to get a SMARTS pattern for a known subset of atoms in an
> ROMol. I haven't been able to find a way to do this directly. Is there a
> way to generate a SMARTS from a subset? Or to extract a subset of atoms
> from an ROMol as a new ROMol? I can have a C++ std::vector<*Atom> or the
> indices or a Python list of atoms or atom indices.
>

Interesting. We have MolFragmentToSmiles() but not MolFragmentToSmarts().
That's something that could/should be fixed.
In the meantime, the easiest solution is probably to just remove the atoms
that aren't in the match and then generate a SMILES.
Here's the python version of that:

In [10]: m = Chem.MolFromSmiles('c1ccc(OC)cc1')


In [11]: match = m.GetSubstructMatch(Chem.MolFromSmarts('*c(OC)*'))


In [12]: rwm = Chem.RWMol(m)


In [13]: for aid in range(m.GetNumAtoms()-1,-1,-1):
    ...:     if aid in match:
    ...:         continue
    ...:     rwm.RemoveAtom(aid)
    ...:


In [14]: Chem.MolToSmarts(rwm)

Out[14]: '[#6]:[#6](-[#8]-[#6]):[#6]'


> The way that I get a list of atoms is that a user lassos them in a GUI.
>

You might be able to get away with MolFragmentToSmiles() here:

In [15]:
Chem.MolFragmentToSmiles(m,match,canonical=False,allBondsExplicit=True)

Out[15]: 'c:c(-O-C):c'

-greg
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to