def largest_ring_size(smiles):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol, smiles)
    n_rings, parts = oechem.OEDetermineRingSystems(mol)
    max_i = max(parts)
    l = 0
    for i in range(1, max_i + 1):
        n_ring = parts.count(i)
        if n_ring > l:
            l = n_ring
    return l
def sort_rings(tagged_smiles):
    """
    Sort ring bonds for nicer plotting

    Paramerts
    ---------
    tagged_smiles: mapped SMILES for plotting

    Returns
    -------
    ring_bonds: list of tuples of aliphatic and aromtic ring bonds atom map indices
    ring_sizes: list of ring sizes
    """
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol, tagged_smiles)
    nringsystems, parts = oechem.OEDetermineRingSystems(mol)
    aromatic_ring_bonds = []
    aliphatic_ring_bonds = []
    aromatic_ring_sizes = []
    aliphatic_ring_sizes = []
    for ring_idx in range(1, nringsystems + 1):
        i = 0
        j = 0
        for bond in mol.GetBonds():
            if bond.IsInRing():
                if bond.IsAromatic():
                    if parts[bond.GetBgnIdx()] == ring_idx and parts[
                            bond.GetEndIdx()] == ring_idx:
                        aromatic_ring_bonds.append((bond.GetBgn().GetMapIdx(),
                                                    bond.GetEnd().GetMapIdx()))
                        i += 1

                if not bond.IsAromatic():
                    if parts[bond.GetBgnIdx()] == ring_idx and parts[
                            bond.GetEndIdx()] == ring_idx:
                        aliphatic_ring_bonds.append(
                            (bond.GetBgn().GetMapIdx(),
                             bond.GetEnd().GetMapIdx()))
                        j += 1
        if i > 0:
            aromatic_ring_sizes.append(i)
        if j > 0:
            aliphatic_ring_sizes.append(j)

    return aliphatic_ring_bonds + aromatic_ring_bonds, aliphatic_ring_sizes + aromatic_ring_sizes
Beispiel #3
0
def test_find_ring_systems(smiles):

    from openeye import oechem

    molecule = Molecule.from_smiles(smiles, allow_undefined_stereo=True)

    oe_molecule = molecule.to_openeye()
    _, expected = oechem.OEDetermineRingSystems(oe_molecule)

    ring_systems = find_ring_systems(molecule)

    for i, ring_system in enumerate(expected):

        if ring_system > 0:
            assert ring_systems[i] == ring_system

        else:
            assert i not in ring_systems
Beispiel #4
0
    def GetSameRingAtoms(mol, atomSet):
        '''
        @type mol: OEGraphMol
        @type atomSet: OEAtomBondSet
        @return list[OEAtombase]
        '''
        oechem.OEFindRingAtomsAndBonds(mol)
        _, ringIdxPerAtom = oechem.OEDetermineRingSystems(mol)
        toKeepRings = {}
        for atom in atomSet.GetAtoms():
            if ringIdxPerAtom[atom.GetIdx()] > 0:
                toKeepRings[ringIdxPerAtom[atom.GetIdx()]] = True

        ringAtoms = []
        for i in range(0, len(ringIdxPerAtom)):
            if ringIdxPerAtom[i] in toKeepRings:
                ringAtoms.append(mol.GetAtom(oechem.OEHasAtomIdx(i)))

        return ringAtoms
Beispiel #5
0
 def ring_size (self):                                 
     """
     Returns a dictionary, which is atom's index correspoding to the ring size the atom in.
     @rtype : C{dic} of C{int} : C{int}
     @return: A dictionary of atom indices correspoing to the size of the ring they are in.          
     """
     ring_size = {}                                    
     oechem.OEFindRingAtomsAndBonds(self._struc)       
     nrrings, rings = oechem.OEDetermineRingSystems(self._struc)     
     ring_dic = {}                                     
     for ring_idx in rings:                            
         if not ring_dic.has_key(ring_idx):            
             ring_dic[ring_idx] = []                   
     for key in ring_dic.keys():                       
         if key > 0:                                   
             ring_dic[key] = rings.count(key)          
         else:                                         
             ring_dic[key] = 0                         
     for (idx, atom) in enumerate(rings):                            
         oe_idx = idx +1                                             
         ring_size [oe_idx] = ring_dic[atom]           
                                                       
     return ring_size
Beispiel #6
0
def _tag_rings(mol):
    """
    This function tags ring atom and bonds with ringsystem index

    Parameters
    ----------
    mol: OpenEye OEMolGraph

    Returns
    -------
    tagged_rings: dict
        maps ringsystem index to ring atom and bond indices

    """
    tagged_rings = {}
    nringsystems, parts = oechem.OEDetermineRingSystems(mol)
    for ringidx in range(1, nringsystems +1):
        ringidx_atoms = set()
        for atom in mol.GetAtoms():
            if parts[atom.GetIdx()] == ringidx:
                ringidx_atoms.add(atom.GetIdx())
                tag = oechem.OEGetTag('ringsystem')
                atom.SetData(tag, ringidx)
        # Find bonds in ring and tag
        ringidx_bonds = set()
        for a_idx in ringidx_atoms:
            atom = mol.GetAtom(oechem.OEHasAtomIdx(a_idx))
            for bond in atom.GetBonds():
                nbrAtom = bond.GetNbr(atom)
                nbrIdx = nbrAtom.GetIdx()
                if nbrIdx in ringidx_atoms and nbrIdx != a_idx:
                    ringidx_bonds.add(bond.GetIdx())
                    tag = oechem.OEGetTag('ringsystem')
                    bond.SetData(tag, ringidx)
        tagged_rings[ringidx] = (ringidx_atoms, ringidx_bonds)
    return tagged_rings
def n_rings(smiles):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol, smiles)
    n_rings, parts = oechem.OEDetermineRingSystems(mol)
    return n_rings