Skip to content

Raise ValueError for malformed FCIDUMP files - #192

Open
ARYAMANN7279 wants to merge 2 commits into
theochem:mainfrom
ARYAMANN7279:fix/fcidump-error-messages
Open

ARYAMANN7279 wants to merge 2 commits into
theochem:mainfrom
ARYAMANN7279:fix/fcidump-error-messages

Conversation

@ARYAMANN7279

Copy link
Copy Markdown

load_fcidump has two error paths that do raise (message, lit), which raises a tuple. In Python 3 this does not show the message, it fails with TypeError: exceptions must derive from BaseException:

from moha.molkit.utils.tools import load_fcidump

load_fcidump(iter(["&FCI NORB=2,NELEC=2,MS2=0,\n", " &END\n"]))
# TypeError: exceptions must derive from BaseException

This changes both to ValueError with the message. MolHam.from_fcidump also called load_fcidump(open(path)) and never closed the file, so it now uses with.

I also added test_fcidump.py: a small handwritten FCIDUMP is read and the integrals are checked in physicists' notation, from_fcidump is checked, and the two error messages are checked. The two error tests fail without the change. I also compared the loader with PySCF on H2O/STO-3G and a 4-atom H chain in 6-31G (integrals to 1e-14 and the FCI energy to 1e-14) and it is correct for valid files.

AryamannSrivastava and others added 2 commits November 25, 2026 09:50
load_fcidump raised a tuple, which Python 3 turns into a TypeError that hides the message. Raise ValueError instead, close the file in MolHam.from_fcidump, and add tests.

This branch has not been deployed

No deployments
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.

1 participant