Source code for schrodinger
"""
This is the top level package for all Schrodinger modules.
The main modules of interest are `schrodinger.structure` and the ones in
the `schrodinger.structutils` package.
The Python Module Overview included with the Schrodinger distribution gives
an expository introduction to the Schrodinger Python API. It is available
at `https://www.schrodinger.com/pythonapi <https://www.schrodinger.com/pythonapi>`_.
If you have questions about the API, please contact us at
`https://www.schrodinger.com/supportcenter <https://www.schrodinger.com/supportcenter>`_.
"""
# Copyright Schrodinger, LLC. All rights reserved.
import os
import sys
from sitecustomize import in_dev_env # noqa: F401
# support for 'from schrodinger import *'
__all__ = [
"application", "infra", "job", "structure", "maestro", "project", "protein",
"ui", "utils", "structutils"
]
_maestro = None
__version__ = int("77128")
[docs]def version_at_least(v):
"""
Check that the Schrodinger python version is at least the value 'v'.
NOTE: Deprecated in favor of get_mmshare_version()
"""
if v > __version__:
raise Exception(
"Schrodinger python version %d is required, but version %d is present."
% (v, __version__))
[docs]def version_at_most(v):
"""
Check that the Schrodinger python version does not exceed 'v'.
NOTE: Deprecated in favor of get_mmshare_version()
"""
import warnings
if v < __version__:
warnings.warn("This code is untested with Schrodinger python version "
"%d. You may want to check for an updated script." %
__version__)
[docs]def version_compatible(minimum, maximum):
"""
Check that the version is between minimum and maximum values.
NOTE: Deprecated in favor of get_mmshare_version()
If the current Schrodinger python version is less than the minimum, an
Exception will be raised. If the current version is greater than the
maximum, a warning will be issued.
"""
version_at_least(minimum)
version_at_most(maximum)
[docs]def get_release_name() -> str:
"""
Return descriptive text name of the current release.
"""
# This function is really only useful inside of toplevel.py - if you are
# looking for this information, please use schrodinger.infra.mm functions
# mmfile_get_relase_name() and mmfile_appdata_release_dir()
# This line is automatically replaced at build time.
return "2022-2"
[docs]def get_mmshare_version() -> int:
"""
Return the mmshare version as a 5 digit integer.
"""
# Must import the mm module here to avoid test failure:
from schrodinger.infra import mm
return mm.mmfile_get_product_version('mmshare')
[docs]def get_maestro():
"""
Get either schrodinger.maestro.maestro or an object that allows scripts to
avoid running maestro dependent-code, and print reasonable errors if that
code is run outside of maestro.
:return: schrodinger.maestro.maestro or _DummyMaestroModule
"""
global _maestro
# Use global so that we can call this function without penality when the
# import error fails (and we aren't persistently trying to re-import)
# from profiling on bolt
if _maestro is None:
try:
from schrodinger.maestro import maestro as _maestro
except ImportError:
_maestro = _DummyMaestroModule()
return _maestro
class _DummyMaestroModule(object):
"""
Used to replace schrodinger.maestro.maestro when running outside of Maestro.
Casts to bool return False to allow portions of scripts to be protected by
"if maestro:" Raises an explanatory error if the calling module tries to
access any attribute.
"""
def __bool__(self):
return False
def __getattr__(self, attr):
msg = ("Cannot access schrodinger.maestro.maestro.%s outside of "
"Maestro" % attr)
raise MaestroNotAvailableError(msg)
def _is_coroutine(self):
"""
Since we override all __getattr__ functions, this function needs to be
defined so isinstance checks work on this object.
"""
return False
def __func__(self):
"""
Since we override all __getattr__ functions, this function needs to be
defined so isinstance checks work on this object.
"""
return super().__func__()
[docs]class MaestroNotAvailableError(ImportError):
"""
Error class to indicate that Maestro is not available and there was an
attempt to use it.
"""
[docs]def get_mpl_backend_name() -> str:
"""
Get the matplotlib backend name to use with for drawing plots.
"""
if sys.platform.startswith("linux") and "DISPLAY" not in os.environ:
return "Agg"
elif "SCHRODINGER_JOBID" in os.environ:
return "Agg"
else:
return "Qt5Agg"