feat: add get_fcidump to output#253
Conversation
a2b39ef to
17a2832
Compare
| """ | ||
| Parse the fcidump file generated by ORCA and return its data in the `Fcidump` data class. | ||
| The fcidump file has to be generated by the ORCA job and cannot be generated on-the-fly after the calculation. | ||
| ORCA can generate fcidump files via the `dumpactints true` flag in the `%output` block. |
There was a problem hiding this comment.
| ORCA can generate fcidump files via the `dumpactints true` flag in the `%output` block. | |
| To generate FCIDUMP files, set the following options: | |
| ``` | |
| %output | |
| dumpactints true | |
| end | |
| ``` |
IMO this reads more concise.
|
|
||
| def get_fcidump(self) -> Fcidump | None: | ||
| """ | ||
| Parse the fcidump file generated by ORCA and return its data in the `Fcidump` data class. |
There was a problem hiding this comment.
| Parse the fcidump file generated by ORCA and return its data in the `Fcidump` data class. | |
| Parse the FCIDUMP file generated by ORCA and return its data in the `Fcidump` data class. |
| def get_fcidump(self) -> Fcidump | None: | ||
| """ | ||
| Parse the fcidump file generated by ORCA and return its data in the `Fcidump` data class. | ||
| The fcidump file has to be generated by the ORCA job and cannot be generated on-the-fly after the calculation. |
There was a problem hiding this comment.
| The fcidump file has to be generated by the ORCA job and cannot be generated on-the-fly after the calculation. | |
| The FCIDUMP file has to be generated by the ORCA job and cannot be generated on-the-fly after the calculation. |
| Returns | ||
| ------- | ||
| fcidump_data: Fcidump | None | ||
| The parsed fcidump data or None if the file is not present or could not be parsed. |
There was a problem hiding this comment.
| The parsed fcidump data or None if the file is not present or could not be parsed. | |
| The parsed FCIDUMP data or None if the file is not present or could not be parsed. |
| @@ -0,0 +1,161 @@ | |||
| """Parse a potential FCIDUMP file""" | |||
There was a problem hiding this comment.
A module that contains one primary class, should also be named after that class -> fcidump.py
| return tensor | ||
|
|
||
| @classmethod | ||
| def parse_fcidump(cls, path: Path | str) -> "Fcidump": |
There was a problem hiding this comment.
- IMO
from_file()is a more accessible name thanparse_fcidump(). - Are the FCIDUMP files documented anywhere? Could add the link to the docstring, if so.
| @classmethod | ||
| def _get_int(cls, key: str, header: str) -> int: | ||
| """Return the integer value of the given key.""" | ||
| m = re.search(rf"{key}\s*=\s*(\d+)", header, re.IGNORECASE) |
There was a problem hiding this comment.
What about negative numbers?
If these lines always look as follows:
key = 1234 [END OF LINE]
You could use .partition("=")
| @classmethod | ||
| def _get_int_list(cls, key: str, header: str) -> list[int]: | ||
| """Return a list of integers corresponding to the given key.""" | ||
| m = re.search(rf"{key}\s*=\s*([\d,\s]+)", header, re.IGNORECASE) |
There was a problem hiding this comment.
| m = re.search(rf"{key}\s*=\s*([\d,\s]+)", header, re.IGNORECASE) | |
| m = re.search(rf"{key}\s*=\s*(\d+(\s*,\s*\d+)+)", header, re.IGNORECASE) |
What about a more precise regex!?
This still does not account for leading plus/minus symbol.
| @@ -0,0 +1,79 @@ | |||
| import textwrap | |||
There was a problem hiding this comment.
Please add units test for _get_int_list() and _get_int() specifically.
|
|
||
| @pytest.mark.unit | ||
| def test_parse_fcidump_header(tmp_path: Path) -> None: | ||
| fcidump_text = textwrap.dedent("""\ |
There was a problem hiding this comment.
I would actually not remove the indentation.
If a file format does not rely on indentation, then our file parser shouldn't as well. And the current also implementation does (good implementation 👍)
So I would actively test that.
Closes Issues
Closes None
Description
output.get_fcidump.Release Notes
Added
get_fcidumpfor easy access to fcidump file properties.