本文整理匯總了Python中prody.SETTINGS類的典型用法代碼示例。如果您正苦於以下問題:Python SETTINGS類的具體用法?Python SETTINGS怎麽用?Python SETTINGS使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SETTINGS類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: backupFile
def backupFile(filename, backup=None, backup_ext='.BAK', **kwargs):
"""Rename *filename* with *backup_ext* appended to its name for backup
purposes, if *backup* is **True** or if automatic backups is turned on
using :func:`.confProDy`. Default extension :file:`.BAK` is used when
one is not set using :func:`.confProDy`. If *filename* does not exist,
no action will be taken and *filename* will be returned. If file is
successfully renamed, new filename will be returned."""
try:
exists = isfile(filename)
except Exception as err:
raise TypeError('filename must be a string ({0})'.format(str(err)))
from prody import SETTINGS
if exists and (backup or SETTINGS.get('backup', False)):
if backup_ext == '.BAK':
backup_ext = SETTINGS.get('backup_ext', '.BAK')
bak = filename + backup_ext
if isfile(bak):
try:
os.remove(bak)
except Exception as err:
pass
try:
os.rename(filename, bak)
except Exception as err:
pass
return bak
else:
return filename
示例2: wwPDBServer
def wwPDBServer(*key):
"""Set/get `wwPDB`_ FTP/HTTP server location used for downloading PDB
structures. Use one of the following keywords for setting a server:
+---------------------------+-----------------------------+
| wwPDB FTP server | *Key* (case insensitive) |
+===========================+=============================+
| RCSB PDB (USA) (default) | RCSB, USA, US |
+---------------------------+-----------------------------+
| PDBe (Europe) | PDBe, Europe, Euro, EU |
+---------------------------+-----------------------------+
| PDBj (Japan) | PDBj, Japan, Jp |
+---------------------------+-----------------------------+
.. _wwPDB: http://www.wwpdb.org/"""
if not key:
return SETTINGS.get('wwpdb', None)
elif len(key) == 1:
try:
key = key[0].lower()
except AttributeError:
raise TypeError('key must be a string')
if key in WWPDB_FTP_SERVERS:
SETTINGS['wwpdb'] = key
SETTINGS.save()
LOGGER.info('wwPDB server is set to {}.'
.format(WWPDB_FTP_SERVERS[key][0]))
else:
raise ValueError('{0} is not a valid wwPDB server identifier'
.format(repr(key)))
else:
raise TypeError('one wwPDB server identifier is expected, {0} given'
.format(len(key)))
示例3: updateDefinitions
def updateDefinitions():
"""Update definitions and set some global variables. This function must be
called at the end of the module."""
global DEFINITIONS, AMINOACIDS, BACKBONE, TIMESTAMP
DEFINITIONS = {}
user = SETTINGS.get('flag_definitions', {})
# nucleics
nucleic = set()
for key in ['nucleobase', 'nucleoside', 'nucleotide']:
aset = set(user.get(key, DEFAULTS[key]))
nucleic.update(aset)
DEFINITIONS[key] = aset
DEFINITIONS['nucleic'] = nucleic
# heteros
for key in ['water', 'lipid', 'ion', 'sugar', 'heme',
'at', 'cg', 'purine', 'pyrimidine',]:
DEFINITIONS[key] = set(user.get(key, DEFAULTS[key]))
DEFINITIONS['backbone'] = DEFINITIONS['bb'] = set(user.get(key,
DEFAULTS['bb']))
DEFINITIONS['backbonefull'] = DEFINITIONS['bbfull'] = set(user.get(key,
DEFAULTS['bbfull']))
# element regex
for key in ['hydrogen', 'carbon', 'nitrogen', 'oxygen', 'sulfur']:
DEFINITIONS[key] = recompile(user.get(key, DEFAULTS[key]))
try:
nonstd = SETTINGS[NONSTANDARD_KEY]
except KeyError:
nonstd = NONSTANDARD
DEFINITIONS.update(CATEGORIZED)
else:
for cat in CATEGORIES:
for key in CATEGORIES[cat]:
DEFINITIONS[key] = set(DEFAULTS[key])
DEFINITIONS['charged'] = set(DEFINITIONS['acidic'])
DEFINITIONS['charged'].update(DEFINITIONS['basic'])
for resi, props in nonstd.iteritems():
for prop in props:
DEFINITIONS[prop].add(resi)
DEFINITIONS['stdaa'] = DEFAULTS['stdaa']
DEFINITIONS['nonstdaa'] = set(nonstd)
AMINOACIDS = set(DEFINITIONS['stdaa'])
AMINOACIDS.update(DEFINITIONS['nonstdaa'])
DEFINITIONS['protein'] = DEFINITIONS['aminoacid'] = AMINOACIDS
BACKBONE = DEFINITIONS['bb']
global TIMESTAMP
TIMESTAMP = SETTINGS.get('flag_timestamp', 0)
示例4: changeDefinitions
def changeDefinitions(**kwargs):
defs = SETTINGS.get(DEFINITIONS_KEY, {})
defs.update(kwargs)
SETTINGS[DEFINITIONS_KEY] = defs
SETTINGS[TIMESTAMP_KEY] = int(time())
SETTINGS.save()
updateDefinitions()
示例5: pathVMD
def pathVMD(*path):
"""Return VMD path, or set it to be a user specified *path*."""
if not path:
path = SETTINGS.get('vmd', None)
if isExecutable(path):
return path
else:
LOGGER.warning('VMD path is not set by user, looking for it.')
vmdbin = None
vmddir = None
if PLATFORM == 'Windows':
if PY3K:
import winreg
else:
import _winreg as winreg # PY3K: OK
for vmdversion in ('1.8.7', '1.9', '1.9.1'):
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
'Software\\University of Illinois\\VMD\\' +
vmdversion)
vmddir = winreg.QueryValueEx(key, 'VMDDIR')[0]
vmdbin = join(vmddir, 'vmd.exe')
except:
pass
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
'Software\\WOW6432node\\University of Illinois\\VMD\\' +
vmdversion)
vmddir = winreg.QueryValueEx(key, 'VMDDIR')[0]
vmdbin = join(vmddir, 'vmd.exe')
except:
pass
else:
vmdbin = which('vmd')
if False:
pipe = os.popen('which vmd')
vmdbin = pipe.next().strip()
vmdfile = open(vmdbin)
for line in vmdfile:
if line.startswith('defaultvmddir='):
vmddir = line.split('=')[1].replace('"', '')
break
vmdfile.close()
if isExecutable(vmdbin):
setVMDpath(vmdbin)
return vmdbin
elif len(path) == 1:
path = path[0]
if isExecutable(path):
SETTINGS['vmd'] = path
SETTINGS.save()
LOGGER.info("VMD path is set to '{0}'.".format(path))
else:
raise OSError('{0} is not executable.'.format(str(path)))
else:
raise ValueError('specify a single path string')
示例6: setVMDpath
def setVMDpath(path):
"""Set path to a VMD executable."""
if isExecutable(path):
SETTINGS["vmd"] = path
SETTINGS.save()
LOGGER.info("VMD path is set to '{0:s}'.".format(path))
else:
raise OSError("{0:s} is not executable.".format(str(path)))
示例7: getPDBLocalFolder
def getPDBLocalFolder():
"""Return the path to a local PDB folder and folder structure specifier.
If a local folder is not set, **None** will be returned."""
folder = SETTINGS.get('pdb_local_folder')
if folder:
if isdir(folder):
return folder, SETTINGS.get('pdb_local_divided', True)
else:
LOGGER.warning('PDB local folder {0:s} is not a accessible.'
.format(repr(folder)))
示例8: setPDBMirrorPath
def setPDBMirrorPath(path):
"""Set the path to a local PDB mirror."""
if not isinstance(path, str):
raise TypeError('path must be a string')
if isdir(path):
path = abspath(path)
LOGGER.info('Local PDB mirror path is set: {0:s}'.format(repr(path)))
SETTINGS['pdb_mirror_path'] = path
SETTINGS.save()
else:
raise IOError('No such directory: {0:s}'.format(repr(path)))
示例9: addNonstdAminoacid
def addNonstdAminoacid(resname, *properties):
"""Add non-standard amino acid *resname* with *properties* selected from:
* {props}
>>> addNonstdAminoacid('PTR', 'acidic', 'aromatic', 'cyclic', 'large',
... 'polar', 'surface')
Default set of non-standard amino acids can be restored as follows:
>>> flagDefinition(reset='nonstdaa')"""
resname = str(resname)
if len(resname) > 4:
LOGGER.warn('Residue name {0:s} is unusually long.'
.format(repr(resname)))
propset = set(properties)
for cat, val in CATEGORIES.items():
intersection = val.intersection(propset)
if intersection:
if len(intersection) > 1:
raise ValueError('amino acid properties {0:s} cannot be '
'present together'
.format(', '.join([repr(prp) for prp in intersection])))
for prop in intersection:
propset.remove(prop)
if propset:
raise ValueError('amino acid property {0:s} is not valid'
.format(repr(propset.pop())))
nonstd = SETTINGS.get(NONSTANDARD_KEY, NONSTANDARD)
nonstd[resname] = set(properties)
updateNonstandard(nonstd)
示例10: pathPDBMirror
def pathPDBMirror(path=None, format=None):
"""Returns or specify PDB mirror path to be used by :func:`.fetchPDB`.
To release the current mirror, pass an invalid path, e.g. ``path=''``.
If you are keeping a partial mirror, such as PDB files in
:file:`/data/structures/divided/pdb/` folder, specify *format*, which is
``'pdb'`` in this case."""
if path is None:
path = SETTINGS.get('pdb_mirror_path')
format = SETTINGS.get('pdb_mirror_format', None)
if path:
if isdir(path):
if format is None:
return path
else:
return path, format
else:
LOGGER.warning('PDB mirror path {0} is not a accessible.'
.format(repr(path)))
else:
if isdir(path):
path = abspath(path)
LOGGER.info('Local PDB mirror path is set: {0}'
.format(repr(path)))
SETTINGS['pdb_mirror_path'] = path
SETTINGS['pdb_mirror_format'] = format
SETTINGS.save()
else:
current = SETTINGS.pop('pdb_mirror_path')
if current:
LOGGER.info('PDB mirror {0} is released.'
.format(repr(current)))
SETTINGS.save()
else:
raise IOError('{0} is not a valid path.'.format(repr(path)))
示例11: getVMDpath
def getVMDpath():
"""Return VMD path set by user or one identified automatically."""
path = SETTINGS.get("vmd", None)
if isExecutable(path):
return path
else:
LOGGER.warning("VMD path is not set by user, looking for it.")
from types import StringType, UnicodeType
vmdbin = None
vmddir = None
if PLATFORM == "Windows":
import _winreg
for vmdversion in ("1.8.7", "1.9", "1.9.1"):
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, "Software\\University of Illinois\\VMD\\" + vmdversion
)
vmddir = _winreg.QueryValueEx(key, "VMDDIR")[0]
vmdbin = os.path.join(vmddir, "vmd.exe")
except:
pass
try:
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, "Software\\WOW6432node\\University of Illinois\\VMD\\" + vmdversion
)
vmddir = _winreg.QueryValueEx(key, "VMDDIR")[0]
vmdbin = os.path.join(vmddir, "vmd.exe")
except:
pass
else:
vmdbin = which("vmd")
if False:
pipe = os.popen("which vmd")
vmdbin = pipe.next().strip()
vmdfile = open(vmdbin)
for line in vmdfile:
if line.startswith("defaultvmddir="):
vmddir = line.split("=")[1].replace('"', "")
break
vmdfile.close()
if (
False
and isinstance(vmdbin, (StringType, UnicodeType))
and isinstance(vmddir, (StringType, UnicodeType))
and os.path.isfile(vmdbin)
and os.path.isdir(vmddir)
):
pass # return vmdbin, vmddir
if isExecutable(vmdbin):
setVMDpath(vmdbin)
return vmdbin
示例12: getPDBMirrorPath
def getPDBMirrorPath():
"""Return the path to a local PDB mirror, or **None** if a mirror path is
not set."""
path = SETTINGS.get('pdb_mirror_path')
if path:
if isdir(path):
return path
else:
LOGGER.warning('PDB mirror path {0:s} is not a accessible.'
.format(repr(path)))
示例13: pathPDBFolder
def pathPDBFolder(folder=None, divided=False):
"""Returns or specify local PDB folder for storing PDB files downloaded from
`wwPDB <http://www.wwpdb.org/>`_ servers. Files stored in this folder can
be accessed via :func:`.fetchPDB` from any working directory. To release
the current folder, pass an invalid path, e.g. ``folder=''``.
If *divided* is **True**, the divided folder structure of wwPDB servers
will be assumed when reading from and writing to the local folder. For
example, a structure with identifier **1XYZ** will be present as
:file:`pdblocalfolder/yz/pdb1xyz.pdb.gz`.
If *divided* is **False**, a plain folder structure will be expected and
adopted when saving files. For example, the same structure will be
present as :file:`pdblocalfolder/1xyz.pdb.gz`.
Finally, in either case, lower case letters will be used and compressed
files will be stored."""
if folder is None:
folder = SETTINGS.get('pdb_local_folder')
if folder:
if isdir(folder):
return folder, SETTINGS.get('pdb_local_divided', True)
else:
LOGGER.warn('PDB local folder {0} is not a accessible.'
.format(repr(folder)))
else:
if isdir(folder):
folder = abspath(folder)
LOGGER.info('Local PDB folder is set: {0}'.format(repr(folder)))
if divided:
LOGGER.info('wwPDB divided folder structure will be assumed.')
else:
LOGGER.info('A plain folder structure will be assumed.')
SETTINGS['pdb_local_folder'] = folder
SETTINGS['pdb_local_divided'] = bool(divided)
SETTINGS.save()
else:
current = SETTINGS.pop('pdb_local_folder')
if current:
LOGGER.info('PDB folder {0} is released.'
.format(repr(current)))
SETTINGS.pop('pdb_local_divided')
SETTINGS.save()
else:
raise IOError('{0} is not a valid path.'.format(repr(folder)))
示例14: setWWPDBFTPServer
def setWWPDBFTPServer(key):
"""Set the `wwPDB <http://www.wwpdb.org/>`_ FTP server used for downloading
PDB structures when needed. Use one of the following keywords for setting
a different server.
+---------------------------+-----------------------------+
| wwPDB FTP server | *Key* (case insensitive) |
+===========================+=============================+
| RCSB PDB (USA) (default) | RCSB, USA, US |
+---------------------------+-----------------------------+
| PDBe (Europe) | PDBe, Europe, Euro, EU |
+---------------------------+-----------------------------+
| PDBj (Japan) | PDBj, Japan, Jp |
+---------------------------+-----------------------------+
"""
server = WWPDB_FTP_SERVERS.get(key.lower())
if server is not None:
SETTINGS['wwpdb_ftp'] = server
SETTINGS.save()
else:
LOGGER.warning('{0:s} is not a valid key.'.format(key))
示例15: getNonstdProperties
def getNonstdProperties(resname):
"""Return properties of non-standard amino acid *resname*.
>>> getNonstdProperties('PTR')
['acidic', 'aromatic', 'cyclic', 'large', 'polar', 'surface']"""
try:
alist = list(SETTINGS.get(NONSTANDARD_KEY, NONSTANDARD)[resname])
except KeyError:
raise ValueError('{0:s} is not a non-standard residue name'
.format(repr(resname)))
else:
alist.sort()
return alist