Skip to content

Commit

Permalink
Permit all active orbitals partially occupied (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesB-1qbit authored Apr 12, 2022
1 parent 7351c8a commit 9e69354
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tangelo/toolboxes/molecular_computation/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,16 @@ def _convert_frozen_orbitals(self, frozen_orbitals):
active_occupied = [i for i in occupied if i not in frozen_occupied]
active_virtual = [i for i in virtual if i not in frozen_virtual]

# Exception raised here if n_occupied <= frozen_orbitals (int), because it means that there is no active electron.
# An exception is raised also if all occupied orbitals are in the frozen_orbitals (list).
if (len(active_occupied) == 0) or (len(active_virtual) == 0):
raise ValueError("All electrons or virtual orbitals are frozen in the system.")
# Calculate number of active electrons and active_mos
n_active_electrons = round(sum([self.mo_occ[i] for i in active_occupied]))
n_active_mos = len(active_occupied + active_virtual)

# Exception raised here if there is no active electron.
# An exception is raised also if all active orbitals are fully occupied.
if n_active_electrons == 0:
raise ValueError("There are no active electrons.")
if n_active_electrons == 2*n_active_mos:
raise ValueError("All active orbitals are fully occupied.")

return active_occupied, frozen_occupied, active_virtual, frozen_virtual

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ def test_no_active_virtual(self):
with self.assertRaises(ValueError):
SecondQuantizedMolecule(H2O_list, frozen_orbitals=[5, 6])

def test_all_active_orbitals_occupied_but_some_not_fully(self):
"""Verify that having all active orbitals occupied but only partially occupied is permitted"""
try:
SecondQuantizedMolecule(H2O_list, frozen_orbitals=[0, 1, 2, 3, 6], spin=2)
except ValueError:
self.fail("Unexpected ValueError raised")

def test_get_fermionic_hamiltonian(self):
"""Verify energy shift in molecular hamiltonian."""

Expand Down

0 comments on commit 9e69354

Please sign in to comment.