{ "cells": [ { "cell_type": "markdown", "id": "3429c855-8e94-4b13-b76d-9514aa388269", "metadata": {}, "source": [ "[![Open In Colab](/_static/colab-badge.svg)](https://colab.research.google.com/github/OpenProteinAI/openprotein-docs/blob/main/source/python-api/structure-prediction/Using_RosettaFold3.ipynb)\n", "[![Get Notebook](/_static/get-notebook-badge.svg)](https://raw.githubusercontent.com/OpenProteinAI/openprotein-docs/refs/heads/main/source/python-api/structure-prediction/Using_RosettaFold3.ipynb)\n", "[![View In GitHub](/_static/view-in-github-badge.svg)](https://github.com/OpenProteinAI/openprotein-docs/blob/main/source/python-api/structure-prediction/Using_RosettaFold3.ipynb)\n", "\n", "# Using RosettaFold-3\n", "This tutorial demonstrates how to use the RosettaFold-3 model to predict the\n", "structure of a molecular complex, including proteins and ligands. We\n", "will also show how to request and retrieve predicted binding affinities\n", "and other quality metrics.\n", "\n", "# What you need before getting started\n", "\n", "First, ensure you have an active `OpenProtein` session. Then, import the\n", "necessary classes for defining the components of your complex." ] }, { "cell_type": "code", "execution_count": 1, "id": "aa67079e-312c-4b64-922c-d80d0b8e072b", "metadata": {}, "outputs": [], "source": [ "import openprotein\n", "from openprotein.protein import Protein\n", "from openprotein.chains import Ligand\n", "\n", "# Login to your session\n", "session = openprotein.connect()" ] }, { "cell_type": "markdown", "id": "ec9a8864-c90f-4489-a606-8f515416c972", "metadata": {}, "source": [ "# Defining the Molecules\n", "\n", "RosettaFold-3 can model proteins and ligands.\n", "For this example, we'll predict the structure of a protein\n", "dimer in complex with a ligand.\n", "\n", "We will define a dimer and one ligand. When using RosettaFold-3, similar to Boltz, we can\n", "specify that a `Protein` is meant to be an oligomer by specifying\n", "multiple ids in the `chain_id`. In this case, the protein is a dimer\n", "since we have `[\"A\", \"B\"]`.\n", "\n", "Note that for affinity prediction, the ligand that is binding must have\n", "a single, unique string for its `chain_id`." ] }, { "cell_type": "code", "execution_count": 2, "id": "e698e738-d5d3-42dd-b78c-a6bb109c5f68", "metadata": {}, "outputs": [], "source": [ "# Define the proteins\n", "proteins = [\n", " Protein(sequence=\"MVTPEGNVSLVDESLLVGVTDEDRAVRSAHQFYERLIGLWAPAVMEAAHELGVFAALAEAPADSGELARRLDCDARAMRVLLDALYAYDVIDRIHDTNGFRYLLSAEARECLLPGTLFSLVGKFMHDINVAWPAWRNLAEVVRHGARDTSGAESPNGIAQEDYESLVGGINFWAPPIVTTLSRKLRASGRSGDATASVLDVGCGTGLYSQLLLREFPRWTATGLDVERIATLANAQALRLGVEERFATRAGDFWRGGWGTGYDLVLFANIFHLQTPASAVRLMRHAAACLAPDGLVAVVDQIVDADREPKTPQDRFALLFAASMTNTGGGDAYTFQEYEEWFTAAGLQRIETLDTPMHRILLARRATEPSAVPEGQASENLYFQ\"),\n", "]\n", "proteins[0].chain_id = [\"A\", \"B\"]\n", "\n", "# You can also specify the proteins to be cyclic by setting the property\n", "# proteins[0].cyclic = True\n", "\n", "# Define the ligand\n", "# We use the three-letter code for S-adenosyl-L-homocysteine (SAH)\n", "# The chain_id 'C' is the \"binder\" we will reference later.\n", "ligands = [\n", " Ligand(ccd=\"SAH\", chain_id=\"C\")\n", "]" ] }, { "cell_type": "markdown", "id": "435b1eb0-51c1-4241-805c-eda60b30e0c0", "metadata": {}, "source": [ "# Create MSA for the Protein using Homology Search\n", "\n", "When using RosettaFold-3 with protein sequences, we need to supply an MSA to\n", "help inform the model. Otherwise, we can also explicitly set it to run\n", "using single sequence mode. You have to specify `protein.msa` either an\n", "MSA or to use `Protein.single_sequence_mode`.\n", "\n", "Here, we will be building an MSA using our platform capabilities. Take\n", "note of the syntax here: creating an MSA with a complex uses ColabFold's\n", "syntax of joining sequences with `:`." ] }, { "cell_type": "code", "execution_count": 3, "id": "f09c738e-b96e-43bf-905d-eb12c5290344", "metadata": {}, "outputs": [], "source": [ "msa_query = []\n", "for p in proteins:\n", " if p.chain_id is not None and isinstance(p.chain_id, list):\n", " for _ in p.chain_id:\n", " msa_query.append(p.sequence.decode())\n", " else:\n", " msa_query.append(p.sequence.decode())\n", "msa = session.align.create_msa(seed=\":\".join(msa_query))\n", "\n", "for p in proteins:\n", " p.msa = msa\n", " # If desired, use single sequence mode to specify no msa\n", " # p.msa = Protein.single_sequence_mode" ] }, { "cell_type": "markdown", "id": "b015df20-d3ca-4fcf-85be-85765979737b", "metadata": {}, "source": [ "# Predicting the Complex Structure and Affinity\n", "\n", "Now, we can call the `fold` method on the RosettaFold-3 model.\n", "\n", "The key steps are:\n", "\n", "1. Access the model via `session.fold.rosettafold_3`.\n", "2. Pass the defined proteins and ligands." ] }, { "cell_type": "code", "execution_count": 4, "id": "a6c53df3-97c3-49d4-9219-5667e1ae91d8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "FoldJob(num_records=1, job_id='d45432c7-3820-4499-ace0-b5b5ffd0a119', job_type=, status=, created_date=datetime.datetime(2025, 9, 11, 6, 59, 46, 990383, tzinfo=TzInfo(UTC)), start_date=None, end_date=None, prerequisite_job_id=None, progress_message=None, progress_counter=0, sequence_length=None)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Request the fold, including an affinity prediction for our ligand.\n", "fold_job = session.fold.rosettafold_3.fold(\n", " proteins=proteins,\n", " ligands=ligands,\n", ")\n", "fold_job" ] }, { "cell_type": "markdown", "id": "9444e3b7-53b8-4e85-baec-a68c5453483e", "metadata": {}, "source": [ "The call returns a `FoldComplexResultFuture` object immediately. This is\n", "a reference to your job running on the OpenProtein platform. You can\n", "monitor its status or wait for it to complete." ] }, { "cell_type": "code", "execution_count": 5, "id": "e9ca9947-5e66-45c4-a278-a02361c5abfb", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Waiting: 100%|█| 100/100 [03:02<00:00, 1.82s/it, status=SU\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Wait for the job to finish\n", "fold_job.wait_until_done(verbose=True)" ] }, { "cell_type": "markdown", "id": "9d5bc3d3-2124-4f41-b2a8-4fde0b24c2a9", "metadata": {}, "source": [ "# Retrieving the Results\n", "\n", "Once the job is complete, you can retrieve the various outputs from the\n", "future object.\n", "\n", "## Getting the Structure File\n", "The primary result is the predicted\n", "structure, which you can retrieve as a mmCIF file. Note that we only implemented mmCIF output format for RosettaFold-3." ] }, { "cell_type": "code", "execution_count": 6, "id": "f16952ef-a1a6-4319-a8ba-17a858e99288", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ATOM 446 C CD . GLU A 0 59 ? -12.421381 25.947437 4.6932273 1 0.854047 ? 59 A 1\n", "ATOM 447 O OE1 . GLU A 0 59 ? -13.197961 25.827934 5.6268296 1 0.808266 ? 59 A 1\n", "ATOM 448 O OE2 . GLU A 0 59 ? -12.76528 25.941364 3.5005865 1 0.790524 ? 59 A 1\n", "ATOM 449 N N . ALA A 0 60 ? -8.835037 25.153896 8.90248 1 0.939511 ? 60 A 1\n", "ATOM 450 C CA . ALA A 0 60 ? -8.65234 25.27169 10.35034 1 0.935187 ? 60 A 1\n", "ATOM 451 C C . ALA A 0 60 ? -8.414101 23.868555 10.900428 1 0.941439 ? 60 A 1\n", "ATOM 452 O O . ALA A 0 60 ? -8.983845 22.844774 10.375406 1 0.936552 ? 60 A 1\n", "ATOM 453 C CB . ALA A 0 60 ? -9.833746 25.863743 11.062814 1 0.918455 ? 60 A 1\n", "ATOM 454 N N . PRO A 0 61 ? -7.5745974 23.69525 11.947628 1 0.93808 ? 61 A 1\n", "ATOM 455 C CA . PRO A 0 61 ? -7.472991 22.403498 12.583999 1 0.938778 ? 61 A 1\n" ] } ], "source": [ "# Get the result as a PDB bytestring\n", "result = fold_job.get()\n", "\n", "print('\\n'.join(result.decode().splitlines()[500:510])) # Print a few lines" ] }, { "cell_type": "markdown", "id": "cdab1798-d544-4eca-89b8-262377f3b8da", "metadata": {}, "source": [ "Visualize the structure using [molviewspec](https://github.com/molstar/mol-view-spec)" ] }, { "cell_type": "code", "execution_count": 7, "id": "e12f68b4-70e4-4eea-835d-9d40dc45ec0b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\n", " setTimeout(function(){\n", " var wrapper = document.getElementById(\"molstar_e0114ebe-ead6-49f4-82fb-f8f2aaaee527\")\n", " if (wrapper === null) {\n", " throw new Error(\"Wrapper element #molstar_e0114ebe-ead6-49f4-82fb-f8f2aaaee527 not found anymore\")\n", " }\n", " var blob = new Blob([\"\\n\\n \\n