Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [unreleased]

### Fixed
- Deleted ORCA `parse_natoms` to fix parsing of xTB log files.
- Fixed gradient regex to account for arbitrary number of stars in log file.


## [0.10.1] - 2026-05-02

### Fixed
Expand Down
26 changes: 7 additions & 19 deletions src/qccodec/parsers/orca.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def parse_hessian(contents: str) -> list[list[float]]:
for block in blocks:
lines = block.splitlines()
if not len(lines) == dim:
raise ParserError(f"Block line count {len(lines)} does not match dimension {dim}: {block}")
raise ParserError(
f"Block line count {len(lines)} does not match dimension {dim}: {block}"
)

for i, line in enumerate(block.splitlines()):
row = list(map(float, line.split()[1:]))
Expand Down Expand Up @@ -194,9 +196,10 @@ def parse_trajectory(

# Capture the stdout for each gradient calculation
regex = (
r"GEOMETRY\s*OPTIMIZATION\s*CYCLE\s*\d+\s*\*\s*\n\s*\**\s*\n" # header
r"(.*?)" # body
r"-*\s*\n\s*ORCA\s+GEOMETRY\s+RELAXATION\s+STEP"
r"GEOMETRY\s*OPTIMIZATION\s*CYCLE\s*\d+.*?" # Match cycle line
r"\*+\n" # Match the line of stars
r"(.*?)" # Body (Captured)
r"-+\s*\n\s*ORCA\s+GEOMETRY\s+RELAXATION\s+STEP" # Footer
)
per_gradient_stdout = re.findall(regex, stdout, flags=re.DOTALL)
if not per_gradient_stdout:
Expand Down Expand Up @@ -249,21 +252,6 @@ def parse_version(contents: str) -> str:
return match.group(1)


@register(filetype=OrcaFileType.STDOUT, target="calcinfo_natoms")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just make the parser optional instead?

@register(filetype=OrcaFileType.STDOUT, target="calcinfo_natoms", required=False)

This will preserve it when the the data exists but not raise an exception if not present :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we add a test for the xTB output logs and ensure no exception is raised. This then covers the case currently causing the error.

Thanks for this!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avcopan here!

def parse_natoms(contents: str) -> int:
"""Parse number of atoms value from Orca stdout.

Returns:
The number of atoms as an integer.

Raises:
MatchNotFoundError: If the regex does not match.
"""
regex = r"Number of atoms\s*...\s*(\d+)"
match = re_search(regex, contents)
return int(match.group(1))


def parse_basename(contents: str) -> str:
"""Parse the file basename from Orca stdout."""
regex = r"NAME\s+=\s+(.*)"
Expand Down
10 changes: 5 additions & 5 deletions tests/data/orca/answers/trajectory.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"success": true,
"data": {
"calcinfo_natoms": 3,
"calcinfo_natoms": null,
"calcinfo_nalpha": null,
"calcinfo_nbeta": null,
"calcinfo_nbasis": null,
Expand Down Expand Up @@ -187,7 +187,7 @@
},
"success": true,
"data": {
"calcinfo_natoms": 3,
"calcinfo_natoms": null,
"calcinfo_nalpha": null,
"calcinfo_nbeta": null,
"calcinfo_nbasis": null,
Expand Down Expand Up @@ -305,7 +305,7 @@
},
"success": true,
"data": {
"calcinfo_natoms": 3,
"calcinfo_natoms": null,
"calcinfo_nalpha": null,
"calcinfo_nbeta": null,
"calcinfo_nbasis": null,
Expand Down Expand Up @@ -423,7 +423,7 @@
},
"success": true,
"data": {
"calcinfo_natoms": 3,
"calcinfo_natoms": null,
"calcinfo_nalpha": null,
"calcinfo_nbeta": null,
"calcinfo_nbasis": null,
Expand Down Expand Up @@ -471,4 +471,4 @@
"hostmem": null
}
}
]
]
9 changes: 0 additions & 9 deletions tests/test_orca_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
parse_energy,
parse_gradient,
parse_hessian,
parse_natoms,
parse_trajectory,
parse_version,
)
Expand Down Expand Up @@ -87,14 +86,6 @@
answer=hessians.water_revdsd,
extra_files=["water.numhess.hess"],
),
ParserTestCase(
name="Parse number of atoms water",
parser=parse_natoms,
stdout=Path("water.energy.out"),
calctype=CalcType.energy,
success=True,
answer=3,
),
ParserTestCase(
name="Parse trajectory",
parser=parse_trajectory,
Expand Down
Loading