Ejemplo n.º 1
0
def get_mols_from_frags(this_smiles, old_smiles=None):
    if old_smiles is None:
        old_smiles = []
    fragfunc = GetFragmentationFunction()
    mol = oechem.OEGraphMol()
    oechem.OESmilesToMol(mol, this_smiles)
    frags = [f for f in fragfunc(mol)]
    len_frags = len(frags)

    for smile in old_smiles:
        mol2 = oechem.OEGraphMol()
        oechem.OESmilesToMol(mol2, smile)
        frags += [f for f in fragfunc(mol2)]

    oechem.OEThrow.Info("%d number of fragments generated" % len(frags))

    fragcombs = GetFragmentCombinations(mol, frags, frag_number=len_frags)
    oechem.OEThrow.Info("%d number of fragment combinations generated" %
                        len(fragcombs))

    smiles = set()
    for frag in fragcombs:
        if oechem.OEDetermineComponents(frag)[0] == 1:
            smiles = smiles.union(oechem.OEMolToSmiles(frag))
    return smiles
Ejemplo n.º 2
0
        def molecules(self):
            """
            Returns a list of atom lists. Each element list is a list of atoms o
f a molecule in the structure. The first
            element in the returned list belongs to the biggest molecule.
            """
            ret = []
            count,parts = oechem.OEDetermineComponents(self._struc)
            for i in range (1, count+1):
                atom_in_this_part = []
                for j,k in enumerate (parts):
                    if i == k:
                        atom_in_this_part.append(j+1)         
                ret.append(atom_in_this_part)                 
            def cmp_mol( x, y ) :                             
                num_x = len( x )                              
                num_y = len( y )                              
                if (num_y == num_x) :                                       
                    heavy_atoms    = set( self.heavy_atoms() )              
                    num_heavy_in_x = len( set( x ) - heavy_atoms )
                    num_heavy_in_y = len( set( y ) - heavy_atoms )          
                    return num_heavy_in_y - num_heavy_in_x                  
                return num_y - num_x
            ret.sort( cmp = cmp_mol )                         
            return ret
Ejemplo n.º 3
0
def split_molecule_components(
        molecule: oechem.OEGraphMol) -> List[oechem.OEGraphMol]:
    """
    Split an OpenEye Molecule into its bonded components.
    Parameters
    ----------
    molecule: oechem.OEGraphMol
        An OpenEye molecule holding multiple components.
    Returns
    -------
    : list of oechem.OEGraphMol
        A list of OpenEye molecules holding the split components.
    """
    # determine bonded components
    number_of_components, part_list = oechem.OEDetermineComponents(molecule)
    predicate = oechem.OEPartPredAtom(part_list)

    # get bonded components
    components = []
    for i in range(number_of_components):
        predicate.SelectPart(i + 1)
        component = oechem.OEGraphMol()
        oechem.OESubsetMol(component, molecule, predicate)
        components.append(component)

    return components
Ejemplo n.º 4
0
def main(argv=[__name__]):
    if len(argv) != 3:
        oechem.OEThrow.Usage("%s <infile> <outfile>" % argv[0])

    ifs = oechem.oemolistream()
    if not ifs.open(argv[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % argv[1])

    ofs = oechem.oemolostream()
    if not ofs.open(argv[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % argv[2])

    for mol in ifs.GetOEGraphMols():
        numparts, partlist = oechem.OEDetermineComponents(mol)
        pred = oechem.OEPartPredAtom(partlist)

        for i in range(1, numparts + 1):
            pred.SelectPart(i)
            partmol = oechem.OEGraphMol()
            oechem.OESubsetMol(partmol, mol, pred)
            oechem.OEWriteMolecule(ofs, partmol)
Ejemplo n.º 5
0
def group_sub_by_type(substructures):
    from collections import defaultdict, OrderedDict
    from openeye import oechem
    groups = defaultdict(list)
    for smi in substructures:

        oemol = oechem.OEGraphMol()
        oechem.OESmilesToMol(oemol, smi)

        num_components, component_membership = oechem.OEDetermineComponents(
            oemol)
        num_rings = oemol.NumBonds() - oemol.NumAtoms() + num_components
        if num_rings == 0:
            groups[1].append(smi)  # aliphatic chains
        elif num_rings > 0:
            nraromsystems, parts = oechem.OEDetermineAromaticRingSystems(oemol)
            if nraromsystems == 0:
                groups[2].append(smi)  # aliphatic rings
            elif nraromsystems > 0:
                for atom in oemol.GetAtoms():
                    if parts[atom.GetIdx()] == 1:
                        size = oechem.OEAtomGetSmallestRingSize(atom)
                if size == 6:
                    groups[3].append(smi)  # 6-membered aromatic rings
                elif size == 5:
                    groups[4].append(smi)  # 5-membered aromatic rings
                else:
                    print(f'not included in any group, {smi}')
            else:
                print(f'not included in any group, {smi}')

    for rx, lst in groups.items():
        groups[rx] = sorted(lst)
    groups = OrderedDict(sorted(groups.items()))
    print(
        f'1. Acyclic aliphatic: {len(groups[1])}, 2. aliphatic rings: {len(groups[2])}, 3. 6-membered aromatic rings:{len(groups[3])}, 4. 5-membered aromatic rings:{len(groups[4])}'
    )
    return groups
Ejemplo n.º 6
0
def check_frag_complexity(frag_smi,
                          filter_type=2,
                          check_n_rings=True,
                          filter_ortho=True):
    from openeye import oechem
    oemol = oechem.OEGraphMol()
    oechem.OESmilesToMol(oemol, frag_smi)
    nrots = oechem.OECount(oemol, oechem.OEIsRotor())
    # print(f'{frag_smi}: {nrots}')
    num_components, component_membership = oechem.OEDetermineComponents(oemol)
    num_rings = oemol.NumBonds() - oemol.NumAtoms() + num_components
    if filter_type == 1:
        if nrots > 0:
            return True, f' nrot: {nrots}'
        else:
            if check_n_rings and num_rings > 1:
                return True, f' nrings: {num_rings}'
            else:
                if filter_ortho and find_ortho_substituents(frag_smi):
                    return True, f'ortho substituent exists.'
                else:
                    return False, 'pass'
    elif filter_type == 2:
        if nrots > 1:
            return True, f' nrot: {nrots}'
        else:  # nrot = 0 or 1
            if check_n_rings and num_rings > 1:
                return True, f' nrings: {num_rings}'
            # remain 1ring with nrot 0 or 1/ chain with nrot 0 or 1
            elif check_n_rings and num_rings == 1 and nrots == 1:
                return True, f' nrings: {num_rings}, nrots: {nrots}'
            else:
                if filter_ortho and find_ortho_substituents(frag_smi):
                    return True, f'ortho substituent exists.'
                else:
                    return False, 'pass'
def PrepareReceptor(pdb,padding=4,outpath=""):
    """
    Prepares a receptor from a pdb with a crystalized ligand
    Padding controls the docking region.
    If outpath is given, PrepareReceptor will write an openeye binary (oeb) of the receptor structure. This will be faster than rebuilding the receptor every time.
    """
    print("STOP CALLING THIS FUNCTION")
    exit()
    com = oechem.OEGraphMol()
    ifs = oechem.oemolistream()
    if ifs.open(pdb):
        oechem.OEReadPDBFile(ifs, com)
        ifs.close()

    """
    Sorry, this requires some explanation. Openeye wasn't recognizing the previously docked ligand, so I tried to find other ways.
    The next blocks of code take our system and split it based on its connected components, for which its REQUIRED that our protein
      only has a single chain. It assumes that the last component is the ligand. It then creates the ligand (lig) and protein (prot)
      as separate molecules. Next, it finds the minimum and maximum 3D coordinates of the current ligand and produces a box around
      it with the specified padding. Finally it uses this box to create a 'receptor' object into which ligands can be docked.
    Only the receptor is returned.
    Openeye's docking shouldn't be this involved, but I couldn't get it to run the typical 'hybrid' docking without error.
    """
    oechem.OEDetermineConnectivity(com)
    nparts, connect = oechem.OEDetermineComponents(com)
    if(nparts != 2):
        print("ERR in dock_conf::prepareReceptor. PDB doesn't have 2 connected components")
        exit()
        ## TODO: What is a good way to catch errors?
    # Get apo
    pred = oechem.OEPartPredAtom(connect)
    pred.SelectPart(nparts)
    lig = oechem.OEGraphMol()
    oechem.OESubsetMol(lig, com, pred)
    print(lig)
    
    # Get protein
    pred = oechem.OEPartPredAtom(connect)
    pred.SelectPart(1)
    prot = oechem.OEGraphMol()
    oechem.OESubsetMol(prot, com, pred)
    
    # Get box dimensions by iterating over ligand
    x_min = y_min = z_min = float('inf')
    x_max = y_max = z_max = -float('inf')
    crd = lig.GetCoords()
    print("CRD", crd)
    for atm in crd:
        x,y,z = crd[atm]
        if x < x_min:
            x_min = x
        if y < y_min:
            y_min = y
        if z < z_min:
            z_min = z
        if x > x_max:
            x_max = x
        if y > y_max:
            y_max = y
        if z > z_max:
            z_max = z
    x_min -= padding
    y_min -= padding
    z_min -= padding
    x_max += padding
    y_max += padding
    z_max += padding
    print(x_min,y_min,z_max, y_max)
    # Now prepare the receptor
    receptor = oechem.OEGraphMol()
    box = oedocking.OEBox()
    box.Setup(x_max, y_max, z_max, x_min, y_min, z_min)
    oedocking.OEMakeReceptor(receptor, prot, box)
    
    if not outpath == "":
        oedocking.OEWriteReceptorFile(receptor,f'{outpath}/receptor.oeb')
    return receptor
Ejemplo n.º 8
0
def determine_connected_components(smiles):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol, smiles)
    count, parts = oechem.OEDetermineComponents(mol)
    return count
def MoleculeParts(mol):
    count, parts = oechem.OEDetermineComponents(mol)

    print("The molecule has %d components" % count)
    for atom in mol.GetAtoms():
        print("atom %d is in part %d" % (atom.GetIdx(), parts[atom.GetIdx()]))