qml.qchem.molecular_hamiltonian

molecular_hamiltonian(name, geo_file, 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. The process begins by reading the file containing the geometry of the molecule.

  2. 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

  3. 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.

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


../../_images/fig_mult_active_space.png

Parameters
  • name (str) – name of the molecule

  • geo_file (str) – file containing the geometry 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.

Returns

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

Return type

tuple[pennylane.Hamiltonian, int]

Example

>>> name = "h2"
>>> geo_file = "h2.xyz"
>>> H, qubits = molecular_hamiltonian(name, geo_file)
>>> print(qubits)
4
>>> 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]