Skip to content

Commit

Permalink
Removing lingering references to orbital overlaps (#142)
Browse files Browse the repository at this point in the history
* Remove lingering references to orbital overlaps

* Remove additional line from test

* Added tests for molecular data

* Update for Python 2 and 3 compatability on unicode string types for test
  • Loading branch information
jarrodmcc authored and babbush committed Aug 15, 2017
1 parent af630c1 commit aee5471
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 7 additions & 13 deletions src/fermilib/utils/_molecular_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
+ 0.5 * \sum_{p,q,r,s} h[p,q,r,s] a_p^\dagger a_q^\dagger a_r a_s
"""

# Define a compatible basestring for checking between Python 2 and 3
try:
basestring
except:
basestring = str


# Define error objects which inherit from Exception.
class MoleculeNameError(Exception):
Expand Down Expand Up @@ -211,7 +217,6 @@ class MolecularData(object):
n_qubits: Integer giving total number of qubits that would be needed.
orbital_energies: Numpy array giving the canonical orbital energies.
fock_matrix: Numpy array giving the Fock matrix.
orbital_overlaps: Numpy array giving the orbital overlap coefficients.
one_body_integrals: Numpy array of one-electron integrals
two_body_integrals: Numpy array of two-electron integrals
mp2_energy: Energy from MP2 perturbation theory.
Expand Down Expand Up @@ -271,8 +276,7 @@ def __init__(self, geometry=None, basis=None, multiplicity=None,

# Metadata fields with default values.
self.charge = charge
if (not isinstance(description, str) and
not isinstance(description, unicode)):
if (not isinstance(description, basestring)):
raise TypeError("description must be a string.")
self.description = description

Expand Down Expand Up @@ -305,9 +309,6 @@ def __init__(self, geometry=None, basis=None, multiplicity=None,
self.hf_energy = None
self.orbital_energies = None

# Attributes generated from integrals.
self._orbital_overlaps = None

# Attributes generated from MP2 calculation.
self.mp2_energy = None

Expand All @@ -328,7 +329,6 @@ def init_lazy_properties(self):

# Molecular orbitals
self._canonical_orbitals = None
self._orbital_overlaps = None

# Electronic Integrals
self._one_body_integrals = None
Expand Down Expand Up @@ -511,12 +511,6 @@ def save(self):
self.orbital_energies is not None else
False))
# Save attributes generated from integrals.
f.create_dataset("orbital_overlaps",
data=(self.orbital_overlaps if
self.orbital_overlaps is
not None else False),
compression=("gzip" if self.orbital_overlaps
is not None else None))
f.create_dataset("one_body_integrals",
data=(self.one_body_integrals if
self.one_body_integrals is
Expand Down
11 changes: 10 additions & 1 deletion src/fermilib/utils/_molecular_data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def test_name_molecule(self):
description="0.7414")
self.assertEqual(correct_name, computed_name)

# Check errors in naming
with self.assertRaises(TypeError):
test_molecule = MolecularData(self.geometry, self.basis,
self.multiplicity, description=5)
correct_name = str('H2_sto-3g_singlet')
test_molecule = self.molecule = MolecularData(
self.geometry, self.basis, self.multiplicity,
data_directory=DATA_DIRECTORY)
self.assertSequenceEqual(correct_name, test_molecule.name)

def test_invalid_multiplicity(self):
geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
basis = 'sto-3g'
Expand Down Expand Up @@ -115,7 +125,6 @@ def test_dummy_save(self):
molecule.hf_energy = 99.
molecule.canonical_orbitals = [1, 2, 3, 4]
molecule.orbital_energies = [5, 6, 7, 8]
molecule.orbital_overlaps = [1, 2, 3, 4]
molecule.one_body_integrals = [5, 6, 7, 8]
molecule.two_body_integrals = [5, 6, 7, 8]
molecule.mp2_energy = -12.
Expand Down

0 comments on commit aee5471

Please sign in to comment.