def main(argv=(__name__)):
    """
    the protein should have charges and radii but the ligand need not
    """
    itf = oechem.OEInterface()

    if not oechem.OEConfigure(itf, InterfaceData):
        oechem.OEThrow.Fatal("Problem configuring OEInterface!")

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

    ligFile = itf.GetString("-l")
    ims = oechem.oemolistream()
    if not ims.open(ligFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile)
    lig = oechem.OEGraphMol()
    oechem.OEReadMolecule(ims, lig)

    contextFile = itf.GetString("-p")
    ims = oechem.oemolistream()
    if not ims.open(contextFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile)
    prot = oechem.OEGraphMol()
    oechem.OEReadMolecule(ims, prot)

    highRes = itf.GetBool("-high_res")
    GetSzmapEnergies(lig, prot, highRes)
Example #2
0
def main(argv=[__name__]):
    # import configuration file
    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    # add configuration for image size and display options
    oedepict.OEConfigureImageOptions(itf)
    oedepict.OEConfigure2DMolDisplayOptions(itf)

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

    ifname = itf.GetString("-in")
    ofname = itf.GetString("-out")

    ifs = oechem.oemolistream(ifname)
    mol = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, mol)
    oedepict.OEPrepareDepiction(mol)

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    opts = oedepict.OE2DMolDisplayOptions(width, height, oedepict.OEScale_AutoScale)
    # set up display options from command line parameters
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    disp = oedepict.OE2DMolDisplay(mol, opts)
    oedepict.OERenderMolecule(ofname, disp)
def main(argv=(__name__)):
    """
    the protein should have charges and radii but the ligand need not
    """
    itf = oechem.OEInterface()

    if not oechem.OEConfigure(itf, InterfaceData):
        oechem.OEThrow.Fatal("Problem configuring OEInterface!")

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

    ligFile = itf.GetString("-l")
    ims = oechem.oemolistream()
    if not ims.open(ligFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % ligFile)
    lig = oechem.OEGraphMol()
    oechem.OEReadMolecule(ims, lig)

    contextFile = itf.GetString("-p")
    ims = oechem.oemolistream()
    if not ims.open(contextFile):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % contextFile)
    prot = oechem.OEGraphMol()
    oechem.OEReadMolecule(ims, prot)

    outputFile = itf.GetString("-o")
    oms = oechem.oemolostream()
    if not oms.open(outputFile):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % outputFile)

    GenerateSzmapProbes(oms, itf.GetDouble("-prob"), lig, prot)
Example #4
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 400.0)
    oedepict.OEConfigureImageHeight(itf, 400.0)
    oedepict.OEConfigureImageGridParams(itf)
    oedepict.OEConfigurePrepareDepictionOptions(itf)
    oedepict.OEConfigure2DMolDisplayOptions(itf)

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

    oname = itf.GetString("-out")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

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

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    rows = oedepict.OEGetImageGridNumRows(itf)
    cols = oedepict.OEGetImageGridNumColumns(itf)
    grid = oedepict.OEImageGrid(image, rows, cols)

    popts = oedepict.OEPrepareDepictionOptions()
    oedepict.OESetupPrepareDepictionOptions(popts, itf)

    dopts = oedepict.OE2DMolDisplayOptions()
    oedepict.OESetup2DMolDisplayOptions(dopts, itf)
    dopts.SetDimensions(grid.GetCellWidth(), grid.GetCellHeight(),
                        oedepict.OEScale_AutoScale)

    celliter = grid.GetCells()
    for iname in itf.GetStringList("-in"):
        ifs = oechem.oemolistream()
        if not ifs.open(iname):
            oechem.OEThrow.Warning("Cannot open %s input file!" % iname)
            continue

        for mol in ifs.GetOEGraphMols():
            if not celliter.IsValid():
                break

            oedepict.OEPrepareDepiction(mol, popts)
            disp = oedepict.OE2DMolDisplay(mol, dopts)
            oedepict.OERenderMolecule(celliter.Target(), disp)
            celliter.Next()

    oedepict.OEWriteImage(ofs, ext, image)

    return 0
Example #5
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oegraphsim.OEConfigureFingerPrint(
        itf, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    ifname = itf.GetString("-in")
    ffname = itf.GetString("-fpdb")

    if oechem.OEGetFileExtension(ffname) != "fpbin":
        oechem.OEThrow.Fatal(
            "Fingerprint database file should have '.fpbin' file extension!")

    idxfname = oechem.OEGetMolDatabaseIdxFileName(ifname)

    if not os.path.exists(idxfname):
        if not oechem.OECreateMolDatabaseIdx(ifname):
            oechem.OEThrow.Warning("Unable to create %s molecule index file" %
                                   idxfname)

    oechem.OEThrow.Info("Using %s index molecule file" % idxfname)

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(ifname):
        oechem.OEThrow.Fatal("Cannot open molecule database file!")

    nrmols = moldb.GetMaxMolIdx()

    fptype = oegraphsim.OESetupFingerPrint(itf)
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())

    opts = oegraphsim.OECreateFastFPDatabaseOptions(fptype)
    opts.SetTracer(oechem.OEDots(100000, 1000, "fingerprints"))
    oechem.OEThrow.Info("Generating fingerprints with %d threads" %
                        opts.GetNumProcessors())

    timer = oechem.OEWallTimer()
    if not oegraphsim.OECreateFastFPDatabaseFile(ffname, ifname, opts):
        oechem.OEThrow.Fatal("Cannot create fingerprint database file!")

    oechem.OEThrow.Info("%5.2f secs to generate %d fingerprints" %
                        (timer.Elapsed(), nrmols))

    return 0
Example #6
0
def SetupInterface(argv, itf):
    oechem.OEConfigure(itf, InterfaceData)
    if oechem.OECheckHelp(itf, argv):
        return False
    if not oechem.OEParseCommandLine(itf, argv):
        return False
    infile = itf.GetString("-in")
    if not oechem.OEIsReadable(
            oechem.OEGetFileType(oechem.OEGetFileExtension(infile))):
        oechem.OEThrow.Warning("%s is not a readable input file" % infile)
        return False
    outfile = itf.GetString("-out")
    if not oegrid.OEIsWriteableGrid(
            oegrid.OEGetGridFileType(oechem.OEGetFileExtension(outfile))):
        oechem.OEThrow.Warning("%s is not a writable grid file" % outfile)
        return False
    return True
Example #7
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)

    defopts = oegraphsim.OEFPDatabaseOptions(10,
                                             oegraphsim.OESimMeasure_Tanimoto)
    oegraphsim.OEConfigureFPDatabaseOptions(itf, defopts)
    oegraphsim.OEConfigureFPDatabaseMemoryType(itf)

    if not oechem.OEParseCommandLine(itf, argv):
        return 0

    qfname = itf.GetString("-query")
    mfname = itf.GetString("-molfname")
    ffname = itf.GetString("-fpdbfname")
    ofname = itf.GetString("-out")

    # initialize databases

    timer = oechem.OEWallTimer()
    timer.Start()

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

    query = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, query):
        oechem.OEThrow.Fatal("Cannot read query molecule!")

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(mfname):
        oechem.OEThrow.Fatal("Cannot open molecule database!")

    memtype = oegraphsim.OEGetFPDatabaseMemoryType(itf)

    fpdb = oegraphsim.OEFastFPDatabase(ffname, memtype)
    if not fpdb.IsValid():
        oechem.OEThrow.Fatal("Cannot open fingerprint database!")
    nrfps = fpdb.NumFingerPrints()
    memtypestr = fpdb.GetMemoryTypeString()

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

    if not oegraphsim.OEAreCompatibleDatabases(moldb, fpdb):
        oechem.OEThrow.Fatal("Databases are not compatible!")

    oechem.OEThrow.Info("%5.2f sec to initialize databases" % timer.Elapsed())

    fptype = fpdb.GetFPTypeBase()
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())

    opts = oegraphsim.OEFPDatabaseOptions()
    oegraphsim.OESetupFPDatabaseOptions(opts, itf)

    # search fingerprint database

    timer.Start()
    scores = fpdb.GetSortedScores(query, opts)
    oechem.OEThrow.Info("%5.2f sec to search %d fingerprints %s" %
                        (timer.Elapsed(), nrfps, memtypestr))

    timer.Start()
    nrhits = 0
    hit = oechem.OEGraphMol()
    for si in scores:
        if moldb.GetMolecule(hit, si.GetIdx()):
            nrhits += 1
            oechem.OESetSDData(hit, "Similarity score", "%.2f" % si.GetScore())
            oechem.OEWriteMolecule(ofs, hit)
    oechem.OEThrow.Info("%5.2f sec to write %d hits" %
                        (timer.Elapsed(), nrhits))

    return 0
Example #8
0
!END
!PARAMETER -i
  !TYPE int
  !BRIEF An integer parameter
!END
!PARAMETER -f
  !TYPE float
  !BRIEF A float parameter
!END
!PARAMETER -str
  !TYPE string
  !BRIEF A string parameter
!END
"""

# @ <SNIPPET-OEINTERFACE-CONVENIENCE>
itf = oechem.OEInterface()

if not oechem.OEConfigure(itf, InterfaceData):
    oechem.OEThrow.Fatal("Problem configuring OEInterface!")

if not oechem.OEParseCommandLine(itf, sys.argv):
    oechem.OEThrow.Fatal("Unable to parse command line")
# @ </SNIPPET-OEINTERFACE-CONVENIENCE>

print("-b =", itf.GetBool("-b"))
print("-i =", itf.GetInt("-i"))
print("-f =", itf.GetFloat("-f"))
print("-str =", itf.GetString("-str"))
# @ </SNIPPET>
Example #9
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(
        itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

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

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

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

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

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not asite.IsValid():
        oechem.OEThrow.Fatal("Cannot initialize active site!")
    asite.SetTitle(ligand.GetTitle())

    oechem.OEPerceiveInteractionHints(asite)

    oegrapheme.OEPrepareActiveSiteDepiction(asite)

    # Depict active site with interactions

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    cframe = oedepict.OEImageFrame(image, width * 0.80, height,
                                   oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, width * 0.20, height,
                                   oedepict.OE2DPoint(width * 0.80, 0.0))

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cframe.GetWidth(),
                                                   cframe.GetHeight())
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    adisp = oegrapheme.OE2DActiveSiteDisplay(asite, opts)
    oegrapheme.OERenderActiveSite(cframe, adisp)

    lopts = oegrapheme.OE2DActiveSiteLegendDisplayOptions(10, 1)
    oegrapheme.OEDrawActiveSiteLegend(lframe, adisp, lopts)

    oedepict.OEWriteImage(oname, image)

    return 0
Example #10
0
def main(argv=[__name__]):
    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, Interface)
    OEAddParameterColors(itf, "-atom_contribution_positive_color")
    OEAddParameterColors(itf, "-atom_contribution_negative_color")
    OEAddParameterColors(itf, "-classification_colors")
    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    # Figure out output file name
    outFile = OEGetFilename(itf, "-molecule_file")
    reportFile = OEGetFilename(itf, "-report_file")
    failTrainFile = OEGetFilename(itf, "-training_fail_file")
    failKrigeFile = OEGetFilename(itf, "-prediction_fail_file")
    settingsFile = OEGetFilename(itf, "-settings_file")

    # Write the settings file and splash to screen
    oechem.OEWriteSettings(itf, oechem.oeout, False)
    ofs = oechem.oeofstream(settingsFile)
    oechem.OEWriteSettings(itf, ofs, True)
    ofs.close()

    # Setup report options
    rOpts = oestats.OEKrigeReportOptions()
    if itf.HasString("-report_title"):
        rOpts.SetTitle(itf.GetString("-report_title"))
    if itf.HasString("-response_name"):
        rOpts.SetResponseName(itf.GetString("-response_name"))
        responseName = itf.GetString("-response_name")
    else:
        rOpts.SetResponseName(itf.GetString("-response_tag"))
        responseName = itf.GetString("-response_tag")
    if itf.HasString("-atom_contribution_negative_color"):
        color = OETextToColor(
            itf.GetString("-atom_contribution_negative_color"))
        rOpts.SetContributionNegativeColor(color)
    if itf.HasString("-atom_contribution_positive_color"):
        color = OETextToColor(
            itf.GetString("-atom_contribution_positive_color"))
        rOpts.SetContributionPositiveColor(color)
    iExtra = 0
    while itf.HasString("-report_tagged_data", iExtra):
        rOpts.PushSDProperty(itf.GetString("-report_tagged_data", iExtra))
        iExtra += 1
    iClass = 0
    while itf.HasDouble("-classification_boundries", iClass):
        boundry = itf.GetDouble("-classification_boundries", iClass)
        if itf.GetBool("-krige_log"):
            boundry = log10(boundry)
        rOpts.PushClassificationBoundry(boundry)
        iClass += 1
    iClass = 0
    while itf.HasString("-classification_colors", iClass):
        color = OETextToColor(itf.GetString("-classification_colors", iClass))
        rOpts.PushClassificationColor(color)
        iClass += 1
    if itf.GetBool("-hide_krige_details"):
        rOpts.SetShowKrigeDetails(False)
    else:
        rOpts.SetShowKrigeDetails(True)
    rOpts.SetUnlog(itf.GetBool("-krige_log"))
    rOpts.SetShowConfidence(itf.GetBool("-show_response_confidence"))
    rOpts.SetResponseSignificantFigures(
        itf.GetUnsignedInt("-report_significant_figures"))
    if itf.HasString("-atom_contribution_positive_label"):
        rOpts.SetContributionPositiveLabel(
            itf.GetString("-atom_contribution_positive_label"))
    if itf.HasString("-atom_contribution_negative_label"):
        rOpts.SetContributionNegativeLabel(
            itf.GetString("-atom_contribution_negative_label"))
    if itf.HasDouble("-atom_contribution_baseline_response"):
        baseline = itf.GetDouble("-atom_contribution_baseline_response")
        if itf.GetBool("-krige_log"):
            baseline = log10(baseline)
            rOpts.SetContributionBaseline(baseline)

    # Figure out the trend properties for universal kriging if we have them
    universalProps = oechem.OEMolPropertyList()
    iProp = 0
    while itf.HasString("-universal_prop", iProp):
        propStr = itf.GetString("-universal_prop", iProp)
        if propStr == "mw":
            universalProps.Add(oestats.OEMolecularWeightPropertyFxn())
            rOpts.PushProperty(oestats.OEMolecularWeightPropertyFxn(),
                               "Molecular Weight")
        else:
            oechem.OEThrow.Error(
                "Unknow property (%s) passed to -universal_prop" % propStr)
        iProp += 1

    # Setup the object for getting the response from the training molecules
    responseFxn = oechem.OEMolTaggedPropertyFxn(itf.GetString("-response_tag"))
    if itf.GetBool("-krige_log"):
        responseFxn = oestats.OEMolLog10PropertyFxn(responseFxn)

    # Construct the krige
    if itf.HasUnsignedInt("-local_krige"):
        opts = oestats.OELocalKrigeOptions()
        opts.SetNumLocal(itf.GetUnsignedInt("-local_krige"))
    else:
        opts = oestats.OEGlobalKrigeOptions()

    # Set if the distance function is stereo aware
    distOpts = oestats.OEDefaultKrigeDistanceOptions()
    distOpts.SetStereoAware(not itf.GetBool("-ignore_stereo"))

    krige = oestats.OEMolKrige(distOpts, universalProps, opts)

    # Add the training molecules to the Krige
    print("Reading in training molecules")
    sw = oechem.OEStopwatch()
    failStr = None
    numTrain = 0
    numTrainFail = 0
    numTrainUnmeasured = 0
    numTrainMeasured = 0
    for trainFile in itf.GetStringList("-train"):
        imstr = oechem.oemolistream(trainFile)
        for mol in imstr.GetOEMols():
            success = False
            # measured = True
            if responseFxn.Has(mol):
                response = responseFxn.Get(mol)
                if OEIsUnmeasured(itf, response):
                    numTrainUnmeasured += 1
                    # measured = False
                    success = krige.AddUnmeasuredTraining(mol, response)
                else:
                    numTrainMeasured += 1
                    success = krige.AddTraining(mol, response)
                numTrain += 1
            if not success:
                numTrainFail += 1
                if failStr is None:
                    failStr = oechem.oemolostream(failTrainFile)
                oechem.OEWriteMolecule(failStr, mol)
            if sw.Elapsed() > 10.0:
                sw.Start()
                if numTrainFail != 0:
                    print("So far added %d training molecules, and of those \
                          %d unmeasured are unmeasured.  "
                          "%d input molecules are missing response data or \
                          universal krige properties." %
                          (numTrain, numTrainUnmeasured, numTrainFail))
                else:
                    print("So far added %d training molecules, and of those \
                          %d unmeasured are unmeasured." %
                          (numTrain, numTrainUnmeasured))
        imstr.close()
    if failStr is not None:
        failStr.close()
        print("Training failed molecules written to %s" % failTrainFile)
    if numTrainFail != 0:
        print(
            "Added %d training molecules, and of those %d unmeasured are unmeasured.  "
            "%d input molecules are missing response data or universal krige properties."
            % (numTrain, numTrainUnmeasured, numTrainFail))
    else:
        print(
            "Added %d training molecules, and of those %d unmeasured are unmeasured."
            % (numTrain, numTrainUnmeasured))

    # Train the Krige on the molecules we added
    print("Training krige model")
    if krige.Train():
        print("Training successful")
    else:
        print("Training failed, aborting")
        return

    # Krige for MW of the test molecules, and compare to actual MW
    krigeTag = "Krige(%s)" % responseName
    upperTag = "Krige(%s) 95%% confidence upper" % responseName
    lowerTag = "Krige(%s) 95%% confidence lower" % responseName

    print("Predicting %s of input molecules" % responseName)
    numKrige = 0
    numKrigeFail = 0
    outstr = oechem.oemolostream(outFile)
    multi = oedepict.OEMultiPageImageFile(oedepict.OEPageOrientation_Landscape,
                                          oedepict.OEPageSize_US_Letter)
    failStr = None
    sw.Start()
    for molFile in itf.GetStringList("-in"):
        imstr = oechem.oemolistream(molFile)
        for mol in imstr.GetOEMols():
            result = krige.GetResult(mol)
            success = True
            if result.Valid():
                response = result.GetResponse()
                conf95 = 1.96 * sqrt(result.GetVariance())
                upper95 = response + conf95
                lower95 = response - conf95
                if itf.GetBool("-krige_log"):
                    response = pow(10.0, response)
                    upper95 = pow(10.0, upper95)
                    lower95 = pow(10.0, lower95)
                oechem.OESetSDData(mol, krigeTag, str(response))
                oechem.OESetSDData(mol, upperTag, str(upper95))
                oechem.OESetSDData(mol, lowerTag, str(lower95))
                if not itf.GetBool("-no_report"):
                    oestats.OEKrigeRenderReport(multi.NewPage(), result, mol,
                                                rOpts)
                oechem.OEWriteMolecule(outstr, mol)
            else:
                success = False
            numKrige += 1
            if not success:
                numKrigeFail += 1
                failStr = oechem.oemolostream(failKrigeFile)
                oechem.OEWriteMolecule(failStr, mol)
            if sw.Elapsed() > 10.0:
                print("Kriging predicted %d molecules (%d failures) so far" %
                      (numKrige, numKrigeFail))
                sw.Start()
        imstr.close()
    outstr.close()
    if failStr is not None:
        failStr.close()
    print("Kriging predicted %d molecules (%d failures)" %
          (numKrige, numKrigeFail))

    if not itf.GetBool("-no_report"):
        print("Writing report to %s" % reportFile)
        oedepict.OEWriteMultiPageImage(reportFile, multi)
    print("Finished")

    return 0
Example #11
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)

    defopts = oegraphsim.OEFPDatabaseOptions(10,
                                             oegraphsim.OESimMeasure_Tanimoto)
    oegraphsim.OEConfigureFPDatabaseOptions(itf, defopts)
    oegraphsim.OEConfigureFingerPrint(
        itf, oegraphsim.OEGetFPType(oegraphsim.OEFPType_Tree))

    if not oechem.OEParseCommandLine(itf, argv):
        return 0

    qfname = itf.GetString("-query")
    mfname = itf.GetString("-molfname")
    ofname = itf.GetString("-out")

    # initialize databases

    timer = oechem.OEWallTimer()
    timer.Start()

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

    query = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, query):
        oechem.OEThrow.Fatal("Cannot read query molecule!")

    moldb = oechem.OEMolDatabase()
    if not moldb.Open(mfname):
        oechem.OEThrow.Fatal("Cannot open molecule database!")

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

    fptype = oegraphsim.OESetupFingerPrint(itf)
    oechem.OEThrow.Info("Using fingerprint type %s" % fptype.GetFPTypeString())
    fpdb = oegraphsim.OEFPDatabase(fptype)

    emptyfp = oegraphsim.OEFingerPrint()
    emptyfp.SetFPTypeBase(fptype)

    nrmols = moldb.GetMaxMolIdx()

    mol = oechem.OEGraphMol()
    for idx in range(0, nrmols):
        if moldb.GetMolecule(mol, idx):
            fpdb.AddFP(mol)
        else:
            fpdb.AddFP(emptyfp)

    nrfps = fpdb.NumFingerPrints()
    oechem.OEThrow.Info("%5.2f sec to initialize databases" % timer.Elapsed())

    opts = oegraphsim.OEFPDatabaseOptions()
    oegraphsim.OESetupFPDatabaseOptions(opts, itf)

    # search fingerprint database

    timer.Start()
    scores = fpdb.GetSortedScores(query, opts)
    oechem.OEThrow.Info("%5.2f sec to search %d fingerprints" %
                        (timer.Elapsed(), nrfps))

    timer.Start()
    hit = oechem.OEGraphMol()
    for si in scores:
        if moldb.GetMolecule(hit, si.GetIdx()):
            oechem.OEWriteMolecule(ofs, hit)
    oechem.OEThrow.Info("%5.2f sec to write %d hits" %
                        (timer.Elapsed(), opts.GetLimit()))

    return 0
Example #12
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 600.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

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

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

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

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

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Calculate average BFactor of the whole complex

    avgbfactor = GetAverageBFactor(complexmol)

    # Calculate minimum and maximum BFactor of the ligand and its environment

    minbfactor, maxbfactor = GetMinAndMaxBFactor(ligand, protein)

    # Attach to each ligand atom the average BFactor of the nearby protein atoms

    stag = "avg residue BFfactor"
    itag = oechem.OEGetTag(stag)
    SetAverageBFactorOfNearbyProteinAtoms(ligand, protein, itag)

    oechem.OEThrow.Info("Average BFactor of the complex = %+.3f" % avgbfactor)
    oechem.OEThrow.Info("Minimum BFactor of the ligand and its environment = %+.3f" % minbfactor)
    oechem.OEThrow.Info("Maximum BFactor of the ligand and its environment = %+.3f" % maxbfactor)

    # Create image

    imagewidth, imageheight = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(itf)
    image = oedepict.OEImage(imagewidth, imageheight)

    mframe = oedepict.OEImageFrame(image, imagewidth,
                                   imageheight * 0.90, oedepict.OE2DPoint(0.0, 0.0))
    lframe = oedepict.OEImageFrame(image, imagewidth, imageheight * 0.10,
                                   oedepict.OE2DPoint(0.0, imageheight * 0.90))

    opts = oedepict.OE2DMolDisplayOptions(mframe.GetWidth(), mframe.GetHeight(),
                                          oedepict.OEScale_AutoScale)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)
    opts.SetAtomColorStyle(oedepict.OEAtomColorStyle_WhiteMonochrome)

    # Create BFactor color gradient

    colorg = oechem.OELinearColorGradient()
    colorg.AddStop(oechem.OEColorStop(0.0, oechem.OEDarkBlue))
    colorg.AddStop(oechem.OEColorStop(10.0, oechem.OELightBlue))
    colorg.AddStop(oechem.OEColorStop(25.0, oechem.OEYellowTint))
    colorg.AddStop(oechem.OEColorStop(50.0, oechem.OERed))
    colorg.AddStop(oechem.OEColorStop(100.0, oechem.OEDarkRose))

    # Prepare ligand for depiction

    oegrapheme.OEPrepareDepictionFrom3D(ligand)
    arcfxn = BFactorArcFxn(colorg, itag)
    for atom in ligand.GetAtoms():
        oegrapheme.OESetSurfaceArcFxn(ligand, atom, arcfxn)
    opts.SetScale(oegrapheme.OEGetMoleculeSurfaceScale(ligand, opts))

    # Render ligand and visualize BFactor

    disp = oedepict.OE2DMolDisplay(ligand, opts)
    colorbfactor = ColorLigandAtomByBFactor(colorg)
    oegrapheme.OEAddGlyph(disp, colorbfactor, oechem.OEIsTrueAtom())
    oegrapheme.OEDraw2DSurface(disp)
    oedepict.OERenderMolecule(mframe, disp)

    # Draw color gradient

    opts = oegrapheme.OEColorGradientDisplayOptions()
    opts.SetColorStopPrecision(1)
    opts.AddMarkedValue(avgbfactor)
    opts.SetBoxRange(minbfactor, maxbfactor)

    oegrapheme.OEDrawColorGradient(lframe, colorg, opts)

    oedepict.OEWriteImage(oname, image)

    return 0
Example #13
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    iname = itf.GetString("-complex")

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

    complexmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, complexmol):
        oechem.OEThrow.Fatal("Unable to read molecule from %s" % iname)

    if not oechem.OEHasResidues(complexmol):
        oechem.OEPerceiveResidues(complexmol, oechem.OEPreserveResInfo_All)

    # Separate ligand and protein

    sopts = oechem.OESplitMolComplexOptions()
    oechem.OESetupSplitMolComplexOptions(sopts, itf)

    ligand = oechem.OEGraphMol()
    protein = oechem.OEGraphMol()
    water = oechem.OEGraphMol()
    other = oechem.OEGraphMol()

    pfilter = sopts.GetProteinFilter()
    wfilter = sopts.GetWaterFilter()
    sopts.SetProteinFilter(oechem.OEOrRoleSet(pfilter, wfilter))
    sopts.SetWaterFilter(
        oechem.OEMolComplexFilterFactory(
            oechem.OEMolComplexFilterCategory_Nothing))

    oechem.OESplitMolComplex(ligand, protein, water, other, complexmol, sopts)

    if ligand.NumAtoms() == 0:
        oechem.OEThrow.Fatal("Cannot separate complex!")

    # Perceive interactions

    asite = oechem.OEInteractionHintContainer(protein, ligand)
    if not oechem.OEIsValidActiveSite(asite):
        oechem.OEThrow.Fatal("Cannot initialize active site!")

    oechem.OEPerceiveInteractionHints(asite)

    print("Number of interactions:", asite.NumInteractions())
    for itype in oechem.OEGetActiveSiteInteractionHintTypes():
        numinters = asite.NumInteractions(
            oechem.OEHasInteractionHintType(itype))
        if numinters == 0:
            continue
        print("%d %s :" % (numinters, itype.GetName()))

        inters = [
            s for s in asite.GetInteractions(
                oechem.OEHasInteractionHintType(itype))
        ]
        print("\n".join(sorted(GetInteractionString(s) for s in inters)))

    print("\nResidue interactions:")
    for res in oechem.OEGetResidues(
            asite.GetMolecule(oechem.OEProteinInteractionHintComponent())):
        PrintResidueInteractions(asite, res)

    print("\nLigand atom interactions:")
    for atom in asite.GetMolecule(
            oechem.OELigandInteractionHintComponent()).GetAtoms():
        PrintLigandAtomInteractions(asite, atom)
Example #14
0
def main(argv=[__name__]):

    itf = oechem.OEInterface()
    oechem.OEConfigure(itf, InterfaceData)
    oedepict.OEConfigureImageWidth(itf, 900.0)
    oedepict.OEConfigureImageHeight(itf, 600.0)
    oedepict.OEConfigure2DMolDisplayOptions(
        itf, oedepict.OE2DMolDisplaySetup_AromaticStyle)
    oechem.OEConfigureSplitMolComplexOptions(
        itf, oechem.OESplitMolComplexSetup_LigName
        | oechem.OESplitMolComplexSetup_CovLig)

    if not oechem.OEParseCommandLine(itf, argv):
        return 1

    if itf.HasString("-complex") and (itf.HasString("-protein")
                                      or itf.HasString("-ligand")):
        oechem.OEThrow.Warning("Only complex in %s file fill be used!" %
                               itf.GetString("-complex"))

    if not (itf.HasString("-complex")) ^ (itf.HasString("-protein")
                                          and itf.HasString("-ligand")):
        oechem.OEThrow.Fatal(
            "Please specify either complex or ligand and protein input files!")

    oname = itf.GetString("-out")

    ext = oechem.OEGetFileExtension(oname)
    if not oedepict.OEIsRegisteredImageFile(ext):
        oechem.OEThrow.Fatal("Unknown image type!")

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

    # initialize protein and ligand

    protein = oechem.OEGraphMol()
    ligand = oechem.OEGraphMol()
    if not get_protein_and_ligands(protein, ligand, itf):
        oechem.OEThrow.Fatal("Cannot initialize protein and/or ligand!")

    # depict active site with interactions

    width, height = oedepict.OEGetImageWidth(itf), oedepict.OEGetImageHeight(
        itf)
    image = oedepict.OEImage(width, height)

    interactive_legend = False
    magnify_residue = 1.0

    if ext == 'svg':
        interactive_legend = itf.GetBool("-interactive-legend")
        magnify_residue = itf.GetFloat("-magnify-residue")

    cwidth, cheight = width, height
    if not interactive_legend:
        cwidth = cwidth * 0.8

    opts = oegrapheme.OE2DActiveSiteDisplayOptions(cwidth, cheight)
    oedepict.OESetup2DMolDisplayOptions(opts, itf)

    opts.SetRenderInteractiveLegend(interactive_legend)
    opts.SetSVGMagnifyResidueInHover(magnify_residue)

    if interactive_legend:
        depict_complex(image, protein, ligand, opts)
    else:
        main_frame = oedepict.OEImageFrame(
            image, width * 0.80, height, oedepict.OE2DPoint(width * 0.2, 0.0))
        legend_frame = oedepict.OEImageFrame(
            image, width * 0.20, height, oedepict.OE2DPoint(width * 0.0, 0.0))
        depict_complex(main_frame, protein, ligand, opts, legend_frame)

    if ext == 'svg' and (interactive_legend or magnify_residue > 1.0):
        iconscale = 0.5
        oedepict.OEAddInteractiveIcon(image, oedepict.OEIconLocation_TopRight,
                                      iconscale)
    oedepict.OEDrawCurvedBorder(image, oedepict.OELightGreyPen, 10.0)

    oedepict.OEWriteImage(oname, image)

    return 0