Views
No views yet

1import mlx.core as mx
2from huggingface_hub import hf_hub_download
3from transformers import AutoTokenizer
4
5# Download model weights
6model_path = hf_hub_download(
7 repo_id="gccmorgoth/protein-structure-mlx-esm2_t33_650M_UR50D",
8 filename="best_model.safetensors"
9)
10
11# Load model architecture (requires model code from repo)
12from src.models.esm2_mlx import ESM2StructurePredictor
13
14model = ESM2StructurePredictor(
15 model_name="facebook/esm2_t33_650M_UR50D",
16 output_type="distance",
17 hidden_dim=768,
18 num_layers=5
19)
20
21# Load trained weights
22model.prediction_head.load_weights(model_path)
23
24# Tokenize protein sequence
25tokenizer = AutoTokenizer.from_pretrained("facebook/esm2_t33_650M_UR50D")
26sequence = "MKTAYIAKQRQISFVKSHFSRQLEERLGLIEVQAPILSRVGDGTQDNLSGAEKAVQVKVKALPDAQFEVVHSLAKWKRQTLGQHDFSAGEGLYTHMKALRPDEDRLSPLHSVYVDQWDWERVMGDGERQFSTLKSTVEAIWAGIKATEAAVSEEFGLAPFLPDQIHFVHSQELLSRYPDLDAKGRERAIAKDLGAVFLVGIGGKLSDGHRHDVRAPDYDDWSTPSELGHAGLNGDILVWNPVLEDAFELSSMGIRVDADTLKHQLALTGDEDRLELEWHQALLRGEMPQTIGGGIGQSRLTMLLLQLPHIGQVQAGVWPAAVRESVPSLL"
27
28inputs = tokenizer(sequence, return_tensors="np")
29input_ids = mx.array(inputs["input_ids"])
30attention_mask = mx.array(inputs["attention_mask"])
31
32# Predict distance bins (logits)
33_, distance_logits = model(input_ids, attention_mask)
34# Shape: (1, seq_len, seq_len, 64)
35
36# Get most likely distance bin per residue pair
37predicted_bins = mx.argmax(distance_logits, axis=-1)1@software{protein-structure-mlx-esm2_t33_650M_UR50D,
2 title={ESM-2 Protein Structure Prediction with MLX},
3 author={Mohammad Huzefa Shaikh},
4 year={2025},
5 url={https://huggingface.co/gccmorgoth/protein-structure-mlx-esm2_t33_650M_UR50D}
6}