repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
assamite/creamas | creamas/util.py | addrs2managers | def addrs2managers(addrs):
'''Map agent addresses to their assumed managers.
.. seealso::
:func:`creamas.util.get_manager`
'''
mgrs = {}
for addr in addrs:
mgr_addr = get_manager(addr)
if mgr_addr not in mgrs:
mgrs[mgr_addr] = []
mgrs[mgr_addr].append(ad... | python | def addrs2managers(addrs):
'''Map agent addresses to their assumed managers.
.. seealso::
:func:`creamas.util.get_manager`
'''
mgrs = {}
for addr in addrs:
mgr_addr = get_manager(addr)
if mgr_addr not in mgrs:
mgrs[mgr_addr] = []
mgrs[mgr_addr].append(ad... | [
"def",
"addrs2managers",
"(",
"addrs",
")",
":",
"mgrs",
"=",
"{",
"}",
"for",
"addr",
"in",
"addrs",
":",
"mgr_addr",
"=",
"get_manager",
"(",
"addr",
")",
"if",
"mgr_addr",
"not",
"in",
"mgrs",
":",
"mgrs",
"[",
"mgr_addr",
"]",
"=",
"[",
"]",
"m... | Map agent addresses to their assumed managers.
.. seealso::
:func:`creamas.util.get_manager` | [
"Map",
"agent",
"addresses",
"to",
"their",
"assumed",
"managers",
"."
] | 54dc3e31c97a3f938e58272f8ab80b6bcafeff58 | https://github.com/assamite/creamas/blob/54dc3e31c97a3f938e58272f8ab80b6bcafeff58/creamas/util.py#L199-L212 | train | Map agent addresses to their assumed managers. |
ronhanson/python-tbx | tbx/template.py | create_jinja_env | def create_jinja_env(template_path):
"""
Creates a Jinja2 environment with a specific template path.
"""
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_path),
block_start_string='{%',
block_end_string='%}',
variable_start_string='${',
vari... | python | def create_jinja_env(template_path):
"""
Creates a Jinja2 environment with a specific template path.
"""
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_path),
block_start_string='{%',
block_end_string='%}',
variable_start_string='${',
vari... | [
"def",
"create_jinja_env",
"(",
"template_path",
")",
":",
"jinja_env",
"=",
"jinja2",
".",
"Environment",
"(",
"loader",
"=",
"jinja2",
".",
"FileSystemLoader",
"(",
"template_path",
")",
",",
"block_start_string",
"=",
"'{%'",
",",
"block_end_string",
"=",
"'%... | Creates a Jinja2 environment with a specific template path. | [
"Creates",
"a",
"Jinja2",
"environment",
"with",
"a",
"specific",
"template",
"path",
"."
] | 87f72ae0cadecafbcd144f1e930181fba77f6b83 | https://github.com/ronhanson/python-tbx/blob/87f72ae0cadecafbcd144f1e930181fba77f6b83/tbx/template.py#L15-L35 | train | Creates a Jinja2 environment with a specific template path. |
ronhanson/python-tbx | tbx/template.py | render_template | def render_template(env, filename, values=None):
"""
Render a jinja template
"""
if not values:
values = {}
tmpl = env.get_template(filename)
return tmpl.render(values) | python | def render_template(env, filename, values=None):
"""
Render a jinja template
"""
if not values:
values = {}
tmpl = env.get_template(filename)
return tmpl.render(values) | [
"def",
"render_template",
"(",
"env",
",",
"filename",
",",
"values",
"=",
"None",
")",
":",
"if",
"not",
"values",
":",
"values",
"=",
"{",
"}",
"tmpl",
"=",
"env",
".",
"get_template",
"(",
"filename",
")",
"return",
"tmpl",
".",
"render",
"(",
"va... | Render a jinja template | [
"Render",
"a",
"jinja",
"template"
] | 87f72ae0cadecafbcd144f1e930181fba77f6b83 | https://github.com/ronhanson/python-tbx/blob/87f72ae0cadecafbcd144f1e930181fba77f6b83/tbx/template.py#L38-L45 | train | Render a jinja template |
ronhanson/python-tbx | tbx/template.py | template | def template(filename):
"""
Decorator
"""
def method_wrapper(method):
@wraps(method)
def jinja_wrapper(*args, **kwargs):
ret = method(*args, **kwargs)
return render_template(filename, ret)
return jinja_wrapper
return method_wrapper | python | def template(filename):
"""
Decorator
"""
def method_wrapper(method):
@wraps(method)
def jinja_wrapper(*args, **kwargs):
ret = method(*args, **kwargs)
return render_template(filename, ret)
return jinja_wrapper
return method_wrapper | [
"def",
"template",
"(",
"filename",
")",
":",
"def",
"method_wrapper",
"(",
"method",
")",
":",
"@",
"wraps",
"(",
"method",
")",
"def",
"jinja_wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"ret",
"=",
"method",
"(",
"*",
"args",
"... | Decorator | [
"Decorator"
] | 87f72ae0cadecafbcd144f1e930181fba77f6b83 | https://github.com/ronhanson/python-tbx/blob/87f72ae0cadecafbcd144f1e930181fba77f6b83/tbx/template.py#L48-L61 | train | Decorator for creating a Jinja2 template |
urain39/KngetPy | knget/base.py | Knget._debug_info | def _debug_info(self):
"""Show a list of recently variables info.
"""
self._msg('DEBUG')
self._msg2('WorkDir: {0}'.format(self._curdir))
self._msg2('Cookies: {0}'.format(self._session.cookies))
self._msg2('Headers: {0}'.format(self._session.headers))
self._msg2('C... | python | def _debug_info(self):
"""Show a list of recently variables info.
"""
self._msg('DEBUG')
self._msg2('WorkDir: {0}'.format(self._curdir))
self._msg2('Cookies: {0}'.format(self._session.cookies))
self._msg2('Headers: {0}'.format(self._session.headers))
self._msg2('C... | [
"def",
"_debug_info",
"(",
"self",
")",
":",
"self",
".",
"_msg",
"(",
"'DEBUG'",
")",
"self",
".",
"_msg2",
"(",
"'WorkDir: {0}'",
".",
"format",
"(",
"self",
".",
"_curdir",
")",
")",
"self",
".",
"_msg2",
"(",
"'Cookies: {0}'",
".",
"format",
"(",
... | Show a list of recently variables info. | [
"Show",
"a",
"list",
"of",
"recently",
"variables",
"info",
"."
] | 00986bc16a497cee08aceb1c072f6187f152ee5d | https://github.com/urain39/KngetPy/blob/00986bc16a497cee08aceb1c072f6187f152ee5d/knget/base.py#L174-L183 | train | Show a list of recently variables info. |
urain39/KngetPy | knget/base.py | KngetCommand.register | def register(self, argtypes=r'M', help_msg=None):
"""Register a method to a command.
NOTE: Method registered here is unbound method,
e.g. registered `run` command -> `KngetShell.run`
So we call it should add `self` at first.
See also: KngetShell.execute()
... | python | def register(self, argtypes=r'M', help_msg=None):
"""Register a method to a command.
NOTE: Method registered here is unbound method,
e.g. registered `run` command -> `KngetShell.run`
So we call it should add `self` at first.
See also: KngetShell.execute()
... | [
"def",
"register",
"(",
"self",
",",
"argtypes",
"=",
"r'M'",
",",
"help_msg",
"=",
"None",
")",
":",
"def",
"format_args",
"(",
"method",
")",
":",
"def",
"wrapped_method",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"args_count",
"=",
"len... | Register a method to a command.
NOTE: Method registered here is unbound method,
e.g. registered `run` command -> `KngetShell.run`
So we call it should add `self` at first.
See also: KngetShell.execute()
:param argtypes: a str of the command args type.
... | [
"Register",
"a",
"method",
"to",
"a",
"command",
"."
] | 00986bc16a497cee08aceb1c072f6187f152ee5d | https://github.com/urain39/KngetPy/blob/00986bc16a497cee08aceb1c072f6187f152ee5d/knget/base.py#L497-L563 | train | Register a method to a command. |
urain39/KngetPy | knget/base.py | KngetShell.run | def run(self, tags, begin, end=False):
"""Override method of class Knget
"""
if not end:
end = begin
# Type `H` doesn't cast anything, so we
# manually cast the strings end to integer.
super(KngetShell, self).run(tags, begin, int(end)) | python | def run(self, tags, begin, end=False):
"""Override method of class Knget
"""
if not end:
end = begin
# Type `H` doesn't cast anything, so we
# manually cast the strings end to integer.
super(KngetShell, self).run(tags, begin, int(end)) | [
"def",
"run",
"(",
"self",
",",
"tags",
",",
"begin",
",",
"end",
"=",
"False",
")",
":",
"if",
"not",
"end",
":",
"end",
"=",
"begin",
"# Type `H` doesn't cast anything, so we",
"# manually cast the strings end to integer.",
"super",
"(",
"KngetShell",
",",
"se... | Override method of class Knget | [
"Override",
"method",
"of",
"class",
"Knget"
] | 00986bc16a497cee08aceb1c072f6187f152ee5d | https://github.com/urain39/KngetPy/blob/00986bc16a497cee08aceb1c072f6187f152ee5d/knget/base.py#L584-L592 | train | Override method of class Knget
|
urain39/KngetPy | knget/base.py | KngetShell.dbgrun | def dbgrun(self, source):
"""Debug run. based on exec(), unsafe.
"""
try:
exec(source)
except Exception as e:
self._msg2('Error: {0}'.format(e)) | python | def dbgrun(self, source):
"""Debug run. based on exec(), unsafe.
"""
try:
exec(source)
except Exception as e:
self._msg2('Error: {0}'.format(e)) | [
"def",
"dbgrun",
"(",
"self",
",",
"source",
")",
":",
"try",
":",
"exec",
"(",
"source",
")",
"except",
"Exception",
"as",
"e",
":",
"self",
".",
"_msg2",
"(",
"'Error: {0}'",
".",
"format",
"(",
"e",
")",
")"
] | Debug run. based on exec(), unsafe. | [
"Debug",
"run",
".",
"based",
"on",
"exec",
"()",
"unsafe",
"."
] | 00986bc16a497cee08aceb1c072f6187f152ee5d | https://github.com/urain39/KngetPy/blob/00986bc16a497cee08aceb1c072f6187f152ee5d/knget/base.py#L689-L695 | train | Run the debug run. |
uogbuji/versa | tools/py/writer/md.py | write | def write(models, out=None, base=None, propertybase=None, shorteners=None, logger=logging):
'''
models - input Versa models from which output is generated. Must be a sequence
object, not an iterator
'''
assert out is not None #Output stream required
if not isinstance(models, list): m... | python | def write(models, out=None, base=None, propertybase=None, shorteners=None, logger=logging):
'''
models - input Versa models from which output is generated. Must be a sequence
object, not an iterator
'''
assert out is not None #Output stream required
if not isinstance(models, list): m... | [
"def",
"write",
"(",
"models",
",",
"out",
"=",
"None",
",",
"base",
"=",
"None",
",",
"propertybase",
"=",
"None",
",",
"shorteners",
"=",
"None",
",",
"logger",
"=",
"logging",
")",
":",
"assert",
"out",
"is",
"not",
"None",
"#Output stream required",
... | models - input Versa models from which output is generated. Must be a sequence
object, not an iterator | [
"models",
"-",
"input",
"Versa",
"models",
"from",
"which",
"output",
"is",
"generated",
".",
"Must",
"be",
"a",
"sequence",
"object",
"not",
"an",
"iterator"
] | f092ffc7ed363a5b170890955168500f32de0dd5 | https://github.com/uogbuji/versa/blob/f092ffc7ed363a5b170890955168500f32de0dd5/tools/py/writer/md.py#L42-L79 | train | Writes a list of Versa models to a file - like object out. |
aacanakin/glim | glim/app.py | Glim.register_routes | def register_routes(self):
"""
Function creates instances of controllers, adds into bottle routes
"""
routes = self.flatten_urls(self.urls)
self.controllers = {}
controller_names = set()
for route in routes:
cname = route['endpoint'].split('.')[0]
... | python | def register_routes(self):
"""
Function creates instances of controllers, adds into bottle routes
"""
routes = self.flatten_urls(self.urls)
self.controllers = {}
controller_names = set()
for route in routes:
cname = route['endpoint'].split('.')[0]
... | [
"def",
"register_routes",
"(",
"self",
")",
":",
"routes",
"=",
"self",
".",
"flatten_urls",
"(",
"self",
".",
"urls",
")",
"self",
".",
"controllers",
"=",
"{",
"}",
"controller_names",
"=",
"set",
"(",
")",
"for",
"route",
"in",
"routes",
":",
"cname... | Function creates instances of controllers, adds into bottle routes | [
"Function",
"creates",
"instances",
"of",
"controllers",
"adds",
"into",
"bottle",
"routes"
] | 71a20ac149a1292c0d6c1dc7414985ea51854f7a | https://github.com/aacanakin/glim/blob/71a20ac149a1292c0d6c1dc7414985ea51854f7a/glim/app.py#L62-L82 | train | Function creates instances of controllers adds into bottle routes
|
aacanakin/glim | glim/app.py | Glim.register_extensions | def register_extensions(self):
"""
Function registers extensions given extensions list
Args
----
extensions (list) : the extensions dict on app.config.<env>
Raises
------
Exception: Raises exception when extension can't be loaded
properly... | python | def register_extensions(self):
"""
Function registers extensions given extensions list
Args
----
extensions (list) : the extensions dict on app.config.<env>
Raises
------
Exception: Raises exception when extension can't be loaded
properly... | [
"def",
"register_extensions",
"(",
"self",
")",
":",
"try",
":",
"for",
"extension",
",",
"config",
"in",
"self",
".",
"config",
"[",
"'extensions'",
"]",
".",
"items",
"(",
")",
":",
"extension_bstr",
"=",
"''",
"# gather package name if exists",
"extension_p... | Function registers extensions given extensions list
Args
----
extensions (list) : the extensions dict on app.config.<env>
Raises
------
Exception: Raises exception when extension can't be loaded
properly. | [
"Function",
"registers",
"extensions",
"given",
"extensions",
"list"
] | 71a20ac149a1292c0d6c1dc7414985ea51854f7a | https://github.com/aacanakin/glim/blob/71a20ac149a1292c0d6c1dc7414985ea51854f7a/glim/app.py#L84-L131 | train | Function registers extensions given extensions list |
aacanakin/glim | glim/app.py | Glim.register_log | def register_log(self):
"""
Function registers Log facade using configuration in app.config.<env>.
Note:
The Log facade will be registered using default configuration
if there isn't any 'log' key in app.config.<env>.
"""
if not empty('log', self.config):
... | python | def register_log(self):
"""
Function registers Log facade using configuration in app.config.<env>.
Note:
The Log facade will be registered using default configuration
if there isn't any 'log' key in app.config.<env>.
"""
if not empty('log', self.config):
... | [
"def",
"register_log",
"(",
"self",
")",
":",
"if",
"not",
"empty",
"(",
"'log'",
",",
"self",
".",
"config",
")",
":",
"if",
"not",
"empty",
"(",
"'glim'",
",",
"self",
".",
"config",
"[",
"'log'",
"]",
")",
":",
"GlimLog",
".",
"boot",
"(",
"na... | Function registers Log facade using configuration in app.config.<env>.
Note:
The Log facade will be registered using default configuration
if there isn't any 'log' key in app.config.<env>. | [
"Function",
"registers",
"Log",
"facade",
"using",
"configuration",
"in",
"app",
".",
"config",
".",
"<env",
">",
"."
] | 71a20ac149a1292c0d6c1dc7414985ea51854f7a | https://github.com/aacanakin/glim/blob/71a20ac149a1292c0d6c1dc7414985ea51854f7a/glim/app.py#L133-L154 | train | Function registers Log facade using configuration in app. config. |
aacanakin/glim | glim/app.py | Glim.register_ssl_context | def register_ssl_context(self):
"""
Function detects ssl context
"""
if not empty('ssl', self.config['app']):
self.ssl_context = self.config['app']['ssl']
else:
self.ssl_context = None | python | def register_ssl_context(self):
"""
Function detects ssl context
"""
if not empty('ssl', self.config['app']):
self.ssl_context = self.config['app']['ssl']
else:
self.ssl_context = None | [
"def",
"register_ssl_context",
"(",
"self",
")",
":",
"if",
"not",
"empty",
"(",
"'ssl'",
",",
"self",
".",
"config",
"[",
"'app'",
"]",
")",
":",
"self",
".",
"ssl_context",
"=",
"self",
".",
"config",
"[",
"'app'",
"]",
"[",
"'ssl'",
"]",
"else",
... | Function detects ssl context | [
"Function",
"detects",
"ssl",
"context"
] | 71a20ac149a1292c0d6c1dc7414985ea51854f7a | https://github.com/aacanakin/glim/blob/71a20ac149a1292c0d6c1dc7414985ea51854f7a/glim/app.py#L156-L163 | train | Function detects ssl context |
aacanakin/glim | glim/app.py | Glim.flatten_urls | def flatten_urls(self, urls):
"""
Function flatten urls for route grouping feature of glim.
Args
----
urls (dict): a dict of url definitions.
current_key (unknown type): a dict or a string marking the
current key that is used for recursive calls.
... | python | def flatten_urls(self, urls):
"""
Function flatten urls for route grouping feature of glim.
Args
----
urls (dict): a dict of url definitions.
current_key (unknown type): a dict or a string marking the
current key that is used for recursive calls.
... | [
"def",
"flatten_urls",
"(",
"self",
",",
"urls",
")",
":",
"available_methods",
"=",
"[",
"'POST'",
",",
"'PUT'",
",",
"'OPTIONS'",
",",
"'GET'",
",",
"'DELETE'",
",",
"'TRACE'",
",",
"'COPY'",
"]",
"ruleset",
"=",
"[",
"]",
"for",
"route",
",",
"endpo... | Function flatten urls for route grouping feature of glim.
Args
----
urls (dict): a dict of url definitions.
current_key (unknown type): a dict or a string marking the
current key that is used for recursive calls.
ruleset (dict): the ruleset that is eventually r... | [
"Function",
"flatten",
"urls",
"for",
"route",
"grouping",
"feature",
"of",
"glim",
"."
] | 71a20ac149a1292c0d6c1dc7414985ea51854f7a | https://github.com/aacanakin/glim/blob/71a20ac149a1292c0d6c1dc7414985ea51854f7a/glim/app.py#L165-L209 | train | Function flatten urls for route grouping feature of glim. |
TUNE-Archive/freight_forwarder | freight_forwarder/cli/info.py | InfoCommand._info | def _info(self, args, **extra_args):
"""Print freight forwarder info to the user.
"""
if not isinstance(args, argparse.Namespace):
raise logger.error(Exception("args should of an instance of argparse.Namespace"))
logger.info("Freight Forwarder: {0}".format(VERSION))
... | python | def _info(self, args, **extra_args):
"""Print freight forwarder info to the user.
"""
if not isinstance(args, argparse.Namespace):
raise logger.error(Exception("args should of an instance of argparse.Namespace"))
logger.info("Freight Forwarder: {0}".format(VERSION))
... | [
"def",
"_info",
"(",
"self",
",",
"args",
",",
"*",
"*",
"extra_args",
")",
":",
"if",
"not",
"isinstance",
"(",
"args",
",",
"argparse",
".",
"Namespace",
")",
":",
"raise",
"logger",
".",
"error",
"(",
"Exception",
"(",
"\"args should of an instance of a... | Print freight forwarder info to the user. | [
"Print",
"freight",
"forwarder",
"info",
"to",
"the",
"user",
"."
] | 6ea4a49f474ec04abb8bb81b175c774a16b5312f | https://github.com/TUNE-Archive/freight_forwarder/blob/6ea4a49f474ec04abb8bb81b175c774a16b5312f/freight_forwarder/cli/info.py#L38-L47 | train | Print freight forwarder info to the user. |
20c/pluginmgr | pluginmgr/__init__.py | PluginManager.register | def register(self, typ):
""" register a plugin """
# should be able to combine class/instance namespace, and inherit from either
# would need to store meta or rely on copy ctor
def _func(cls):
if typ in self._class:
raise ValueError("duplicated type name '%s'"... | python | def register(self, typ):
""" register a plugin """
# should be able to combine class/instance namespace, and inherit from either
# would need to store meta or rely on copy ctor
def _func(cls):
if typ in self._class:
raise ValueError("duplicated type name '%s'"... | [
"def",
"register",
"(",
"self",
",",
"typ",
")",
":",
"# should be able to combine class/instance namespace, and inherit from either",
"# would need to store meta or rely on copy ctor",
"def",
"_func",
"(",
"cls",
")",
":",
"if",
"typ",
"in",
"self",
".",
"_class",
":",
... | register a plugin | [
"register",
"a",
"plugin"
] | ea19edab6d145f539641c304745acd4ab2c67eb7 | https://github.com/20c/pluginmgr/blob/ea19edab6d145f539641c304745acd4ab2c67eb7/pluginmgr/__init__.py#L167-L177 | train | register a plugin |
20c/pluginmgr | pluginmgr/__init__.py | PluginManager.get_plugin_class | def get_plugin_class(self, typ):
"""
get class by name
"""
if typ in self._class:
return self._class[typ]
# try to import by same name
try:
importlib.import_module("%s.%s" % (self.namespace, typ))
if typ in self._class:
... | python | def get_plugin_class(self, typ):
"""
get class by name
"""
if typ in self._class:
return self._class[typ]
# try to import by same name
try:
importlib.import_module("%s.%s" % (self.namespace, typ))
if typ in self._class:
... | [
"def",
"get_plugin_class",
"(",
"self",
",",
"typ",
")",
":",
"if",
"typ",
"in",
"self",
".",
"_class",
":",
"return",
"self",
".",
"_class",
"[",
"typ",
"]",
"# try to import by same name",
"try",
":",
"importlib",
".",
"import_module",
"(",
"\"%s.%s\"",
... | get class by name | [
"get",
"class",
"by",
"name"
] | ea19edab6d145f539641c304745acd4ab2c67eb7 | https://github.com/20c/pluginmgr/blob/ea19edab6d145f539641c304745acd4ab2c67eb7/pluginmgr/__init__.py#L186-L202 | train | get class by name |
projectshift/shift-boiler | boiler/errors.py | register_error_handler | def register_error_handler(app, handler=None):
"""
Register error handler
Registers an exception handler on the app instance for every type of
exception code werkzeug is aware about.
:param app: flask.Flask - flask application instance
:param handler: function - the handler
:return: None
... | python | def register_error_handler(app, handler=None):
"""
Register error handler
Registers an exception handler on the app instance for every type of
exception code werkzeug is aware about.
:param app: flask.Flask - flask application instance
:param handler: function - the handler
:return: None
... | [
"def",
"register_error_handler",
"(",
"app",
",",
"handler",
"=",
"None",
")",
":",
"if",
"not",
"handler",
":",
"handler",
"=",
"default_error_handler",
"for",
"code",
"in",
"exceptions",
".",
"default_exceptions",
".",
"keys",
"(",
")",
":",
"app",
".",
... | Register error handler
Registers an exception handler on the app instance for every type of
exception code werkzeug is aware about.
:param app: flask.Flask - flask application instance
:param handler: function - the handler
:return: None | [
"Register",
"error",
"handler",
"Registers",
"an",
"exception",
"handler",
"on",
"the",
"app",
"instance",
"for",
"every",
"type",
"of",
"exception",
"code",
"werkzeug",
"is",
"aware",
"about",
"."
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/errors.py#L6-L20 | train | Registers an error handler on the app instance for every type of
exception code werkzeug is aware about. |
projectshift/shift-boiler | boiler/errors.py | default_error_handler | def default_error_handler(exception):
"""
Default error handler
Will display an error page with the corresponding error code from template
directory, for example, a not found will load a 404.html etc.
Will first look in userland app templates and if not found, fallback to
boiler templates to dis... | python | def default_error_handler(exception):
"""
Default error handler
Will display an error page with the corresponding error code from template
directory, for example, a not found will load a 404.html etc.
Will first look in userland app templates and if not found, fallback to
boiler templates to dis... | [
"def",
"default_error_handler",
"(",
"exception",
")",
":",
"http_exception",
"=",
"isinstance",
"(",
"exception",
",",
"exceptions",
".",
"HTTPException",
")",
"code",
"=",
"exception",
".",
"code",
"if",
"http_exception",
"else",
"500",
"# log exceptions only (app... | Default error handler
Will display an error page with the corresponding error code from template
directory, for example, a not found will load a 404.html etc.
Will first look in userland app templates and if not found, fallback to
boiler templates to display a default page.
:param exception: Except... | [
"Default",
"error",
"handler",
"Will",
"display",
"an",
"error",
"page",
"with",
"the",
"corresponding",
"error",
"code",
"from",
"template",
"directory",
"for",
"example",
"a",
"not",
"found",
"will",
"load",
"a",
"404",
".",
"html",
"etc",
".",
"Will",
"... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/errors.py#L23-L48 | train | Default error handler for userland templates. |
projectshift/shift-boiler | boiler/errors.py | json_error_handler | def json_error_handler(exception):
"""
Json error handler
Returns a json message for th excepion with appripriate response code and
application/json content type.
:param exception:
:return:
"""
http_exception = isinstance(exception, exceptions.HTTPException)
code = exception.code if ... | python | def json_error_handler(exception):
"""
Json error handler
Returns a json message for th excepion with appripriate response code and
application/json content type.
:param exception:
:return:
"""
http_exception = isinstance(exception, exceptions.HTTPException)
code = exception.code if ... | [
"def",
"json_error_handler",
"(",
"exception",
")",
":",
"http_exception",
"=",
"isinstance",
"(",
"exception",
",",
"exceptions",
".",
"HTTPException",
")",
"code",
"=",
"exception",
".",
"code",
"if",
"http_exception",
"else",
"500",
"# log exceptions only (app de... | Json error handler
Returns a json message for th excepion with appripriate response code and
application/json content type.
:param exception:
:return: | [
"Json",
"error",
"handler",
"Returns",
"a",
"json",
"message",
"for",
"th",
"excepion",
"with",
"appripriate",
"response",
"code",
"and",
"application",
"/",
"json",
"content",
"type",
".",
":",
"param",
"exception",
":",
":",
"return",
":"
] | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/errors.py#L51-L68 | train | Json error handler |
projectshift/shift-boiler | boiler/errors.py | template_error_handler | def template_error_handler(exception):
"""
Template error handler
Renders a template for the error code if exception is know by werkzeug.
Will attempt to load a template from userland app templates and then
fall back to boiler templates if not found.
:param exception: Exception
:return:
... | python | def template_error_handler(exception):
"""
Template error handler
Renders a template for the error code if exception is know by werkzeug.
Will attempt to load a template from userland app templates and then
fall back to boiler templates if not found.
:param exception: Exception
:return:
... | [
"def",
"template_error_handler",
"(",
"exception",
")",
":",
"http_exception",
"=",
"isinstance",
"(",
"exception",
",",
"exceptions",
".",
"HTTPException",
")",
"code",
"=",
"exception",
".",
"code",
"if",
"http_exception",
"else",
"500",
"# log exceptions only (ap... | Template error handler
Renders a template for the error code if exception is know by werkzeug.
Will attempt to load a template from userland app templates and then
fall back to boiler templates if not found.
:param exception: Exception
:return: | [
"Template",
"error",
"handler",
"Renders",
"a",
"template",
"for",
"the",
"error",
"code",
"if",
"exception",
"is",
"know",
"by",
"werkzeug",
".",
"Will",
"attempt",
"to",
"load",
"a",
"template",
"from",
"userland",
"app",
"templates",
"and",
"then",
"fall"... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/errors.py#L71-L88 | train | Template error handler |
projectshift/shift-boiler | boiler/errors.py | json_url_error_handler | def json_url_error_handler(urls=()):
"""
Closure: Json URL error handler
Checks if request matches provided url prefix and returns json response if
it does. Otherwise falls back to template error handler. This is usefull
if you want to return json errors for a subset of your routes.
Register th... | python | def json_url_error_handler(urls=()):
"""
Closure: Json URL error handler
Checks if request matches provided url prefix and returns json response if
it does. Otherwise falls back to template error handler. This is usefull
if you want to return json errors for a subset of your routes.
Register th... | [
"def",
"json_url_error_handler",
"(",
"urls",
"=",
"(",
")",
")",
":",
"if",
"type",
"(",
"urls",
")",
"is",
"str",
":",
"urls",
"=",
"[",
"urls",
"]",
"# the handler itself",
"def",
"handler",
"(",
"exception",
")",
":",
"http_exception",
"=",
"isinstan... | Closure: Json URL error handler
Checks if request matches provided url prefix and returns json response if
it does. Otherwise falls back to template error handler. This is usefull
if you want to return json errors for a subset of your routes.
Register this by calling a closure:
register_error_h... | [
"Closure",
":",
"Json",
"URL",
"error",
"handler",
"Checks",
"if",
"request",
"matches",
"provided",
"url",
"prefix",
"and",
"returns",
"json",
"response",
"if",
"it",
"does",
".",
"Otherwise",
"falls",
"back",
"to",
"template",
"error",
"handler",
".",
"Thi... | 8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b | https://github.com/projectshift/shift-boiler/blob/8e6f3a3e4b9493fb6c8bd16bed160ede153bfb0b/boiler/errors.py#L91-L130 | train | Json URL error handler |
ethan92429/onshapepy | onshapepy/core/onshape.py | Onshape._make_nonce | def _make_nonce(self):
'''
Generate a unique ID for the request, 25 chars in length
Returns:
- str: Cryptographic nonce
'''
chars = string.digits + string.ascii_letters
nonce = ''.join(random.choice(chars) for i in range(25))
if self._logging:
... | python | def _make_nonce(self):
'''
Generate a unique ID for the request, 25 chars in length
Returns:
- str: Cryptographic nonce
'''
chars = string.digits + string.ascii_letters
nonce = ''.join(random.choice(chars) for i in range(25))
if self._logging:
... | [
"def",
"_make_nonce",
"(",
"self",
")",
":",
"chars",
"=",
"string",
".",
"digits",
"+",
"string",
".",
"ascii_letters",
"nonce",
"=",
"''",
".",
"join",
"(",
"random",
".",
"choice",
"(",
"chars",
")",
"for",
"i",
"in",
"range",
"(",
"25",
")",
")... | Generate a unique ID for the request, 25 chars in length
Returns:
- str: Cryptographic nonce | [
"Generate",
"a",
"unique",
"ID",
"for",
"the",
"request",
"25",
"chars",
"in",
"length"
] | 61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df | https://github.com/ethan92429/onshapepy/blob/61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df/onshapepy/core/onshape.py#L60-L74 | train | Generate a unique ID for the request |
ethan92429/onshapepy | onshapepy/core/onshape.py | Onshape._make_auth | def _make_auth(self, method, date, nonce, path, query={}, ctype='application/json'):
'''
Create the request signature to authenticate
Args:
- method (str): HTTP method
- date (str): HTTP date header string
- nonce (str): Cryptographic nonce
- path... | python | def _make_auth(self, method, date, nonce, path, query={}, ctype='application/json'):
'''
Create the request signature to authenticate
Args:
- method (str): HTTP method
- date (str): HTTP date header string
- nonce (str): Cryptographic nonce
- path... | [
"def",
"_make_auth",
"(",
"self",
",",
"method",
",",
"date",
",",
"nonce",
",",
"path",
",",
"query",
"=",
"{",
"}",
",",
"ctype",
"=",
"'application/json'",
")",
":",
"query",
"=",
"urlencode",
"(",
"query",
")",
"hmac_str",
"=",
"(",
"method",
"+"... | Create the request signature to authenticate
Args:
- method (str): HTTP method
- date (str): HTTP date header string
- nonce (str): Cryptographic nonce
- path (str): URL pathname
- query (dict, default={}): URL query string in key-value pairs
... | [
"Create",
"the",
"request",
"signature",
"to",
"authenticate"
] | 61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df | https://github.com/ethan92429/onshapepy/blob/61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df/onshapepy/core/onshape.py#L76-L105 | train | Create the request signature to authenticate the user |
ethan92429/onshapepy | onshapepy/core/onshape.py | Onshape._make_headers | def _make_headers(self, method, path, query={}, headers={}):
'''
Creates a headers object to sign the request
Args:
- method (str): HTTP method
- path (str): Request path, e.g. /api/documents. No query string
- query (dict, default={}): Query string in key-va... | python | def _make_headers(self, method, path, query={}, headers={}):
'''
Creates a headers object to sign the request
Args:
- method (str): HTTP method
- path (str): Request path, e.g. /api/documents. No query string
- query (dict, default={}): Query string in key-va... | [
"def",
"_make_headers",
"(",
"self",
",",
"method",
",",
"path",
",",
"query",
"=",
"{",
"}",
",",
"headers",
"=",
"{",
"}",
")",
":",
"date",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
".",
"strftime",
"(",
"'%a, %d %b %Y %H:%M:%S GMT'... | Creates a headers object to sign the request
Args:
- method (str): HTTP method
- path (str): Request path, e.g. /api/documents. No query string
- query (dict, default={}): Query string in key-value format
- headers (dict, default={}): Other headers to pass in
... | [
"Creates",
"a",
"headers",
"object",
"to",
"sign",
"the",
"request"
] | 61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df | https://github.com/ethan92429/onshapepy/blob/61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df/onshapepy/core/onshape.py#L107-L140 | train | Creates a headers object to sign the request |
ethan92429/onshapepy | onshapepy/core/onshape.py | Onshape.request | def request(self, method, path, query={}, headers={}, body={}, base_url=None):
'''
Issues a request to Onshape
Args:
- method (str): HTTP method
- path (str): Path e.g. /api/documents/:id
- query (dict, default={}): Query params in key-value pairs
... | python | def request(self, method, path, query={}, headers={}, body={}, base_url=None):
'''
Issues a request to Onshape
Args:
- method (str): HTTP method
- path (str): Path e.g. /api/documents/:id
- query (dict, default={}): Query params in key-value pairs
... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"path",
",",
"query",
"=",
"{",
"}",
",",
"headers",
"=",
"{",
"}",
",",
"body",
"=",
"{",
"}",
",",
"base_url",
"=",
"None",
")",
":",
"req_headers",
"=",
"self",
".",
"_make_headers",
"(",
"met... | Issues a request to Onshape
Args:
- method (str): HTTP method
- path (str): Path e.g. /api/documents/:id
- query (dict, default={}): Query params in key-value pairs
- headers (dict, default={}): Key-value pairs of headers
- body (dict, default={}): B... | [
"Issues",
"a",
"request",
"to",
"Onshape"
] | 61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df | https://github.com/ethan92429/onshapepy/blob/61dc7ccbdc6095fa6cc3b4a414e2f72d03d1c9df/onshapepy/core/onshape.py#L142-L194 | train | Issues a request to Onshape s API. |
tech-pi/doufo | src/python/doufo/convert.py | tuple_type_compare | def tuple_type_compare(types0, types1):
"""doufo.tuple_type_compare: compare two types
if `types0` is 'bigger' than `types1`, return negative (<0);
otherwise, return positive (>0). Here 'bigger' is defined by
whether they are 'parent and child', or ituitively bigger
Args:
... | python | def tuple_type_compare(types0, types1):
"""doufo.tuple_type_compare: compare two types
if `types0` is 'bigger' than `types1`, return negative (<0);
otherwise, return positive (>0). Here 'bigger' is defined by
whether they are 'parent and child', or ituitively bigger
Args:
... | [
"def",
"tuple_type_compare",
"(",
"types0",
",",
"types1",
")",
":",
"compares",
"=",
"[",
"single_type_compare",
"(",
"types0",
"[",
"0",
"]",
",",
"types1",
"[",
"0",
"]",
")",
",",
"single_type_compare",
"(",
"types0",
"[",
"1",
"]",
",",
"types1",
... | doufo.tuple_type_compare: compare two types
if `types0` is 'bigger' than `types1`, return negative (<0);
otherwise, return positive (>0). Here 'bigger' is defined by
whether they are 'parent and child', or ituitively bigger
Args:
types0 (`type`): types0
types1... | [
"doufo",
".",
"tuple_type_compare",
":",
"compare",
"two",
"types",
"if",
"types0",
"is",
"bigger",
"than",
"types1",
"return",
"negative",
"(",
"<0",
")",
";",
"otherwise",
"return",
"positive",
"(",
">",
"0",
")",
".",
"Here",
"bigger",
"is",
"defined",
... | 3d375fef30670597768a6eef809b75b4b1b5a3fd | https://github.com/tech-pi/doufo/blob/3d375fef30670597768a6eef809b75b4b1b5a3fd/src/python/doufo/convert.py#L96-L116 | train | doufo. tuple_type_compare - compare two types
articles |
tech-pi/doufo | src/python/doufo/convert.py | ConvertersDict.sorted_converters_keys | def sorted_converters_keys(self):
"""doufo.ConvertDict().sorted_converters_key: sort converter keys
sort key according to their relationship (if parent- and child-class)
or their hash value.
Args:
`self`
"""
keys = sorted(self.converters.keys(),
... | python | def sorted_converters_keys(self):
"""doufo.ConvertDict().sorted_converters_key: sort converter keys
sort key according to their relationship (if parent- and child-class)
or their hash value.
Args:
`self`
"""
keys = sorted(self.converters.keys(),
... | [
"def",
"sorted_converters_keys",
"(",
"self",
")",
":",
"keys",
"=",
"sorted",
"(",
"self",
".",
"converters",
".",
"keys",
"(",
")",
",",
"key",
"=",
"cmp_to_key",
"(",
"tuple_type_compare",
")",
")",
"return",
"{",
"k",
":",
"self",
".",
"converters",
... | doufo.ConvertDict().sorted_converters_key: sort converter keys
sort key according to their relationship (if parent- and child-class)
or their hash value.
Args:
`self` | [
"doufo",
".",
"ConvertDict",
"()",
".",
"sorted_converters_key",
":",
"sort",
"converter",
"keys",
"sort",
"key",
"according",
"to",
"their",
"relationship",
"(",
"if",
"parent",
"-",
"and",
"child",
"-",
"class",
")",
"or",
"their",
"hash",
"value",
".",
... | 3d375fef30670597768a6eef809b75b4b1b5a3fd | https://github.com/tech-pi/doufo/blob/3d375fef30670597768a6eef809b75b4b1b5a3fd/src/python/doufo/convert.py#L28-L37 | train | doufo. ConvertDict. sorted_converters_key - sort converters keys
self |
tech-pi/doufo | src/python/doufo/convert.py | ConvertersDict.register | def register(self, src: type, tar: type) -> Callable[[T], B]:
"""doufo.ConverterDict().register(): A decorator factory to define typing converting decorator
Attributes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
... | python | def register(self, src: type, tar: type) -> Callable[[T], B]:
"""doufo.ConverterDict().register(): A decorator factory to define typing converting decorator
Attributes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
... | [
"def",
"register",
"(",
"self",
",",
"src",
":",
"type",
",",
"tar",
":",
"type",
")",
"->",
"Callable",
"[",
"[",
"T",
"]",
",",
"B",
"]",
":",
"def",
"deco",
"(",
"f",
")",
":",
"self",
".",
"converters",
"[",
"(",
"src",
",",
"tar",
")",
... | doufo.ConverterDict().register(): A decorator factory to define typing converting decorator
Attributes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
Returns:
`f` (`Callable[[T], B]`): a decorater that defin... | [
"doufo",
".",
"ConverterDict",
"()",
".",
"register",
"()",
":",
"A",
"decorator",
"factory",
"to",
"define",
"typing",
"converting",
"decorator",
"Attributes",
":",
"self",
"src",
"(",
"type",
")",
":",
"source",
"type",
"tar",
"(",
"type",
")",
":",
"t... | 3d375fef30670597768a6eef809b75b4b1b5a3fd | https://github.com/tech-pi/doufo/blob/3d375fef30670597768a6eef809b75b4b1b5a3fd/src/python/doufo/convert.py#L39-L52 | train | A decorator factory to define typing converting |
tech-pi/doufo | src/python/doufo/convert.py | ConvertersDict.convert | def convert(self, src: type, tar: type) -> Callable[[T], B]:
""" doufo.ConvertDict().convert: define a converter from `type src` to `type tar`
Attibutes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
Ret... | python | def convert(self, src: type, tar: type) -> Callable[[T], B]:
""" doufo.ConvertDict().convert: define a converter from `type src` to `type tar`
Attibutes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
Ret... | [
"def",
"convert",
"(",
"self",
",",
"src",
":",
"type",
",",
"tar",
":",
"type",
")",
"->",
"Callable",
"[",
"[",
"T",
"]",
",",
"B",
"]",
":",
"return",
"self",
".",
"converters",
"[",
"(",
"src",
",",
"tar",
")",
"]"
] | doufo.ConvertDict().convert: define a converter from `type src` to `type tar`
Attibutes:
`self`
`src` (`type`): source `type`,
`tar` (`type`): target `type`,
Returns:
`converter` (`Callable[[T], B]`): converter from `t... | [
"doufo",
".",
"ConvertDict",
"()",
".",
"convert",
":",
"define",
"a",
"converter",
"from",
"type",
"src",
"to",
"type",
"tar",
"Attibutes",
":",
"self",
"src",
"(",
"type",
")",
":",
"source",
"type",
"tar",
"(",
"type",
")",
":",
"target",
"type",
... | 3d375fef30670597768a6eef809b75b4b1b5a3fd | https://github.com/tech-pi/doufo/blob/3d375fef30670597768a6eef809b75b4b1b5a3fd/src/python/doufo/convert.py#L55-L64 | train | Returns a converter function that converts from source to target type. |
Ceasar/twosheds | twosheds/program.py | Program.gen_tokens | def gen_tokens(self):
"""
>>> list(Program("ls").gen_tokens())
['ls']
>>> list(Program("ls -a").gen_tokens())
['ls', '-a']
>>> list(Program("cd /; pwd").gen_tokens())
['cd', '/', None, 'pwd']
>>> list(Program("'cd /; pwd'").gen_tokens())
['cd /; pw... | python | def gen_tokens(self):
"""
>>> list(Program("ls").gen_tokens())
['ls']
>>> list(Program("ls -a").gen_tokens())
['ls', '-a']
>>> list(Program("cd /; pwd").gen_tokens())
['cd', '/', None, 'pwd']
>>> list(Program("'cd /; pwd'").gen_tokens())
['cd /; pw... | [
"def",
"gen_tokens",
"(",
"self",
")",
":",
"current_token",
"=",
"[",
"]",
"escape",
"=",
"False",
"quote",
"=",
"None",
"skip",
"=",
"0",
"for",
"char",
",",
"peek",
"in",
"zip",
"(",
"self",
".",
"text",
",",
"self",
".",
"text",
"[",
"1",
":"... | >>> list(Program("ls").gen_tokens())
['ls']
>>> list(Program("ls -a").gen_tokens())
['ls', '-a']
>>> list(Program("cd /; pwd").gen_tokens())
['cd', '/', None, 'pwd']
>>> list(Program("'cd /; pwd'").gen_tokens())
['cd /; pwd'] | [
">>>",
"list",
"(",
"Program",
"(",
"ls",
")",
".",
"gen_tokens",
"()",
")",
"[",
"ls",
"]",
">>>",
"list",
"(",
"Program",
"(",
"ls",
"-",
"a",
")",
".",
"gen_tokens",
"()",
")",
"[",
"ls",
"-",
"a",
"]",
">>>",
"list",
"(",
"Program",
"(",
... | 55b0a207e3a06b85e9a9567069b3822a651501a7 | https://github.com/Ceasar/twosheds/blob/55b0a207e3a06b85e9a9567069b3822a651501a7/twosheds/program.py#L39-L94 | train | Generator for all tokens in the text. |
Ceasar/twosheds | twosheds/program.py | Program.gen_sentences | def gen_sentences(self, tokens, aliases=None):
"""
Generate a sequence of sentences from stream of tokens.
"""
if aliases is None:
aliases = {}
for sentence in self._gen_sentences(tokens):
try:
alias = aliases[str(sentence[0])]
... | python | def gen_sentences(self, tokens, aliases=None):
"""
Generate a sequence of sentences from stream of tokens.
"""
if aliases is None:
aliases = {}
for sentence in self._gen_sentences(tokens):
try:
alias = aliases[str(sentence[0])]
... | [
"def",
"gen_sentences",
"(",
"self",
",",
"tokens",
",",
"aliases",
"=",
"None",
")",
":",
"if",
"aliases",
"is",
"None",
":",
"aliases",
"=",
"{",
"}",
"for",
"sentence",
"in",
"self",
".",
"_gen_sentences",
"(",
"tokens",
")",
":",
"try",
":",
"ali... | Generate a sequence of sentences from stream of tokens. | [
"Generate",
"a",
"sequence",
"of",
"sentences",
"from",
"stream",
"of",
"tokens",
"."
] | 55b0a207e3a06b85e9a9567069b3822a651501a7 | https://github.com/Ceasar/twosheds/blob/55b0a207e3a06b85e9a9567069b3822a651501a7/twosheds/program.py#L106-L122 | train | Generate a sequence of sentences from a stream of tokens. |
ZEDGR/pychal | challonge/api.py | set_timezone | def set_timezone(new_tz=None):
"""Set the timezone for datetime fields.
By default is your machine's time.
If it's called without parameter sets the
local time again.
:keyword param new_tz: timezone string
ex. 'Europe/Athens',
'Asia/Seoul',
'America/Los_Angeles',
'UTC'
... | python | def set_timezone(new_tz=None):
"""Set the timezone for datetime fields.
By default is your machine's time.
If it's called without parameter sets the
local time again.
:keyword param new_tz: timezone string
ex. 'Europe/Athens',
'Asia/Seoul',
'America/Los_Angeles',
'UTC'
... | [
"def",
"set_timezone",
"(",
"new_tz",
"=",
"None",
")",
":",
"global",
"tz",
"if",
"new_tz",
":",
"tz",
"=",
"pytz",
".",
"timezone",
"(",
"new_tz",
")",
"else",
":",
"tz",
"=",
"tzlocal",
".",
"get_localzone",
"(",
")"
] | Set the timezone for datetime fields.
By default is your machine's time.
If it's called without parameter sets the
local time again.
:keyword param new_tz: timezone string
ex. 'Europe/Athens',
'Asia/Seoul',
'America/Los_Angeles',
'UTC'
:return
None | [
"Set",
"the",
"timezone",
"for",
"datetime",
"fields",
".",
"By",
"default",
"is",
"your",
"machine",
"s",
"time",
".",
"If",
"it",
"s",
"called",
"without",
"parameter",
"sets",
"the",
"local",
"time",
"again",
"."
] | 3600fa9e0557a2a14eb1ad0c0711d28dad3693d7 | https://github.com/ZEDGR/pychal/blob/3600fa9e0557a2a14eb1ad0c0711d28dad3693d7/challonge/api.py#L32-L51 | train | Set the timezone for datetime fields. |
ZEDGR/pychal | challonge/api.py | fetch | def fetch(method, uri, params_prefix=None, **params):
"""Fetch the given uri and return the contents of the response."""
params = _prepare_params(params, params_prefix)
if method == "POST" or method == "PUT":
r_data = {"data": params}
else:
r_data = {"params": params}
# build the H... | python | def fetch(method, uri, params_prefix=None, **params):
"""Fetch the given uri and return the contents of the response."""
params = _prepare_params(params, params_prefix)
if method == "POST" or method == "PUT":
r_data = {"data": params}
else:
r_data = {"params": params}
# build the H... | [
"def",
"fetch",
"(",
"method",
",",
"uri",
",",
"params_prefix",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"params",
"=",
"_prepare_params",
"(",
"params",
",",
"params_prefix",
")",
"if",
"method",
"==",
"\"POST\"",
"or",
"method",
"==",
"\"PUT\""... | Fetch the given uri and return the contents of the response. | [
"Fetch",
"the",
"given",
"uri",
"and",
"return",
"the",
"contents",
"of",
"the",
"response",
"."
] | 3600fa9e0557a2a14eb1ad0c0711d28dad3693d7 | https://github.com/ZEDGR/pychal/blob/3600fa9e0557a2a14eb1ad0c0711d28dad3693d7/challonge/api.py#L64-L91 | train | Fetch the given uri and return the contents of the response. |
ZEDGR/pychal | challonge/api.py | fetch_and_parse | def fetch_and_parse(method, uri, params_prefix=None, **params):
"""Fetch the given uri and return python dictionary with parsed data-types."""
response = fetch(method, uri, params_prefix, **params)
return _parse(json.loads(response.text)) | python | def fetch_and_parse(method, uri, params_prefix=None, **params):
"""Fetch the given uri and return python dictionary with parsed data-types."""
response = fetch(method, uri, params_prefix, **params)
return _parse(json.loads(response.text)) | [
"def",
"fetch_and_parse",
"(",
"method",
",",
"uri",
",",
"params_prefix",
"=",
"None",
",",
"*",
"*",
"params",
")",
":",
"response",
"=",
"fetch",
"(",
"method",
",",
"uri",
",",
"params_prefix",
",",
"*",
"*",
"params",
")",
"return",
"_parse",
"(",... | Fetch the given uri and return python dictionary with parsed data-types. | [
"Fetch",
"the",
"given",
"uri",
"and",
"return",
"python",
"dictionary",
"with",
"parsed",
"data",
"-",
"types",
"."
] | 3600fa9e0557a2a14eb1ad0c0711d28dad3693d7 | https://github.com/ZEDGR/pychal/blob/3600fa9e0557a2a14eb1ad0c0711d28dad3693d7/challonge/api.py#L94-L97 | train | Fetch the given uri and return python dictionary with parsed data - types. |
ZEDGR/pychal | challonge/api.py | _parse | def _parse(data):
"""Recursively convert a json into python data types"""
if not data:
return []
elif isinstance(data, (tuple, list)):
return [_parse(subdata) for subdata in data]
# extract the nested dict. ex. {"tournament": {"url": "7k1safq" ...}}
d = {ik: v for k in data.keys() ... | python | def _parse(data):
"""Recursively convert a json into python data types"""
if not data:
return []
elif isinstance(data, (tuple, list)):
return [_parse(subdata) for subdata in data]
# extract the nested dict. ex. {"tournament": {"url": "7k1safq" ...}}
d = {ik: v for k in data.keys() ... | [
"def",
"_parse",
"(",
"data",
")",
":",
"if",
"not",
"data",
":",
"return",
"[",
"]",
"elif",
"isinstance",
"(",
"data",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"return",
"[",
"_parse",
"(",
"subdata",
")",
"for",
"subdata",
"in",
"data",
... | Recursively convert a json into python data types | [
"Recursively",
"convert",
"a",
"json",
"into",
"python",
"data",
"types"
] | 3600fa9e0557a2a14eb1ad0c0711d28dad3693d7 | https://github.com/ZEDGR/pychal/blob/3600fa9e0557a2a14eb1ad0c0711d28dad3693d7/challonge/api.py#L100-L132 | train | Recursively convert a json into python data types |
ZEDGR/pychal | challonge/api.py | _prepare_params | def _prepare_params(dirty_params, prefix=None):
"""Prepares parameters to be sent to challonge.com.
The `prefix` can be used to convert parameters with keys that
look like ("name", "url", "tournament_type") into something like
("tournament[name]", "tournament[url]", "tournament[tournament_type]"),
... | python | def _prepare_params(dirty_params, prefix=None):
"""Prepares parameters to be sent to challonge.com.
The `prefix` can be used to convert parameters with keys that
look like ("name", "url", "tournament_type") into something like
("tournament[name]", "tournament[url]", "tournament[tournament_type]"),
... | [
"def",
"_prepare_params",
"(",
"dirty_params",
",",
"prefix",
"=",
"None",
")",
":",
"if",
"prefix",
"and",
"prefix",
".",
"endswith",
"(",
"'[]'",
")",
":",
"keys",
"=",
"[",
"]",
"values",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"dirty_params",
... | Prepares parameters to be sent to challonge.com.
The `prefix` can be used to convert parameters with keys that
look like ("name", "url", "tournament_type") into something like
("tournament[name]", "tournament[url]", "tournament[tournament_type]"),
which is how challonge.com expects parameters describin... | [
"Prepares",
"parameters",
"to",
"be",
"sent",
"to",
"challonge",
".",
"com",
"."
] | 3600fa9e0557a2a14eb1ad0c0711d28dad3693d7 | https://github.com/ZEDGR/pychal/blob/3600fa9e0557a2a14eb1ad0c0711d28dad3693d7/challonge/api.py#L135-L174 | train | Prepares parameters to be sent to challonge. com. |
uw-it-aca/uw-restclients-sws | uw_sws/department.py | get_departments_by_college | def get_departments_by_college(college):
"""
Returns a list of restclients.Department models, for the passed
College model.
"""
url = "{}?{}".format(
dept_search_url_prefix,
urlencode({"college_abbreviation": college.label}))
return _json_to_departments(get_resource(url), college... | python | def get_departments_by_college(college):
"""
Returns a list of restclients.Department models, for the passed
College model.
"""
url = "{}?{}".format(
dept_search_url_prefix,
urlencode({"college_abbreviation": college.label}))
return _json_to_departments(get_resource(url), college... | [
"def",
"get_departments_by_college",
"(",
"college",
")",
":",
"url",
"=",
"\"{}?{}\"",
".",
"format",
"(",
"dept_search_url_prefix",
",",
"urlencode",
"(",
"{",
"\"college_abbreviation\"",
":",
"college",
".",
"label",
"}",
")",
")",
"return",
"_json_to_departmen... | Returns a list of restclients.Department models, for the passed
College model. | [
"Returns",
"a",
"list",
"of",
"restclients",
".",
"Department",
"models",
"for",
"the",
"passed",
"College",
"model",
"."
] | 4d36776dcca36855fc15c1b8fe7650ae045194cf | https://github.com/uw-it-aca/uw-restclients-sws/blob/4d36776dcca36855fc15c1b8fe7650ae045194cf/uw_sws/department.py#L14-L22 | train | Returns a list of restclients. Department models for the passed College model. |
berkeley-cocosci/Wallace | wallace/db.py | scoped_session_decorator | def scoped_session_decorator(func):
"""Manage contexts and add debugging to psiTurk sessions."""
@wraps(func)
def wrapper(*args, **kwargs):
from wallace.db import session as wallace_session
with sessions_scope(wallace_session) as session:
from psiturk.db import db_session as psi_... | python | def scoped_session_decorator(func):
"""Manage contexts and add debugging to psiTurk sessions."""
@wraps(func)
def wrapper(*args, **kwargs):
from wallace.db import session as wallace_session
with sessions_scope(wallace_session) as session:
from psiturk.db import db_session as psi_... | [
"def",
"scoped_session_decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"wallace",
".",
"db",
"import",
"session",
"as",
"wallace_session",
"with",
"sessions... | Manage contexts and add debugging to psiTurk sessions. | [
"Manage",
"contexts",
"and",
"add",
"debugging",
"to",
"psiTurk",
"sessions",
"."
] | 3650c0bc3b0804d0adb1d178c5eba9992babb1b0 | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/db.py#L47-L62 | train | Manage contexts and add debugging to psiTurk sessions. |
berkeley-cocosci/Wallace | wallace/db.py | init_db | def init_db(drop_all=False):
"""Initialize the database, optionally dropping existing tables."""
if drop_all:
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)
return session | python | def init_db(drop_all=False):
"""Initialize the database, optionally dropping existing tables."""
if drop_all:
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)
return session | [
"def",
"init_db",
"(",
"drop_all",
"=",
"False",
")",
":",
"if",
"drop_all",
":",
"Base",
".",
"metadata",
".",
"drop_all",
"(",
"bind",
"=",
"engine",
")",
"Base",
".",
"metadata",
".",
"create_all",
"(",
"bind",
"=",
"engine",
")",
"return",
"session... | Initialize the database, optionally dropping existing tables. | [
"Initialize",
"the",
"database",
"optionally",
"dropping",
"existing",
"tables",
"."
] | 3650c0bc3b0804d0adb1d178c5eba9992babb1b0 | https://github.com/berkeley-cocosci/Wallace/blob/3650c0bc3b0804d0adb1d178c5eba9992babb1b0/wallace/db.py#L65-L71 | train | Initialize the database optionally dropping existing tables. |
Ceasar/twosheds | twosheds/terminal.py | Terminal.readline | def readline(self, continuation=False):
"""Read a line from the terminal.
A backslash followed by a <newline> is interpreted as a line
continuation. The backslash and <newline>s are removed before return.
For example::
$ uname \
> -m
x86_64
... | python | def readline(self, continuation=False):
"""Read a line from the terminal.
A backslash followed by a <newline> is interpreted as a line
continuation. The backslash and <newline>s are removed before return.
For example::
$ uname \
> -m
x86_64
... | [
"def",
"readline",
"(",
"self",
",",
"continuation",
"=",
"False",
")",
":",
"prompt",
"=",
"(",
"self",
".",
"secondary_prompt_string",
"if",
"continuation",
"else",
"self",
".",
"primary_prompt_string",
")",
"try",
":",
"line",
"=",
"raw_input",
"(",
"prom... | Read a line from the terminal.
A backslash followed by a <newline> is interpreted as a line
continuation. The backslash and <newline>s are removed before return.
For example::
$ uname \
> -m
x86_64
:param continuation:
True if the line ... | [
"Read",
"a",
"line",
"from",
"the",
"terminal",
"."
] | 55b0a207e3a06b85e9a9567069b3822a651501a7 | https://github.com/Ceasar/twosheds/blob/55b0a207e3a06b85e9a9567069b3822a651501a7/twosheds/terminal.py#L24-L48 | train | Read a line from the terminal. |
Ceasar/twosheds | twosheds/terminal.py | Terminal.readlines | def readlines(self):
"""Read a command from the terminal.
Returns a list of tokens containing the user's input.
"""
continuation = False
while True:
yield self.readline(continuation)
continuation = True | python | def readlines(self):
"""Read a command from the terminal.
Returns a list of tokens containing the user's input.
"""
continuation = False
while True:
yield self.readline(continuation)
continuation = True | [
"def",
"readlines",
"(",
"self",
")",
":",
"continuation",
"=",
"False",
"while",
"True",
":",
"yield",
"self",
".",
"readline",
"(",
"continuation",
")",
"continuation",
"=",
"True"
] | Read a command from the terminal.
Returns a list of tokens containing the user's input. | [
"Read",
"a",
"command",
"from",
"the",
"terminal",
"."
] | 55b0a207e3a06b85e9a9567069b3822a651501a7 | https://github.com/Ceasar/twosheds/blob/55b0a207e3a06b85e9a9567069b3822a651501a7/twosheds/terminal.py#L50-L58 | train | Read a command from the terminal. |
sprockets/sprockets.mixins.mediatype | sprockets/mixins/mediatype/handlers.py | TextContentHandler.to_bytes | def to_bytes(self, inst_data, encoding=None):
"""
Transform an object into :class:`bytes`.
:param object inst_data: object to encode
:param str encoding: character set used to encode the bytes
returned from the ``dumps`` function. This defaults to
:attr:`default... | python | def to_bytes(self, inst_data, encoding=None):
"""
Transform an object into :class:`bytes`.
:param object inst_data: object to encode
:param str encoding: character set used to encode the bytes
returned from the ``dumps`` function. This defaults to
:attr:`default... | [
"def",
"to_bytes",
"(",
"self",
",",
"inst_data",
",",
"encoding",
"=",
"None",
")",
":",
"selected",
"=",
"encoding",
"or",
"self",
".",
"default_encoding",
"content_type",
"=",
"'{0}; charset=\"{1}\"'",
".",
"format",
"(",
"self",
".",
"content_type",
",",
... | Transform an object into :class:`bytes`.
:param object inst_data: object to encode
:param str encoding: character set used to encode the bytes
returned from the ``dumps`` function. This defaults to
:attr:`default_encoding`
:returns: :class:`tuple` of the selected conten... | [
"Transform",
"an",
"object",
"into",
":",
"class",
":",
"bytes",
"."
] | c034e04f674201487a8d6ce9f8ce36f3f5de07d8 | https://github.com/sprockets/sprockets.mixins.mediatype/blob/c034e04f674201487a8d6ce9f8ce36f3f5de07d8/sprockets/mixins/mediatype/handlers.py#L87-L103 | train | Transform an object into bytes. |
sprockets/sprockets.mixins.mediatype | sprockets/mixins/mediatype/handlers.py | TextContentHandler.from_bytes | def from_bytes(self, data, encoding=None):
"""
Get an object from :class:`bytes`
:param bytes data: stream of bytes to decode
:param str encoding: character set used to decode the incoming
bytes before calling the ``loads`` function. This defaults
to :attr:`defa... | python | def from_bytes(self, data, encoding=None):
"""
Get an object from :class:`bytes`
:param bytes data: stream of bytes to decode
:param str encoding: character set used to decode the incoming
bytes before calling the ``loads`` function. This defaults
to :attr:`defa... | [
"def",
"from_bytes",
"(",
"self",
",",
"data",
",",
"encoding",
"=",
"None",
")",
":",
"return",
"self",
".",
"_loads",
"(",
"data",
".",
"decode",
"(",
"encoding",
"or",
"self",
".",
"default_encoding",
")",
")"
] | Get an object from :class:`bytes`
:param bytes data: stream of bytes to decode
:param str encoding: character set used to decode the incoming
bytes before calling the ``loads`` function. This defaults
to :attr:`default_encoding`
:param dict content_parameters: optional ... | [
"Get",
"an",
"object",
"from",
":",
"class",
":",
"bytes"
] | c034e04f674201487a8d6ce9f8ce36f3f5de07d8 | https://github.com/sprockets/sprockets.mixins.mediatype/blob/c034e04f674201487a8d6ce9f8ce36f3f5de07d8/sprockets/mixins/mediatype/handlers.py#L105-L119 | train | Returns an object from the bytes data. |
Kortemme-Lab/klab | klab/bio/pdb.py | sequence | def sequence(pdb_filepath):
'''A convenience method for printing PDB sequences in command-line execution.
:param pdb_filepath: A path to a PDB file.
:return: A string where odd line is a chain letter and each following even line is that chain's ATOM sequence.
Example use:
from ... | python | def sequence(pdb_filepath):
'''A convenience method for printing PDB sequences in command-line execution.
:param pdb_filepath: A path to a PDB file.
:return: A string where odd line is a chain letter and each following even line is that chain's ATOM sequence.
Example use:
from ... | [
"def",
"sequence",
"(",
"pdb_filepath",
")",
":",
"return",
"'\\n'",
".",
"join",
"(",
"[",
"'{0}\\n{1}'",
".",
"format",
"(",
"chain_id",
",",
"str",
"(",
"seq",
")",
")",
"for",
"chain_id",
",",
"seq",
"in",
"sorted",
"(",
"PDB",
".",
"from_filepath"... | A convenience method for printing PDB sequences in command-line execution.
:param pdb_filepath: A path to a PDB file.
:return: A string where odd line is a chain letter and each following even line is that chain's ATOM sequence.
Example use:
from klab.bio import pdb
pri... | [
"A",
"convenience",
"method",
"for",
"printing",
"PDB",
"sequences",
"in",
"command",
"-",
"line",
"execution",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L3149-L3159 | train | A convenience method for printing PDB sequences in command - line execution. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.fix_pdb | def fix_pdb(self):
'''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if
self.strict is False. We may want a separate property for this since we may want to keep strict mode but still
allow PDBs to be fixed.
The only ... | python | def fix_pdb(self):
'''A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if
self.strict is False. We may want a separate property for this since we may want to keep strict mode but still
allow PDBs to be fixed.
The only ... | [
"def",
"fix_pdb",
"(",
"self",
")",
":",
"if",
"self",
".",
"strict",
":",
"return",
"# Get the list of chains",
"chains",
"=",
"set",
"(",
")",
"for",
"l",
"in",
"self",
".",
"lines",
":",
"if",
"l",
".",
"startswith",
"(",
"'ATOM '",
")",
"or",
"l... | A function to fix fatal errors in PDB files when they can be automatically fixed. At present, this only runs if
self.strict is False. We may want a separate property for this since we may want to keep strict mode but still
allow PDBs to be fixed.
The only fixes at the moment are for mi... | [
"A",
"function",
"to",
"fix",
"fatal",
"errors",
"in",
"PDB",
"files",
"when",
"they",
"can",
"be",
"automatically",
"fixed",
".",
"At",
"present",
"this",
"only",
"runs",
"if",
"self",
".",
"strict",
"is",
"False",
".",
"We",
"may",
"want",
"a",
"sepa... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L456-L490 | train | A function to fix fatal errors in PDB files when they can be automatically fixed. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.replace_headers | def replace_headers(source_pdb_content, target_pdb_content):
'''Takes the headers from source_pdb_content and adds them to target_pdb_content, removing any headers that
target_pdb_content had.
Only the content up to the first structural line are taken from source_pdb_content and only the c... | python | def replace_headers(source_pdb_content, target_pdb_content):
'''Takes the headers from source_pdb_content and adds them to target_pdb_content, removing any headers that
target_pdb_content had.
Only the content up to the first structural line are taken from source_pdb_content and only the c... | [
"def",
"replace_headers",
"(",
"source_pdb_content",
",",
"target_pdb_content",
")",
":",
"s",
"=",
"PDB",
"(",
"source_pdb_content",
")",
"t",
"=",
"PDB",
"(",
"target_pdb_content",
")",
"source_headers",
"=",
"[",
"]",
"for",
"l",
"in",
"s",
".",
"lines",
... | Takes the headers from source_pdb_content and adds them to target_pdb_content, removing any headers that
target_pdb_content had.
Only the content up to the first structural line are taken from source_pdb_content and only the content from
the first structural line in target_pdb_content a... | [
"Takes",
"the",
"headers",
"from",
"source_pdb_content",
"and",
"adds",
"them",
"to",
"target_pdb_content",
"removing",
"any",
"headers",
"that",
"target_pdb_content",
"had",
".",
"Only",
"the",
"content",
"up",
"to",
"the",
"first",
"structural",
"line",
"are",
... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L557-L581 | train | Takes the headers from source_pdb_content and adds them to target_pdb_content removing any headers that were not present in the target_pdb_content. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.from_filepath | def from_filepath(filepath, strict = True, parse_ligands = False):
'''A function to replace the old constructor call where a filename was passed in.'''
return PDB(read_file(filepath), strict = strict, parse_ligands = parse_ligands) | python | def from_filepath(filepath, strict = True, parse_ligands = False):
'''A function to replace the old constructor call where a filename was passed in.'''
return PDB(read_file(filepath), strict = strict, parse_ligands = parse_ligands) | [
"def",
"from_filepath",
"(",
"filepath",
",",
"strict",
"=",
"True",
",",
"parse_ligands",
"=",
"False",
")",
":",
"return",
"PDB",
"(",
"read_file",
"(",
"filepath",
")",
",",
"strict",
"=",
"strict",
",",
"parse_ligands",
"=",
"parse_ligands",
")"
] | A function to replace the old constructor call where a filename was passed in. | [
"A",
"function",
"to",
"replace",
"the",
"old",
"constructor",
"call",
"where",
"a",
"filename",
"was",
"passed",
"in",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L586-L588 | train | A function to replace the old constructor call where a filename was passed in. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.from_lines | def from_lines(pdb_file_lines, strict = True, parse_ligands = False):
'''A function to replace the old constructor call where a list of the file's lines was passed in.'''
return PDB("\n".join(pdb_file_lines), strict = strict, parse_ligands = parse_ligands) | python | def from_lines(pdb_file_lines, strict = True, parse_ligands = False):
'''A function to replace the old constructor call where a list of the file's lines was passed in.'''
return PDB("\n".join(pdb_file_lines), strict = strict, parse_ligands = parse_ligands) | [
"def",
"from_lines",
"(",
"pdb_file_lines",
",",
"strict",
"=",
"True",
",",
"parse_ligands",
"=",
"False",
")",
":",
"return",
"PDB",
"(",
"\"\\n\"",
".",
"join",
"(",
"pdb_file_lines",
")",
",",
"strict",
"=",
"strict",
",",
"parse_ligands",
"=",
"parse_... | A function to replace the old constructor call where a list of the file's lines was passed in. | [
"A",
"function",
"to",
"replace",
"the",
"old",
"constructor",
"call",
"where",
"a",
"list",
"of",
"the",
"file",
"s",
"lines",
"was",
"passed",
"in",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L591-L593 | train | A function to replace the old constructor call where a list of the file s lines was passed in. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.retrieve | def retrieve(pdb_id, cache_dir = None, strict = True, parse_ligands = False):
'''Creates a PDB object by using a cached copy of the file if it exists or by retrieving the file from the RCSB.'''
# Check to see whether we have a cached copy
pdb_id = pdb_id.upper()
if cache_dir:
... | python | def retrieve(pdb_id, cache_dir = None, strict = True, parse_ligands = False):
'''Creates a PDB object by using a cached copy of the file if it exists or by retrieving the file from the RCSB.'''
# Check to see whether we have a cached copy
pdb_id = pdb_id.upper()
if cache_dir:
... | [
"def",
"retrieve",
"(",
"pdb_id",
",",
"cache_dir",
"=",
"None",
",",
"strict",
"=",
"True",
",",
"parse_ligands",
"=",
"False",
")",
":",
"# Check to see whether we have a cached copy",
"pdb_id",
"=",
"pdb_id",
".",
"upper",
"(",
")",
"if",
"cache_dir",
":",
... | Creates a PDB object by using a cached copy of the file if it exists or by retrieving the file from the RCSB. | [
"Creates",
"a",
"PDB",
"object",
"by",
"using",
"a",
"cached",
"copy",
"of",
"the",
"file",
"if",
"it",
"exists",
"or",
"by",
"retrieving",
"the",
"file",
"from",
"the",
"RCSB",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L597-L615 | train | Creates a PDB object by using a cached copy of the file if it exists or by retrieving the file from the RCSB. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._split_lines | def _split_lines(self):
'''Creates the parsed_lines dict which keeps all record data in document order indexed by the record type.'''
parsed_lines = {}
for rt in all_record_types:
parsed_lines[rt] = []
parsed_lines[0] = []
for line in self.lines:
linetype... | python | def _split_lines(self):
'''Creates the parsed_lines dict which keeps all record data in document order indexed by the record type.'''
parsed_lines = {}
for rt in all_record_types:
parsed_lines[rt] = []
parsed_lines[0] = []
for line in self.lines:
linetype... | [
"def",
"_split_lines",
"(",
"self",
")",
":",
"parsed_lines",
"=",
"{",
"}",
"for",
"rt",
"in",
"all_record_types",
":",
"parsed_lines",
"[",
"rt",
"]",
"=",
"[",
"]",
"parsed_lines",
"[",
"0",
"]",
"=",
"[",
"]",
"for",
"line",
"in",
"self",
".",
... | Creates the parsed_lines dict which keeps all record data in document order indexed by the record type. | [
"Creates",
"the",
"parsed_lines",
"dict",
"which",
"keeps",
"all",
"record",
"data",
"in",
"document",
"order",
"indexed",
"by",
"the",
"record",
"type",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L621-L636 | train | Creates the parsed_lines dict which keeps all record data in document order indexed by the record type. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._update_structure_lines | def _update_structure_lines(self):
'''ATOM and HETATM lines may be altered by function calls. When this happens, this function should be called to keep self.structure_lines up to date.'''
structure_lines = []
atom_chain_order = []
chain_atoms = {}
for line in self.lines:
... | python | def _update_structure_lines(self):
'''ATOM and HETATM lines may be altered by function calls. When this happens, this function should be called to keep self.structure_lines up to date.'''
structure_lines = []
atom_chain_order = []
chain_atoms = {}
for line in self.lines:
... | [
"def",
"_update_structure_lines",
"(",
"self",
")",
":",
"structure_lines",
"=",
"[",
"]",
"atom_chain_order",
"=",
"[",
"]",
"chain_atoms",
"=",
"{",
"}",
"for",
"line",
"in",
"self",
".",
"lines",
":",
"linetype",
"=",
"line",
"[",
"0",
":",
"6",
"]"... | ATOM and HETATM lines may be altered by function calls. When this happens, this function should be called to keep self.structure_lines up to date. | [
"ATOM",
"and",
"HETATM",
"lines",
"may",
"be",
"altered",
"by",
"function",
"calls",
".",
"When",
"this",
"happens",
"this",
"function",
"should",
"be",
"called",
"to",
"keep",
"self",
".",
"structure_lines",
"up",
"to",
"date",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L639-L666 | train | Update self. structure_lines and self. atom_chain_order. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.clone | def clone(self, parse_ligands = False):
'''A function to replace the old constructor call where a PDB object was passed in and 'cloned'.'''
return PDB("\n".join(self.lines), pdb_id = self.pdb_id, strict = self.strict, parse_ligands = parse_ligands) | python | def clone(self, parse_ligands = False):
'''A function to replace the old constructor call where a PDB object was passed in and 'cloned'.'''
return PDB("\n".join(self.lines), pdb_id = self.pdb_id, strict = self.strict, parse_ligands = parse_ligands) | [
"def",
"clone",
"(",
"self",
",",
"parse_ligands",
"=",
"False",
")",
":",
"return",
"PDB",
"(",
"\"\\n\"",
".",
"join",
"(",
"self",
".",
"lines",
")",
",",
"pdb_id",
"=",
"self",
".",
"pdb_id",
",",
"strict",
"=",
"self",
".",
"strict",
",",
"par... | A function to replace the old constructor call where a PDB object was passed in and 'cloned'. | [
"A",
"function",
"to",
"replace",
"the",
"old",
"constructor",
"call",
"where",
"a",
"PDB",
"object",
"was",
"passed",
"in",
"and",
"cloned",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L670-L672 | train | A function to replace the old constructor call where a PDB object was passed in and cloned. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_pdb_id | def get_pdb_id(self):
'''Return the PDB ID. If one was passed in to the constructor, this takes precedence, otherwise the header is
parsed to try to find an ID. The header does not always contain a PDB ID in regular PDB files and appears to
always have an ID of 'XXXX' in biological units s... | python | def get_pdb_id(self):
'''Return the PDB ID. If one was passed in to the constructor, this takes precedence, otherwise the header is
parsed to try to find an ID. The header does not always contain a PDB ID in regular PDB files and appears to
always have an ID of 'XXXX' in biological units s... | [
"def",
"get_pdb_id",
"(",
"self",
")",
":",
"if",
"self",
".",
"pdb_id",
":",
"return",
"self",
".",
"pdb_id",
"else",
":",
"header",
"=",
"self",
".",
"parsed_lines",
"[",
"\"HEADER\"",
"]",
"assert",
"(",
"len",
"(",
"header",
")",
"<=",
"1",
")",
... | Return the PDB ID. If one was passed in to the constructor, this takes precedence, otherwise the header is
parsed to try to find an ID. The header does not always contain a PDB ID in regular PDB files and appears to
always have an ID of 'XXXX' in biological units so the constructor override is use... | [
"Return",
"the",
"PDB",
"ID",
".",
"If",
"one",
"was",
"passed",
"in",
"to",
"the",
"constructor",
"this",
"takes",
"precedence",
"otherwise",
"the",
"header",
"is",
"parsed",
"to",
"try",
"to",
"find",
"an",
"ID",
".",
"The",
"header",
"does",
"not",
... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L684-L696 | train | Return the PDB ID. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_annotated_chain_sequence_string | def get_annotated_chain_sequence_string(self, chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = True):
'''A helper function to return the Sequence for a chain. If use_seqres_sequences_if_possible then we return the SEQRES
Sequence if it exists. We return a tuple of values, th... | python | def get_annotated_chain_sequence_string(self, chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = True):
'''A helper function to return the Sequence for a chain. If use_seqres_sequences_if_possible then we return the SEQRES
Sequence if it exists. We return a tuple of values, th... | [
"def",
"get_annotated_chain_sequence_string",
"(",
"self",
",",
"chain_id",
",",
"use_seqres_sequences_if_possible",
",",
"raise_Exception_if_not_found",
"=",
"True",
")",
":",
"if",
"use_seqres_sequences_if_possible",
"and",
"self",
".",
"seqres_sequences",
"and",
"self",
... | A helper function to return the Sequence for a chain. If use_seqres_sequences_if_possible then we return the SEQRES
Sequence if it exists. We return a tuple of values, the first identifying which sequence was returned. | [
"A",
"helper",
"function",
"to",
"return",
"the",
"Sequence",
"for",
"a",
"chain",
".",
"If",
"use_seqres_sequences_if_possible",
"then",
"we",
"return",
"the",
"SEQRES",
"Sequence",
"if",
"it",
"exists",
".",
"We",
"return",
"a",
"tuple",
"of",
"values",
"t... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L704-L714 | train | A helper function to return the Sequence for a chain. If use_seqres_sequences_if_possible then we return the SEQRES
Sequence if it exists. If raise_Exception_if_not_found then we return None. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_chain_sequence_string | def get_chain_sequence_string(self, chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = True):
'''Similar to get_annotated_chain_sequence_string except that we only return the Sequence and do not state which sequence it was.'''
chain_pair = self.get_annotated_chain_sequence_string... | python | def get_chain_sequence_string(self, chain_id, use_seqres_sequences_if_possible, raise_Exception_if_not_found = True):
'''Similar to get_annotated_chain_sequence_string except that we only return the Sequence and do not state which sequence it was.'''
chain_pair = self.get_annotated_chain_sequence_string... | [
"def",
"get_chain_sequence_string",
"(",
"self",
",",
"chain_id",
",",
"use_seqres_sequences_if_possible",
",",
"raise_Exception_if_not_found",
"=",
"True",
")",
":",
"chain_pair",
"=",
"self",
".",
"get_annotated_chain_sequence_string",
"(",
"chain_id",
",",
"use_seqres_... | Similar to get_annotated_chain_sequence_string except that we only return the Sequence and do not state which sequence it was. | [
"Similar",
"to",
"get_annotated_chain_sequence_string",
"except",
"that",
"we",
"only",
"return",
"the",
"Sequence",
"and",
"do",
"not",
"state",
"which",
"sequence",
"it",
"was",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L717-L722 | train | Similar to get_annotated_chain_sequence_string except that we only return the Sequence and do not state which sequence it was. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._get_replacement_pdb_id | def _get_replacement_pdb_id(self):
'''Checks to see if the PDB file has been deprecated and, if so, what the new ID is.'''
deprecation_lines = self.parsed_lines['OBSLTE']
date_regex = re.compile('(\d+)-(\w{3})-(\d+)')
if deprecation_lines:
assert(len(deprecation_lines) == 1)
... | python | def _get_replacement_pdb_id(self):
'''Checks to see if the PDB file has been deprecated and, if so, what the new ID is.'''
deprecation_lines = self.parsed_lines['OBSLTE']
date_regex = re.compile('(\d+)-(\w{3})-(\d+)')
if deprecation_lines:
assert(len(deprecation_lines) == 1)
... | [
"def",
"_get_replacement_pdb_id",
"(",
"self",
")",
":",
"deprecation_lines",
"=",
"self",
".",
"parsed_lines",
"[",
"'OBSLTE'",
"]",
"date_regex",
"=",
"re",
".",
"compile",
"(",
"'(\\d+)-(\\w{3})-(\\d+)'",
")",
"if",
"deprecation_lines",
":",
"assert",
"(",
"l... | Checks to see if the PDB file has been deprecated and, if so, what the new ID is. | [
"Checks",
"to",
"see",
"if",
"the",
"PDB",
"file",
"has",
"been",
"deprecated",
"and",
"if",
"so",
"what",
"the",
"new",
"ID",
"is",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L748-L770 | train | Checks to see if the PDB file has been deprecated and if so what the new ID is. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.strip_to_chains | def strip_to_chains(self, chains, break_at_endmdl = True):
'''Throw away all ATOM/HETATM/ANISOU/TER lines for chains that are not in the chains list.'''
if chains:
chains = set(chains)
# Remove any structure lines not associated with the chains
self.lines = [l for l ... | python | def strip_to_chains(self, chains, break_at_endmdl = True):
'''Throw away all ATOM/HETATM/ANISOU/TER lines for chains that are not in the chains list.'''
if chains:
chains = set(chains)
# Remove any structure lines not associated with the chains
self.lines = [l for l ... | [
"def",
"strip_to_chains",
"(",
"self",
",",
"chains",
",",
"break_at_endmdl",
"=",
"True",
")",
":",
"if",
"chains",
":",
"chains",
"=",
"set",
"(",
"chains",
")",
"# Remove any structure lines not associated with the chains",
"self",
".",
"lines",
"=",
"[",
"l"... | Throw away all ATOM/HETATM/ANISOU/TER lines for chains that are not in the chains list. | [
"Throw",
"away",
"all",
"ATOM",
"/",
"HETATM",
"/",
"ANISOU",
"/",
"TER",
"lines",
"for",
"chains",
"that",
"are",
"not",
"in",
"the",
"chains",
"list",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L776-L797 | train | Throw away all ATOM HETATM and ANISOU lines for chains that are not in the chains list. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.strip_HETATMs | def strip_HETATMs(self, only_strip_these_chains = []):
'''Throw away all HETATM lines. If only_strip_these_chains is specified then only strip HETATMs lines for those chains.'''
if only_strip_these_chains:
self.lines = [l for l in self.lines if not(l.startswith('HETATM')) or l[21] not in onl... | python | def strip_HETATMs(self, only_strip_these_chains = []):
'''Throw away all HETATM lines. If only_strip_these_chains is specified then only strip HETATMs lines for those chains.'''
if only_strip_these_chains:
self.lines = [l for l in self.lines if not(l.startswith('HETATM')) or l[21] not in onl... | [
"def",
"strip_HETATMs",
"(",
"self",
",",
"only_strip_these_chains",
"=",
"[",
"]",
")",
":",
"if",
"only_strip_these_chains",
":",
"self",
".",
"lines",
"=",
"[",
"l",
"for",
"l",
"in",
"self",
".",
"lines",
"if",
"not",
"(",
"l",
".",
"startswith",
"... | Throw away all HETATM lines. If only_strip_these_chains is specified then only strip HETATMs lines for those chains. | [
"Throw",
"away",
"all",
"HETATM",
"lines",
".",
"If",
"only_strip_these_chains",
"is",
"specified",
"then",
"only",
"strip",
"HETATMs",
"lines",
"for",
"those",
"chains",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L800-L806 | train | Throw away all HETATMs lines. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.generate_all_paired_mutations_for_position | def generate_all_paired_mutations_for_position(self, chain_ids, chain_sequence_mappings = {}, residue_ids_to_ignore = [], typed_residue_ids_to_ignore = [], silent = True):
'''Generates a set of mutations for the chains in chain_ids where each set corresponds to the "same" residue (see
below) in both ... | python | def generate_all_paired_mutations_for_position(self, chain_ids, chain_sequence_mappings = {}, residue_ids_to_ignore = [], typed_residue_ids_to_ignore = [], silent = True):
'''Generates a set of mutations for the chains in chain_ids where each set corresponds to the "same" residue (see
below) in both ... | [
"def",
"generate_all_paired_mutations_for_position",
"(",
"self",
",",
"chain_ids",
",",
"chain_sequence_mappings",
"=",
"{",
"}",
",",
"residue_ids_to_ignore",
"=",
"[",
"]",
",",
"typed_residue_ids_to_ignore",
"=",
"[",
"]",
",",
"silent",
"=",
"True",
")",
":",... | Generates a set of mutations for the chains in chain_ids where each set corresponds to the "same" residue (see
below) in both chains and where the wildtype residues match.
e.g. if chain A and B both have K19 then the set of mutations K19A, ... K19I, K19L, K19Y will be included in
... | [
"Generates",
"a",
"set",
"of",
"mutations",
"for",
"the",
"chains",
"in",
"chain_ids",
"where",
"each",
"set",
"corresponds",
"to",
"the",
"same",
"residue",
"(",
"see",
"below",
")",
"in",
"both",
"chains",
"and",
"where",
"the",
"wildtype",
"residues",
"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L825-L895 | train | Generates a set of mutations for all chains in chain_ids that are paired with the same residue. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._get_pdb_format_version | def _get_pdb_format_version(self):
'''Remark 4 indicates the version of the PDB File Format used to generate the file.'''
if not self.format_version:
version = None
version_lines = None
try:
version_lines = [line for line in self.parsed_lines['REMARK']... | python | def _get_pdb_format_version(self):
'''Remark 4 indicates the version of the PDB File Format used to generate the file.'''
if not self.format_version:
version = None
version_lines = None
try:
version_lines = [line for line in self.parsed_lines['REMARK']... | [
"def",
"_get_pdb_format_version",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"format_version",
":",
"version",
"=",
"None",
"version_lines",
"=",
"None",
"try",
":",
"version_lines",
"=",
"[",
"line",
"for",
"line",
"in",
"self",
".",
"parsed_lines",
... | Remark 4 indicates the version of the PDB File Format used to generate the file. | [
"Remark",
"4",
"indicates",
"the",
"version",
"of",
"the",
"PDB",
"File",
"Format",
"used",
"to",
"generate",
"the",
"file",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L926-L944 | train | Get the version of the PDB File Format used to generate the file. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_DB_references | def get_DB_references(self):
''' "The DBREF record provides cross-reference links between PDB sequences (what appears in SEQRES record) and
a corresponding database sequence." - http://www.wwpdb.org/documentation/format33/sect3.html#DBREF
'''
_database_names = {
'GB'... | python | def get_DB_references(self):
''' "The DBREF record provides cross-reference links between PDB sequences (what appears in SEQRES record) and
a corresponding database sequence." - http://www.wwpdb.org/documentation/format33/sect3.html#DBREF
'''
_database_names = {
'GB'... | [
"def",
"get_DB_references",
"(",
"self",
")",
":",
"_database_names",
"=",
"{",
"'GB'",
":",
"'GenBank'",
",",
"'PDB'",
":",
"'Protein Data Bank'",
",",
"'UNP'",
":",
"'UNIPROT'",
",",
"'NORINE'",
":",
"'Norine'",
",",
"'TREMBL'",
":",
"'UNIPROT'",
",",
"}",... | "The DBREF record provides cross-reference links between PDB sequences (what appears in SEQRES record) and
a corresponding database sequence." - http://www.wwpdb.org/documentation/format33/sect3.html#DBREF | [
"The",
"DBREF",
"record",
"provides",
"cross",
"-",
"reference",
"links",
"between",
"PDB",
"sequences",
"(",
"what",
"appears",
"in",
"SEQRES",
"record",
")",
"and",
"a",
"corresponding",
"database",
"sequence",
".",
"-",
"http",
":",
"//",
"www",
".",
"w... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1014-L1056 | train | The DBREF record provides cross - reference links between PDB sequences ( what appears in SEQRES record ) and
a corresponding database sequence. - http://www. wwwpdb. org / documentation / format33. html#DBREF
|
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._get_SEQRES_sequences | def _get_SEQRES_sequences(self):
'''Creates the SEQRES Sequences and stores the chains in order of their appearance in the SEQRES records. This order of chains
in the SEQRES sequences does not always agree with the order in the ATOM records.'''
pdb_id = self.get_pdb_id()
SEQRES_lines... | python | def _get_SEQRES_sequences(self):
'''Creates the SEQRES Sequences and stores the chains in order of their appearance in the SEQRES records. This order of chains
in the SEQRES sequences does not always agree with the order in the ATOM records.'''
pdb_id = self.get_pdb_id()
SEQRES_lines... | [
"def",
"_get_SEQRES_sequences",
"(",
"self",
")",
":",
"pdb_id",
"=",
"self",
".",
"get_pdb_id",
"(",
")",
"SEQRES_lines",
"=",
"self",
".",
"parsed_lines",
"[",
"\"SEQRES\"",
"]",
"modified_residue_mapping_3",
"=",
"self",
".",
"modified_residue_mapping_3",
"# I ... | Creates the SEQRES Sequences and stores the chains in order of their appearance in the SEQRES records. This order of chains
in the SEQRES sequences does not always agree with the order in the ATOM records. | [
"Creates",
"the",
"SEQRES",
"Sequences",
"and",
"stores",
"the",
"chains",
"in",
"order",
"of",
"their",
"appearance",
"in",
"the",
"SEQRES",
"records",
".",
"This",
"order",
"of",
"chains",
"in",
"the",
"SEQRES",
"sequences",
"does",
"not",
"always",
"agree... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1237-L1373 | train | Creates the SEQRES Sequences and stores the chains in order of their appearance in the ATOM records. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._get_ATOM_sequences | def _get_ATOM_sequences(self):
'''Creates the ATOM Sequences.'''
# Get a list of all residues with ATOM or HETATM records
atom_sequences = {}
structural_residue_IDs_set = set() # use a set for a quicker lookup
ignore_HETATMs = True # todo: fix this if we need to deal with HETATM... | python | def _get_ATOM_sequences(self):
'''Creates the ATOM Sequences.'''
# Get a list of all residues with ATOM or HETATM records
atom_sequences = {}
structural_residue_IDs_set = set() # use a set for a quicker lookup
ignore_HETATMs = True # todo: fix this if we need to deal with HETATM... | [
"def",
"_get_ATOM_sequences",
"(",
"self",
")",
":",
"# Get a list of all residues with ATOM or HETATM records",
"atom_sequences",
"=",
"{",
"}",
"structural_residue_IDs_set",
"=",
"set",
"(",
")",
"# use a set for a quicker lookup",
"ignore_HETATMs",
"=",
"True",
"# todo: fi... | Creates the ATOM Sequences. | [
"Creates",
"the",
"ATOM",
"Sequences",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1376-L1540 | train | Creates the ATOM Sequences. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._get_ATOM_sequences_2 | def _get_ATOM_sequences_2(self):
'''Creates the ATOM Sequences.'''
# Get a list of all residues with ATOM or HETATM records
atom_sequences = {}
structural_residue_IDs_set = set() # use a set for a quicker lookup
ignore_HETATMs = True # todo: fix this if we need to deal with HETA... | python | def _get_ATOM_sequences_2(self):
'''Creates the ATOM Sequences.'''
# Get a list of all residues with ATOM or HETATM records
atom_sequences = {}
structural_residue_IDs_set = set() # use a set for a quicker lookup
ignore_HETATMs = True # todo: fix this if we need to deal with HETA... | [
"def",
"_get_ATOM_sequences_2",
"(",
"self",
")",
":",
"# Get a list of all residues with ATOM or HETATM records",
"atom_sequences",
"=",
"{",
"}",
"structural_residue_IDs_set",
"=",
"set",
"(",
")",
"# use a set for a quicker lookup",
"ignore_HETATMs",
"=",
"True",
"# todo: ... | Creates the ATOM Sequences. | [
"Creates",
"the",
"ATOM",
"Sequences",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1543-L1586 | train | Creates the ATOM Sequences. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.construct_seqres_to_atom_residue_map | def construct_seqres_to_atom_residue_map(self):
'''Uses the SequenceAligner to align the SEQRES and ATOM sequences and return the mappings.
If the SEQRES sequence does not exist for a chain, the mappings are None.
Note: The ResidueRelatrix is better equipped for this job since it can use t... | python | def construct_seqres_to_atom_residue_map(self):
'''Uses the SequenceAligner to align the SEQRES and ATOM sequences and return the mappings.
If the SEQRES sequence does not exist for a chain, the mappings are None.
Note: The ResidueRelatrix is better equipped for this job since it can use t... | [
"def",
"construct_seqres_to_atom_residue_map",
"(",
"self",
")",
":",
"from",
"klab",
".",
"bio",
".",
"clustalo",
"import",
"SequenceAligner",
"seqres_to_atom_maps",
"=",
"{",
"}",
"atom_to_seqres_maps",
"=",
"{",
"}",
"for",
"c",
"in",
"self",
".",
"seqres_cha... | Uses the SequenceAligner to align the SEQRES and ATOM sequences and return the mappings.
If the SEQRES sequence does not exist for a chain, the mappings are None.
Note: The ResidueRelatrix is better equipped for this job since it can use the SIFTS mappings. This function
is provided for... | [
"Uses",
"the",
"SequenceAligner",
"to",
"align",
"the",
"SEQRES",
"and",
"ATOM",
"sequences",
"and",
"return",
"the",
"mappings",
".",
"If",
"the",
"SEQRES",
"sequence",
"does",
"not",
"exist",
"for",
"a",
"chain",
"the",
"mappings",
"are",
"None",
".",
"N... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1589-L1620 | train | Uses the SequenceAligner to align the SEQRES and ATOM sequences and return the mappings. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.construct_pdb_to_rosetta_residue_map | def construct_pdb_to_rosetta_residue_map(self, rosetta_scripts_path, rosetta_database_path = None, extra_command_flags = None, cache_dir = None):
''' Uses the features database to create a mapping from Rosetta-numbered residues to PDB ATOM residues.
Next, the object's rosetta_sequences (a dict of Se... | python | def construct_pdb_to_rosetta_residue_map(self, rosetta_scripts_path, rosetta_database_path = None, extra_command_flags = None, cache_dir = None):
''' Uses the features database to create a mapping from Rosetta-numbered residues to PDB ATOM residues.
Next, the object's rosetta_sequences (a dict of Se... | [
"def",
"construct_pdb_to_rosetta_residue_map",
"(",
"self",
",",
"rosetta_scripts_path",
",",
"rosetta_database_path",
"=",
"None",
",",
"extra_command_flags",
"=",
"None",
",",
"cache_dir",
"=",
"None",
")",
":",
"## Create a mapping from Rosetta-numbered residues to PDB ATO... | Uses the features database to create a mapping from Rosetta-numbered residues to PDB ATOM residues.
Next, the object's rosetta_sequences (a dict of Sequences) element is created.
Finally, a SequenceMap object is created mapping the Rosetta Sequences to the ATOM Sequences.
The extra_... | [
"Uses",
"the",
"features",
"database",
"to",
"create",
"a",
"mapping",
"from",
"Rosetta",
"-",
"numbered",
"residues",
"to",
"PDB",
"ATOM",
"residues",
".",
"Next",
"the",
"object",
"s",
"rosetta_sequences",
"(",
"a",
"dict",
"of",
"Sequences",
")",
"element... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1623-L1716 | train | Constructs a mapping from the Rosetta - numbered residues to the ATOM Sequences. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_atom_sequence_to_rosetta_map | def get_atom_sequence_to_rosetta_map(self):
'''Uses the Rosetta->ATOM injective map to construct an injective mapping from ATOM->Rosetta.
We do not extend the injection to include ATOM residues which have no corresponding Rosetta residue.
e.g. atom_sequence_to_rosetta_mapping[c].map.get(... | python | def get_atom_sequence_to_rosetta_map(self):
'''Uses the Rosetta->ATOM injective map to construct an injective mapping from ATOM->Rosetta.
We do not extend the injection to include ATOM residues which have no corresponding Rosetta residue.
e.g. atom_sequence_to_rosetta_mapping[c].map.get(... | [
"def",
"get_atom_sequence_to_rosetta_map",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"rosetta_to_atom_sequence_maps",
"and",
"self",
".",
"rosetta_sequences",
":",
"raise",
"Exception",
"(",
"'The PDB to Rosetta mapping has not been determined. Please call construct_pdb_... | Uses the Rosetta->ATOM injective map to construct an injective mapping from ATOM->Rosetta.
We do not extend the injection to include ATOM residues which have no corresponding Rosetta residue.
e.g. atom_sequence_to_rosetta_mapping[c].map.get('A 45 ') will return None if there is no corresponding... | [
"Uses",
"the",
"Rosetta",
"-",
">",
"ATOM",
"injective",
"map",
"to",
"construct",
"an",
"injective",
"mapping",
"from",
"ATOM",
"-",
">",
"Rosetta",
".",
"We",
"do",
"not",
"extend",
"the",
"injection",
"to",
"include",
"ATOM",
"residues",
"which",
"have"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1719-L1741 | train | Returns a mapping from ATOM to Rosetta. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_atom_sequence_to_rosetta_json_map | def get_atom_sequence_to_rosetta_json_map(self):
'''Returns the mapping from PDB ATOM residue IDs to Rosetta residue IDs in JSON format.'''
import json
d = {}
atom_sequence_to_rosetta_mapping = self.get_atom_sequence_to_rosetta_map()
for c, sm in atom_sequence_to_rosetta_mapping.... | python | def get_atom_sequence_to_rosetta_json_map(self):
'''Returns the mapping from PDB ATOM residue IDs to Rosetta residue IDs in JSON format.'''
import json
d = {}
atom_sequence_to_rosetta_mapping = self.get_atom_sequence_to_rosetta_map()
for c, sm in atom_sequence_to_rosetta_mapping.... | [
"def",
"get_atom_sequence_to_rosetta_json_map",
"(",
"self",
")",
":",
"import",
"json",
"d",
"=",
"{",
"}",
"atom_sequence_to_rosetta_mapping",
"=",
"self",
".",
"get_atom_sequence_to_rosetta_map",
"(",
")",
"for",
"c",
",",
"sm",
"in",
"atom_sequence_to_rosetta_mapp... | Returns the mapping from PDB ATOM residue IDs to Rosetta residue IDs in JSON format. | [
"Returns",
"the",
"mapping",
"from",
"PDB",
"ATOM",
"residue",
"IDs",
"to",
"Rosetta",
"residue",
"IDs",
"in",
"JSON",
"format",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1744-L1752 | train | Returns the mapping from PDB ATOM residue IDs to Rosetta residue IDs in JSON format. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_rosetta_sequence_to_atom_json_map | def get_rosetta_sequence_to_atom_json_map(self):
'''Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format.'''
import json
if not self.rosetta_to_atom_sequence_maps and self.rosetta_sequences:
raise Exception('The PDB to Rosetta mapping has not been deter... | python | def get_rosetta_sequence_to_atom_json_map(self):
'''Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format.'''
import json
if not self.rosetta_to_atom_sequence_maps and self.rosetta_sequences:
raise Exception('The PDB to Rosetta mapping has not been deter... | [
"def",
"get_rosetta_sequence_to_atom_json_map",
"(",
"self",
")",
":",
"import",
"json",
"if",
"not",
"self",
".",
"rosetta_to_atom_sequence_maps",
"and",
"self",
".",
"rosetta_sequences",
":",
"raise",
"Exception",
"(",
"'The PDB to Rosetta mapping has not been determined.... | Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format. | [
"Returns",
"the",
"mapping",
"from",
"Rosetta",
"residue",
"IDs",
"to",
"PDB",
"ATOM",
"residue",
"IDs",
"in",
"JSON",
"format",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1755-L1766 | train | Returns the mapping from Rosetta residue IDs to PDB ATOM residue IDs in JSON format. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.map_pdb_residues_to_rosetta_residues | def map_pdb_residues_to_rosetta_residues(self, mutations):
'''This function takes a list of ChainMutation objects and uses the PDB to Rosetta mapping to return the corresponding
list of SimpleMutation objects using Rosetta numbering.
e.g.
p = PDB(...)
p.construc... | python | def map_pdb_residues_to_rosetta_residues(self, mutations):
'''This function takes a list of ChainMutation objects and uses the PDB to Rosetta mapping to return the corresponding
list of SimpleMutation objects using Rosetta numbering.
e.g.
p = PDB(...)
p.construc... | [
"def",
"map_pdb_residues_to_rosetta_residues",
"(",
"self",
",",
"mutations",
")",
":",
"if",
"not",
"self",
".",
"rosetta_to_atom_sequence_maps",
"and",
"self",
".",
"rosetta_sequences",
":",
"raise",
"Exception",
"(",
"'The PDB to Rosetta mapping has not been determined. ... | This function takes a list of ChainMutation objects and uses the PDB to Rosetta mapping to return the corresponding
list of SimpleMutation objects using Rosetta numbering.
e.g.
p = PDB(...)
p.construct_pdb_to_rosetta_residue_map()
rosetta_mutations = p.map... | [
"This",
"function",
"takes",
"a",
"list",
"of",
"ChainMutation",
"objects",
"and",
"uses",
"the",
"PDB",
"to",
"Rosetta",
"mapping",
"to",
"return",
"the",
"corresponding",
"list",
"of",
"SimpleMutation",
"objects",
"using",
"Rosetta",
"numbering",
".",
"e",
"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1769-L1785 | train | This function maps the Residues of a list of ChainMutation objects to the corresponding SimpleMutation objects using the Rosetta numbering. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.assert_wildtype_matches | def assert_wildtype_matches(self, mutation):
'''Check that the wildtype of the Mutation object matches the PDB sequence.'''
readwt = self.getAminoAcid(self.getAtomLine(mutation.Chain, mutation.ResidueID))
assert(mutation.WildTypeAA == residue_type_3to1_map[readwt]) | python | def assert_wildtype_matches(self, mutation):
'''Check that the wildtype of the Mutation object matches the PDB sequence.'''
readwt = self.getAminoAcid(self.getAtomLine(mutation.Chain, mutation.ResidueID))
assert(mutation.WildTypeAA == residue_type_3to1_map[readwt]) | [
"def",
"assert_wildtype_matches",
"(",
"self",
",",
"mutation",
")",
":",
"readwt",
"=",
"self",
".",
"getAminoAcid",
"(",
"self",
".",
"getAtomLine",
"(",
"mutation",
".",
"Chain",
",",
"mutation",
".",
"ResidueID",
")",
")",
"assert",
"(",
"mutation",
".... | Check that the wildtype of the Mutation object matches the PDB sequence. | [
"Check",
"that",
"the",
"wildtype",
"of",
"the",
"Mutation",
"object",
"matches",
"the",
"PDB",
"sequence",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1788-L1791 | train | Check that the wildtype of the Mutation object matches the PDB sequence. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB._determine_heterogen_chain_type | def _determine_heterogen_chain_type(residue_types):
'''We distinguish three types of heterogen chain: i) all solution; ii) all ligand; or iii) other (a mix of solution, ligand, and/or ions).
residue_types should be a Set of sequence identifers e.g. GTP, ZN, HOH.
'''
residue_type_id_le... | python | def _determine_heterogen_chain_type(residue_types):
'''We distinguish three types of heterogen chain: i) all solution; ii) all ligand; or iii) other (a mix of solution, ligand, and/or ions).
residue_types should be a Set of sequence identifers e.g. GTP, ZN, HOH.
'''
residue_type_id_le... | [
"def",
"_determine_heterogen_chain_type",
"(",
"residue_types",
")",
":",
"residue_type_id_lengths",
"=",
"set",
"(",
"map",
"(",
"len",
",",
"residue_types",
")",
")",
"if",
"(",
"len",
"(",
"residue_types",
")",
">",
"0",
")",
":",
"if",
"len",
"(",
"res... | We distinguish three types of heterogen chain: i) all solution; ii) all ligand; or iii) other (a mix of solution, ligand, and/or ions).
residue_types should be a Set of sequence identifers e.g. GTP, ZN, HOH. | [
"We",
"distinguish",
"three",
"types",
"of",
"heterogen",
"chain",
":",
"i",
")",
"all",
"solution",
";",
"ii",
")",
"all",
"ligand",
";",
"or",
"iii",
")",
"other",
"(",
"a",
"mix",
"of",
"solution",
"ligand",
"and",
"/",
"or",
"ions",
")",
".",
"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1798-L1809 | train | Determine the type of heterogen chain. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.convert_hetatms_to_Hill_notation | def convert_hetatms_to_Hill_notation(lines, ignore_list = []):#['HOH']):
'''From the PDB site:
The elements of the chemical formula are given in the order following Hill ordering. The order of elements depends
on whether carbon is present or not. If carbon is present, the order should be: ... | python | def convert_hetatms_to_Hill_notation(lines, ignore_list = []):#['HOH']):
'''From the PDB site:
The elements of the chemical formula are given in the order following Hill ordering. The order of elements depends
on whether carbon is present or not. If carbon is present, the order should be: ... | [
"def",
"convert_hetatms_to_Hill_notation",
"(",
"lines",
",",
"ignore_list",
"=",
"[",
"]",
")",
":",
"#['HOH']):",
"ignore_list",
"=",
"set",
"(",
"ignore_list",
")",
"hetatms",
"=",
"{",
"}",
"for",
"l",
"in",
"lines",
":",
"if",
"l",
".",
"startswith",
... | From the PDB site:
The elements of the chemical formula are given in the order following Hill ordering. The order of elements depends
on whether carbon is present or not. If carbon is present, the order should be: C, then H, then the other elements
in alphabetical order of their symbol.... | [
"From",
"the",
"PDB",
"site",
":",
"The",
"elements",
"of",
"the",
"chemical",
"formula",
"are",
"given",
"in",
"the",
"order",
"following",
"Hill",
"ordering",
".",
"The",
"order",
"of",
"elements",
"depends",
"on",
"whether",
"carbon",
"is",
"present",
"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L1823-L1872 | train | Convert the HETATM lines to Hill notation. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_B_factors | def get_B_factors(self, force = False):
'''This reads in all ATOM lines and compute the mean and standard deviation of each
residue's B-factors. It returns a table of the mean and standard deviation per
residue as well as the mean and standard deviation over all residues with each
... | python | def get_B_factors(self, force = False):
'''This reads in all ATOM lines and compute the mean and standard deviation of each
residue's B-factors. It returns a table of the mean and standard deviation per
residue as well as the mean and standard deviation over all residues with each
... | [
"def",
"get_B_factors",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"# Read in the list of bfactors for each ATOM line.",
"if",
"(",
"not",
"self",
".",
"bfactors",
")",
"or",
"(",
"force",
"==",
"True",
")",
":",
"bfactors",
"=",
"{",
"}",
"old_chain... | This reads in all ATOM lines and compute the mean and standard deviation of each
residue's B-factors. It returns a table of the mean and standard deviation per
residue as well as the mean and standard deviation over all residues with each
residue having equal weighting.
Whet... | [
"This",
"reads",
"in",
"all",
"ATOM",
"lines",
"and",
"compute",
"the",
"mean",
"and",
"standard",
"deviation",
"of",
"each",
"residue",
"s",
"B",
"-",
"factors",
".",
"It",
"returns",
"a",
"table",
"of",
"the",
"mean",
"and",
"standard",
"deviation",
"p... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2071-L2104 | train | This reads in all ATOM lines and compute the mean and standard deviation of each residue s B - factors. It returns a table of the mean and standard deviation per residue and the mean and standard deviation per residue. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.GetRosettaResidueMap | def GetRosettaResidueMap(self, ConvertMSEToAtom = False, RemoveIncompleteFinalResidues = False, RemoveIncompleteResidues = False):
'''Note: This function ignores any DNA.'''
raise Exception('This code looks to be deprecated. Use construct_pdb_to_rosetta_residue_map instead.')
chain = None
... | python | def GetRosettaResidueMap(self, ConvertMSEToAtom = False, RemoveIncompleteFinalResidues = False, RemoveIncompleteResidues = False):
'''Note: This function ignores any DNA.'''
raise Exception('This code looks to be deprecated. Use construct_pdb_to_rosetta_residue_map instead.')
chain = None
... | [
"def",
"GetRosettaResidueMap",
"(",
"self",
",",
"ConvertMSEToAtom",
"=",
"False",
",",
"RemoveIncompleteFinalResidues",
"=",
"False",
",",
"RemoveIncompleteResidues",
"=",
"False",
")",
":",
"raise",
"Exception",
"(",
"'This code looks to be deprecated. Use construct_pdb_t... | Note: This function ignores any DNA. | [
"Note",
":",
"This",
"function",
"ignores",
"any",
"DNA",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2115-L2234 | train | This function returns a dictionary of all the residue IDs that are used in the ROSetTA residue table. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.validate_mutations | def validate_mutations(self, mutations):
'''This function has been refactored to use the SimpleMutation class.
The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException
if the wildtype in the Mutation m does not match the residue type... | python | def validate_mutations(self, mutations):
'''This function has been refactored to use the SimpleMutation class.
The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException
if the wildtype in the Mutation m does not match the residue type... | [
"def",
"validate_mutations",
"(",
"self",
",",
"mutations",
")",
":",
"# Chain, ResidueID, WildTypeAA, MutantAA",
"resID2AA",
"=",
"self",
".",
"get_residue_id_to_type_map",
"(",
")",
"badmutations",
"=",
"[",
"]",
"for",
"m",
"in",
"mutations",
":",
"wildtype",
"... | This function has been refactored to use the SimpleMutation class.
The parameter is a list of Mutation objects. The function has no return value but raises a PDBValidationException
if the wildtype in the Mutation m does not match the residue type corresponding to residue m.ResidueID in the PDB fil... | [
"This",
"function",
"has",
"been",
"refactored",
"to",
"use",
"the",
"SimpleMutation",
"class",
".",
"The",
"parameter",
"is",
"a",
"list",
"of",
"Mutation",
"objects",
".",
"The",
"function",
"has",
"no",
"return",
"value",
"but",
"raises",
"a",
"PDBValidat... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2252-L2265 | train | This function is refactored to use the SimpleMutation class. It is called by the validate_mutations method in order to validate the list of mutations. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.fix_chain_id | def fix_chain_id(self):
"""fill in missing chain identifier"""
for i in xrange(len(self.lines)):
line = self.lines[i]
if line.startswith("ATOM") and line[21] == ' ':
self.lines[i] = line[:21] + 'A' + line[22:] | python | def fix_chain_id(self):
"""fill in missing chain identifier"""
for i in xrange(len(self.lines)):
line = self.lines[i]
if line.startswith("ATOM") and line[21] == ' ':
self.lines[i] = line[:21] + 'A' + line[22:] | [
"def",
"fix_chain_id",
"(",
"self",
")",
":",
"for",
"i",
"in",
"xrange",
"(",
"len",
"(",
"self",
".",
"lines",
")",
")",
":",
"line",
"=",
"self",
".",
"lines",
"[",
"i",
"]",
"if",
"line",
".",
"startswith",
"(",
"\"ATOM\"",
")",
"and",
"line"... | fill in missing chain identifier | [
"fill",
"in",
"missing",
"chain",
"identifier"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2308-L2314 | train | fill in missing chain identifier |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.getAtomLine | def getAtomLine(self, chain, resid):
'''This function assumes that all lines are ATOM or HETATM lines.
resid should have the proper PDB format i.e. an integer left-padded
to length 4 followed by the insertion code which may be a blank space.'''
for line in self.lines:
f... | python | def getAtomLine(self, chain, resid):
'''This function assumes that all lines are ATOM or HETATM lines.
resid should have the proper PDB format i.e. an integer left-padded
to length 4 followed by the insertion code which may be a blank space.'''
for line in self.lines:
f... | [
"def",
"getAtomLine",
"(",
"self",
",",
"chain",
",",
"resid",
")",
":",
"for",
"line",
"in",
"self",
".",
"lines",
":",
"fieldtype",
"=",
"line",
"[",
"0",
":",
"6",
"]",
".",
"strip",
"(",
")",
"assert",
"(",
"fieldtype",
"==",
"\"ATOM\"",
"or",
... | This function assumes that all lines are ATOM or HETATM lines.
resid should have the proper PDB format i.e. an integer left-padded
to length 4 followed by the insertion code which may be a blank space. | [
"This",
"function",
"assumes",
"that",
"all",
"lines",
"are",
"ATOM",
"or",
"HETATM",
"lines",
".",
"resid",
"should",
"have",
"the",
"proper",
"PDB",
"format",
"i",
".",
"e",
".",
"an",
"integer",
"left",
"-",
"padded",
"to",
"length",
"4",
"followed",
... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2329-L2338 | train | This function returns the ATOM or HETATM line corresponding to the given chain and residue. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.getAtomLinesForResidueInRosettaStructure | def getAtomLinesForResidueInRosettaStructure(self, resid):
'''We assume a Rosetta-generated structure where residues are uniquely identified by number.'''
lines = [line for line in self.lines if line[0:4] == "ATOM" and resid == int(line[22:27])]
if not lines:
#print('Failed searching... | python | def getAtomLinesForResidueInRosettaStructure(self, resid):
'''We assume a Rosetta-generated structure where residues are uniquely identified by number.'''
lines = [line for line in self.lines if line[0:4] == "ATOM" and resid == int(line[22:27])]
if not lines:
#print('Failed searching... | [
"def",
"getAtomLinesForResidueInRosettaStructure",
"(",
"self",
",",
"resid",
")",
":",
"lines",
"=",
"[",
"line",
"for",
"line",
"in",
"self",
".",
"lines",
"if",
"line",
"[",
"0",
":",
"4",
"]",
"==",
"\"ATOM\"",
"and",
"resid",
"==",
"int",
"(",
"li... | We assume a Rosetta-generated structure where residues are uniquely identified by number. | [
"We",
"assume",
"a",
"Rosetta",
"-",
"generated",
"structure",
"where",
"residues",
"are",
"uniquely",
"identified",
"by",
"number",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2340-L2347 | train | We assume a Rosetta - generated structure where residues are uniquely identified by number. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.remapMutations | def remapMutations(self, mutations, pdbID = '?'):
'''Takes in a list of (Chain, ResidueID, WildTypeAA, MutantAA) mutation tuples and returns the remapped
mutations based on the ddGResmap (which must be previously instantiated).
This function checks that the mutated positions exist and that... | python | def remapMutations(self, mutations, pdbID = '?'):
'''Takes in a list of (Chain, ResidueID, WildTypeAA, MutantAA) mutation tuples and returns the remapped
mutations based on the ddGResmap (which must be previously instantiated).
This function checks that the mutated positions exist and that... | [
"def",
"remapMutations",
"(",
"self",
",",
"mutations",
",",
"pdbID",
"=",
"'?'",
")",
":",
"raise",
"Exception",
"(",
"'This code is deprecated. Please use map_pdb_residues_to_rosetta_residues instead.'",
")",
"remappedMutations",
"=",
"[",
"]",
"ddGResmap",
"=",
"self... | Takes in a list of (Chain, ResidueID, WildTypeAA, MutantAA) mutation tuples and returns the remapped
mutations based on the ddGResmap (which must be previously instantiated).
This function checks that the mutated positions exist and that the wild-type matches the PDB. | [
"Takes",
"in",
"a",
"list",
"of",
"(",
"Chain",
"ResidueID",
"WildTypeAA",
"MutantAA",
")",
"mutation",
"tuples",
"and",
"returns",
"the",
"remapped",
"mutations",
"based",
"on",
"the",
"ddGResmap",
"(",
"which",
"must",
"be",
"previously",
"instantiated",
")"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2349-L2370 | train | Takes in a list of mutation tuples and returns the list of mutated positions and the remapped residue IDs. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.stripForDDG | def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True):
'''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.
By default all PDB chains are kept. The chains parameter should be True or a list.
In the latter case... | python | def stripForDDG(self, chains = True, keepHETATM = False, numberOfModels = None, raise_exception = True):
'''Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.
By default all PDB chains are kept. The chains parameter should be True or a list.
In the latter case... | [
"def",
"stripForDDG",
"(",
"self",
",",
"chains",
"=",
"True",
",",
"keepHETATM",
"=",
"False",
",",
"numberOfModels",
"=",
"None",
",",
"raise_exception",
"=",
"True",
")",
":",
"if",
"raise_exception",
":",
"raise",
"Exception",
"(",
"'This code is deprecate... | Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines.
By default all PDB chains are kept. The chains parameter should be True or a list.
In the latter case, only those chains in the list are kept.
Unoccupied ATOM lines are discarded.
This function a... | [
"Strips",
"a",
"PDB",
"to",
"ATOM",
"lines",
".",
"If",
"keepHETATM",
"is",
"True",
"then",
"also",
"retain",
"HETATM",
"lines",
".",
"By",
"default",
"all",
"PDB",
"chains",
"are",
"kept",
".",
"The",
"chains",
"parameter",
"should",
"be",
"True",
"or",... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2372-L2432 | train | Strips a PDB to ATOM lines. If keepHETATM is True then also retain HETATM lines. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.CheckForPresenceOf | def CheckForPresenceOf(self, reslist):
'''This checks whether residues in reslist exist in the ATOM lines.
It returns a list of the residues in reslist which did exist.'''
if type(reslist) == type(""):
reslist = [reslist]
foundRes = {}
for line in self.lines:
... | python | def CheckForPresenceOf(self, reslist):
'''This checks whether residues in reslist exist in the ATOM lines.
It returns a list of the residues in reslist which did exist.'''
if type(reslist) == type(""):
reslist = [reslist]
foundRes = {}
for line in self.lines:
... | [
"def",
"CheckForPresenceOf",
"(",
"self",
",",
"reslist",
")",
":",
"if",
"type",
"(",
"reslist",
")",
"==",
"type",
"(",
"\"\"",
")",
":",
"reslist",
"=",
"[",
"reslist",
"]",
"foundRes",
"=",
"{",
"}",
"for",
"line",
"in",
"self",
".",
"lines",
"... | This checks whether residues in reslist exist in the ATOM lines.
It returns a list of the residues in reslist which did exist. | [
"This",
"checks",
"whether",
"residues",
"in",
"reslist",
"exist",
"in",
"the",
"ATOM",
"lines",
".",
"It",
"returns",
"a",
"list",
"of",
"the",
"residues",
"in",
"reslist",
"which",
"did",
"exist",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2475-L2488 | train | This checks whether residues in reslist exist in the ATOM lines. It returns a list of the residues in reslist which did exist. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_residue_id_to_type_map | def get_residue_id_to_type_map(self):
'''Returns a dictionary mapping 6-character residue IDs (Chain, residue number, insertion code e.g. "A 123B") to the
corresponding one-letter amino acid.
Caveat: This function ignores occupancy - this function should be called once occupancy has been ... | python | def get_residue_id_to_type_map(self):
'''Returns a dictionary mapping 6-character residue IDs (Chain, residue number, insertion code e.g. "A 123B") to the
corresponding one-letter amino acid.
Caveat: This function ignores occupancy - this function should be called once occupancy has been ... | [
"def",
"get_residue_id_to_type_map",
"(",
"self",
")",
":",
"resid2type",
"=",
"{",
"}",
"atomlines",
"=",
"self",
".",
"parsed_lines",
"[",
"'ATOM '",
"]",
"for",
"line",
"in",
"atomlines",
":",
"resname",
"=",
"line",
"[",
"17",
":",
"20",
"]",
"if",
... | Returns a dictionary mapping 6-character residue IDs (Chain, residue number, insertion code e.g. "A 123B") to the
corresponding one-letter amino acid.
Caveat: This function ignores occupancy - this function should be called once occupancy has been dealt with appropriately. | [
"Returns",
"a",
"dictionary",
"mapping",
"6",
"-",
"character",
"residue",
"IDs",
"(",
"Chain",
"residue",
"number",
"insertion",
"code",
"e",
".",
"g",
".",
"A",
"123B",
")",
"to",
"the",
"corresponding",
"one",
"-",
"letter",
"amino",
"acid",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2490-L2502 | train | Returns a dictionary mapping 6 - character residue IDs to residue types corresponding one - letter amino acid. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.fix_residue_numbering | def fix_residue_numbering(self):
"""this function renumbers the res ids in order to avoid strange behaviour of Rosetta"""
resid_list = self.aa_resids()
resid_set = set(resid_list)
resid_lst1 = list(resid_set)
resid_lst1.sort()
map_res_id = {}
x = 1
old_... | python | def fix_residue_numbering(self):
"""this function renumbers the res ids in order to avoid strange behaviour of Rosetta"""
resid_list = self.aa_resids()
resid_set = set(resid_list)
resid_lst1 = list(resid_set)
resid_lst1.sort()
map_res_id = {}
x = 1
old_... | [
"def",
"fix_residue_numbering",
"(",
"self",
")",
":",
"resid_list",
"=",
"self",
".",
"aa_resids",
"(",
")",
"resid_set",
"=",
"set",
"(",
"resid_list",
")",
"resid_lst1",
"=",
"list",
"(",
"resid_set",
")",
"resid_lst1",
".",
"sort",
"(",
")",
"map_res_i... | this function renumbers the res ids in order to avoid strange behaviour of Rosetta | [
"this",
"function",
"renumbers",
"the",
"res",
"ids",
"in",
"order",
"to",
"avoid",
"strange",
"behaviour",
"of",
"Rosetta"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2542-L2573 | train | this function renumbers the residue numbering in order to avoid strange behaviour of Rosetta |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.get_residue_mapping | def get_residue_mapping(self):
"""this function maps the chain and res ids "A 234" to values from [1-N]"""
resid_list = self.aa_resids()
# resid_set = set(resid_list)
# resid_lst1 = list(resid_set)
# resid_lst1.sort()
map_res_id = {}
x = 1
for resid in ... | python | def get_residue_mapping(self):
"""this function maps the chain and res ids "A 234" to values from [1-N]"""
resid_list = self.aa_resids()
# resid_set = set(resid_list)
# resid_lst1 = list(resid_set)
# resid_lst1.sort()
map_res_id = {}
x = 1
for resid in ... | [
"def",
"get_residue_mapping",
"(",
"self",
")",
":",
"resid_list",
"=",
"self",
".",
"aa_resids",
"(",
")",
"# resid_set = set(resid_list)",
"# resid_lst1 = list(resid_set)",
"# resid_lst1.sort()",
"map_res_id",
"=",
"{",
"}",
"x",
"=",
"1",
"for",
"resid",
"in",
... | this function maps the chain and res ids "A 234" to values from [1-N] | [
"this",
"function",
"maps",
"the",
"chain",
"and",
"res",
"ids",
"A",
"234",
"to",
"values",
"from",
"[",
"1",
"-",
"N",
"]"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2575-L2589 | train | this function maps the chain and res ids A 234 to values from [ 1 - N ) |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.neighbors2 | def neighbors2(self, distance, chain_residue, atom = None, resid_list = None):
#atom = " CA "
'''this one is more precise since it uses the chain identifier also'''
if atom == None: # consider all atoms
lines = [line for line in self.atomlines(resid_list) if line[17:20] in allo... | python | def neighbors2(self, distance, chain_residue, atom = None, resid_list = None):
#atom = " CA "
'''this one is more precise since it uses the chain identifier also'''
if atom == None: # consider all atoms
lines = [line for line in self.atomlines(resid_list) if line[17:20] in allo... | [
"def",
"neighbors2",
"(",
"self",
",",
"distance",
",",
"chain_residue",
",",
"atom",
"=",
"None",
",",
"resid_list",
"=",
"None",
")",
":",
"#atom = \" CA \"",
"if",
"atom",
"==",
"None",
":",
"# consider all atoms",
"lines",
"=",
"[",
"line",
"for",
"lin... | this one is more precise since it uses the chain identifier also | [
"this",
"one",
"is",
"more",
"precise",
"since",
"it",
"uses",
"the",
"chain",
"identifier",
"also"
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2634-L2660 | train | returns a list of all neighbors of a given residue |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.extract_xyz_matrix_from_chain | def extract_xyz_matrix_from_chain(self, chain_id, atoms_of_interest = []):
'''Create a pandas coordinates dataframe from the lines in the specified chain.'''
chains = [l[21] for l in self.structure_lines if len(l) > 21]
chain_lines = [l for l in self.structure_lines if len(l) > 21 and l[21] == c... | python | def extract_xyz_matrix_from_chain(self, chain_id, atoms_of_interest = []):
'''Create a pandas coordinates dataframe from the lines in the specified chain.'''
chains = [l[21] for l in self.structure_lines if len(l) > 21]
chain_lines = [l for l in self.structure_lines if len(l) > 21 and l[21] == c... | [
"def",
"extract_xyz_matrix_from_chain",
"(",
"self",
",",
"chain_id",
",",
"atoms_of_interest",
"=",
"[",
"]",
")",
":",
"chains",
"=",
"[",
"l",
"[",
"21",
"]",
"for",
"l",
"in",
"self",
".",
"structure_lines",
"if",
"len",
"(",
"l",
")",
">",
"21",
... | Create a pandas coordinates dataframe from the lines in the specified chain. | [
"Create",
"a",
"pandas",
"coordinates",
"dataframe",
"from",
"the",
"lines",
"in",
"the",
"specified",
"chain",
"."
] | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L2998-L3002 | train | Create a pandas coordinates dataframe from the lines in the specified chain. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.extract_xyz_matrix_from_pdb | def extract_xyz_matrix_from_pdb(pdb_lines, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, fail_on_model_records = True, include_all_columns = False):
'''Returns a pandas dataframe of X, Y, Z coordinates for all chains in the PDB.
Note: This functi... | python | def extract_xyz_matrix_from_pdb(pdb_lines, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, fail_on_model_records = True, include_all_columns = False):
'''Returns a pandas dataframe of X, Y, Z coordinates for all chains in the PDB.
Note: This functi... | [
"def",
"extract_xyz_matrix_from_pdb",
"(",
"pdb_lines",
",",
"atoms_of_interest",
"=",
"backbone_atoms",
",",
"expected_num_residues",
"=",
"None",
",",
"expected_num_residue_atoms",
"=",
"None",
",",
"fail_on_model_records",
"=",
"True",
",",
"include_all_columns",
"=",
... | Returns a pandas dataframe of X, Y, Z coordinates for all chains in the PDB.
Note: This function is not intended to handle structures with MODELs e.g. from NMR although the fail_on_model_records
check is optional for convenience in case the first model is to be parsed.
Otherwise, the fi... | [
"Returns",
"a",
"pandas",
"dataframe",
"of",
"X",
"Y",
"Z",
"coordinates",
"for",
"all",
"chains",
"in",
"the",
"PDB",
".",
"Note",
":",
"This",
"function",
"is",
"not",
"intended",
"to",
"handle",
"structures",
"with",
"MODELs",
"e",
".",
"g",
".",
"f... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L3006-L3022 | train | Returns a pandas dataframe of X Y Z coordinates for all chains in the PDB. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.extract_xyz_matrix_from_pdb_chain | def extract_xyz_matrix_from_pdb_chain(pdb_lines, chain_id, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, fail_on_model_records = True, include_all_columns = False):
'''Returns a pandas dataframe of X, Y, Z coordinates for the PDB chain.
Note: Thi... | python | def extract_xyz_matrix_from_pdb_chain(pdb_lines, chain_id, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, fail_on_model_records = True, include_all_columns = False):
'''Returns a pandas dataframe of X, Y, Z coordinates for the PDB chain.
Note: Thi... | [
"def",
"extract_xyz_matrix_from_pdb_chain",
"(",
"pdb_lines",
",",
"chain_id",
",",
"atoms_of_interest",
"=",
"backbone_atoms",
",",
"expected_num_residues",
"=",
"None",
",",
"expected_num_residue_atoms",
"=",
"None",
",",
"fail_on_model_records",
"=",
"True",
",",
"in... | Returns a pandas dataframe of X, Y, Z coordinates for the PDB chain.
Note: This function is not intended to handle structures with MODELs e.g. from NMR although the fail_on_model_records
check is optional for convenience in case the chain of the first model is to be parsed. | [
"Returns",
"a",
"pandas",
"dataframe",
"of",
"X",
"Y",
"Z",
"coordinates",
"for",
"the",
"PDB",
"chain",
".",
"Note",
":",
"This",
"function",
"is",
"not",
"intended",
"to",
"handle",
"structures",
"with",
"MODELs",
"e",
".",
"g",
".",
"from",
"NMR",
"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L3026-L3045 | train | Returns a pandas dataframe of X Y Z coordinates for the given PDB chain. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.extract_xyz_matrix_from_loop_json | def extract_xyz_matrix_from_loop_json(pdb_lines, parsed_loop_json_contents, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, allow_overlaps = False, include_all_columns = False):
'''A utility wrapper to extract_xyz_matrix_from_pdb_residue_range.
Thi... | python | def extract_xyz_matrix_from_loop_json(pdb_lines, parsed_loop_json_contents, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, allow_overlaps = False, include_all_columns = False):
'''A utility wrapper to extract_xyz_matrix_from_pdb_residue_range.
Thi... | [
"def",
"extract_xyz_matrix_from_loop_json",
"(",
"pdb_lines",
",",
"parsed_loop_json_contents",
",",
"atoms_of_interest",
"=",
"backbone_atoms",
",",
"expected_num_residues",
"=",
"None",
",",
"expected_num_residue_atoms",
"=",
"None",
",",
"allow_overlaps",
"=",
"False",
... | A utility wrapper to extract_xyz_matrix_from_pdb_residue_range.
This accepts PDB file lines and a loop.json file (a defined Rosetta format) and returns a pandas dataframe of
the X, Y, Z coordinates for the requested atom types for all residues in all loops defined by the loop.json
file.... | [
"A",
"utility",
"wrapper",
"to",
"extract_xyz_matrix_from_pdb_residue_range",
".",
"This",
"accepts",
"PDB",
"file",
"lines",
"and",
"a",
"loop",
".",
"json",
"file",
"(",
"a",
"defined",
"Rosetta",
"format",
")",
"and",
"returns",
"a",
"pandas",
"dataframe",
... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L3049-L3068 | train | A utility wrapper to extract_xyz_matrix_from_pdb_residue_range. This accepts a list of lines and a dict read in from a loop. json file and returns a pandas dataframe of xyz coordinates for all residues in all loops. |
Kortemme-Lab/klab | klab/bio/pdb.py | PDB.extract_xyz_matrix_from_pdb_residue_range | def extract_xyz_matrix_from_pdb_residue_range(pdb_lines, start_pdb_residue_id = None, stop_pdb_residue_id = None, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, break_on_chain_end = True, include_all_columns = False):
'''Creates a pandas dataframe of X, Y, Z... | python | def extract_xyz_matrix_from_pdb_residue_range(pdb_lines, start_pdb_residue_id = None, stop_pdb_residue_id = None, atoms_of_interest = backbone_atoms, expected_num_residues = None, expected_num_residue_atoms = None, break_on_chain_end = True, include_all_columns = False):
'''Creates a pandas dataframe of X, Y, Z... | [
"def",
"extract_xyz_matrix_from_pdb_residue_range",
"(",
"pdb_lines",
",",
"start_pdb_residue_id",
"=",
"None",
",",
"stop_pdb_residue_id",
"=",
"None",
",",
"atoms_of_interest",
"=",
"backbone_atoms",
",",
"expected_num_residues",
"=",
"None",
",",
"expected_num_residue_at... | Creates a pandas dataframe of X, Y, Z coordinates for the residues identified in the range from
start_pdb_residue_id to stop_pdb_residue_id inclusive. The dataframe is indexed by a string identifying the
PDB residue and atom type.
pdb_lines should be an array of lines from a PDB file (... | [
"Creates",
"a",
"pandas",
"dataframe",
"of",
"X",
"Y",
"Z",
"coordinates",
"for",
"the",
"residues",
"identified",
"in",
"the",
"range",
"from",
"start_pdb_residue_id",
"to",
"stop_pdb_residue_id",
"inclusive",
".",
"The",
"dataframe",
"is",
"indexed",
"by",
"a"... | 6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b | https://github.com/Kortemme-Lab/klab/blob/6d410ad08f1bd9f7cbbb28d7d946e94fbaaa2b6b/klab/bio/pdb.py#L3072-L3146 | train | Creates a pandas dataframe of X Y Z coordinates for the residues identified in the range from start_pdb_residue_id to stop_pdb_residue_id inclusive. |
cozy/python_cozy_management | cozy_management/couchdb.py | create_token_file | def create_token_file(username=id_generator(), password=id_generator()):
'''
Store the admins password for further retrieve
'''
cozy_ds_uid = helpers.get_uid('cozy-data-system')
if not os.path.isfile(LOGIN_FILENAME):
with open(LOGIN_FILENAME, 'w+') as token_file:
token_file.... | python | def create_token_file(username=id_generator(), password=id_generator()):
'''
Store the admins password for further retrieve
'''
cozy_ds_uid = helpers.get_uid('cozy-data-system')
if not os.path.isfile(LOGIN_FILENAME):
with open(LOGIN_FILENAME, 'w+') as token_file:
token_file.... | [
"def",
"create_token_file",
"(",
"username",
"=",
"id_generator",
"(",
")",
",",
"password",
"=",
"id_generator",
"(",
")",
")",
":",
"cozy_ds_uid",
"=",
"helpers",
".",
"get_uid",
"(",
"'cozy-data-system'",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfil... | Store the admins password for further retrieve | [
"Store",
"the",
"admins",
"password",
"for",
"further",
"retrieve"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L37-L47 | train | Create the token file for the current user. |
cozy/python_cozy_management | cozy_management/couchdb.py | get_admin | def get_admin():
'''
Return the actual admin from token file
'''
if os.path.isfile(LOGIN_FILENAME):
with open(LOGIN_FILENAME, 'r') as token_file:
old_login, old_password = token_file.read().splitlines()[:2]
return old_login, old_password
else:
return None,... | python | def get_admin():
'''
Return the actual admin from token file
'''
if os.path.isfile(LOGIN_FILENAME):
with open(LOGIN_FILENAME, 'r') as token_file:
old_login, old_password = token_file.read().splitlines()[:2]
return old_login, old_password
else:
return None,... | [
"def",
"get_admin",
"(",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"LOGIN_FILENAME",
")",
":",
"with",
"open",
"(",
"LOGIN_FILENAME",
",",
"'r'",
")",
"as",
"token_file",
":",
"old_login",
",",
"old_password",
"=",
"token_file",
".",
"read",... | Return the actual admin from token file | [
"Return",
"the",
"actual",
"admin",
"from",
"token",
"file"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L50-L59 | train | Return the actual admin from token file
|
cozy/python_cozy_management | cozy_management/couchdb.py | curl_couchdb | def curl_couchdb(url, method='GET', base_url=BASE_URL, data=None):
'''
Launch a curl on CouchDB instance
'''
(username, password) = get_admin()
if username is None:
auth = None
else:
auth = (username, password)
if method == 'PUT':
req = requests.put('{}{}'.format... | python | def curl_couchdb(url, method='GET', base_url=BASE_URL, data=None):
'''
Launch a curl on CouchDB instance
'''
(username, password) = get_admin()
if username is None:
auth = None
else:
auth = (username, password)
if method == 'PUT':
req = requests.put('{}{}'.format... | [
"def",
"curl_couchdb",
"(",
"url",
",",
"method",
"=",
"'GET'",
",",
"base_url",
"=",
"BASE_URL",
",",
"data",
"=",
"None",
")",
":",
"(",
"username",
",",
"password",
")",
"=",
"get_admin",
"(",
")",
"if",
"username",
"is",
"None",
":",
"auth",
"=",... | Launch a curl on CouchDB instance | [
"Launch",
"a",
"curl",
"on",
"CouchDB",
"instance"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L62-L81 | train | Launch a curl on CouchDB instance |
cozy/python_cozy_management | cozy_management/couchdb.py | get_couchdb_admins | def get_couchdb_admins():
'''
Return the actual CouchDB admins
'''
user_list = []
req = curl_couchdb('/_config/admins/')
for user in req.json().keys():
user_list.append(user)
return user_list | python | def get_couchdb_admins():
'''
Return the actual CouchDB admins
'''
user_list = []
req = curl_couchdb('/_config/admins/')
for user in req.json().keys():
user_list.append(user)
return user_list | [
"def",
"get_couchdb_admins",
"(",
")",
":",
"user_list",
"=",
"[",
"]",
"req",
"=",
"curl_couchdb",
"(",
"'/_config/admins/'",
")",
"for",
"user",
"in",
"req",
".",
"json",
"(",
")",
".",
"keys",
"(",
")",
":",
"user_list",
".",
"append",
"(",
"user",
... | Return the actual CouchDB admins | [
"Return",
"the",
"actual",
"CouchDB",
"admins"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L84-L94 | train | Return the actual CouchDB admins |
cozy/python_cozy_management | cozy_management/couchdb.py | create_couchdb_admin | def create_couchdb_admin(username, password):
'''
Create a CouchDB user
'''
curl_couchdb('/_config/admins/{}'.format(username),
method='PUT',
data='"{}"'.format(password)) | python | def create_couchdb_admin(username, password):
'''
Create a CouchDB user
'''
curl_couchdb('/_config/admins/{}'.format(username),
method='PUT',
data='"{}"'.format(password)) | [
"def",
"create_couchdb_admin",
"(",
"username",
",",
"password",
")",
":",
"curl_couchdb",
"(",
"'/_config/admins/{}'",
".",
"format",
"(",
"username",
")",
",",
"method",
"=",
"'PUT'",
",",
"data",
"=",
"'\"{}\"'",
".",
"format",
"(",
"password",
")",
")"
] | Create a CouchDB user | [
"Create",
"a",
"CouchDB",
"user"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L97-L103 | train | Create a CouchDB user |
cozy/python_cozy_management | cozy_management/couchdb.py | is_cozy_registered | def is_cozy_registered():
'''
Check if a Cozy is registered
'''
req = curl_couchdb('/cozy/_design/user/_view/all')
users = req.json()['rows']
if len(users) > 0:
return True
else:
return False | python | def is_cozy_registered():
'''
Check if a Cozy is registered
'''
req = curl_couchdb('/cozy/_design/user/_view/all')
users = req.json()['rows']
if len(users) > 0:
return True
else:
return False | [
"def",
"is_cozy_registered",
"(",
")",
":",
"req",
"=",
"curl_couchdb",
"(",
"'/cozy/_design/user/_view/all'",
")",
"users",
"=",
"req",
".",
"json",
"(",
")",
"[",
"'rows'",
"]",
"if",
"len",
"(",
"users",
")",
">",
"0",
":",
"return",
"True",
"else",
... | Check if a Cozy is registered | [
"Check",
"if",
"a",
"Cozy",
"is",
"registered"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L114-L124 | train | Check if a Cozy is registered |
cozy/python_cozy_management | cozy_management/couchdb.py | unregister_cozy | def unregister_cozy():
'''
Unregister a cozy
'''
req = curl_couchdb('/cozy/_design/user/_view/all')
users = req.json()['rows']
if len(users) > 0:
user = users[0]['value']
user_id = user['_id']
user_rev = user['_rev']
print 'Delete cozy user: {}'.format(user_... | python | def unregister_cozy():
'''
Unregister a cozy
'''
req = curl_couchdb('/cozy/_design/user/_view/all')
users = req.json()['rows']
if len(users) > 0:
user = users[0]['value']
user_id = user['_id']
user_rev = user['_rev']
print 'Delete cozy user: {}'.format(user_... | [
"def",
"unregister_cozy",
"(",
")",
":",
"req",
"=",
"curl_couchdb",
"(",
"'/cozy/_design/user/_view/all'",
")",
"users",
"=",
"req",
".",
"json",
"(",
")",
"[",
"'rows'",
"]",
"if",
"len",
"(",
"users",
")",
">",
"0",
":",
"user",
"=",
"users",
"[",
... | Unregister a cozy | [
"Unregister",
"a",
"cozy"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L127-L146 | train | Unregister a cozy |
cozy/python_cozy_management | cozy_management/couchdb.py | delete_all_couchdb_admins | def delete_all_couchdb_admins():
'''
Delete all CouchDB users
'''
# Get current cozy token
username = get_admin()[0]
# Get CouchDB admin list
admins = get_couchdb_admins()
# Delete all admin user excluding current
for admin in admins:
if admin == username:
pr... | python | def delete_all_couchdb_admins():
'''
Delete all CouchDB users
'''
# Get current cozy token
username = get_admin()[0]
# Get CouchDB admin list
admins = get_couchdb_admins()
# Delete all admin user excluding current
for admin in admins:
if admin == username:
pr... | [
"def",
"delete_all_couchdb_admins",
"(",
")",
":",
"# Get current cozy token",
"username",
"=",
"get_admin",
"(",
")",
"[",
"0",
"]",
"# Get CouchDB admin list",
"admins",
"=",
"get_couchdb_admins",
"(",
")",
"# Delete all admin user excluding current",
"for",
"admin",
... | Delete all CouchDB users | [
"Delete",
"all",
"CouchDB",
"users"
] | 820cea58458ae3e067fa8cc2da38edbda4681dac | https://github.com/cozy/python_cozy_management/blob/820cea58458ae3e067fa8cc2da38edbda4681dac/cozy_management/couchdb.py#L159-L179 | train | Delete all CouchDB admins excluding current ones |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.