Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: Support CP2K 2025 output format for energy and forces (fixes #850) #947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
fix: Support CP2K 2025 output format for energy and forces (fixes #850) #947
Changes from all commits
b067f01ac0d5ba602a06f7478a4cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential uninitialized variable in fallback path.
If
"[hartree]"is not found inpartsand the fallback loop doesn't find any numeric value,energywill not be set for this line, but the code continues silently. While the assertion on line 491 will eventually catch this, the error message won't be helpful for debugging malformed CP2K 2025 output.Consider adding explicit error handling:
Proposed fix
if is_cp2k_2025: # Find the energy value after "[hartree]" parts = ii.split() try: hartree_idx = parts.index("[hartree]") energy = parts[hartree_idx + 1] except (ValueError, IndexError): # Fallback: try to find energy value in the line for part in reversed(parts): try: float(part) energy = part break except ValueError: continue + else: + # Loop completed without finding energy + raise RuntimeError(f"Cannot parse energy from CP2K 2025 line: {ii}")🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use explicit
Nonechecks for override inputs.Line 114 and Line 127 use truthiness checks, so empty overrides (
""/[]) cannot be tested and silently fall back to defaults.Suggested fix
Also applies to: 127-130
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitespace-energy test does not validate the parsed energy value.
This test currently only checks non-null fields, so incorrect energy parsing could still pass. Add an explicit numeric assertion for Line 166 input.
Suggested fix
def test_cp2k2025_energy_parsing_with_extra_whitespace(self): """Test energy parsing with extra whitespace around value (coverage for parsing robustness).""" fname = self.create_cp2k_output_2025( energy_line=" ENERGY| Total FORCE_EVAL ( QS ) energy [hartree] -7.364190264587725 " ) try: system = dpdata.LabeledSystem(fname, fmt="cp2k/output") - self.assertIsNotNone(system.data["energies"]) + self.assertAlmostEqual( + system.data["energies"][0], -200.3898256786414, places=5 + ) self.assertEqual(system.data["forces"].shape[1], 2) finally: os.unlink(fname)🤖 Prompt for AI Agents