Пример #1
0
    def _load_verify_openeye(self, oechemlicensepath=None):
        """Loads required OpenEye libraries and checks licenses

        Parameters
        ----------
        oechemlicensepath : str, optional, default=None
            OpenEye license path to use, or None if environment variables are to be used.

        Raises
        ------
        RuntimeError
            If OE_LICENSE is not found as an environment variable
            If A valid license is missing

        Notes
        -----
        Needs to be run before any of the other functions to assure OpenEye libraries are accessible.

        """

        # Don't do anything if we've already imported OpenEye toolkit.
        if self.oechem: return

        try:
            # Import the OpenEye toolkit components.
            from openeye import oechem     # For chemical objects
            from openeye import oeiupac    # For IUPAC conversion
            from openeye import oeomega    # For conformer generation
            from openeye import oequacpac  # For pKa estimations
        except Exception as e:
            raise Exception("Could not import `openeye` library.  Make sure OpenEye Python Toolkit is installed and on PYTHONPATH.")

        import os

        if oechemlicensepath is not None:
            os.environ['OE_LICENSE'] = oechemlicensepath

        try:
            os.environ['OE_LICENSE']  # See if license path is set.
        except KeyError:
            raise RuntimeError("Environment variable OE_LICENSE needs to be set.")

        if not oechem.OEChemIsLicensed():  # Check for OEchem TK license.
            raise RuntimeError("No valid license available for OEChem TK.")

        if not oeiupac.OEIUPACIsLicensed():  # Check for Lexichem TK license.
            raise RuntimeError("No valid license available for Lexichem TK.")

        if not oeomega.OEOmegaIsLicensed():  # Check for Omega TK license.
            raise RuntimeError("No valid license for Omega TK.")

        if not oequacpac.OEQuacPacIsLicensed():  # Check for Quacpac TK license.
            raise RuntimeError("No valid license for Quacpac TK.")

        #Attach libraries to the instance to only load and check them once at initialization.
        self.oechem = oechem
        self.oeiupac = oeiupac
        self.oeomega = oeomega
        self.oequacpac = oequacpac
        return
Пример #2
0
def is_openeye_installed():
    try:
        from openeye import oechem
        from openeye import oequacpac
        from openeye import oeiupac
        from openeye import oeomega

        if not (oechem.OEChemIsLicensed() and oequacpac.OEQuacPacIsLicensed()
                and oeiupac.OEIUPACIsLicensed()
                and oeomega.OEOmegaIsLicensed()):
            raise ImportError
    except ImportError:
        return False
    return True
Пример #3
0
try:
    from openeye import oechem

    if not oechem.OEChemIsLicensed():
        raise (ImportError("Need License for OEChem!"))
    from openeye import oequacpac

    if not oequacpac.OEQuacPacIsLicensed():
        raise (ImportError("Need License for oequacpac!"))
    from openeye import oeiupac

    if not oeiupac.OEIUPACIsLicensed():
        raise (ImportError("Need License for OEOmega!"))
    from openeye import oeomega

    if not oeomega.OEOmegaIsLicensed():
        raise (ImportError("Need License for OEOmega!"))
    hasOpenEye = True
    openeye_exception_message = str()
except Exception as e:
    hasOpenEye = False
    openeye_exception_message = str(e)


def files_to_tempdir(files: List[str],
                     suffix="protons-test",
                     prefix="tmp") -> str:
    """Make a temporary directory in the current directory, copy files over and return the location."""
    newdir = tempfile.mkdtemp(prefix=prefix, suffix=suffix)

    for filename in files: