def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    oemolprop.OEConfigureFilterParams(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    iname = itf.GetString("-in")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ftype = oemolprop.OEGetFilterType(itf)
    filt = oemolprop.OEFilter(ftype)

    ver = itf.GetInt("-verbose")
    oechem.OEThrow.SetLevel(ver)

    ostr = oechem.oeosstream()
    pwnd = False
    filt.SetTable(ostr, pwnd)

    headers = ostr.str().split(b'\t')
    ostr.clear()  # remove the header row from the stream

    for mol in ifs.GetOEGraphMols():
        filt(mol)

        fields = ostr.str().decode("UTF-8").split('\t')
        ostr.clear()  # remove this row from the stream

        tmpdct = dict(zip(headers, fields))
        print(mol.GetTitle(), tmpdct[b"Lipinski violations"])
Esempio n. 2
0
def filter_smiles(smis):
    '''
    :param smis: list of smiles
    :return: (oe graph mols, smiles)
    '''
    ims = oechem.oemolistream()
    ims.SetFormat(oechem.OEFormat_SMI)
    smiles = "\n".join(list(smis))
    ims.openstring(smiles)

    oms = oechem.oemolostream()
    oms.SetFormat(oechem.OEFormat_SMI)
    oms.openstring()

    filt = oemolprop.OEFilter(oemolprop.OEFilterType_BlockBuster)

    goods = []
    counter, good = 0, 0
    for i, mol in enumerate(ims.GetOEGraphMols()):
        counter += 1
        if filt(mol):
            oechem.OEWriteMolecule(oms, mol)
            goods.append(i)
            good += 1
    print("FILTERD", counter, "ACCEPTED", good)
    actions = str(oms.GetString().decode("utf-8"))
    actions = actions.split("\n")

    oms.close()
    ims.close()
    return [smis[i] for i in goods], actions
Esempio n. 3
0
def from_smiles(in_smiles, outfile):
    '''

    :param in_smiles: a list of smile strings
    :param outfile:
    :return:
    '''
    in_smiles = "\n".join(in_smiles)

    ims = oechem.oemolistream()
    ims.SetFormat(oechem.OEFormat_SMI)
    ims.openstring(in_smiles)

    ofs = oechem.oemolostream()
    ofs.SetFormat(oechem.OEFormat_OEB)
    filt = oemolprop.OEFilter(oemolprop.OEFilterType_BlockBuster)

    if not ofs.open(outfile):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % outfile)

    for mol in ims.GetOEMols():
        if filt(mol):
            result = gen_conf(mol)
            for res in result:
                oechem.OEWriteMolecule(ofs, res)

    ofs.close()
    return 0
Esempio n. 4
0
def from_single_smiles(in_smiles, outfile):
    mol = oechem.OEMol()
    oechem.OESmilesToMol(mol, in_smiles)

    ofs = oechem.oemolostream()
    ofs.SetFormat(oechem.OEFormat_OEB)
    if not ofs.open(outfile):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % outfile)
    filt = oemolprop.OEFilter(oemolprop.OEFilterType_BlockBuster)
    if filt(mol):
        result = gen_conf(mol)
        for res in result:
            oechem.OEWriteMolecule(ofs, res)

    ofs.close()
    return 0
Esempio n. 5
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    oemolprop.OEConfigureFilterParams(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ftype = oemolprop.OEGetFilterType(itf)
    filt = oemolprop.OEFilter(ftype)

    ver = itf.GetInt("-verbose")
    oechem.OEThrow.SetLevel(ver)

    oemolprop.OEWritePropertyDataToCSV(oname, ifs, filt)
Esempio n. 6
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    oemolprop.OEConfigureFilterParams(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ofs = oechem.oemolostream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot create output file!")

    fmt = ofs.GetFormat()
    if fmt not in [
            oechem.OEFormat_SDF, oechem.OEFormat_OEB, oechem.OEFormat_CSV
    ]:
        oechem.OEThrow.Fatal("Only SD, OEB, and CSV formats preserve SD data")

    ftype = oemolprop.OEGetFilterType(itf)
    filt = oemolprop.OEFilter(ftype)

    ver = itf.GetInt("-verbose")
    oechem.OEThrow.SetLevel(ver)

    pwnd = False
    filt.SetTable(oechem.oenul, pwnd)
    filt.SetSDTag(True)

    for mol in ifs.GetOEGraphMols():
        filt(mol)
        oechem.OEWriteMolecule(ofs, mol)
Esempio n. 7
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData)
    oemolprop.OEConfigureFilterParams(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        oechem.OEThrow.Fatal("Unable to interpret command line!")

    iname = itf.GetString("-in")
    oname = itf.GetString("-out")

    ifs = oechem.oemolistream()
    if not ifs.open(iname):
        oechem.OEThrow.Fatal("Cannot open input file!")

    ofs = oechem.oemolostream()
    if not ofs.open(oname):
        oechem.OEThrow.Fatal("Cannot create output file!")

    ftype = oemolprop.OEGetFilterType(itf)
    filt = oemolprop.OEFilter(ftype)

    for mol in ifs.GetOEGraphMols():
        if filt(mol):
            oechem.OEWriteMolecule(ofs, mol)
Esempio n. 8
0
def compute_conformers(smiles=None, smiles_file=None, start_index=0, batch_size=0, out_file=None, bad_file=None, save_csv=False,  overwrite=False, save_gzip=False, license=None, timeout=0, max_failures=2):
    import csv
    import os
    from openeye import oechem
    from openeye import oeomega
    from openeye import oemolprop
    import signal

    os.environ['OE_LICENSE'] = license    
    
    if save_gzip or save_csv: 
        raise Exception("GZip and CSV not supported")
 
    if not overwrite and  os.path.exists(out_file):
        raise Exception("File exists: %s" % out_file)

    if smiles_file: 
        with open(smiles_file) as current:
            current.seek(start_index)
            smiles = [current.readline() for i in range(batch_size)]
    
    if len(smiles) == 0: 
        return ""

    # function to compute enantiomers
    # separated out so we can use an alarm to timeout
    def get_enan(omega, enan):
        enan = oechem.OEMol(enan)
        ret = omega.Build(enan)
        return enan, ret


    def alarm_handler(signum, frame):
        #print("ALARM signal received")
        raise Exception()

    #ofs = oechem.oemolostream()
    #ofs.SetFormat(oechem.OEFormat_OEB)
    #if not ofs.open(out_file):
    #    oechem.OEThrow.Fatal("Unable to open %s for writing" % out_file)

    sep = ","
    bad = []
    mols = []
    for s in smiles:
        mol = s.split(sep)
        if len(mol) > 1: 
            mols.append(mol[2].rstrip())

    # put all mols in a string as we're told it is faster to process this way
    in_smiles = "\n".join(mols)

    ims = oechem.oemolistream()
    ims.SetFormat(oechem.OEFormat_SMI)
    ims.openstring(in_smiles)

    # Turn off logging except errors
    oechem.OEThrow.SetLevel(5)

    filt = oemolprop.OEFilter(oemolprop.OEFilterType_BlockBuster)
    #ofs.open(out_file)
    signal.signal(signal.SIGALRM, alarm_handler)
    oe_results = []
    for mol in ims.GetOEMols():
        if filt(mol):
            oemols = []
            ret_code = None
            omegaOpts = oeomega.OEOmegaOptions(oeomega.OEOmegaSampling_FastROCS)
            omega = oeomega.OEOmega(omegaOpts)
            
            failures = 0
            for enantiomer in oeomega.OEFlipper(mol.GetActive(), 6, True):
                if max_failures > 0 and failures >= max_failures: 
                    break
                if len(oemols) >= 10:
                    break

                ret_code = None
                error = False
                signal.alarm(timeout)
                try: 
                    enantiomer, ret_code = get_enan(omega, enantiomer)
                except:
                    print("Timeout %s" % out_file) 
                    failures += 1
                    error = True
                signal.alarm(0)

                if not error and ret_code == oeomega.OEOmegaReturnCode_Success:
                    halfMol = oechem.OEMol(mol, oechem.OEMCMolType_HalfFloatCartesian)
                    oemols.append(halfMol)
                #else:
                    #oechem.OEThrow.Warning("%s: %s" %
                    #    (enantiomer.GetTitle(), oeomega.OEGetOmegaError(ret_code)))
                oe_results.append(oemols)

    ofs = oechem.oemolostream()
    ofs.SetFormat(oechem.OEFormat_OEB)
    ofs.open(out_file)
    for r in oe_results: 
        for res in r:
            oechem.OEWriteMolecule(ofs, res)

    ofs.close()
 
    return out_file
Esempio n. 9
0
#!/usr/bin/env python
"""
Extract SMILES from SMIRNOFF_sub3rot.tar.gz to generate input.smi
"""

from openeye import oechem
from openeye import oemolprop
import gzip

filterfile = oechem.oeifstream('oechem-filterfile')
filter = oemolprop.OEFilter(filterfile)

ifs = oechem.oemolistream('nci-250k.smi.gz')
ofs = oechem.oemolostream('input.smi')
for mol in ifs.GetOEMols():
    if filter(mol):
        smiles = oechem.OEMolToSmiles(mol)
        oechem.OEWriteMolecule(ofs, mol)

ifs.close()
ofs.close()
Esempio n. 10
0
def compute_druggables(smiles=None,
                       smiles_file=None,
                       start_index=0,
                       batch_size=0,
                       out_file=None,
                       bad_file=None,
                       save_csv=False,
                       overwrite=False,
                       save_gzip=False,
                       license=None,
                       timeout=0,
                       max_failures=2):
    import csv
    import os
    from openeye import oechem
    from openeye import oeomega
    from openeye import oemolprop
    import signal

    os.environ['OE_LICENSE'] = license

    if save_gzip or not save_csv:
        raise Exception("GZip and PKL not supported")

    if not overwrite and os.path.exists(out_file):
        raise Exception("File exists: %s" % out_file)

    if smiles_file:
        with open(smiles_file) as current:
            current.seek(start_index)
            smiles = [current.readline() for i in range(batch_size)]

    if len(smiles) == 0:
        return ""

    sep = ","
    mols = []
    full_mols = []
    for s in smiles:
        mol = s.split(sep)
        if len(mol) > 1:
            mols.append(mol[2].rstrip())
            full_mols.append(mol)

    # put all mols in a string as we're told it is faster to process this way
    in_smiles = "\n".join(mols)

    ims = oechem.oemolistream()
    ims.SetFormat(oechem.OEFormat_SMI)
    ims.openstring(in_smiles)

    # Turn off logging except errors
    oechem.OEThrow.SetLevel(5)

    filt = oemolprop.OEFilter(oemolprop.OEFilterType_BlockBuster)

    bad = []
    results = []
    for (m, mol) in zip(ims.GetOEMols(), full_mols):
        if len(mol) > 1:
            results.append((mol[0], mol[1], filt(m)))

    with open(out_file, 'w') as output_file:
        writer = csv.writer(output_file, delimiter=',')
        writer.writerows(results)

    return out_file