Skip to content

Commit bd1c3ba

Browse files
committed
fixing the use_esm_1b notebook, updating to use alphafolddb v3
1 parent 5bec062 commit bd1c3ba

File tree

1 file changed

+65
-31
lines changed

1 file changed

+65
-31
lines changed

af/examples/use_esm_1b_bias.ipynb

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,59 @@
1010
"<a href=\"https://colab.research.google.com/github/sokrypton/ColabDesign/blob/main/af/examples/use_esm_1b_bias.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
1111
]
1212
},
13+
{
14+
"cell_type": "markdown",
15+
"source": [
16+
"# Gather inputs"
17+
],
18+
"metadata": {
19+
"id": "M9xamJDvx1pd"
20+
}
21+
},
22+
{
23+
"cell_type": "code",
24+
"source": [
25+
"import requests, re\n",
26+
"from google.colab import files\n",
27+
"\n",
28+
"def get_uniprot_seq(uid):\n",
29+
" url = f'https://rest.uniprot.org/uniprotkb/stream?compressed=false&format=fasta&query={uid}'\n",
30+
" sequence = \"\".join(re.split(r'\\n(?=>)', requests.get(url).text)[0].split(\"\\n\")[1:])\n",
31+
" return sequence\n",
32+
"\n",
33+
"def get_pdb(pdb_code=\"\",alphafold_model=False):\n",
34+
" if pdb_code is None or pdb_code == \"\":\n",
35+
" upload_dict = files.upload()\n",
36+
" pdb_string = upload_dict[list(upload_dict.keys())[0]]\n",
37+
" with open(\"tmp.pdb\",\"wb\") as out: out.write(pdb_string)\n",
38+
" return \"tmp.pdb\"\n",
39+
" else:\n",
40+
" if alphafold_model:\n",
41+
" os.system(f\"wget -qnc https://alphafold.ebi.ac.uk/files/AF-{pdb_code}-F1-model_v3.pdb\")\n",
42+
" return f\"AF-{pdb_code}-F1-model_v3.pdb\" \n",
43+
" else:\n",
44+
" os.system(f\"wget -qnc https://files.rcsb.org/view/{pdb_code}.pdb\")\n",
45+
" return f\"{pdb_code}.pdb\""
46+
],
47+
"metadata": {
48+
"id": "lev6Nc_-vx2D"
49+
},
50+
"execution_count": null,
51+
"outputs": []
52+
},
53+
{
54+
"cell_type": "code",
55+
"source": [
56+
"UNIPROT = \"P0A6A8\"\n",
57+
"SEQUENCE = get_uniprot_seq(UNIPROT)\n",
58+
"PDB_FILENAME = get_pdb(UNIPROT, alphafold_model=True)"
59+
],
60+
"metadata": {
61+
"id": "VkPdQj-Fv1LQ"
62+
},
63+
"execution_count": null,
64+
"outputs": []
65+
},
1366
{
1467
"cell_type": "markdown",
1568
"metadata": {
@@ -93,7 +146,7 @@
93146
"outputs": [],
94147
"source": [
95148
"# get bias\n",
96-
"seq = \"MSTIEERVKKIIGEQLGVKQEEVTNNASFVEDLGADSLDTVELVMALEEEFDTEIPDEEAEKITTVQAAIDYINGHQA\"\n",
149+
"seq = SEQUENCE\n",
97150
"bias = get_bias_from_esm(seq)\n",
98151
"np.savetxt(\"bias.txt\",bias)"
99152
]
@@ -107,7 +160,7 @@
107160
"outputs": [],
108161
"source": [
109162
"import matplotlib.pyplot as plt\n",
110-
"plt.imshow(bias.T)"
163+
"plt.imshow(bias.T,cmap=\"bwr_r\",vmin=-10,vmax=10)"
111164
]
112165
},
113166
{
@@ -157,34 +210,21 @@
157210
"cell_type": "code",
158211
"execution_count": null,
159212
"metadata": {
160-
"id": "Vt7G_nbNeSQ3"
213+
"id": "Vt7G_nbNeSQ3",
214+
"cellView": "form"
161215
},
162216
"outputs": [],
163217
"source": [
164-
"#import libraries\n",
218+
"#@title import libraries\n",
165219
"import warnings\n",
166220
"warnings.simplefilter(action='ignore', category=FutureWarning)\n",
167221
"\n",
168222
"import os\n",
169223
"from colabdesign import mk_afdesign_model, clear_mem\n",
224+
"from colabdesign.af.alphafold.common import residue_constants\n",
170225
"from IPython.display import HTML\n",
171-
"from google.colab import files\n",
172226
"import numpy as np\n",
173-
"from alphafold.common import residue_constants\n",
174-
"\n",
175-
"def get_pdb(pdb_code=\"\",alphafold_model=False):\n",
176-
" if pdb_code is None or pdb_code == \"\":\n",
177-
" upload_dict = files.upload()\n",
178-
" pdb_string = upload_dict[list(upload_dict.keys())[0]]\n",
179-
" with open(\"tmp.pdb\",\"wb\") as out: out.write(pdb_string)\n",
180-
" return \"tmp.pdb\"\n",
181-
" else:\n",
182-
" if alphafold_model:\n",
183-
" os.system(f\"wget -qnc https://alphafold.ebi.ac.uk/files/AF-{pdb_code}-F1-model_v2.pdb\")\n",
184-
" return f\"AF-{pdb_code}-F1-model_v2.pdb\" \n",
185-
" else:\n",
186-
" os.system(f\"wget -qnc https://files.rcsb.org/view/{pdb_code}.pdb\")\n",
187-
" return f\"{pdb_code}.pdb\""
227+
"\n"
188228
]
189229
},
190230
{
@@ -197,11 +237,8 @@
197237
"source": [
198238
"clear_mem()\n",
199239
"model = mk_afdesign_model(protocol=\"fixbb\",\n",
200-
" use_templates=False) # set True to constrain structure\n",
201-
"\n",
202-
"pdb_filename = get_pdb(\"P0A6A8\",alphafold_model=True)\n",
203-
"model.prep_inputs(pdb_filename, chain=\"A\")\n",
204-
"\n",
240+
" use_templates=False) # set True to constrain structure\n",
241+
"model.prep_inputs(PDB_FILENAME, chain=\"A\")\n",
205242
"print(\"length\", model._len)"
206243
]
207244
},
@@ -227,8 +264,7 @@
227264
"outputs": [],
228265
"source": [
229266
"model.restart()\n",
230-
"model.opt[\"bias\"] = bias\n",
231-
"\n",
267+
"model.set_seq(bias=bias)\n",
232268
"model.design_3stage(50,50,10)"
233269
]
234270
},
@@ -268,9 +304,7 @@
268304
},
269305
{
270306
"cell_type": "code",
271-
"source": [
272-
""
273-
],
307+
"source": [],
274308
"metadata": {
275309
"id": "0Xd7zQ-PqTly"
276310
},
@@ -298,4 +332,4 @@
298332
},
299333
"nbformat": 4,
300334
"nbformat_minor": 0
301-
}
335+
}

0 commit comments

Comments
 (0)