Learn how to fold large proteins, multi-chain proteins, and at scale via REST API.
Fast & Accurate PDB Prediction with ESMFold¶
Having the ability to use AlphaFold2, ESM, and other recent structural modeling NNs is great, but what if you don't want to leave Python, don't want to spin up a GPU, want to avoid conterization, or need to massively scale out your PDB file prediction / creation?
You can predict a PDB file for proteins up to 1024+ in length using the highly accurate ESMFold, scaled out and pre-loaded into memory on BioLM.ai. The API docs show an example protein and PDB string response.
Set Your API Token¶
In order to use the BioLM API, you need to have a token. You can get one from the User API Tokens page.
Paste the API token you generated in the cell below, as the value
of the variable BIOLMAI_TOKEN
.
BIOLMAI_TOKEN = ' ' # !!! YOUR API TOKEN HERE !!!
SEQ = "MAETAVINHKKRNSPRIVQSNDLEAAYSLSRDQKRMLYLFVDQIRKSDGTLQEHDGICEIHVAKYAEIFGLTSAEASKDIRQALKSFAGKEVVFYRPEEDAGDEKGYESFPWFIKRAHSPSRGLYSVHINPYLIPFFIGLQNRFTQFRLSETKEITNPYAMRLYESLCQYRKPDGSGIVSLKIDWIIERYQLPQSYQRMPDFRRRFLQVCVNEINSRTPMRLSYIEKKKGRQTTHIVFSFRDITSMTTG"
print("Sequence length: {}".format(len(SEQ)))
SLUG = 'esmfold-multichain' # Model on BioLM.ai to use
ACTION = 'predict' # How to use model: 'generate', 'predict', 'encode', etc
# JSON payload to send to model endpoint
data = {
"items": [{
"sequence": SEQ
}]
}
Make API Request¶
There is already a server on BioLM with ESMFold loaded into memory, so predictions should be fast. Let's import the requests
library.
from IPython.display import JSON # Helpful UI for JSON display
try:
# Install packages to make API requests in JLite
import micropip
await micropip.install('requests')
await micropip.install('pyodide-http')
# Patch requests for in-browser support
import pyodide_http
pyodide_http.patch_all()
except ModuleNotFoundError:
pass # Won't be using micropip outside of JLite
import requests # Will use to make calls to BioLM.ai
url = f"https://biolm.ai/api/v2/{SLUG}/{ACTION}/"
headers = {
"Content-Type": "application/json",
"Authorization": f"Token {BIOLMAI_TOKEN.strip()}",
}
# Make the request - let's time it!
import time
s = time.time() # Start time
response = requests.post(
url=url,
headers=headers,
json=data,
)
e = time.time() # End time
d = e - s # Duration
print(f'Response time: {d:.4}s')
result = response.json()
# If you wish to view the full result, you can expand the tree in the cell below
JSON(result)
If the model was starting cold, there would be an initial wait time of several minutese to load this large model into memory, after which subsequent API requests would respond normally, without delay. This is what is known as a model cold-start time. It is generally not very noticeable, except in this case since ESMFold is one of the largest protein models to date at the time of this writing.
Visualize Structure in 3D¶
We have the PDB file contents as a string. We can use it directly to visualize the structure.
# View the file contents first
import json
pdb_pred = result['results'][0] # Extract the contents of the PDB file
json.dumps(pdb_pred)[:1000] # Look at the first 1000 characters, since PDBs are long...
Let's use the py3Dmol
Python package to visualize the PDB here, in-browser.
try:
# Install packages for JLite
import micropip
await micropip.install('py3Dmol')
except ModuleNotFoundError:
pass # Won't be using micropip outside of JLite
import py3Dmol # Install with `pip install py3Dmol` if running notebook elsewhere
view = py3Dmol.view(js='https://3Dmol.org/build/3Dmol-min.js', width=800, height=400)
view.addModel(pdb_pred, 'pdb')
view.setStyle({'model': -1}, {"cartoon": {'color': 'spectrum'}})
view.zoomTo()
See more use-cases and APIs on your BioLM Console Catalog.¶
BioLM hosts deep learning models and runs inference at scale. You do the science.¶
Enzyme Engineering | Antibody Engineering | Biosecurity |
Single-Cell Genomics | DNA Sequence Modelling | Finetuning |
Contact us to learn more.¶