pestifer.util.util module¶
Various utility functions for pestifer
- pestifer.util.util.cell_from_xsc(xsc: Path | str)[source]¶
Reads a NAMD extended system configuration file and returns the box vectors and origin.
- pestifer.util.util.cell_to_xsc(box: ndarray, orig: ndarray, xsc: Path | str)[source]¶
Writes the box vectors and origin to a NAMD extended system configuration file.
- Parameters:
box (np.ndarray) – A 3x3 array representing the box vectors.
orig (np.ndarray) – A 3-element array representing the origin of the box.
xsc (str) – The path to the NAMD extended system configuration file to be written.
- pestifer.util.util.countTime(fn)[source]¶
Decorator to measure the time taken by a function to execute. It logs the time taken and the average time per call, as well as the number of calls made to the function.
- Parameters:
fn (callable) – The function to be decorated. It can be any callable object, such as a function or a method.
- Returns:
A wrapper function that measures the execution time of the original function.
- Return type:
callable
- pestifer.util.util.flatten(current: dict, key: str, result: dict) dict[source]¶
Recursively flattens a nested dictionary into a single-level dictionary with keys as dot-separated paths.
- pestifer.util.util.hmsf(seconds: float, precision: int = 3) str[source]¶
Return HH:MM:SS.sss with seconds as float (no 24h wrap).
- pestifer.util.util.is_periodic(xsc: Path | str)[source]¶
Checks to see if the contents of the NAMD output xsc indicate that the current system is periodic
- pestifer.util.util.protect_str_arg(arg: str | None)[source]¶
Returns a string with spaces replaced by underscores.
- pestifer.util.util.reduce_intlist(L: list[int]) str[source]¶
Generate a “reduced-byte” representation of a list of integers by collapsing runs of adjacent integers into ‘i to j’ format. Example:
[1,2,3,4,5,7,8,9,10,12] -> ‘1 to 5 7 to 10 12’
- pestifer.util.util.remove_argument(parser: ArgumentParser, name_or_flag: str)[source]¶
Remove an argument by its dest name or option string.
- pestifer.util.util.replace(data: list | dict, match: str, repl: str) None[source]¶
Recursive value search-and-replace; data is either list or dictionary; nesting is ok
- Parameters:
data (dict or list) – The data structure in which to search and replace values.
match (str) – The string to match in the data structure. If a value matches this string, it will be replaced.
repl (str) – The string to replace the matched value with. If a value contains the match string, it will be replaced with this string.
- pestifer.util.util.tarball_walk(tar)[source]¶
Simulates os.walk() for tarball contents. (chatgpt)
- Parameters:
tar (tarfile.TarFile) – A tarfile object representing the tarball to walk through.
- Yields:
tuple – A tuple containing the directory path, a list of subdirectories, and a list of files in the current directory.
- pestifer.util.util.write_residue_map(the_map: dict, filename: str) None[source]¶
Writes a flattened map of residue objects to a file. The map is flattened such that each key is a dot-separated string representing the path to the value, and the values are the attributes of the residue objects specified by
valkeys.- Parameters:
the_map (dict) – A dictionary where keys are strings of the form <chainID>:<resid> as labelled in a CIF file, and values are strings of the form <chainID>:<resid> as labelled by the “auth” attributes.
filename (str) – The name of the file to which the flattened map will be written.
valkeys (list of str, optional) – A list of attribute names to be extracted from the residue objects. Default is [
chainID,resid].