\n",
"
You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
\n",
" jupyter labextension install jupyterlab_3dmol
\n",
"
\n",
""
]
},
"metadata": {}
}
],
"source": [
"# @title # **7. Visualize 3D Structure of ColabFold Prediction** { run: \"auto\", display-mode: \"form\" }\n",
"\n",
"#@markdown Rank number/score for the **monomer model is the average pLDDT**,\n",
"#@markdown where a ranking of 1 correlates better local structure confidence.\n",
"#@markdown An acceptable model prediction should average $\\ge 85$.\n",
"#@markdown The number of ranked models was set in step `6. Run Prediction` (step 6, line 75.).\n",
"\n",
"#@markdown \\\n",
"#@markdown Here, you can change the value for `rank_num` to visualize the 5 predictions.\n",
"\n",
"import py3Dmol\n",
"import glob\n",
"import matplotlib.pyplot as plt\n",
"from colabfold.colabfold import plot_plddt_legend\n",
"from colabfold.colabfold import pymol_color_list, alphabet_list\n",
"\n",
"rank_num = 1 #@param [\"1\", \"2\", \"3\", \"4\", \"5\"] {type:\"raw\"}\n",
"color = \"rainbow\" #@param [\"chain\", \"lDDT\", \"rainbow\"]\n",
"show_sidechains = False #@param {type:\"boolean\"}\n",
"show_mainchains = False #@param {type:\"boolean\"}\n",
"\n",
"tag = results[\"rank\"][0][rank_num - 1]\n",
"jobname_prefix = \".custom\" if msa_mode == \"custom\" else \"\"\n",
"pdb_filename = f\"{jobname}/{jobname}{jobname_prefix}_unrelaxed_{tag}.pdb\"\n",
"pdb_file = glob.glob(pdb_filename)\n",
"\n",
"def show_pdb(rank_num=1, show_sidechains=False, show_mainchains=False, color=\"lDDT\"):\n",
" model_name = f\"rank_{rank_num}\"\n",
" view = py3Dmol.view(js='https://3dmol.org/build/3Dmol.js',)\n",
" view.addModel(open(pdb_file[0],'r').read(),'pdb')\n",
"\n",
"\n",
" if color == \"lDDT\":\n",
" view.setStyle({'cartoon': {'colorscheme': {'prop':'b','gradient': 'roygb','min':50,'max':90}}})\n",
" elif color == \"rainbow\":\n",
" view.setStyle({'cartoon': {'color':'spectrum'}})\n",
" elif color == \"chain\":\n",
" chains = len(queries[0][1]) + 1 if is_complex else 1\n",
" for n,chain,color in zip(range(chains),alphabet_list,pymol_color_list):\n",
" view.setStyle({'chain':chain},{'cartoon': {'color':color}})\n",
"\n",
" if show_sidechains:\n",
" BB = ['C','O','N']\n",
" view.addStyle({'and':[{'resn':[\"GLY\",\"PRO\"],'invert':True},{'atom':BB,'invert':True}]},\n",
" {'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n",
" view.addStyle({'and':[{'resn':\"GLY\"},{'atom':'CA'}]},\n",
" {'sphere':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n",
" view.addStyle({'and':[{'resn':\"PRO\"},{'atom':['C','O'],'invert':True}]},\n",
" {'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}})\n",
" if show_mainchains:\n",
" BB = ['C','O','N','CA']\n",
" view.addStyle({'atom':BB},{'stick':{'colorscheme':f\"WhiteCarbon\",'radius':0.3}}, viewer=(0,0))\n",
"\n",
" view.zoomTo()\n",
" return view\n",
"\n",
"print('Prediction: Rank %d' % rank_num)\n",
"show_pdb(rank_num, show_sidechains, show_mainchains, color).show()\n",
"if color == \"lDDT\":\n",
" plot_plddt_legend().show()\n",
"\n",
"\n",
"#@markdown \\"
]
},
{
"cell_type": "code",
"source": [
"# @title # **8. Align PDBs** { run: \"auto\", display-mode: \"form\" }\n",
"#@markdown We can compare the predictions with experiment.\n",
"#@markdown Example: PDB 1F16 was obtained from NMR, so there is an ensemble of structures.\n",
"\n",
"import Bio.PDB\n",
"\n",
"pdb_code = \"1f16\" #@param{type:\"string\"}\n",
"#@markdown - Reference PDB (Experiment)\n",
"cpred = \"\"#@param{type:\"string\"}\n",
"#@markdown - Color for Reference PDB (Experiment)\n",
"os.system(\"wget -qnc https://files.rcsb.org/download/%s.pdb.gz; gunzip %s.pdb.gz\" % (pdb_code,pdb_code))\n",
"\n",
"start_id = 1\n",
"end_id = len(query_sequence)\n",
"atoms_to_be_aligned = range(start_id, end_id + 1)\n",
"\n",
"# Start the parser\n",
"pdb_parser = Bio.PDB.PDBParser(QUIET = True)\n",
"\n",
"# Get the structures\n",
"ref_structure = pdb_parser.get_structure(\"reference\", \"%s.pdb\" % pdb_code)\n",
"sample_structure = pdb_parser.get_structure(\"sample\", pdb_file[0])\n",
"\n",
"# Use the first model in the pdb-files for alignment\n",
"# Change the number 0 if you want to align to another structure\n",
"ref_model = ref_structure[0]\n",
"sample_model = sample_structure[0]\n",
"\n",
"# Make a list of the atoms (in the structures) you wish to align.\n",
"# In this case we use CA atoms whose index is in the specified range\n",
"ref_atoms = []\n",
"sample_atoms = []\n",
"\n",
"# Iterate of all chains in the model in order to find all residues\n",
"for ref_chain in ref_model:\n",
" # Iterate of all residues in each model in order to find proper atoms\n",
" for ref_res in ref_chain:\n",
" # Check if residue number ( .get_id() ) is in the list\n",
" if ref_res.get_id()[1] in atoms_to_be_aligned:\n",
" # Append CA atom to list\n",
" ref_atoms.append(ref_res['CA'])\n",
"\n",
"# Do the same for the sample structure\n",
"for sample_chain in sample_model:\n",
" for sample_res in sample_chain:\n",
" if sample_res.get_id()[1] in atoms_to_be_aligned:\n",
" sample_atoms.append(sample_res['CA'])\n",
"\n",
"# Now we initiate the superimposer:\n",
"super_imposer = Bio.PDB.Superimposer()\n",
"super_imposer.set_atoms(ref_atoms, sample_atoms)\n",
"super_imposer.apply(sample_model.get_atoms())\n",
"\n",
"# Print RMSD:\n",
"print('The calculated RMSD is: %.3f Å' % super_imposer.rms)\n",
"\n",
"# Save the aligned version of one of the chains of 6ANE\n",
"io = Bio.PDB.PDBIO()\n",
"io.set_structure(sample_structure)\n",
"io.save(\"%s-aligned.pdb\" % jobname)\n",
"print('Saved Aligned PDB.')\n",
"\n",
"# rank_num = 1 #@param [\"1\", \"2\", \"3\", \"4\", \"5\"] {type:\"raw\"}\n",
"# #@markdown - Predicted PDB (AF/CF)\n",
"# color = \"lDDT\" #@param [\"chain\", \"lDDT\", \"rainbow\"]\n",
"# #@markdown - Color Predicted PDB (Default: lDDT)\n",
"# tag = results[\"rank\"][0][rank_num - 1]\n",
"# jobname_prefix = \".custom\" if msa_mode == \"custom\" else \"\"\n",
"# pdb_filename = f\"{jobname}/{jobname}{jobname_prefix}_unrelaxed_{tag}.pdb\"\n",
"# pdb_file = glob.glob(pdb_filename)\n",
"\n",
"# how_sidechains = False #@param {type:\"boolean\"}\n",
"# show_mainchains = False #@param {type:\"boolean\"}\n",
"\n",
"view=py3Dmol.view()\n",
"view.addModel(open(\"%s-aligned.pdb\" % jobname).read(),'pdb')\n",
"# view.addModel(open(\"%s.pdb\" % pdb_code).read())\n",
"view.zoomTo()\n",
"view.setBackgroundColor('white')\n",
"view.setStyle({'chain':'A'},{'cartoon': {'color': 'red'}})\n",
"view.setStyle({'chain':'B'},{'cartoon': {'color': 'blue'}})\n",
"view.show()\n",
"\n",
"# show_pdb(rank_num, show_sidechains, show_mainchains, color).show()\n",
"# if color == \"lDDT\":\n",
"# plot_plddt_legend().show()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 551
},
"collapsed": true,
"id": "aA_ldVyPrSWt",
"outputId": "e474d900-1469-4198-fa88-f547c5c702c3"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"The calculated RMSD is: 5.711 Å\n",
"Saved Aligned PDB.\n"
]
},
{
"output_type": "display_data",
"data": {
"application/3dmoljs_load.v0": "