tools package

Submodules

tools.file_utils module

Tools to work with files

tools.file_utils.check_argument(path: Path | None, argument: str, optional: bool, module_name: str, input_output: str | None = None, output_files_created: bool = False, extension_list: List[str] | None = None, raise_exception: bool = True, check_extensions: bool = True, out_log: Logger | None = None) None[source]
tools.file_utils.check_complete_files(output_file_list: Iterable[str]) bool[source]
tools.file_utils.check_properties(obj: object, properties: dict, reserved_properties: dict | None = None)[source]
tools.file_utils.copy_to_container(container_path: str, container_volume_path: str, io_dict: Mapping, out_log: Logger | None = None) dict[source]
tools.file_utils.copy_to_host(container_path: str, container_io_dict: dict, io_dict: dict)[source]
tools.file_utils.create_cmd_line(cmd: Iterable[str], container_path: str = '', host_volume: str | None = None, container_volume: str | None = None, container_working_dir: str | None = None, container_user_uid: str | None = None, container_shell_path: str | None = None, container_image: str | None = None, out_log: Logger | None = None, global_log: Logger | None = None) List[str][source]
tools.file_utils.create_dir(dir_path: str) str[source]

Returns the directory dir_path and create it if path does not exist.

Parameters:

dir_path (str) – Path to the directory that will be created.

Returns:

Directory dir path.

Return type:

str

tools.file_utils.create_name(path: str | None = None, prefix: str | None = None, step: str | None = None, name: str | None = None) str[source]

Return file name.

Parameters:
  • path (str) – Path to the file directory.

  • prefix (str) – Prefix added to the name of the file.

  • step (str) – String added between the prefix arg and the name arg of the file.

  • name (str) – Name of the file.

Returns:

Composed file name.

Return type:

str

tools.file_utils.create_stdin_file(intput_string: str) str[source]
tools.file_utils.create_unique_dir(path: str = '', prefix: str = '', number_attempts: int = 10, out_log: Logger | None = None) str[source]

Create a directory with a prefix + computed unique name. If the computed name collides with an existing file name it attemps number_attempts times to create another unique id and create the directory with the new name.

Parameters:
  • path (str) – (‘’) Parent path of the new directory.

  • prefix (str) – (‘’) String to be added before the computed unique dir name.

  • number_attempts (int) –

    1. number of times creating the directory if there’s a name conflict.

  • out_log (logger) – (None) Python logger object.

Returns:

Directory dir path.

Return type:

str

tools.file_utils.create_unique_file_path(parent_dir: str | None = None, extension: str | None = None) str[source]
tools.file_utils.get_doc_dicts(doc: str | None)[source]
tools.file_utils.get_logs(path: str | None = None, prefix: str | None = None, step: str | None = None, can_write_console: bool = True, level: str = 'INFO', light_format: bool = False) Tuple[Logger, Logger][source]

Get the error and and out Python Logger objects.

Parameters:
  • path (str) – (current working directory) Path to the log file directory.

  • prefix (str) – Prefix added to the name of the log file.

  • step (str) – String added between the prefix arg and the name of the log file.

  • can_write_console (bool) – (False) If True, show log in the execution terminal.

  • level (str) – (‘INFO’) Set Logging level. [‘CRITICAL’,’ERROR’,’WARNING’,’INFO’,’DEBUG’,’NOTSET’]

  • light_format (bool) – (False) Minimalist log format.

Returns:

Out and err Logger objects.

Return type:

tuple of logging.Logger and logging.Logger

tools.file_utils.get_logs_prefix()[source]
tools.file_utils.get_working_dir_path(working_dir_path: str | None = None, restart: bool = False) str[source]

Return the directory working_dir_path and create it if working_dir_path does not exist. If working_dir_path exists a consecutive numerical suffix is added to the end of the working_dir_path and is returned.

Parameters:
  • working_dir_path (str) – Path to the workflow results.

  • restart (bool) – If step result exists do not execute the step again.

Returns:

Path to the workflow results directory.

Return type:

str

tools.file_utils.human_readable_time(time_ps: int) str[source]

Transform time_ps to a human readable string.

Parameters:

time_ps (int) – Time in pico seconds.

Returns:

Human readable time.

Return type:

str

tools.file_utils.launchlogger(func)[source]
tools.file_utils.log(string: str, local_log: Logger | None = None, global_log: Logger | None = None)[source]

Checks if log exists

Parameters:
  • string (str) – Message to log.

  • local_log (logging.Logger) – local log object.

  • global_log (logging.Logger) – global log object.

tools.file_utils.rm(file_name: str) str[source]
tools.file_utils.rm_file_list(file_list: Iterable[str], out_log: Logger | None = None) List[str][source]
tools.file_utils.search_topology_files(top_file: str, out_log: Logger | None = None) List[str][source]

Search the top and itp files to create a list of the topology files

Parameters:
  • top_file (str) – Topology GROMACS top file.

  • out_log (logging.Logger) – Input log object.

Returns:

List of paths of the extracted files.

Return type:

list of str

tools.file_utils.unzip_list(zip_file: str, dest_dir: str | None = None, out_log: Logger | None = None) List[str][source]
Extract all files in the zipball file and return a list containing the

absolute path of the extracted files.

Parameters:
  • zip_file (str) – Input compressed zip file.

  • dest_dir (str) – Path to directory where the files will be extracted.

  • out_log (logging.Logger) – Input log object.

Returns:

List of paths of the extracted files.

Return type:

list of str

tools.file_utils.unzip_top(zip_file: str, out_log: Logger | None = None, unique_dir: Path | str | None = None) str[source]

Extract all files in the zip_file and copy the file extracted “.top” file to top_file.

Parameters:
  • zip_file (str) – Input topology zipball file path.

  • out_log (logging.Logger) – Input log object.

  • unique_dir (str) – Directory where the topology will be extracted.

Returns:

Path to the extracted “.top” file.

Return type:

str

tools.file_utils.write_failed_output(file_name: str)[source]
tools.file_utils.zip_list(zip_file: str, file_list: Iterable[str], out_log: Logger | None = None)[source]

Compress all files listed in file_list into zip_file zip file.

Parameters:
  • zip_file (str) – Output compressed zip file.

  • file_list (list of str) – Input list of files to be compressed.

  • out_log (logging.Logger) – Input log object.

tools.file_utils.zip_top(zip_file: str, top_file: str, out_log: Logger | None = None, remove_original_files: bool = True) List[str][source]

Compress all .itp and *.top files in the cwd into **zip_file* zip file.

Parameters:
  • zip_file (str) – Output compressed zip file.

  • top_file (str) – Topology TOP GROMACS file.

  • out_log (logging.Logger) – Input log object.

Returns:

List of compressed paths.

Return type:

list of str

tools.test_fixtures module

Boiler plate functions for testsys

tools.test_fixtures.compare_hash(file_a: str, file_b: str) bool[source]

Compute and compare the hashes of two files

tools.test_fixtures.compare_ignore_first(file_a: str, file_b: str) bool[source]

Compare two files ignoring the first line

tools.test_fixtures.compare_images(file_a: str, file_b: str, percent_tolerance: float = 1.0) bool[source]
tools.test_fixtures.compare_line_by_line(file_a: str, file_b: str, ignore_list: List[str | int]) bool[source]
tools.test_fixtures.compare_pdb(pdb_a: str, pdb_b: str, rmsd_cutoff: int = 1, remove_hetatm: bool = True, remove_hydrogen: bool = True, **kwargs)[source]

Compare pdb files

tools.test_fixtures.compare_size(file_a: str, file_b: str, percent_tolerance: float = 1.0) bool[source]

Compare two files using size

tools.test_fixtures.compare_top_itp(file_a: str, file_b: str) bool[source]

Compare top/itp files

tools.test_fixtures.compare_xvg(file_a: str, file_b: str, percent_tolerance: float = 1.0) bool[source]

Compare two files using size

tools.test_fixtures.compare_zip(zip_a: str, zip_b: str) bool[source]

Compare zip files

tools.test_fixtures.equal(file_a: str, file_b: str, ignore_list: List[str | int] | None = None, **kwargs) bool[source]

Check if two files are equal

tools.test_fixtures.equal_txt(file_a: str, file_b: str) bool[source]

Check if two text files are equal

tools.test_fixtures.exe_success(return_code: int) bool[source]

Check if return_code is 0

Parameters:

return_code (int) – Return code of a process.

Returns:

True if return code is equal to 0

Return type:

bool

tools.test_fixtures.not_empty(file_path: str) bool[source]

Check if file exists and is not empty.

Parameters:

file_path (str) – Path to the file.

Returns:

True if file_path exists and is not empty.

Return type:

bool

tools.test_fixtures.test_setup(test_object, dict_key: str | None = None, config: str | None = None)[source]

Add the unitest_dir, test_dir, conf_file_path, system, properties and path as attributes to the test_object and create a directory to launch the unitest.

Parameters:
  • test_object (test) – The test object.

  • dict_key (str) – Key of the test parameters in the yaml config file.

  • config (str) – Path to the configuration file.

tools.test_fixtures.test_teardown(test_object)[source]

Remove the test_object.properties[‘working_dir_path’]

Parameters:

test_object (test) – The test object.