def main(argv=[__name__]):
    if len(argv) != 3:
        oechem.OEThrow.Usage("%s <reffile> <fitfile>" % argv[0])

    reffs = oechem.oemolistream(argv[1])
    fitfs = oechem.oemolistream(argv[2])

    refmol = oechem.OEGraphMol()
    oechem.OEReadMolecule(reffs, refmol)

    # Prepare reference molecule for calculation
    # With default options this will remove any explicit
    # hydrogens present and add color atoms
    prep = oeshape.OEOverlapPrep()
    prep.Prep(refmol)

    # Get appropriate function to calculate both shape and color
    # By default the OEOverlapFunc contains OEGridShapeFunc for shape
    # and OEExactColorFunc for color
    func = oeshape.OEOverlapFunc()
    func.SetupRef(refmol)

    res = oeshape.OEOverlapResults()
    for fitmol in fitfs.GetOEGraphMols():
        prep.Prep(fitmol)
        func.Overlap(fitmol, res)
        print("title: %s  tanimoto combo = %.2f shape tanimoto = %.2f color tanimoto = %.2f" %
              (fitmol.GetTitle(), res.GetTanimotoCombo(),
               res.GetTanimoto(), res.GetColorTanimoto()))
Exemple #2
0
def tanimotocombo(ref_mol, query_mol):
    """
    This is the TanimotoCombo function. It takes in two OEMols. 
    It does not matter (for our purposes) which mol is the reference mol and 
    which one is the query mol. The TanimotoCombo distance between the two
    mols is the same no matter which is the reference and which is the query.
    The GetTanimotoCombo() function comes from openeye.
     
    Args:
        ref_mol (oemol) An oemol that has already been read in. 
        query_mol (oemol) Another oemol that has already been read in. 
 
    Returns: 
        res.GetTanimotoCombo() (float) The TanimotoCombo value.
    """
    # Prepare reference molecule for calculation
    # With default options this will remove any explicit
    # hydrogens present and add color atoms
    prep = oeshape.OEOverlapPrep()
    prep.Prep(ref_mol)
    # Get appropriate function to calculate both shape and color
    # By default the OEOverlapFunc contains OEGridShapeFunc for shape
    # and OEExactColorFunc for color
    func = oeshape.OEOverlapFunc()
    func.SetupRef(ref_mol)
    res = oeshape.OEOverlapResults()
    prep.Prep(query_mol)
    func.Overlap(query_mol, res)
    return (res.GetTanimotoCombo())
Exemple #3
0
    def from_oemol(self, from_oemol):
        with self.logger("from_oemol") as logger:
            tautomer_options = oequacpac.OETautomerOptions()
            tautomer_options.SetMaxTautomersGenerated(4096)
            tautomer_options.SetMaxTautomersToReturn(16)
            tautomer_options.SetCarbonHybridization(True)
            tautomer_options.SetMaxZoneSize(50)
            tautomer_options.SetApplyWarts(True)

            pKa_norm = True

            omegaOpts = oeomega.OEOmegaOptions(oeomega.OEOmegaSampling_Pose)
            omegaOpts.SetStrictAtomTypes(False)
            omegaOpts.SetSampleHydrogens(True)
            omegaOpts.SetMaxSearchTime(30)
            omegaOpts.SetFixDeleteH(True)
            omega = oeomega.OEOmega(omegaOpts)

            options = oeshape.OEROCSOptions()
            overlayoptions = oeshape.OEOverlayOptions()
            overlayoptions.SetOverlapFunc(
                oeshape.OEOverlapFunc(oeshape.OEAnalyticShapeFunc()))
            options.SetOverlayOptions(overlayoptions)
            # options.SetNumBestHits(10)
            options.SetConfsPerHit(200)
            # options.SetMaxHits(10000)
            rocs = oeshape.OEROCS(options)
            for tautomer in oequacpac.OEGetReasonableTautomers(
                    from_oemol, tautomer_options, pKa_norm):
                logger.log("got enantiomer")
                for enantiomer in oeomega.OEFlipper(tautomer, 4, False):
                    logger.log("got tautomer ")
                    enantiomer_ = oechem.OEMol(enantiomer)
                    ret_code = omega.Build(enantiomer_)
                    if ret_code != oeomega.OEOmegaReturnCode_Success:
                        logger.error("got oemeg_failed",
                                     oeomega.OEGetOmegaError(ret_code))
                    else:
                        rocs.AddMolecule(oechem.OEMol(enantiomer_))

            for res in rocs.Overlay(self.refmol):
                outmol = oechem.OEMol(res.GetOverlayConfs())
                good_mol = oechem.OEMol(outmol)
                oechem.OEAddExplicitHydrogens(good_mol)
                oechem.OEClearSDData(good_mol)
                oeshape.OEDeleteCompressedColorAtoms(good_mol)
                oeshape.OEClearCachedSelfColor(good_mol)
                oeshape.OEClearCachedSelfShape(good_mol)
                oeshape.OERemoveColorAtoms(good_mol)
                return good_mol
            logger.error("Returning None.")

        return None
Exemple #4
0
            fragment = oechem.OEGraphMol()
            while oechem.OEReadMolecule(ifs, fragment):
                match = re.search(
                    'Mpro-(?P<fragment_name>x\d\d\d\d)-ligand.mol2', filename)
                fragment_name = match.group('fragment_name')
                # Set fragment name as title
                fragment.SetTitle(fragment_name)
                # Store it
                fragments[fragment_name] = fragment.CreateCopy()
    print(f'{len(fragments)} fragments loaded.')

    # Get appropriate function to calculate analytic shape
    #shapeFunc = oeshape.OEAnalyticShapeFunc()
    #shapeFunc = oeshape.OEAnalyticShapeFunc()
    #shapeFunc = oeshape.OEOverlapFunc()
    shapeFunc = oeshape.OEOverlapFunc()

    # Compute distinct fragments
    compute_fragment_basis = True
    n_clusters = 40
    if compute_fragment_basis:
        # TODO: Use PCCA+ when we have time to implement this
        print('Extracting a fragment basis...')
        import numpy as np
        from sklearn.cluster import SpectralClustering
        fragment_names = list(fragments.keys())
        nfragments = len(fragment_names)
        affinity_matrix = np.ones([nfragments, nfragments], np.float32)
        for i in range(nfragments):
            shapeFunc.SetupRef(fragments[fragment_names[i]])
            result = oeshape.OEOverlapResults()
            color_width = 0.5
            color_gauss = oegrid.OEGaussian(color_prefactor,
                                            color_width, coords,
                                            oeshape.OEGetColorType(atom))
            query.AddColorGaussian(color_gauss)

    oeshape.OEWriteShapeQuery('query.sq', query)

    #merged_func = oeshape.OEOverlapFunc()
    #merged_func = oeshape.OEAnalyticColorFunc()
    merged_func = oeshape.OEExactColorFunc()
    merged_func.SetupRef(query)

    # Get appropriate function to calculate analytic shape
    result = oeshape.OEOverlapResults()
    fragment_func = oeshape.OEOverlapFunc()
    print('Computing overlap scores...')
    OVERLAP_THRESHOLD = 0.50
    for molecule in tqdm(docked_molecules):
        # Compute overlap with merged query
        fitmol = molecule.CreateCopy()
        prep.Prep(fitmol)
        merged_func.Overlap(fitmol, result)
        volume = oeshape.OECalcVolume(molecule)
        score = result.GetFitTverskyCombo()
        #score = result.GetRefTverskyCombo()

        # Compute overlaps
        fragment_func.SetupRef(molecule)
        overlapping_fragments = list()
        fragment_overlap_scores = dict()