A quantum computing approach to solving the protein folding problem using Qiskit. This project implements Variational Quantum Eigensolver (VQE) algorithm to predict the 3D structure of proteins based on their amino acid sequence.
Our implementation is inspired by and extends the methods described in
Protein Folding Problem: A Quantum Approach, and this repository: quantum-protein-folding-qiskit
- Overview
- Features
- Visualizations
- Requirements
- Installation
- Usage
- Documentation (Sphinx)
- Running Tests
- Adding Dependencies
- Project Structure
- How It Works
- Key Modules
- Contributing
- Authors
- License
Protein folding is one of the most challenging problems in computational biology. This project leverages quantum computing to explore protein conformations on a lattice model, using quantum optimization to find low-energy states that represent folded protein structures.
The implementation uses:
- Qiskit for quantum circuit construction and simulation
- VQE (Variational Quantum Eigensolver) for quantum optimization
- Hamiltonian formulation combining distance constraints, contact interactions, and backtracking penalties
- HP and MJ interaction models for residue-residue energies
- π¬ Multiple interaction models: Hydrophobic-Polar (HP) and Miyazawa-Jernigan (MJ)
- βοΈ Quantum backend support: IBM Quantum and local simulator
- π Rich visualizations: 2D projections, interactive 3D plots, and animated rotations
- π Result tracking: Detailed logging of VQE iterations, energies, and convergence
The quantum optimization produces protein conformations that can be visualized in multiple ways:

Click to view the interactive 3D visualization (HTML)
Animated 360Β° rotation of the folded protein structure
The visualizations show:
- Backbone chain (main chain beads) in one color
- Residue labels for each amino acid position
- 3D spatial arrangement on a discrete lattice
- Energy-minimized conformation from VQE optimization
- Python 3.12 or higher
uv- Fast Python package and environment manager
Choose one of the following methods:
Linux/macOS:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Alternative (via pip):
pip install uv
git clone https://github.com/QFold-Thesis/quantum-protein-folding.git
cd quantum-protein-folding
uv sync
This command:
- Creates a virtual environment in
.venv/ - Installs all dependencies from
pyproject.toml - Sets up the development environment
To use IBM Quantum hardware or cloud simulators:
- Create a
.envfile in the project root:
cp .env.example .env
- Add your IBM Quantum API token to
.env:
IBM_QUANTUM_TOKEN="your_token_here"
Get your token from IBM Quantum.
uv run src/main.py
This will:
- Fold the default protein sequence (
APRLRFY) - Run VQE optimization using a quantum simulator
- Generate visualizations in the
output/directory - Save results including energies, conformations, and plots
Edit src/main.py to change the sequence:
def main() -> None:
main_chain: str = "APRLRFY" # Change this to your sequence
side_chain: str = EMPTY_SIDECHAIN_PLACEHOLDER * len(main_chain)
# ... rest of the code
Edit src/constants.py to adjust:
CONFORMATION_ENCODING:ConformationEncoding.DENSEorConformationEncoding.SPARSE- Backend settings for IBM Quantum or local simulators
- Interaction model: HP or MJ
After running, check the output/results/ directory for timestamped folders containing:
interactive_3d_visualization.html- Interactive 3D plot (open in browser)rotating_3d_visualization.gif- Animated rotationconformation_2d.png- 2D projectionconformation.xyz- XYZ coordinate fileraw_vqe_results.json- Detailed VQE outputvqe_iterations.txt- Iteration-by-iteration energies
Additionally, each test run generates timestamped logfiles - check the output/logs/ directory to inspect them.
Tip
If you wish to see the usage demonstration and suggested setup, please check:
- π΅π± Demo Jupyter Notebook in Polish
- π¬π§ Demo Jupyter Notebook in English
- Register jupyter kernel with .venv
Linux/macOS:
uv run ipython kernel install --user --env VIRTUAL_ENV "$(pwd)/.venv" --name=quantum_protein_folding
Windows (PowerShell):
uv run ipython kernel install --user --env VIRTUAL_ENV "$($PWD)\.venv" --name=quantum_protein_folding
- Run the demo notebook
uv run --with jupyter jupyter lab docs/usage-demo-en.ipynb # In english
uv run --with jupyter jupyter lab docs/usage-demo-pl.ipynb # In polish
- Notebook should be automatically launched - if not, check
localhost:8888/lab/. Also remember about choosing proper kernel (quantum_protein_folding).
The documentation for this repository is automatically built and deployed to GitHub Pages. You can view the latest published docs at:
qfold-thesis.github.io/quantum-protein-folding
You can also build the documentation locally with Sphinx. If you use uv as the project environment manager, the following command will run the Sphinx builder inside the project's environment:
uv run sphinx-build -b html docs/sphinx docs/sphinx/_build/html
After a successful build the generated HTML files will be placed in docs/sphinx/_build/html.
uv run pytest -v -s
For specific test modules:
uv run pytest tests/test_utils.py -v
To add a new package:
uv add <package-name>
For development dependencies:
uv add --dev <package-name>
quantum-protein-folding/
βββ docs/ # Sphinx documentation and README
βββ src/
β βββ backend/ # Quantum backend configurations
β βββ builder/ # Hamiltonian construction
β βββ contact/ # Contact map generation
β βββ distance/ # Distance operator builders
β βββ interaction/ # HP and MJ interaction models
β βββ protein/ # Protein, chain, and bead classes
β βββ result/ # Result interpretation and visualization
β βββ utils/ # Utility functions
β βββ constants.py # Global constants
β βββ enums.py # Enumerations
β βββ main.py # Main entry point
βββ tests/ # Unit tests
βββ output/ #
β βββ results/ # Generated results and visualizations
β βββ logs/ # Generated logfiles
βββ pyproject.toml # Project metadata and dependencies
βββ .env.example # Example of .env file
-
Protein Representation: Proteins are modeled as chains of beads on a tetrahedral lattice, with each bead representing an amino acid residue.
-
Quantum Encoding: Turn directions at each position are encoded into qubits using either sparse (more qubits) or dense (fewer qubits) encoding schemes.
-
Hamiltonian Construction: A quantum Hamiltonian is built combining:
- Contact interaction energies (HP or MJ model)
- Distance constraints between beads
- Backtracking penalties
-
VQE Optimization: A variational quantum eigensolver finds the ground state (minimum energy) configuration.
-
Result Interpretation: The optimal quantum state is decoded into 3D coordinates and visualized.
protein/: Models proteins as main/side chains composed of beads with quantum turn operatorsinteraction/: Provides pairwise residue energies (HP or MJ models)contact/: Computes contact map and converts residueβresidue contacts into Hamiltonian termsdistance/: Builds distance operators and encodes geometric constraintsbuilder/: Constructs the full Hamiltonian from protein structure and interactionsbackend/: Manages quantum backends (IBM Quantum, simulators)result/: Interprets VQE results and generates visualizations
This project maintains high code quality standards using a strict stack managed by uv. We enforce static typing, rigorous linting, and documentation coverage.
Quality Assurance Tools are listed under dev dependency group in pyproject.toml. Each tool has it's own config section in the file.
Linting and Formatting is handled by Ruff:
# Check for errors
uv run ruff check .
# Auto-fix import sorting and simple style issues
uv run ruff check --fix .
# Reformat code (black-style)
uv run ruff format .
Static code analysis is performed by Pyrefly:
# Run type check
uv run pyrefly check
We require at least 90% docstring coverage for the project (excluding tests and docs) using Interrogate:
# Check coverage
uv run interrogate -v
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is released under the terms of the MIT license. See the LICENSE file for details.