Skip to content
Merged
7 changes: 3 additions & 4 deletions src/openfermion/chem/molecular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions src/openfermion/chem/molecular_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, {})
Loading