Peter, quite correct.

To do that, you'll need to do operations on the rings themselves:

>>> m = Chem.MolFromSmiles("C1CC12CCC2")

>>> list(m.GetRingInfo().AtomRings())

[(0, 1, 2), (3, 4, 5, 2)]

And set operations are probably your friend

>>> m = Chem.MolFromSmiles("C1CCC12CCC2")

>>> list(m.GetRingInfo().AtomRings())

[(0, 3, 2, 1), (4, 5, 6, 3)]

# get all 4 membered rings

>>> rings = [set(r) for r in m.GetRingInfo().AtomRings() if len(r) == 4]

# from the first ring, see if there are any intersections

>>> s = rings[0]

>>> for r in rings[1:]:

...   p = s.intersection(r)

...   if p: print p

...

set([3])

Cheers,
 Brian

On Tue, Apr 11, 2017 at 4:19 PM, Peter S. Shenkin <shen...@gmail.com> wrote:

> But Brian's solution won't help Jonathan find atoms that are in two
> three-membered or two four-membered rings, which I thought Jonathan also
> wanted, based on the wording of the original query.
>
> -P.
>
> On Tue, Apr 11, 2017 at 4:12 PM, Curt Fischer <curt.r.fisc...@gmail.com>
> wrote:
>
>> Brian's solution is obviously better (shorter, uses less functions) than
>> mine.  (Although mine assumes that you want atoms that are part of
>> _exactly_ two rings, not atoms that are part of _at least_ two rings as
>> Brian's does.  Probably Brian's solution is what you want but worth noting.)
>>
>> CF
>>
>> On Tue, Apr 11, 2017 at 1:03 PM, Brian Kelley <fustiga...@gmail.com>
>> wrote:
>>
>>> You are so close!
>>>
>>> >>> from rdkit import Chem
>>>
>>> >>> m = Chem.MolFromSmiles("C1CC12CCC2")
>>>
>>> >>> for atom in m.GetAtoms():
>>>
>>> ...   if atom.IsInRingSize(3) and atom.IsInRingSize(4): print
>>> atom.GetIdx()
>>>
>>> ...
>>>
>>> 2
>>>
>>> >>>
>>>
>>> Cheers,
>>>  Brian
>>>
>>> On Tue, Apr 11, 2017 at 1:38 PM, Jonathan Saboury <jsab...@gmail.com>
>>> wrote:
>>>
>>>> Hello All,
>>>>
>>>> I'm trying to make a function to check if a mol has an atom that is
>>>> part of two small rings (3 or 4 atoms). Using GetRingInfo()/NumAtomRings()
>>>> I can find out how many ring systems each atom is in, but not the details
>>>> of the rings. atom.IsInRingSize(size) returns a bool so I couldn't use
>>>> that. I'm using the python api.
>>>>
>>>> Any suggestions? Thanks!
>>>>
>>>> - Jonathan
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>
>>>
>>
>> ------------------------------------------------------------
>> ------------------
>> 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