Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions chemtools/toolbox/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def test_get_dict_energy_raises():
assert_raises(ValueError, get_dict_energy, molecule)


def test_get_dict_energy_none_energy_raises():
"""Test that get_dict_energy raises ValueError when energy is None."""
with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as fname:
molecule = Molecule.from_file(fname)
# Simulate a molecule without energy (like ORCA files)
molecule._iodata.energy = None
assert_raises(ValueError, get_dict_energy, molecule)


def test_get_dict_density_raises():
# check molecule
with path('chemtools.data', 'ch4_uhf_ccpvdz.fchk') as file1:
Expand Down
14 changes: 14 additions & 0 deletions chemtools/toolbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def get_dict_energy(molecule):
# get homo/lumo energy
homo_e, lumo_e, _, _ = get_homo_lumo_data(molecule)
nelec = sum(molecule.mo.nelectrons)
# validate that energy is available
if molecule.energy is None:
raise ValueError(
"Molecule does not contain total energy information. "
"This is common for ORCA output files (*.wfn, *.mkl). "
"Please use a file format that includes energy (e.g., *.fchk) "
"or provide multiple molecule files with explicit energy values."
)
# store number of electron and energy in a dictionary
energies = {nelec: molecule.energy,
nelec + 1: molecule.energy + lumo_e,
Expand All @@ -197,6 +205,12 @@ def get_dict_energy(molecule):
nelec = sum(mol.mo.nelectrons)
if nelec in list(energies.keys()):
raise ValueError("Two molecules have {0} electrons!".format(nelec))
# validate that energy is available
if mol.energy is None:
raise ValueError(
"Molecule with {0} electrons does not contain total energy. "
"This is common for ORCA output files (*.wfn, *.mkl).".format(nelec)
Comment thread
manvirsingh01 marked this conversation as resolved.
Outdated
)
Comment thread
manvirsingh01 marked this conversation as resolved.
# store number of electrons and energy in a dictionary
energies[nelec] = mol.energy
else:
Expand Down
Loading