Source code for prody

"""ProDy is a package for Protein Dynamics, Sequence, and Structure Analysis"""

__version__ = '1.9.2'
__release__ = __version__ # + '-dev' # comment out '-dev' before a release

import sys
import warnings

if sys.version_info[:2] < (2, 6):
    raise Exception('prody is compatible with Python version less than 2.6')

    import numpy as np
except ImportError:
    raise ImportError('Numpy is a required package for ProDy')
    if tuple(map(int, np.__version__.split('.')[:2])) < (1, 4):
        raise ImportError('Numpy v1.4 or later is required for ProDy')

from .utilities import PackageLogger, PackageSettings
from .utilities import getPackagePath, joinRepr, tabulate


def deprecate(dep, alt, ver=None, sl=3):
    """Issue a deprecation warning for *dep* and recommend using *alt*."""

    if ver is None:
        ver = list(__version__.split('.')[:2])
        ver[1] = str(int(ver[1]) + 1)
        ver = '.'.join(ver)

    warnings.warn('`{0:s}` is deprecated for removal in v{1:s}, use `{2:s}`.'
                  .format(dep, ver, alt), DeprecationWarning, stacklevel=sl)

def turnonDepracationWarnings(action='always'):
    """Turn on deprecation warnings for the current session.  By default
     (``action='always'``), deprecation warnings will be printed every time
     a function is called to help identification of multiple occurrence
     of deprecated function and method names.  When ``action='default'``
     is passed, warning will be issued at the first call of a function.
     The latter behavior will automatically kick in when v0.9 is released.
     Until v0.9 is released, restarting the session will turn of warnings.
     This function must be called as ``prody.turnonDepracationWarnings``."""

    warnings.filterwarnings(action, category=DeprecationWarning)

_PY3K = PY3K = sys.version_info[0] > 2
PY2K = not PY3K

LOGGER = PackageLogger('.prody')

SETTINGS = PackageSettings('prody', logger=LOGGER)

__all__ = ['checkUpdates', 'confProDy', 'startLogfile', 'closeLogfile', 'plog']

from . import kdtree
from .kdtree import *

from . import atomic
from .atomic import *

from .atomic import SELECT

from . import proteins
from .proteins import *

from . import measure
from .measure import *

from . import database
from .database import *

from . import sequence
from .sequence import *

from . import dynamics
from .dynamics import *

from . import ensemble
from .ensemble import *

from . import trajectory
from .trajectory import *

from . import chromatin
from .chromatin import *

#from . import comd
#from .comd import *

import prody

# default, acceptable values, setter
    'backup': (False, None, None),
    'backup_ext': ('.BAK', None, None),
    'auto_show': (True, None, None),
    'ligand_xml_save': (False, None, None),
    'typo_warnings': (True, None, None),
    'check_updates': (0, None, None),
    'auto_secondary': (False, None, None),
    'selection_warning': (True, None, None),
    'verbosity': ('debug', list(utilities.LOGGING_LEVELS),
    'pdb_mirror_path': ('', None, proteins.pathPDBMirror),
    'local_pdb_folder': ('', None, proteins.pathPDBFolder),

[docs]def confProDy(*args, **kwargs): """Configure ProDy.""" if args: values = [] for option in args: try: values.append(SETTINGS[option]) except KeyError: raise KeyError('{0:s} is not a valid configuration option' .format(repr(option))) if len(values) == 1: return values[0] else: return values for option, value in kwargs.items(): try: default, acceptable, setter = CONFIGURATION[option] except KeyError: raise KeyError('{0:s} is not a valid configuration option' .format(repr(option))) else: try: value = type(default)(value) except ValueError: raise TypeError('{0:s} must be a {1:s}' .format(option, type(default).__name__)) if acceptable is not None and value not in acceptable: raise ValueError('{0:s} must be one of {1:s}'.format(option, joinRepr(acceptable, sort=True, last=', or '))) SETTINGS[option] = value'ProDy is configured: {0:s}={1:s}' .format(option, repr(value))) if setter is not None: setter(value)
_keys = list(CONFIGURATION) _keys.sort() _vals = [] for _key in _keys: default, acceptable, setter = CONFIGURATION[_key] try: if not setter.func_name.startswith('_'): seealso = ' See also :func:`.' + setter.func_name + '`.' except AttributeError: seealso = '' if acceptable is None: _vals.append(repr(default) + seealso) else: _vals.append(repr(default) + ' (' + joinRepr(acceptable, sort=True, last=', or ') + ')' + seealso) if _key not in SETTINGS: SETTINGS[_key] = default LOGGER._setverbosity(confProDy('verbosity')) confProDy.__doc__ += '\n\n' + tabulate(['Option'] + _keys, ['Default (acceptable values)'] + _vals ) + """ Usage example:: confProDy('backup') confProDy('backup', 'backup_ext') confProDy(backup=True, backup_ext='.bak') confProDy(backup_ext='.BAK')"""
[docs]def plog(*text): """Log *text* using ProDy logger at log level info. Multiple arguments are accepted. Each argument will be converted to string and joined using a white space as delimiter."""' '.join([str(s) for s in text]))
[docs]def startLogfile(filename, **kwargs):
LOGGER.start(filename, **kwargs) startLogfile.__doc__ = LOGGER.start.__doc__
[docs]def closeLogfile(filename): """Close logfile with *filename*.""" LOGGER.close(filename)
[docs]def checkUpdates(): """Check PyPI to see if there is a newer ProDy version available. Setting ProDy configuration parameter *check_updates* to a positive integer will make ProDy automatically check updates, e.g.:: confProDy(check_updates=7) # check at most once a week confProDy(check_updates=0) # do not auto check updates confProDy(check_updates=-1) # check at the start of every session""" if PY3K: import xmlrpc.client pypi = xmlrpc.client.Server('') else: import xmlrpclib pypi = xmlrpclib.Server('') releases = pypi.package_releases('ProDy') if releases[0] == __version__:'You are using the latest ProDy release (v{0:s}).' .format(__version__)) else:'ProDy v{0:s} is available, you are using {1:s}.' .format(releases[0], __version__)) if SETTINGS['check_updates']: import time SETTINGS['last_check'] = time.time()
if SETTINGS['check_updates']: if SETTINGS.get('last_check') is None: SETTINGS['last_check'] = 0 import time if ((time.time() - SETTINGS.get('last_check')) / 3600 / 24 > SETTINGS['check_updates']):'Checking PyPI for ProDy updates:') checkUpdates()