pyssianutils API
initialize
The initialize module defines all the parser commands (and their behaviour) related with the pyssianutils data and provides methods for easy access to said resources.
- pyssianutils.initialize.get_appdir()[source]
If a pyssianutils app data exists return it. Otherwise return a suitable path for its creation.
- Parameters:
use_home (bool) -- For Linux, to facilitate the access to the configuration files or the templates stored in the app data a True value of this parameter will favor returning a $HOME/.pyssianutils location instead of the XDG recommended one in $HOME/.local/shared/pyssianutils.
- Returns:
path to the app data folder if it exists. Otherwise returns a suitable path for it.
- Return type:
Path
- Raises:
RuntimeError -- Two pyssianutils appdata directories were found
- pyssianutils.initialize.get_resourcesdir()[source]
Returns the path to the resources as they were installed. Files in this directory should not be changed and are removed upon pip uninstall.
- Returns:
path to the resources folder.
- Return type:
Path
- pyssianutils.initialize.check_initialization()[source]
Ensures that pyssianutils was initialized. If it was not it errors.
- Raises:
RuntimeError -- pyssianutils was not initialized
- pyssianutils.initialize.load_app_defaults()[source]
Looks for the configuration files in the resources and in the user's app directory, loads and returns them
- Parameters:
only_resources (bool, optional) -- If True, it ignores the defaults of the user and returns the ones that came packaged with pyssianutils, by default False
- Returns:
configuration defaults of pyssianutils for a given user
- Return type:
configparser.ConfigParser
utils
This module provides a set of functions with general utilities. as well as the basic variables for registering the subparsers and main functions
- class pyssianutils.utils.DirectoryTree(path: str | Path | PathLike, in_suffix: str, out_suffix: str)[source]
Class that provides recursive file iteration search, iteration and recursive creation of directories following the same structure as the original one.
- static RecursiveFileSystemGenerator(path, key=None)[source]
Generator that traverses the filesystem in depth first order and yields the paths that satisfy the key function condition. If no key function is provided, returns all folders and items. The first yield is always None, and the second yield is always the path value if it satisfies the key condition.
- Parameters:
path (Path) -- Path pointing to a directory.
key (function) -- A function that returns a boolean. Used in a similar fashion as the key paramer of the 'sorted' python builtin.
- create_folders()[source]
Creates the folders of a new Directory tree, rooted in self.newroot instead of self.root
- newpath(path: str | Path | PathLike) Path [source]
Takes a path rooted to the previous root and prepares it to be rooted in the new root.
- Parameters:
path (str | Path | os.PathLike) -- path to a file relative to the DirectoryTree's root
- Returns:
path of the file as if it was relative to the newroot instead of the root
- Return type:
Path
- pyssianutils.utils.add_parser_as_subparser(subparsers: _SubParsersAction, parser: ArgumentParser, name: str, **kwargs) ArgumentParser [source]
Adds a previously existing parser as a subparser. This function is copied and adapted from the implementation of the function argparse._SubParsersAction.add_parser in python 3.12.11.
- Parameters:
subparsers (argparse._SubParsersAction) -- Subparser action (which allows the standard .add_parser method) where the new parser will be added to.
parser (argparse.ArgumentParser) -- Existing parser that is going to be added as subparser.
name (str) -- value in the main parser to invoke the existing parser added as subparser
**kwargs
- Returns:
The same existing parser that was provided as input. In order to match the behavior of argparse._SubParsersAction.add_parser
- Return type:
argparse.ArgumentParser
- Raises:
argparse.ArgumentError -- Conflict in subparser name
argparse.ArgumentError -- Conflict in subparser alias
- pyssianutils.utils.create_parser() tuple[ArgumentParser, _SubParsersAction] [source]
Creates the highest-level parser of the pyssianutils as well as the _SubparsersAction to which each subparser must be added.
- Returns:
parser,subparsers
- Return type:
tuple[argparse.ArgumentParser,argparse._SubParsersAction]
- pyssianutils.utils.print_convergence(GOF: GaussianOutFile, JobId: int, Last: bool = False)[source]
Displays the Convergence parameters for a certain InternalJob of a GaussianOutFile.
- Parameters:
GOF (GaussianOutFile) -- Gaussian File whose convergence parameters are going to be displayed.
JobId (int) -- InternalJob number in the Gaussian Output File.
Last (bool) -- If enabled only the last set of parameters is displayed (the default is False).
- pyssianutils.utils.print_thermo(GOF: GaussianOutFile)[source]
Prints in the console the thermochemistry of a GaussianOutFile.
- Parameters:
GOF (GaussianOutFile) -- Gaussian File whose thermochemistry is going to be displayed.
- pyssianutils.utils.register_main(f: Callable, name: None | str = None) Callable [source]
Function used to store the main functions of each command of pyssianutils, abstracting it from how it is actually stored.
- Parameters:
f (Callable) -- any function to be stored
name (None | str, optional) -- name used to store the function. If none is provided it will assume that the function name follows the convention "{something}_name", by default None
- Returns:
The function that was added. Allows the usage of register_main as a decorator.
- Return type:
Callable
- pyssianutils.utils.thermochemistry(GOF: GaussianOutFile) tuple[float | None, float | None, float | None] [source]
Returns the Zero Point Energy, Enthalpy and Free Energy from a frequency calculation.
- Parameters:
GOF (GaussianOutFile) -- Gaussian Output File Instance. (It assumes that previously the .read() or .update() methods have been used)
- Returns:
Zero point energy, Enthalpy, Free Energy
- Return type:
tuple[float|None,float|None,float|None]
- pyssianutils.utils.write_2_file(filepath: Path) Callable[[str], None] [source]
Creates a wrapper for appending text to a certain File. Assumes that each call is equivalent to writing a single line.
- Parameters:
filepath (Path) -- file where the output will be appended.
- Returns:
a function where each call writes the text and attaches a newline at the end of it.
- Return type:
Callable[[str],None]