RosettaCommons/PISCES-CulledPDB
Viewer • Updated • 4.54M • 118
SERAPH is a deep learning model designed for 3-state (Q3) protein secondary structure prediction. It processes raw single amino acid sequences and predicts residue-level secondary structure states: Alpha Helix (H), Beta Sheet (E), or Coil/Loop (C).
The model leverages a fine-tuned facebook/esm2_t6_8M_UR50D backbone combined with a 1D Convolutional feature extractor and a 2-layer Bidirectional LSTM to capture local motifs and long-range sequence context simultaneously.
facebook/esm2_t6_8M_UR50DPypCoder/SERAPHH, E, C), not 3D atomic coordinates.pip install torch transformers huggingface_hub
import torch
import torch.nn as nn
from transformers import EsmModel, EsmTokenizer
# 1. Define SERAPH Architecture
class SERAPH(nn.Module):
def __init__(self, esm_model, conv_channels=256, kernel_size=7, lstm_hidden=256, num_classes=3, dropout=0.3):
super().__init__()
self.esm = esm_model
esm_embed_dim = self.esm.config.hidden_size
self.conv = nn.Conv1d(esm_embed_dim, conv_channels, kernel_size=kernel_size, padding=kernel_size // 2)
self.bn = nn.BatchNorm1d(conv_channels)
self.dropout = nn.Dropout(dropout)
self.bilstm = nn.LSTM(conv_channels, lstm_hidden, num_layers=2, batch_first=True, bidirectional=True)
self.fc = nn.Linear(lstm_hidden * 2, num_classes)
def forward(self, input_ids, attention_mask=None):
x = self.esm(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
x = x.transpose(1, 2)
x = torch.relu(self.bn(self.conv(x)))
x = self.dropout(x)
x = x.transpose(1, 2)
x, _ = self.bilstm(x)
x = self.dropout(x)
return self.fc(x)
# 2. Load Tokenizer & Base Backbone
ESM_MODEL_ID = "facebook/esm2_t6_8M_UR50D"
tokenizer = EsmTokenizer.from_pretrained(ESM_MODEL_ID)
esm_backbone = EsmModel.from_pretrained(ESM_MODEL_ID)
model = SERAPH(esm_model=esm_backbone)
# Load weight checkpoint
# checkpoint = torch.load("SERAPH.pth", map_location="cpu")
# model.load_state_dict(checkpoint["model_state_dict"])
model.eval()
# 3. Perform Prediction
IDX_TO_LABEL = {0: 'H', 1: 'E', 2: 'C'}
sequence = "MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHGKKVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKYR"
tokens = tokenizer(sequence, return_tensors="pt", truncation=True, max_length=512)
with torch.no_grad():
output = model(input_ids=tokens["input_ids"], attention_mask=tokens["attention_mask"])
preds = output.argmax(dim=-1)[0]
# Omit special tokens [CLS] and [EOS]
prediction = "".join([IDX_TO_LABEL[p.item()] for p in preds[1:-1]])
print(f"Sequence: {sequence}")
print(f"Prediction: {prediction}")
lr=5e-5, weight_decay=1e-4)CrossEntropyLoss with class weight adjustments [H: 1.3, E: 1.3, C: 1.0]max_norm = 1.0ReduceLROnPlateau (patience=3, factor=0.5)facebook/esm2_t6_8M_UR50D unfrozen during training.| Layer Component | Trainable Parameters |
|---|---|
| ESM-2 Backbone (Unfrozen layers) | ~2,600,000 |
Conv1D (320 → 256, k=7) |
573,440 |
BatchNorm1d (256) |
512 |
| BiLSTM (2 Layers, hidden=256) | ~1,311,232 |
Linear Head (512 → 3) |
1,539 |
| Total Trainable Parameters | 3,205,379 |
Evaluated on the standard CB513 benchmark dataset.
| Evaluation Metric | Score |
|---|---|
| Q3 Test Accuracy (CB513) | 75.31% |
| Q3 Training Accuracy | 79.34% |
| Structure Class | Precision | Recall |
|---|---|---|
Helix (H) |
0.82 | 0.80 |
Sheet (E) |
0.63 | 0.81 |
Coil (C) |
0.79 | 0.68 |
If you use SERAPH in your work, please cite the underlying ESM-2 paper and reference this repository:
@software{seraph2026,
author = {Muhammad Asad Ullah},
title = {SERAPH: Secondary Structure Recognition & Prediction Hub},
year = {2026},
url = {https://huggingface.co/PypCoder/SERAPH}
}
Base model
facebook/esm2_t6_8M_UR50D