Spaces:
Sleeping
Sleeping
File size: 5,070 Bytes
e76b79a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | {
"cells": [
{
"cell_type": "markdown",
"id": "4f84941e",
"metadata": {},
"source": [
"# Fixed Backbone design from LM\n",
"\n",
"This notebook demonstrates the Fixed Backbone design task from the paper [Language models generalize beyond natural proteins\n",
"](https://www.biorxiv.org/content/10.1101/2022.12.21.521521v1).\n",
"\n",
"Given an input structure as .pdb file, the LM is used iteratively in an MCMC optimization to find a sequence that folds to that structure\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d378b7f4-0792-446b-9e95-f7025bee5bec",
"metadata": {},
"outputs": [],
"source": [
"# First install additional dependencies\n",
"!pip install -r additional_requirements.txt\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cfd13d6a",
"metadata": {},
"outputs": [],
"source": [
"# Imports\n",
"import os\n",
"import time\n",
"import hydra\n",
"import py3Dmol\n",
"from lm_design import Designer\n",
"\n",
"# Params\n",
"pdb_fn = os.getcwd() + '/2N2U.pdb'\n",
"seed = 0 # Use different seeds to get different sequence designs for the same structure\n",
"TASK = \"fixedbb\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "989996bf",
"metadata": {},
"outputs": [],
"source": [
"# Load hydra config from config.yaml\n",
"with hydra.initialize_config_module(config_module=\"conf\"):\n",
" cfg = hydra.compose(\n",
" config_name=\"config\", \n",
" overrides=[\n",
" f\"task={TASK}\", \n",
" f\"seed={seed}\", \n",
" f\"pdb_fn={pdb_fn}\", \n",
" # 'tasks.fixedbb.num_iter=100' # DEBUG - use a smaller number of iterations\n",
" ])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63178538",
"metadata": {},
"outputs": [],
"source": [
"# Create a designer from configuration\n",
"des = Designer(cfg, pdb_fn)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86d25575",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Run the designer\n",
"start_time = time.time()\n",
"des.run_from_cfg()\n",
"print(\"finished after %s hours\", (time.time() - start_time) / 3600)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6d9f742",
"metadata": {},
"outputs": [],
"source": [
"print(\"Output seq:\", des.output_seq)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ba6c8c66",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Fold output with ESMFold API\n",
"output_seq = des.output_seq\n",
"# Fold with api:\n",
"# curl -X POST --data \"GENGEIPLEIRATTGAEVDTRAVTAVEMTEGTLGIFRLPEEDYTALENFRYNRVAGENWKPASTVIYVGGTYARLCAYAPYNSVEFKNSSLKTEAGLTMQTYAAEKDMRFAVSGGDEVWKKTPTANFELKRAYARLVLSVVRDATYPNTCKITKAKIEAFTGNIITANTVDISTGTEGSGTQTPQYIHTVTTGLKDGFAIGLPQQTFSGGVVLTLTVDGMEYSVTIPANKLSTFVRGTKYIVSLAVKGGKLTLMSDKILIDKDWAEVQTGTGGSGDDYDTSFN\" https://api.esmatlas.com/foldSequence/v1/pdb/\n",
"import requests\n",
"import json\n",
"url = 'https://api.esmatlas.com/foldSequence/v1/pdb/'\n",
"r = requests.post(url, data=output_seq)\n",
"output_struct = r.text\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5c06ab3",
"metadata": {},
"outputs": [],
"source": [
"# Visualize output structure\n",
"view = py3Dmol.view(width=800, height=800)\n",
"view.addModel(output_struct, 'pdb')\n",
"view.setStyle({'cartoon': {'color': 'spectrum'}})\n",
"view.zoomTo()\n",
"view.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b7247225",
"metadata": {},
"outputs": [],
"source": [
"des.x_logits.shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d8e5c184",
"metadata": {},
"outputs": [],
"source": [
"# Visualize wild type structure\n",
"wt_struct_file = pdb_fn\n",
"view = py3Dmol.view(width=800, height=800)\n",
"view.addModel(open(wt_struct_file).read(), 'pdb')\n",
"view.setStyle({'cartoon': {'color': 'spectrum'}})\n",
"view.zoomTo()\n",
"view.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "222ec344",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.12"
},
"vscode": {
"interpreter": {
"hash": "5502aca739f2549ad2771378ffc455b2bbb8b06f1a91617971f7097758a3cf84"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|