sparc.utils module

Utilities that are loosely related to core sparc functionalities

exception sparc.utils.ProcessReturned[source]

Bases: Exception

Simple class for process that has returned

exception sparc.utils.TimeoutException[source]

Bases: Exception

Simple class for timeout

sparc.utils.compare_dict(d1, d2)[source]

Helper function to compare dictionaries

sparc.utils.cprint(content, color=None, bold=False, underline=False, **kwargs)[source]

Color print wrapper for ansi terminal. Only a few color names are provided

sparc.utils.deprecated(message)[source]
sparc.utils.h2gpts(h, cell_cv, idiv=4)[source]

Convert a h-parameter (Angstrom) to gpts

sparc.utils.locate_api(json_file=None, doc_path=None, cfg=<ase.config.Config object>)[source]

Locate the SPARC API setup file with the following priority: 1) If json_file is provided (either from parameter or cfg), use it directly. 2) If doc_path is provided:

  1. Function parameter takes precedence.

  2. Environment variable SPARC_DOC_PATH comes next.

  3. Configuration section [sparc] in the ini file is the last resort.

  1. If both json_file and doc_path are provided, raise an exception.

  2. Fallback to the default API setup if neither is provided.

sparc.utils.monitor_process(self, interval=1.0)[source]

Usage: try:

with monitor_process(process):

do_something()

except TimeoutException:

raise

sparc.utils.sanitize_path(path_string)[source]

Sanitize path containing string in UNIX systems Returns a PosixPath object

It is recommended to use this sanitize function before passing any path-like strings from cfg parser

sparc.utils.string2index(string: str) int | slice | str[source]

Convert index string to either int or slice This method is a copy of ase.io.formats.string2index

sparc.utils.time_limit(seconds)[source]

Usage: try:

with time_limit(60):

do_something()

except TimeoutException:

raise