Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

permit all active orbitals partially occupied #146

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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