pestifer.logparsers.logparser module

Defines the LogParser class and its subclasses for parsing log files from various applications used by Pestifer, such as NAMD and Packmol.

class pestifer.logparsers.logparser.LogParser[source]

Bases: ByteCollector

A base class for parsing log files from various applications used by Pestifer. This class is a subclass of ByteCollector and provides methods for reading, updating, and dumping log data.

dump(basename: str = 'logparser')[source]

Dump the collected log data to a file with the specified basename. The file will be named <basename>.log and will contain the collected log data.

Parameters:

basename (str) – The base name for the log file. The final file will be named <basename>.log.

enable_progress_bar(PS: PestiferProgress = None)[source]

Enable a progress bar for the log parser. If a progress bar instance is provided, it will be used to track the progress of the log parsing.

Parameters:

PS (PestiferProgress) – An instance of a progress bar to track the progress of the log parsing.

follow(filename: str, sleep_interval: float = 0.5, timeout_intervals: int = 120)[source]

Follow a log file, reading new lines as they are added.

Parameters:
  • filename (str) – The path to the log file to follow.

  • sleep_interval (float) – The time to sleep between checks for new lines (in seconds).

  • timeout_intervals (int) – The maximum number of intervals to wait before timing out.

measure_progress()[source]

Measure the progress of the log parsing. This method is intended to be overridden by subclasses to provide specific progress measurement logic.

static(filename: str)[source]

Initialize the LogParser from an existing, static file.

success()[source]

Check if the log parsing was successful. This method is intended to be overridden by subclasses to provide specific success criteria.

Returns:

True if the log parsing was successful, False otherwise.

Return type:

bool

update(bytes: str)[source]

Update the LogParser with new bytes of data.

update_progress_bar()[source]

Update the progress bar for the log parser. This method calls the go method of the progress bar instance, if it exists.

class pestifer.logparsers.logparser.VMDLogParser(basename: str = 'vmd-logparser')[source]

Bases: LogParser

A class for parsing VMD log files. This class is a subclass of LogParser and provides methods for reading, updating, and dumping VMD log data. It also includes methods for processing specific lines in the log file, such as those containing information about the simulation, TCL commands, and energy calculations.

Parameters:

basename (str) – The base name for the log parser.

collect_validation_results()[source]

Collect validation results from the log data.

classmethod from_file(filename: str | Path) VMDLogParser[source]

Create a VMDLogParser instance from a log file.

pestifer.logparsers.logparser.get_single(flag: str, bytes: str)[source]

Get the first token that follows the first occurrence of flag in the bytes. If the flag is not found or there are no tokens, return None and log a debug message.

Parameters:
  • flag (str) – The flag to search for in the bytes.

  • bytes (bytes) – The bytes to search within.

Returns:

The first token found in the bytes, or None if not found.

Return type:

bytes

pestifer.logparsers.logparser.get_toeol(flag: str, bytes: str)[source]

Get the substring of bytes from the first occurrence of flag to the end of the line. If the flag is not found or there is no newline character after the flag, return None and log a debug message.

Parameters:
  • flag (str) – The flag to search for in the bytes.

  • bytes (bytes) – The bytes to search within.

Returns:

The substring of bytes from the first occurrence of flag to the end of the line, or None if not found.

Return type:

bytes

pestifer.logparsers.logparser.get_toflag(flag: str, bytes: str)[source]

Get the substring of bytes up to the first occurrence of flag. If the flag is not found, return None and log a debug message.

Parameters:
  • flag (str) – The flag to search for in the bytes.

  • bytes (bytes) – The bytes to search within.

Returns:

The substring of bytes up to the first occurrence of flag, or None if not found.

Return type:

bytes

pestifer.logparsers.logparser.get_tokens(flag: str, bytes: str)[source]

Get the tokens from the bytes that follow the first occurrence of flag. If the flag is not found or there are no tokens, return an empty list and log a debug message.

Parameters:
  • flag (str) – The flag to search for in the bytes.

  • bytes (bytes) – The bytes to search within.

Returns:

A list of tokens found in the bytes, or an empty list if none are found.

Return type:

list

pestifer.logparsers.logparser.get_values(flag: str, bytes: str, dtype=<class 'float'>)[source]

Get the values from the bytes that follow the first occurrence of flag. If the flag is not found or there are no values, return an empty list and log a debug message.

Parameters:
  • flag (str) – The flag to search for in the bytes.

  • bytes (bytes) – The bytes to search within.

  • dtype (type) – The data type to convert the values to (default is float).

Returns:

A list of values found in the bytes, or an empty list if none are found.

Return type:

list