How do I specify the total number of orbitals for qchem.melecular_hamiltonian?

Hi, I have the following two functions:

def water(charge=0, multiplicity=1, basis_set='sto-3g', active_electrons=4, active_orbitals=4):
    symbols, coordinates = qchem.read_structure('Water.xyz')
    hamiltonian, qubits = qchem.molecular_hamiltonian(
        symbols,
        coordinates,
        charge=charge,
        mult=multiplicity,
        basis=basis_set,
        active_electrons=active_electrons,
        active_orbitals=active_orbitals,
    )

    return hamiltonian, qubits

def hydrogen_fluoride(charge=0, multiplicity=1, basis_set='sto-3g', active_electrons=2, active_orbitals=2):
    symbols = ["H", "F"]
    coordinates = np.array([0.896, 0, 0, -0.896, 0, 0])
    hamiltonian, qubits = qchem.molecular_hamiltonian(
        symbols,
        coordinates,
        charge=charge,
        mult=multiplicity,
        basis=basis_set,
        active_electrons=active_electrons,
        active_orbitals=active_orbitals,
    )

    return hamiltonian, qubits

The molecules obviously have the same number of electrons. But when I run the following code:

    ELECTRONS = 4
    ORBITALS = 4
    H, qubits = hydrogen_fluoride(active_electrons=ELECTRONS, active_orbitals=ORBITALS)

I get an error :

The number of core (3) + active orbitals (4) cannot be greater than the total number of orbitals (6)

However, the code

    ELECTRONS = 4
    ORBITALS = 4
    H, qubits = water(active_electrons=ELECTRONS, active_orbitals=ORBITALS)

runs fine. I looked into it further, and it seems that within the qchem.molecular_hamiltonian function, it has the following code:

mol = qml.qchem.Molecule(
            symbols,
            geometry_dhf,
            charge=charge,
            mult=mult,
            basis_name=basis,
            load_data=load_data,
            alpha=alpha,
            coeff=coeff,
        )

Which returns a mol with n_orbitals = 7 for water and 6 for HF. Any idea how I can fix this?

Hi @somearthling! The fix is pretty easy but please let me first explain the issue briefly.

Water has 10 electrons and 7 molecular orbitals while HF has 10 electrons and 6 molecular orbitals. From these 10 electrons you are excluding 6 of them as core electrons by specifying 4 active electrons in your code. That means, you have excluded 3 core orbitals because each orbital can contain two electrons. So for water, you are left with 7 - 3 = 4 active orbitals while for HF you can only have 6 - 3 = 3 active orbitals. In conclusion, you should have

# for H2O:
active_electrons= 4
active_orbitals = 4

# for HF:
active_electrons= 4
active_orbitals = 3

For more details on constructing an active space, please see this function and this demo. Please also let us know if you have other questions.

Hi, thanks! Is there no way to increase the number of active orbitals by treating some of the external orbitals in HF as active?

Hi @somearthling, yes you can do it.

One way is to use a smaller number of core electrons and core orbitals. The other way is to use a larger basis set, for example 6-31g, which allows you to have a larger number of active orbitals.

Please let me know if need help with any of these methods!

1 Like