Predict Protein Contact Maps with ESM-2

Let's say you want to securely generate a fast but accurate contact map for visualization or ML. BioLM lets you predict the contact map data in seconds, no spinning up GPUs or installing programs and dependencies.

# Import the BioLM SDK
import time
from biolmai import BioLM

Define Endpoint Params

# Let's use the sequence from the paper
# https://www.biorxiv.org/content/10.1101/2021.07.09.450648v2.full.pdf
SEQ = "ASKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLVTTFSYGVQCFSRYPDHMKRHDFFKSAMPEGYVQERTIFFKDDGNYKTRAEVKFEGDTLVNRIELKGIDFKEDGNILGHKLEYNYNSHNVYIMADKQKNGIKVNFKIRHNIEDGSVQLADHYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK"
params = {
            "include": [
                "mean",
                "contacts",
                "logits",
                "attentions"
            ]
    }
print("Sequence length: {}".format(len(SEQ)))
Sequence length: 238

Make API Request

Let's make a secure REST API request to BioLM API to quickly make the prediction on GPU.

start = time.time()
result = BioLM(entity="esm2-650m", action="encode", type="sequence", items=[SEQ], params=params)
end = time.time()
print(f"ESM2 contact map generation took {end - start:.4f} seconds.")
ESM2 contact map generation took 257.2853 seconds.

There are keys containing:

  • our contacts, which is a len(seq) x len(seq) matrix
  • the logits from the final hidden state, which is a vector of len(seq)
  • the attentions or attention map, which is len(seq) x n_layers
  • mean_representations, which are the protein embeddings which is a vector of 1280
  • lastly sequence_index, which is simply the index of the sequence in the order it was POSTed
contact_map = result['contacts']

# Straight from the model, this would be 223, 223 due to start/end tokens,
# but the endpoint cleans that up for us
nrow = len(contact_map)
ncol = len(contact_map[0])

print(f'({nrow}, {ncol})')
(238, 238)
from matplotlib import pyplot as plt
plt.figure(figsize=(9, 9))
plt.xlabel('Residue')
plt.ylabel('Residue')
plt.title('Contact Map of Example Protein Using ESM2')
plt.imshow(contact_map, cmap='viridis', interpolation='nearest')
plt.show()
No description has been provided for this image

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.


Contact us to learn more.

<span></span>

Accelerate yourLead generation

BioLM offers tailored AI solutions to meet your experimental needs. We deliver top-tier results with our model-agnostic approach, powered by our highly scalable and real-time GPU-backed APIs and years of experience in biological data modeling, all at a competitive price.

CTA

We speak the language of bio-AI

© 2022 - 2025 BioLM. All Rights Reserved.