Input/Output & Utilities

File handling and helper functions.

class ensemble_analyzer.io_utils.SerialiseEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Custom JSON Encoder for Ensemble Analyzer objects.

Handles serialization of: - NumPy arrays (converted to lists). - NumPy numeric types (converted to Python scalars). - NaN / Inf floats (converted to None). - Complex numbers (converted to [real, imag]). - Custom objects with ‘__dict__’ (via obj.__dict__).

default(obj) Any[source]

Override default serialization method.

Parameters:

obj (Any) – The object to serialize.

Returns:

JSON-serializable representation of the object.

Return type:

Any

ensemble_analyzer.io_utils.mkdir(directory: str) bool[source]

Create a directory, ensuring parent directories exist.

Parameters:

directory (str) – Path of the folder to be created.

Returns:

True if creation was successful (or directory already exists).

Return type:

bool

ensemble_analyzer.io_utils.move_files(conf: Conformer, protocol: Protocol, label: str) None[source]

Move calculation output files to the conformer’s specific folder.

Identifies files generated by the calculator (based on label) and moves them to conf_X/protocol_Y/.

Parameters:
  • conf (Conformer) – The conformer instance associated with the files.

  • protocol (Protocol) – The protocol instance defining the step.

  • label (str) – The calculator label used as a prefix/suffix for files.

Returns:

None

ensemble_analyzer.io_utils.tail(file_path: str, num_lines: int = 100) str[source]

Read the last N lines of a file.

Useful for extracting summary information from large log files.

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

  • num_lines (int, optional) – Number of lines to read from the end. Defaults to 100.

Returns:

The tail of the file content as a single string.

Return type:

str

ensemble_analyzer.io_utils.write_json(data: Any, fp, indent: int = 4) None[source]

Write JSON with compact matrix formatting.

Matrices (lists of lists) are kept on single inner lines:

[
    [1.0, 2.0, 3.0],
    [4.0, 5.0, 6.0]
]

instead of expanding every element onto a separate line.

Parameters:
  • data – Data to serialize (numpy objects are converted automatically).

  • fp – File-like object to write to.

  • indent – Spaces per level (default 4).

ensemble_analyzer.constants.boltzmann_distribution(energies: numpy.ndarray, temperature: float) tuple[numpy.ndarray, numpy.ndarray][source]
ensemble_analyzer.constants.compute_boltzmann_populations(conformers, protocol_number: int, temperature: float) None[source]
ensemble_analyzer.constants.eV_to_nm(eV: numpy.ndarray) numpy.ndarray[source]
ensemble_analyzer.constants.get_models_dir(calculator_name: str, create: bool = True) Path[source]
ensemble_analyzer.constants.ordinal(n: int) str[source]