diff --git a/src/openfermion/chem/molecular_data.py b/src/openfermion/chem/molecular_data.py index d95bf43a9..9229f80ea 100644 --- a/src/openfermion/chem/molecular_data.py +++ b/src/openfermion/chem/molecular_data.py @@ -909,11 +909,10 @@ def load(self): key.tobytes().decode('utf-8'): value for key, value in zip(keys[...], values[...]) } + else: + self.general_calculations = {} 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. diff --git a/src/openfermion/chem/molecular_data_test.py b/src/openfermion/chem/molecular_data_test.py index efba40ea1..7e12f328e 100644 --- a/src/openfermion/chem/molecular_data_test.py +++ b/src/openfermion/chem/molecular_data_test.py @@ -12,7 +12,9 @@ """Tests for molecular_data.""" import os +import tempfile import unittest +import h5py import numpy.random import scipy.linalg import numpy as np @@ -347,3 +349,21 @@ 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. + with tempfile.NamedTemporaryFile(suffix='.hdf5') as tmp_file: + filename = tmp_file.name + 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) + molecule.save() + + # Manually remove the general_calculations_keys dataset. + with h5py.File(filename, '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, {})