Python-Ref > Cheminformatics > OpenBabel > Ring perception
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Ring perception

How to find a set of smallest simple rings.
Ring in openbabel is represented by an object of class OBRing. You can find the "Smallest Set of Smallest Rings" using the molecule method GetSSSR.
Expand/Shrink
Zdroj: (babel4-1.py)
  1   import pybel
  2   
  3   mol = pybel.readstring( "smi", "C1CC1CC(C1CCC1)Cc1ccccc1")
  4   for ring in mol.OBMol.GetSSSR():
  5     print ring
stdout:
<openbabel.OBRing; proxy of <Swig Object of type 'OpenBabel::OBRing *' at 0xa03360> >
<openbabel.OBRing; proxy of <Swig Object of type 'OpenBabel::OBRing *' at 0xa026e0> >
<openbabel.OBRing; proxy of <Swig Object of type 'OpenBabel::OBRing *' at 0xa02060> >
Doba běhu: 143.0 ms
The following code shows a more practical example of what we can do with SSSR's.
Expand/Shrink
Zdroj: (babel4-2.py)
  1   import pybel
  2   
  3   mol = pybel.readstring( "smi", "C1CC1CC(C1CCC1)Cc1ccccc1")
  4   for ring in mol.OBMol.GetSSSR():
  5     print ring.Size(), ring.IsAromatic(), ring.GetType()
  6   
  7   # atoms in first ring
  8   print "--------------------"
  9   ring1 = mol.OBMol.GetSSSR()[0]
 10   for a in mol.atoms:
 11     print a.idx, ring1.IsMember( a.OBAtom)
stdout:
3 False 
4 False 
6 True benzene
--------------------
1 True
2 True
3 True
4 False
5 False
6 False
7 False
8 False
9 False
10 False
11 False
12 False
13 False
14 False
15 False
16 False
Doba běhu: 140.8 ms