Utils.interface module

Description

This module defines the ParaMol.Utils.interface.ParaMolInterface used for ParaMol to interact with system.

class ParaMol.Utils.interface.ParaMolInterface(base_dir=None)

Bases: object

This class defines method that has, for example, moving between and creating new directories, running subprocesses, etc…

Parameters

base_dir (str, optional, default=os.getcwd()) – Path to the base working directory.

Variables
  • base_dir (str) – Path to the base working directory.

  • dirs (list) – Keeps track of where we are at.

  • created_dirs (list) – List of all created directories.

  • cwd (list) – Current working directory

chdir(*args, absolute=False, relative_to_base=False)

Method that changes directory.

Parameters
  • args (strings) – Strings to be joined.

  • absolute (bool) – If True it assumes the first argument is absolute and the remaining are are defined relatively to the first.

  • relative_to_base (bool, default=False) – If False path are defined relatively to the current working directory, if True paths are defined relatively to the base working directory. Ignored if absolute is True.

Returns

cwd (str) – Current working directory.

chdir_base()

Method that goes back to the base directory.

Returns

cwd (str) – Current working directory.

chdir_previous()

Method that changes to previous directory.

Returns

cwd (str) – Current working directory.

static check_dir_exists(dirs, not_exists=False)

Method that checks if the fed directories exist.

Parameters
  • dirs (str or list of str) – List or str with directory path names.

  • not_exists (bool, optional, default=False) – If True, the method checks if the fed directories do not exist.

Returns

bool or list of bool or Exception – If not_exists is False, returns True if dir exists and Raises an Exception if it does not exist. If not_exists is True, returns True if dir does not exist and Raises an Exception if it exists.

static check_file_exists(files, not_exists=False)

Method that checks if the fed files exist.

Parameters
  • files (str or list of str) – List or str with directory path names.

  • not_exists (bool, optional, default=False) – If True, the method checks if the fed directories do not exists

Returns

bool or list of bool or Exception – If not_exists is False, returns True if file exists and Raises an Exception if it does not exist. If not_exists is True, returns True if file does not exist and Raises an Exception if it exists.

create_dir(dirs)

Method that checks if the fed directories exists and if they don’t exists it creates them.

Parameters

dirs (str or list of str) –

Returns

True – Returns True if all directories were created without errors.

remove_all_created_dirs()

Method that removes all created directories.

Returns

created_dirs (list) – It should be an empty list.

static run_subprocess(*commands, process_name=None, output_file=None, pipe=False, shell=False)

A wrapper for subprocess.check_call.

Parameters
  • commands (str or list of str) – Shell commands to be executed. If pipe is True they should be passes as shell commands.

  • process_name (str or None, optional) – Name of the process. If it is none, it will be equal to the first argument’s word. Only relevant if pipe is False.

  • output_file (str or None, optional) – Output name. None is equal to the process_name. If not None should include extension. Only relevant if pipe is False.

  • pipe (bool) – Whether to use subprocess.PIPE.

  • shell (bool) – Shell command to be passed to subprocess