The science of rainbows
Welcome! I'm so excited to explore the physics of rainbows with you today. Before we dive into how light and water play together to create these beautiful arcs in the sky, I'd love to know a little more about what brings you here.
What brings you to learning about rainbows today, and how much background in physics or science do you already have?
[file content begin]
From: Dr. Junaid Amjad
Associate Professor (Tenured)
COMSATS University Islamabad, Lahore Campus
Welcome to your first assignment in Quantum Simulation of Electronic Structure. This assignment is designed to introduce you to the complete workflow used in modern Quantum Simulation of Electronic Structure research. You will reproduce the entire pipeline using the simplest molecule, H₂, before progressing to larger systems.
This is Assignment 1 in an ongoing research track in our group applying quantum computing methods (the variational quantum eigensolver, VQE) to electronic structure problems of real chemical and materials interest, from coordination complexes of rare-earth ions to, eventually, two-dimensional materials. H₂ is deliberately the simplest possible case: closed-shell, one bond, minimal basis. Every tool you touch here, PySCF, Qiskit, active-space selection, Jordan--Wigner mapping, is the same tool used in that research, just applied to the smallest system where you can check every step by hand. See "Research Roadmap" below for where this is going.
-
Build the H₂ molecular geometry.
-
Understand basis sets (STO-3G).
-
Perform Hartree--Fock calculations with PySCF.
-
Analyze occupied and virtual molecular orbitals.
-
Generate and visualize molecular orbitals using cube files and VMD.
-
Understand active-space selection.
-
Construct the electronic Hamiltonian.
-
Map the Hamiltonian to qubits.
-
Run a VQE calculation using Qiskit.
-
Compare Hartree--Fock, exact, and VQE energies.
Geometry → Basis Set → Hartree--Fock → Molecular Orbitals → Orbital Visualization → Active Space → Electronic Hamiltonian → Qubit Mapping → VQE
This assignment is the first step in a longer sequence. You do not need to know the later steps to complete Assignment 1, but it helps to see where each piece leads.
-
Assignment 1 (this one): H₂, closed-shell Hartree--Fock, minimal active space, first VQE run. Goal: understand every stage of the pipeline on a system small enough to check by hand.
-
Assignment 2: an open-shell molecule. Restricted open-shell Hartree--Fock (ROHF), unequal alpha/beta electron counts, and active-space selection using Mulliken population analysis rather than by inspection. This is where several real, well-documented conventions first matter, see the note in Part 7 below.
-
Assignment 3: a small rare-earth coordination complex, bridging toward the group's active VQE research on lanthanide 4f-shell systems (Er³⁺ and related coordination environments). Larger active spaces, CASCI/CASSCF, and the double-shell effect.
-
Later: extension toward two-dimensional materials, using plane-wave DFT (Quantum ESPRESSO, open-source) alongside the molecular-orbital tools used here, for periodic/solid-state electronic structure.
Standardizing on one environment now will save real time later. All students should set up: Python 3.x on Ubuntu (native Linux, or WSL2 if working from Windows) with PySCF, Qiskit, Qiskit Nature, and OpenFermion. Some later assignments in this sequence use Qiskit Nature and some use OpenFermion directly, both are used in the group's own research code, so familiarity with both is worthwhile rather than a detour. Quantum ESPRESSO will be introduced separately when we reach the 2D-materials phase; no need to install it yet.
Create H₂ with bond length 0.735 Å, charge 0, spin 0. Submit geometry.py.
Use STO-3G. Explain what a basis set is, why STO-3G is minimal, and how many basis functions H₂ has.
Print total energy, MO energies, occupations, electron count, and nuclear repulsion energy. Define HOMO and LUMO.
Generate cube files with PySCF and visualize HOMO/LUMO in VMD. Include screenshots and discuss bonding/antibonding.
Calculate energies from 0.4--2.5 Å and plot energy vs bond length.
Identify occupied/virtual orbitals and justify the (2e,2o) active space.
Generate the fermionic Hamiltonian using Qiskit Nature.
Look ahead (not needed for H₂, worth remembering later): Qiskit Nature handles the conversion from PySCF's two-electron integrals to a fermionic operator internally, so this step "just works" here. When you later build a fermionic Hamiltonian by hand, for example with OpenFermion, which several later assignments use directly, the two-electron integral index ordering and the reference-determinant construction for open-shell systems are two of the most common sources of a wrong sign or a wrong energy that still runs without an error. If you ever see a two-electron energy exactly opposite in sign, or a reference-state energy correct to the wrong problem, that is almost always a convention mismatch, not a physics error, check integral index order and occupation construction before anything else.
Apply Jordan--Wigner mapping and inspect the Pauli Hamiltonian.
Run VQE (UCCSD + Hartree--Fock initial state + COBYLA).
Compare Hartree--Fock, Exact Diagonalization, and VQE energies.
Study optimizer convergence.
Prepare a professional report (maximum 10 pages).
-
geometry.py
-
hf.py
-
orbitals.py
-
vqe.py
-
plot_energy.py
-
Source code
-
Figures of molecular orbitals
-
Energy curve
-
Final report
-
10-minute presentation
Do not treat this as a programming exercise alone. Your goal is to understand every stage of the computational workflow. This assignment forms the foundation for future work on larger molecules, materials, and rare-earth systems in our research group. When Assignment 2 introduces an open-shell reference and Assignment 3 introduces a real coordination complex, the difference will mostly be scale and a handful of new conventions to get right, not new ideas. If you understand why each step in this H₂ pipeline works, you are already most of the way to reproducing the group's ongoing VQE research. Ask questions early; a wrong sign or a mislabeled orbital is much easier to fix on H₂, where you can check the answer by hand, than three assignments from now.
i have to complete this task and then i have to give a presentation on it help me
Welcome! I'm so glad to help you tackle this assignment. It's the perfect way to build a solid foundation because once you understand the entire pipeline on a small, manageable molecule like , you'll have the exact tools needed to study complex, real-world materials later in your research with Dr. Junaid Amjad.
Let's get started with your first deliverable: defining the molecular geometry and setting up your first script, geometry.py.
Setting Up the Molecular Geometry in PySCF
geometry.py deliverable, we want to set up a hydrogen molecule with a bond length of exactly 0.735 Å (Angstroms), a net charge of 0, and a spin of 0.
Here is how we translate these physical parameters into clean, executable PySCF code:from pyscf import gto
# Define the H2 molecular geometry and settings
mol = gto.Mole()
mol.atom = '''
H 0.0 0.0 0.0
H 0.0 0.0 0.735
'''
mol.basis = 'sto-3g'
mol.charge = 0
mol.spin = 0
mol.build()
print("PySCF Molecule built successfully!")
print(f"Nuclear repulsion energy: {mol.energy_nuc():.6f} Hartree")
(0.0, 0.0, 0.0) and the second hydrogen atom along the z-axis at (0.0, 0.0, 0.735) to precisely set our 0.735 Å bond length.
We set charge = 0 because our molecule is neutral, and spin = 0 because all the electron spins are paired up in a singlet state.
Let's run this first. Do you have your Python environment ready to execute this, or would you like to discuss what the sto-3g basis set setting actually means next?Let's continue to the STO-3G basis set concept
Let's dive straight into the concept of basis sets, which is one of the most critical approximations we make in computational quantum chemistry.
What is a Basis Set?
In quantum mechanics, electrons don't orbit the nucleus in tidy planetary paths; they exist as fuzzy probability clouds described by wavefunctions. To simulate these clouds on a computer, we need a mathematical way to represent them.
This is where a comes in.
A basis set is a collection of mathematical functions (typically styled after atomic orbitals) that we mix together in different proportions to represent the electronic wavefunction of our molecule.
If you want to think of this as an analogy, imagine a basis set as a box of watercolors. If you only have red, blue, and yellow, you can paint a basic picture. If you have 120 different shades, you can paint a masterpiece with highly realistic lighting and shadows. In quantum chemistry, more basis functions allow our electronic "paint" to flex and polarize, giving us a much more accurate picture of where the electrons actually want to go. However, just like a massive watercolor kit, more functions mean the computer has to work much harder to calculate the result.
For Assignment 1, Dr. Junaid Amjad has assigned the simplest possible watercolor box: the STO-3G basis set. Let's look at exactly what that means.
STO-3G
noun
A minimal basis set where each Slater-Type Orbital (representing a physical atomic orbital) is mathematically approximated by a linear combination of exactly three primitive Gaussian-Type Orbitals.
Because STO-3G is a minimal basis set, it only allocates the absolute bare minimum number of orbital functions required to hold the electrons of the ground-state neutral atoms.
For a hydrogen atom, a neutral ground-state atom only has a single electron in its 1s shell. Therefore, STO-3G assigns exactly one spatial orbital function (the 1s orbital) to each hydrogen atom.
Next, let's look at how we count these up for our entire H₂ molecule, which will directly answer Part 2 of your assignment deliverable.
Continue to counting H₂ spatial and spin orbitals
Let's map out exactly how our basis functions translate into the spatial and spin orbitals that the computer tracks for H₂.
Spatial Orbitals vs Spin Orbitals
When we build our hydrogen molecule using the STO-3G minimal basis set, each hydrogen atom contributes exactly one 1s basis function. This gives our H₂ molecule a total of 2 spatial orbitals (one on each hydrogen atom).
However, quantum mechanics requires us to consider the quantum spin of our electrons. Because electrons are fermions, they possess an intrinsic spin that can point in one of two directions: up ( ) or down ( ).
To account for this, we must expand our spatial orbitals into spin-orbitals.
Every single spatial orbital can hold up to two electrons: one with alpha spin and one with beta spin. Therefore, to get our total spin-orbital count, we simply multiply our spatial orbital count by 2.
For our STO-3G H₂ simulation, this leaves us with:
- 2 spatial orbitals
- 4 spin-orbitals (2 spatial orbitals 2 spin states)
This means that when we map our molecule to a quantum computer in Part 8 of your assignment, we will need exactly 4 qubits (one qubit to represent the occupation of each spin-orbital).
Now that you've got the geometry and basis set count down for your report, are you ready to run the Hartree-Fock calculation in PySCF and analyze the resulting molecular orbitals?