Ejemplo n.º 1
0
def FromMol(mol, isomer=True, num_enantiomers=-1):
    """
    Generates a set of conformers as an OEMol object
    Inputs:
        mol is an OEMol
        isomers is a boolean controling whether or not the various diasteriomers of a molecule are created
        num_enantiomers is the allowable number of enantiomers. For all, set to -1
    """
    omegaOpts = oeomega.OEOmegaOptions()
    omegaOpts.SetMaxConfs(199)
    omega = oeomega.OEOmega(omegaOpts)
    out_conf = []
    ofs = oechem.oemolostream("test.sdf")
    if not isomer:
        ret_code = omega.Build(mol)
        if ret_code == oeomega.OEOmegaReturnCode_Success:
            out_conf.append(mol)
        else:
            oechem.OEThrow.Warning("%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code)))

    elif isomer:
        for enantiomer in oeomega.OEFlipper(mol.GetActive(), 12, True):
            enantiomer = oechem.OEMol(enantiomer)
            ret_code = omega.Build(enantiomer)
            if ret_code == oeomega.OEOmegaReturnCode_Success:
                out_conf.append(enantiomer)
                num_enantiomers -= 1
                oechem.OEWriteMolecule(ofs, mol)
                if num_enantiomers == 0:
                    break
            else:
                oechem.OEThrow.Warning("%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code)))

    return out_conf
Ejemplo n.º 2
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])

    if not oechem.OEIs3DFormat(ofs.GetFormat()):
        oechem.OEThrow.Fatal("Invalid output file format for 3D coordinates!")

    omegaOpts = oeomega.OEMacrocycleOmegaOptions()
    mcomega = oeomega.OEMacrocycleOmega(omegaOpts)

    for mol in ifs.GetOEMols():
        oechem.OEThrow.Info("Title: %s" % mol.GetTitle())
        ret_code = mcomega.Build(mol)
        if ret_code == oeomega.OEOmegaReturnCode_Success:
            oechem.OEWriteMolecule(ofs, mol)
        else:
            oechem.OEThrow.Warning("%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code)))

    return 0
Ejemplo n.º 3
0
def FromMol(mol, use_flipper=True, num_sterocenters=12, force_flipper=False):
    """
    Generates a set of conformers as an OEMol object
    Inputs:
        mol is an OEMol
        isomers is a boolean controling whether or not the various diasteriomers of a molecule are created
        num_enantiomers is the allowable number of enantiomers. For all, set to -1
    """
    omegaOpts = oeomega.OEOmegaOptions()
    omegaOpts.SetMaxConfRange("200,800")
    omegaOpts.SetRangeIncrement(8)
    omegaOpts.SetMaxSearchTime(30)
    omega = oeomega.OEOmega(omegaOpts)

    out_conf = []

    for enantiomer in oeomega.OEFlipper(mol.GetActive(), num_sterocenters,
                                        force_flipper):
        enantiomer = oechem.OEMol(enantiomer)
        ret_code = omega.Build(enantiomer)
        if ret_code == oeomega.OEOmegaReturnCode_Success:
            out_conf.append(enantiomer)

        else:
            oechem.OEThrow.Warning(
                "%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code)))

    return out_conf
Ejemplo n.º 4
0
def create_conformers(infile=None, outfile=None, resname=None, folder= None, name = None):

    """
    This function takes a mol1 file and runs Openeye's omega to create conformers for the molecules
    The conformers are stored in separated files, adding the number of the conformer at the end of the filename

    :param infile: Path to input file
    :param outfile: Path to output file return
    :param folder: Name of the folder for the target. If not specified. {name}-liquid is used.
    :param resname: Abbreviation of the Residue. Specified in the mol2
    :return: Number of conformers for this molecule
    """
    if folder is None and name is None:
        log.error('Please specify keyword argument folder or name')
        sys.exit(1)
    elif folder is None:
        folder = name +'-liquid'
    infilepath = os.path.join(folder, infile)
    outfilepath = os.path.join(folder, outfile)
    ifs = oechem.oemolistream()
    if not ifs.open(infilepath):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % infilepath)

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

    if not oechem.OEIs2DFormat(ofs.GetFormat()):
        oechem.OEThrow.Fatal("Invalid output file format for 2D coordinates!")

    omegaOpts = oeomega.OEOmegaOptions()
    omega = oeomega.OEOmega(omegaOpts)
    omega.SetCommentEnergy(True)
    omega.SetEnumNitrogen(True)
    omega.SetSampleHydrogens(True)
    omega.SetEnergyWindow(9.0)
    omega.SetMaxConfs(5)
    omega.SetRangeIncrement(2)
    omega.SetRMSRange([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5])
    filename = '{}-conformers'.format(resname)
    for mol in ifs.GetOEMols():
        ret_code = omega.Build(mol)
        if ret_code == oeomega.OEOmegaReturnCode_Success:
            oechem.OEWriteMolecule(ofs, mol)
            for k, conf in enumerate(mol.GetConfs()):
                ofs1 = oechem.oemolostream()
                if not ofs1.open(os.path.join(folder, filename + '_' + str(k + 1) + '.mol2')):
                    oechem.OEThrow.Fatal("Unable to open %s for writing" % os.path.join(folder, filename + '_' + str(k + 1) + '.mol2'))
                oechem.OEWriteMolecule(ofs1, conf)
                nconf = k + 1
            log.info('Created conformations for {} and saved them to {}'.format(infilepath, outfilepath))

        else:
            oechem.OEThrow.Warning("%s: %s" % (mol.GetTitle(), oeomega.OEGetOmegaError(ret_code)))

    return nconf
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def gen_conf(mol):
    oemols = []
    omegaOpts = oeomega.OEOmegaOptions(oeomega.OEOmegaSampling_FastROCS)
    omega = oeomega.OEOmega(omegaOpts)
    for enantiomer in oeomega.OEFlipper(mol.GetActive(), 6, True):
        enantiomer = oechem.OEMol(enantiomer)
        ret_code = omega.Build(enantiomer)
        if 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)))
    return oemols
Ejemplo n.º 7
0
    def process(self, record, port):
        # Make sure we have a molecule defined
        if not record.has_value(OEPrimaryMolField()):
            record.set_value(self.args.log_field,
                             'Record is missing an input molecule field')
            self.failure.emit(record)
        mol = record.get_value(OEPrimaryMolField())

        # Report which compound we are processing
        from openeye.oechem import OEMolToSmiles
        smiles = OEMolToSmiles(mol)
        self.log.info(f"Processing compound {smiles}")

        # Generate arbitrary 3D coordinates for target ligand
        from openeye import oeomega
        omegaOpts = oeomega.OEOmegaOptions()
        omega = oeomega.OEOmega(omegaOpts)
        ret_code = omega.Build(mol)
        if ret_code != oeomega.OEOmegaReturnCode_Success:
            record.set_value(self.args.log_field,
                             oeomega.OEGetOmegaError(ret_code))
            self.failure.emit(record)

        from tempfile import TemporaryDirectory
        import os
        cwd = os.getcwd()
        with TemporaryDirectory() as tmpdir:
            self.log.info(f"Entering temporary directory {tmpdir}")
            os.chdir(tmpdir)

            # Set up perses calculation
            from perses.app.setup_relative_calculation import getSetupOptions, run_setup, run
            self.log.info(f"Loading setup options...")
            setup_options = getSetupOptions(self.yaml_filename)
            self.log.info(str(setup_options))

            # Prepare input for perses
            # TODO: Use tempdir in future for filesystem reasons
            self.log.info(f"Writing receptor...", flush=True)
            from openeye import oechem
            protein_pdb_filename = 'receptor.pdb'
            with oechem.oemolostream(protein_pdb_filename) as ofs:
                oechem.OEWriteMolecule(ofs, self._receptor)
            self.log.info(f"Writing ligands...", flush=True)
            ligands_sdf_filename = 'ligands.sdf'
            with oechem.oemolostream(ligands_sdf_filename) as ofs:
                oechem.OEWriteMolecule(ofs,
                                       self._reference_ligand)  # molecule 0
                oechem.OEWriteMolecule(ofs, mol)  # molecule 1

            self.log.info(f"Setting up perses calculation...", flush=True)
            perses_setup = run_setup(setup_options)

            self.log.info(f"Running calculations...", flush=True)
            run(self.yaml_filename)

            # Analyze the data
            self.log.info(f"Analyzing calculations...", flush=True)
            from perses.analysis.load_simulations import Simulation
            simulation = Simulation(0, 1)
            simulation.load_data()

            os.chdir(cwd)

        # Set output molecule information
        # TODO: Store trajectory or final snapshots
        phases = setup_options['phases']
        if ('complex' in phases) and ('solvent' in phases):
            self.log.info(
                f"DDG = {simulation.bindingdb} +- {simulation.bindingddg} kcal/mol..."
            )
            record.set_value(self.DDG_field, simulation.bindingdg)
            record.set_field(self.dDDG_field, simulation.bindingddg)
        elif 'vacuum' in setup_options['p']:
            self.log.info(
                f"DDG(vacuum) = {simulation.vacdb} +- {simulation.vacddg} kcal/mol..."
            )
            record.set_value(self.DDG_field, simulation.vacdg)
            record.set_field(self.dDDG_field, simulation.vacddg)
        self.success.emit(record)