molecular_hamiltonian(symbols, coordinates, name='molecule', charge=0, mult=1, basis='sto-3g', package='pyscf', active_electrons=None, active_orbitals=None, mapping='jordan_wigner', outpath='.', wires=None)[source]

Generates the qubit Hamiltonian of a molecule.

This function drives the construction of the second-quantized electronic Hamiltonian of a molecule and its transformation to the basis of Pauli matrices.

  1. OpenFermion-PySCF or OpenFermion-Psi4 plugins are used to launch the Hartree-Fock (HF) calculation for the polyatomic system using the quantum chemistry package PySCF or Psi4, respectively.

    • The net charge of the molecule can be given to simulate cationic/anionic systems. Also, the spin multiplicity can be input to determine the number of unpaired electrons occupying the HF orbitals as illustrated in the left panel of the figure below.

    • The basis of Gaussian-type atomic orbitals used to represent the molecular orbitals can be specified to go beyond the minimum basis approximation. Basis set availability per element can be found here

  2. An active space can be defined for a given number of active electrons occupying a reduced set of active orbitals in the vicinity of the frontier orbitals as sketched in the right panel of the figure below.

  3. Finally, the second-quantized Hamiltonian is mapped to the Pauli basis and converted to a PennyLane observable.


  • symbols (list[str]) – symbols of the atomic species in the molecule

  • coordinates (array[float]) – 1D array with the atomic positions in Cartesian coordinates. The coordinates must be given in atomic units and the size of the array should be 3*N where N is the number of atoms.

  • name (str) – name of the molecule

  • charge (int) – Net charge of the molecule. If not specified a a neutral system is assumed.

  • mult (int) – Spin multiplicity \(\mathrm{mult}=N_\mathrm{unpaired} + 1\) for \(N_\mathrm{unpaired}\) unpaired electrons occupying the HF orbitals. Possible values of mult are \(1, 2, 3, \ldots\). If not specified, a closed-shell HF state is assumed.

  • basis (str) –

    Atomic basis set used to represent the molecular orbitals. Basis set availability per element can be found here

  • package (str) – quantum chemistry package (pyscf or psi4) used to solve the mean field electronic structure problem

  • active_electrons (int) – Number of active electrons. If not specified, all electrons are considered to be active.

  • active_orbitals (int) – Number of active orbitals. If not specified, all orbitals are considered to be active.

  • mapping (str) – transformation ('jordan_wigner' or 'bravyi_kitaev') used to map the fermionic Hamiltonian to the qubit Hamiltonian

  • outpath (str) – path to the directory containing output files

  • wires (Wires, list, tuple, dict) – Custom wire mapping for connecting to Pennylane ansatz. For types Wires/list/tuple, each item in the iterable represents a wire label corresponding to the qubit number equal to its index. For type dict, only int-keyed dict (for qubit-to-wire conversion) is accepted for partial mapping. If None, will use identity map.


the fermionic-to-qubit transformed Hamiltonian and the number of qubits

Return type

tuple[pennylane.Hamiltonian, int]


>>> symbols, coordinates = (['H', 'H'], np.array([0., 0., -0.66140414, 0., 0., 0.66140414]))
>>> H, qubits = molecular_hamiltonian(symbols, coordinates)
>>> print(qubits)
>>> print(H)
(-0.04207897647782188) [I0]
+ (0.17771287465139934) [Z0]
+ (0.1777128746513993) [Z1]
+ (-0.24274280513140484) [Z2]
+ (-0.24274280513140484) [Z3]
+ (0.17059738328801055) [Z0 Z1]
+ (0.04475014401535161) [Y0 X1 X2 Y3]
+ (-0.04475014401535161) [Y0 Y1 X2 X3]
+ (-0.04475014401535161) [X0 X1 Y2 Y3]
+ (0.04475014401535161) [X0 Y1 Y2 X3]
+ (0.12293305056183801) [Z0 Z2]
+ (0.1676831945771896) [Z0 Z3]
+ (0.1676831945771896) [Z1 Z2]
+ (0.12293305056183801) [Z1 Z3]
+ (0.176276408043196) [Z2 Z3]