Skip to content

Fix #57: Add energy validation for ORCA output files#60

Open
manvirsingh01 wants to merge 2 commits intotheochem:masterfrom
manvirsingh01:fix/issue-57-orca-energy-validation
Open

Fix #57: Add energy validation for ORCA output files#60
manvirsingh01 wants to merge 2 commits intotheochem:masterfrom
manvirsingh01:fix/issue-57-orca-energy-validation

Conversation

@manvirsingh01
Copy link

@manvirsingh01 manvirsingh01 commented Jan 23, 2026

Fix ORCA file handling error in CondensedConceptualDFT.from_file()

This PR fixes #57, where ORCA-generated .wfn and .mkl files caused a runtime crash when loaded using CondensedConceptualDFT.from_file().

Issue

ORCA output files do not include total energy information. However, get_dict_energy() assumed molecule.energy was always present, leading to the following error:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'

Solution

  • Added explicit validation in get_dict_energy() to check whether molecule.energy is None
  • Raises a clear and user-friendly ValueError explaining the limitation
  • Guides users to prefer .fchk files or alternative conversion workflows
  • Added a dedicated test case to cover this scenario

Changes

  • chemtools/toolbox/utils.py: Added energy availability validation
  • chemtools/toolbox/test/test_utils.py: Added regression test for missing energy data

Testing

  • Syntax and static checks passed
  • Full test suite requires the optional horton dependency

- Added validation in get_dict_energy() to check if molecule.energy is None
- Raises clear ValueError with guidance for users using ORCA files (.wfn, .mkl)
- Added test case for the new validation
- ORCA files don't contain total energy, so users are directed to use .fchk files
@PaulWAyers
Copy link
Member

@manvirsingh01 I've @'d @FarnazH who is the primary maintainer of ChemTools. You should know that there is a MAJOR refactor of ChemTools underway (in a private repository) so I wouldn't invest too much time in this current version.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit handling for molecule files that lack total energy (common with ORCA-generated .wfn/.mkl) to prevent downstream crashes when building energy dictionaries for conceptual DFT workflows.

Changes:

  • Validate molecule.energy / mol.energy in get_dict_energy() and raise a clearer ValueError when missing.
  • Add a regression test that simulates a molecule missing energy to ensure the error is raised.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
chemtools/toolbox/utils.py Adds None-energy validation and raises clearer ValueError instead of crashing during FMO energy construction.
chemtools/toolbox/test/test_utils.py Adds a test that forces energy=None on a loaded molecule and asserts get_dict_energy() raises.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants