initialization

class pyrosetta.utility.initialization.PyRosettaInitFileParserBase

Bases: object

_database_option_name = 'in:path:database'
_corrections_option_name = 'corrections:'
_init_file_extension = '.init'
_strftime_format = '%Y-%m-%d-%H-%M-%S'
_required_keys = ('author', 'datetime', 'email', 'license', 'md5', 'metadata', 'num_files', 'num_poses', 'options', 'poses', 'pyrosetta_build')
get_pyrosetta_build()
pyrosetta_build_warning(original_pyrosetta_build, current_pyrosetta_build)
get_to_base64()
property was_init_called
validate_init_was_called()
validate_init_was_not_called()
md5_warning(md5, expected_md5)
class pyrosetta.utility.initialization.PyRosettaInitFileSerializer

Bases: object

_chunk_size = 65536
_compression_level = 9
_encoding = 'utf-8'
_decode_errors = 'strict'
_prefix_string = '[PyRosettaInitTextFile]'
_prefix_binary = '[PyRosettaInitBinaryFile]'
_tag_str = b'Txt'
_tag_obj = b'Obj'
dump_json(obj)
load_json(string)
join_tag(tag, raw)
split_tag(obj)
encode_bytestring(bytestring)
encode_string(obj)
decode_binary(string)
decode_string(bytestring, max_decompressed_bytes)
zlib_decompress(data, max_decompressed_bytes)
get_zlib_decompress_err_msg(arr, max_decompressed_bytes)
static to_json(init_dict)
static from_json(string)
static get_md5(init_dict)
class pyrosetta.utility.initialization.PyRosettaInitFileWriter(output_filename, **kwargs)

Bases: PyRosettaInitFileParserBase, PyRosettaInitFileSerializer

__init__(output_filename, **kwargs)
setup_output_filename(output_filename)
setup_kwargs(**kwargs)
_poses_error_msg(obj)
assert_metadata_json_serializable(data)
get_datetime_now()
init_pose()
get_protocol_settings_metric(base_name_option_only=False, get_script_vars=False, get_user_options=True, skip_corrections=False)
get_protocol_settings_dict()
get_options_dict()
get_options_str()
get_encoded_options_dict()
is_text_file(filename)
encode_object(obj)
format_encode_bytestring(bytestring)
format_encode_string(string, parent_dir)
format_encode_substring(string)
encode_subfile(file)
encode(string, parent_dir)
encode_file(filename)
print_cached_files(output_filename, dry_run)
static write_json(data_dict, output_filename)
get_dict()
get_json()
dump()
_chunk_size = 65536
_compression_level = 9
_corrections_option_name = 'corrections:'
_database_option_name = 'in:path:database'
_decode_errors = 'strict'
_encoding = 'utf-8'
_init_file_extension = '.init'
_prefix_binary = '[PyRosettaInitBinaryFile]'
_prefix_string = '[PyRosettaInitTextFile]'
_required_keys = ('author', 'datetime', 'email', 'license', 'md5', 'metadata', 'num_files', 'num_poses', 'options', 'poses', 'pyrosetta_build')
_strftime_format = '%Y-%m-%d-%H-%M-%S'
_tag_obj = b'Obj'
_tag_str = b'Txt'
decode_binary(string)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_string(obj)
static from_json(string)
static get_md5(init_dict)
get_pyrosetta_build()
get_to_base64()
get_zlib_decompress_err_msg(arr, max_decompressed_bytes)
join_tag(tag, raw)
load_json(string)
md5_warning(md5, expected_md5)
pyrosetta_build_warning(original_pyrosetta_build, current_pyrosetta_build)
split_tag(obj)
static to_json(init_dict)
validate_init_was_called()
validate_init_was_not_called()
property was_init_called
zlib_decompress(data, max_decompressed_bytes)
class pyrosetta.utility.initialization.PyRosettaInitDictWriter(**kwargs)

Bases: PyRosettaInitFileWriter

__init__(**kwargs)
property _init_file_writer_err_msg
dump()
_chunk_size = 65536
_compression_level = 9
_corrections_option_name = 'corrections:'
_database_option_name = 'in:path:database'
_decode_errors = 'strict'
_encoding = 'utf-8'
_init_file_extension = '.init'
_poses_error_msg(obj)
_prefix_binary = '[PyRosettaInitBinaryFile]'
_prefix_string = '[PyRosettaInitTextFile]'
_required_keys = ('author', 'datetime', 'email', 'license', 'md5', 'metadata', 'num_files', 'num_poses', 'options', 'poses', 'pyrosetta_build')
_strftime_format = '%Y-%m-%d-%H-%M-%S'
_tag_obj = b'Obj'
_tag_str = b'Txt'
assert_metadata_json_serializable(data)
decode_binary(string)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode(string, parent_dir)
encode_bytestring(bytestring)
encode_file(filename)
encode_object(obj)
encode_string(obj)
encode_subfile(file)
format_encode_bytestring(bytestring)
format_encode_string(string, parent_dir)
format_encode_substring(string)
static from_json(string)
get_datetime_now()
get_dict()
get_encoded_options_dict()
get_json()
static get_md5(init_dict)
get_options_dict()
get_options_str()
get_protocol_settings_dict()
get_protocol_settings_metric(base_name_option_only=False, get_script_vars=False, get_user_options=True, skip_corrections=False)
get_pyrosetta_build()
get_to_base64()
get_zlib_decompress_err_msg(arr, max_decompressed_bytes)
init_pose()
is_text_file(filename)
join_tag(tag, raw)
load_json(string)
md5_warning(md5, expected_md5)
print_cached_files(output_filename, dry_run)
pyrosetta_build_warning(original_pyrosetta_build, current_pyrosetta_build)
setup_kwargs(**kwargs)
setup_output_filename(output_filename)
split_tag(obj)
static to_json(init_dict)
validate_init_was_called()
validate_init_was_not_called()
property was_init_called
static write_json(data_dict, output_filename)
zlib_decompress(data, max_decompressed_bytes)
class pyrosetta.utility.initialization.PyRosettaInitFileReader(init_file, **kwargs)

Bases: PyRosettaInitFileParserBase, PyRosettaInitFileSerializer

__init__(init_file, **kwargs)
setup_kwargs(**kwargs)
static from_json(string)
static read_json(init_file)
setup_init_dict(_init_dict)
get_encoded_options_dict()
property _malformed_init_file_error_msg
format_decode_binary(value)
format_decode_string(value, option_name)
format_decode_substring(value)
decode(encoded_object, option_name)
setup_new_file(option_name, basename)
write_file(option_name, basename, file_content, mode='w')
write_text_file(*args)
write_binary_file(*args)
get_options_dict()
get_options()
print_results()
print_info()
pprint_options(options)
init()
_chunk_size = 65536
_compression_level = 9
_corrections_option_name = 'corrections:'
_database_option_name = 'in:path:database'
_decode_errors = 'strict'
_encoding = 'utf-8'
_init_file_extension = '.init'
_prefix_binary = '[PyRosettaInitBinaryFile]'
_prefix_string = '[PyRosettaInitTextFile]'
_required_keys = ('author', 'datetime', 'email', 'license', 'md5', 'metadata', 'num_files', 'num_poses', 'options', 'poses', 'pyrosetta_build')
_strftime_format = '%Y-%m-%d-%H-%M-%S'
_tag_obj = b'Obj'
_tag_str = b'Txt'
decode_binary(string)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_string(obj)
static get_md5(init_dict)
get_pyrosetta_build()
get_to_base64()
get_zlib_decompress_err_msg(arr, max_decompressed_bytes)
join_tag(tag, raw)
load_json(string)
md5_warning(md5, expected_md5)
pyrosetta_build_warning(original_pyrosetta_build, current_pyrosetta_build)
split_tag(obj)
static to_json(init_dict)
validate_init_was_called()
validate_init_was_not_called()
property was_init_called
zlib_decompress(data, max_decompressed_bytes)
class pyrosetta.utility.initialization.PyRosettaInitDictReader(init_dict, **kwargs)

Bases: PyRosettaInitFileReader

__init__(init_dict, **kwargs)
property _malformed_init_file_error_msg
print_results()
_chunk_size = 65536
_compression_level = 9
_corrections_option_name = 'corrections:'
_database_option_name = 'in:path:database'
_decode_errors = 'strict'
_encoding = 'utf-8'
_init_file_extension = '.init'
_prefix_binary = '[PyRosettaInitBinaryFile]'
_prefix_string = '[PyRosettaInitTextFile]'
_required_keys = ('author', 'datetime', 'email', 'license', 'md5', 'metadata', 'num_files', 'num_poses', 'options', 'poses', 'pyrosetta_build')
_strftime_format = '%Y-%m-%d-%H-%M-%S'
_tag_obj = b'Obj'
_tag_str = b'Txt'
decode(encoded_object, option_name)
decode_binary(string)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_string(obj)
format_decode_binary(value)
format_decode_string(value, option_name)
format_decode_substring(value)
static from_json(string)
get_encoded_options_dict()
static get_md5(init_dict)
get_options()
get_options_dict()
get_pyrosetta_build()
get_to_base64()
get_zlib_decompress_err_msg(arr, max_decompressed_bytes)
init()
join_tag(tag, raw)
load_json(string)
md5_warning(md5, expected_md5)
pprint_options(options)
print_info()
pyrosetta_build_warning(original_pyrosetta_build, current_pyrosetta_build)
static read_json(init_file)
setup_init_dict(_init_dict)
setup_kwargs(**kwargs)
setup_new_file(option_name, basename)
split_tag(obj)
static to_json(init_dict)
validate_init_was_called()
validate_init_was_not_called()
property was_init_called
write_binary_file(*args)
write_file(option_name, basename, file_content, mode='w')
write_text_file(*args)
zlib_decompress(data, max_decompressed_bytes)
class pyrosetta.utility.initialization.PyRosettaInitFileParser

Bases: object

static init_from_file(init_file, dry_run=None, output_dir=None, skip_corrections=None, relative_paths=None, max_decompressed_bytes=None, database=None, verbose=None, set_logging_handler=None, notebook=None, silent=None)

Initialize PyRosetta from a ‘.init’ file.

This method decompresses PyRosetta initialization input files from an input ‘.init’ file into an output directory, and then runs pyrosetta.init with the cached Rosetta command line options pointing to the files written to the output directory. Therefore, it may be helpful to enable the ‘dry_run’ keyword argument to first inspect the Rosetta command line options before committing to writing all PyRosetta input files to disk and running PyRosetta initialization.

Args:

init_file: A required str object representing the input ‘.init’ file.

Keyword Args:
dry_run: An optional bool object specifying whether or not to write PyRosetta input files and perform PyRosetta

initialization. If True, then only print the PyRosetta initialization options that would be run if it were False. Default: False

output_dir: An optional str object representing the output directory into which to decompress PyRosetta input files.

Default: ./pyrosetta_init_input_files

skip_corrections: An optional bool object specifying whether or not to skip any ScoreFunction corrections specified

in the input ‘.init’ file, which are set in-code upon PyRosetta initialization. If a NoneType object is provided, then the input ScoreFunction corrections are automatically used for PyRosetta initialization only if the PyRosetta version from the ‘.init’ file does not match the current PyRosetta version. Default: None

relative_paths: An optional bool object specifying whether or not to initialize PyRosetta with the relative paths

(with respect to the current working directory) of the files written to the ‘output_dir’ keyword argument parameter. Default: False

max_decompressed_bytes: An optional int object specifying the maximum permitted number of bytes per decompressed PyRosetta

input file (with a default of 200 MB). If a PyRosetta input file in the input ‘.init’ file exceeds this buffer size upon decompression, then a BufferError is intentionally raised as a precaution. Default: 200_000_000

database: An optional str object representing the path to the Rosetta database. By default, the Rosetta database

is found using pyrosetta._rosetta_database_from_env(), but if the search fails then the Rosetta database path may be manually input here. Default: None

verbose: An optional bool object specifying whether or not to print PyRosetta initialization information.

Default: True

set_logging_handler: An optional object passed to pyrosetta.init(set_logging_handler=…) during PyRosetta initialization.

If a NoneType object is provided, then the default pyrosetta.init keyword argument parameter is used. Default: None

notebook: An optional object passed to pyrosetta.init(notebook=…) during PyRosetta initialization.

If a NoneType object is provided, then the default pyrosetta.init keyword argument parameter is used. Default: None

silent: An optional object passed to pyrosetta.init(silent=…) during PyRosetta initialization.

If a NoneType object is provided, then the default pyrosetta.init keyword argument parameter is used. Default: None

Returns:

None

static get_init_options_from_file(init_file, dry_run=True, output_dir=None, relative_paths=None, max_decompressed_bytes=None, database=None, as_dict=False)

Get PyRosetta initialization options from a ‘.init’ file.

This method returns the PyRosetta initialization options from an input ‘.init’ file without running pyrosetta.init(). The ‘dry_run’ keyword argument is enabled by default in order to inspect the Rosetta command line options before committing to decompressing and writing all PyRosetta input files to disk. If ‘dry_run’ is disabled, then also decompress the PyRosetta input files into an output directory given by the ‘output_dir’ keyword argument parameter without running pyrosetta.init().

Args:

init_file: A required str object representing the input ‘.init’ file.

Keyword Args:
dry_run: An optional bool object specifying whether or not to write PyRosetta input files to disk. If True, then the

PyRosetta input files will not be written to disk so the returned options can be inspected (or input manually into pyrosetta.init if options do not contain input files). Default: True

output_dir: An optional str object representing the output directory into which to decompress PyRosetta input files if

the ‘dry_run’ keyword argument parameter is False. Default: ./pyrosetta_init_input_files

relative_paths: An optional bool object specifying whether or not to return the relative paths (with respect to

the current working directory) of the files written to the ‘output_dir’ keyword argument parameter. Default: False

max_decompressed_bytes: An optional int object specifying the maximum permitted number of bytes per decompressed PyRosetta

input file (with a default of 200 MB). If a PyRosetta input file in the input ‘.init’ file exceeds this buffer size upon decompression, then a BufferError is intentionally raised as a precaution. Default: 200_000_000

database: An optional str object representing the path to the Rosetta database. By default, the Rosetta database

is found using pyrosetta._rosetta_database_from_env(), but if the search fails then the Rosetta database path may be manually input here. Default: None

as_dict: An optional bool object specifying whether or not to return the PyRosetta initialization options as a dict

object, otherwise options are returned as a str object. Default: False

Raises:

ValueError when the ‘as_dict’ keyword argument parameter is not a bool object.

Returns:

A str or dict object representing the PyRosetta initialization options.

static dump_init_file(output_filename, poses=None, author=None, email=None, license=None, metadata=None, overwrite=None, dry_run=None, verbose=None)

Write a PyRosetta initialization ‘.init’ file.

This method uses the ProtocolSettingsMetric SimpleMetric to get Rosetta command line options and compresses any PyRosetta input files (including subfiles within files) into the output ‘.init’ file. The Rosetta database directory is automatically excluded. Only the relative paths of any input directories (from the current working directory) are saved in the Rosetta command line options (e.g., ‘-in:path:bcl /path/to/current/directory/bcl_rosetta’ is saved as ‘-in:path:bcl ./bcl_rosetta’). Therefore, it may be helpful to add comments to the ‘metadata’ keyword argument parameter about specific PyRosetta initialization requirements. PyRosetta initialization input files are automatically detected and compressed into the provided ‘output_filename’ argument parameter, and so it can be useful to start with the dry_run keyword argument enabled to confirm that the PyRosetta input files are correct. Note that automatic detection of PyRosetta input files containing any spaces (e.g., ‘ ‘) in file paths or filenames is not supported.

Args:

output_filename: A required str object representing the output ‘.init’ file.

Keyword Args:
poses: An optional Pose, PackedPose, or iterable of Pose or PackedPose objects to cache in the output ‘.init’ file.

Default: []

author: An optional str object representing the author’s/authors’ name(s) or username(s).

Default: “”

email: An optional str object representing the author’s/authors’ email address(es).

Default: “”

license: An optional str object representing the license(s) for the output ‘.init’ file.

Default: “”

metadata: An optional JSON-serializable object representing any additional metadata to save to the output ‘.init’ file.

Default: {}

overwrite: An optional bool object specifying whether or not to overwrite the output ‘.init’ file if it exists.

If False, then raise an error if the output ‘.init’ file already exists. Default: False

dry_run: An optional bool object specifying whether or not to dump the output ‘.init’ file. If True, then only print

the files that would be compressed into the ‘.init’ file if it were False. Default: False

verbose: An optional bool object specifying whether or not to print PyRosetta ‘.init’ file information.

Default: True

Returns:

None

static get_init_options(compressed=False, as_dict=False)

Get the currently initialized Rosetta command line options using the ProtocolSettingsMetric SimpleMetric, including the Rosetta database.

Keyword Args:
compressed: An optional bool object specifying whether or not to compress any input files (including files containing

lists of files) in memory, and return only the relative paths of any input directories (from the current working directory) in the Rosetta command line options (e.g., ‘-in:path:bcl /path/to/current/directory/bcl_rosetta’ is returned as ‘-in:path:bcl ./bcl_rosetta’). Default: False

as_dict: An optional bool object specifying whether or not to return the PyRosetta initialization options as a dict

object, otherwise options are returned as a str object. Default: False

Raises:

ValueError when the ‘compressed’ or ‘as_dict’ keyword argument parameters are not bool objects. NotImplementedError when compressed=True and as_dict=False.

Returns:

A str or dict object representing the PyRosetta initialization options.