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)
encode_rg_state(rg_state_str)
decode_rg_state(rg_state)
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)
get_rg_state()
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_rg_state(rg_state)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_rg_state(rg_state_str)
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_rg_state(rg_state)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode(string, parent_dir)
encode_bytestring(bytestring)
encode_file(filename)
encode_object(obj)
encode_rg_state(rg_state_str)
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_rg_state()
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()
restore_rg_state()
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_rg_state(rg_state)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_rg_state(rg_state_str)
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_rg_state(rg_state)
decode_string(bytestring, max_decompressed_bytes)
dump_json(obj)
encode_bytestring(bytestring)
encode_rg_state(rg_state_str)
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)
restore_rg_state()
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, restore_rg_state=None, database=None, verbose=None, set_logging_handler=None, notebook=None, silent=None)

Initialize PyRosetta from a PyRosetta initialization (i.e., 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 set the dry_run keyword argument value to True to first inspect the Rosetta command line options before committing to writing all PyRosetta initialization input files to disk and running PyRosetta initialization.

Args:
init_file: str

A required str object representing the input “.init” file.

dry_run: bool | None

An optional bool object specifying whether or not to write PyRosetta initialization input files and perform PyRosetta initialization. If True, then only print the Rosetta command-line options that would be run if it were False.

Default: False

output_dir: str | None

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

Default: “./pyrosetta_init_input_files”

skip_corrections: bool | None

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 None 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: bool | None

An optional bool object specifying whether or not to initialize PyRosetta with the relative filesystem paths (with respect to the current working directory) of the files written to the output_dir keyword argument value.

Default: False

max_decompressed_bytes: int | None

An optional int object specifying the maximum permitted number of bytes per decompressed PyRosetta initialization input file (with a default of 200 MB). If a PyRosetta initialization 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

restore_rg_state: bool | None

An optional bool object specifying whether or not to restore the RandomGenerator state if cached in the input “.init” file. This enables continuity of the PyRosetta session’s MT19937 internal state from the point at which the original input “.init” file was written, whether or not the RandomGenerator seed was explicitly configured by the author(s).

Default: True

database: str | None

An optional str object representing the filesystem path to the Rosetta database. By default, the Rosetta database is found using the pyrosetta._rosetta_database_from_env function, but if the search fails then the Rosetta database filesystem path may be manually passed here.

Default: None

verbose: bool | None

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

Default: True

set_logging_handler: str | bool | None

An optional object passed to pyrosetta.init(set_logging_handler=…) during PyRosetta initialization. If None is provided, then the default set_logging_handler parameter of the pyrosetta.init function is used.

Default: None

notebook: None

An optional object passed to pyrosetta.init(notebook=…) during PyRosetta initialization. If None is provided, then the default notebook parameter of the pyrosetta.init function is used.

Default: None

silent: bool | None

An optional object passed to pyrosetta.init(silent=…) during PyRosetta initialization. If a NoneType object is provided, then the default silent parameter of the pyrosetta.init function 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 Rosetta command-line options from a PyRosetta initialization (i.e., a “.init”) file.

This method returns the Rosetta command-line options from an input “.init” file without running the pyrosetta.init function. The dry_run parameter is True by default in order to inspect the Rosetta command-line options before committing to decompressing and writing all PyRosetta initialization input files to disk. If the dry_run keyword argument value is False, then also decompress the PyRosetta initialization input files into an output directory given by the output_dir keyword argument value without running the pyrosetta.init function.

Args:
init_file: str

A required str object representing the input “.init” file.

dry_run: bool | None

An optional bool object specifying whether or not to write PyRosetta initialization 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 manually passed to the pyrosetta.init function if the Rosetta command-line options do not contain PyRosetta initialization input files).

Default: True

output_dir: str | None

An optional str object representing the output directory into which to decompress PyRosetta initialization input files if the dry_run keyword argument value is False.

Default: “./pyrosetta_init_input_files”

relative_paths: bool | None

An optional bool object specifying whether or not to return the relative filesystem paths (with respect to the current working directory) of the files written to the output_dir keyword argument value.

Default: False

max_decompressed_bytes: int | None

An optional int object specifying the maximum permitted number of bytes per decompressed PyRosetta initialization 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: str | None

An optional str object representing the filesystem path to the Rosetta database. By default, the Rosetta database is found using the pyrosetta._rosetta_database_from_env function, but if the search fails then the Rosetta database filesystem path may be manually passed here.

Default: None

as_dict: bool

An optional bool object specifying whether or not to return the Rosetta command-line options as a dict object, otherwise Rosetta command-line options are returned as a str object.

Default: False

Raises:

ValueError when the as_dict keyword argument value is not a bool object.

Returns:

A str or dict object representing the Rosetta command-line 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 (i.e., a “.init”) file.

This method uses the ProtocolSettingsMetric SimpleMetric to get Rosetta command-line options and compresses any PyRosetta initialization 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 pass comments to the metadata keyword argument value about specific PyRosetta initialization requirements. PyRosetta initialization input files are automatically detected and compressed into the provided output_filename argument value, and so it can be useful to start with the dry_run keyword argument value as True 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: str

A required str object representing the output “.init” file.

poses: Pose | PackedPose | Iterable[Pose | PackedPose] | None

An optional Pose, PackedPose, or iterable of Pose or PackedPose objects to cache in the output “.init” file.

Default: []

author: str | None

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

Default: “”

email: str | None

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

Default: “”

license: str | None

An optional str object representing the license(s) for the output “.init” file.

Default: “”

metadata: Any

An optional JSON-serializable object representing any additional metadata to save to the output “.init” file.

Default: {}

overwrite: bool | None

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: bool | None

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: bool | None

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.

Args:
compressed: bool

An optional bool object specifying whether or not to compress any PyRosetta initialization input files (including files containing lists of files) in memory, and return only the relative filesystem 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: bool

An optional bool object specifying whether or not to return the Rosetta command-line 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 Rosetta command-line options.