Skip to content
Merged
5 changes: 1 addition & 4 deletions src/openfermion/chem/molecular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,7 @@ def load(self):
for key, value in zip(keys[...], values[...])
}
else:
# TODO: test the no cover
# no coverage here because pathway is check on
# bad user generated file
self.general_calculations = None # pragma: nocover
self.general_calculations = {}

def get_from_file(self, property_name):
"""Helper routine to re-open HDF5 file and pull out single property.
Expand Down
21 changes: 21 additions & 0 deletions src/openfermion/chem/molecular_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import os
import unittest
import h5py
import numpy.random
import scipy.linalg
import numpy as np
Expand Down Expand Up @@ -347,3 +348,23 @@ def test_missing_calcs_for_integrals(self):
molecule.get_k()
with self.assertRaises(MissingCalculationError):
molecule.get_antisym()

def test_load_no_general_calculations(self):
# Make fake molecule.
filename = os.path.join(DATA_DIRECTORY, 'dummy_molecule_no_gen_calc')
geometry = [('H', (0.0, 0.0, 0.0)), ('H', (0.0, 0.0, 0.7414))]
basis = '6-31g*'
multiplicity = 1
molecule = MolecularData(geometry, basis, multiplicity, filename=filename)
try:
molecule.save()

# Manually remove the general_calculations_keys dataset.
with h5py.File(filename + '.hdf5', 'r+') as f:
del f['general_calculations_keys']

# Load the molecule and check that general_calculations is empty.
new_molecule = MolecularData(filename=filename)
self.assertEqual(new_molecule.general_calculations, {})
finally:
os.remove(filename + '.hdf5')
Loading