Skip to content

Calculation Outcome (outcome.py)

Calculation outcome processing

pymultiwfn.api.outcome

Raw results container for MultiwfnJob execution.

MultiwfnJobOutcome dataclass

Encapsulates results from a Multiwfn execution.

Attributes

stdout Standard output from Multiwfn stderr Standard error from Multiwfn return_code Process return code execution_time Execution time in seconds

Source code in src/pymultiwfn/api/outcome.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@dataclass
class MultiwfnJobOutcome:
    """Encapsulates results from a Multiwfn execution.

    Attributes
    ----------
    stdout
        Standard output from Multiwfn
    stderr
        Standard error from Multiwfn
    return_code
        Process return code
    execution_time
        Execution time in seconds

    """

    stdout: str
    stderr: str
    return_code: int | None
    execution_time: float

    def is_successful(self) -> bool:
        """Check if execution was successful.

        Notes
        -----
        Multiwfn often returns non-zero codes in batch mode even on success.
        We check for actual error indicators instead of just return code.
        """
        if self.return_code is None or self.return_code < 0:
            return False
        error_indicators = [
            "error",
            "fatal",
            "cannot open",
            "not found",
            "failed to",
        ]
        has_error = any(ind in self.stderr.lower() for ind in error_indicators)
        return not has_error

    def save_output(self, filename: str | Path) -> None:
        """Save stdout to file.

        Parameters
        ----------
        filename : str or Path
            Output file path
        """
        Path(filename).write_text(self.stdout, encoding="utf-8")

is_successful()

Check if execution was successful.

Notes

Multiwfn often returns non-zero codes in batch mode even on success. We check for actual error indicators instead of just return code.

Source code in src/pymultiwfn/api/outcome.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def is_successful(self) -> bool:
    """Check if execution was successful.

    Notes
    -----
    Multiwfn often returns non-zero codes in batch mode even on success.
    We check for actual error indicators instead of just return code.
    """
    if self.return_code is None or self.return_code < 0:
        return False
    error_indicators = [
        "error",
        "fatal",
        "cannot open",
        "not found",
        "failed to",
    ]
    has_error = any(ind in self.stderr.lower() for ind in error_indicators)
    return not has_error

save_output(filename)

Save stdout to file.

Parameters

filename : str or Path Output file path

Source code in src/pymultiwfn/api/outcome.py
49
50
51
52
53
54
55
56
57
def save_output(self, filename: str | Path) -> None:
    """Save stdout to file.

    Parameters
    ----------
    filename : str or Path
        Output file path
    """
    Path(filename).write_text(self.stdout, encoding="utf-8")