Learn how to quickly access the ProGen2 models using REST APIs, for rapid and semi-directed protein generation.




ProGen2 API

ProGen2, with models up to 6.4B parameters, is adept at generating viable protein sequences and predicting their fitness. It's utilized in protein design, trained on data from genomic and metagenomic sources.


Postman API Docs
Python SDK Docs
Github Link
Paper Link


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.

In [1]:
BIOLMAI_TOKEN = " "  # !!! YOUR API TOKEN HERE !!!

API Call with Python requests

We need to make sure we have the Python requests module loaded first.

In [2]:
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
from IPython.display import JSON  # Helpful UI for JSON display

ProGen2 Medium

In [3]:
SLUG = 'progen2-medium'
ACTION = 'generate'

url = f"https://biolm.ai/api/v2/{SLUG}/{ACTION}/"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Token {BIOLMAI_TOKEN.strip()}",
}

data = {
    "params": {
        "temperature": 0.1,  # Temperature
        "top_p": 0.6,  # Nucleus sampling probability
        "num_samples": 2,  # Number of proteins to generate
        "max_length": 175  # Max length of generated proteins
    },
    "items": [
        {
            "context": "MA"  # Starting amino acid(s) for protein
        }
    ]
}

# Make the request
response = requests.post(
    url=url,
    headers=headers,
    json=data,
)

result = response.json()
result
Out[3]:
{'results': [[{'sequence': 'MASSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS',
    'll_sum': -24.980167388916016,
    'll_mean': -0.14356417953968048},
   {'sequence': 'MASSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS',
    'll_sum': -24.980167388916016,
    'll_mean': -0.14356417953968048}]]}

We can view this a bit more easily below:

In [4]:
JSON(result)
Out[4]:
<IPython.core.display.JSON object>

ProGen2 OAS

In [5]:
import requests

SLUG = 'progen2-oas'
ACTION = 'generate'

url = f"https://biolm.ai/api/v2/{SLUG}/{ACTION}/"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Token {BIOLMAI_TOKEN.strip()}",
}

data = {
    "params": {
        "temperature": 0.7,  # Temperature
        "top_p": 0.6,  # Nucleus sampling probability
        "num_samples": 2,  # Number of proteins to generate
        "max_length": 175  # Max length of generated proteins
    },
    "items": [
        {
            "context": "EVQ"  # Starting amino acids for Antibody
        }
    ]
}

# Make the POST request
response = requests.post(
    url=url,
    headers=headers,
    json=data,
)

result = response.json()
result
Out[5]:
{'results': [[{'sequence': 'EVQLVESGGGLVQPGGSLRLSCAASGFTFSSYWMSWVRQAPGKGLEWVANIKQDGSEKYYVDSVKGRFTISRDNAKNSLYLQMNSLRAEDTAVYYCARDRYYDFWSGYYTGYYYYYMDVWGKGTTVTVSS',
    'll_sum': -24.10324001312256,
    'll_mean': -0.1854095384478569},
   {'sequence': 'EVQLVESGGGLVQPGGSLRLSCAASGFTFSSYSMNWVRQAPGKGLEWVSYISSSSSTIYYADSVKGRFTISRDNAKNSLYLQMNSLRAEDTAVYYCARDRSSSWYGGGYYYYGMDVWGQGTTVTVSS',
    'll_sum': -26.63103485107422,
    'll_mean': -0.20969318598508835}]]}
In [6]:
JSON(result)
Out[6]:
<IPython.core.display.JSON object>
In [ ]:
 

ProGen2 BFD90

In [9]:
import requests

SLUG = 'progen2-bfd90'
ACTION = 'generate'

url = f"https://biolm.ai/api/v2/{SLUG}/{ACTION}/"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Token {BIOLMAI_TOKEN.strip()}",
}

data = {
    "params": {
        "temperature": 0.7,  # Temperature
        "top_p": 0.6,  # Nucleus sampling probability
        "num_samples": 2,  # Number of proteins to generate
        "max_length": 175  # Max length of generated proteins
    },
    "items": [
        {
            "context": "M"  # Starting amino acid(s) for protein
        }
    ]
}

# Make the request
response = requests.post(
    url=url,
    headers=headers,
    json=data,
)

result = response.json()
result
Out[9]:
{'results': [[{'sequence': 'MASGASAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAAA',
    'll_sum': -84.33449363708496,
    'll_mean': -0.48468099534511566},
   {'sequence': 'MADDEEYEEVVEYYTEETVYEEVPGETITEIYETTTTRTSDYEQSETSKPALAQPVPAKPVERKKVIRKKVDSSKFMTPYIEHSQKMQDLFSTNKYKENYEKAKGQPYAITTDTPELRRIKKVQDQLSEVKYRMDGDVAKTICHVDEKAKDIEHAKKVSQQVSKVLYKQNWEDT',
    'll_sum': -114.54681396484375,
    'll_mean': -0.6583150252699852}]]}
In [10]:
JSON(result)
Out[10]:
<IPython.core.display.JSON object>
In [ ]:
 

Next Steps

Check out additional tutorials at jupyter.biolm.ai, or head over to our BioLM Documentation to explore additional models and functionality.

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.

In [ ]: